untitled-5696utils.ts3 matches
5// Estimar duração baseada no tipo e quantidade de steps
6const baseDuration = steps.length * 2; // 2 segundos por step base
7const complexSteps = steps.filter(s => ["api_call", "database_operation"].includes(s.action)).length;
8return baseDuration + (complexSteps * 5); // +5 segundos para steps complexos
9}
22steps.forEach(step => {
23switch (step.action) {
24case "make_api_call":
25permissions.add("network_access");
26break;
44
45steps.forEach(step => {
46if (step.action === "make_api_call") {
47dependencies.add("http_client");
48}
untitled-5696api.ts1 match
1// api.ts
23import { convertFlowchartToAI } from './aiConverter';
autonomous-valdemo.tsx5 matches
22objective = formData.get("objective")?.toString() || objective;
2324// Continue with API call using the submitted objective
25} else {
26return new Response("Unsupported content type", { status: 415 });
27}
2829// Make API call with the objective from the form
30const requestBody = {
31messages: [
40headers: {
41"Content-Type": "application/json",
42"Authorization": `Bearer ${Deno.env.get("AGENT_API_KEY")}`,
43},
44body: JSON.stringify(requestBody),
50}
5152// Get the API response data
53const responseData = await response.json();
54console.log("API Response:", responseData);
5556// Return HTML with the results
autonomous-valtools.tsx4 matches
77}),
78execute: async ({ query }) => {
79const apiKey = Deno.env.get("EXA_API_KEY");
80const exa = new Exa(apiKey);
81const result = await exa.searchAndContents(query, {
82text: true,
100}),
101execute: async ({ url }) => {
102const apiKey = Deno.env.get("EXA_API_KEY");
103const exa = new Exa(apiKey);
104const result = await exa.getContents([url], { text: true });
105return {
autonomous-valREADME.md9 matches
1# Autonomous Val
2This project demonstrates how to build autonomous agents on Val Town that can be triggered by API calls, cron jobs, etc.
34
89Configure 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)
1314## Usage
15Use `demo.tsx` to send objectives to your agent.
1617### API Usage
18To use the API from another client, you can POST authenticated requests to the agent.tsx endpoint:
1920```javascript
30headers: {
31"Content-Type": "application/json",
32"Authorization": `Bearer ${Deno.env.get("AGENT_API_KEY")}`,
33},
34body: JSON.stringify(requestBody),
3738### Streaming Chat
39The API will also work with streaming chat front ends based on the Vercel AI SDK's useChat hook.
4041You just need to pass `streamResults: true` in your API POST request.
4243## Using Other Models
autonomous-valdiagram.tsx1 match
5linkStyle default stroke:#aaaaaa,stroke-width:1.5px
6
7API[API] <--> Agent
8
9subgraph "Agent Runtime"
autonomous-valagent.tsx2 matches
1718export default async function POST(req: Request) {
19if (req.headers.get("Authorization") !== `Bearer ${Deno.env.get("AGENT_API_KEY")}`) {
20return new Response("Unauthorized", { status: 401 });
21}
34const maxSteps = 10;
3536const model = Deno.env.get("ANTHROPIC_API_KEY") ? anthropic("claude-3-7-sonnet-latest") : openai("gpt-4.1");
3738const options = {
3// Permite criar fluxogramas de arrastar e soltar e converter para instruções de IA
45import { convertToAI, exportJSON, importJSON, loadFlowchart, saveFlowchart } from "./apiHandlers.ts";
6import { getMainHTML } from "./frontend/mainHtml.ts"; // Vamos criar este arquivo para o HTML
710const path = url.pathname;
1112// Roteamento da API
13if (path === "/api/save-flowchart" && req.method === "POST") {
14return await saveFlowchart(req);
15}
1617if (path === "/api/convert-to-ai" && req.method === "POST") {
18return await convertToAI(req);
19}
2021if (path === "/api/load-flowchart" && req.method === "GET") {
22return await loadFlowchart(req);
23}
2425if (path === "/api/export-json" && req.method === "POST") {
26return await exportJSON(req);
27}
2829if (path === "/api/import-json" && req.method === "POST") {
30return await importJSON(req);
31}
65"input": "Entrada",
66"output": "SaÃda",
67"api": "API Call",
68"end": "Fim",
69"database": "Banco de Dados", // Adicionado
98{ value: "file", label: "Arquivo" },
99{ value: "notification", label: "Notificação" },
100{ value: "api_response", label: "Resposta API" },
101],
102"api": [
103{ value: "rest", label: "REST API" },
104{ value: "graphql", label: "GraphQL" },
105{ value: "webhook", label: "Webhook" },
233(window as any).showStatus = showStatus;
234(window as any).addNode = addNode; // Será definida mais abaixo
235(window as any).saveFlowchart = saveFlowchartGlobal; // Funções de API serão wrappers
236(window as any).convertToAI = convertToAIGlobal;
237(window as any).exportJSON = exportJSONGlobal;
243(window as any).saveNodeEdit = saveNodeEdit;
244245// === Funções Globais para o HTML (wrappers para as chamadas de API) ===
246// Estas funções farão as chamadas para o backend via fetch
247253254try {
255const response = await fetch("/api/save-flowchart", {
256method: "POST",
257headers: { "Content-Type": "application/json" },
277try {
278showStatus("Convertendo fluxograma...");
279const response = await fetch("/api/convert-to-ai", {
280method: "POST",
281headers: { "Content-Type": "application/json" },
301302try {
303const response = await fetch("/api/export-json", {
304method: "POST",
305headers: { "Content-Type": "application/json" },
332const jsonData = JSON.parse(e.target!.result as string);
333334const response = await fetch("/api/import-json", {
335method: "POST",
336headers: { "Content-Type": "application/json" },