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

推荐订阅源

J
Java Code Geeks
小众软件
小众软件
博客园 - 叶小钗
宝玉的分享
宝玉的分享
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
U
Unit 42
F
Fortinet All Blogs
IT之家
IT之家
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – 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.