IA, HTTP et outils
g.http.* — HTTP
Section intitulée « g.http.* — HTTP »| Méthode | Signature | Description |
|---|---|---|
g.http.makeHttpRequest | (options) → Promise<HttpResponse> | Effectue une requête HTTP |
HttpRequestOptions :
{ url: string // required method?: string // "GET" (default), "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS" body?: string headers?: Record<string, string> timeout?: number // milliseconds}HttpResponse :
{ status: number statusText: string body: string headers: Record<string, string>}g.llm.* — LLM
Section intitulée « g.llm.* — LLM »Exige qu’un fournisseur LLM soit configuré.
| Méthode | Signature | Description |
|---|---|---|
g.llm.promptLocalLlm | (model, prompt, options?) → Promise<string> | Envoie un prompt au LLM configuré |
g.llm.abortLocalLlm | () | Annule une requête LLM en cours |
g.llm.getLocalLlmModels | () → Promise<OllamaModelInfo[]> | Liste les modèles disponibles |
OllamaOptions :
{ timeout?: number // milliseconds image?: string // base64-encoded image for vision models}g.secrets.* — Identifiants d’accès
Section intitulée « g.secrets.* — Identifiants d’accès »Voir Identifiants d’accès pour les détails complets.
| Méthode | Signature | Description |
|---|---|---|
g.secrets.getSecret | (secretName) → Promise<string> | Récupère la valeur déchiffrée d’une entrée |
OcrOptions pour g.page.ocr :
{ x?: number y?: number width?: number height?: number lang?: string // default: "eng" browserTabId?: string}g.* de haut niveau — utilitaires
Section intitulée « g.* de haut niveau — utilitaires »| Méthode | Signature | Description |
|---|---|---|
g.log | (message) → void | Écrit dans le panneau Console |
g.wait | (milliseconds?) → Promise | Attend une durée |
g.generateApiDocs | (outputDirectory?) → string | Génère scripting-api.d.ts |
g.generateApiDocs() est un helper avancé réservé à TypeScript (advanced TypeScript-only helper). Pour le paquet complet de support du scripting, utilisez Tools > Developer > Generate Scripting Support Files… afin de générer les définitions TypeScript, guides Lua et Janet, instructions LLM de l’espace de travail et fichiers de base pour l’écriture TypeScript.
g.tool.* — contexte d’outil
Section intitulée « g.tool.* — contexte d’outil »Disponible lorsqu’un script est appelé comme outil MCP personnalisé.
| Propriété | Type | Description |
|---|---|---|
g.tool.args | any | null | Paramètres passés par l’agent IA, ou null si le script n’est pas invoqué comme outil |
Globals de bibliothèque standard
Section intitulée « Globals de bibliothèque standard »Ces globals de haut niveau sont disponibles dans les moteurs JavaScript et Lua ; ils ne se trouvent pas sous g.*.
URL / URLSearchParams
Section intitulée « URL / URLSearchParams »API URL WHATWG appuyée par System.Uri. En JS, utilisez new URL(...); en Lua, utilisez URL(...), qui renvoie une table.
Propriétés URL : href, origin, protocol, hostname, host, port, pathname, search, hash, username, password, searchParams
const url = new URL("https://example.com/path?q=hello&page=2");const q = url.searchParams.get("q"); // "hello"g.log(url.hostname); // "example.com"g.log(url.pathname); // "/path"
// Relative URL resolutionconst api = new URL("/api/data", "https://example.com");g.log(api.href); // "https://example.com/api/data"btoa() / atob()
Section intitulée « btoa() / atob() »Encode et décode en Base64 (UTF-8).
const encoded = btoa("Hello, World!"); // "SGVsbG8sIFdvcmxkIQ=="const decoded = atob(encoded); // "Hello, World!"crypto.randomUUID()
Section intitulée « crypto.randomUUID() »Génère une chaîne UUID v4.
const id = crypto.randomUUID(); // "3b241101-e2bb-4d7a-8613-e9a3fdc1e2b3"g.tts.* — Text-to-Speech
Section intitulée « g.tts.* — Text-to-Speech »Synthèse vocale Windows. Toujours disponible, sans portée limitée à l’espace de travail.
| Méthode | Signature | Async | Description |
|---|---|---|---|
speak | (text, options?) → Promise | Oui | Prononce un texte à voix haute |
getVoices | () → string[] | Non | Liste les noms des voix disponibles |
stop | () | Non | Arrête la parole en cours |
SpeakOptions :
{ voice?: string // e.g., "Microsoft David" rate?: number // -10 to 10, default 0}g.stt.* — Speech-to-Text
Section intitulée « g.stt.* — Speech-to-Text »Le moteur STT local Whisper permet aux scripts d’écouter des commandes vocales utilisateur ou de transcrire des fichiers audio. Tout le traitement s’exécute localement sur votre CPU.
| Méthode | Signature | Async | Description |
|---|---|---|---|
listen | (ms) → Promise<string> | Oui | Enregistre l’audio du microphone sélectionné pendant une durée en millisecondes et renvoie le texte transcrit |
transcribeFile | (path) → Promise<string> | Oui | Lit un fichier .wav existant sur disque et renvoie le texte transcrit |
async function main() { g.log("Listening for 5 seconds..."); try { const text = await g.stt.listen(5000); g.log("You said: " + text);
if (text.toLowerCase().includes("hello")) { g.log("Hello to you too!"); } } catch (e) { g.log("STT Error: " + e.message); }}