31 'input': 'user_input',
32 'output': 'system_output',
33 'api': 'api_call',
34 'database': 'data_operation',
35 'loop': 'iteration'
115 break;
116
117 case 'api':
118 step.action = "make_api_call";
119 step.parameters = {
120 url: node.url || "",
200 },
201 {
202 type: "api_error",
203 action: "log_and_continue",
204 fallback_step: "error_notification"
411 <button class="glass-button" data-node-type="input">š Entrada</button>
412 <button class="glass-button" data-node-type="output">š¤ SaĆda</button>
413 <button class="glass-button" data-node-type="api">š API</button>
414 <button class="glass-button" data-node-type="end">ā¹ļø Fim</button>
415 <button class="glass-button" id="saveFlowchart">š¾ Salvar</button>
464 <li><strong>š Entrada:</strong> Coleta de dados ou informaƧƵes.</li>
465 <li><strong>š¤ SaĆda:</strong> Exibição de resultados ou informaƧƵes.</li>
466 <li><strong>š API:</strong> Chamada a uma API externa.</li>
467 <li><strong>ā¹ļø Fim:</strong> O ponto final do seu fluxograma.</li>
468 </ul>
506 decision: { label: "DecisĆ£o", icon: "ā", color: "#FFC107", subtypes: ["Booleano", "Comparação", "Intervalo", "PadrĆ£o"] },
507 input: { label: "Entrada", icon: "š", color: "#9C27B0", subtypes: ["Texto", "NĆŗmero", "Arquivo", "Seleção"] },
508 output: { label: "SaĆda", icon: "š¤", color: "#FF5722", subtypes: ["Exibir", "Arquivo", "Notificação", "Resposta API"] },
509 api: { label: "API", icon: "š", color: "#673AB7", subtypes: ["REST API", "GraphQL", "Webhook", "Database"] },
510 end: { label: "Fim", icon: "ā¹ļø", color: "#F4436", subtypes: [] },
511 };
1// main.ts
2
3import { saveFlowchart, convertToAI, loadFlowchart, exportJSON, importJSON } from './api';
4import { getMainHTML } from './htmlTemplate';
5
8 const path = url.pathname;
9
10 // Roteamento da API
11 if (path === '/api/save-flowchart' && req.method === 'POST') {
12 return await saveFlowchart(req);
13 }
14
15 if (path === '/api/convert-to-ai' && req.method === 'POST') {
16 return await convertToAI(req);
17 }
18
19 if (path === '/api/load-flowchart' && req.method === 'GET') {
20 return await loadFlowchart(req);
21 }
22
23 if (path === '/api/export-json' && req.method === 'POST') {
24 return await exportJSON(req);
25 }
26
27 if (path === '/api/import-json' && req.method === 'POST') {
28 return await importJSON(req);
29 }
15- Arrastar e soltar componentes da paleta
16- Edição de nós com duplo-clique
17- MĆŗltiplos tipos de nós: InĆcio, Processo, DecisĆ£o, Entrada, SaĆda, API, Fim
18- Subtipos especĆficos para cada tipo de nó
19
63#### š¤ SaĆda
64- **Função**: Exibir resultados ou dados
65- **Subtipos**: Exibir, Arquivo, Notificação, Resposta API
66- **Uso**: Apresentação de resultados
67
68#### š API
69- **Função**: Chamadas para APIs externas
70- **Subtipos**: REST API, GraphQL, Webhook, Database
71- **Uso**: Integração com serviços externos
72
88[InĆcio] ā [Entrada: Nome do usuĆ”rio] ā [Processo: Validar nome] ā [DecisĆ£o: Nome vĆ”lido?]
89 ā (Sim) ā (NĆ£o)
90[API: Buscar dados] ā [SaĆda: Exibir resultado] ā [Fim] [SaĆda: Erro] ā [Fim]
91```
92
160### Tratamento de Erros
161- Retry automƔtico para timeouts
162- Fallbacks para erros de API
163- Validação de entrada com retry
164
169- `collect_user_input`: Coleta de entrada
170- `display_output`: Exibição de saĆda
171- `make_api_call`: Chamadas de API
172- `database_operation`: OperaƧƵes de banco
173- `iterate`: Loops e iteraƧƵes
5 // Estimar duração baseada no tipo e quantidade de steps
6 const baseDuration = steps.length * 2; // 2 segundos por step base
7 const complexSteps = steps.filter(s => ["api_call", "database_operation"].includes(s.action)).length;
8 return baseDuration + (complexSteps * 5); // +5 segundos para steps complexos
9}
22 steps.forEach(step => {
23 switch (step.action) {
24 case "make_api_call":
25 permissions.add("network_access");
26 break;
44
45 steps.forEach(step => {
46 if (step.action === "make_api_call") {
47 dependencies.add("http_client");
48 }
1// api.ts
2
3import { convertFlowchartToAI } from './aiConverter';
22 objective = formData.get("objective")?.toString() || objective;
23
24 // Continue with API call using the submitted objective
25 } else {
26 return new Response("Unsupported content type", { status: 415 });
27 }
28
29 // Make API call with the objective from the form
30 const requestBody = {
31 messages: [
40 headers: {
41 "Content-Type": "application/json",
42 "Authorization": `Bearer ${Deno.env.get("AGENT_API_KEY")}`,
43 },
44 body: JSON.stringify(requestBody),
50 }
51
52 // Get the API response data
53 const responseData = await response.json();
54 console.log("API Response:", responseData);
55
56 // Return HTML with the results
77 }),
78 execute: async ({ query }) => {
79 const apiKey = Deno.env.get("EXA_API_KEY");
80 const exa = new Exa(apiKey);
81 const result = await exa.searchAndContents(query, {
82 text: true,
100 }),
101 execute: async ({ url }) => {
102 const apiKey = Deno.env.get("EXA_API_KEY");
103 const exa = new Exa(apiKey);
104 const result = await exa.getContents([url], { text: true });
105 return {
1# Autonomous Val
2This project demonstrates how to build autonomous agents on Val Town that can be triggered by API calls, cron jobs, etc.
3
4
8
9Configure the following variables in your environment:
10- `AGENT_API_KEY` (This is a secure token that you choose to secure the agent.tsx POST endpoint)
11- `OPENAI_API_KEY` (An OpenAI API Key)
12- `EXA_API_KEY` (Optional, though needed if you use the web search tool)
13
14## Usage
15Use `demo.tsx` to send objectives to your agent.
16
17### API Usage
18To use the API from another client, you can POST authenticated requests to the agent.tsx endpoint:
19
20```javascript
30 headers: {
31 "Content-Type": "application/json",
32 "Authorization": `Bearer ${Deno.env.get("AGENT_API_KEY")}`,
33 },
34 body: JSON.stringify(requestBody),
37
38### Streaming Chat
39The API will also work with streaming chat front ends based on the Vercel AI SDK's useChat hook.
40
41You just need to pass `streamResults: true` in your API POST request.
42
43## Using Other Models
5 linkStyle default stroke:#aaaaaa,stroke-width:1.5px
6
7 API[API] <--> Agent
8
9 subgraph "Agent Runtime"