@flow-state-dev/tools
Interfaces
BashToolkit
The toolkit returned by createBashTool().
Properties
bash
bash: unknown;
readFile
readFile: unknown;
writeFile
writeFile: unknown;
CommandResult
Result of executing a bash command in a sandbox.
Properties
exitCode
exitCode: number;
stderr
stderr: string;
stdout
stdout: string;
CrawlConfig
Properties
allowedHosts?
allowedHosts?: string[];
Hostnames the crawl may read from, matched exactly (example.com does not
allow www.example.com). Checked on the root URL and on every redirect hop
of every page. Only the built-in provider can check redirect hops, so
setting this selects it, and naming Firecrawl with it throws. Unset: any
public host; an empty list allows none.
excludePatterns?
excludePatterns?: string[];
URL glob patterns to exclude. Matched against path.
includePatterns?
includePatterns?: string[];
URL glob patterns to include. Matched against path.
keys?
keys?: object;
Explicit API keys.
firecrawl?
firecrawl?: string;
maxDepth?
maxDepth?: number;
Deepest link-following one crawl may go; the model can ask for less. Default: 2.
maxPages?
maxPages?: number;
Most pages one crawl may visit; the model can ask for fewer. Default: 20.
provider?
provider?: "firecrawl" | "builtin";
Override auto-selection. Use a specific provider.
waitForJS?
waitForJS?: boolean;
Enable JS rendering per page when available. Default: false.
CreateBashToolOptions
Configuration for createBashTool().
collections maps friendly names to runtime ResourceCollectionRef handles.
Only the collections you pass are synced to the workspace — nothing else
is accessible to the bash tool.
Properties
bashSession?
bashSession?: ResourceRef<BashSessionState>;
Optional singleton resource ref for persisting sandbox state across sessions.
Pass ctx.resources.bashSession (or equivalent) to enable persistence.
collections?
collections?: Record<string, ResourceCollectionRef<ProjectedEntryState, ScopeType>>;
Resource collections to sync into the workspace. Keys are collection names; values are runtime refs from the block context. Only collections explicitly passed here are materialized as files.
destination?
destination?: string;
Workspace root inside the sandbox. Default: "/workspace".
onAfterCommand?
onAfterCommand?: (cmd, result) => void | CommandResult;
Hook called after every bash command. Return a CommandResult to override the result.
Parameters
cmd
string
result
Returns
void | CommandResult
onBeforeCommand?
onBeforeCommand?: (cmd) => string | void;
Hook called before every bash command. Return a string to rewrite the command.
Parameters
cmd
string
Returns
string | void
persist?
persist?: boolean;
Persist sandbox across sessions via the bashSession resource. Default: false.
provider?
provider?: SandboxProvider;
Sandbox provider. Default: { type: "just-bash" }.
CreateBashToolResult
Return value of createBashTool().
Properties
sandbox
sandbox: Sandbox;
The resolved sandbox instance (for direct access if needed).
tools
tools: BashToolkit;
AI SDK tool definitions for bash, readFile, and writeFile.
FetchConfig
Properties
allowedHosts?
allowedHosts?: string[];
Hostnames the tool may read from, matched exactly (example.com does not
allow www.example.com). Checked on the URL the model asks for and on every
redirect hop. Only the built-in provider can check redirect hops, so setting
this selects it, and naming a hosted provider with it throws. Unset: any
public host; an empty list allows none.
keys?
keys?: object;
Explicit API keys. If omitted, auto-detect from env vars.
firecrawl?
firecrawl?: string;
jina?
jina?: string;
provider?
provider?: "firecrawl" | "jina" | "builtin";
Override auto-selection. Use a specific provider.
waitForJS?
waitForJS?: boolean;
Enable JS rendering when available (Firecrawl, Jina). Default: false.
Sandbox
Sandbox interface — the execution seam.
Matches the Vercel bash-tool Sandbox contract for compatibility. Every adapter (local fs, Vercel, Upstash, just-bash) implements this interface. Swapping adapters requires no changes to tool logic.
Properties
hostMountSource?
hostMountSource?: string;
Host directory that backs the sandbox's /workspace. Set by adapters
whose container/runtime sees a bind-mounted host directory — today
just MOAT. When present, the framework can do filesystem operations
(hydrate, flush walk) directly via Node fs APIs instead of paying
for an IPC round-trip per file. Path translation: a sandbox-side
path under <destination> maps to <hostMountSource>/<relative> on
the host.
Methods
executeCommand()
executeCommand(command): Promise<CommandResult>;
Parameters
command
string
Returns
Promise<CommandResult>
readFile()
readFile(path): Promise<string>;
Parameters
path
string
Returns
Promise<string>
stop()?
stop?(): Promise<void>;
Returns
Promise<void>
writeFile()
writeFile(path, content): Promise<void>;
Parameters
path
string
content
string
Returns
Promise<void>
SearchConfig
Properties
agentControlsTier?
agentControlsTier?: boolean;
Expose tier as a tool parameter so the calling model picks the depth per
query (e.g. choosing 'deep' when the user asks for thorough research). When
false (default), tier stays a build-time setting the model never sees.
excludeDomains?
excludeDomains?: string[];
Exclude these domains from results, where the provider supports it.
includeDomains?
includeDomains?: string[];
Restrict results to these domains, where the provider supports it.
keys?
keys?: Partial<Record<
| "tavily"
| "exa"
| "perplexity"
| "serper"
| "brave"
| "parallel"
| "perplexity-sonar", string>>;
Explicit API keys. If omitted, auto-detect from env vars.
maxResults?
maxResults?: number;
Maximum results to return. Default: 5.
provider?
provider?:
| "tavily"
| "exa"
| "perplexity"
| "serper"
| "brave"
| "parallel"
| "perplexity-sonar";
Override auto-selection. Use a specific provider.
searchDepth?
searchDepth?: "basic" | "advanced";
Search depth. 'basic' is faster/cheaper, 'advanced' returns full content. Default: 'basic'.
searchMode?
searchMode?: string;
Provider-native execution-mode passthrough / escape hatch. When set, it
overrides the tier-derived native value for adapters that read it (exa →
type, parallel → mode). Use it to reach provider-specific behaviors the
normalized tier does not cover (e.g. Exa neural / instant /
deep-reasoning). Adapters with no mode concept ignore it.
tier?
tier?: "fast" | "balanced" | "deep";
Normalized retrieval-thoroughness tier. Maps per-provider; providers with
no depth knob (serper, brave) ignore it, and auto-selection prefers a
provider that meaningfully supports the requested tier. Default: 'balanced'.
When agentControlsTier is set, this is the default the model can override.
topic?
topic?: "general" | "news";
Topic filter. Default: 'general'.
Type Aliases
BashSessionState
type BashSessionState = object;
State stored in the bash:session singleton resource for sandbox persistence.
Indexable
[key: string]: string
Properties
lastSyncedAt
lastSyncedAt: string;
provider
provider: string;
sandboxId
sandboxId: string;
workingDirectory
workingDirectory: string;
CrawlInput
type CrawlInput = z.infer<typeof crawlInputSchema>;
CrawlProviderName
type CrawlProviderName = typeof crawlProviders[number];
CrawlResult
type CrawlResult = z.infer<typeof crawlResultSchema>;
FetchInput
type FetchInput = z.infer<typeof fetchInputSchema>;
FetchProviderName
type FetchProviderName = typeof fetchProviders[number];
FetchResult
type FetchResult = z.infer<typeof fetchResultSchema>;
SandboxProvider
type SandboxProvider =
| {
cwd?: string;
env?: Record<string, string>;
execTimeoutMs?: number;
scope?: WorkspaceScope;
strictPaths?: boolean;
type: "local";
}
| {
createOptions?: unknown;
Sandbox: VercelSandboxClassLike;
sandboxId?: string;
type: "vercel";
}
| {
boxId?: string;
client: UpstashBoxClientLike;
type: "upstash";
}
| {
env?: Record<string, string>;
executionLimits?: ExecutionLimits;
javascript?: | boolean
| {
bootstrap?: string;
};
network?: NetworkConfig;
python?: boolean;
type: "just-bash";
}
| {
allowHosts?: string[];
bin?: string;
configPath?: string;
execTimeoutMs?: number;
grants?: string[];
mountTarget?: string;
noSandbox?: boolean;
persist?: boolean;
runName?: string;
runtime?: "auto" | "docker" | "apple";
type: "moat";
workspace?: string;
}
| {
sandbox: Sandbox;
type: "custom";
};
Discriminated union of sandbox provider configurations.
Union Members
Type Literal
{
cwd?: string;
env?: Record<string, string>;
execTimeoutMs?: number;
scope?: WorkspaceScope;
strictPaths?: boolean;
type: "local";
}
cwd?
cwd?: string;
Explicit workspace directory. Cannot be combined with scope — one
directory is one workspace, so a scope alongside it would separate
nothing while claiming to, and the pair is refused at construction.
When omitted, the workspace is auto-created at
.fsdev/workspaces/{scope}/{scopeId}/, with a tenant segment for run and session.
env?
env?: Record<string, string>;
Extra environment variables for each command. Commands get a minimal
environment (the BASE_ENV_KEYS list in adapters/local-fs.ts,
copied from the server when set) plus these, layered over it — not
the server's full process.env, so commands don't inherit the
server's API keys by accident. This is not an isolation boundary:
commands run as the server's user and can still read its
environment deliberately (e.g. /proc/$PPID/environ). Run untrusted
commands with the moat adapter or in a container.
execTimeoutMs?
execTimeoutMs?: number;
Per-command deadline in milliseconds. Default: 60 000. On overrun the
command's process group is killed and the result has exitCode: 124.
A process that detaches into its own session (setsid, a daemon)
leaves the group and can survive.
scope?
scope?: WorkspaceScope;
Scope for the auto-created workspace directory. Default: "session".
Cannot be combined with cwd.
"run"— one workspace per request, shared with nothing"session"— one workspace per session (isolated, ephemeral)"user"— shared across all sessions for a user"org"— shared across all sessions in an org
The list is ordered narrowest first, and that ordering is the whole
decision: everything below "run" is a workspace two runs can be
inside at once. That is usually what you want — a session's runs
building on each other is the point of a session — but it is also the
only way one run sees another's half-finished work, so a workflow
running several agents at once wants "run".
strictPaths?
strictPaths?: boolean;
Enforce that all filesystem operations stay within the workspace root.
When true (default), commands and file paths are validated before
execution. Absolute paths outside the workspace, traversals (../),
home references (~/, $HOME), and command substitution are rejected.
Set to false to disable guards. A warning is logged at initialization.
type
type: "local";
Type Literal
{
createOptions?: unknown;
Sandbox: VercelSandboxClassLike;
sandboxId?: string;
type: "vercel";
}
createOptions?
createOptions?: unknown;
Forwarded to Sandbox.create() when a new sandbox is provisioned.
Sandbox
Sandbox: VercelSandboxClassLike;
The Sandbox class from @vercel/sandbox. The consumer imports
the SDK directly and passes the class in. Keeps @flow-state-dev/tools
free of a peer dep on the SDK and gives bundlers a real static
import to trace — Vercel's nft can't follow magic-comment'd
dynamic imports through framework chunks reliably.
Usage:
import { Sandbox } from "@vercel/sandbox";
createBashCapability({ provider: { type: "vercel", Sandbox } });
sandboxId?
sandboxId?: string;
Reconnect to an existing sandbox by ID. Omit to create a fresh one.
The framework returns the resolved ID alongside the sandbox so a
bashSession resource can persist it for the next request.
type
type: "vercel";
Type Literal
{
boxId?: string;
client: UpstashBoxClientLike;
type: "upstash";
}
boxId?
boxId?: string;
Reconnect to an existing box by ID. Omit to provision a fresh one.
client
client: UpstashBoxClientLike;
The Upstash Box client instance. As with the Vercel provider, the
consumer constructs the client (which knows its own auth/region)
and passes it in. Structural typing — see UpstashBoxClient in
./adapters/upstash.
type
type: "upstash";
Type Literal
{
env?: Record<string, string>;
executionLimits?: ExecutionLimits;
javascript?: | boolean
| {
bootstrap?: string;
};
network?: NetworkConfig;
python?: boolean;
type: "just-bash";
}
env?
env?: Record<string, string>;
Environment variables available inside the sandbox.
executionLimits?
executionLimits?: ExecutionLimits;
Limits for recursion, loops, and command counts.
javascript?
javascript?:
| boolean
| {
bootstrap?: string;
};
Enable JS/TS execution (QuickJS WASM).
network?
network?: NetworkConfig;
Network/URL allowlisting for curl. Off by default.
python?
python?: boolean;
Enable python3/python commands (WASM).
type
type: "just-bash";
Type Literal
{
allowHosts?: string[];
bin?: string;
configPath?: string;
execTimeoutMs?: number;
grants?: string[];
mountTarget?: string;
noSandbox?: boolean;
persist?: boolean;
runName?: string;
runtime?: "auto" | "docker" | "apple";
type: "moat";
workspace?: string;
}
allowHosts?
allowHosts?: string[];
Outbound host whitelist. Default-deny when empty. Translated to a
repeated --allow-host argument and to network.allow in the
generated moat.yaml.
bin?
bin?: string;
MOAT binary name or absolute path. Default "moat".
configPath?
configPath?: string;
Pre-authored moat.yaml path. When set, the adapter does not
generate a transient config. If the file lives outside the workspace,
it is copied into the workspace root before moat run and removed
on teardown.
execTimeoutMs?
execTimeoutMs?: number;
Per-moat exec timeout in ms. Default 60_000.
grants?
grants?: string[];
Provider names required in moat grant list. Adapter fails fast if
any are missing.
mountTarget?
mountTarget?: string;
Bind-mount target inside the container. Defaults to destination
(which itself defaults to /workspace). Pass-through ensures agent
prompts that reference /workspace/foo.ts resolve correctly.
noSandbox?
noSandbox?: boolean;
Pass --no-sandbox (disables gVisor under Docker). Default false.
persist?
persist?: boolean;
When true, the container survives sandbox.stop() — moat stop /
moat destroy are skipped and the generated moat.yaml + tempDir
are retained. The next request with the same runName reconnects
to the live container via moat list --json. Useful for local
development: the cold-start cost is paid once, every subsequent
request runs moat exec against the running container.
Pair with a stable runName (otherwise each request generates a
fresh UUID and never finds the existing run). Under the bash
blocks, a container no command has used for 30 minutes is stopped
and destroyed; the next command starts a fresh one. A container
left by a server that has since exited is reclaimed via
moat stop <runName> or moat clean.
runName?
runName?: string;
Stable run name. Default derived from the session/scope ID.
runtime?
runtime?: "auto" | "docker" | "apple";
Container runtime. Default "auto" (MOAT picks).
type
type: "moat";
workspace?
workspace?: string;
Host directory bind-mounted as the workspace. Defaults to the resolved cwd.
Type Literal
{
sandbox: Sandbox;
type: "custom";
}
SearchInput
type SearchInput = z.infer<typeof searchInputSchema>;
SearchOutput
type SearchOutput = z.infer<typeof searchOutputSchema>;
SearchProviderName
type SearchProviderName = typeof searchProviders[number];
SearchResult
type SearchResult = z.infer<typeof searchResultSchema>;
Variables
crawlInputSchema
const crawlInputSchema: z.ZodObject<{
maxDepth: z.ZodOptional<z.ZodNumber>;
maxPages: z.ZodOptional<z.ZodNumber>;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
maxDepth?: number;
maxPages?: number;
url: string;
}, {
maxDepth?: number;
maxPages?: number;
url: string;
}>;
crawlProviders
const crawlProviders: readonly ["firecrawl", "builtin"];
crawlResultSchema
const crawlResultSchema: z.ZodObject<{
crawlDepth: z.ZodNumber;
pages: z.ZodArray<z.ZodObject<{
markdown: z.ZodString;
metadata: z.ZodObject<{
contentType: z.ZodString;
description: z.ZodOptional<z.ZodString>;
publishedDate: z.ZodOptional<z.ZodString>;
statusCode: z.ZodNumber;
wordCount: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
}, {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
}>;
source: z.ZodEnum<["firecrawl", "jina", "builtin"]>;
title: z.ZodString;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
markdown: string;
metadata: {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
};
source: "builtin" | "firecrawl" | "jina";
title: string;
url: string;
}, {
markdown: string;
metadata: {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
};
source: "builtin" | "firecrawl" | "jina";
title: string;
url: string;
}>, "many">;
rootUrl: z.ZodString;
source: z.ZodEnum<["firecrawl", "builtin"]>;
totalPages: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
crawlDepth: number;
pages: object[];
rootUrl: string;
source: "builtin" | "firecrawl";
totalPages: number;
}, {
crawlDepth: number;
pages: object[];
rootUrl: string;
source: "builtin" | "firecrawl";
totalPages: number;
}>;
fetchInputSchema
const fetchInputSchema: z.ZodObject<{
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
url: string;
}, {
url: string;
}>;
fetchProviders
const fetchProviders: readonly ["firecrawl", "jina", "builtin"];
fetchResultSchema
const fetchResultSchema: z.ZodObject<{
markdown: z.ZodString;
metadata: z.ZodObject<{
contentType: z.ZodString;
description: z.ZodOptional<z.ZodString>;
publishedDate: z.ZodOptional<z.ZodString>;
statusCode: z.ZodNumber;
wordCount: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
}, {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
}>;
source: z.ZodEnum<["firecrawl", "jina", "builtin"]>;
title: z.ZodString;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
markdown: string;
metadata: {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
};
source: "builtin" | "firecrawl" | "jina";
title: string;
url: string;
}, {
markdown: string;
metadata: {
contentType: string;
description?: string;
publishedDate?: string;
statusCode: number;
wordCount: number;
};
source: "builtin" | "firecrawl" | "jina";
title: string;
url: string;
}>;
searchInputSchema
const searchInputSchema: z.ZodObject<{
maxResults: z.ZodDefault<z.ZodNumber>;
query: z.ZodString;
topic: z.ZodDefault<z.ZodEnum<["general", "news"]>>;
}, "strip", z.ZodTypeAny, {
maxResults: number;
query: string;
topic: "general" | "news";
}, {
maxResults?: number;
query: string;
topic?: "general" | "news";
}>;
searchOutputSchema
const searchOutputSchema: z.ZodObject<{
answer: z.ZodOptional<z.ZodString>;
query: z.ZodString;
results: z.ZodArray<z.ZodObject<{
content: z.ZodOptional<z.ZodString>;
publishedDate: z.ZodOptional<z.ZodString>;
score: z.ZodOptional<z.ZodNumber>;
snippet: z.ZodString;
source: z.ZodEnum<["tavily", "exa", "perplexity", "serper", "brave", "parallel", "perplexity-sonar"]>;
title: z.ZodString;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
content?: string;
publishedDate?: string;
score?: number;
snippet: string;
source: | "brave"
| "exa"
| "parallel"
| "perplexity"
| "perplexity-sonar"
| "serper"
| "tavily";
title: string;
url: string;
}, {
content?: string;
publishedDate?: string;
score?: number;
snippet: string;
source: | "brave"
| "exa"
| "parallel"
| "perplexity"
| "perplexity-sonar"
| "serper"
| "tavily";
title: string;
url: string;
}>, "many">;
}, "strip", z.ZodTypeAny, {
answer?: string;
query: string;
results: object[];
}, {
answer?: string;
query: string;
results: object[];
}>;
searchProviders
const searchProviders: readonly ["tavily", "exa", "perplexity", "serper", "brave", "parallel", "perplexity-sonar"];
searchResultSchema
const searchResultSchema: z.ZodObject<{
content: z.ZodOptional<z.ZodString>;
publishedDate: z.ZodOptional<z.ZodString>;
score: z.ZodOptional<z.ZodNumber>;
snippet: z.ZodString;
source: z.ZodEnum<["tavily", "exa", "perplexity", "serper", "brave", "parallel", "perplexity-sonar"]>;
title: z.ZodString;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
content?: string;
publishedDate?: string;
score?: number;
snippet: string;
source: | "brave"
| "exa"
| "parallel"
| "perplexity"
| "perplexity-sonar"
| "serper"
| "tavily";
title: string;
url: string;
}, {
content?: string;
publishedDate?: string;
score?: number;
snippet: string;
source: | "brave"
| "exa"
| "parallel"
| "perplexity"
| "perplexity-sonar"
| "serper"
| "tavily";
title: string;
url: string;
}>;
tools
const tools: object;
Type Declaration
crawl
readonly crawl: typeof crawl;
createBashTool
readonly createBashTool: typeof createBashTool;
fetch
readonly fetch: typeof fetch;
search
readonly search: typeof search;
Functions
createBashTool()
function createBashTool(options?): Promise<CreateBashToolResult>;
Creates bash, readFile, and writeFile tools backed by a sandbox environment.
Files are bidirectionally synced between the passed resource collections and
the sandbox filesystem. On init, resources are hydrated into the sandbox.
After every bash and writeFile call, changes are flushed back to resources.
Parameters
options?
Returns
Promise<CreateBashToolResult>
AI SDK tool objects and the resolved sandbox instance.
References
braveSearch
Re-exports braveSearch
builtinCrawl
Re-exports builtinCrawl
builtinFetch
Re-exports builtinFetch
crawl
Re-exports crawl
exaSearch
Re-exports exaSearch
fetch
Re-exports fetch
firecrawlCrawl
Re-exports firecrawlCrawl
firecrawlFetch
Re-exports firecrawlFetch
jinaFetch
Re-exports jinaFetch
parallelSearch
Re-exports parallelSearch
perplexitySearch
Re-exports perplexitySearch
perplexitySonarSearch
Re-exports perplexitySonarSearch
search
Re-exports search
serperSearch
Re-exports serperSearch
tavilySearch
Re-exports tavilySearch