File size: 1,970 Bytes
95eb75a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// ─── Data & database tools — execute_sql, database_query ───────────────────────────────────────────────────────────
  // P3-4 split da toolDefinitions.ts — DO NOT edit toolDefinitions.ts directly
  // Tools (2): execute_sql, database_query

  import type { ChatCompletionTool } from "openai/resources/chat/completions";

  export const DATA_TOOLS: (ChatCompletionTool | undefined)[] = [
    {
    type: "function",
    function: {
      name: "execute_sql",
      description: "Esegue query SQL su dati JSON in-memory (SQLite virtuale) senza bisogno di un database reale. Ottimo per analisi, aggregazioni, JOIN su dati forniti. Passa i dati come array di oggetti JSON.",
      parameters: {
        type: "object",
        properties: {
          sql:  { type: "string", description: "Query SQL da eseguire (SELECT, INSERT, CREATE TABLE, ecc.)" },
          data: { type: "array",  description: "Dati di input come array di oggetti JSON (es. [{id:1, nome:'Alice'}])" },
          read_only: { type: "boolean", description: "Se true, blocca INSERT/UPDATE/DELETE (default: false per in-memory)" },
        },
        required: ["sql"],
      },
    },
  },
  {
    type: "function",
    function: {
      name: "database_query",
      description: "Esegue query SQL su database PostgreSQL configurato nel backend (DATABASE_URL). Usa per leggere/scrivere dati persistenti. read_only:true per SELECT sicure senza rischi di modifica.",
      parameters: {
        type: "object",
        properties: {
          sql:       { type: "string", description: "Query SQL da eseguire" },
          params:    { type: "array",  description: "Parametri posizionali ($1, $2, ecc.)" },
          read_only: { type: "boolean", description: "Se true, accetta solo SELECT (default: true)" },
        },
        required: ["sql"],
      },
    },
  },
  ];