@kaitranntt/ccs 7.9.0-dev.1 → 7.9.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/dist/cliproxy/index.d.ts +0 -2
- package/dist/cliproxy/index.d.ts.map +1 -1
- package/dist/cliproxy/index.js +1 -3
- package/dist/cliproxy/index.js.map +1 -1
- package/dist/cliproxy/stats-fetcher.d.ts +0 -4
- package/dist/cliproxy/stats-fetcher.d.ts.map +1 -1
- package/dist/cliproxy/stats-fetcher.js.map +1 -1
- package/dist/ui/assets/accounts-CZms_PBW.js +1 -0
- package/dist/ui/assets/{alert-dialog-zpnBn2CA.js → alert-dialog-sKmXLtjs.js} +1 -1
- package/dist/ui/assets/api-TANgowVA.js +1 -0
- package/dist/ui/assets/auth-section-Ddg5Cdd6.js +1 -0
- package/dist/ui/assets/{card-dTUi3LxW.js → card-CfgEo_Fi.js} +1 -1
- package/dist/ui/assets/cliproxy-BpCuX751.js +3 -0
- package/dist/ui/assets/cliproxy-control-panel-Cp0Tweyl.js +1 -0
- package/dist/ui/assets/{confirm-dialog-ByfOsjk9.js → confirm-dialog-Dut98zdb.js} +1 -1
- package/dist/ui/assets/{copilot-BQscualu.js → copilot-DvOZJmtw.js} +3 -3
- package/dist/ui/assets/globalenv-section-DlnizwvB.js +1 -0
- package/dist/ui/assets/{health-DTRd-dXk.js → health-D1M4owiM.js} +1 -1
- package/dist/ui/assets/icons-CMYcel9O.js +1 -0
- package/dist/ui/assets/index-BCBypoXT.js +1 -0
- package/dist/ui/assets/index-BXkzlgVE.js +1 -0
- package/dist/ui/assets/{index-Bfwze8tN.js → index-Bdp0Hpgh.js} +1 -1
- package/dist/ui/assets/index-D-LYJymx.js +47 -0
- package/dist/ui/assets/index-DQAJ1wqP.css +1 -0
- package/dist/ui/assets/{shared-BgDSyHKz.js → shared-Dgmje0CZ.js} +1 -1
- package/dist/ui/assets/{switch-B0PXGFIv.js → switch-MkSHHW1_.js} +1 -1
- package/dist/ui/index.html +3 -3
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.js +5 -89
- package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
- package/package.json +1 -1
- package/dist/cliproxy/quota-fetcher.d.ts +0 -46
- package/dist/cliproxy/quota-fetcher.d.ts.map +0 -1
- package/dist/cliproxy/quota-fetcher.js +0 -406
- package/dist/cliproxy/quota-fetcher.js.map +0 -1
- package/dist/ui/assets/accounts-CmzZXhfc.js +0 -1
- package/dist/ui/assets/api-DFbZVPK4.js +0 -1
- package/dist/ui/assets/auth-section-YgJ7Cv--.js +0 -1
- package/dist/ui/assets/cliproxy-CsqKCFzj.js +0 -3
- package/dist/ui/assets/cliproxy-control-panel-BRCh_7b3.js +0 -1
- package/dist/ui/assets/globalenv-section-BEpPTvKo.js +0 -1
- package/dist/ui/assets/icons-CwFZAiDB.js +0 -1
- package/dist/ui/assets/index-BLoAjpcw.js +0 -1
- package/dist/ui/assets/index-CEZrgkam.js +0 -1
- package/dist/ui/assets/index-QeBLfRj8.js +0 -47
- package/dist/ui/assets/index-oS2cgEFl.css +0 -1
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Quota Fetcher for Antigravity Accounts
|
|
4
|
-
*
|
|
5
|
-
* Fetches quota information from Google Cloud Code internal API.
|
|
6
|
-
* Used for displaying remaining quota percentages and reset times.
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.fetchAccountQuota = void 0;
|
|
33
|
-
const fs = __importStar(require("node:fs"));
|
|
34
|
-
const path = __importStar(require("node:path"));
|
|
35
|
-
const config_generator_1 = require("./config-generator");
|
|
36
|
-
/** Google Cloud Code API endpoints */
|
|
37
|
-
const ANTIGRAVITY_API_BASE = 'https://cloudcode-pa.googleapis.com';
|
|
38
|
-
const ANTIGRAVITY_API_VERSION = 'v1internal';
|
|
39
|
-
/** Google OAuth token endpoint */
|
|
40
|
-
const GOOGLE_TOKEN_URL = 'https://oauth2.googleapis.com/token';
|
|
41
|
-
/** Antigravity OAuth credentials (from CLIProxyAPIPlus - public in open-source code) */
|
|
42
|
-
const ANTIGRAVITY_CLIENT_ID = '1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com';
|
|
43
|
-
const ANTIGRAVITY_CLIENT_SECRET = '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';
|
|
44
|
-
/** Headers for loadCodeAssist (matches CLIProxyAPI antigravity.go) */
|
|
45
|
-
const LOADCODEASSIST_HEADERS = {
|
|
46
|
-
'Content-Type': 'application/json',
|
|
47
|
-
'User-Agent': 'google-api-nodejs-client/9.15.1',
|
|
48
|
-
'X-Goog-Api-Client': 'google-cloud-sdk vscode_cloudshelleditor/0.1',
|
|
49
|
-
'Client-Metadata': '{"ideType":"IDE_UNSPECIFIED","platform":"PLATFORM_UNSPECIFIED","pluginType":"GEMINI"}',
|
|
50
|
-
};
|
|
51
|
-
/** Headers for fetchAvailableModels (matches CLIProxyAPI antigravity_executor.go) */
|
|
52
|
-
const FETCHMODELS_HEADERS = {
|
|
53
|
-
'Content-Type': 'application/json',
|
|
54
|
-
'User-Agent': 'antigravity/1.104.0 darwin/arm64',
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Sanitize email to match CLIProxyAPI auth file naming convention
|
|
58
|
-
* Replaces @ and . with underscores (matches Go sanitizeAntigravityFileName)
|
|
59
|
-
*/
|
|
60
|
-
function sanitizeEmail(email) {
|
|
61
|
-
return email.replace(/@/g, '_').replace(/\./g, '_');
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Check if token is expired based on the expired timestamp
|
|
65
|
-
*/
|
|
66
|
-
function isTokenExpired(expiredStr) {
|
|
67
|
-
if (!expiredStr)
|
|
68
|
-
return false;
|
|
69
|
-
try {
|
|
70
|
-
const expiredDate = new Date(expiredStr);
|
|
71
|
-
return expiredDate.getTime() < Date.now();
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Refresh access token using refresh_token via Google OAuth
|
|
79
|
-
* This allows CCS to get fresh tokens independently of CLIProxyAPI
|
|
80
|
-
*/
|
|
81
|
-
async function refreshAccessToken(refreshToken) {
|
|
82
|
-
const controller = new AbortController();
|
|
83
|
-
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
84
|
-
try {
|
|
85
|
-
const response = await fetch(GOOGLE_TOKEN_URL, {
|
|
86
|
-
method: 'POST',
|
|
87
|
-
signal: controller.signal,
|
|
88
|
-
headers: {
|
|
89
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
90
|
-
},
|
|
91
|
-
body: new URLSearchParams({
|
|
92
|
-
grant_type: 'refresh_token',
|
|
93
|
-
refresh_token: refreshToken,
|
|
94
|
-
client_id: ANTIGRAVITY_CLIENT_ID,
|
|
95
|
-
client_secret: ANTIGRAVITY_CLIENT_SECRET,
|
|
96
|
-
}).toString(),
|
|
97
|
-
});
|
|
98
|
-
clearTimeout(timeoutId);
|
|
99
|
-
const data = (await response.json());
|
|
100
|
-
if (!response.ok || data.error) {
|
|
101
|
-
return {
|
|
102
|
-
accessToken: null,
|
|
103
|
-
error: data.error_description || data.error || `OAuth error: ${response.status}`,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (!data.access_token) {
|
|
107
|
-
return { accessToken: null, error: 'No access_token in response' };
|
|
108
|
-
}
|
|
109
|
-
return { accessToken: data.access_token };
|
|
110
|
-
}
|
|
111
|
-
catch (err) {
|
|
112
|
-
clearTimeout(timeoutId);
|
|
113
|
-
if (err instanceof Error && err.name === 'AbortError') {
|
|
114
|
-
return { accessToken: null, error: 'Token refresh timeout' };
|
|
115
|
-
}
|
|
116
|
-
return { accessToken: null, error: err instanceof Error ? err.message : 'Unknown error' };
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Read auth data from auth file (access token, project_id, expiry status)
|
|
121
|
-
*/
|
|
122
|
-
function readAuthData(provider, accountId) {
|
|
123
|
-
const authDir = (0, config_generator_1.getAuthDir)();
|
|
124
|
-
// Check if auth directory exists
|
|
125
|
-
if (!fs.existsSync(authDir)) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
// Sanitize accountId (email) to match auth file naming: @ and . → _
|
|
129
|
-
const sanitizedId = sanitizeEmail(accountId);
|
|
130
|
-
const prefix = provider === 'agy' ? 'antigravity-' : `${provider}-`;
|
|
131
|
-
const expectedFile = `${prefix}${sanitizedId}.json`;
|
|
132
|
-
const filePath = path.join(authDir, expectedFile);
|
|
133
|
-
// Direct file access (most common case)
|
|
134
|
-
if (fs.existsSync(filePath)) {
|
|
135
|
-
try {
|
|
136
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
137
|
-
const data = JSON.parse(content);
|
|
138
|
-
if (!data.access_token)
|
|
139
|
-
return null;
|
|
140
|
-
return {
|
|
141
|
-
accessToken: data.access_token,
|
|
142
|
-
refreshToken: data.refresh_token || null,
|
|
143
|
-
projectId: data.project_id || null,
|
|
144
|
-
isExpired: isTokenExpired(data.expired),
|
|
145
|
-
expiresAt: data.expired || null,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// Fallback: scan directory for matching email in file content
|
|
153
|
-
const files = fs.readdirSync(authDir);
|
|
154
|
-
for (const file of files) {
|
|
155
|
-
if (file.startsWith(prefix) && file.endsWith('.json')) {
|
|
156
|
-
const candidatePath = path.join(authDir, file);
|
|
157
|
-
try {
|
|
158
|
-
const content = fs.readFileSync(candidatePath, 'utf-8');
|
|
159
|
-
const data = JSON.parse(content);
|
|
160
|
-
// Match by email field inside the auth file
|
|
161
|
-
if (data.email === accountId && data.access_token) {
|
|
162
|
-
return {
|
|
163
|
-
accessToken: data.access_token,
|
|
164
|
-
refreshToken: data.refresh_token || null,
|
|
165
|
-
projectId: data.project_id || null,
|
|
166
|
-
isExpired: isTokenExpired(data.expired),
|
|
167
|
-
expiresAt: data.expired || null,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Get project ID via loadCodeAssist endpoint
|
|
180
|
-
*/
|
|
181
|
-
async function getProjectId(accessToken) {
|
|
182
|
-
const url = `${ANTIGRAVITY_API_BASE}/${ANTIGRAVITY_API_VERSION}:loadCodeAssist`;
|
|
183
|
-
const controller = new AbortController();
|
|
184
|
-
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
185
|
-
try {
|
|
186
|
-
const response = await fetch(url, {
|
|
187
|
-
method: 'POST',
|
|
188
|
-
signal: controller.signal,
|
|
189
|
-
headers: {
|
|
190
|
-
...LOADCODEASSIST_HEADERS,
|
|
191
|
-
Authorization: `Bearer ${accessToken}`,
|
|
192
|
-
},
|
|
193
|
-
body: JSON.stringify({
|
|
194
|
-
metadata: {
|
|
195
|
-
ideType: 'IDE_UNSPECIFIED',
|
|
196
|
-
platform: 'PLATFORM_UNSPECIFIED',
|
|
197
|
-
pluginType: 'GEMINI',
|
|
198
|
-
},
|
|
199
|
-
}),
|
|
200
|
-
});
|
|
201
|
-
clearTimeout(timeoutId);
|
|
202
|
-
if (!response.ok) {
|
|
203
|
-
// Return specific error based on status
|
|
204
|
-
if (response.status === 401) {
|
|
205
|
-
return { projectId: null, error: 'Token expired or invalid' };
|
|
206
|
-
}
|
|
207
|
-
if (response.status === 403) {
|
|
208
|
-
return { projectId: null, error: 'Access forbidden' };
|
|
209
|
-
}
|
|
210
|
-
return { projectId: null, error: `API error: ${response.status}` };
|
|
211
|
-
}
|
|
212
|
-
const data = (await response.json());
|
|
213
|
-
// Extract project ID from response
|
|
214
|
-
let projectId;
|
|
215
|
-
if (typeof data.cloudaicompanionProject === 'string') {
|
|
216
|
-
projectId = data.cloudaicompanionProject;
|
|
217
|
-
}
|
|
218
|
-
else if (typeof data.cloudaicompanionProject === 'object') {
|
|
219
|
-
projectId = data.cloudaicompanionProject?.id;
|
|
220
|
-
}
|
|
221
|
-
if (!projectId?.trim()) {
|
|
222
|
-
// Account authenticated but not provisioned - user needs to sign in via Antigravity app
|
|
223
|
-
return {
|
|
224
|
-
projectId: null,
|
|
225
|
-
error: 'Sign in to Antigravity app to activate quota.',
|
|
226
|
-
isUnprovisioned: true,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
return { projectId: projectId.trim() };
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
clearTimeout(timeoutId);
|
|
233
|
-
if (err instanceof Error && err.name === 'AbortError') {
|
|
234
|
-
return { projectId: null, error: 'Request timeout' };
|
|
235
|
-
}
|
|
236
|
-
return { projectId: null, error: err instanceof Error ? err.message : 'Unknown error' };
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Fetch available models with quota info
|
|
241
|
-
* Note: projectId is kept for potential future use but not sent in body
|
|
242
|
-
* (CLIProxyAPI sends empty {} body for this endpoint)
|
|
243
|
-
*/
|
|
244
|
-
async function fetchAvailableModels(accessToken, _projectId) {
|
|
245
|
-
const url = `${ANTIGRAVITY_API_BASE}/${ANTIGRAVITY_API_VERSION}:fetchAvailableModels`;
|
|
246
|
-
const controller = new AbortController();
|
|
247
|
-
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
248
|
-
try {
|
|
249
|
-
// Match CLIProxyAPI exactly: empty body, minimal headers
|
|
250
|
-
const response = await fetch(url, {
|
|
251
|
-
method: 'POST',
|
|
252
|
-
signal: controller.signal,
|
|
253
|
-
headers: {
|
|
254
|
-
...FETCHMODELS_HEADERS,
|
|
255
|
-
Authorization: `Bearer ${accessToken}`,
|
|
256
|
-
},
|
|
257
|
-
body: JSON.stringify({}),
|
|
258
|
-
});
|
|
259
|
-
clearTimeout(timeoutId);
|
|
260
|
-
if (response.status === 403) {
|
|
261
|
-
return {
|
|
262
|
-
success: false,
|
|
263
|
-
models: [],
|
|
264
|
-
lastUpdated: Date.now(),
|
|
265
|
-
isForbidden: true,
|
|
266
|
-
error: 'Quota access forbidden for this account',
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
if (response.status === 401) {
|
|
270
|
-
return {
|
|
271
|
-
success: false,
|
|
272
|
-
models: [],
|
|
273
|
-
lastUpdated: Date.now(),
|
|
274
|
-
error: 'Access token expired or invalid',
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
if (!response.ok) {
|
|
278
|
-
return {
|
|
279
|
-
success: false,
|
|
280
|
-
models: [],
|
|
281
|
-
lastUpdated: Date.now(),
|
|
282
|
-
error: `API error: ${response.status}`,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
const data = (await response.json());
|
|
286
|
-
const models = [];
|
|
287
|
-
if (data.models && typeof data.models === 'object') {
|
|
288
|
-
for (const [modelId, modelData] of Object.entries(data.models)) {
|
|
289
|
-
const quotaInfo = modelData.quotaInfo || modelData.quota_info;
|
|
290
|
-
if (!quotaInfo)
|
|
291
|
-
continue;
|
|
292
|
-
// Extract remaining fraction (0-1 range)
|
|
293
|
-
const remaining = quotaInfo.remainingFraction ?? quotaInfo.remaining_fraction ?? quotaInfo.remaining;
|
|
294
|
-
// Skip invalid values (NaN, Infinity, non-numbers)
|
|
295
|
-
if (typeof remaining !== 'number' || !isFinite(remaining))
|
|
296
|
-
continue;
|
|
297
|
-
// Convert to percentage (0-100) and clamp to valid range
|
|
298
|
-
const percentage = Math.max(0, Math.min(100, Math.round(remaining * 100)));
|
|
299
|
-
// Extract reset time
|
|
300
|
-
const resetTime = quotaInfo.resetTime || quotaInfo.reset_time || null;
|
|
301
|
-
models.push({
|
|
302
|
-
name: modelId,
|
|
303
|
-
displayName: modelData.displayName,
|
|
304
|
-
percentage,
|
|
305
|
-
resetTime,
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return {
|
|
310
|
-
success: true,
|
|
311
|
-
models,
|
|
312
|
-
lastUpdated: Date.now(),
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
catch (err) {
|
|
316
|
-
clearTimeout(timeoutId);
|
|
317
|
-
return {
|
|
318
|
-
success: false,
|
|
319
|
-
models: [],
|
|
320
|
-
lastUpdated: Date.now(),
|
|
321
|
-
error: err instanceof Error ? err.message : 'Unknown error',
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Fetch quota for an Antigravity account
|
|
327
|
-
*
|
|
328
|
-
* @param provider - Provider name (only 'agy' supported)
|
|
329
|
-
* @param accountId - Account identifier (email)
|
|
330
|
-
* @returns Quota result with models and percentages
|
|
331
|
-
*/
|
|
332
|
-
async function fetchAccountQuota(provider, accountId) {
|
|
333
|
-
// Only Antigravity supports quota fetching
|
|
334
|
-
if (provider !== 'agy') {
|
|
335
|
-
return {
|
|
336
|
-
success: false,
|
|
337
|
-
models: [],
|
|
338
|
-
lastUpdated: Date.now(),
|
|
339
|
-
error: `Quota not supported for provider: ${provider}`,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
// Read auth data from auth file
|
|
343
|
-
const authData = readAuthData(provider, accountId);
|
|
344
|
-
if (!authData) {
|
|
345
|
-
return {
|
|
346
|
-
success: false,
|
|
347
|
-
models: [],
|
|
348
|
-
lastUpdated: Date.now(),
|
|
349
|
-
error: 'Auth file not found for account',
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
// Determine which access token to use
|
|
353
|
-
// File-based token is often stale (CLIProxyAPIPlus refreshes at runtime but doesn't persist)
|
|
354
|
-
// Proactive refresh: refresh 5 minutes before expiry (matches CLIProxyAPIPlus behavior)
|
|
355
|
-
let accessToken = authData.accessToken;
|
|
356
|
-
const REFRESH_LEAD_TIME_MS = 5 * 60 * 1000; // 5 minutes
|
|
357
|
-
if (authData.refreshToken) {
|
|
358
|
-
const shouldRefresh = authData.isExpired || // Already expired
|
|
359
|
-
!authData.expiresAt || // No expiry info - refresh to be safe
|
|
360
|
-
new Date(authData.expiresAt).getTime() - Date.now() < REFRESH_LEAD_TIME_MS; // Expiring soon
|
|
361
|
-
if (shouldRefresh) {
|
|
362
|
-
const refreshResult = await refreshAccessToken(authData.refreshToken);
|
|
363
|
-
if (refreshResult.accessToken) {
|
|
364
|
-
accessToken = refreshResult.accessToken;
|
|
365
|
-
}
|
|
366
|
-
// If refresh fails, fall back to existing token (might still work)
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
// Get project ID - prefer stored value, fallback to API call
|
|
370
|
-
let projectId = authData.projectId;
|
|
371
|
-
if (!projectId) {
|
|
372
|
-
let lastProjectResult = await getProjectId(accessToken);
|
|
373
|
-
if (!lastProjectResult.projectId) {
|
|
374
|
-
// If project ID fetch fails, it might be token issue - try refresh if we haven't
|
|
375
|
-
if (authData.refreshToken && accessToken === authData.accessToken) {
|
|
376
|
-
const refreshResult = await refreshAccessToken(authData.refreshToken);
|
|
377
|
-
if (refreshResult.accessToken) {
|
|
378
|
-
accessToken = refreshResult.accessToken;
|
|
379
|
-
lastProjectResult = await getProjectId(accessToken);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
if (!lastProjectResult.projectId) {
|
|
383
|
-
return {
|
|
384
|
-
success: false,
|
|
385
|
-
models: [],
|
|
386
|
-
lastUpdated: Date.now(),
|
|
387
|
-
error: lastProjectResult.error || 'Failed to retrieve project ID',
|
|
388
|
-
isUnprovisioned: lastProjectResult.isUnprovisioned,
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
projectId = lastProjectResult.projectId;
|
|
393
|
-
}
|
|
394
|
-
// Fetch models with quota
|
|
395
|
-
const result = await fetchAvailableModels(accessToken, projectId);
|
|
396
|
-
// If quota fetch fails with auth error and we haven't refreshed yet, try refresh
|
|
397
|
-
if (!result.success && result.error?.includes('expired') && authData.refreshToken) {
|
|
398
|
-
const refreshResult = await refreshAccessToken(authData.refreshToken);
|
|
399
|
-
if (refreshResult.accessToken) {
|
|
400
|
-
return fetchAvailableModels(refreshResult.accessToken, projectId);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return result;
|
|
404
|
-
}
|
|
405
|
-
exports.fetchAccountQuota = fetchAccountQuota;
|
|
406
|
-
//# sourceMappingURL=quota-fetcher.js.map
|
|
@@ -1 +0,0 @@
|
|
|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AC;YAC9B,OAAO,oBAAoB,CAAC,aAAa,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AApFD,8CAoFC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as p}from"./react-vendor-B_CU-WTZ.js";import{a as D,u as b,b as N,d as A,f as y,g as T}from"./tanstack-Coed0rqz.js";import{c as m,ad as f,a as d,_ as k,$ as R,a0 as S,a1 as z,a2 as P,L as C,I as _}from"./index-QeBLfRj8.js";import{A as q,a as F,b as K,c as L,d as M,e as $,f as E,g as H}from"./alert-dialog-zpnBn2CA.js";import{t as u}from"./notifications-dJQY2-U6.js";import{R as O,j,a9 as Q,t as I,l as v,O as B}from"./icons-CwFZAiDB.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function U({className:t,...s}){return e.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:e.jsx("table",{"data-slot":"table",className:m("w-full caption-bottom text-sm",t),...s})})}function V({className:t,...s}){return e.jsx("thead",{"data-slot":"table-header",className:m("[&_tr]:border-b",t),...s})}function Z({className:t,...s}){return e.jsx("tbody",{"data-slot":"table-body",className:m("[&_tr:last-child]:border-0",t),...s})}function w({className:t,...s}){return e.jsx("tr",{"data-slot":"table-row",className:m("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",t),...s})}function G({className:t,...s}){return e.jsx("th",{"data-slot":"table-head",className:m("text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",t),...s})}function J({className:t,...s}){return e.jsx("td",{"data-slot":"table-cell",className:m("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",t),...s})}function W(){return D({queryKey:["accounts"],queryFn:()=>f.accounts.list()})}function X(){const t=b();return N({mutationFn:s=>f.accounts.setDefault(s),onSuccess:(s,l)=>{t.invalidateQueries({queryKey:["accounts"]}),u.success(`Default account set to "${l}"`)},onError:s=>{u.error(s.message)}})}function Y(){const t=b();return N({mutationFn:()=>f.accounts.resetDefault(),onSuccess:()=>{t.invalidateQueries({queryKey:["accounts"]}),u.success("Default account reset to CCS")},onError:s=>{u.error(s.message)}})}function ee(){const t=b();return N({mutationFn:s=>f.accounts.delete(s),onSuccess:(s,l)=>{t.invalidateQueries({queryKey:["accounts"]}),u.success(`Account "${l}" deleted`)},onError:s=>{u.error(s.message)}})}function se({data:t,defaultAccount:s}){const l=X(),i=ee(),r=Y(),[c,o]=p.useState(null),x=A({data:t,columns:[{accessorKey:"name",header:"Name",size:200,cell:({row:a})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:a.original.name}),a.original.name===s&&e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-1.5 py-0.5 rounded border border-primary/20",children:"default"})]})},{accessorKey:"type",header:"Type",size:100,cell:({row:a})=>e.jsx("span",{className:"capitalize text-muted-foreground",children:a.original.type||"oauth"})},{accessorKey:"created",header:"Created",size:150,cell:({row:a})=>{const n=new Date(a.original.created);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{accessorKey:"last_used",header:"Last Used",size:150,cell:({row:a})=>{if(!a.original.last_used)return e.jsx("span",{className:"text-muted-foreground/50",children:"-"});const n=new Date(a.original.last_used);return e.jsx("span",{className:"text-muted-foreground",children:n.toLocaleDateString()})}},{id:"actions",header:"Actions",size:180,cell:({row:a})=>{const n=a.original.name===s,h=l.isPending||i.isPending;return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(d,{variant:n?"secondary":"default",size:"sm",className:"h-8 px-2",disabled:n||h,onClick:()=>l.mutate(a.original.name),children:[e.jsx(j,{className:`w-3 h-3 mr-1 ${n?"opacity-50":""}`}),n?"Active":"Set Default"]}),e.jsx(d,{variant:"ghost",size:"sm",className:"h-8 px-2 text-destructive hover:text-destructive hover:bg-destructive/10",disabled:n||h,onClick:()=>o(a.original.name),title:n?"Cannot delete default account":"Delete account",children:e.jsx(Q,{className:"w-4 h-4"})})]})}}],getCoreRowModel:T()});return t.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:["No accounts found. Use"," ",e.jsx("code",{className:"text-sm bg-muted px-1 rounded",children:"ccs auth create"})," to add accounts."]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"border rounded-md",children:e.jsxs(U,{children:[e.jsx(V,{children:x.getHeaderGroups().map(a=>e.jsx(w,{children:a.headers.map(n=>{const h={name:"w-[200px]",type:"w-[100px]",created:"w-[150px]",last_used:"w-[150px]",actions:"w-[180px]"}[n.id]||"w-auto";return e.jsx(G,{className:h,children:n.isPlaceholder?null:y(n.column.columnDef.header,n.getContext())},n.id)})},a.id))}),e.jsx(Z,{children:x.getRowModel().rows.map(a=>e.jsx(w,{children:a.getVisibleCells().map(n=>e.jsx(J,{children:y(n.column.columnDef.cell,n.getContext())},n.id))},a.id))})]})}),s&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(d,{variant:"outline",size:"sm",onClick:()=>r.mutate(),disabled:r.isPending,children:[e.jsx(O,{className:"w-4 h-4 mr-2"}),"Reset to CCS Default"]})})]}),e.jsx(q,{open:!!c,onOpenChange:a=>!a&&o(null),children:e.jsxs(F,{children:[e.jsxs(K,{children:[e.jsx(L,{children:"Delete Account"}),e.jsxs(M,{children:['Are you sure you want to delete the account "',c,'"? This will remove the profile and all its session data. This action cannot be undone.']})]}),e.jsxs($,{children:[e.jsx(E,{children:"Cancel"}),e.jsx(H,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{c&&(i.mutate(c),o(null))},children:"Delete"})]})]})})]})}function te({open:t,onClose:s}){const[l,i]=p.useState(""),[r,c]=p.useState(!1),o=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(l),g=l?`ccs auth create ${l}`:"ccs auth create <name>",x=async()=>{o&&(await navigator.clipboard.writeText(g),c(!0),setTimeout(()=>c(!1),2e3))},a=()=>{i(""),c(!1),s()};return e.jsx(k,{open:t,onOpenChange:n=>!n&&a(),children:e.jsxs(R,{className:"sm:max-w-md",children:[e.jsxs(S,{children:[e.jsx(z,{children:"Create New Account"}),e.jsx(P,{children:"Auth profiles require Claude CLI login. Run the command below in your terminal."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"profile-name",children:"Profile Name"}),e.jsx(_,{id:"profile-name",value:l,onChange:n=>i(n.target.value),placeholder:"e.g., work, personal, client",autoComplete:"off"}),l&&!o&&e.jsx("p",{className:"text-xs text-destructive",children:"Name must start with a letter and contain only letters, numbers, dashes, or underscores."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{children:"Command"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-md font-mono text-sm",children:[e.jsx(I,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("code",{className:"flex-1 break-all",children:g}),e.jsx(d,{variant:"ghost",size:"sm",className:"shrink-0 h-8 px-2",onClick:x,disabled:!o,children:r?e.jsx(j,{className:"w-4 h-4 text-green-500"}):e.jsx(v,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("p",{children:"After running the command:"}),e.jsxs("ol",{className:"list-decimal list-inside pl-2 space-y-0.5",children:[e.jsx("li",{children:"Complete the Claude login in your browser"}),e.jsx("li",{children:"Return here and refresh to see the new account"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(d,{variant:"ghost",onClick:a,children:"Close"}),e.jsx(d,{onClick:x,disabled:!o,children:r?e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"w-4 h-4 mr-2"}),"Copied!"]}):e.jsxs(e.Fragment,{children:[e.jsx(v,{className:"w-4 h-4 mr-2"}),"Copy Command"]})})]})]})]})})}function xe(){const{data:t,isLoading:s,refetch:l}=W(),[i,r]=p.useState(!1);return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Accounts"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage multi-account Claude sessions (profiles.json)"})]}),e.jsxs(d,{onClick:()=>r(!0),children:[e.jsx(B,{className:"w-4 h-4 mr-2"}),"Create Account"]})]}),s?e.jsx("div",{className:"text-muted-foreground",children:"Loading accounts..."}):e.jsx(se,{data:t?.accounts||[],defaultAccount:t?.default??null,onRefresh:l}),e.jsx(te,{open:i,onClose:()=>r(!1)})]})}export{xe as AccountsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as c}from"./react-vendor-B_CU-WTZ.js";import{B as S,c as E,T as je,k as Ne,l as ve,a as g,I as C,i as I,L as T,m as M,n as ne,o as be,s as we,p as Ce,q as ye,S as W,r as L,t as $,v as re,w as Oe,x as Ae,y as le,z as ie,A as ce,D as Ee,E as Te,F as X,G as Z,R as ke,H as q,J as _e,K as Se,M as Pe,N as Re}from"./index-QeBLfRj8.js";import{u as Le,a as Me,b as De}from"./tanstack-Coed0rqz.js";import{C as B,S as ee}from"./confirm-dialog-ByfOsjk9.js";import{t as Q}from"./notifications-dJQY2-U6.js";import{a0 as U,a9 as oe,L as G,aa as Ie,E as Ue,d as He,O as D,I as Fe,ab as de,Q as V,b as xe,ac as ze,N as Ke,ad as Je,m as me,X as $e,Z as ue,ae as Be,_ as Qe,V as he,af as qe,n as fe}from"./icons-CwFZAiDB.js";import{C as Ge,b as Ve,c as Ye,d as We,a as Xe}from"./card-dTUi3LxW.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";import"./alert-dialog-zpnBn2CA.js";function Ze({className:s,showTooltip:t=!0}){const l=e.jsxs(S,{variant:"outline",className:E("bg-accent/10 border-accent/30 text-accent","dark:bg-accent/20 dark:border-accent/40 dark:text-accent-foreground",s),children:[e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"mr-1 h-3 w-3"}),"OpenRouter"]});return t?e.jsxs(je,{children:[e.jsx(Ne,{asChild:!0,children:l}),e.jsx(ve,{children:e.jsx("p",{children:"Access 349+ models via OpenRouter"})})]}):l}function se(s){return[/^ANTHROPIC_AUTH_TOKEN$/,/_API_KEY$/,/_AUTH_TOKEN$/,/^API_KEY$/,/^AUTH_TOKEN$/,/_SECRET$/,/^SECRET$/].some(l=>l.test(s))}function pe(s){return s?.env?(s.env.ANTHROPIC_BASE_URL||"").toLowerCase().includes("openrouter.ai"):!1}function es(s){return{opus:s.ANTHROPIC_DEFAULT_OPUS_MODEL||void 0,sonnet:s.ANTHROPIC_DEFAULT_SONNET_MODEL||void 0,haiku:s.ANTHROPIC_DEFAULT_HAIKU_MODEL||void 0}}function ss(s,t){const l={...s};return t.opus?l.ANTHROPIC_DEFAULT_OPUS_MODEL=t.opus:delete l.ANTHROPIC_DEFAULT_OPUS_MODEL,t.sonnet?l.ANTHROPIC_DEFAULT_SONNET_MODEL=t.sonnet:delete l.ANTHROPIC_DEFAULT_SONNET_MODEL,t.haiku?l.ANTHROPIC_DEFAULT_HAIKU_MODEL=t.haiku:delete l.ANTHROPIC_DEFAULT_HAIKU_MODEL,l}function ts({profileName:s,data:t,settings:l,isLoading:i,isSaving:d,hasChanges:h,isRawJsonValid:x,onRefresh:n,onDelete:o,onSave:m}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s}),t?.path&&e.jsx(S,{variant:"outline",className:"text-xs",children:t.path.replace(/^.*\//,"")}),pe(l)&&e.jsx(Ze,{className:"ml-1"})]}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified: ",new Date(t.mtime).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{variant:"ghost",size:"sm",onClick:n,disabled:i,children:e.jsx(U,{className:`w-4 h-4 ${i?"animate-spin":""}`})}),o&&e.jsx(g,{variant:"ghost",size:"sm",onClick:o,children:e.jsx(oe,{className:"w-4 h-4 text-destructive"})}),e.jsx(g,{size:"sm",onClick:m,disabled:d||!h||!x,children:d?e.jsxs(e.Fragment,{children:[e.jsx(G,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}function ge({label:s,...t}){const[l,i]=c.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[s&&e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"relative",children:[e.jsx(C,{type:l?"text":"password",className:"pr-10 font-mono",...t}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3",onClick:()=>i(!l),tabIndex:-1,children:l?e.jsx(Ue,{className:"w-4 h-4"}):e.jsx(He,{className:"w-4 h-4"})})]})]})}function as({currentSettings:s,newEnvKey:t,newEnvValue:l,onNewEnvKeyChange:i,onNewEnvValueChange:d,onEnvValueChange:h,onAddEnvVar:x}){return e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-4",children:s?.env&&Object.keys(s.env).length>0?e.jsx(e.Fragment,{children:Object.entries(s.env).map(([n,o])=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(T,{className:"text-xs font-medium flex items-center gap-2 text-muted-foreground",children:[n,se(n)&&e.jsx(S,{variant:"secondary",className:"text-[10px] px-1 py-0 h-4",children:"sensitive"})]}),se(n)?e.jsx(ge,{value:o,onChange:m=>h(n,m.target.value),className:"font-mono text-sm h-8"}):e.jsx(C,{value:o,onChange:m=>h(n,m.target.value),className:"font-mono text-sm h-8"})]},n))}):e.jsxs("div",{className:"py-8 text-center text-muted-foreground bg-muted/30 rounded-lg border border-dashed text-sm",children:[e.jsx("p",{children:"No environment variables configured."}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:"Add variables using the input below or edit the JSON directly."})]})})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(C,{placeholder:"VARIABLE_NAME",value:t,onChange:n=>i(n.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(C,{placeholder:"value",value:l,onChange:n=>d(n.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:n=>n.key==="Enter"&&t.trim()&&x()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:x,disabled:!t.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]})}function ns({profileName:s,data:t}){return e.jsx(I,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(Fe,{className:"w-4 h-4"}),"Profile Information"]}),e.jsx("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Profile Name"}),e.jsx("span",{className:"font-mono",children:t.profile})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:t.path}),e.jsx(M,{value:t.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Last Modified"}),e.jsx("span",{className:"text-xs",children:new Date(t.mtime).toLocaleString()})]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"Run with profile"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs ",s,' "prompt"']}),e.jsx(M,{value:`ccs ${s} "prompt"`,size:"icon",className:"h-6 w-6"})]})]}),e.jsxs("div",{children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:"Set as default"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsxs("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:["ccs default ",s]}),e.jsx(M,{value:`ccs default ${s}`,size:"icon",className:"h-6 w-6"})]})]})]})]})]})})}function rs({value:s,onChange:t,placeholder:l="Search models...",className:i}){const[d,h]=c.useState(""),[x,n]=c.useState(null),{models:o,isLoading:m,isError:j,isFetching:y}=ne(),O=be(),N=c.useMemo(()=>we(o,d,{category:x??void 0}),[o,d,x]),b=c.useMemo(()=>Ce(o,2),[o]),_=!d.trim()&&!x,k=c.useMemo(()=>{const r={anthropic:[],openai:[],google:[],meta:[],mistral:[],opensource:[],other:[]};N.forEach(a=>{r[a.category].push(a)});for(const a of Object.keys(r))r[a]=ye(r[a]);return r},[N]),w=c.useCallback(()=>{O()},[O]),p=o.find(r=>r.id===s);return m&&o.length===0?e.jsxs("div",{className:E("space-y-2",i),children:[e.jsx(W,{className:"h-10 w-full"}),e.jsx(W,{className:"h-32 w-full"})]}):e.jsxs("div",{className:E("space-y-2 w-full min-w-0 overflow-hidden",i),children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(de,{className:"text-muted-foreground absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2"}),e.jsx(C,{value:d,onChange:r=>h(r.target.value),placeholder:l,className:"pl-9"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:w,disabled:y,title:"Refresh models",children:y?e.jsx(G,{className:"h-4 w-4 animate-spin"}):e.jsx(U,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs(S,{variant:x===null?"default":"outline",className:"cursor-pointer",onClick:()=>n(null),children:["All (",o.length,")"]}),Object.keys(L).map(r=>{const a=k[r].length;return a===0?null:e.jsxs(S,{variant:x===r?"default":"outline",className:"cursor-pointer",onClick:()=>n(r),children:[L[r]," (",a,")"]},r)})]}),p&&e.jsxs("div",{className:"bg-muted rounded-md p-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:p.name}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:[$(p.pricing)," |"," ",re(p.context_length)]})]}),e.jsx(I,{className:"h-72 w-full rounded-md border",children:j?e.jsxs("div",{className:"text-destructive p-4 text-center",children:["Failed to load models."," ",e.jsx(g,{variant:"link",onClick:w,children:"Retry"})]}):N.length===0?e.jsxs("div",{className:"text-muted-foreground p-4 text-center",children:['No models found matching "',d,'"']}):e.jsxs("div",{className:"space-y-6 p-3",children:[_&&b.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 flex items-center gap-1.5 py-1.5 text-xs font-semibold border-b pb-2",children:[e.jsx(V,{className:"h-3 w-3 text-accent"}),e.jsx("span",{children:"Newest Models"})]}),e.jsx("div",{className:"space-y-1",children:b.map(r=>e.jsx(te,{model:r,isSelected:r.id===s,onClick:()=>t(r.id),showAge:!0},r.id))})]}),Object.keys(L).map(r=>{const a=k[r];return a.length===0?null:e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground bg-background sticky top-0 mb-2 py-1.5 text-xs font-semibold border-b pb-2",children:L[r]}),e.jsx("div",{className:"space-y-1",children:a.map(v=>e.jsx(te,{model:v,isSelected:v.id===s,onClick:()=>t(v.id)},v.id))})]},r)})]})})]})}function te({model:s,isSelected:t,onClick:l,showAge:i=!1}){return e.jsxs("button",{type:"button",onClick:l,className:E("group flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors","hover:bg-accent hover:text-accent-foreground",t&&"bg-accent text-accent-foreground"),children:[e.jsx("span",{className:"flex-1 min-w-0 truncate font-medium",children:s.name}),e.jsxs("span",{className:E("flex shrink-0 items-center gap-1 text-xs whitespace-nowrap",t?"text-accent-foreground/80":"text-muted-foreground group-hover:text-accent-foreground/80"),children:[i&&s.created&&e.jsx(S,{variant:"outline",className:E("text-[10px] px-1",t?"border-accent-foreground/30 text-accent-foreground/80":"text-accent border-accent/30 group-hover:text-accent-foreground/80 group-hover:border-accent-foreground/30"),children:Oe(s.created)}),s.isFree?e.jsx(S,{variant:"secondary",className:E("text-[10px] px-1",t?"bg-accent-foreground/20 text-accent-foreground":"group-hover:bg-accent-foreground/20 group-hover:text-accent-foreground"),children:"Free"}):s.isExacto?e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",className:E("text-[10px] px-1 border-emerald-500/50 text-emerald-600",t?"border-accent-foreground/30 text-accent-foreground/80":"group-hover:border-accent-foreground/30 group-hover:text-accent-foreground/80"),children:"Exacto"}),e.jsx("span",{className:"tabular-nums",children:$(s.pricing)})]}):e.jsx("span",{className:"tabular-nums",children:$(s.pricing)}),e.jsx("span",{className:"tabular-nums",children:re(s.context_length)})]})]})}function ls({selectedModel:s,value:t,onChange:l,className:i}){const{models:d}=ne(),h=c.useMemo(()=>s?Ae(s,d):{},[s,d]),x=()=>{l(h)},n=(m,j)=>{l({...t,[m]:j||void 0})},o=s&&Object.keys(h).length>0;return e.jsxs(le,{className:E("group",i),children:[e.jsxs(ie,{className:"flex items-center gap-2 text-sm font-medium hover:underline",children:[e.jsx(xe,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-90"}),"Model Tier Mapping",e.jsx("span",{className:"text-muted-foreground font-normal",children:"(Advanced)"})]}),e.jsxs(ce,{className:"space-y-3 pt-3",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Configure different models for Claude Code's opus/sonnet/haiku tiers."}),o&&e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:x,children:[e.jsx(ze,{className:"mr-1 h-4 w-4"}),"Auto-suggest based on ",s?.split("/")[0]]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-opus",className:"text-right",children:"Opus"}),e.jsx(C,{id:"tier-opus",value:t.opus??"",onChange:m=>n("opus",m.target.value),placeholder:"e.g., anthropic/claude-opus-4"})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-sonnet",className:"text-right",children:"Sonnet"}),e.jsx(C,{id:"tier-sonnet",value:t.sonnet??"",onChange:m=>n("sonnet",m.target.value),placeholder:"e.g., anthropic/claude-sonnet-4"})]}),e.jsxs("div",{className:"grid grid-cols-[80px_1fr] items-center gap-2",children:[e.jsx(T,{htmlFor:"tier-haiku",className:"text-right",children:"Haiku"}),e.jsx(C,{id:"tier-haiku",value:t.haiku??"",onChange:m=>n("haiku",m.target.value),placeholder:"e.g., anthropic/claude-3.5-haiku"})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:"These set ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL."})]})]})}function is({profileName:s,data:t,currentSettings:l,newEnvKey:i,newEnvValue:d,onNewEnvKeyChange:h,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o,onEnvBulkChange:m}){const j=pe(l),y=l?.env,O=c.useMemo(()=>es(y??{}),[y]),N=y??{},b=a=>{if(m){const v={...N,ANTHROPIC_MODEL:a,ANTHROPIC_DEFAULT_OPUS_MODEL:a,ANTHROPIC_DEFAULT_SONNET_MODEL:a,ANTHROPIC_DEFAULT_HAIKU_MODEL:a};m(v)}else n("ANTHROPIC_MODEL",a),n("ANTHROPIC_DEFAULT_OPUS_MODEL",a),n("ANTHROPIC_DEFAULT_SONNET_MODEL",a),n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a);Q.success("Applied model to all tiers",{duration:2e3})},_=a=>{if(m){const v=ss(N,a);m(v)}else a.opus!==void 0&&n("ANTHROPIC_DEFAULT_OPUS_MODEL",a.opus||""),a.sonnet!==void 0&&n("ANTHROPIC_DEFAULT_SONNET_MODEL",a.sonnet||""),a.haiku!==void 0&&n("ANTHROPIC_DEFAULT_HAIKU_MODEL",a.haiku||"")},[k,w]=c.useState(!1),p=new Set(["ANTHROPIC_AUTH_TOKEN"]),r=Object.entries(N).filter(([a])=>!p.has(a));return e.jsx("div",{className:"h-full w-full min-w-0 flex flex-col",children:e.jsxs(Ee,{defaultValue:"env",className:"h-full w-full min-w-0 flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Te,{className:"w-full",children:[e.jsx(X,{value:"env",className:"flex-1",children:j?"Configuration":"Environment Variables"}),e.jsx(X,{value:"info",className:"flex-1",children:"Info & Usage"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col min-w-0",children:[e.jsx(Z,{value:"env",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden min-w-0",children:j?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsxs("div",{className:"h-full overflow-y-auto overflow-x-hidden p-4 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{className:"text-sm font-medium",children:"Model Selection"}),e.jsx(rs,{value:N.ANTHROPIC_MODEL,onChange:b,placeholder:"Search OpenRouter models..."})]}),e.jsx(ls,{selectedModel:N.ANTHROPIC_MODEL,value:O,onChange:_}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{className:"text-sm font-medium",children:"API Key"}),e.jsx(ge,{value:N.ANTHROPIC_AUTH_TOKEN||"",onChange:a=>n("ANTHROPIC_AUTH_TOKEN",a.target.value),placeholder:"sk-or-v1-...",className:"font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your API key from"," ",e.jsx("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"openrouter.ai/keys"})]})]}),r.length>0&&e.jsxs(le,{open:k,onOpenChange:w,children:[e.jsxs(ie,{className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors group",children:[e.jsx(xe,{className:E("h-4 w-4 transition-transform",k&&"rotate-90")}),e.jsx(Ke,{className:"h-4 w-4"}),e.jsx("span",{children:"Additional Variables"}),e.jsxs("span",{className:"text-xs font-normal opacity-70",children:["(",r.length,")"]})]}),e.jsx(ce,{className:"pt-4",children:e.jsx("div",{className:"space-y-3 border rounded-lg p-3 bg-muted/30",children:r.map(([a,v])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(T,{className:"text-xs text-muted-foreground",children:a}),e.jsx(C,{value:v,onChange:P=>n(a,P.target.value),className:"font-mono text-xs h-8"})]},a))})})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background shrink-0",children:[e.jsx(T,{className:"text-xs font-medium text-muted-foreground",children:"Add Environment Variable"}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(C,{placeholder:"VARIABLE_NAME",value:i,onChange:a=>h(a.target.value.toUpperCase()),className:"font-mono text-sm h-8 w-2/5",onKeyDown:a=>a.key==="Enter"&&i.trim()&&o()}),e.jsx(C,{placeholder:"value",value:d,onChange:a=>x(a.target.value),className:"font-mono text-sm h-8 flex-1",onKeyDown:a=>a.key==="Enter"&&i.trim()&&o()}),e.jsx(g,{variant:"outline",size:"sm",className:"h-8",onClick:o,disabled:!i.trim(),children:e.jsx(D,{className:"w-4 h-4"})})]})]})]}):e.jsx(as,{currentSettings:l,newEnvKey:i,newEnvValue:d,onNewEnvKeyChange:h,onNewEnvValueChange:x,onEnvValueChange:n,onAddEnvVar:o})}),e.jsx(Z,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(ns,{profileName:s,data:t})})]})]})})}function cs({profileName:s,onDelete:t,onHasChangesUpdate:l}){const[i,d]=c.useState({}),[h,x]=c.useState(!1),[n,o]=c.useState(null),[m,j]=c.useState(""),[y,O]=c.useState(""),N=Le(),{data:b,isLoading:_,isError:k,refetch:w}=Me({queryKey:["settings",s],queryFn:async()=>{const f=await fetch(`/api/settings/${s}/raw`);if(!f.ok)throw new Error(`Failed to load settings: ${f.status}`);return f.json()}}),p=b?.settings,r=c.useMemo(()=>{if(n!==null)try{return JSON.parse(n)}catch{}if(p)return{...p,env:{...p.env,...i}}},[p,i,n]),a=c.useMemo(()=>n!==null?n:p?JSON.stringify(p,null,2):"",[n,p]),v=c.useCallback(f=>{o(f)},[]),P=(f,A)=>{const R={...r?.env||{},[f]:A};d(J=>({...J,[f]:A})),o(JSON.stringify({...r,env:R},null,2))},H=f=>{const A={...r?.env||{},...f};d(R=>({...R,...f})),o(JSON.stringify({...r,env:A},null,2))},F=()=>{if(!m.trim())return;const f=m.trim(),A=y,R={...r?.env||{},[f]:A};d(J=>({...J,[f]:A})),o(JSON.stringify({...r,env:R},null,2)),j(""),O("")},u=c.useMemo(()=>{try{return JSON.parse(a),!0}catch{return!1}},[a]),z=c.useMemo(()=>n!==null?n!==JSON.stringify(p,null,2):Object.keys(i).length>0,[n,i,p]);c.useEffect(()=>{l?.(z)},[z,l]);const K=De({mutationFn:async()=>{let f;try{f=JSON.parse(a)}catch{f={...b?.settings,env:{...b?.settings?.env,...i}}}const A=await fetch(`/api/settings/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:f,expectedMtime:b?.mtime})});if(A.status===409)throw new Error("CONFLICT");if(!A.ok)throw new Error("Failed to save");return A.json()},onSuccess:()=>{N.invalidateQueries({queryKey:["settings",s]}),N.invalidateQueries({queryKey:["profiles"]}),d({}),o(null),Q.success("Settings saved")},onError:f=>{f.message==="CONFLICT"?x(!0):Q.error(f.message)}}),Y=async f=>{x(!1),f?(await w(),K.mutate()):(d({}),o(null))};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(ts,{profileName:s,data:b,settings:r,isLoading:_,isSaving:K.isPending,hasChanges:z,isRawJsonValid:u,onRefresh:()=>w(),onDelete:t,onSave:()=>K.mutate()}),_?e.jsxs("div",{className:"flex-1 flex items-center justify-center",children:[e.jsx(G,{className:"w-8 h-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground",children:"Loading settings..."})]}):k?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load settings."}),e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>w(),children:[e.jsx(U,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):e.jsxs("div",{className:"flex-1 grid grid-cols-[40%_60%] divide-x overflow-hidden",children:[e.jsx("div",{className:"flex flex-col overflow-hidden bg-muted/5 min-w-0",children:e.jsx(is,{profileName:s,data:b,currentSettings:r,newEnvKey:m,newEnvValue:y,onNewEnvKeyChange:j,onNewEnvValueChange:O,onEnvValueChange:P,onEnvBulkChange:H,onAddEnvVar:F})}),e.jsxs("div",{className:"flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx(Je,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(ke,{rawJsonContent:a,isRawJsonValid:u,rawJsonEdits:n,settings:p,onChange:v})]})]}),e.jsx(B,{open:h,title:"File Modified Externally",description:"Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>Y(!0),onCancel:()=>Y(!1)})]},s)}const ae="ccs:openrouter-banner-dismissed";function os({onCreateClick:s}){const[t,l]=c.useState(!0),{modelCount:i,isLoading:d}=q();c.useEffect(()=>{const x=localStorage.getItem(ae)==="true";l(x)},[]);const h=()=>{localStorage.setItem(ae,"true"),l(!0)};return t?null:e.jsx("div",{className:"bg-gradient-to-r from-accent to-accent/90 text-white px-4 py-3 relative shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 max-w-screen-xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"p-1.5 bg-white/20 rounded-md shrink-0",children:e.jsx(V,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:"NEW: OpenRouter Integration"}),e.jsxs("p",{className:"text-xs text-white/80 truncate",children:["Browse ",d?"300+":`${i}+`," models from OpenAI, Anthropic, Google, Meta and more."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s&&e.jsx(g,{size:"sm",variant:"secondary",onClick:s,className:"bg-white text-accent hover:bg-white/90 h-8",children:"Try it now"}),e.jsxs("a",{href:"https://openrouter.ai",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-white/80 hover:text-white hidden sm:flex items-center gap-1",children:["Learn more",e.jsx(me,{className:"w-3 h-3"})]}),e.jsxs(g,{size:"icon",variant:"ghost",onClick:h,className:"h-7 w-7 text-white/70 hover:text-white hover:bg-white/20",children:[e.jsx($e,{className:"w-4 h-4"}),e.jsx("span",{className:"sr-only",children:"Dismiss"})]})]})]})})}function ds({onOpenRouterClick:s,onCustomClick:t}){const{modelCount:l,isLoading:i}=q();return e.jsx("div",{className:"flex-1 flex items-center justify-center bg-muted/20 p-8",children:e.jsxs("div",{className:"max-w-lg w-full space-y-6",children:[e.jsxs(Ge,{className:"border-accent/30 dark:border-accent/40 bg-gradient-to-br from-accent/5 to-background dark:from-accent/10",children:[e.jsxs(Ve,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-lg bg-accent/10 dark:bg-accent/20",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"OpenRouter",className:"w-6 h-6"})}),e.jsx(S,{variant:"secondary",className:"bg-accent/10 text-accent dark:bg-accent/20 dark:text-accent-foreground",children:"Recommended"})]}),e.jsx(Ye,{className:"text-xl",children:"Start with OpenRouter"}),e.jsxs(We,{className:"text-base",children:["Access ",i?"300+":`${l}+`," models from OpenAI, Anthropic, Google, Meta and more - all through one API."]})]}),e.jsxs(Xe,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ue,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"One API, all providers"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(V,{className:"w-4 h-4 text-accent"}),e.jsx("span",{children:"Model tier mapping"})]})]}),e.jsxs(g,{onClick:s,className:"w-full bg-accent hover:bg-accent/90 text-white",size:"lg",children:["Create OpenRouter Profile",e.jsx(Be,{className:"w-4 h-4 ml-2"})]}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:["Get your API key at"," ",e.jsxs("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline inline-flex items-center gap-1",children:["openrouter.ai/keys",e.jsx(me,{className:"w-3 h-3"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ee,{className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx(ee,{className:"flex-1"})]}),e.jsx(g,{variant:"outline",onClick:t,className:"w-full",children:"Create Custom API Profile"})]})})}function xs({onCreateClick:s}){const{modelCount:t,isLoading:l}=q();return e.jsx("div",{className:"p-3 border-t bg-gradient-to-r from-accent/5 to-accent/10 dark:from-accent/10 dark:to-accent/15",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 bg-accent/10 dark:bg-accent/20 rounded shrink-0",children:e.jsx("img",{src:"/icons/openrouter.svg",alt:"",className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-accent dark:text-accent-foreground",children:"OpenRouter"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground truncate",children:[l?"300+":`${t}+`," models available"]})]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:s,className:"h-7 px-2 text-accent hover:text-accent hover:bg-accent/10 dark:hover:bg-accent/20",children:[e.jsx(ue,{className:"w-3 h-3 mr-1"}),e.jsx("span",{className:"text-xs",children:"Add"})]})]})})}function Os(){const{data:s,isLoading:t,isError:l,refetch:i}=_e(),d=Se(),[h,x]=c.useState(null),[n,o]=c.useState(""),[m,j]=c.useState(!1),[y,O]=c.useState("normal"),[N,b]=c.useState(null),[_,k]=c.useState(!1),[w,p]=c.useState(null);Pe();const r=c.useMemo(()=>s?.profiles||[],[s?.profiles]),a=c.useMemo(()=>r.filter(u=>u.name.toLowerCase().includes(n.toLowerCase())),[r,n]),v=h?r.find(u=>u.name===h):null,P=u=>{d.mutate(u,{onSuccess:()=>{h===u&&x(null),b(null)}})},H=u=>{j(!1),_&&h!==null?p(u):x(u)},F=u=>{_&&h!==u?p(u):x(u)};return e.jsxs("div",{className:"h-[calc(100vh-100px)] flex flex-col",children:[e.jsx(os,{onCreateClick:()=>j(!0)}),e.jsxs("div",{className:"flex-1 flex min-h-0",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qe,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:"API Profiles"})]}),e.jsxs(g,{size:"sm",onClick:()=>{j(!0)},children:[e.jsx(D,{className:"w-4 h-4 mr-1"}),"New"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(de,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(C,{placeholder:"Search profiles...",className:"pl-8 h-9",value:n,onChange:u=>o(u.target.value)})]})]}),e.jsx(I,{className:"flex-1",children:t?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading profiles..."}):l?e.jsx("div",{className:"p-4 text-center",children:e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(he,{className:"w-12 h-12 mx-auto text-destructive/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Failed to load profiles"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Unable to fetch API profiles. Please try again."})]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>i(),children:[e.jsx(U,{className:"w-4 h-4 mr-1"}),"Retry"]})]})}):a.length===0?e.jsx("div",{className:"p-4 text-center",children:r.length===0?e.jsxs("div",{className:"space-y-3 py-8",children:[e.jsx(qe,{className:"w-12 h-12 mx-auto text-muted-foreground/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"No API profiles yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Create your first profile to connect to custom API endpoints"})]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>{j(!0)},children:[e.jsx(D,{className:"w-4 h-4 mr-1"}),"Create Profile"]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground py-4",children:['No profiles match "',n,'"']})}):e.jsx("div",{className:"p-2 space-y-1",children:a.map(u=>e.jsx(ms,{profile:u,isSelected:h===u.name,onSelect:()=>F(u.name),onDelete:()=>b(u.name)},u.name))})}),r.length>0&&e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{children:[r.length," profile",r.length!==1?"s":""]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(fe,{className:"w-3 h-3 text-green-600"}),r.filter(u=>u.configured).length," configured"]})]})}),e.jsx(xs,{onCreateClick:()=>{O("openrouter"),j(!0)}})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:v?e.jsx(cs,{profileName:v.name,onDelete:()=>b(v.name),onHasChangesUpdate:k},v.name):e.jsx(ds,{onOpenRouterClick:()=>{O("openrouter"),j(!0)},onCustomClick:()=>{O("normal"),j(!0)}})})]}),e.jsx(Re,{open:m,onOpenChange:j,onSuccess:H,initialMode:y}),e.jsx(B,{open:!!N,title:"Delete Profile",description:`Are you sure you want to delete "${N}"? This will remove the settings file and cannot be undone.`,confirmText:"Delete",variant:"destructive",onConfirm:()=>N&&P(N),onCancel:()=>b(null)}),e.jsx(B,{open:!!w,title:"Unsaved Changes",description:`You have unsaved changes in "${h}". Discard and switch to "${w}"?`,confirmText:"Discard & Switch",variant:"destructive",onConfirm:()=>{k(!1),x(w),p(null)},onCancel:()=>p(null)})]})}function ms({profile:s,isSelected:t,onSelect:l,onDelete:i}){return e.jsxs("div",{className:E("group flex items-center gap-2 px-3 py-2.5 rounded-md cursor-pointer transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-muted border border-transparent"),onClick:l,children:[s.configured?e.jsx(fe,{className:"w-4 h-4 text-green-600 shrink-0"}):e.jsx(he,{className:"w-4 h-4 text-yellow-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:s.name}),e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("div",{className:"text-xs text-muted-foreground truncate flex-1",children:s.settingsPath}),e.jsx(M,{value:s.settingsPath,size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 transition-opacity"})]})]}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity",onClick:d=>{d.stopPropagation(),i()},children:e.jsx(oe,{className:"w-3.5 h-3.5 text-destructive"})})]})}export{Os as ApiPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-uXQB-q0u.js";import{r as t}from"./react-vendor-B_CU-WTZ.js";import{aB as Q,aw as V,ay as H,i as W,I as b,a as i}from"./index-QeBLfRj8.js";import{a0 as E,V as X,n as Y,k as Z,E as K,d as A,j as T,l as P,ay as _,Q as ee,R as se,aa as ae}from"./icons-CwFZAiDB.js";import"./tanstack-Coed0rqz.js";import"./notifications-dJQY2-U6.js";import"./utils-CzKF5WmX.js";import"./form-utils-kUVlZZAO.js";import"./code-highlight-DKN39ySy.js";function ue(){const{fetchRawConfig:o}=Q(),[a,I]=t.useState(null),[g,v]=t.useState(!0),[n,c]=t.useState(!1),[x,r]=t.useState(null),[p,f]=t.useState(null),[y,R]=t.useState(!1),[w,z]=t.useState(!1),[d,j]=t.useState(null),[m,N]=t.useState(null),[L,C]=t.useState(!1),[U,k]=t.useState(!1),u=t.useCallback(async()=>{try{v(!0),r(null);const s=await fetch("/api/settings/auth/tokens/raw");if(!s.ok)throw new Error("Failed to fetch auth tokens");const l=await s.json();I(l)}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{v(!1)}},[]);t.useEffect(()=>{u(),o()},[u,o]),t.useEffect(()=>{if(p){const s=setTimeout(()=>f(null),3e3);return()=>clearTimeout(s)}},[p]),t.useEffect(()=>{if(x){const s=setTimeout(()=>r(null),5e3);return()=>clearTimeout(s)}},[x]);const F=async()=>{const s=d!==null&&d!==a?.apiKey.value,l=m!==null&&m!==a?.managementSecret.value;if(!(!s&&!l))try{c(!0),r(null);const h={};s&&(h.apiKey=d),l&&(h.managementSecret=m);const S=await fetch("/api/settings/auth/tokens",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)});if(!S.ok){const J=await S.json();throw new Error(J.error||"Failed to save tokens")}f("Tokens updated. Restart CLIProxy to apply."),j(null),N(null),await u(),await o()}catch(h){r(h instanceof Error?h.message:"Unknown error")}finally{c(!1)}},O=async()=>{try{c(!0),r(null);const s=await fetch("/api/settings/auth/tokens/regenerate-secret",{method:"POST"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to regenerate secret")}f("New management secret generated. Restart CLIProxy to apply."),await u(),await o()}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{c(!1)}},D=async()=>{try{c(!0),r(null);const s=await fetch("/api/settings/auth/tokens/reset",{method:"POST"});if(!s.ok){const l=await s.json();throw new Error(l.error||"Failed to reset tokens")}f("Tokens reset to defaults. Restart CLIProxy to apply."),j(null),N(null),await u(),await o()}catch(s){r(s instanceof Error?s.message:"Unknown error")}finally{c(!1)}},$=async()=>{a&&(await navigator.clipboard.writeText(a.apiKey.value),C(!0),setTimeout(()=>C(!1),2e3))},B=async()=>{a&&(await navigator.clipboard.writeText(a.managementSecret.value),k(!0),setTimeout(()=>k(!1),2e3))};if(g||!a)return e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(E,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const M=d??a.apiKey.value,q=m??a.managementSecret.value,G=d!==null&&d!==a.apiKey.value||m!==null&&m!==a.managementSecret.value;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${x||p?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[x&&e.jsxs(V,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx(H,{children:x})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(Y,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:p})]})]}),e.jsx(W,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure CLIProxy authentication tokens. Changes require CLIProxy restart."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:"API Key"}),a.apiKey.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:"Custom"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used by Claude Code to authenticate with CLIProxy"}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(b,{type:y?"text":"password",value:M,onChange:s=>j(s.target.value),placeholder:"API key",disabled:n,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>R(!y),children:y?e.jsx(K,{className:"w-4 h-4"}):e.jsx(A,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:$,disabled:!a.apiKey.value,children:L?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(P,{className:"w-4 h-4"})})]})]})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-base font-medium",children:"Management Secret"}),a.managementSecret.isCustom&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-amber-100 text-amber-700 dark:bg-amber-900/50 dark:text-amber-300",children:"Custom"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used by CCS dashboard to access CLIProxy management APIs"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(b,{type:w?"text":"password",value:q,onChange:s=>N(s.target.value),placeholder:"Management secret",disabled:n,className:"pr-20 font-mono text-sm"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>z(!w),children:w?e.jsx(K,{className:"w-4 h-4"}):e.jsx(A,{className:"w-4 h-4"})}),e.jsx(i,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:B,disabled:!a.managementSecret.value,children:U?e.jsx(T,{className:"w-4 h-4 text-green-600"}):e.jsx(P,{className:"w-4 h-4"})})]})]}),e.jsx(i,{variant:"outline",size:"sm",onClick:O,disabled:n,title:"Generate new secure secret",children:e.jsx(ee,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:D,disabled:n||!a.apiKey.isCustom&&!a.managementSecret.isCustom,className:"gap-2",children:[e.jsx(se,{className:"w-4 h-4"}),"Reset to Defaults"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Resets both API key and management secret to their default values."})]})]})}),e.jsxs("div",{className:"p-4 border-t bg-background flex gap-2",children:[e.jsxs(i,{variant:"outline",size:"sm",onClick:()=>{u(),o()},disabled:g||n,className:"flex-1",children:[e.jsx(E,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),"Refresh"]}),e.jsxs(i,{variant:"default",size:"sm",onClick:F,disabled:!G||n,className:"flex-1",children:[e.jsx(ae,{className:`w-4 h-4 mr-2 ${n?"animate-pulse":""}`}),n?"Saving...":"Save"]})]})]})}export{ue as default};
|