blob_adminapp.tsx19 matches
70const menuRef = useRef(null);
71const isPublic = blob.key.startsWith("__public/");
72const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
7374useEffect(() => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
554onClick={() =>
555copyToClipboard(
556`${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
557)}
558className="text-blue-400 hover:text-blue-300 text-sm"
577>
578<img
579src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
580alt="Blob content"
581className="max-w-full h-auto"
untitled-2604new-file-9513.tsx24 matches
1// Creado por Alfonso Boldo
2// Sistema Completo de Prueba de APIs de LLMs para ValTown
3// Fecha: 05 de mayo de 2025
426}
2728// Para solicitudes POST, procesar la llamada a la API
29if (req.method === 'POST') {
30try {
57
58// Extraer parΓ‘metros
59const { provider, apiKey, prompt, model, temperature, maxTokens } = body || {};
60
61// Validar parΓ‘metros requeridos
62if (!provider || !apiKey || !prompt) {
63return new Response(
64JSON.stringify({
65error: 'Se requieren los parΓ‘metros: provider, apiKey y prompt'
66}),
67{ status: 400, headers }
74switch (provider.toLowerCase()) {
75case 'openai':
76result = await callOpenAI(apiKey, prompt, model || 'gpt-4o', temperature || 0.7, maxTokens || 1000);
77break;
78case 'anthropic':
79result = await callClaude(apiKey, prompt, model || 'claude-3-5-sonnet-20240521', temperature || 0.7, maxTokens || 1000);
80break;
81default:
111}
112113// FunciΓ³n para llamar a la API de OpenAI
114async function callOpenAI(apiKey, prompt, model, temperature, maxTokens) {
115const url = 'https://api.openai.com/v1/chat/completions';
116
117console.log(`Llamando a OpenAI con modelo: ${model}`);
122headers: {
123'Content-Type': 'application/json',
124'Authorization': `Bearer ${apiKey}`
125},
126body: JSON.stringify({
170}
171172// FunciΓ³n para llamar a la API de Claude (Anthropic)
173async function callClaude(apiKey, prompt, model, temperature, maxTokens) {
174const url = 'https://api.anthropic.com/v1/messages';
175
176console.log(`Llamando a Claude con modelo: ${model}`);
181headers: {
182'Content-Type': 'application/json',
183'x-api-key': apiKey,
184'anthropic-version': '2023-06-01'
185},
244<meta charset="UTF-8">
245<meta name="viewport" content="width=device-width, initial-scale=1.0">
246<title>Probador de APIs de LLMs</title>
247<style>
248body {
329</head>
330<body>
331<h1>Probador de APIs de LLMs</h1>
332<p>Esta herramienta te permite probar diferentes APIs de modelos de lenguaje como OpenAI (ChatGPT) y Claude (Anthropic).</p>
333
334<div class="container">
342
343<div class="form-group">
344<label for="apiKey">API Key:</label>
345<input type="password" id="apiKey" placeholder="Ingresa tu API key aquΓ">
346</div>
347
465submitBtn.addEventListener('click', async function() {
466const provider = document.getElementById('provider').value;
467const apiKey = document.getElementById('apiKey').value;
468const model = document.getElementById('model').value;
469const temperature = parseFloat(document.getElementById('temperature').value);
472
473// Validar campos
474if (!apiKey || !prompt) {
475alert('Por favor completa todos los campos requeridos.');
476return;
482rawResult.textContent = 'Cargando...';
483
484// Obtener la URL actual para la API
485// Como ahora todo estΓ‘ en un solo endpoint, simplemente usamos la misma URL
486const endpointUrl = window.location.href;
492const requestBody = {
493provider,
494apiKey,
495prompt,
496model,
morningmailmain.tsx1 match
19async function wikitext(): string {
20const randomArticle = await fetch(
21"https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro&explaintext&redirects=1&generator=random&formatversion=2&grnnamespace=0&grnlimit=3",
22);
23const articleJson = await randomArticle.json();
81async function getDiscussionPosts(discussionId: string): Promise<PostT[]> {
82// Used to get the list of post id's for the discussion.
83const discussionRes = await fetch(`${server}/api/discussions/${discussionId}`);
84const discussionResJson = await discussionRes.json();
859394await Promise.all(chunks.map(async (c: string[]) => {
95const postRes = await fetch(`${server}/api/posts?filter[id]=${c.join(",")}`);
96const postJson = await postRes.json();
97
slack-prgithub-pr-inherit-labels.ts9 matches
198}
199
200const url = `https://api.github.com/repos/${repo}/issues/${issueNumber}`;
201console.log("π Fetching issue from:", url);
202
209});
210
211console.log("π GitHub API response status:", response.status);
212
213if (!response.ok) {
215try {
216const error = await response.json();
217console.error("β GitHub API error:", JSON.stringify(error));
218errorMessage = error.message || errorMessage;
219} catch (e) {
220const errorText = await response.text();
221console.error("β GitHub API error text:", errorText);
222}
223throw new Error(`Failed to fetch issue: ${errorMessage}`);
237
238try {
239const url = `https://api.github.com/repos/${repo}/issues/${prNumber}/labels`;
240console.log("π Sending labels update request to:", url);
241
253});
254
255console.log("π GitHub API response status:", response.status);
256
257if (response.ok) {
264try {
265const error = await response.json();
266console.error("β GitHub API error:", JSON.stringify(error));
267errorMessage = error.message || errorMessage;
268} catch (e) {
269const errorText = await response.text();
270console.error("β GitHub API error text:", errorText);
271}
272return { success: false, message: errorMessage };
273}
274} catch (error) {
275console.error("β Exception during API call:", error);
276return { success: false, message: error.message };
277}
38391. **Create a Slack App**:
40- Go to [Slack API Apps](https://api.slack.com/apps) β Create New App β From scratch
41- Name your app and select your workspace
42- Click "Create App"
774. If the merge button is clicked, the Val:
78- Receives the interaction from Slack
79- Uses the GitHub API to merge the PR
80- Sends a confirmation message back to Slack
81122- **Webhook not triggering**: Check the webhook delivery logs in GitHub repository settings
123- **Labels not copying**: Ensure the issue numbers are properly referenced in the PR description
124- **403 errors with GitHub API**: Your token doesn't have sufficient permissions. For most operations, you need:
125- Classic tokens: "repo" scope
126- Fine-grained tokens: "Read and Write" access to relevant resources (PRs, Issues, etc.)
slack-prgithub-pr-auto-assign.ts5 matches
155
156try {
157const url = `https://api.github.com/repos/${repo}/issues/${prNumber}/assignees`;
158console.log("π Sending assignee request to:", url);
159
171});
172
173console.log("π GitHub API response status:", response.status);
174
175if (response.ok) {
181try {
182const error = await response.json();
183console.error("β GitHub API error:", JSON.stringify(error));
184errorMessage = error.message || errorMessage;
185
194} catch (e) {
195const errorText = await response.text();
196console.error("β GitHub API error text:", errorText);
197}
198return { success: false, message: errorMessage };
199}
200} catch (error) {
201console.error("β Exception during API call:", error);
202return { success: false, message: error.message };
203}
slack-prgithub-pr-title-prefix.ts5 matches
162
163try {
164const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
165console.log("π Sending title update request to:", url);
166
178});
179
180console.log("π GitHub API response status:", response.status);
181
182if (response.ok) {
188try {
189const error = await response.json();
190console.error("β GitHub API error:", JSON.stringify(error));
191errorMessage = error.message || errorMessage;
192} catch (e) {
193const errorText = await response.text();
194console.error("β GitHub API error text:", errorText);
195}
196return { success: false, message: errorMessage };
197}
198} catch (error) {
199console.error("β Exception during API call:", error);
200return { success: false, message: error.message };
201}
slack-prgithub-slack-pr-approvals.ts16 matches
34};
3536// Types for Slack API
37type SlackMessage = {
38blocks: any[];
372
373// Get PR details
374const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
375console.log("π Fetching from GitHub API URL:", url);
376
377let response;
384}
385});
386console.log("π GitHub API response received");
387console.log("π Response status:", response.status);
388console.log("π Response status text:", response.statusText);
395
396if (!response.ok) {
397console.error(`β GitHub API error: ${response.status} ${response.statusText}`);
398
399let errorText;
400try {
401errorText = await response.text();
402console.error("β GitHub API error response:", errorText);
403
404try {
405// Try to parse as JSON for more details
406const errorJson = JSON.parse(errorText);
407console.error("β GitHub API error details:", JSON.stringify(errorJson));
408} catch (e) {
409// Not JSON, that's fine
419try {
420data = await response.json();
421console.log("π Successfully parsed GitHub API response");
422} catch (jsonError) {
423console.error("β Failed to parse GitHub API response:", jsonError);
424
425try {
430}
431
432throw new Error(`Failed to parse GitHub API response: ${jsonError.message}`);
433}
434
446}
447448// Merge a PR via GitHub API
449async function mergePR(repo: string, prNumber: number) {
450console.log(`π Starting mergePR for PR #${prNumber} in ${repo}`);
494
495// Proceed with merge
496const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}/merge`;
497console.log("π Sending merge request to:", url);
498
514body: mergeBody
515});
516console.log("π Merge API response received");
517console.log("π Response status:", response.status);
518console.log("π Response status text:", response.statusText);
683body: JSON.stringify(message)
684});
685console.log("π Slack API response received");
686console.log("π Response status:", response.status);
687console.log("π Response status text:", response.statusText);
694
695if (!response.ok) {
696console.error(`β Slack API error: ${response.status} ${response.statusText}`);
697
698let errorText;
699try {
700errorText = await response.text();
701console.error("β Slack API error response:", errorText);
702} catch (e) {
703console.error("β Could not read error response:", e);
TownieuseAuth.tsx11 matches
34const TOKEN_KEY = "bearer";
5const ANTHROPIC_KEY = "anthropic_api_key";
67export function useAuth() {
8const [token, setToken, removeToken] = useLocalStorage(TOKEN_KEY, "");
9const [anthropicApiKey, setAnthropicApiKey, removeAnthropicApiKey] = useLocalStorage(ANTHROPIC_KEY, "");
10const [error, setError] = useState(null);
1112const isAuthenticated = !!token;
1314const authenticate = async (valTownAPIKey: string, anthropicKey: string) => {
15// replace all this with oauth when it's ready
16try {
17const res = await fetch("/api/user", {
18headers: {
19"Authorization": "Bearer " + valTownAPIKey,
20},
21});
25setError(data.error);
26removeToken();
27removeAnthropicApiKey();
28return;
29}
30setError(null);
31setToken(valTownAPIKey);
32setAnthropicApiKey(anthropicKey);
33} catch (e) {
34console.error(e);
35setError(e.error);
36removeToken();
37removeAnthropicApiKey();
38}
39};
41const logOut = () => {
42removeToken();
43removeAnthropicApiKey();
44};
4550logOut,
51token,
52anthropicApiKey,
53};
54}