@fastino-ai/pioneer-cli 0.2.10 → 0.2.11

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/src/config.ts DELETED
@@ -1,225 +0,0 @@
1
- /**
2
- * Configuration management for Pioneer CLI.
3
- * Stores API key, base URL, and agent settings in ~/.pioneer/config.json
4
- */
5
-
6
- import fs from "fs";
7
- import os from "os";
8
- import path from "path";
9
-
10
- export interface TelemetryConfig {
11
- enabled?: boolean;
12
- anonymousId?: string;
13
- }
14
-
15
- export interface Config {
16
- // Pioneer API configuration
17
- apiKey?: string;
18
- baseUrl?: string;
19
-
20
- // MLE Agent model selection (for Pioneer server)
21
- mleModel?: string;
22
-
23
- // Hugging Face token for pushing datasets/models
24
- hfToken?: string;
25
-
26
- // Last agent conversation ID used for resuming chats
27
- lastAgentConversationId?: string;
28
-
29
- // Telemetry (opt-in analytics)
30
- telemetry?: TelemetryConfig;
31
-
32
- }
33
-
34
- const CONFIG_DIR = path.join(os.homedir(), ".pioneer");
35
- const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
36
-
37
- // Base URL from environment - defaults to production
38
- export const DEFAULT_BASE_URL = process.env.PIONEER_API_URL || "https://api.pioneer.ai";
39
-
40
- // WebSocket URL environments
41
- const WS_URLS: Record<string, string> = {
42
- local: "ws://localhost:5001/mle-agent/ws",
43
- dev: "wss://api-dev.pioneer.ai/mle-agent/ws",
44
- stg: "wss://api-stg.pioneer.ai/mle-agent/ws",
45
- prod: "wss://api.pioneer.ai/mle-agent/ws",
46
- };
47
-
48
- /**
49
- * Get WebSocket URL with priority:
50
- * 1. PIONEER_WS_URL environment variable (explicit override)
51
- * 2. PIONEER_ENV environment variable (local, dev, prod)
52
- * 3. Auto-detect from PIONEER_API_URL pattern
53
- * 4. Derive from PIONEER_API_URL (legacy behavior for local dev)
54
- */
55
- export function getWsUrl(): string {
56
- // Explicit WebSocket URL override
57
- if (process.env.PIONEER_WS_URL) {
58
- return process.env.PIONEER_WS_URL;
59
- }
60
-
61
- // Environment-based URL selection
62
- const env = process.env.PIONEER_ENV;
63
- if (env && WS_URLS[env]) {
64
- return WS_URLS[env];
65
- }
66
-
67
- // Auto-detect environment from REST API URL pattern
68
- const baseUrl = getBaseUrl();
69
- if (baseUrl.includes("execute-api") && baseUrl.includes("/dev")) {
70
- // Dev API Gateway detected - use dev WebSocket URL
71
- return WS_URLS.dev;
72
- }
73
- if (baseUrl.includes("api-dev.pioneer.ai")) {
74
- return WS_URLS.dev;
75
- }
76
- if (baseUrl.includes("api-stg.pioneer.ai")) {
77
- return WS_URLS.stg;
78
- }
79
- if (baseUrl === "https://api.pioneer.ai" || baseUrl === "https://api.pioneer.ai/") {
80
- // Production detected
81
- return WS_URLS.prod;
82
- }
83
-
84
- // Legacy: derive from REST API URL (for local development)
85
- const wsBase = baseUrl.replace(/^https:/, "wss:").replace(/^http:/, "ws:").replace(/\/$/, "");
86
- return `${wsBase}/mle-agent/ws`;
87
- }
88
-
89
- // Available MLE models for server-side agent
90
- export const AVAILABLE_MLE_MODELS = [
91
- { id: "claude-sonnet-4-5-20250929", name: "Claude Sonnet 4.5", description: "Balanced (default)" },
92
- { id: "claude-haiku-4-5-20251001", name: "Claude Haiku 4.5", description: "Fast & cheap" },
93
- { id: "claude-opus-4-5-20251101", name: "Claude Opus 4.5", description: "Most capable" },
94
- ] as const;
95
-
96
- export const DEFAULT_MLE_MODEL = "claude-sonnet-4-5-20250929";
97
-
98
- function ensureConfigDir(): void {
99
- if (!fs.existsSync(CONFIG_DIR)) {
100
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
101
- }
102
- }
103
-
104
- export function loadConfig(): Config {
105
- try {
106
- if (fs.existsSync(CONFIG_FILE)) {
107
- const raw = fs.readFileSync(CONFIG_FILE, "utf-8");
108
- return JSON.parse(raw) as Config;
109
- }
110
- } catch {
111
- // Ignore parse errors
112
- }
113
- return {};
114
- }
115
-
116
- export function saveConfig(config: Partial<Config>): void {
117
- ensureConfigDir();
118
- const existing = loadConfig();
119
- const merged = deepMerge(existing, config);
120
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(merged, null, 2));
121
- }
122
-
123
- function deepMerge(target: Config, source: Partial<Config>): Config {
124
- const result = { ...target };
125
- for (const key of Object.keys(source) as Array<keyof Config>) {
126
- const sourceValue = source[key];
127
- const targetValue = result[key];
128
- if (
129
- sourceValue !== null &&
130
- typeof sourceValue === "object" &&
131
- !Array.isArray(sourceValue) &&
132
- targetValue !== null &&
133
- typeof targetValue === "object" &&
134
- !Array.isArray(targetValue)
135
- ) {
136
- (result as Record<string, unknown>)[key] = {
137
- ...targetValue,
138
- ...sourceValue,
139
- };
140
- } else if (sourceValue !== undefined) {
141
- (result as Record<string, unknown>)[key] = sourceValue;
142
- }
143
- }
144
- return result;
145
- }
146
-
147
- export function clearApiKey(): void {
148
- const config = loadConfig();
149
- delete config.apiKey;
150
- ensureConfigDir();
151
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
152
- }
153
-
154
- export function getApiKey(): string | undefined {
155
- // Environment variable takes precedence
156
- if (process.env.PIONEER_API_KEY) {
157
- return process.env.PIONEER_API_KEY;
158
- }
159
- return loadConfig().apiKey;
160
- }
161
-
162
- export function getBaseUrl(): string {
163
- // Environment variable takes precedence (for internal testing)
164
- if (process.env.PIONEER_API_URL) {
165
- return process.env.PIONEER_API_URL;
166
- }
167
- // Config file takes second precedence
168
- const config = loadConfig();
169
- if (config.baseUrl) {
170
- return config.baseUrl;
171
- }
172
- // Default to production
173
- return DEFAULT_BASE_URL;
174
- }
175
-
176
- export function getLastAgentConversationId(): string | undefined {
177
- return loadConfig().lastAgentConversationId;
178
- }
179
-
180
- export function setLastAgentConversationId(conversationId?: string): void {
181
- if (!conversationId) {
182
- return;
183
- }
184
- saveConfig({ lastAgentConversationId: conversationId });
185
- }
186
-
187
- export function getMleModel(): string | undefined {
188
- return loadConfig().mleModel;
189
- }
190
-
191
- export function setMleModel(model: string): void {
192
- saveConfig({ mleModel: model });
193
- }
194
-
195
- export function getConfigDir(): string {
196
- ensureConfigDir();
197
- return CONFIG_DIR;
198
- }
199
-
200
- /**
201
- * Get Hugging Face token with priority:
202
- * 1. Explicit token passed as parameter (from --hf-token flag)
203
- * 2. HF_TOKEN environment variable
204
- * 3. Token stored in config file
205
- */
206
- export function getHfToken(explicitToken?: string): string | undefined {
207
- if (explicitToken) {
208
- return explicitToken;
209
- }
210
- if (process.env.HF_TOKEN) {
211
- return process.env.HF_TOKEN;
212
- }
213
- return loadConfig().hfToken;
214
- }
215
-
216
- export function setHfToken(token: string): void {
217
- saveConfig({ hfToken: token });
218
- }
219
-
220
- export function clearHfToken(): void {
221
- const config = loadConfig();
222
- delete config.hfToken;
223
- ensureConfigDir();
224
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
225
- }