import { A as WorkflowDefinition, At as NodeId, B as RunStopCondition, C as NodeOutputs, Ct as WebhookTriggerMatcher, E as RunId, F as RunCurrentState, H as WebhookRunResult, I as RunExecutionOptions, M as NodeInputsByPort, P as PersistedWorkflowTokenRegistryLike, R as RunResult, St as WebhookInvocationMatch, U as WorkflowExecutionRepository, b as NodeActivationId, f as ResumeContext, j as CurrentStateExecutionRequest, jt as WorkflowId, l as NodeExecutionRequest, m as WorkflowSnapshotResolver, o as LiveWorkflowRepository, p as WorkflowRepository, s as NodeActivationContinuation, u as NodeExecutionRequestHandler, v as Items, w as ParentExecutionRef, wt as WebhookTriggerResolution, xt as HttpMethod } from "./ItemsInputNormalizer-CFkfNMLt.js";
import { ZodType } from "zod";

//#region ../core/src/contracts/Clock.d.ts
/** Port for time; inject `SystemClock` in production and a fake/test clock in tests. */
interface Clock {
  now(): Date;
}
//#endregion
//#region ../core/src/authoring/defineCollection.types.d.ts
type CollectionFieldType = "text" | "int" | "bigint" | "double" | "bool" | "timestamptz" | "jsonb" | "uuid";
interface CollectionFieldDefinition {
  readonly type: CollectionFieldType;
  readonly nullable: boolean;
  readonly default?: unknown;
}
interface CollectionIndexDefinition {
  readonly on: ReadonlyArray<string>;
  readonly unique?: boolean;
}
interface CollectionDefinition {
  readonly name: string;
  readonly fields: Readonly<Record<string, CollectionFieldDefinition>>;
  readonly indexes: ReadonlyArray<CollectionIndexDefinition>;
}
interface DefinedCollection<TDefinition extends CollectionDefinition = CollectionDefinition> {
  readonly kind: "defined-collection";
  readonly definition: TDefinition;
  register(context: {
    registerCollection(d: CollectionDefinition): void;
  }): void;
}
//#endregion
//#region ../core/src/orchestration/Engine.d.ts
interface EngineTriggerRuntime {
  startTriggers(): Promise<void>;
  stop(): Promise<void>;
  syncWorkflowTriggersForActivation(workflowId: WorkflowId): Promise<void>;
  createTriggerTestItems(args: {
    workflow: WorkflowDefinition;
    nodeId: NodeId;
  }): Promise<Items | undefined>;
}
interface EngineRunStartService {
  runWorkflow(wf: WorkflowDefinition, startAt: NodeId, items: Items, parent?: ParentExecutionRef, executionOptions?: RunExecutionOptions, persistedStateOverrides?: Readonly<{
    workflowSnapshot?: NonNullable<Awaited<ReturnType<WorkflowExecutionRepository["load"]>>>["workflowSnapshot"];
    mutableState?: NonNullable<Awaited<ReturnType<WorkflowExecutionRepository["load"]>>>["mutableState"];
  }>): Promise<RunResult>;
  runWorkflowFromState(request: CurrentStateExecutionRequest): Promise<RunResult>;
}
interface EngineRunContinuationService {
  markNodeRunning(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    inputsByPort: NodeInputsByPort;
  }): Promise<void>;
  resumeFromNodeResult(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    outputs: NodeOutputs;
  }): Promise<RunResult>;
  resumeFromNodeError(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    error: Error;
  }): Promise<RunResult>;
  resumeFromStepResult(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    outputs: NodeOutputs;
  }): Promise<RunResult>;
  resumeFromStepError(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    error: Error;
  }): Promise<RunResult>;
  waitForCompletion(runId: RunId): Promise<Extract<RunResult, {
    status: "completed" | "failed" | "halted";
  }>>;
  waitForWebhookResponse(runId: RunId): Promise<WebhookRunResult>;
  resumeRun(args: {
    runId: RunId;
    taskId: string;
    resumeContext: ResumeContext;
  }): Promise<RunResult>;
}
interface EngineNodeExecutionRequestHandler {
  handleNodeExecutionRequest(request: NodeExecutionRequest): Promise<void>;
}
interface EngineFacadeDeps {
  liveWorkflowRepository: LiveWorkflowRepository;
  tokenRegistry: PersistedWorkflowTokenRegistryLike;
  webhookTriggerMatcher: WebhookTriggerMatcher;
  workflowSnapshotResolver: WorkflowSnapshotResolver;
  triggerRuntime: EngineTriggerRuntime;
  runStartService: EngineRunStartService;
  runContinuationService: EngineRunContinuationService;
  nodeExecutionRequestHandler: EngineNodeExecutionRequestHandler;
}
/**
 * Runtime facade for orchestration, continuation, triggers, and webhook routing.
 * Prefer {@link import("../intents/RunIntentService").RunIntentService} for host/HTTP invocation boundaries.
 * The class token is exported from `@codemation/core/bootstrap` (not the main `@codemation/core` barrel).
 */
