broadfield commited on
Commit
6dba5cb
·
verified ·
1 Parent(s): 3446177

Deploy compact ChatSeed HF Hub Manager v10

Browse files
Files changed (1) hide show
  1. index.html +67 -666
index.html CHANGED
@@ -6,118 +6,49 @@
6
  <title>ChatSeed HF Hub Manager</title>
7
  <style>
8
  * { box-sizing: border-box; margin: 0; padding: 0; }
9
- body {
10
- font-family: system-ui, -apple-system, sans-serif;
11
- background: #0f172a; color: #e2e8f0; min-height: 100vh;
12
- }
13
  .app { max-width: 900px; margin: 0 auto; padding: 24px; }
14
- header {
15
- display: flex; align-items: center; justify-content: space-between;
16
- padding: 16px 0; border-bottom: 1px solid #1e293b; margin-bottom: 24px;
17
- }
18
  header h1 { font-size: 1.4rem; display: flex; align-items: center; gap: 8px; }
19
- header h1 span { background: #059669; color: #fff; font-size: 0.6rem;
20
- padding: 2px 8px; border-radius: 999px; font-weight: 500; }
21
- .status-bar {
22
- display: flex; align-items: center; gap: 12px;
23
- background: #1e293b; padding: 10px 16px; border-radius: 12px;
24
- margin-bottom: 20px; font-size: 0.85rem;
25
- }
26
  .status-dot { width: 8px; height: 8px; border-radius: 50%; }
