Node Development

Node Contract

Mỗi node executor nhận inputconfig, trả về output:

type NodeExecutor = (
  input: unknown,
  config: Record<string, unknown>,
  env: ExecutorEnv
) => Promise<unknown>;

ExecutorEnv

interface ExecutorEnv {
  DB: D1Database;              // Cloudflare D1
  KV?: KVNamespace;            // Cloudflare KV
  ANTHROPIC_API_KEY?: string;  // for AI nodes
  log: LogFn;                  // write execution log
}

Node Definition (Catalog)

interface NodeCatalogEntry {
  id: string;            // e.g. "http_request"
  type: string;          // same as id
  name: string;          // display name
  category: string;      // ai | integration | data | logic | trigger | utility
  description: string;
  official: boolean;
  config_schema?: Record<string, ConfigField>;
}

interface ConfigField {
  type: "string" | "number" | "boolean" | "json" | "code";
  label: string;
  required?: boolean;
  default?: unknown;
  placeholder?: string;
}

Example: Custom HTTP Node

// workers/api/src/nodes/my-http-node.ts
import type { NodeExecutor } from "../types";

export const myHttpNode: NodeExecutor = async (input, config, env) => {
  const url    = String(config.url || "");
  const method = String(config.method || "GET");

  const response = await fetch(url, {
    method,
    headers: { "Content-Type": "application/json" },
    body: method !== "GET" ? JSON.stringify(input) : undefined,
  });

  if (!response.ok) {
    throw new Error(`HTTP ${response.status}: ${url}`);
  }

  return response.json();
};

Registering a Node

Trong workers/api/src/executor.ts, thêm node vào NODE_EXECUTORS map:

import { myHttpNode } from "./nodes/my-http-node";

const NODE_EXECUTORS: Record<string, NodeExecutor> = {
  // ...existing nodes...
  "my_http": myHttpNode,
};

Và thêm vào NODES_CATALOG trong index.ts:

{
  id: "my_http",
  type: "my_http",
  name: "My HTTP Node",
  category: "integration",
  description: "Custom HTTP node with special logic.",
  official: false,
}

Node Categories

CategoryDùng cho
aiAI/LLM nodes: claude, agent, prompt
integrationExternal APIs, webhooks, HTTP
dataD1, KV, R2, transforms
logicCondition, branch, loop, merge
triggerManual, schedule, webhook, http_trigger
utilityLog, delay, debug

Testing a Node

// Test locally with wrangler dev
wrangler dev workers/api/src/index.ts --local

// Then POST a test run
curl -X POST http://localhost:8787/api/workflows/test/run \
  -H "Content-Type: application/json" \
  -d '{"input": {"url": "https://example.com"}}'
Nodes chạy trong Cloudflare Workers — không có process.env, không có Node.js built-ins. Chỉ dùng Web APIs và Cloudflare platform APIs.