declare class Engine implements NodeActivationContinuation, NodeExecutionRequestHandler {
  private readonly deps;
  constructor(deps: EngineFacadeDeps);
  loadWorkflows(workflows: ReadonlyArray<WorkflowDefinition>): void;
  getTokenRegistry(): EngineFacadeDeps["tokenRegistry"];
  resolveWorkflowSnapshot(args: {
    workflowId: WorkflowId;
    workflowSnapshot?: NonNullable<Awaited<ReturnType<WorkflowExecutionRepository["load"]>>>["workflowSnapshot"];
  }): WorkflowDefinition | undefined;
  startTriggers(): Promise<void>;
  syncWorkflowTriggersForActivation(workflowId: WorkflowId): Promise<void>;
  start(workflows: WorkflowDefinition[]): Promise<void>;
  stop(): Promise<void>;
  resolveWebhookTrigger(args: {
    endpointPath: string;
    method: HttpMethod;
  }): WebhookTriggerResolution;
  createTriggerTestItems(args: {
    workflow: WorkflowDefinition;
    nodeId: NodeId;
  }): Promise<Items | undefined>;
  runWorkflow(wf: WorkflowDefinition, startAt: NodeId, items: Items, parent?: ParentExecutionRef, executionOptions?: RunExecutionOptions, persistedStateOverrides?: Readonly<{
    workflowSnapshot?: NonNullable<Awaited<ReturnType<WorkflowExecutionRepository["load"]>>>["workflowSnapshot"];
    mutableState?: NonNullable<Awaited<ReturnType<WorkflowExecutionRepository["load"]>>>["mutableState"];
  }>): Promise<RunResult>;
  runWorkflowFromState(request: CurrentStateExecutionRequest): Promise<RunResult>;
  markNodeRunning(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    inputsByPort: NodeInputsByPort;
  }): Promise<void>;
  resumeFromNodeResult(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    outputs: NodeOutputs;
  }): Promise<RunResult>;
  resumeFromNodeError(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    error: Error;
  }): Promise<RunResult>;
  resumeFromStepResult(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    outputs: NodeOutputs;
  }): Promise<RunResult>;
  resumeFromStepError(args: {
    runId: RunId;
    activationId: NodeActivationId;
    nodeId: NodeId;
    error: Error;
  }): Promise<RunResult>;
  waitForCompletion(runId: RunId): Promise<Extract<RunResult, {
    status: "completed" | "failed" | "halted";
  }>>;
  waitForWebhookResponse(runId: RunId): Promise<WebhookRunResult>;
  /**
   * Re-activate a suspended run item with a human decision (HITL).
   * The HTTP resume endpoint calls this; this method exposes the engine primitive.
   */
  resumeRun(args: {
    runId: RunId;
    taskId: string;
    resumeContext: ResumeContext;
  }): Promise<RunResult>;
  handleNodeExecutionRequest(request: NodeExecutionRequest): Promise<void>;
}
//#endregion
//#region ../core/src/runtime/RunIntentService.d.ts
type StartWorkflowIntent = {
  workflow: WorkflowDefinition;
  startAt?: string;
  items: Items;
  synthesizeTriggerItems?: boolean;
  parent?: CurrentStateExecutionRequest["parent"];
  executionOptions?: RunExecutionOptions;
  workflowSnapshot?: CurrentStateExecutionRequest["workflowSnapshot"];
  mutableState?: CurrentStateExecutionRequest["mutableState"];
  currentState?: RunCurrentState;
  stopCondition?: RunStopCondition;
  reset?: CurrentStateExecutionRequest["reset"];
};
type RerunFromNodeIntent = {
  workflow: WorkflowDefinition;
  nodeId: NodeId;
  currentState: RunCurrentState;
  items?: Items;
  synthesizeTriggerItems?: boolean;
  parent?: CurrentStateExecutionRequest["parent"];
  executionOptions?: RunExecutionOptions;
  workflowSnapshot?: CurrentStateExecutionRequest["workflowSnapshot"];
  mutableState?: CurrentStateExecutionRequest["mutableState"];
};
type MatchedWebhookRunIntent = {
  endpointPath: string;
  method: HttpMethod;
  requestItem: Items[number];
};
type WebhookMatchRunIntent = {
  match: WebhookInvocationMatch;
  requestItem: Items[number];
};
declare class RunIntentService {
  private readonly engine;
  private readonly workflowRepository;
  constructor(engine: Engine, workflowRepository: WorkflowRepository);
  startWorkflow(args: StartWorkflowIntent): Promise<RunResult>;
  rerunFromNode(args: RerunFromNodeIntent): Promise<RunResult>;
  private resolveStartWorkflowItems;
  private resolveRerunItems;
  private resolveStartWorkflowTriggerNodeId;
  private resolveRerunTriggerNodeId;
  private firstTriggerNodeId;
  private isTriggerNode;
  private hasNonEmptyItems;
  resolveWebhookTrigger(args: {
    endpointPath: string;
    method: HttpMethod;
  }): WebhookTriggerResolution;
  runMatchedWebhook(args: MatchedWebhookRunIntent): Promise<WebhookRunResult>;
  runWebhookMatch(args: WebhookMatchRunIntent): Promise<WebhookRunResult>;
  /**
   * Webhook-triggered runs always force inline execution first.
   * This is the highest-precedence scheduler override: it wins over node hints and container defaults.
   */
  private createWebhookExecutionOptions;
}
//#endregion
//#region ../core/src/credentials/OAuthFlowExecutor.types.d.ts
/**
 * Four-concept model for credentials (see docs/design/credentials-oauth-unification.md):
 *   1. CredentialType — schema for stored material (e.g. "oauth.google.gmail").
 *   2. Credential slot requirement — which types a node or MCP server accepts.
 *   3. CredentialInstance — a stored, usable token row in the host's credential store.
 *   4. OAuthFlowExecutor (this file) — the only concept that differs between deployment
 *      modes. DI selects one implementation at boot; the rest of the system programs
 *      against this interface alone.
 */
