Skip to content

CoworkDeployedRoutineContext

The context a DEPLOYED routine receives (cowork deploy — it runs on a server, not on this computer): a subset of CoworkRoutineContext. There is no Cowork around it, so it has no sign-in, no account secrets, no data folder and no consent prompts — calling a member that is not here fails.

auth: object;

Always signed out: getState() → { authenticated: false, user: null }, getIdToken() → null.

getIdToken: () => Promise<string | null>;

The ID token to call an authenticated API with — null when signed out, or when the token is too close to expiring to be trusted.

Promise<string | null>

getState: () => Promise<{
authenticated: boolean;
user: | {
displayName: string | null;
email: string | null;
uid: string;
}
| null;
}>;

authenticated and the account (user), or user: null when nobody is signed in.

Promise<{ authenticated: boolean; user: | { displayName: string | null; email: string | null; uid: string; } | null; }>


db?: (path) => object;

A SQLite database where the target has one: in a container, files under its data folder (COWORK_DATA_DIR, default /data) — synchronous; on a Cloudflare Worker deployed with a D1 database, that database whatever the path — query/exec return Promises (await them and the routine runs on both) and transaction throws. Absent elsewhere.

Parameter Type
path string

object

exec: (sql, params?) =>
| CoworkDbExecResult
| Promise<CoworkDbExecResult>;
Parameter Type
sql string
params? unknown[]

| CoworkDbExecResult | Promise<CoworkDbExecResult>

query: (sql, params?) =>
| CoworkDbQueryResult
| Promise<CoworkDbQueryResult>;
Parameter Type
sql string
params? unknown[]

| CoworkDbQueryResult | Promise<CoworkDbQueryResult>

transaction: <T>(fn) => T;
Type Parameter
T
Parameter Type
fn () => T

T


identity: CoworkIdentity;

An anonymous caller: user and organization null.


log: (...parts) => void;

A line in the platform's log (stderr).

Parameter Type
...parts unknown[]

void


secrets: Pick<CoworkRoutineContext["secrets"], "get" | "list">;

The deployment's environment: get(name) is the variable of that name (the secrets you deployed with are set there); list() the names of those secrets.


unchanged: () => void;

Does nothing: a deployed run keeps no run list to leave it out of.

void


workspaceRoot: string;

The deployment's COWORK_WORKSPACE_ROOT, else "/" — a deployed routine has no workspace.