27
  .status-dot.online { background: #22c55e; box-shadow: 0 0 6px #22c55e88; }
28
- .btn {
29
- padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer;
30
- font-size: 0.8rem; font-weight: 500; transition: all 0.15s;
31
- }
32
  .btn-primary { background: #059669; color: #fff; }
33
  .btn-primary:hover { background: #047857; }
34
- .btn-danger { background: #dc2626; color: #fff; }
35
- .btn-danger:hover { background: #b91c1c; }
36
  .btn-outline { background: transparent; border: 1px solid #334155; color: #cbd5e1; }
37
  .btn-outline:hover { background: #1e293b; }
38
- .card {
39
- background: #1e293b; border: 1px solid #334155; border-radius: 14px;
40
- padding: 20px; margin-bottom: 16px;
41
- }
42
- .card h3 { font-size: 0.9rem; color: #94a3b8; margin-bottom: 12px;
43
- text-transform: uppercase; letter-spacing: 0.04em; }
44
  .tool-grid { display: grid; gap: 8px; }
45
- .tool-btn {
46
- display: flex; align-items: center; gap: 8px;
47
- width: 100%; padding: 10px 14px; background: #0f172a;
48
- border: 1px solid #334155; border-radius: 10px; color: #e2e8f0;
49
- cursor: pointer; font-size: 0.8rem; transition: all 0.15s;
50
- }
51
  .tool-btn:hover { border-color: #059669; background: #1a2332; }
52
  .tool-btn .icon { font-size: 1.1rem; width: 24px; text-align: center; }
53
  .tool-btn .name { flex: 1; text-align: left; }
54
- .tool-btn .arrow { color: #475569; }
55
- .modal-overlay {
56
- position: fixed; top: 0; left: 0; right: 0; bottom: 0;
57
- background: rgba(0,0,0,0.7); z-index: 1000;
58
- display: flex; align-items: center; justify-content: center;
59
- padding: 16px;
60
- }
61
- .modal {
62
- background: #1e293b; border: 1px solid #334155;
63
- border-radius: 16px; padding: 24px; width: 520px; max-width: 100%;
64
- box-shadow: 0 25px 50px rgba(0,0,0,0.4);
65
- }
66
  .modal h2 { margin-bottom: 16px; font-size: 1.1rem; }
67
- .modal input, .modal textarea, .modal select {
68
- width: 100%; padding: 10px 12px; background: #0f172a;
69
- border: 1px solid #475569; border-radius: 8px; color: #f1f5f9;
70
- font-size: 0.85rem; margin-bottom: 12px;
71
- }
72
  .modal textarea { min-height: 80px; font-family: monospace; }
73
  .modal input:focus, .modal textarea:focus { outline: none; border-color: #059669; }
74
- .output {
75
- background: #0f172a; border: 1px solid #334155; border-radius: 10px;
76
- padding: 14px; margin-top: 12px; white-space: pre-wrap;
77
- font-family: monospace; font-size: 0.78rem; line-height: 1.6;
78
- max-height: 400px; overflow-y: auto;
79
- }
80
  .hidden { display: none; }
81
  .flex { display: flex; gap: 8px; }
82
  .flex-1 { flex: 1; }
83
  .mb-2 { margin-bottom: 8px; }
84
- .token-display {
85
- display: flex; align-items: center; gap: 8px;
86
- background: #0f172a; padding: 8px 12px; border-radius: 8px;
87
- border: 1px solid #334155;
88
- }
89
- .token-display .masked { font-family: monospace; color: #94a3b8; font-size: 0.8rem; }
90
- .tag {
91
- display: inline-block; padding: 2px 8px; border-radius: 999px;
92
- font-size: 0.65rem; font-weight: 500;
93
- }
94
- .tag-green { background: #05966922; color: #6ee7b7; }
95
- .tag-red { background: #dc262622; color: #fca5a5; }
96
- .tag-yellow { background: #d9770622; color: #fde68a; }
97
- footer {
98
- text-align: center; padding: 24px; color: #475569;
99
- font-size: 0.75rem; border-top: 1px solid #1e293b; margin-top: 32px;
100
- }
101
- .spinner {
102
- display: inline-block; width: 16px; height: 16px;
103
- border: 2px solid #475569; border-top-color: #22c55e;
104
- border-radius: 50%; animation: spin 0.6s linear infinite;
105
- }
106
- @keyframes spin { to { transform: rotate(360deg); } }
107
  </style>
108
  </head>
109
  <body>
110
  <div class="app">
111
  <header>
112
- <h1>
113
- 🤗 ChatSeed <span>HF Module v10</span>
114
- </h1>
115
  <div style="display:flex;gap:8px;align-items:center;">
116
  <div class="status-dot online" id="statusDot"></div>
117
- <span id="statusText" style="font-size:0.8rem;color:#94a3b8;">Loading...</span>
118
  </div>
119
  </header>
120
-
121
  <div class="status-bar">
122
  <div style="flex:1;display:flex;gap:8px;align-items:center;">
123
  <span>🔑</span>
@@ -126,600 +57,70 @@
126
  <button class="btn btn-outline" onclick="showTokenPopup()">Login</button>
127
  <button class="btn btn-outline" onclick="logout()">Logout</button>
128
  </div>
129
-
130
  <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:20px;">
131
- <button class="tool-btn" onclick="refreshStatus()">
132
- <span class="icon">🔍</span>
133
- <span class="name">Check Token / Whoami</span>
134
- <span class="arrow">→</span>
135
- </button>
136
- <button class="tool-btn" onclick="listMySpaces()">
137
- <span class="icon">📂</span>
138
- <span class="name">List My Spaces</span>
139
- <span class="arrow">→</span>
140
- </button>
141
- <button class="tool-btn" onclick="showCreateSpace()">
142
- <span class="icon">✨</span>
143
- <span class="name">Create Space</span>
144
- <span class="arrow">→</span>
145
- </button>
146
- <button class="tool-btn" onclick="showSpaceStatus()">
147
- <span class="icon">📊</span>
148
- <span class="name">Space Status</span>
149
- <span class="arrow">→</span>
150
- </button>
151
- <button class="tool-btn" onclick="showUploadFile()">
152
- <span class="icon">📄</span>
153
- <span class="name">Upload File</span>
154
- <span class="arrow">→</span>
155
- </button>
156
- <button class="tool-btn" onclick="showSearchSpaces()">
157
- <span class="icon">🔎</span>
158
- <span class="name">Search Spaces</span>
159
- <span class="arrow">→</span>
160
- </button>
161
  </div>
162
-
163
  <div class="card">
164
  <h3>📋 Output</h3>
165
- <div id="output" class="output">Click a button above to get started! 🚀</div>
166
  </div>
167
-
168
  <div id="modalArea"></div>
169
- <footer>
170
- ChatSeed HuggingFace Hub Manager v10 — <a href="https://huggingface.co/spaces/broadfield/chatseed-v2" target="_blank" style="color:#60a5fa;">broadfield/chatseed-v2</a>
171
- </footer>
172
  </div>
173
-
174
  <div id="tokenPopup" class="modal-overlay hidden">
175
  <div class="modal">
176
  <h2>🔐 HuggingFace Login</h2>
177
- <p style="color:#94a3b8;font-size:0.85rem;margin-bottom:16px;">
178
- Token stored in your browser's localStorage — never sent to any server except HF's API.
179
- </p>
180
  <input type="password" id="tokenInput" placeholder="hf_..." style="font-family:monospace;">
181
- <label style="display:flex;align-items:center;gap:6px;font-size:0.8rem;color:#94a3b8;margin-bottom:12px;">
182
- <input type="checkbox" id="showToken" style="accent-color:#059669;"> Show token
183
- </label>
184
- <div class="flex">
185
- <button class="btn btn-primary flex-1" onclick="setToken()">🔐 Set Token</button>
186
- <button class="btn btn-outline" onclick="closeTokenPopup()">Cancel</button>
187
- </div>
188
  </div>
189
  </div>
190
-
191
- <script>
192
- // ============================================================================
193
- // HuggingFace Hub Module for ChatSeed v10 — FIXED
194
- // ============================================================================
195
- // FIXES:
196
- // 1. commitFiles() now uses dynamic repo type path (spaces/models/datasets)
197
- // instead of hardcoded /api/models/ fixes "Repository not found" on uploads
198
- // 2. hf_delete_file() now uses the same dynamic path for commit endpoint
199
- // 3. Added proper repo type resolution throughout
200
- // ============================================================================
201
-
202
- (function() {
203
- 'use strict';
204
-
205
- // ─── Configuration ───────────────────────────────────────────────────────
206
- const HF_API_BASE = 'https://huggingface.co';
207
- const INFERENCE_API_BASE = 'https://api-inference.huggingface.co';
208
-
209
- // ─── Helpers ─────────────────────────────────────────────────────────────
210
-
211
- function getToken() {
212
- try { return localStorage.getItem('chatseed_hf_token') || ''; } catch(e) { return ''; }
213
- }
214
- function setToken(token) {
215
- try { localStorage.setItem('chatseed_hf_token', token); } catch(e) {}
216
- }
217
- function clearToken() {
218
- try { localStorage.removeItem('chatseed_hf_token'); } catch(e) {}
219
- }
220
- function authHeader() {
221
- const t = getToken();
222
- if (!t) throw new Error('No HuggingFace token set. Use hf_set_token or hf_login_ui to set your HF access token first.');
223
- return { 'Authorization': 'Bearer ' + t };
224
- }
225
- async function hfFetch(path, options = {}) {
226
- const url = HF_API_BASE + path;
227
- const headers = { ...authHeader(), 'Content-Type': 'application/json', ...(options.headers || {}) };
228
- const res = await fetch(url, { ...options, headers });
229
- if (!res.ok) {
230
- let msg = '';
231
- try { const err = await res.json(); msg = err.error || JSON.stringify(err); } catch(e) { msg = res.statusText; }
232
- throw new Error('HF API ' + res.status + ': ' + msg);
233
- }
234
- if (res.status === 204) return null;
235
- const ct = res.headers.get('content-type') || '';
236
- if (ct.includes('application/json')) return res.json();
237
- return res.text();
238
- }
239
- async function hfFetchText(path) {
240
- const url = HF_API_BASE + path;
241
- const headers = { ...authHeader() };
242
- const res = await fetch(url, { headers });
243
- if (!res.ok) {
244
- let msg = '';
245
- try { const err = await res.json(); msg = err.error || JSON.stringify(err); } catch(e) { msg = res.statusText; }
246
- throw new Error('HF API ' + res.status + ': ' + msg);
247
- }
248
- return res.text();
249
- }
250
- function repoTypePath(type) {
251
- switch(type) { case 'space': return 'spaces'; case 'model': return 'models'; case 'dataset': return 'datasets'; default: return 'spaces'; }
252
- }
253
- async function commitFiles(repoType, namespace, repo, files, summary, description) {
254
- const rev = 'main';
255
- const typePath = repoTypePath(repoType);
256
- const body = {
257
- summary: summary || 'Update via ChatSeed',
258
- description: description || '',
259
- files: files.map(f => ({ path: f.path, content: f.content, encoding: f.encoding || 'utf-8' }))
260
- };
261
- return hfFetch('/api/' + typePath + '/' + namespace + '/' + repo + '/commit/' + rev, {
262
- method: 'POST', body: JSON.stringify(body)
263
- });
264
- }
265
-
266
- // ─── Tool Implementations ────────────────────────────────────────────────
267
- const tools = {};
268
-
269
- // Authentication
270
- tools.hf_set_token = {
271
- handler: async function(args) {
272
- const t = (args.token || '').trim();
273
- if (!t || !t.startsWith('hf_')) return '⚠️ Invalid token format. Tokens start with hf_.';
274
- const masked = t.substring(0, 6) + '…' + t.substring(t.length - 4);
275
- setToken(t);
276
- try {
277
- const whoami = await hfFetch('/api/whoami-v2');
278
- const name = whoami.name || whoami.user || 'unknown';
279
- return '✅ **HuggingFace token stored** (' + masked + ')\n👤 Authenticated as: **' + name + '**\nYou can now use all HF tools.';
280
- } catch(e) {
281
- return '⚠️ Token stored (' + masked + ') but verification failed: ' + e.message;
282
- }
283
- }
284
- };
285
-
286
- tools.hf_token_status = {
287
- handler: async function() {
288
- const t = getToken();
289
- if (!t) return '🔑 **No token stored.**';
290
- const masked = t.substring(0, 6) + '…' + t.substring(t.length - 4);
291
- try {
292
- const info = await hfFetch('/api/whoami-v2');
293
- const name = info.name || info.user || 'unknown';
294
- return '🔑 **Token Status:** Active (' + masked + ')\n👤 **Authenticated as:** ' + name + '\n📧 **Email:** ' + (info.email || 'N/A') + '\n💳 **Can Pay:** ' + (info.canPay ? 'Yes' : 'No');
295
- } catch(e) {
296
- return '⚠️ **Token stored** (' + masked + ') but verification failed: ' + e.message;
297
- }
298
- }
299
- };
300
-
301
- tools.hf_whoami = {
302
- handler: async function() {
303
- try {
304
- const info = await hfFetch('/api/whoami-v2');
305
- let r = '**👤 HuggingFace User Info**\n**ID:** ' + (info.id || info.name || 'N/A') + '\n**Name:** ' + (info.name || info.user || 'N/A') + '\n**Email:** ' + (info.email || 'N/A') + '\n**Type:** ' + (info.type || info.org || 'user') + '\n**Can Pay:** ' + (info.canPay ? '✅ Yes' : '❌ No');
306
- if (info.orgs && info.orgs.length) r += '\n**Organizations:** ' + info.orgs.map(o => o.name).join(', ');
307
- return r;
308
- } catch(e) { return '❌ Failed: ' + e.message; }
309
- }
310
- };
311
-
312
- // Spaces
313
- tools.hf_create_space = {
314
- handler: async function(args) {
315
- const namespace = args.org || (await hfFetch('/api/whoami-v2')).name;
316
- const repoId = namespace + '/' + args.name;
317
- const payload = { name: args.name, type: 'space', sdk: args.sdk || 'gradio', private: args.private || false };
318
- if (args.title) payload.title = args.title;
319
- if (args.license) payload.license = args.license;
320
- if (args.hardware) payload.hardware = args.hardware;
321
- if (args.sleep_time) payload.sleep_time = args.sleep_time;
322
- const secrets = args.secrets ? (typeof args.secrets === 'string' ? JSON.parse(args.secrets) : args.secrets) : {};
323
- const variables = args.variables ? (typeof args.variables === 'string' ? JSON.parse(args.variables) : args.variables) : {};
324
- if (Object.keys(secrets).length) payload.secrets = secrets;
325
- if (Object.keys(variables).length) payload.variables = variables;
326
- const result = await hfFetch('/api/repos/create', { method: 'POST', body: JSON.stringify(payload) });
327
- return '✅ **Space created!**\n\n**Repo:** ' + repoId + '\n**SDK:** ' + (args.sdk || 'gradio') + '\n**Visibility:** ' + (args.private ? '🔒 Private' : '🌍 Public') + '\n**URL:** https://huggingface.co/spaces/' + repoId + '\n**App:** https://' + namespace.replace(/\//g, '-') + '-' + args.name + '.hf.space' + (args.hardware ? '\n⚡ Hardware: ' + args.hardware : '') + (args.sleep_time ? '\n💤 Sleep: ' + args.sleep_time + 's' : '');
328
- }
329
- };
330
-
331
- tools.hf_duplicate_space = {
332
- handler: async function(args) {
333
- const namespace = args.org || (await hfFetch('/api/whoami-v2')).name;
334
- const repoId = namespace + '/' + args.name;
335
- const secrets = args.secrets ? (typeof args.secrets === 'string' ? JSON.parse(args.secrets) : args.secrets) : {};
336
- const variables = args.variables ? (typeof args.variables === 'string' ? JSON.parse(args.variables) : args.variables) : {};
337
- const body = { from: args.from, name: args.name, namespace: namespace, private: args.private || false };
338
- if (args.hardware) body.hardware = args.hardware;
339
- if (args.sleep_time) body.sleep_time = args.sleep_time;
340
- if (Object.keys(secrets).length) body.secrets = secrets;
341
- if (Object.keys(variables).length) body.variables = variables;
342
- const result = await hfFetch('/api/spaces/duplicate', { method: 'POST', body: JSON.stringify(body) });
343
- return '✅ **Space duplicated!**\n\n**From:** ' + args.from + '\n**New Repo:** ' + repoId + '\n**URL:** https://huggingface.co/spaces/' + repoId;
344
- }
345
- };
346
-
347
- tools.hf_delete_space = {
348
- handler: async function(args) {
349
- const parts = args.repo_id.split('/');
350
- if (parts.length !== 2) return '❌ Invalid repo_id';
351
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1], { method: 'DELETE' });
352
- return '✅ **Space deleted:** ' + args.repo_id;
353
- }
354
- };
355
-
356
- // File Operations
357
- tools.hf_upload_file = {
358
- handler: async function(args) {
359
- const parts = args.repo_id.split('/');
360
- if (parts.length !== 2) return '❌ Invalid repo_id';
361
- const result = await commitFiles('space', parts[0], parts[1], [{ path: args.path, content: args.content }], args.summary || 'Update via ChatSeed', args.description || '');
362
- return '✅ **File uploaded:** `' + args.path + '` → `' + args.repo_id + '`\n📝 ' + (args.summary || 'Update via ChatSeed');
363
- }
364
- };
365
-
366
- tools.hf_upload_app = {
367
- handler: async function(args) {
368
- const parts = args.repo_id.split('/');
369
- if (parts.length !== 2) return '❌ Invalid repo_id';
370
- const files = [{ path: 'app.py', content: args.app_code }];
371
- if (args.requirements) files.push({ path: 'requirements.txt', content: args.requirements });
372
- if (args.readme) files.push({ path: 'README.md', content: args.readme });
373
- if (args.extra_files) {
374
- const extras = typeof args.extra_files === 'string' ? JSON.parse(args.extra_files) : args.extra_files;
375
- for (const [path, content] of Object.entries(extras)) files.push({ path, content: String(content) });
376
- }
377
- const result = await commitFiles('space', parts[0], parts[1], files, args.summary || 'Deploy app via ChatSeed', '');
378
- return '✅ **App deployed to:** `' + args.repo_id + '`\n📦 **Files:** ' + files.map(f => '`' + f.path + '`').join(', ');
379
- }
380
- };
381
-
382
- tools.hf_delete_file = {
383
- handler: async function(args) {
384
- const parts = args.repo_id.split('/');
385
- if (parts.length !== 2) return '❌ Invalid repo_id';
386
- const body = { summary: args.summary || 'Delete ' + args.path, description: '', deletedEntries: [{ path: args.path }] };
387
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/commit/main', { method: 'POST', body: JSON.stringify(body) });
388
- return '✅ **File deleted:** `' + args.path + '` from `' + args.repo_id + '`';
389
- }
390
- };
391
-
392
- // Configuration
393
- tools.hf_set_secret = {
394
- handler: async function(args) {
395
- const parts = args.repo_id.split('/');
396
- if (parts.length !== 2) return '❌ Invalid repo_id';
397
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/secrets', { method: 'POST', body: JSON.stringify({ key: args.key, value: args.value }) });
398
- return '🔐 **Secret set:** `' + args.key + '` in `' + args.repo_id + '`\n⚠️ Space will restart.';
399
- }
400
- };
401
-
402
- tools.hf_delete_secret = {
403
- handler: async function(args) {
404
- const parts = args.repo_id.split('/');
405
- if (parts.length !== 2) return '❌ Invalid repo_id';
406
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/secrets', { method: 'DELETE', body: JSON.stringify({ key: args.key }) });
407
- return '🗑️ **Secret deleted:** `' + args.key + '` from `' + args.repo_id + '`';
408
- }
409
- };
410
-
411
- tools.hf_set_hardware = {
412
- handler: async function(args) {
413
- const parts = args.repo_id.split('/');
414
- if (parts.length !== 2) return '❌ Invalid repo_id';
415
- const body = { hardware: args.hardware };
416
- if (args.sleep_time) body.sleep_time = args.sleep_time;
417
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/hardware', { method: 'POST', body: JSON.stringify(body) });
418
- return '⚡ **Hardware change for:** `' + args.repo_id + '`\n**New:** ' + args.hardware + (args.sleep_time ? '\n**Sleep:** ' + args.sleep_time + 's' : '');
419
- }
420
- };
421
-
422
- tools.hf_set_visibility = {
423
- handler: async function(args) {
424
- const parts = args.repo_id.split('/');
425
- if (parts.length !== 2) return '❌ Invalid repo_id';
426
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/settings', { method: 'POST', body: JSON.stringify({ private: args.visibility === 'private' }) });
427
- return (args.visibility === 'private' ? '🔒' : '🌍') + ' **Visibility changed to ' + args.visibility + ':** `' + args.repo_id + '`';
428
- }
429
- };
430
-
431
- tools.hf_set_sleep = {
432
- handler: async function(args) {
433
- const parts = args.repo_id.split('/');
434
- if (parts.length !== 2) return '❌ Invalid repo_id';
435
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/settings', { method: 'POST', body: JSON.stringify({ sleep_time: args.sleep_time }) });
436
- const status = args.sleep_time === 0 ? '❌ Disabled' : '💤 ' + args.sleep_time + 's (' + Math.round(args.sleep_time/60) + ' min)';
437
- return '✅ **Sleep configured:** `' + args.repo_id + '` → ' + status;
438
- }
439
- };
440
-
441
- tools.hf_pause_space = {
442
- handler: async function(args) {
443
- const parts = args.repo_id.split('/');
444
- if (parts.length !== 2) return '❌ Invalid repo_id';
445
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/pause', { method: 'POST' });
446
- return '⏸️ **Space paused:** `' + args.repo_id + '`';
447
- }
448
- };
449
-
450
- tools.hf_restart_space = {
451
- handler: async function(args) {
452
- const parts = args.repo_id.split('/');
453
- if (parts.length !== 2) return '❌ Invalid repo_id';
454
- await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/restart', { method: 'POST' });
455
- return '▶️ **Space restarting:** `' + args.repo_id + '`';
456
- }
457
- };
458
-
459
- // Query / Status
460
- tools.hf_space_status = {
461
- handler: async function(args) {
462
- const parts = args.repo_id.split('/');
463
- if (parts.length !== 2) return '❌ Invalid repo_id';
464
- const runtime = await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1] + '/runtime');
465
- const repoInfo = await hfFetch('/api/spaces/' + parts[0] + '/' + parts[1]);
466
- const stageEmoji = { 'NO_APP_FILE': '📄', 'BUILDING': '🔨', 'RUNNING': '✅', 'RUNNING_BUILDING': '🔄', 'PAUSED': '⏸️', 'SLEEPING': '💤', 'STOPPED': '⛔', 'ERROR': '❌' };
467
- const stage = runtime.stage || 'UNKNOWN';
468
- return '**📊 Space Status:** `' + args.repo_id + '`\n\n**Stage:** ' + (stageEmoji[stage] || '❓') + ' ' + stage + '\n**SDK:** ' + (repoInfo.sdk || 'N/A') + '\n**Hardware:** ' + (runtime.hardware || 'cpu-basic') + '\n**Visibility:** ' + (repoInfo.private ? '🔒 Private' : '🌍 Public') + '\n**URL:** https://huggingface.co/spaces/' + args.repo_id + '\n**App:** https://' + parts[0] + '-' + parts[1] + '.hf.space';
469
- }
470
- };
471
-
472
- tools.hf_space_logs = {
473
- handler: async function(args) {
474
- const parts = args.repo_id.split('/');
475
- if (parts.length !== 2) return '❌ Invalid repo_id';
476
- try {
477
- const logs = await hfFetchText('/api/spaces/' + parts[0] + '/' + parts[1] + '/logs');
478
- const truncated = logs.length > 3000 ? '... (truncated)\n' + logs.slice(-3000) : logs;
479
- return '📋 **Logs for** `' + args.repo_id + '`\n```\n' + truncated + '\n```';
480
- } catch(e) { return '❌ Could not fetch logs: ' + e.message; }
481
- }
482
- };
483
-
484
- // Search / List
485
- tools.hf_search_spaces = {
486
- handler: async function(args) {
487
- const limit = Math.min(Math.max(args.limit || 5, 1), 25);
488
- const results = await hfFetch('/api/spaces?search=' + encodeURIComponent(args.query) + '&limit=' + limit + '&sort=likes');
489
- if (!results || !results.length) return '🔍 No Spaces found for "' + args.query + '"';
490
- let r = '🔍 **Spaces matching "' + args.query + '":**\n';
491
- results.forEach((s, i) => {
492
- const id = s.id || (s.namespace || '?') + '/' + (s.name || '?');
493
- r += '\n' + (i+1) + '. **' + id + '**' + (s.sdk ? ' [' + s.sdk + ']' : '') + (s.likes ? ' ⭐' + s.likes : '') + '\n https://huggingface.co/spaces/' + id;
494
- });
495
- return r;
496
- }
497
- };
498
-
499
- tools.hf_list_my_spaces = {
500
- handler: async function() {
501
- const userInfo = await hfFetch('/api/whoami-v2');
502
- const name = userInfo.name || userInfo.user;
503
- const results = await hfFetch('/api/spaces?author=' + encodeURIComponent(name) + '&limit=25&sort=lastModified');
504
- if (!results || !results.length) return '📭 No Spaces found under **' + name + '**';
505
- let r = '📂 **Your Spaces (' + name + '):**\n';
506
- results.forEach(s => {
507
- const id = s.id || s.namespace + '/' + s.name;
508
- r += '\n' + (s.private ? '🔒' : '🌍') + ' **' + id + '**' + (s.sdk ? ' [' + s.sdk + ']' : '') + (s.likes ? ' ⭐' + s.likes : '') + (s.runtime?.stage ? ' — ' + s.runtime.stage : '');
509
- });
510
- return r;
511
- }
512
- };
513
-
514
- tools.hf_search_models = {
515
- handler: async function(args) {
516
- const limit = Math.min(Math.max(args.limit || 5, 1), 25);
517
- const results = await hfFetch('/api/models?search=' + encodeURIComponent(args.query) + '&limit=' + limit + '&sort=likes');
518
- if (!results || !results.length) return '🔍 No models found for "' + args.query + '"';
519
- let r = '🔍 **Models matching "' + args.query + '":**\n';
520
- results.forEach((m, i) => {
521
- const id = m.id || (m.namespace || '?') + '/' + (m.name || '?');
522
- r += '\n' + (i+1) + '. **' + id + '**' + (m.pipeline_tag ? ' [' + m.pipeline_tag + ']' : '') + (m.likes ? ' ⭐' + m.likes : '') + '\n https://huggingface.co/' + id;
523
- });
524
- return r;
525
- }
526
- };
527
-
528
- tools.hf_repo_info = {
529
- handler: async function(args) {
530
- const parts = args.repo_id.split('/');
531
- if (parts.length !== 2) return '❌ Invalid repo_id';
532
- const type = repoTypePath(args.type || 'space');
533
- const info = await hfFetch('/api/' + type + '/' + parts[0] + '/' + parts[1]);
534
- let r = '**📦 Repo Info:** `' + args.repo_id + '`\n**Type:** ' + (args.type || 'space') + '\n**Visibility:** ' + (info.private ? '🔒 Private' : '🌍 Public') + '\n**Likes:** ⭐ ' + (info.likes || 0) + '\n**URL:** https://huggingface.co/' + args.repo_id;
535
- if (info.sdk) r += '\n**SDK:** ' + info.sdk;
536
- if (info.description) r += '\n**Description:** ' + info.description.substring(0, 200);
537
- return r;
538
- }
539
- };
540
-
541
- tools.hf_list_files = {
542
- handler: async function(args) {
543
- const parts = args.repo_id.split('/');
544
- if (parts.length !== 2) return '❌ Invalid repo_id';
545
- const type = repoTypePath(args.type || 'space');
546
- const rev = args.revision || 'main';
547
- const path = args.path || '';
548
- const body = { paths: [path || '/'], expand: false };
549
- const info = await hfFetch('/api/' + type + '/' + parts[0] + '/' + parts[1] + '/paths-info/' + rev, { method: 'POST', body: JSON.stringify(body) });
550
- if (!info || !info.length) return '📁 No files at `' + (path || '/') + '` in `' + args.repo_id + '`';
551
- let r = '📁 **Files in `' + args.repo_id + '/' + (path || '') + '` (' + rev + '):**\n';
552
- info.forEach(f => { r += '\n' + (f.type === 'directory' ? '📁' : '📄') + ' `' + f.path + '`' + (f.size ? ' (' + (f.size / 1024).toFixed(1) + ' KB)' : ''); });
553
- return r;
554
- }
555
- };
556
-
557
- // ─── UI Functions ────────────────────────────────────────────────
558
- const out = document.getElementById('output');
559
- function log(msg) { out.textContent = msg; }
560
-
561
- window.refreshStatus = async function() {
562
- try { log(await tools.hf_token_status.handler()); } catch(e) { log('❌ ' + e.message); }
563
- };
564
-
565
- window.listMySpaces = async function() {
566
- try { log(await tools.hf_list_my_spaces.handler()); } catch(e) { log('❌ ' + e.message); }
567
- };
568
-
569
- window.showTokenPopup = function() {
570
- document.getElementById('tokenPopup').classList.remove('hidden');
571
- document.getElementById('tokenInput').focus();
572
- };
573
-
574
- window.closeTokenPopup = function() {
575
- document.getElementById('tokenPopup').classList.add('hidden');
576
- };
577
-
578
- window.setToken = async function() {
579
- const input = document.getElementById('tokenInput');
580
- const token = input.value.trim();
581
- if (!token) return;
582
- try {
583
- const result = await tools.hf_set_token.handler({ token: token });
584
- log(result);
585
- closeTokenPopup();
586
- updateUI();
587
- } catch(e) { log('❌ ' + e.message); }
588
- };
589
-
590
- window.logout = function() {
591
- clearToken();
592
- updateUI();
593
- log('🚪 Logged out. Token cleared.');
594
- };
595
-
596
- window.showCreateSpace = function() {
597
- showModal('✨ Create Space', `
598
- <input id="spaceName" placeholder="Space name (e.g. my-awesome-demo)">
599
- <select id="spaceSdk">
600
- <option value="gradio">Gradio</option>
601
- <option value="streamlit">Streamlit</option>
602
- <option value="docker">Docker</option>
603
- <option value="static">Static</option>
604
- </select>
605
- <div class="flex">
606
- <input id="spaceHardware" class="flex-1" placeholder="Hardware (optional, e.g. t4-medium)">
607
- <input id="spaceSleep" class="flex-1" type="number" placeholder="Sleep sec (optional)">
608
- </div>
609
- <div class="flex mb-2">
610
- <label style="display:flex;align-items:center;gap:6px;font-size:0.8rem;">
611
- <input type="checkbox" id="spacePrivate" style="accent-color:#059669;"> Private
612
- </label>
613
- </div>
614
- <button class="btn btn-primary" onclick="createSpace()">🚀 Create</button>
615
- `);
616
- };
617
-
618
- window.createSpace = async function() {
619
- const name = document.getElementById('spaceName').value.trim();
620
- if (!name) return;
621
- const args = { name: name, sdk: document.getElementById('spaceSdk').value };
622
- if (document.getElementById('spacePrivate').checked) args.private = true;
623
- const hw = document.getElementById('spaceHardware').value.trim();
624
- if (hw) args.hardware = hw;
625
- const sl = parseInt(document.getElementById('spaceSleep').value);
626
- if (sl) args.sleep_time = sl;
627
- try { log(await tools.hf_create_space.handler(args)); closeModal(); } catch(e) { log('❌ ' + e.message); }
628
- };
629
-
630
- window.showSpaceStatus = function() {
631
- showModal('📊 Space Status', `
632
- <input id="statusRepoId" placeholder="namespace/space-name">
633
- <button class="btn btn-primary" onclick="getSpaceStatus()">🔍 Check</button>
634
- `);
635
- };
636
-
637
- window.getSpaceStatus = async function() {
638
- const id = document.getElementById('statusRepoId').value.trim();
639
- if (!id) return;
640
- try { log(await tools.hf_space_status.handler({ repo_id: id })); closeModal(); } catch(e) { log('❌ ' + e.message); }
641
- };
642
-
643
- window.showUploadFile = function() {
644
- showModal('📄 Upload File', `
645
- <input id="uploadRepoId" placeholder="namespace/space-name">
646
- <input id="uploadPath" placeholder="File path (e.g. app.py)">
647
- <textarea id="uploadContent" placeholder="File content..."></textarea>
648
- <button class="btn btn-primary" onclick="uploadFile()">📤 Upload</button>
649
- `);
650
- };
651
-
652
- window.uploadFile = async function() {
653
- const repo_id = document.getElementById('uploadRepoId').value.trim();
654
- const path = document.getElementById('uploadPath').value.trim();
655
- const content = document.getElementById('uploadContent').value;
656
- if (!repo_id || !path) return;
657
- try { log(await tools.hf_upload_file.handler({ repo_id, path, content })); closeModal(); } catch(e) { log('❌ ' + e.message); }
658
- };
659
-
660
- window.showSearchSpaces = function() {
661
- showModal('🔎 Search Spaces', `
662
- <input id="searchQuery" placeholder="Search query...">
663
- <button class="btn btn-primary" onclick="searchSpaces()">🔍 Search</button>
664
- `);
665
- };
666
-
667
- window.searchSpaces = async function() {
668
- const q = document.getElementById('searchQuery').value.trim();
669
- if (!q) return;
670
- try { log(await tools.hf_search_spaces.handler({ query: q })); closeModal(); } catch(e) { log('❌ ' + e.message); }
671
- };
672
-
673
- function showModal(title, content) {
674
- const area = document.getElementById('modalArea');
675
- area.innerHTML = '<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>' + title + '</h2>' + content + '</div></div>';
676
- }
677
-
678
- window.closeModal = function() {
679
- document.getElementById('modalArea').innerHTML = '';
680
- };
681
-
682
- function updateUI() {
683
- const t = getToken();
684
- const label = document.getElementById('tokenLabel');
685
- const statusText = document.getElementById('statusText');
686
- if (t) {
687
- label.innerHTML = '✅ <strong>Token set</strong> (' + t.substring(0, 6) + '…' + t.substring(t.length - 4) + ')';
688
- statusText.textContent = 'Authenticated — ' + Object.keys(tools).length + ' tools ready';
689
- } else {
690
- label.innerHTML = '❌ No token set';
691
- statusText.textContent = 'Click Login to get started';
692
- }
693
- }
694
-
695
- // Init
696
- const t = getToken();
697
- if (t) {
698
- (async () => {
699
- try {
700
- const info = await tools.hf_token_status.handler();
701
- log(info + '\n\n---\n\n🚀 Welcome to ChatSeed HF Module v10!\nClick any button above to use the tools.');
702
- } catch(e) {
703
- log('⚠️ Token stored but verification failed: ' + e.message);
704
- }
705
- })();
706
- } else {
707
- log('👋 Welcome to ChatSeed HF Hub Manager v10!\n\nClick **Login** to set your HuggingFace token, then use the buttons above to manage your Spaces!');
708
- }
709
- updateUI();
710
-
711
- // Show token toggle
712
- document.getElementById('showToken').addEventListener('change', function() {
713
- document.getElementById('tokenInput').type = this.checked ? 'text' : 'password';
714
- });
715
-
716
- // Enter key in token popup
717
- document.getElementById('tokenInput').addEventListener('keydown', function(e) {
718
- if (e.key === 'Enter') window.setToken();
719
- });
720
-
721
- console.log('[ChatSeed HF Module v10] Loaded — ' + Object.keys(tools).length + ' tools');
722
- })();
723
- </script>
724
  </body>
725
  </html>
 
6
  <title>ChatSeed HF Hub Manager</title>
7
  <style>
8
  * { box-sizing: border-box; margin: 0; padding: 0; }
9
+ body { font-family: system-ui, -apple-system, sans-serif; background: #0f172a; color: #e2e8f0; min-height: 100vh; }
 
 
 
10
  .app { max-width: 900px; margin: 0 auto; padding: 24px; }
11
+ header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; border-bottom: 1px solid #1e293b; margin-bottom: 24px; }
 
 
 
12
  header h1 { font-size: 1.4rem; display: flex; align-items: center; gap: 8px; }
13
+ header h1 span { background: #059669; color: #fff; font-size: 0.6rem; padding: 2px 8px; border-radius: 999px; font-weight: 500; }
14
+ .status-bar { display: flex; align-items: center; gap: 12px; background: #1e293b; padding: 10px 16px; border-radius: 12px; margin-bottom: 20px; font-size: 0.85rem; }
 
 
 
 
 
15
  .status-dot { width: 8px; height: 8px; border-radius: 50%; }
16
  .status-dot.online { background: #22c55e; box-shadow: 0 0 6px #22c55e88; }
17
+ .btn { padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer; font-size: 0.8rem; font-weight: 500; transition: all 0.15s; }
 
 
 
18
  .btn-primary { background: #059669; color: #fff; }
19
  .btn-primary:hover { background: #047857; }
 
 
20
  .btn-outline { background: transparent; border: 1px solid #334155; color: #cbd5e1; }
21
  .btn-outline:hover { background: #1e293b; }
22
+ .card { background: #1e293b; border: 1px solid #334155; border-radius: 14px; padding: 20px; margin-bottom: 16px; }
23
+ .card h3 { font-size: 0.9rem; color: #94a3b8; margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
 
 
 
 
24
  .tool-grid { display: grid; gap: 8px; }
25
+ .tool-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; background: #0f172a; border: 1px solid #334155; border-radius: 10px; color: #e2e8f0; cursor: pointer; font-size: 0.8rem; transition: all 0.15s; }
 
 
 
 
 
26
  .tool-btn:hover { border-color: #059669; background: #1a2332; }
27
  .tool-btn .icon { font-size: 1.1rem; width: 24px; text-align: center; }
28
  .tool-btn .name { flex: 1; text-align: left; }
29
+ .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
30
+ .modal { background: #1e293b; border: 1px solid #334155; border-radius: 16px; padding: 24px; width: 520px; max-width: 100%; box-shadow: 0 25px 50px rgba(0,0,0,0.4); }
 
 
 
 
 
 
 
 
 
 
31
  .modal h2 { margin-bottom: 16px; font-size: 1.1rem; }
32
+ .modal input, .modal textarea, .modal select { width: 100%; padding: 10px 12px; background: #0f172a; border: 1px solid #475569; border-radius: 8px; color: #f1f5f9; font-size: 0.85rem; margin-bottom: 12px; box-sizing: border-box; }
 
 
 
 
33
  .modal textarea { min-height: 80px; font-family: monospace; }
34
  .modal input:focus, .modal textarea:focus { outline: none; border-color: #059669; }
35
+ .output { background: #0f172a; border: 1px solid #334155; border-radius: 10px; padding: 14px; margin-top: 12px; white-space: pre-wrap; font-family: monospace; font-size: 0.78rem; line-height: 1.6; max-height: 400px; overflow-y: auto; }
 
 
 
 
 
36
  .hidden { display: none; }
37
  .flex { display: flex; gap: 8px; }
38
  .flex-1 { flex: 1; }
39
  .mb-2 { margin-bottom: 8px; }
40
+ footer { text-align: center; padding: 24px; color: #475569; font-size: 0.75rem; border-top: 1px solid #1e293b; margin-top: 32px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  </style>
42
  </head>
43
  <body>
44
  <div class="app">
45
  <header>
46
+ <h1>🤗 ChatSeed <span>HF Module v10</span></h1>
 
 
47
  <div style="display:flex;gap:8px;align-items:center;">
48
  <div class="status-dot online" id="statusDot"></div>
49
+ <span id="statusText" style="font-size:0.8rem;color:#94a3b8;">Online</span>
50
  </div>
51
  </header>
 
52
  <div class="status-bar">
53
  <div style="flex:1;display:flex;gap:8px;align-items:center;">
54
  <span>🔑</span>
 
57
  <button class="btn btn-outline" onclick="showTokenPopup()">Login</button>
58
  <button class="btn btn-outline" onclick="logout()">Logout</button>
59
  </div>
 
60
  <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:20px;">
61
+ <button class="tool-btn" onclick="refreshStatus()"><span class="icon">🔍</span><span class="name">Whoami</span><span class="arrow">→</span></button>
62
+ <button class="tool-btn" onclick="listMySpaces()"><span class="icon">📂</span><span class="name">My Spaces</span><span class="arrow">→</span></button>
63
+ <button class="tool-btn" onclick="showCreateSpace()"><span class="icon">✨</span><span class="name">Create Space</span><span class="arrow">→</span></button>
64
+ <button class="tool-btn" onclick="showSpaceStatus()"><span class="icon">📊</span><span class="name">Space Status</span><span class="arrow">→</span></button>
65
+ <button class="tool-btn" onclick="showUploadFile()"><span class="icon">📄</span><span class="name">Upload File</span><span class="arrow">→</span></button>
66
+ <button class="tool-btn" onclick="showSearchSpaces()"><span class="icon">🔎</span><span class="name">Search</span><span class="arrow">→</span></button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  </div>
 
68
  <div class="card">
69
  <h3>📋 Output</h3>
70
+ <div id="output" class="output">🚀 ChatSeed HF Module v10 loaded! Login to start.</div>
71
  </div>
 
72
  <div id="modalArea"></div>
73
+ <footer>ChatSeed HF Hub Manager v10 — <a href="https://huggingface.co/spaces/broadfield/chatseed-v2" target="_blank" style="color:#60a5fa;">broadfield/chatseed-v2</a></footer>
 
 
74
  </div>
 
75
  <div id="tokenPopup" class="modal-overlay hidden">
76
  <div class="modal">
77
  <h2>🔐 HuggingFace Login</h2>
78
+ <p style="color:#94a3b8;font-size:0.85rem;margin-bottom:16px;">Token stored in your browser's localStorage — never sent to any server except HF's API.</p>
 
 
79
  <input type="password" id="tokenInput" placeholder="hf_..." style="font-family:monospace;">
80
+ <label style="display:flex;align-items:center;gap:6px;font-size:0.8rem;color:#94a3b8;margin-bottom:12px;"><input type="checkbox" id="showToken" style="accent-color:#059669;"> Show token</label>
81
+ <div class="flex"><button class="btn btn-primary flex-1" onclick="setToken()">🔐 Set Token</button><button class="btn btn-outline" onclick="closeTokenPopup()">Cancel</button></div>
 
 
 
 
 
82
  </div>
83
  </div>
84
+ <script>
85
+ (function(){
86
+ 'use strict';
87
+ const HF_API_BASE='https://huggingface.co';
88
+ function gt(){try{return localStorage.getItem('chatseed_hf_token')||''}catch(e){return ''}}
89
+ function st(t){try{localStorage.setItem('chatseed_hf_token',t)}catch(e){}}
90
+ function ct(){try{localStorage.removeItem('chatseed_hf_token')}catch(e){}}
91
+ function ah(){const t=gt();if(!t)throw new Error('No HF token');return{Authorization:'Bearer '+t}}
92
+ async function hf(p,o={}){const u=HF_API_BASE+p;const h={...ah(),'Content-Type':'application/json',...o.headers||{}};const r=await fetch(u,{...o,headers:h});if(!r.ok){let m='';try{const e=await r.json();m=e.error||JSON.stringify(e)}catch(e){m=r.statusText}throw new Error('HF '+r.status+': '+m)}if(r.status===204)return null;const c=r.headers.get('content-type')||'';if(c.includes('application/json'))return r.json();return r.text()}
93
+ async function cf(rt,ns,repo,files,s,d){const body={summary:s||'Update',description:d||'',files:files.map(f=>({path:f.path,content:f.content}))};return hf('/api/spaces/'+ns+'/'+repo+'/commit/main',{method:'POST',body:JSON.stringify(body)})}
94
+ const tools={};
95
+ tools.hf_token_status={handler:async function(){const t=gt();if(!t)return'🔑 No token.';try{const i=await hf('/api/whoami-v2');return'🔑 **Active** ('+t.substring(0,6)+'…'+t.substring(t.length-4)+')\n👤 '+(i.name||i.user)+'\n📧 '+(i.email||'N/A')}catch(e){return'⚠�� Token stored but: '+e.message}}};
96
+ tools.hf_whoami={handler:async function(){try{const i=await hf('/api/whoami-v2');return'**👤 User**\nName: '+(i.name||i.user)+'\nEmail: '+(i.email||'N/A')+'\nOrg: '+(i.orgs?i.orgs.map(o=>o.name).join(', '):'none')}catch(e){return'❌ '+e.message}}};
97
+ tools.hf_list_my_spaces={handler:async function(){const u=await hf('/api/whoami-v2');const n=u.name||u.user;const r=await hf('/api/spaces?author='+encodeURIComponent(n)+'&limit=25&sort=lastModified');if(!r||!r.length)return'📭 No spaces.';let o='📂 **Spaces ('+n+'):**\n';r.forEach(s=>{o+='\n'+(s.private?'🔒':'🌍')+' **'+(s.id||s.namespace+'/'+s.name)+'**'+(s.sdk?' ['+s.sdk+']':'')+(s.runtime?.stage?' — '+s.runtime.stage:'')});return o}};
98
+ tools.hf_create_space={handler:async function(a){const ns=a.org||(await hf('/api/whoami-v2')).name;const p={name:a.name,type:'space',sdk:a.sdk||'gradio',private:a.private||false};if(a.hardware)p.hardware=a.hardware;if(a.sleep_time)p.sleep_time=a.sleep_time;const r=await hf('/api/repos/create',{method:'POST',body:JSON.stringify(p)});return'✅ **Created:** '+ns+'/'+a.name+'\n🔗 https://huggingface.co/spaces/'+ns+'/'+a.name}};
99
+ tools.hf_upload_file={handler:async function(a){const p=a.repo_id.split('/');if(p.length!==2)return'❌ Invalid';await cf('space',p[0],p[1],[{path:a.path,content:a.content}]);return'✅ Uploaded `'+a.path+'` → `'+a.repo_id+'`'}};
100
+ tools.hf_space_status={handler:async function(a){const p=a.repo_id.split('/');if(p.length!==2)return'❌ Invalid';const r=await hf('/api/spaces/'+p[0]+'/'+p[1]+'/runtime');const ri=await hf('/api/spaces/'+p[0]+'/'+p[1]);const em={'NO_APP_FILE':'📄','BUILDING':'🔨','RUNNING':'✅','PAUSED':'⏸️','SLEEPING':'💤','ERROR':'❌'};const s=r.stage||'UNKNOWN';return'**📊 Status:** `'+a.repo_id+'`\n**Stage:** '+(em[s]||'❓')+' '+s+'\n**SDK:** '+(ri.sdk||'N/A')+'\n**App:** https://'+p[0]+'-'+p[1]+'.hf.space'}};
101
+ tools.hf_search_spaces={handler:async function(a){const r=await hf('/api/spaces?search='+encodeURIComponent(a.query)+'&limit=5&sort=likes');if(!r||!r.length)return'🔍 None';let o='🔍 **"'+a.query+'"**\n';r.forEach((s,i)=>{o+='\n'+(i+1)+'. **'+(s.id||s.namespace+'/'+s.name)+'**'+(s.sdk?' ['+s.sdk+']':'')+(s.likes?' ⭐'+s.likes:'')});return o}};
102
+ tools.hf_repo_info={handler:async function(a){const p=a.repo_id.split('/');if(p.length!==2)return'❌ Invalid';const i=await hf('/api/spaces/'+p[0]+'/'+p[1]);return'**📦 '+a.repo_id+'**\n👁️ '+(i.private?'Private':'Public')+'\n⭐ '+(i.likes||0)+'\nSDK: '+(i.sdk||'N/A')+(i.description?'\n📝 '+i.description.substring(0,200):'')}};
103
+ const out=document.getElementById('output');
104
+ function log(m){out.textContent=m}
105
+ window.refreshStatus=async function(){try{log(await tools.hf_whoami.handler())}catch(e){log('❌ '+e.message)}};
106
+ window.listMySpaces=async function(){try{log(await tools.hf_list_my_spaces.handler())}catch(e){log(' '+e.message)}};
107
+ window.showTokenPopup=function(){document.getElementById('tokenPopup').classList.remove('hidden');document.getElementById('tokenInput').focus()};
108
+ window.closeTokenPopup=function(){document.getElementById('tokenPopup').classList.add('hidden')};
109
+ window.setToken=async function(){const v=document.getElementById('tokenInput').value.trim();if(!v)return;st(v);log('✅ Token set. Verifying...');try{const i=await hf('/api/whoami-v2');log('✅ **Authenticated as** '+(i.name||i.user));closeTokenPopup();updateUI()}catch(e){log('⚠️ Stored but verify failed: '+e.message);closeTokenPopup();updateUI()}};
110
+ window.logout=function(){ct();updateUI();log('🚪 Logged out.')};
111
+ window.showCreateSpace=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>✨ Create Space</h2><input id="spName" placeholder="Space name"><select id="spSdk"><option value="gradio">Gradio</option><option value="streamlit">Streamlit</option><option value="docker">Docker</option><option value="static">Static</option></select><input id="spHw" placeholder="Hardware (optional)"><label style="display:flex;align-items:center;gap:6px;font-size:0.8rem;margin-bottom:12px;"><input type="checkbox" id="spPriv" style="accent-color:#059669;"> Private</label><button class="btn btn-primary" onclick="createSpace()">🚀 Create</button></div></div>'};
112
+ window.createSpace=async function(){const n=document.getElementById('spName').value.trim();if(!n)return;const a={name:n,sdk:document.getElementById('spSdk').value};if(document.getElementById('spPriv').checked)a.private=true;const h=document.getElementById('spHw').value.trim();if(h)a.hardware=h;try{log(await tools.hf_create_space.handler(a));closeModal()}catch(e){log('❌ '+e.message)}};
113
+ window.showSpaceStatus=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>📊 Status</h2><input id="stRepo" placeholder="namespace/space-name"><button class="btn btn-primary" onclick="getStatus()">🔍 Check</button></div></div>'};
114
+ window.getStatus=async function(){const id=document.getElementById('stRepo').value.trim();if(!id)return;try{log(await tools.hf_space_status.handler({repo_id:id}));closeModal()}catch(e){log('❌ '+e.message)}};
115
+ window.showUploadFile=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>📄 Upload</h2><input id="upRepo" placeholder="namespace/space-name"><input id="upPath" placeholder="path/to/file"><textarea id="upContent" placeholder="file content..."></textarea><button class="btn btn-primary" onclick="uploadFile()">📤 Upload</button></div></div>'};
116
+ window.uploadFile=async function(){const r=document.getElementById('upRepo').value.trim();const p=document.getElementById('upPath').value.trim();const c=document.getElementById('upContent').value;if(!r||!p)return;try{log(await tools.hf_upload_file.handler({repo_id:r,path:p,content:c}));closeModal()}catch(e){log('❌ '+e.message)}};
117
+ window.showSearchSpaces=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>🔎 Search</h2><input id="sq" placeholder="Search..."><button class="btn btn-primary" onclick="searchSpaces()">🔍 Search</button></div></div>'};
118
+ window.searchSpaces=async function(){const q=document.getElementById('sq').value.trim();if(!q)return;try{log(await tools.hf_search_spaces.handler({query:q}));closeModal()}catch(e){log('❌ '+e.message)}};
119
+ window.closeModal=function(){document.getElementById('modalArea').innerHTML=''};
120
+ function updateUI(){const t=gt();const l=document.getElementById('tokenLabel');if(t){l.innerHTML='✅ <strong>Token set</strong> ('+t.substring(0,6)+'…'+t.substring(t.length-4)+')'}else{l.innerHTML='❌ No token set'}}
121
+ const t=gt();if(t){(async()=>{try{const i=await tools.hf_token_status.handler();log(i+'\n\n🚀 Click any button!')}catch(e){log('⚠️ '+e.message)}})()}updateUI()
122
+ document.getElementById('showToken').addEventListener('change',function(){document.getElementById('tokenInput').type=this.checked?'text':'password'});
123
+ })();
124
+ </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  </body>
126
  </html>