Skip to content
API reference

cloudflare

Import
import * as api from "@fungi.computer/shiitake/cloudflare";
Kind Export Description
class abstract ShiitakeOwner Owns runtime opening, HTTP/ACP transport, inbox observation and alarm recovery.
class abstract ShiitakeDO Native Cloudflare entry points; all runtime lifetime belongs to the owner.
type alias CloudflareShiitakeState Native Durable Object capabilities used by the Cloudflare adapter.
type alias CloudflareShiitakeTools Non-empty Mycelium capabilities supplied by a Cloudflare host.
type alias CloudflareHostWork Durable host work that shares Shiitake’s one native alarm, such as a host-owned delivery outbox. Shiitake never interprets it.
type alias CloudflareHostJobs Host jobs use a separate slot in Shiitake’s one Watchdog and native alarm.
type alias CloudflareShiitakeAcpServer ACP’s maintained transport, supplied by the host without a package cycle.
type alias CloudflareShiitakeOptions Cloudflare host inputs; the model owner resolves one frozen run selection.
type alias CloudflareShiitake Cloudflare host lifecycle; alarm forwarding stays outside the neutral client.
type alias SessionInboxChanges Revisioned Session inbox changes after one owner revision, oldest first.
function deliverSessionGrantsToStorage() Deliver one Session’s grants into a Cloudflare owner’s own storage, synchronously, whether or not its runtime is open; the very next tool call reads it. A plain function, not a Durable Object method, so no other Durable Object can call it over RPC: only code running inside the owner, holding its storage, delivers grants.
function makeCloudflareShiitake() Open Shiitake over one Durable Object’s storage. It resolves once the runtime is started and initialize has run; if initialize throws, the runtime is closed and the error is rethrown.

Owns runtime opening, HTTP/ACP transport, inbox observation and alarm recovery.

Type Parameter Default type
Env -
State extends CloudflareShiitakeState CloudflareShiitakeState
Signature
new ShiitakeOwner<Env, State>(ctx, env): ShiitakeOwner<Env, State>;
Parameter Type
ctx State
env Env

ShiitakeOwner<Env, State>

Signature
shiitake(): Promise<CloudflareShiitake>;

Borrow this owner’s runtime directly; only the host owns its lifetime.

Promise<CloudflareShiitake>

Signature
abortActiveSessions(): Promise<void>;

Stop live execution without constructing a cold owner’s runtime.

Promise<void>

Signature
closeShiitake(): Promise<void>;

Close owned resources before storage erasure; a cold owner has none.

Promise<void>

Signature
hasStoredSession(sessionId): Promise<boolean>;

Indexed owner-local existence check; corrupt stored Sessions remain unavailable.

Parameter Type
sessionId string

Promise<boolean>

Signature
readInboxChanges(after, limit): Promise<Readonly<{
rows: readonly (
| SessionSummaryRow
| Readonly<{
sessionId: string;
deleted: true;
}>)[];
through: number;
latest: number;
}>>;

Bounded strict-after read of this Agent’s changed inbox rows.

Parameter Type
after number
limit number

Promise<Readonly<{ rows: readonly ( | SessionSummaryRow | Readonly<{ sessionId: string; deleted: true; }>)[]; through: number; latest: number; }>>

Signature
readColdSessions(request): Promise<Readonly<{
sessions: readonly Readonly<{
sessionId: string;
bytes: number;
lastActivityAt: number;
idle: boolean;
}>[];
next?: string;
}>>;

One bounded, read-only page of Sessions with stored bytes, last activity and an idle flag, coldest first. The store keeper’s only view of cold Sessions; it carries no SQL, transaction or write.

Parameter Type
request ColdSessionPageRequest

Promise<Readonly<{ sessions: readonly Readonly<{ sessionId: string; bytes: number; lastActivityAt: number; idle: boolean; }>[]; next?: string; }>>

Signature
readInboxRevision(): number;

Latest inbox revision; read only after the owner has opened.

number

Signature
pruneInboxTombstones(through): void;

Prune deletion deltas after every current member inbox has acknowledged them.

Parameter Type
through number

void

Signature
wakeRuntime(): Promise<void>;

Persist a wake and run one reconciliation pass, including host work.

Promise<void>

Signature
alarm(): Promise<void>;

Native alarms reconstruct the owner without an incoming user request. A construction or wake failure must not strand the claimed work on platform alarm retries: it is caught, logged, and explicitly re-armed with bounded backoff instead.

Promise<void>

Signature
fetch(request): Promise<Response>;

Serve one request through Shiitake’s whole HTTP surface.

Parameter Type
request Request

Promise<Response>


Native Cloudflare entry points; all runtime lifetime belongs to the owner.

  • DurableObject<Env>
Type Parameter
Env
Signature
new ShiitakeDO<Env>(ctx, env): ShiitakeDO<Env>;
Parameter Type
ctx DurableObjectState
env Env

ShiitakeDO<Env>

Signature
DurableObject<Env>.constructor
Signature
alarm(): Promise<void>;

Reconcile due runtime and host work through the owner.

Promise<void>

Signature
DurableObject.alarm;
Signature
fetch(request): Promise<Response>;

