@mathzdevolper/phantomcode-cli 1.0.0 → 2.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/bin/phantomcode.js +2 -0
- package/package.json +6 -26
- package/src/cli.js +65 -0
- package/src/commands/chat.js +50 -0
- package/src/commands/config.js +35 -0
- package/src/commands/interactive.js +87 -0
- package/src/commands/models.js +35 -0
- package/src/config.js +135 -0
- package/src/hf.js +67 -0
- package/src/logger.js +84 -0
- package/src/models.js +49 -0
- package/dist/commands/chat.d.ts +0 -9
- package/dist/commands/chat.js +0 -68
- package/dist/commands/chat.js.map +0 -1
- package/dist/commands/config.d.ts +0 -1
- package/dist/commands/config.js +0 -57
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/interactive.d.ts +0 -7
- package/dist/commands/interactive.js +0 -155
- package/dist/commands/interactive.js.map +0 -1
- package/dist/commands/models.d.ts +0 -5
- package/dist/commands/models.js +0 -38
- package/dist/commands/models.js.map +0 -1
- package/dist/commands/session.d.ts +0 -1
- package/dist/commands/session.js +0 -77
- package/dist/commands/session.js.map +0 -1
- package/dist/config/manager.d.ts +0 -14
- package/dist/config/manager.js +0 -49
- package/dist/config/manager.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -90
- package/dist/index.js.map +0 -1
- package/dist/provider/dogrouter.d.ts +0 -28
- package/dist/provider/dogrouter.js +0 -58
- package/dist/provider/dogrouter.js.map +0 -1
- package/dist/session/manager.d.ts +0 -20
- package/dist/session/manager.js +0 -112
- package/dist/session/manager.js.map +0 -1
- package/dist/tui/colors.d.ts +0 -15
- package/dist/tui/colors.js +0 -47
- package/dist/tui/colors.js.map +0 -1
- package/src/commands/chat.ts +0 -81
- package/src/commands/config.ts +0 -74
- package/src/commands/interactive.ts +0 -140
- package/src/commands/models.ts +0 -41
- package/src/commands/session.ts +0 -93
- package/src/config/manager.ts +0 -49
- package/src/index.ts +0 -109
- package/src/provider/dogrouter.ts +0 -82
- package/src/session/manager.ts +0 -93
- package/src/tui/colors.ts +0 -43
- package/tsconfig.json +0 -17
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export interface ChatOptions {
|
|
2
|
-
model?: string;
|
|
3
|
-
systemPrompt?: string;
|
|
4
|
-
temperature?: number;
|
|
5
|
-
maxTokens?: number;
|
|
6
|
-
stream?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface ChatResponse {
|
|
9
|
-
content: string;
|
|
10
|
-
model: string;
|
|
11
|
-
usage?: {
|
|
12
|
-
promptTokens: number;
|
|
13
|
-
completionTokens: number;
|
|
14
|
-
totalTokens: number;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export declare function chat(apiKey: string, messages: {
|
|
18
|
-
role: "user" | "assistant" | "system";
|
|
19
|
-
content: string;
|
|
20
|
-
}[], options?: ChatOptions): Promise<ChatResponse>;
|
|
21
|
-
export declare function chatStream(apiKey: string, messages: {
|
|
22
|
-
role: "user" | "assistant" | "system";
|
|
23
|
-
content: string;
|
|
24
|
-
}[], options?: ChatOptions): AsyncGenerator<string>;
|
|
25
|
-
export declare function listModels(apiKey: string): Promise<{
|
|
26
|
-
id: string;
|
|
27
|
-
ownedBy: string;
|
|
28
|
-
}[]>;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.chat = chat;
|
|
7
|
-
exports.chatStream = chatStream;
|
|
8
|
-
exports.listModels = listModels;
|
|
9
|
-
const openai_1 = __importDefault(require("openai"));
|
|
10
|
-
const BASE_URL = "https://api.dogrouter.ai/v1";
|
|
11
|
-
let client = null;
|
|
12
|
-
function getClient(apiKey) {
|
|
13
|
-
if (!client) {
|
|
14
|
-
client = new openai_1.default({ apiKey, baseURL: BASE_URL });
|
|
15
|
-
}
|
|
16
|
-
return client;
|
|
17
|
-
}
|
|
18
|
-
async function chat(apiKey, messages, options = {}) {
|
|
19
|
-
const c = getClient(apiKey);
|
|
20
|
-
const completion = await c.chat.completions.create({
|
|
21
|
-
model: options.model || "dogrouter/auto",
|
|
22
|
-
messages: messages.map((m) => ({ role: m.role, content: m.content })),
|
|
23
|
-
temperature: options.temperature ?? 0.7,
|
|
24
|
-
max_tokens: options.maxTokens,
|
|
25
|
-
});
|
|
26
|
-
return {
|
|
27
|
-
content: completion.choices[0]?.message?.content || "",
|
|
28
|
-
model: completion.model,
|
|
29
|
-
usage: completion.usage
|
|
30
|
-
? {
|
|
31
|
-
promptTokens: completion.usage.prompt_tokens,
|
|
32
|
-
completionTokens: completion.usage.completion_tokens,
|
|
33
|
-
totalTokens: completion.usage.total_tokens,
|
|
34
|
-
}
|
|
35
|
-
: undefined,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
async function* chatStream(apiKey, messages, options = {}) {
|
|
39
|
-
const c = getClient(apiKey);
|
|
40
|
-
const stream = await c.chat.completions.create({
|
|
41
|
-
model: options.model || "dogrouter/auto",
|
|
42
|
-
messages: messages.map((m) => ({ role: m.role, content: m.content })),
|
|
43
|
-
temperature: options.temperature ?? 0.7,
|
|
44
|
-
max_tokens: options.maxTokens,
|
|
45
|
-
stream: true,
|
|
46
|
-
});
|
|
47
|
-
for await (const chunk of stream) {
|
|
48
|
-
const delta = chunk.choices[0]?.delta?.content;
|
|
49
|
-
if (delta)
|
|
50
|
-
yield delta;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async function listModels(apiKey) {
|
|
54
|
-
const c = getClient(apiKey);
|
|
55
|
-
const models = await c.models.list();
|
|
56
|
-
return models.data.map((m) => ({ id: m.id, ownedBy: m.owned_by || "dogrouter" }));
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=dogrouter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3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C,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
interface Message {
|
|
2
|
-
role: "user" | "assistant" | "system";
|
|
3
|
-
content: string;
|
|
4
|
-
timestamp: number;
|
|
5
|
-
}
|
|
6
|
-
interface Session {
|
|
7
|
-
id: string;
|
|
8
|
-
title: string;
|
|
9
|
-
model: string;
|
|
10
|
-
messages: Message[];
|
|
11
|
-
createdAt: number;
|
|
12
|
-
updatedAt: number;
|
|
13
|
-
}
|
|
14
|
-
export declare function createSession(model: string, title?: string): Session;
|
|
15
|
-
export declare function getSession(id: string): Session | null;
|
|
16
|
-
export declare function listSessions(): Session[];
|
|
17
|
-
export declare function addMessage(sessionId: string, role: Message["role"], content: string): Session | null;
|
|
18
|
-
export declare function deleteSession(id: string): void;
|
|
19
|
-
export declare function getMessages(sessionId: string): Message[];
|
|
20
|
-
export {};
|
package/dist/session/manager.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createSession = createSession;
|
|
37
|
-
exports.getSession = getSession;
|
|
38
|
-
exports.listSessions = listSessions;
|
|
39
|
-
exports.addMessage = addMessage;
|
|
40
|
-
exports.deleteSession = deleteSession;
|
|
41
|
-
exports.getMessages = getMessages;
|
|
42
|
-
const uuid_1 = require("uuid");
|
|
43
|
-
const fs = __importStar(require("fs"));
|
|
44
|
-
const path = __importStar(require("path"));
|
|
45
|
-
const os = __importStar(require("os"));
|
|
46
|
-
const SESSIONS_DIR = path.join(os.homedir(), ".phantomcode", "sessions");
|
|
47
|
-
function ensureDir() {
|
|
48
|
-
if (!fs.existsSync(SESSIONS_DIR)) {
|
|
49
|
-
fs.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function sessionPath(id) {
|
|
53
|
-
return path.join(SESSIONS_DIR, `${id}.json`);
|
|
54
|
-
}
|
|
55
|
-
function createSession(model, title = "Nova sessao") {
|
|
56
|
-
ensureDir();
|
|
57
|
-
const session = {
|
|
58
|
-
id: (0, uuid_1.v4)(),
|
|
59
|
-
title,
|
|
60
|
-
model,
|
|
61
|
-
messages: [],
|
|
62
|
-
createdAt: Date.now(),
|
|
63
|
-
updatedAt: Date.now(),
|
|
64
|
-
};
|
|
65
|
-
fs.writeFileSync(sessionPath(session.id), JSON.stringify(session, null, 2));
|
|
66
|
-
return session;
|
|
67
|
-
}
|
|
68
|
-
function getSession(id) {
|
|
69
|
-
try {
|
|
70
|
-
return JSON.parse(fs.readFileSync(sessionPath(id), "utf-8"));
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function listSessions() {
|
|
77
|
-
ensureDir();
|
|
78
|
-
const files = fs.readdirSync(SESSIONS_DIR).filter((f) => f.endsWith(".json"));
|
|
79
|
-
return files
|
|
80
|
-
.map((f) => {
|
|
81
|
-
try {
|
|
82
|
-
return JSON.parse(fs.readFileSync(path.join(SESSIONS_DIR, f), "utf-8"));
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
.filter((s) => s !== null)
|
|
89
|
-
.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
90
|
-
}
|
|
91
|
-
function addMessage(sessionId, role, content) {
|
|
92
|
-
const session = getSession(sessionId);
|
|
93
|
-
if (!session)
|
|
94
|
-
return null;
|
|
95
|
-
session.messages.push({ role, content, timestamp: Date.now() });
|
|
96
|
-
session.updatedAt = Date.now();
|
|
97
|
-
if (session.messages.length === 1) {
|
|
98
|
-
session.title = content.slice(0, 50) + (content.length > 50 ? "..." : "");
|
|
99
|
-
}
|
|
100
|
-
fs.writeFileSync(sessionPath(sessionId), JSON.stringify(session, null, 2));
|
|
101
|
-
return session;
|
|
102
|
-
}
|
|
103
|
-
function deleteSession(id) {
|
|
104
|
-
const p = sessionPath(id);
|
|
105
|
-
if (fs.existsSync(p))
|
|
106
|
-
fs.unlinkSync(p);
|
|
107
|
-
}
|
|
108
|
-
function getMessages(sessionId) {
|
|
109
|
-
const session = getSession(sessionId);
|
|
110
|
-
return session?.messages || [];
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/session/manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,sCAYC;AAED,gCAMC;AAED,oCAaC;AAED,gCAaC;AAED,sCAGC;AAED,kCAGC;AA5FD,+BAAkC;AAClC,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AAiBzB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;AAEzE,SAAS,SAAS;IAChB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,EAAU;IAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,aAAa,CAAC,KAAa,EAAE,KAAK,GAAG,aAAa;IAChE,SAAS,EAAE,CAAC;IACZ,MAAM,OAAO,GAAY;QACvB,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,KAAK;QACL,KAAK;QACL,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;IACF,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,UAA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G,IAAI,CAAC,GAAG,EAAE,CAAC;IAE/B,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,aAAa,CAAC,EAAU;IACtC,MAAM,CAAC,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAgB,WAAW,CAAC,SAAiB;IAC3C,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAC;AACjC,CAAC"}
|
package/dist/tui/colors.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
export declare const style: {
|
|
3
|
-
primary: (s: string) => string;
|
|
4
|
-
success: (s: string) => string;
|
|
5
|
-
warning: (s: string) => string;
|
|
6
|
-
error: (s: string) => string;
|
|
7
|
-
muted: (s: string) => string;
|
|
8
|
-
highlight: (s: string) => string;
|
|
9
|
-
label: (s: string) => string;
|
|
10
|
-
bold: chalk.Chalk;
|
|
11
|
-
dim: chalk.Chalk;
|
|
12
|
-
code: (s: string) => string;
|
|
13
|
-
header: (s: string) => string;
|
|
14
|
-
separator: () => string;
|
|
15
|
-
};
|
package/dist/tui/colors.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.style = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const manager_1 = require("../config/manager");
|
|
9
|
-
const theme = {
|
|
10
|
-
light: {
|
|
11
|
-
primary: chalk_1.default.hex("#2563eb"),
|
|
12
|
-
success: chalk_1.default.hex("#16a34a"),
|
|
13
|
-
warning: chalk_1.default.hex("#ea580c"),
|
|
14
|
-
error: chalk_1.default.hex("#dc2626"),
|
|
15
|
-
muted: chalk_1.default.hex("#64748b"),
|
|
16
|
-
highlight: chalk_1.default.hex("#1e293b"),
|
|
17
|
-
label: chalk_1.default.hex("#475569"),
|
|
18
|
-
},
|
|
19
|
-
dark: {
|
|
20
|
-
primary: chalk_1.default.hex("#60a5fa"),
|
|
21
|
-
success: chalk_1.default.hex("#4ade80"),
|
|
22
|
-
warning: chalk_1.default.hex("#fb923c"),
|
|
23
|
-
error: chalk_1.default.hex("#f87171"),
|
|
24
|
-
muted: chalk_1.default.hex("#94a3b8"),
|
|
25
|
-
highlight: chalk_1.default.hex("#e2e8f0"),
|
|
26
|
-
label: chalk_1.default.hex("#cbd5e1"),
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
function getColors() {
|
|
30
|
-
const t = (0, manager_1.getTheme)() === "light" ? theme.light : theme.dark;
|
|
31
|
-
return t;
|
|
32
|
-
}
|
|
33
|
-
exports.style = {
|
|
34
|
-
primary: (s) => getColors().primary(s),
|
|
35
|
-
success: (s) => getColors().success(s),
|
|
36
|
-
warning: (s) => getColors().warning(s),
|
|
37
|
-
error: (s) => getColors().error(s),
|
|
38
|
-
muted: (s) => getColors().muted(s),
|
|
39
|
-
highlight: (s) => getColors().highlight(s),
|
|
40
|
-
label: (s) => getColors().label(s),
|
|
41
|
-
bold: chalk_1.default.bold,
|
|
42
|
-
dim: chalk_1.default.dim,
|
|
43
|
-
code: (s) => chalk_1.default.cyan(s),
|
|
44
|
-
header: (s) => chalk_1.default.bold.hex("#60a5fa")(s),
|
|
45
|
-
separator: () => chalk_1.default.dim("─".repeat(process.stdout.columns || 60)),
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=colors.js.map
|
package/dist/tui/colors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/tui/colors.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,+CAA6C;AAE7C,MAAM,KAAK,GAAG;IACZ,KAAK,EAAE;QACL,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC7B,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC7B,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC7B,KAAK,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC3B,KAAK,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC3B,SAAS,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC/B,KAAK,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;KAC5B;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC7B,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC7B,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC7B,KAAK,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC3B,KAAK,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAC3B,SAAS,EAAE,eAAK,CAAC,GAAG,CAA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,EAAE,CAAC,eAAK,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;CACrE,CAAC"}
|
package/src/commands/chat.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { getApiKey, getDefaultModel } from "../config/manager";
|
|
2
|
-
import { chat } from "../provider/dogrouter";
|
|
3
|
-
import { style } from "../tui/colors";
|
|
4
|
-
import { createSession, addMessage, getSession } from "../session/manager";
|
|
5
|
-
|
|
6
|
-
interface ChatArgs {
|
|
7
|
-
message: string;
|
|
8
|
-
model?: string;
|
|
9
|
-
noSave?: boolean;
|
|
10
|
-
session?: string;
|
|
11
|
-
system?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function handleChat(args: ChatArgs): Promise<void> {
|
|
15
|
-
let apiKey: string;
|
|
16
|
-
try {
|
|
17
|
-
apiKey = getApiKey();
|
|
18
|
-
} catch {
|
|
19
|
-
console.error(style.error("✗ API key nao configurada"));
|
|
20
|
-
console.log(style.muted(" Execute: phantomcode config set <sua-api-key>"));
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const model = args.model || getDefaultModel();
|
|
25
|
-
const messages: { role: "user" | "assistant" | "system"; content: string }[] = [];
|
|
26
|
-
|
|
27
|
-
if (args.session) {
|
|
28
|
-
const session = getSession(args.session);
|
|
29
|
-
if (session) {
|
|
30
|
-
messages.push(...session.messages.map((m) => ({ role: m.role, content: m.content })));
|
|
31
|
-
console.log(style.muted(`↻ Continuando sessao: ${session.title}`));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (args.system) {
|
|
36
|
-
messages.unshift({ role: "system", content: args.system });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
messages.push({ role: "user", content: args.message });
|
|
40
|
-
|
|
41
|
-
console.log(style.separator());
|
|
42
|
-
console.log(`${style.label("Voce:")} ${args.message}`);
|
|
43
|
-
console.log(style.separator());
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
const response = await chat(apiKey, messages, { model });
|
|
47
|
-
|
|
48
|
-
console.log(`${style.primary("Phantom:")} ${response.content}`);
|
|
49
|
-
|
|
50
|
-
if (response.usage) {
|
|
51
|
-
console.log(style.separator());
|
|
52
|
-
console.log(
|
|
53
|
-
style.muted(
|
|
54
|
-
`↳ Modelo: ${response.model} | Tokens: ${response.usage.promptTokens}→${response.usage.completionTokens} (${response.usage.totalTokens})`
|
|
55
|
-
)
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!args.noSave) {
|
|
60
|
-
if (!args.session) {
|
|
61
|
-
const session = createSession(model, args.message);
|
|
62
|
-
addMessage(session.id, "user", args.message);
|
|
63
|
-
addMessage(session.id, "assistant", response.content);
|
|
64
|
-
console.log(style.muted(`↳ Sessao salva: ${session.id}`));
|
|
65
|
-
} else {
|
|
66
|
-
addMessage(args.session, "user", args.message);
|
|
67
|
-
addMessage(args.session, "assistant", response.content);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
} catch (error: unknown) {
|
|
71
|
-
const err = error as { message?: string; status?: number };
|
|
72
|
-
if (err.status === 401) {
|
|
73
|
-
console.error(style.error("✗ API key invalida. Use: phantomcode config set <api-key>"));
|
|
74
|
-
} else if (err.status === 429) {
|
|
75
|
-
console.error(style.error("✗ Limite de requisicoes excedido. Tente novamente mais tarde"));
|
|
76
|
-
} else {
|
|
77
|
-
console.error(style.error(`✗ Erro: ${err.message || "Erro desconhecido"}`));
|
|
78
|
-
}
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
}
|
package/src/commands/config.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { setApiKey, getApiKey, removeApiKey, hasApiKey, getDefaultModel, setDefaultModel, getAll } from "../config/manager";
|
|
2
|
-
import { style } from "../tui/colors";
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
export function buildConfigCommand(yargs: any): any {
|
|
6
|
-
return yargs
|
|
7
|
-
.command(
|
|
8
|
-
"set <api-key>",
|
|
9
|
-
"Define a API key do DogRouter",
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
(y: any) =>
|
|
12
|
-
y.positional("api-key", {
|
|
13
|
-
describe: "Sua API key do DogRouter",
|
|
14
|
-
type: "string",
|
|
15
|
-
demandOption: true,
|
|
16
|
-
}),
|
|
17
|
-
(args: { apiKey: string }) => {
|
|
18
|
-
setApiKey(args.apiKey);
|
|
19
|
-
console.log(style.success("✓ API key configurada com sucesso"));
|
|
20
|
-
}
|
|
21
|
-
)
|
|
22
|
-
.command(
|
|
23
|
-
"get",
|
|
24
|
-
"Exibe as configuracoes atuais",
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
(y: any) =>
|
|
27
|
-
y
|
|
28
|
-
.option("api-key", { type: "boolean", desc: "Exibir apenas a API key" })
|
|
29
|
-
.option("model", { type: "boolean", desc: "Exibir apenas o modelo padrao" })
|
|
30
|
-
.option("all", { type: "boolean", desc: "Exibir todas as configuracoes" }),
|
|
31
|
-
(args: { apiKey?: boolean; model?: boolean; all?: boolean }) => {
|
|
32
|
-
if (args.apiKey) {
|
|
33
|
-
console.log(style.label(`API Key: ${hasApiKey() ? style.code(getApiKey()) : style.warning("nao definida")}`));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (args.model) {
|
|
37
|
-
console.log(style.label(`Modelo padrao: ${style.code(getDefaultModel())}`));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const all = getAll();
|
|
41
|
-
console.log(style.header("┌─ Configuracao ──────────────────────"));
|
|
42
|
-
console.log(style.label(`│ API Key: ${all.apiKey ? style.code(all.apiKey.slice(0, 12) + "...") : style.muted("nao definida")}`));
|
|
43
|
-
console.log(style.label(`│ Modelo padrao: ${style.code(all.defaultModel || "dogrouter/auto")}`));
|
|
44
|
-
console.log(style.label(`│ Tema: ${style.code(all.theme || "dark")}`));
|
|
45
|
-
console.log(style.header("└────────────────────────────────────"));
|
|
46
|
-
}
|
|
47
|
-
)
|
|
48
|
-
.command(
|
|
49
|
-
"reset",
|
|
50
|
-
"Remove a API key configurada",
|
|
51
|
-
() => ({}),
|
|
52
|
-
() => {
|
|
53
|
-
removeApiKey();
|
|
54
|
-
console.log(style.warning("⚠ API key removida"));
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
.command(
|
|
58
|
-
"set-model <model>",
|
|
59
|
-
"Define o modelo padrao",
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
(y: any) =>
|
|
62
|
-
y.positional("model", {
|
|
63
|
-
describe: "Nome do modelo (ex: dogrouter/auto)",
|
|
64
|
-
type: "string",
|
|
65
|
-
demandOption: true,
|
|
66
|
-
}),
|
|
67
|
-
(args: { model: string }) => {
|
|
68
|
-
setDefaultModel(args.model);
|
|
69
|
-
console.log(style.success(`✓ Modelo padrao alterado para: ${style.code(args.model)}`));
|
|
70
|
-
}
|
|
71
|
-
)
|
|
72
|
-
.demandCommand(1, "Use: phantomcode config <comando>")
|
|
73
|
-
.help();
|
|
74
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import * as readline from "readline";
|
|
2
|
-
import { getApiKey, getDefaultModel } from "../config/manager";
|
|
3
|
-
import { chat } from "../provider/dogrouter";
|
|
4
|
-
import { style } from "../tui/colors";
|
|
5
|
-
import { createSession, addMessage, getSession } from "../session/manager";
|
|
6
|
-
|
|
7
|
-
interface InteractiveArgs {
|
|
8
|
-
model?: string;
|
|
9
|
-
session?: string;
|
|
10
|
-
system?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function runInteractive(args: InteractiveArgs): Promise<void> {
|
|
14
|
-
let apiKey: string;
|
|
15
|
-
try {
|
|
16
|
-
apiKey = getApiKey();
|
|
17
|
-
} catch {
|
|
18
|
-
console.error(style.error("✗ API key nao configurada"));
|
|
19
|
-
console.log(style.muted(" Execute: phantomcode config set <sua-api-key>"));
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const model = args.model || getDefaultModel();
|
|
24
|
-
let sessionId: string | null = null;
|
|
25
|
-
const messages: { role: "user" | "assistant" | "system"; content: string }[] = [];
|
|
26
|
-
|
|
27
|
-
if (args.session) {
|
|
28
|
-
const existing = getSession(args.session);
|
|
29
|
-
if (existing) {
|
|
30
|
-
sessionId = existing.id;
|
|
31
|
-
messages.push(...existing.messages.map((m) => ({ role: m.role, content: m.content })));
|
|
32
|
-
console.log(style.muted(`↻ Continuando sessao: ${existing.title}\n`));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (args.system) {
|
|
37
|
-
messages.unshift({ role: "system", content: args.system });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
printBanner();
|
|
41
|
-
|
|
42
|
-
const rl = readline.createInterface({
|
|
43
|
-
input: process.stdin,
|
|
44
|
-
output: process.stdout,
|
|
45
|
-
prompt: style.primary("» "),
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
rl.prompt();
|
|
49
|
-
|
|
50
|
-
rl.on("line", async (line: string) => {
|
|
51
|
-
const input = line.trim();
|
|
52
|
-
|
|
53
|
-
if (input === "" || input === "/exit" || input === "/quit") {
|
|
54
|
-
rl.close();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (input === "/help") {
|
|
59
|
-
printHelp();
|
|
60
|
-
rl.prompt();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (input === "/clear") {
|
|
65
|
-
console.clear();
|
|
66
|
-
printBanner();
|
|
67
|
-
rl.prompt();
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (input === "/new") {
|
|
72
|
-
messages.length = 0;
|
|
73
|
-
if (args.system) messages.unshift({ role: "system", content: args.system });
|
|
74
|
-
sessionId = null;
|
|
75
|
-
console.log(style.success("✓ Nova conversa iniciada\n"));
|
|
76
|
-
rl.prompt();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (input.startsWith("/model ")) {
|
|
81
|
-
const newModel = input.slice(7).trim();
|
|
82
|
-
if (newModel) {
|
|
83
|
-
console.log(style.muted(`Modelo alterado para: ${style.code(newModel)}\n`));
|
|
84
|
-
}
|
|
85
|
-
rl.prompt();
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
messages.push({ role: "user", content: input });
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
const response = await chat(apiKey, messages, { model });
|
|
93
|
-
console.log(`\n${style.primary("Phantom:")} ${response.content}\n`);
|
|
94
|
-
messages.push({ role: "assistant", content: response.content });
|
|
95
|
-
|
|
96
|
-
if (sessionId) {
|
|
97
|
-
addMessage(sessionId, "user", input);
|
|
98
|
-
addMessage(sessionId, "assistant", response.content);
|
|
99
|
-
} else {
|
|
100
|
-
const session = createSession(model, input);
|
|
101
|
-
sessionId = session.id;
|
|
102
|
-
addMessage(sessionId, "user", input);
|
|
103
|
-
addMessage(sessionId, "assistant", response.content);
|
|
104
|
-
}
|
|
105
|
-
} catch (error: unknown) {
|
|
106
|
-
const err = error as { message?: string };
|
|
107
|
-
console.error(`\n${style.error(`✗ ${err.message || "Erro"}`)}\n`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
rl.prompt();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
rl.on("close", () => {
|
|
114
|
-
console.log(`\n${style.muted("Sessao encerrada")}`);
|
|
115
|
-
if (sessionId) {
|
|
116
|
-
console.log(style.muted(`ID da sessao: ${sessionId}`));
|
|
117
|
-
}
|
|
118
|
-
process.exit(0);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function printBanner(): void {
|
|
123
|
-
console.clear();
|
|
124
|
-
console.log(style.header("╔══════════════════════════════════════════════╗"));
|
|
125
|
-
console.log(style.header("║ PhantomCode - Modo Interativo ║"));
|
|
126
|
-
console.log(style.header("║ DogRouter AI Integration ║"));
|
|
127
|
-
console.log(style.header("╚══════════════════════════════════════════════╝"));
|
|
128
|
-
console.log(style.muted(" /help /exit /clear /new /model <nome>\n"));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function printHelp(): void {
|
|
132
|
-
console.log(style.header("\n┌─ Comandos Disponiveis ──────────────────────"));
|
|
133
|
-
console.log(` ${style.code("/exit")} ${style.muted("Sair do modo interativo")}`);
|
|
134
|
-
console.log(` ${style.code("/quit")} ${style.muted("Sair do modo interativo")}`);
|
|
135
|
-
console.log(` ${style.code("/clear")} ${style.muted("Limpar a tela")}`);
|
|
136
|
-
console.log(` ${style.code("/new")} ${style.muted("Iniciar nova conversa")}`);
|
|
137
|
-
console.log(` ${style.code("/model")} ${style.muted("Alterar o modelo (ex: /model dogrouter/auto)")}`);
|
|
138
|
-
console.log(` ${style.code("/help")} ${style.muted("Exibir esta ajuda")}`);
|
|
139
|
-
console.log(style.header("└───────────────────────────────────────────────┘\n"));
|
|
140
|
-
}
|
package/src/commands/models.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getApiKey } from "../config/manager";
|
|
2
|
-
import { listModels } from "../provider/dogrouter";
|
|
3
|
-
import { style } from "../tui/colors";
|
|
4
|
-
|
|
5
|
-
interface ModelsArgs {
|
|
6
|
-
search?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function handleModels(args: ModelsArgs): Promise<void> {
|
|
10
|
-
let apiKey: string;
|
|
11
|
-
try {
|
|
12
|
-
apiKey = getApiKey();
|
|
13
|
-
} catch {
|
|
14
|
-
console.error(style.error("✗ API key nao configurada"));
|
|
15
|
-
console.log(style.muted(" Execute: phantomcode config set <sua-api-key>"));
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const models = await listModels(apiKey);
|
|
21
|
-
|
|
22
|
-
const filtered = args.search
|
|
23
|
-
? models.filter((m) => m.id.toLowerCase().includes(args.search!.toLowerCase()))
|
|
24
|
-
: models;
|
|
25
|
-
|
|
26
|
-
if (filtered.length === 0) {
|
|
27
|
-
console.log(style.warning("Nenhum modelo encontrado"));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
console.log(style.header(`┌─ Modelos Disponiveis (${filtered.length}) ───────────`));
|
|
32
|
-
for (const m of filtered) {
|
|
33
|
-
console.log(`│ ${style.code(m.id)}`);
|
|
34
|
-
}
|
|
35
|
-
console.log(style.header("└───────────────────────────────────────────"));
|
|
36
|
-
} catch (error: unknown) {
|
|
37
|
-
const err = error as { message?: string };
|
|
38
|
-
console.error(style.error(`✗ Erro ao listar modelos: ${err.message || "Erro desconhecido"}`));
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
}
|