Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions docs/content/docs/api-reference/workflow-api/get-world.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: getWorld
---

Retrieves the World instance for direct access to workflow storage, queuing, and streaming backends. This function returns a `World` which provides low-level access to manage workflow runs, steps, events, and hooks.

Use this function when you need direct access to the underlying workflow infrastructure, such as listing all runs, querying events, or implementing custom workflow management logic.

```typescript lineNumbers
import { getWorld } from "workflow/api";

const world = getWorld();
```

## API Signature

### Parameters

This function does not accept any parameters.

### Returns

Returns a `World` object:

<TSDoc
definition={`
import type { World } from "@workflow/world";
export default World;`}
showSections={["returns"]}
/>

## Examples

### List Workflow Runs

List all workflow runs with pagination:

```typescript lineNumbers
import { getWorld } from "workflow/api";

export async function GET(req: Request) {
const url = new URL(req.url);
const cursor = url.searchParams.get("cursor") ?? undefined;

try {
const world = getWorld(); // [!code highlight]
const runs = await world.runs.list({
pagination: { cursor },
});

return Response.json(runs);
} catch (error) {
return Response.json(
{ error: "Failed to list workflow runs" },
{ status: 500 }
);
}
}
```

### Cancel a Workflow Run

Cancel a running workflow:

```typescript lineNumbers
import { getWorld } from "workflow/api";

export async function POST(req: Request) {
const { runId } = await req.json();

if (!runId) {
return Response.json({ error: "No runId provided" }, { status: 400 });
}

try {
const world = getWorld(); // [!code highlight]
const run = await world.runs.cancel(runId); // [!code highlight]

return Response.json({ status: run.status });
} catch (error) {
return Response.json(
{ error: "Failed to cancel workflow run" },
{ status: 500 }
);
}
}
```

## Related Functions

- [`getRun()`](/docs/api-reference/workflow-api/get-run) - Higher-level API for working with individual runs by ID.
- [`start()`](/docs/api-reference/workflow-api/start) - Start a new workflow run.
5 changes: 4 additions & 1 deletion docs/content/docs/api-reference/workflow-api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ API reference for runtime functions from the `workflow/api` package.

## Functions

Workflow DevKit provides runtime functions that are used outside of workflow and step functions. These are accessed from the runtime entrypoint (e.g. where `start(workflowFn)` is called):
The API package is for access and introspection of workflow data to inspect runs, start new runs, or access anything else directly accessible by the world.

<Cards>
<Card href="/docs/api-reference/workflow-api/start" title="start()">
Expand All @@ -21,4 +21,7 @@ Workflow DevKit provides runtime functions that are used outside of workflow and
<Card href="/docs/api-reference/workflow-api/get-run" title="getRun()">
Get workflow run status and metadata without waiting for completion.
</Card>
<Card href="/docs/api-reference/workflow-api/get-world" title="getWorld()">
Get direct access to workflow storage, queuing, and streaming backends.
</Card>
</Cards>
Loading