Route an authenticated client request through the host’s routes, then the owner.

Parameter Type
request Request

Promise<Response>

Signature
DurableObject.fetch;

CloudflareShiitakeStatetype alias

Section titled “CloudflareShiitakeState”
Signature
type CloudflareShiitakeState = Readonly<{
storage: SqliteOwner &
Pick<DurableObjectStorage, "getAlarm" | "setAlarm" | "deleteAlarm"> &
object;
waitUntil: (task) => void;
id?: Readonly<{
toString: () => string;
}>;
}>;

Native Durable Object capabilities used by the Cloudflare adapter.


CloudflareShiitakeToolstype alias

Section titled “CloudflareShiitakeTools”
Signature
type CloudflareShiitakeTools = Readonly<{
modules?: readonly ModuleRegistration[];
sources?: readonly CapabilitySource[];
sandbox: Sandbox;
access?: ToolAccess;
}>;

Non-empty Mycelium capabilities supplied by a Cloudflare host.


CloudflareHostWorktype alias

Section titled “CloudflareHostWork”
Signature
type CloudflareHostWork = Readonly<{
pending: () => Readonly<{
due: boolean;
nextWakeAt: number | null;
}>;
run: () => Promise<void>;
}>;

Durable host work that shares Shiitake’s one native alarm, such as a host-owned delivery outbox. Shiitake never interprets it.


CloudflareHostJobstype alias

Section titled “CloudflareHostJobs”
Signature
type CloudflareHostJobs = Readonly<{
lane: string;
open: (runtime) => Readonly<{
execute: (job) => Promise<WatchdogExecutionDecision>;
}>;
}>;

Host jobs use a separate slot in Shiitake’s one Watchdog and native alarm.


CloudflareShiitakeAcpServertype alias

Section titled “CloudflareShiitakeAcpServer”
Signature
type CloudflareShiitakeAcpServer = Readonly<{
handleRequest: (request, meta) => Promise<Response>;
}>;

ACP’s maintained transport, supplied by the host without a package cycle.


CloudflareShiitakeOptionstype alias

Section titled “CloudflareShiitakeOptions”
Signature
type CloudflareShiitakeOptions = Readonly<{
meta?: HostMetaOptions;
model: ModelSource;
instructions: InstructionSource;
tools?: readonly [] | CloudflareShiitakeTools;
storagePressure?: StoragePressureCheck;
compaction?: CompactionOptions;
extensions: ExtensionRosterV0;
initialize?: (agent) => Promise<void>;
hostWork?: readonly CloudflareHostWork[];
hostJobs?: CloudflareHostJobs;
mailRoom?: BirdDogEffect;
acp?: (agent) => Promise<CloudflareShiitakeAcpServer>;
}>;

Cloudflare host inputs; the model owner resolves one frozen run selection.


CloudflareShiitaketype alias

Section titled “CloudflareShiitake”
Signature
type CloudflareShiitake = ShiitakeOwnerAgent &
Readonly<{
readSettlement: (
sessionId,
commandId,
) => Promise<CommandSettlement | undefined>;
acceptMail: (
mail,
meta?,
reply?,
stageAcceptedNotice?,
sessionGrantDelivery?,
) => Promise<Accepted>;
alarm: () => Promise<void>;
activeSessions: () => Promise<readonly string[]>;
abortActive: () => Promise<void>;
}>;

Cloudflare host lifecycle; alarm forwarding stays outside the neutral client.


SessionInboxChangestype alias

Section titled “SessionInboxChanges”
Signature
type SessionInboxChanges = Readonly<{
rows: readonly (
| SessionSummaryRow
| Readonly<{
sessionId: string;
deleted: true;
}>
)[];
through: number;
latest: number;
}>;

Revisioned Session inbox changes after one owner revision, oldest first.

deliverSessionGrantsToStorage()function

Section titled “deliverSessionGrantsToStorage()”
Signature
function deliverSessionGrantsToStorage(
storage,
sessionId,
delivery,
): GrantsDeliveryResult;

Deliver one Session’s grants into a Cloudflare owner’s own storage, synchronously, whether or not its runtime is open; the very next tool call reads it. A plain function, not a Durable Object method, so no other Durable Object can call it over RPC: only code running inside the owner, holding its storage, delivers grants.

Parameter Type
storage SqliteOwner
sessionId string
delivery GrantsDelivery

GrantsDeliveryResult


makeCloudflareShiitake()function

Section titled “makeCloudflareShiitake()”
Signature
function makeCloudflareShiitake(unnamed, options): Promise<CloudflareShiitake>;

Open Shiitake over one Durable Object’s storage. It resolves once the runtime is started and initialize has run; if initialize throws, the runtime is closed and the error is rethrown.

Parameter Type
unnamed CloudflareShiitakeState
options CloudflareShiitakeOptions

Promise<CloudflareShiitake>

Re-exports ColdSessionPage


Re-exports ColdSessionPageRequest


Re-exports ColdSessionRow


Re-exports GrantsDelivery


Re-exports GrantsDeliveryResult


Re-exports ShiitakeOwnerAgent


Re-exports ToolAccess