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.
Properties
Section titled “Properties”auth: object;Always signed out: getState() → { authenticated: false, user: null },
getIdToken() → null.
getIdToken
Section titled “getIdToken”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.
Returns
Section titled “Returns”Promise<string | null>
getState
Section titled “getState”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.
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string |
Returns
Section titled “Returns”object
exec: (sql, params?) => | CoworkDbExecResult| Promise<CoworkDbExecResult>;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sql |
string |
params? |
unknown[] |
Returns
Section titled “Returns”| CoworkDbExecResult
| Promise<CoworkDbExecResult>
query: (sql, params?) => | CoworkDbQueryResult| Promise<CoworkDbQueryResult>;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sql |
string |
params? |
unknown[] |
Returns
Section titled “Returns”| CoworkDbQueryResult
| Promise<CoworkDbQueryResult>
transaction
Section titled “transaction”transaction: <T>(fn) => T;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fn |
() => T |
Returns
Section titled “Returns”T
identity
Section titled “identity”identity: CoworkIdentity;An anonymous caller: user and organization null.
log: (...parts) => void;A line in the platform's log (stderr).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
...parts |
unknown[] |
Returns
Section titled “Returns”void
secrets
Section titled “secrets”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
Section titled “unchanged”unchanged: () => void;Does nothing: a deployed run keeps no run list to leave it out of.
Returns
Section titled “Returns”void
workspaceRoot
Section titled “workspaceRoot”workspaceRoot: string;The deployment's COWORK_WORKSPACE_ROOT, else "/" — a deployed routine has no workspace.