interface OAuthFlowStartArgs {
  readonly typeId: string;
  readonly scopes: ReadonlyArray<string>;
  readonly redirectUri: string;
  readonly instanceId?: string;
}
interface OAuthFlowStartResult {
  readonly consentUrl: string;
  readonly stateToken: string;
}
interface OAuthFlowCallbackArgs {
  readonly stateToken: string;
  readonly code: string;
}
interface OAuthMaterial {
  readonly accessToken: string;
  readonly refreshToken?: string;
  readonly expiresAt?: string;
  readonly grantedScopes: ReadonlyArray<string>;
}
interface OAuthFlowExecutor {
  start(args: OAuthFlowStartArgs): Promise<OAuthFlowStartResult>;
  /**
   * Returns the instanceId associated with a pending stateToken without consuming it.
   * Used by callback routes to identify the target instance before calling completeCallback.
   * Returns undefined when the stateToken is unknown or already consumed.
   */
  lookupInstanceId(stateToken: string): string | undefined;
  completeCallback(args: OAuthFlowCallbackArgs): Promise<OAuthMaterial>;
  refresh(args: {
    typeId: string;
    instanceId: string;
    material: OAuthMaterial;
  }): Promise<OAuthMaterial>;
}
//#endregion
//#region ../core/src/credentials/CredentialMaterialProvider.types.d.ts
/**
 * Material provider seam — see `docs/design/credentials-oauth-unification.md`,
 * "Material provider seam" section. Sits beside the workspace's
 * `CredentialStore`; persistence of the row stays at the store, persistence of
 * the bytes goes through this provider so they can live at the control plane
 * in managed mode.
 */
/**
 * Pointer to material bytes. For local rows `ref` is the workspace instance id
 * and the bytes co-locate with the row (existing `CredentialOAuth2Material` /
 * `CredentialSecretMaterial` tables). For control-plane rows `ref` is the
 * CP-side credential id; the workspace stores only the pointer.
 */
type CredentialMaterialRef = Readonly<{
  source: "local" | "control-plane";
  id: string;
}>;
/**
 * Decrypted material bytes returned by a provider. Shape matches
 * `OAuthMaterial` — every supported credential type today is OAuth-shaped.
 */
type MaterialBundle = OAuthMaterial;
/**
 * Caller context recorded by the CP material endpoint per fetch (D5 in the
 * `credentials-vault` sprint README). The local provider accepts but ignores
 * it; standalone mode has no audit log.
 */
type CallerContext = Readonly<{
  workspaceId: string;
  caller: Readonly<{
    kind: "workflow-node";
    workflowId: string;
    nodeId: string;
  }> | Readonly<{
    kind: "concierge";
    chatId: string;
  }> | Readonly<{
    kind: "research-agent";
    chatId: string;
  }> | Readonly<{
    kind: "manual";
    userId: string;
  }>;
  reason?: string;
}>;
interface CredentialMaterialProvider {
  getMaterial(ref: CredentialMaterialRef, context: CallerContext): Promise<MaterialBundle>;
  setMaterial(ref: CredentialMaterialRef, material: MaterialBundle): Promise<void>;
}
//#endregion
export { CollectionDefinition as a, Engine as i, OAuthFlowExecutor as n, DefinedCollection as o, RunIntentService as r, Clock as s, CredentialMaterialProvider as t };
//# sourceMappingURL=index-ChIfeWzk.d.ts.map