Conn2Flow
Docs navigation

Reference / Libraries

ia.php library

The editors' AI prompt component (servers, models, prompts and modes per target) and sending the prompt to the Gemini API.

Path in the Gestor bibliotecas/ia.php

It is the AI inside the editors: the component where the user picks server, model, prompt and mode, and the call that sends the text to the API. It is used by the HTML editor (html-editor.php) and by the dashboard Live Editor.

Concepts

Table What it is
servidores_ia An (encrypted) API key with a name; padrao sets the first one in the list. Registered in admin-ia
prompts_ia Ready-made texts per target and language, such as "generate a pricing section"
modos_ia System instructions per target (how the AI should answer); the one with padrao comes preselected

The target is the context where the component shows up (for example, paginas in the page editor). Prompts and modes are resources: they are born from modules (ai_prompts, ai_modes, ai_prompts_targets) and can be created in the editor itself (resources).

Rendering the component

ia_renderizar_prompt(['alvo' => 'paginas', 'prompt_controls' => $html]) returns the HTML of the ia-prompt component:

  • it lists the target's servers, prompts and modes, and the Gemini models, with the default selected;

  • it includes the library JS, CodeMirror and the ia-prompt-modais modals;

  • it exposes gestor.ai.activated and gestor.ia (target and messages) to JavaScript;

  • with no active server, it returns the ia-sem-servidor component and gestor.ai.activated = false.

ia_editor_dados($target) returns the same data as JSON, for the Live Editor to build the screen by itself.

Available filters (hooks): ia.prompts.load.where (WHERE of the prompt list), ia.prompt.option (HTML of each option), ia.models.available (models) and ia.config (extra data for the JS).

Sending the prompt

$r = ia_enviar_prompt(['servidor_id' => 3, 'modelo' => 'models/gemini-3-flash-preview', 'prompt' => $text]);
if ($r['status'] === 'success') {
    $text = $r['data']['texto_gerado'];   // + modelo_usado, tokens_entrada/saida/total, resposta_completa
}
  • Without modelo, it uses the defaultModel from admin-ia.json (currently models/gemini-3-flash-preview). The model name carries the models/ prefix; the hard-coded fallback, gemini-1.5-flash, lacks the prefix and would not work in the URL.

  • It decrypts the server key and calls the Gemini API generateContent (120 s timeout).

  • It returns ['status' => 'success', 'data' => …] or ['status' => 'error', 'message' => …]; on an HTTP error, the message includes the API response body.

  • There is no conversation history: each call sends a single text.

  • ia_processar_retorno(['dados_retorno' => $r['data'], 'formato' => 'texto'|'html'|'json']) formats the result (html applies htmlspecialchars + nl2br). It has no callers.

Editor AJAX

ia_ajax_interface() dispatches, by ajax-opcao: ia-prompts → ia_ajax_prompts() and ia-modos → ia_ajax_modos() (text of a prompt/mode), ia-prompt-edit → ia_ajax_prompt_edit(), ia-prompt-new → ia_ajax_prompt_novo() and ia-prompt-del → ia_ajax_prompt_del().

Functions

Generated from gestor/bibliotecas/ia.php · 10 functions

10 of 10

ia_editor_dados

view source · line 507 ↗
ia_editor_dados(string $alvo): array

Dados do assistente de IA para UI vanilla (Live Editor — BATCH-080).

Parameters

$alvostring
Alvo do prompt/modo (ex.: 'paginas').

Returns

array
Estrutura {status, data|message}.

The Future is Hybrid: Human + AI.

Conn2Flow is the tool. If you need the Architect to design your company's strategy using this technology...

Hire Specialized Consulting