Tahap 03 & 04Cloudflare Workers · Inference Matrix · n8n Autonomous Workflows

Blueprint Infrastruktur, Inference & n8n

Arsitektur produksi untuk meng-host ai.wisatamasalalu.kaca.blog di Cloudflare Workers, memilih backend inference paling efisien dari Hugging Face, serta menggerakkan program UNUL jangka panjang lewat n8n.

01. Matriks Opsi Backend Inference (Pasca-Upload Hugging Face)

Hugging Face Hub bertindak sebagai registri file (git-lfs). Pilih salah satu mesin eksekusi berikut untuk melayani panggilan API dari Cloudflare Workers atau Antigravity.

Skenario PenggunaanPlatform / EngineFormat FileKarakteristik Operasional
Lokal & Antigravity IDEOllama / LM Studio / llama.cpp.gguf (Q4_K_M dari HF)Gratis 100%, berjalan offline di komputer pengembang setelah unduh bobot.
Cloud API On-Trigger (Scale-to-Zero)Modal / RunPod Serverless / HF InferenceMerged FP16 / LoRA AdapterKontainer GPU menyala otomatis saat Cloudflare Workers mengirim request, lalu mati saat idle (5–30 detik).
VPS Sendiri (CPU / RAM Besar)Ollama / llama-server.gguf (1.5B atau 3B Q4_K_M)Siap 24/7 tanpa GPU (~5–15 token/detik) untuk endpoint internal & webhook n8n.
Colab Pro (Semi On-Trigger Batch)Python Queue Poller + R2 / D1Adapter / GGUF sesi aktifMenarik antrean tugas selama sesi aktif, lalu memanggil runtime.unassign() saat antrean kosong.

02. Cloudflare Workers Edge Gateway

Menyajikan antarmuka ai.wisatamasalalu.kaca.blog dan endpoint /api/infer dengan latensi milidetik. Workers menarik spesifikasi UNUL dari Cloudflare R2 (zero egress fee) lalu merutekan prompt ke Modal/RunPod/VPS atau Gemini Context Cache.

Integrasi Migrasi Web Docs

Saat model UNUL-Coder siap di produksi, proyek dokumentasi di wisatamasalalu.kaca.blog cukup mengganti target fetch() asisten AI-nya ke endpoint Worker ini tanpa merombak UI dokumentasi.

// Cloudflare Workers API Gateway + RAG + Hybrid Inference Router
// Domain target: https://ai.wisatamasalalu.kaca.blog/api/infer
export interface Env {
  UNUL_DOCS_R2: R2Bucket;
  UNUL_JOBS_KV: KVNamespace;
  INFERENCE_ENDPOINT_URL: string; // Modal / RunPod Serverless / VPS Ollama / HF Endpoint
  INFERENCE_API_TOKEN: string;
  GEMINI_API_KEY: string;
  N8N_WEBHOOK_URL: string;
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const url = new URL(request.url);

    if (url.pathname === "/api/health") {
      return Response.json({ ok: true, service: "unul-ai-gateway", domain: "ai.wisatamasalalu.kaca.blog" });
    }

    if (url.pathname === "/api/infer" && request.method === "POST") {
      const payload = (await request.json()) as {
        prompt?: string;
        backend?: "unul_gpu" | "gemini_rag";
        triggerN8n?: boolean;
      };
      const prompt = (payload.prompt ?? "").trim();
      if (!prompt) {
        return Response.json({ error: "Prompt tidak boleh kosong." }, { status: 400 });
      }

      // 1. Ambil spesifikasi inti UNUL dari R2 sebagai konteks RAG
      const specObj = await env.UNUL_DOCS_R2.get("unul_spec_summary.txt");
      const ragContext = specObj ? await specObj.text() : "UNUL Enki Engine: datang...pergi, takdir.soft/hard, |>, coba...tabu...pasrah.";

      // 2. Rutekan ke Inference GPU Scale-to-Zero (Modal/RunPod/HF) atau Gemini Teacher
      if (payload.backend === "unul_gpu" && env.INFERENCE_ENDPOINT_URL) {
        const upstream = await fetch(env.INFERENCE_ENDPOINT_URL, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            Authorization: `Bearer ${env.INFERENCE_API_TOKEN}`,
          },
          body: JSON.stringify({
            model: "wisatamasalalu/unul-coder-7b",
            messages: [
              { role: "system", content: `Konteks UNUL:\n${ragContext}` },
              { role: "user", content: prompt },
            ],
          }),
        });
        const data = await upstream.json();
        return Response.json({ route: "unul_gpu", data });
      }

      return Response.json({
        route: "gemini_rag",
        ragBytes: ragContext.length,
        hint: "Teruskan ke Gemini API Context Cache atau aktifkan INFERENCE_ENDPOINT_URL.",
      });
    }

    return new Response("UNUL AI Gateway Active", { status: 200 });
  },
};

03. Otomasi n8n untuk Program UNUL Reguler & Agen Jangka Panjang

Setelah model UNUL-Coder aktif, impor salah satu cetak biru JSON berikut langsung ke instance n8n untuk menjalankan generasi program terverifikasi compiler maupun agen otonom berkelanjutan.

Webhook HTTP POST

Auto-Generate & Compile UNUL Program

Menerima permintaan pembuatan program UNUL dari Cloudflare Workers, membangkitkan kode lewat model UNUL-Coder, memverifikasinya di compiler Enki, dan mengulang otomatis jika terjadi KIAMAT SINTAKSIS.

  1. 01.Webhook Trigger (/unul-build) menerima deskripsi fitur dari ai.wisatamasalalu.kaca.blog
  2. 02.HTTP Request memanggil Cloudflare Workers /api/infer (UNUL-Coder GPU / Ollama)
  3. 03.Execute Command / Sandbox API menguji blok .unul dengan binary unul ayo
  4. 04.IF Node mengecek exit_code == 0; jika gagal, umpan balik pesan KIAMAT kembali ke UNUL AI
  5. 05.Simpan berkas .unul tervalidasi ke Cloudflare R2 & kembalikan respon ke pengguna
n8n/codegen_verify.workflow.jsonSiap impor di n8n > Import from File
{
  "name": "UNUL AI - Auto-Generate & Compile Verify",
  "nodes": [
    {
      "id": "1",
      "name": "Webhook UNUL Build",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        200,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "unul-build",
        "responseMode": "responseNode"
      }
    },
    {
      "id": "2",
      "name": "Call UNUL AI Gateway",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "https://ai.wisatamasalalu.kaca.blog/api/infer",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "prompt",
              "value": "={{ $json.body.prompt }}"
            },
            {
              "name": "backend",
              "value": "unul_gpu"
            }
          ]
        }
      }
    },
    {
      "id": "3",
      "name": "Verify via Enki Compiler",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        720,
        300
      ],
      "parameters": {
        "command": "unul ayo /tmp/generated_task.unul"
      }
    },
    {
      "id": "4",
      "name": "Check Exit Code == 0",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        980,
        300
      ],
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.exitCode }}",
              "operation": "equal",
              "value2": 0
            }
          ]
        }
      }
    }
  ],
  "connections": {
    "Webhook UNUL Build": {
      "main": [
        [
          {
            "node": "Call UNUL AI Gateway",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call UNUL AI Gateway": {
      "main": [
        [
          {
            "node": "Verify via Enki Compiler",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify via Enki Compiler": {
      "main": [
        [
          {
            "node": "Check Exit Code == 0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}