import { x as ActionDefinition, y as ActionServices } from '../decompile-BNprXLsA.mjs';
export { D as ActionContext, G as ActionResult, I as ActorConstraint, A as AuthorizationResult, B as BaseUcanFlow, K as CompiledBlock, L as CompiledEdge, v as CompiledFlow, P as CompiledFlowNode, C as CompilerRegistry, H as ConditionRef, E as ExecuteNodeParams, f as ExecutionContext, d as ExecutionOutcome, u as FlowCapability, F as FlowRuntimeStateManager, w as FlowStrategy, M as MergeResult, N as NodeActionResult, O as OutputSchemaField, R as ReadFlowOptions, q as ReadFlowResult, J as RuntimeRef, S as SetupFlowOptions, p as SetupFlowResult, T as TTLConstraint, Q as TriggerSpec, a as buildAuthzFromProps, b as buildFlowNodeFromBlock, z as clearRuntimeForTemplateClone, l as compileBaseUcanFlow, c as createRuntimeStateManager, o as decompileToBaseUcanFlow, e as executeNode, k as getActiveEditor, i as isAuthorized, U as isRuntimeRef, n as mergeCompiledFlows, m as readCompiledFlowFromYDoc, h as readFlow, r as readFlowAsBaseUcan, g as readFlowFromEditor, j as setActiveEditor, s as setupFlowFromBaseUcan } from '../decompile-BNprXLsA.mjs';
import { s as IxoEditorType } from '../index-CNCZs4wP.mjs';
export { C as ClaimCollectionURI, G as CreateDelegationParams, H as CreateInvocationParams, B as CreateRootDelegationParams, t as DID, D as DelegationChainValidationResult, k as DelegationGrant, E as EvaluationStatus, z as ExecutionWithInvocationResult, A as FindProofsResult, w as FlowNode, F as FlowNodeAuthzExtension, v as FlowNodeBase, u as FlowNodeRuntimeState, x as InvocationRequest, y as InvocationResult, I as InvocationStore, L as LinkedClaim, N as NodeState, S as StoredDelegation, j as StoredInvocation, i as UcanCapability, U as UcanDelegationStore, f as UcanService, g as UcanServiceConfig, h as UcanServiceHandlers, b as createInvocationStore, d as createMemoryInvocationStore, a as createMemoryUcanDelegationStore, c as createUcanDelegationStore, e as createUcanService } from '../index-CNCZs4wP.mjs';
import * as Y from 'yjs';
import 'matrix-js-sdk';
import '@blocknote/core';
import 'react';
import '@ixo/ucan';

declare function registerAction<TInputs extends Record<string, any> = Record<string, any>>(definition: ActionDefinition<TInputs>): void;
declare function getAction(type: string): ActionDefinition | undefined;
declare function getAllActions(): ActionDefinition[];
declare function hasAction(type: string): boolean;
/** Look up an action by its UCAN `can` ability string, e.g., "bid/submit". */
declare function getActionByCan(can: string): ActionDefinition | undefined;

/**
 * Bidirectional mapping between UCAN `can` vocabulary and registry `type` strings.
 * Derived mechanically: strip "qi/", replace "." with "/".
 */
/** Resolve a `can` ability string to the registry `type` string. */
declare function canToType(can: string): string | undefined;
/** Resolve a registry `type` string to the `can` ability string. */
declare function typeToCan(type: string): string | undefined;
/** Get all registered can↔type mappings. */
declare function getAllCanMappings(): ReadonlyArray<{
    can: string;
    type: string;
}>;

/**
 * Builds an ActionServices map from BlocknoteHandlers.
 * Used by block components to bridge existing DI into registry calls.
 *
 * The handlers parameter is typed as `any` to avoid a circular dependency
 * between core and mantine layers — BlocknoteHandlers is defined in mantine/context.
 */
declare function buildServicesFromHandlers(handlers: any): ActionServices;

/**
 * Run record stored in the audit trail as `type: 'block.run'`.
 *
 * Per Phase 0 #2 (eng review pass 2), run records are NOT a parallel
 * `_yRunHistory` structure — they ride on the existing `auditTrail` Y.Map
 * via `useAuditTrail.addEvent`. The shape below is what goes into the
 * audit trail event's `details` field.
 *
 * See `docs/events-and-triggers-plan.md` §3.4, §18, §19.
 */
