// ─── Git & project tools — create_webpage, git_get/push/read/list/push_multiple/sync_vfs, create_project, zip, validate_json, check_package ─────────────────────────────────────────────────────────── // P3-4 split da toolDefinitions.ts — DO NOT edit toolDefinitions.ts directly // Tools (11): create_webpage, git_get_sha, git_push, create_project, zip_project, git_read_file, git_list_files, git_push_multiple, git_sync_vfs, validate_json, check_package import type { ChatCompletionTool } from "openai/resources/chat/completions"; export const GIT_TOOLS: (ChatCompletionTool | undefined)[] = [ { type: "function", function: { name: "create_webpage", description: "Crea una pagina web HTML/CSS/JS completa e mostrala in anteprima live. Usa per landing page, dashboard, giochi browser, tool interattivi, visualizzazioni. L'HTML deve essere self-contained (CSS e JS inline).", parameters: { type: "object", properties: { filename: { type: "string", description: "Nome file (es. app.html, dashboard.html)" }, html: { type: "string", description: "HTML completo con CSS e JS inline" }, show_preview: { type: "boolean", description: "Mostra anteprima immediata (default true)" } }, required: ["filename", "html"] } } }, { type: "function", function: { name: "git_get_sha", description: "Recupera il SHA attuale di un file nel repository GitHub. Necessario prima di usare git_push su un file esistente. Ritorna SHA + dimensione. Se il file non esiste restituisce 404 — in quel caso git_push può procedere senza SHA.", parameters: { type: "object", properties: { owner: { type: "string", description: "Owner del repo (es. 'my-org')" }, repo: { type: "string", description: "Nome repo (es. 'my-repo')" }, path: { type: "string", description: "Path del file nel repo (es. 'src/app.ts')" }, ref: { type: "string", description: "Branch o commit (default: 'main')" }, token: { type: "string", description: "GitHub token (opzionale — usa quello salvato con store_token se omesso)" } }, required: ["owner", "repo", "path"] } } }, { type: "function", function: { name: "git_push", description: "Carica o aggiorna un file su un repository GitHub via REST API (richiede connettore GitHub configurato o token). Usa per salvare codice generato direttamente su GitHub.", parameters: { type: "object", properties: { owner: { type: "string", description: "Username/org GitHub (es. 'my-org')" }, repo: { type: "string", description: "Nome repository (es. 'my-repo')" }, path: { type: "string", description: "Percorso file nel repo (es. 'src/utils/helper.ts')" }, content: { type: "string", description: "Contenuto del file (testo)" }, message: { type: "string", description: "Messaggio di commit" }, token: { type: "string", description: "Token GitHub (opzionale se il connettore è configurato)" } }, required: ["owner", "repo", "path", "content", "message"] } } }, { type: "function", function: { name: "create_project", description: "Crea più file VFS in una sola chiamata per scaffoldare interi progetti (React, Node, Python, ecc). Usa per creare strutture di progetto complete.", parameters: { type: "object", properties: { files: { type: "array", description: "Array di file da creare", items: { type: "object", properties: { path: { type: "string", description: "Percorso nel VFS (es. /myapp/src/App.tsx)" }, content: { type: "string", description: "Contenuto del file" }, mime: { type: "string", description: "MIME type opzionale (es. text/typescript)" } }, required: ["path", "content"] } }, project_name: { type: "string", description: "Nome del progetto (opzionale)" } }, required: ["files"] } } }, { type: "function", function: { name: "zip_project", description: "Crea un archivio ZIP di tutti (o alcuni) file nel VFS e lo offre in download all'utente. Usa al termine di un progetto per consegnare il codice completo.", parameters: { type: "object", properties: { paths: { type: "array", items: { type: "string" }, description: "Lista di percorsi VFS da includere. Se omesso, include tutti i file." }, filename: { type: "string", description: "Nome del file ZIP (default: project.zip)" } } } } }, { type: "function", function: { name: "git_read_file", description: "Leggi il contenuto di un file da qualsiasi repository GitHub (pubblico o privato con token). Usa per leggere codice esistente prima di modificarlo.", parameters: { type: "object", properties: { owner: { type: "string", description: "Username/org GitHub" }, repo: { type: "string", description: "Nome repository" }, path: { type: "string", description: "Percorso del file nel repo (es. src/App.tsx)" }, ref: { type: "string", description: "Branch/tag/commit (default: main)" }, token: { type: "string", description: "Token GitHub opzionale (per repo privati)" } }, required: ["owner", "repo", "path"] } } }, { type: "function", function: { name: "git_list_files", description: "Elenca file e cartelle in un repository GitHub (o in una directory specifica). Usa per esplorare la struttura di un repo prima di leggerlo o modificarlo.", parameters: { type: "object", properties: { owner: { type: "string", description: "Username/org GitHub" }, repo: { type: "string", description: "Nome repository" }, path: { type: "string", description: "Percorso directory (default: root '')" }, ref: { type: "string", description: "Branch/tag/commit (default: main)" }, token: { type: "string", description: "Token GitHub opzionale" } }, required: ["owner", "repo"] } } }, { type: "function", function: { name: "git_push_multiple", description: "Push atomico di più file su GitHub (1 commit solo via Trees API — no stato parziale). Usa per distribuire interi progetti o feature su GitHub. Richiede connettore GitHub.", parameters: { type: "object", properties: { owner: { type: "string", description: "Username/org GitHub" }, repo: { type: "string", description: "Nome repository" }, files: { type: "array", items: { type: "object", properties: { path: { type: "string", description: "Percorso file nel repo" }, content: { type: "string", description: "Contenuto testo del file" } }, required: ["path","content"] }, description: "File da pushare (tutti in un solo commit)" }, message: { type: "string", description: "Messaggio del commit atomico" }, branch: { type: "string", description: "Branch target (default: main)" }, token: { type: "string", description: "Token GitHub opzionale" } }, required: ["owner","repo","files","message"] } } }, { type: "function", function: { name: "git_sync_vfs", description: "Pusha TUTTO il VFS locale su GitHub in un commit atomico. Usa questo tool DOPO aver scritto/modificato file con write_file per sincronizzare automaticamente il workspace con il repository. Non richiede di specificare i file — li rileva automaticamente dal VFS. Usa sempre questo al posto di git_push_multiple quando vuoi sincronizzare l'intero workspace.", parameters: { type: "object", properties: { message: { type: "string", description: "Messaggio commit (opzionale — auto-generato se non fornito)" }, filter: { type: "string", description: "Prefisso percorso per filtrare i file (es. '/src' — default: tutti)" }, branch: { type: "string", description: "Branch target (default: main)" }, repo_prefix: { type: "string", description: "Prefisso da anteporre ai percorsi nel repo GitHub (default: nessuno)" }, }, required: [] } } }, { type: "function", function: { name: "auto_deploy_loop", description: "GAP-C v2: Deploy loop single-shot — una chiamata = un tentativo. Trigga deploy (se monitor_only=false) → poll → se fallisce ritorna errori strutturati + istruzioni per il fix. L'agente applica il fix, usa git_push (che trigga CF Pages), poi richiama con monitor_only:true e attempt:N+1. NON ritenta internamente — il retry è gestito dall'agente per permettere l'applicazione del fix tra un tentativo e il successivo.", parameters: { type: "object", properties: { project_name: { type: "string", description: "Nome progetto CF Pages (default: agente-ai)" }, timeout_s: { type: "number", description: "Timeout polling per tentativo in secondi (default: 90, max: 180)" }, max_attempts: { type: "number", description: "Max tentativi totali (default: 3, max: 5) — usato solo per il conteggio nel messaggio di output" }, monitor_only: { type: "boolean", description: "SEMPRE true sui retry: il git_push ha già triggerato CF Pages, non serve un nuovo POST /deployments" }, attempt: { type: "number", description: "Tentativo corrente 1-based (default: 1). L'agente incrementa questo valore ad ogni retry dopo aver applicato un fix." }, }, required: [] } } }, { type: "function", function: { name: "validate_json", description: "Valida e formatta JSON. Rileva errori di sintassi con numero di riga. Opzionalmente verifica che le chiavi richieste esistano.", parameters: { type: "object", properties: { json_string: { type: "string", description: "Stringa JSON da validare" }, required_keys: { type: "array", items: { type: "string" }, description: "Chiavi che devono essere presenti (opzionale)" } }, required: ["json_string"] } } }, { type: "function", function: { name: "check_package", description: "Dettagli di un pacchetto npm: versione più recente, dipendenze, homepage, licenza, dimensione bundle, data ultimo aggiornamento.", parameters: { type: "object", properties: { package_name: { type: "string", description: "Nome pacchetto npm (es. 'react', 'lodash', 'zod')" } }, required: ["package_name"] } } }, // FILE-5: Working Copy deep link per iPhone { type: "function", function: { name: "open_in_working_copy", description: "Genera un deep link per aprire un file o il repository in Working Copy (app Git per iOS). Usa per: aprire file specifici, fare clone/pull/push da iPhone. Ritorna l'URL e avvia l'apertura automatica.", parameters: { type: "object", properties: { repo: { type: "string", description: "Nome repository GitHub (default: AI)" }, path: { type: "string", description: "Percorso file specifico da aprire in Working Copy (opzionale)" }, action: { type: "string", enum: ["open", "clone", "pull", "push", "read"], description: "Azione Working Copy: open (default), clone, pull, push, read" }, }, required: [] } } }, // FILE-5: Share file VFS via iOS share sheet { type: "function", function: { name: "share_file", description: "Condivide un file dal VFS tramite la share sheet nativa iOS (AirDrop, Note, Messaggi, Files, Mail, ecc.). Su desktop mostra il file nella coda di download. Usa dopo write_file per consegnare file all'utente su iPhone.", parameters: { type: "object", properties: { path: { type: "string", description: "Percorso file nel VFS da condividere (es. /output/report.md, /code/app.ts)" }, title: { type: "string", description: "Titolo per la share sheet (default: nome file)" }, }, required: ["path"] } } }, // TG-1: send_telegram — agent client per bot Telegram (complementare al bot server) { type: "function", function: { name: "send_telegram", description: "Invia messaggio o file al bot Telegram dell'utente. Usa per notifiche proattive (task completato, file pronto, errore critico) e per consegnare file fuori dall'app. Richiede telegram_bot_token e telegram_chat_id nel vault (store_token). Complementare al bot server: questo tool INVIA, il bot server RICEVE comandi.", parameters: { type: "object", properties: { message: { type: "string", description: "Testo del messaggio (max 4096 caratteri). Supporta Markdown: grassetto, corsivo, codice." }, file_path: { type: "string", description: "Percorso file VFS da inviare come documento (es. /output/report.pdf). Se presente, message diventa caption." }, parse_mode: { type: "string", enum: ["Markdown","HTML","MarkdownV2"], description: "Formato testo (default: Markdown)" }, }, required: [] } } } ];