eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
103 lines (102 loc) • 4.88 kB
TypeScript
/** Shared owner-side dispatch context preparation. */
import type { ActivityObserverConfig } from "#channel/types.js";
import { type ChannelAdapter, type ChannelAdapterContext } from "#channel/adapter.js";
import { type LocalDevRequestProvenance } from "#context/keys.js";
import { ContextContainer } from "#context/container.js";
import { type CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
import type { RuntimeSession } from "#subagents/handle-dispatch.js";
import type { ActivityWorkIdentityV1 } from "#protocol/activity.js";
import type { RuntimeActionResult, RuntimeToolCallActionRequest, RuntimeWorkflowTaskRequest } from "#shared/action-types.js";
import type { SessionParent } from "#channel/types.js";
import { type DurableSessionState, readDurableSession } from "#execution/durable-session-store.js";
import { buildSubagentRunInput } from "#subagents/tool.js";
import type { WorkflowToolRunOwner } from "#execution/tools/workflow/messages.js";
export type DispatchPlanEntry = {
readonly kind: "task-control";
readonly action: RuntimeToolCallActionRequest;
} | {
readonly kind: "workflow-task";
readonly task: RuntimeWorkflowTaskRequest;
};
/** Input shared by direct and Workflow-originated owner-side dispatch. */
export interface CoordinationDispatchInput {
readonly callbackBaseUrl?: string;
readonly workflowToolRunOwner: WorkflowToolRunOwner;
readonly parentWritable: WritableStream<Uint8Array>;
readonly serializedContext: Record<string, unknown>;
readonly sessionState: DurableSessionState;
}
/** Owner-side results plus any task-control work that still needs acknowledgement. */
export interface CoordinationDispatchResult {
readonly results: readonly RuntimeActionResult[];
readonly sessionState: DurableSessionState;
readonly pendingTasks: readonly {
readonly taskInboxToken: string;
readonly taskId: string;
readonly taskRunId: string;
}[];
}
/** Everything preflight produces before either step's dispatch loop runs. */
export interface PreparedCoordinationDispatch<PlanEntry = DispatchPlanEntry> {
readonly adapter: ChannelAdapter;
readonly adapterCtx: ChannelAdapterContext;
readonly auth: Parameters<typeof buildSubagentRunInput>[0]["auth"];
readonly batch: DispatchBatch;
readonly bundle: CompiledBundle;
readonly capabilities: Parameters<typeof buildSubagentRunInput>[0]["capabilities"];
readonly channelMetadata: Parameters<typeof buildSubagentRunInput>[0]["channelMetadata"];
/** Number of local children sharing the parent's remaining token quota. */
readonly fanoutSize: number;
readonly initiatorAuth: Parameters<typeof buildSubagentRunInput>[0]["initiatorAuth"];
readonly localDevRequest?: LocalDevRequestProvenance;
/** Lineage of the session running this dispatch, when it is itself a delegated child. */
readonly parentSession: SessionParent | undefined;
readonly activityObserver?: ActivityObserverConfig & {
readonly workIdentity: ActivityWorkIdentityV1;
};
readonly sandboxSessionId: string;
readonly serializedContext: Record<string, unknown>;
readonly plan: readonly PlanEntry[];
readonly session: RuntimeSession;
readonly sessionState: DurableSessionState;
}
/**
* Runs every dispatch precondition that may throw — durable reads, context
* deserialization, handle-store validation, and batch planning — before
* the caller acquires the parent stream writer, so a preflight failure
* never leaks the writer lock. Returns undefined when no actions are
* pending.
*/
export declare function prepareCoordinationDispatch(input: {
readonly serializedContext: Record<string, unknown>;
readonly sessionState: DurableSessionState;
}): Promise<PreparedCoordinationDispatch | undefined>;
interface DispatchBatch {
readonly event: {
readonly sequence: number;
readonly stepIndex: number;
readonly turnId: string;
};
readonly localFanoutSize?: number;
readonly requests: readonly {
readonly callId: string;
}[];
}
export declare function prepareActionDispatch<PlanEntry>(input: {
readonly batch: DispatchBatch;
readonly ctx: ContextContainer;
readonly durableSession: Awaited<ReturnType<typeof readDurableSession>>;
readonly fanoutSize?: number;
readonly plan: (input: {
readonly bundle: CompiledBundle;
readonly ctx: ContextContainer;
readonly requests: DispatchBatch["requests"];
readonly session: RuntimeSession;
}) => readonly PlanEntry[];
readonly planSharesSandbox?: (input: {
readonly bundle: CompiledBundle;
readonly plan: readonly PlanEntry[];
}) => boolean;
readonly serializedContext: Record<string, unknown>;
}): Promise<Omit<PreparedCoordinationDispatch<PlanEntry>, "sessionState">>;
export {};