interface RunRecordDetails {
    /** Stable identifier for this run, deterministic from invocation context. */
    runId: string;
    /** Action's output. */
    output: Record<string, unknown>;
    /**
     * Events the action emitted on this run. Persisted as part of the run
     * record so the reconciliation loop can process them idempotently — even
     * across page refreshes and across multiple clients.
     */
    events: Array<{
        name: string;
        payload: Record<string, unknown>;
    }>;
    /** ISO timestamp when the action started. */
    startedAt: string;
    /** ISO timestamp when the action completed (success or failure). */
    completedAt: string;
    /** DID of the actor who signed the invocation that produced this run. */
    actorDid: string;
    /** Optional error if the run failed. */
    error?: {
        message: string;
        code?: string;
    };
    /**
     * If this run was triggered by a pending invocation (i.e. it's a listener
     * run), the id of that pending invocation. Used to dedup replays and trace
     * causality back through `triggeredBy`.
     */
    fromPendingInvocationId?: string;
    /**
     * If this run is a listener run, the (sourceBlockId, eventName) that
     * caused it. Used by the failure visibility surface to attribute failures
     * back to the source block (CP-1).
     */
    triggeredBy?: {
        sourceBlockId: string;
        eventName: string;
    };
}
declare const RUN_RECORD_AUDIT_TYPE = "block.run";
/**
 * Pending invocation queued on a listener block.
 *
 * Stored in `_yPendingInvocations: Y.Map<blockId, Y.Map<id, PendingInvocation>>`.
 *
 * The id is deterministic — derived from
 * `(sourceBlockId, sourceRunId, listenerBlockId, eventName, eventIndex)` —
 * so the reconciliation loop can run idempotently from multiple clients
 * without producing duplicates.
 *
 * See `docs/events-and-triggers-plan.md` §3.4, §3.5.1, §18.
 */
interface PendingInvocation {
    /** Deterministic id, see `computePendingInvocationId`. */
    id: string;
    /** Block that emitted the event. */
    triggeringBlockId: string;
    /** Run id of the triggering source run, used for the deterministic id. */
    sourceRunId: string;
    /** Event name from the source action's vocabulary. */
    eventName: string;
    /** Event index within the source run's `events` array (a single run can emit multiple). */
    eventIndex: number;
    /**
     * The frozen event payload, captured by value at emission time. The
     * assignee invokes the listener against this payload, not against the
     * source block's current state. This is the property that makes the
     * Sally → Mike scenario produce 10 distinct emails even when Mike acts
     * on them all hours later.
     */
    payload: Record<string, unknown>;
    /**
     * Snapshots of `nodeId.output.*` ref values that the listener's inputs
     * reference, captured at queue time. Keyed by the full ref string.
     *
     * §3.5.1: ref snapshots are the load-bearing fix for the lag-time
     * overwrite scenario. If a listener references a non-trigger block's
     * output (e.g. `evaluateBlock.output.claimId`), that value is captured
     * here at queue time. Resolution at invocation time prefers the snapshot
     * over current state, so multiple queued invocations don't drift when
     * the source re-runs.
     */
    refSnapshots: Record<string, unknown>;
    /** DID of the assigned actor who must invoke this listener. Resolved from `props.assignment.assignedActor.did`. */
    assigneeDid: string;
    /** ISO timestamp when the source emission happened. */
    emittedAt: string;
    /** ISO timestamp after which this pending invocation is considered expired. Resolved from `FlowCapability.ttl` at queue time. */
    expiresAt: string;
}
/**
 * Compute a deterministic id for a pending invocation from its content.
 *
 * The same (sourceBlockId, sourceRunId, listenerBlockId, eventName,
 * eventIndex) tuple always produces the same id. This is the property that
 * makes the reconciliation loop idempotent — re-running it from a different
 * client, or after a page refresh, produces the same `Y.Map.set` operation
 * with the same key, which Yjs converges to a single entry.
 *
 * Implementation: simple deterministic string concatenation, hashed via a
 * 32-bit FNV-1a. The id is short and stable; collision risk within a single
 * flow is negligible because the inputs are scoped (block ids are unique
 * within a flow, run ids are unique within a block).
 */
declare function computePendingInvocationId(args: {
    sourceBlockId: string;
    sourceRunId: string;
    listenerBlockId: string;
    eventName: string;
    eventIndex: number;
}): string;
/**
 * Walk an inputs object and collect every RuntimeRef of the form
 * `nodeId.output.fieldPath`. Returns a map of `{refString: resolvedValue}`
 * suitable for storing as `PendingInvocation.refSnapshots`.
 *
 * The walker mirrors `resolveRuntimeRefs` in `flowCompiler/resolveRefs.ts`
 * but reads instead of resolving — it captures the current value of each
 * ref so the listener can later resolve against the snapshot rather than
 * against current state.
 *
 * See `docs/events-and-triggers-plan.md` §3.5.1.
 */
