惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
月光博客
月光博客
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
小众软件
小众软件
U
Unit 42
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
宝玉的分享
宝玉的分享
B
Blog
C
Check Point Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
量子位
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell

Workflow SDK Documentation

Patterns for Defining Tools Human-in-the-Loop Building Durable AI Agents Queueing User Messages Resumable Streams Sleep, Suspense, and Scheduling Streaming Updates from Tools API Reference Changelog Resilient run start Cookbook Building a World Deploying Astro Express Fastify Hono Getting Started NestJS Next.js Nitro Nuxt Python SvelteKit Vite corrupted-event-log fetch-in-workflow hook-conflict Errors node-js-module-in-workflow
Workflow Globals
2026-05-31 · via Workflow SDK Documentation

Global APIs available inside workflow functions.

Workflow functions run in a restricted environment that prevents access to non-deterministic or side-effecting APIs. This page lists all global APIs available inside "use workflow" functions.

For full Node.js runtime access, use step functions.

These APIs are available but are seeded or fixed to ensure deterministic behavior across replays.

APIBehavior
Math.random()Seeded random number generator — same seed produces the same sequence every replay
Date / Date.now() / new Date()Returns a fixed timestamp that advances with the workflow's logical clock
crypto.getRandomValues()Seeded — produces deterministic output for a given workflow run
crypto.randomUUID()Seeded — produces deterministic UUIDs for a given workflow run
crypto.subtle.digest()Passes through to the real implementation (SHA-256, etc. are deterministic by nature)

You can safely use Math.random(), Date.now(), and crypto.randomUUID() in workflow functions. The framework ensures these return the same values across replays.

These standard Web APIs are available in workflow functions:

process.env is available as a read-only, frozen snapshot of the environment variables at the time the workflow was started. You cannot modify it.

export async function myWorkflow() {
  "use workflow";

  const apiKey = process.env.API_KEY; // works
  process.env.FOO = "bar"; // throws — process.env is frozen
}

Standard JavaScript typed arrays (Uint8Array, Int32Array, Float64Array, etc.) are available in workflow functions.

Base64 and hex encoding

The workflow environment provides Uint8Array base64 and hex methods for encoding and decoding binary data:

// Encode to base64
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
bytes.toBase64(); // "SGVsbG8="
bytes.toBase64({ alphabet: "base64url" }); // URL-safe variant
bytes.toBase64({ omitPadding: true }); // "SGVsbG8"

// Decode from base64
Uint8Array.fromBase64("SGVsbG8="); // Uint8Array([72, 101, 108, 108, 111])

// Encode to hex
bytes.toHex(); // "48656c6c6f"

// Decode from hex
Uint8Array.fromHex("48656c6c6f"); // Uint8Array([72, 101, 108, 108, 111])

// Write into an existing array
const target = new Uint8Array(5);
target.setFromBase64("SGVsbG8="); // { read: 8, written: 5 }
target.setFromHex("48656c6c6f"); // { read: 10, written: 5 }

These methods are polyfilled in the workflow environment. When the JavaScript runtime ships native support, the polyfill is automatically bypassed.

The following are not available in workflow functions. Move this logic to step functions instead.

  • Node.js core modules: fs, path, http, https, net, dns, child_process, cluster, os, stream, crypto (Node.js version), etc. See node-js-module-in-workflow.
  • Global fetch: Use import { fetch } from "workflow" instead. See fetch-in-workflow.
  • Timers: setTimeout, setInterval, setImmediate, and their clear* counterparts. Use sleep() instead. See timeout-in-workflow.
  • Buffer: Node.js-specific API. Use Uint8Array with toBase64() / fromBase64() / toHex() / fromHex() for binary data encoding, or atob() / btoa() for string-based base64.