Skip to content

TaskRuntime

The service a running phase handler or abort handler uses to advance its task. It is provided to every handler and is bound to that one invocation: once the invocation ends, its operations fail with InvocationEnded.

Since v0.0.0


Failures of the runtime’s committed reads.

Signature

type ReadError = StorageFailure | SessionPoisoned | InvocationEnded

Source

Since v0.0.0

Signature

declare class TaskRuntime

Source

Since v0.0.0

Signature

export interface TaskRuntimeShape {
readonly taskId: TaskId
readonly conversationId: ConversationId
/** `run` for phase handlers; `abort` for the abort handler, which cannot wait. */
readonly mode: "run" | "abort"
/**
* Run `body` as one atomic commit with `Tx` provided. When it returns a `Next`, the task's state is replaced in
* the same commit; returning nothing leaves it unchanged.
*/
readonly commit: <E, R>(
body: Effect.Effect<Next<any, any> | void, E, R>
) => Effect.Effect<void, E | TaskCommitError, Exclude<R, Tx>>
/** The memo's committed value, if any. */
readonly readMemo: (name: string) => Effect.Effect<Option.Option<Json>, InvocationEnded>
/** First writer wins: stores `candidate` unless the memo exists; returns the durable winner. */
readonly memo: (name: string, candidate: Json) => Effect.Effect<Json, TaskCommitError>
/** The committed task record. */
readonly getTask: (id: TaskId) => Effect.Effect<Option.Option<TaskRecord>, ReadError>
/** Wait for a terminal receipt; for example, a child task that a tool created. */
readonly waitForTask: (id: TaskId) => Effect.Effect<TaskRecord, TaskNotFound | SchedulerClosed | ReadError>
/** Outcomes of terminal tasks, in order. Used after a wait. */
readonly outcomes: (
ids: ReadonlyArray<TaskId>
) => Effect.Effect<ReadonlyArray<TaskOutcome>, TaskNotFound | TaskNotTerminal | ReadError>
/** Wait until the clock reaches `until` (epoch milliseconds). Resumes correctly after a restart. */
readonly sleep: (until: number) => Effect.Effect<void, InvocationEnded>
/** The clock, in epoch milliseconds. */
readonly now: Effect.Effect<number, InvocationEnded>
/**
* A handle bound to this invocation for an existing conversation, such as a subagent's; `None` when it does not
* exist. See `ConversationHandle`.
*/
readonly conversation: (id: ConversationId) => Effect.Effect<Option.Option<ConversationHandle>, ReadError>
}

Source

Since v0.0.0

Signature

declare const commit: <E, R>(body: Effect.Effect<Next<any, any> | void, E, R>) => any

Source

Since v0.0.0

An invocation-bound handle of an existing conversation; see TaskRuntimeShape.conversation.

Signature

declare const conversation: (id: ConversationId) => any

Source

Since v0.0.0

Signature

declare const getTask: (id: TaskId) => any

Source

Since v0.0.0

Signature

declare const memo: (name: string, candidate: Json) => any

Source

Since v0.0.0

Signature

declare const now: Effect.Effect<number, InvocationEnded, TaskRuntime>

Source

Since v0.0.0

Signature

declare const outcomes: (ids: ReadonlyArray<TaskId>) => any

Source

Since v0.0.0

Signature

declare const readMemo: (name: string) => any

Source

Since v0.0.0

Signature

declare const sleep: (until: number) => any

Source

Since v0.0.0

The id of the running task.

Signature

declare const taskId: Effect.Effect<any, never, TaskRuntime>

Source

Since v0.0.0

Signature

declare const waitForTask: (id: TaskId) => any

Source

Since v0.0.0