declare function snapshotInputRefs(inputs: unknown, getNodeOutput: (nodeId: string) => Record<string, unknown> | undefined): Record<string, unknown>;
/**
 * Get the top-level pending invocations Y.Map from the editor's yDoc.
 * Lazily creates it if missing.
 *
 * Shape: `Y.Map<blockId, Y.Map<pendingInvocationId, PendingInvocation>>`.
 * The outer map is keyed by listener block id; the inner map is keyed by
 * deterministic pending invocation id (see `computePendingInvocationId`).
 */
declare function getPendingInvocationsMap(yDoc: Y.Doc): Y.Map<Y.Map<unknown>>;
/**
 * Get the inner pending-invocations map for a specific listener block.
 * Lazily creates it if missing. Caller is responsible for being inside a
 * Yjs transaction if atomic creation matters.
 */
declare function getOrCreateBlockPendingMap(yDoc: Y.Doc, blockId: string): Y.Map<unknown>;
/**
 * Read all pending invocations for a block as plain JS objects.
 * Returns an array sorted by `emittedAt` ascending (oldest first).
 */
declare function readPendingInvocations(yDoc: Y.Doc, blockId: string): PendingInvocation[];
/**
 * Idempotently write a pending invocation under its deterministic id.
 *
 * Returns true if a new entry was created, false if the id already
 * existed (meaning another client or a previous reconciliation pass
 * already queued this invocation). This is the property that makes
 * `reconcilePendingInvocations` safe to run from multiple clients
 * simultaneously and across page refreshes — see plan §18.
 *
 * Wraps the write in a Yjs transaction so the existence check and the
 * subsequent set are atomic from the local client's perspective. Concurrent
 * clients each computing the same id will all converge to a single entry
 * because Y.Map.set with the same key is last-writer-wins on identical
 * content.
 */
declare function queuePendingInvocation(yDoc: Y.Doc, listenerBlockId: string, invocation: PendingInvocation): boolean;
/**
 * Remove a pending invocation by id. Used when the assignee completes the
 * invocation (transitioning to a `block.run` audit trail entry) or when
 * the expiration sweep marks it as expired.
 */
declare function removePendingInvocation(yDoc: Y.Doc, listenerBlockId: string, pendingInvocationId: string): boolean;
/**
 * Append a run record to the audit trail for a block. Run records are
 * stored as audit trail events with `type: 'block.run'` and the structured
 * data in `details`. Per Phase 0 #2 of eng review pass 2, this avoids
 * inventing a parallel `_yRunHistory` storage system.
 *
 * Y.Array.push from concurrent clients merges correctly — verified by the
 * existing `useAuditTrail` shipping in production.
 */
declare function appendRunRecord(yDoc: Y.Doc, blockId: string, details: RunRecordDetails, userId: string): void;
/**
 * Read all run records for a block from the audit trail. Filters audit
 * trail entries to only those with `type: 'block.run'`.
 */
declare function readRunRecords(yDoc: Y.Doc, blockId: string): RunRecordDetails[];
/**
 * A failed listener run, attributed to the source block emission that
 * triggered it. Used by the failure visibility surface (CP-1) on source
 * blocks: the source block can show "N listeners failed for your last run".
 */
interface FailedListenerRun {
    /** Block id of the listener whose run failed. */
    listenerBlockId: string;
    /** The full RunRecordDetails of the failed listener invocation. */
    record: RunRecordDetails;
}
/**
 * Find all failed listener runs that were triggered by a specific source
 * block run. Walks every block's audit trail, filters to listener runs
 * triggered by (sourceBlockId, sourceRunId), and returns the ones with an
 * error set.
 *
 * Used by the source block UI to show a failure badge linked to a specific
 * run — if Sally evaluates 10 claims and 2 of Mike's emails fail, Sally
 * sees "2 failed listeners on claim-G" rather than discovering it days
 * later in the email service logs.
 */
declare function findFailedListenersForSourceRun(yDoc: Y.Doc, sourceBlockId: string, sourceRunId: string, listenerBlockIds: string[]): FailedListenerRun[];
/**
 * Replay a previously failed listener run by re-queueing a pending
 * invocation with the same content. Reuses the original frozen payload
 * and ref snapshots from the failed run record's audit trail entry, so the
 * replay sees exactly the same data the original invocation saw.
 *
 * CP-2 from the plan. Used by the replay button in the failure visibility
 * surface. Returns true if a new pending invocation was queued.
 *
 * Note: replay does NOT re-derive the deterministic id from the original
 * source emission, because the original pending invocation's id is already
 * present (or removed) in the pendingInvocations Y.Map. Instead, replay
 * generates a fresh id by appending a `:replay-N` suffix to the original.
 * This means the replay creates a NEW pending invocation that the assignee
 * can act on, separate from any history of the original.
 */
