import { type RuntimeActionAttemptCompletion, type RuntimeActionAttemptStart, type RuntimeActionCompletion, type RuntimeCoordinationOffer, type RuntimeRunContext as ContractRuntimeRunContext, type RuntimeTargetAction, type RuntimeValueContext as ContractRuntimeValueContext, type SignalDerivation, type runtimeContract } from "@automate.ax/api-contract/runtime"; import { type Encodable } from "@automate.ax/codec"; import type { ContractRouterClient } from "@orpc/contract"; import type { ActionRuntime } from "./actions.js"; import type { AutomationDescriptor } from "./automation.js"; import type { IntegrationAccountConnectionOption } from "./integrations.js"; import { type AutomationError, type Signal } from "./signal-protocol.js"; /** Stable nested namespace containing one durable hook slot. */ export interface HookLocation { readonly scopePath: readonly number[]; readonly slot: number; } interface AutomationInvocationEnvironment { appOrigin: string; automationId: string; parameterValues?: Readonly>; projectId: string; } interface RuntimeContext extends AutomationInvocationEnvironment { apiOrigin: string; contextId: string; emailOriginToken: string; phase: "run"; token: string; } /** Read-only durable identity of the active automation execution. */ export interface AutomationExecutionIdentity { readonly automationId: string; readonly contextId: string; } /** Raised when replayed automation structure no longer matches durable state. */ export declare class AutomationCompatibilityError extends Error { name: string; } export interface PlanningContext { accountDeclarations: { binding: string; connectionOptionGroups?: readonly (readonly IntegrationAccountConnectionOption[])[]; serviceId: string; }[]; accountUses: ({ binding: string; connectionOptions: readonly IntegrationAccountConnectionOption[]; dynamic: false; serviceId: string; } | { connectionOptions: readonly IntegrationAccountConnectionOption[]; dynamic: true; serviceId: string; })[]; nextHookSlot: number; parameterIssues?: string[]; parameters?: import("@automate.ax/catalog").FormField[]; scopes: { name?: string; path: number[]; presentation: "collapsed" | "expanded" | "hidden"; }[]; subscriptions: { config: unknown; eventType: string; hookSlot: number; scopePath?: number[]; }[]; usesMarkSignificant?: boolean; } type RuntimeClient = ContractRouterClient; interface RuntimeValueClient { loadValues(input: Parameters[0]): Promise; } /** Runtime procedures available while one action handler is executing. */ type ActionRuntimeClient = Pick; interface RuntimeLoadResult { context: RuntimeRunContext; targetAction?: RuntimeTargetAction; } export type RuntimeRunContext = ContractRuntimeRunContext; export type RuntimeValueContext = ContractRuntimeValueContext; type RuntimeCommitInput = Parameters[0]; /** One action candidate accepted by the runtime commit contract. */ type CommittedActionInvocation = RuntimeCommitInput["actionInvocations"][number]; type CommittedCoordinationOffer = RuntimeCoordinationOffer; type CommittedRaceOffer = Extract; type CommittedCorrelationOffer = Extract; type CommittedCollectionOffer = Extract; type CommittedFanoutOffer = Extract; type CommittedFunnelOffer = Extract; /** Merge offer retained separately for planned evaluation adaptation. */ type CommittedMergeOffer = Extract; type CommittedSerializationOffer = Extract; type CommittedConcurrencyOffer = Extract; type CommittedTakeOffer = Extract; type CommittedRateLimitOffer = Extract; /** Defers literal input hashing while symbolic traversal continues. */ type PlannedActionInvocation = T extends { inputHash: string; } ? Omit & { inputHash: Promise; } : never; export type SignalEvaluationOutcome = { status: "closed"; } | { failure: AutomationError; status: "failed"; } | { status: "open"; }; export interface PlannedSignalEvaluation { actionDependencyIds: string[]; derivation: SignalDerivation | null; evaluate(context: RuntimeValueContext): SignalEvaluationOutcome; eventDependencyIds: string[]; scopePath: number[]; signalDependencyIds: string[]; slot: number; } export interface PlannedSignificanceEvaluation { actionDependencyIds: string[]; evaluate(context: RuntimeValueContext): boolean; eventDependencyIds: string[]; signalDependencyIds: string[]; } export interface PlannedCorrelationEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } export interface PlannedCollectionEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } export interface PlannedFanoutEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } export interface PlannedFunnelEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } export interface PlannedMergeEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): void; scopePath: number[]; } export interface PlannedSerializationEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } export interface PlannedConcurrencyEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } export interface PlannedTakeEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } export interface PlannedRateLimitEvaluation extends Omit { evaluate(this: void, context: RuntimeValueContext): Pick; scopePath: number[]; } type PlannedTerminalRaceEvaluation = Extract; export type PlannedRaceEvaluation = (Extract & { evaluate(this: void, context: RuntimeValueContext): void; }) | PlannedTerminalRaceEvaluation; export type PlannedCoordinationEvaluation = PlannedCollectionEvaluation | PlannedConcurrencyEvaluation | PlannedCorrelationEvaluation | PlannedFanoutEvaluation | PlannedFunnelEvaluation | PlannedMergeEvaluation | PlannedRateLimitEvaluation | PlannedRaceEvaluation | PlannedSerializationEvaluation | PlannedTakeEvaluation; export interface AutomationRunState { actionDeferred: boolean; actionExecution?: () => Promise; actionInvocations: PlannedActionInvocation[]; compatibilityChecks: Promise[]; completeAction(input: RuntimeActionCompletion): Promise; completeActionAttempt(input: RuntimeActionAttemptCompletion): Promise; context: RuntimeRunContext; coordinationEvaluations: PlannedCoordinationEvaluation[]; googleAdsRequest?: RuntimeClient["googleAdsRequest"]; initiatingSubscriptionSignals?: Signal[]; nextHookSlot: number; nonInitiatingSubscriptionOrigins?: Set; phase: "run"; resolveAccountInput: RuntimeClient["resolveAccountInput"]; runtime: ActionRuntime; signalEvaluations: PlannedSignalEvaluation[]; signalInvocations: RuntimeCommitInput["signalInvocations"]; significanceEvaluations: PlannedSignificanceEvaluation[]; startActionAttempt(replaySafety: "safe" | "unsafe"): Promise; targetAction?: Extract, { status: "pending"; }>; } interface InvocationStore { invocationEnvironment?: AutomationInvocationEnvironment; planningContext?: PlanningContext; runtimeContext?: RuntimeContext; runtimeState?: AutomationRunState; } export type AutomationRuntimeState = NonNullable; export type AutomationInvocationInput = (AutomationInvocationEnvironment & { phase: "planning"; }) | RuntimeContext; export interface AutomationInvocationResult { exitCode: number; files: Record; stderr: string; stdout: string; } export interface AutomationInvocationModule { default: AutomationDescriptor; } /** * Runs one automation phase inside an invocation-scoped runtime context. * * Warm Lambda environments may reuse the loaded descriptor, while mutable * platform state remains isolated to this asynchronous invocation. * * @param input - Planning or authenticated runtime phase details. * @param loadAutomation - Bundled automation loader evaluated in the context. */ export declare function runAutomationInvocation(input: AutomationInvocationInput, loadAutomation: () => Promise): Promise; /** * Runs an automation body locally or advances one durable runtime context. * * A runtime invocation executes at most one targeted action, then keeps * replaying inside the same sandbox while terminal decisions expose more work. * * @param fn - Automation body whose hook calls should be evaluated. * @throws When a pending target action has no matching hook slot. */ export declare function runAutomationFunction(fn: () => void): Promise; /** * Creates the bounded action capabilities backed by one runtime client. * * @param runtimeContext - Durable identity and signed email provenance. * @param client - Authenticated runtime transport used by action effects. */ export declare function createActionRuntime(runtimeContext: Pick & Partial>, client: ActionRuntimeClient): ActionRuntime; /** Returns the planning state associated with the current async invocation. */ export declare function getAutomationPlanningContext(): PlanningContext | undefined; /** Returns the runtime state associated with the current async invocation. */ export declare function getAutomationRuntimeState(): AutomationRunState | undefined; /** Returns endpoint identity available throughout planning and execution. */ export declare function getAutomationInvocationEnvironment(): AutomationInvocationEnvironment | undefined; /** * Returns the active automation and context IDs during runtime execution. * * Planning has no execution context, so this returns undefined in that phase. */ export declare function getAutomationExecutionIdentity(): AutomationExecutionIdentity | undefined; /** * Returns the durable identity that the next hook will consume without * reserving it, or undefined outside an active automation traversal. */ export declare function getNextHookLocation(): HookLocation | undefined; /** Returns the active nested hook namespace. */ export declare function getCurrentHookScopePath(): readonly number[]; /** * Reserves the next deterministic hook slot in the active planning or runtime * context. */ export declare function consumeHookSlot(): number; /** Reserves a deterministic declaration slot without shifting durable hooks. */ export declare function consumeDeclarationSlot(): number; /** Reserves the next durable hook identity in the active scope. */ export declare function consumeHookLocation(): HookLocation; /** * Tests whether a durable record belongs to one hook location. * * @param candidate - Durable record location. * @param location - Expected hook location. */ export declare function isSameHookLocation(candidate: HookLocation, location: HookLocation): boolean; /** * Formats one nested hook location for diagnostics and signal origins. * * @param location - Hook location to format. */ export declare function formatHookLocation(location: HookLocation): string; /** * Traverses a callback in a child hook namespace reserved from its parent. * * @param fn - Synchronous declaration callback. */ export declare function withHookScope(fn: () => TResult): TResult; /** * Sets planning state for SDK tests that exercise hooks directly. * * @param planningContext - Test planning state, or undefined to clear it. */ export declare function setAutomationPlanningContextForTest(planningContext: PlanningContext | undefined): void; /** * Sets runtime state for SDK tests that exercise hooks directly. * * @param runtimeState - Test runtime state, or undefined to clear it. */ export declare function setAutomationRuntimeStateForTest(runtimeState: AutomationRuntimeState | undefined): void; /** * Hydrates and evaluates every pure durable boundary discovered by one pass. * * @param state - Traversal state containing exact value demands. * @param client - Authenticated runtime transport. */ export declare function evaluateBoundaries(state: AutomationRunState, client: RuntimeValueClient): Promise<{ coordinationOffers: (PlannedTerminalRaceEvaluation | { actionDependencyIds: string[]; eventDependencyIds: string[]; scopePath: number[]; signalDependencyIds: string[]; slot: number; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; cohortActionDependencyIds: string[]; cohortEventDependencyIds: string[]; cohortOrigins: string[]; cohortSignalDependencyIds: string[]; inputOrigins: string[][]; outcomeSeq: number; policy: "race"; scopeOrigins: string[]; selectedIndex: number; status: "succeeded"; } | { scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; selectedIndex: number; policy: "merge"; inputOrigins: string[][]; } | { key?: Encodable; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; occurrenceTtl?: string | number | undefined; policy: "correlate"; ttl?: string | number | undefined; inputPolicies?: { consumption: "consume" | "retain"; selection: "oldest" | "latest"; }[] | undefined; ordered: boolean; streamIndex: number; streamOrigins: string[][]; } | { position?: number | undefined; count: number; key?: Encodable; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; occurrenceTtl?: string | number | undefined; policy: "collect"; primaryPosition: "first" | "last"; ttl?: string | number | undefined; } | { count: number; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; policy: "fanout"; } | { key?: Encodable; maxBurstDuration?: string | number | undefined; minGap?: string | number | undefined; minQuietPeriod?: string | number | undefined; until?: Date | undefined; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; policy: "funnel"; primaryPosition: "first" | "last"; ttl?: string | number | undefined; selection: "first" | "last" | "all"; triggerAt: "start" | "end" | "both"; } | { key?: Encodable; ttl?: string | number | undefined; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; count: number; policy: "take"; } | { key?: Encodable; interval: string | number; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; policy: "rateLimit"; limit: number; overflow: "drop" | "wait"; } | { key?: Encodable; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; policy: "serialize"; releaseScopePath: number[]; releaseSlot: number; sourceOrigins: string[]; } | { key?: Encodable; scopePath: number[]; outcomeSeq: number; actionDependencyIds: string[]; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; eventDependencyIds: string[]; signalDependencyIds: string[]; slot: number; policy: "concurrent"; limit: number; releaseScopePath: number[]; releaseSlot: number; sourceOrigins: string[]; })[]; significant: boolean; signalInvocations: ({ actionDependencyIds: string[]; eventDependencyIds: string[]; scopePath: number[]; signalDependencyIds: string[]; slot: number; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; status: "closed"; outcomeSeq?: number | undefined; } | { actionDependencyIds: string[]; eventDependencyIds: string[]; scopePath: number[]; signalDependencyIds: string[]; slot: number; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; failure: import("@automate.ax/api-contract").AutomationErrorValue; status: "failed"; outcomeSeq?: number | undefined; } | { actionDependencyIds: string[]; eventDependencyIds: string[]; scopePath: number[]; signalDependencyIds: string[]; slot: number; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; status: "open"; outcomeSeq?: number | undefined; } | { actionDependencyIds: string[]; eventDependencyIds: string[]; scopePath: number[]; signalDependencyIds: string[]; slot: number; derivation: { nodes: ({ id: string; source: "signal" | "action" | "event"; type: "source"; } | { inputs: number[]; property: string; type: "property"; } | { inputs: number[]; type: "transform"; })[]; roots: number[]; } | null; selectedIndex: number; status: "succeeded"; outcomeSeq?: number | undefined; })[]; }>; export {}; //# sourceMappingURL=runtime.d.ts.map