declare function replayFailedListenerRun(yDoc: Y.Doc, failedRecord: RunRecordDetails, listenerBlockId: string, originalPayload: Record<string, unknown>, originalRefSnapshots: Record<string, unknown>, assigneeDid: string): boolean;

/**
 * Reconciliation loop — turns persisted run records into pending invocations
 * idempotently, so the trigger system survives page refreshes and works
 * across multiple connected clients.
 *
 * See `docs/events-and-triggers-plan.md` §18 for the full design rationale.
 *
 * Called from:
 *   - The editor lifecycle on open (alongside performDMNotificationScan)
 *   - The yDoc observer when remote run records arrive
 *   - Immediately after a local action completes
 *
 * Idempotency comes from `computePendingInvocationId` producing the same id
 * for the same (sourceBlockId, sourceRunId, listenerBlockId, eventName,
 * eventIndex) tuple. Both ends of a sync compute the same id, both call
 * `Y.Map.set` on the same key, Yjs converges to one entry.
 *
 * The loop is intentionally write-only-on-new — it never deletes pending
 * invocations. Removal happens elsewhere (assignee invokes, expiration sweep).
 */
declare function reconcilePendingInvocations(editor: IxoEditorType): void;
declare function getActionForBlock(block: any): ReturnType<typeof getAction>;

/**
 * Context passed to resolveRuntimeRefs when resolving inputs for a triggered
 * listener block. The runtime constructs this from a PendingInvocation when
 * the assignee invokes the listener.
 *
 * - `payload`: the frozen event payload, used to resolve `trigger.payload.*` refs
 * - `refSnapshots`: frozen `nodeId.output.*` values captured at queue time,
 *   used to resolve those refs against the moment of emission rather than
 *   current state. See docs/events-and-triggers-plan.md §3.5.1 for the
 *   Sally → Mike scenario this fixes.
 */
interface TriggerResolutionContext {
    payload: Record<string, unknown>;
    refSnapshots: Record<string, unknown>;
}
/**
 * Resolve runtime references in an nb (caveats) object.
 *
 * At compile time, `{ "$ref": "nodeId.output.fieldPath" }` values are serialized
 * as-is into the block's `inputs` JSON string. At execution time, this function
 * replaces them with actual output values from upstream nodes.
 *
 * Two ref namespaces are supported:
 *  - `nodeId.output.fieldPath` — looked up via `getNodeOutput`. When a
 *    `triggerContext` is provided AND `refSnapshots[ref]` exists, the
 *    snapshot is preferred over the live lookup. This is the load-bearing
 *    fix for the lag-time scenario where multiple pending invocations are
 *    queued and the source block re-runs before the assignee acts on them.
 *  - `trigger.payload.fieldPath` — looked up in `triggerContext.payload`.
 *    Only valid when `triggerContext` is provided (i.e. resolving inputs
 *    for a triggered listener invocation). Compile-time validation in
 *    compiler.ts guarantees these only appear on `block.event`-triggered
 *    blocks.
 *
 * @param nb - The caveats object (may contain nested RuntimeRef values)
 * @param getNodeOutput - Lookup function for upstream node outputs
 * @param triggerContext - Optional, present only for triggered listener invocations
 * @returns A new object with all $ref values resolved
 */
declare function resolveRuntimeRefs(nb: Record<string, unknown>, getNodeOutput: (nodeId: string) => Record<string, unknown> | undefined, triggerContext?: TriggerResolutionContext): Record<string, unknown>;

/**
 * Compute an IPFS-compatible CID for arbitrary content.
 * Dependencies are lazy-loaded to avoid bundling IPFS libraries
 * into the main entry point.
 *
 * Uses CIDv0 with raw leaves disabled to match ixo ecosystem conventions.
 */
declare function computeCID(content: Uint8Array): Promise<string>;
/**
 * Compute CID for a JSON object by stringifying and encoding to UTF-8.
 */
declare function computeJsonCID(obj: Record<string, any>): Promise<string>;

export { ActionDefinition, ActionServices, type FailedListenerRun, type PendingInvocation, RUN_RECORD_AUDIT_TYPE, type RunRecordDetails, type TriggerResolutionContext, appendRunRecord, buildServicesFromHandlers, canToType, computeCID, computeJsonCID, computePendingInvocationId, findFailedListenersForSourceRun, getAction, getActionByCan, getActionForBlock, getAllActions, getAllCanMappings, getOrCreateBlockPendingMap, getPendingInvocationsMap, hasAction, queuePendingInvocation, readPendingInvocations, readRunRecords, reconcilePendingInvocations, registerAction, removePendingInvocation, replayFailedListenerRun, resolveRuntimeRefs, snapshotInputRefs, typeToCan };
