import { type ExecutionDatasetManifest, type ExecutionDatasetScope } from "@automate.ax/api-contract"; import { type Encodable } from "@automate.ax/codec"; import { type Row } from "@electric-sql/client"; import { PGlite, type Results } from "@electric-sql/pglite"; import { z } from "zod"; declare const EXECUTION_DATA_RECOVERY: { readonly localDatabaseRebuilt: true; readonly productionDataAffected: false; }; declare const LOCAL_EXECUTION_DATASET_RESOURCE_SCHEMA: z.ZodEnum<{ automations: "automations"; projects: "projects"; events: "events"; actions: "actions"; outputs: "outputs"; "automation-invocations": "automation-invocations"; contexts: "contexts"; "context-parents": "context-parents"; "event-links": "event-links"; "action-attempts": "action-attempts"; "signal-invocations": "signal-invocations"; "signal-coordinators": "signal-coordinators"; "signal-partitions": "signal-partitions"; "signal-offers": "signal-offers"; "signal-decisions": "signal-decisions"; "signal-decision-offers": "signal-decision-offers"; logs: "logs"; }>; type LocalExecutionDatasetResource = z.infer; export declare const DEFAULT_EXECUTION_DATA_SINCE = "7d"; type ElectricRow = Row; export declare const EXECUTION_DATA_SCHEMA_SQL = "\nCREATE SCHEMA IF NOT EXISTS automate;\nCREATE SCHEMA IF NOT EXISTS automate_internal;\nCREATE SCHEMA IF NOT EXISTS automate_extensions;\nCREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA automate_extensions;\n\nCREATE TABLE IF NOT EXISTS automate.projects (\n id text PRIMARY KEY,\n organization_id text NOT NULL,\n name text NOT NULL,\n active_deployment_id text,\n created_at timestamptz NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.automations (\n id text PRIMARY KEY,\n project_id text NOT NULL,\n identity_key text NOT NULL,\n enabled boolean NOT NULL,\n created_at timestamptz NOT NULL,\n updated_at timestamptz NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.automation_invocations (\n id text PRIMARY KEY,\n automation_id text NOT NULL,\n entrypoint text NOT NULL,\n idempotency_key text NOT NULL,\n run_at timestamptz NOT NULL,\n event_id text,\n processed_at timestamptz,\n created_at timestamptz NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.contexts (\n id text PRIMARY KEY,\n automation_id text NOT NULL,\n status text NOT NULL,\n created_at timestamptz NOT NULL,\n significant boolean NOT NULL DEFAULT false,\n settled_at timestamptz,\n error jsonb\n);\nCREATE TABLE IF NOT EXISTS automate.context_parents (\n context_id text NOT NULL,\n parent_context_id text NOT NULL,\n position integer NOT NULL,\n is_primary boolean NOT NULL,\n inherits_frontier boolean NOT NULL,\n PRIMARY KEY (context_id, parent_context_id)\n);\nCREATE TABLE IF NOT EXISTS automate.event_links (\n id text PRIMARY KEY,\n context_id text NOT NULL,\n event_id text NOT NULL,\n event_subscription_id text,\n hook_slot integer NOT NULL,\n scope_path integer[] NOT NULL,\n outcome_seq bigint NOT NULL,\n config jsonb NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.events (\n id text PRIMARY KEY,\n event_source_id text NOT NULL,\n event_type text NOT NULL,\n ingest_seq bigint NOT NULL,\n created_at timestamptz NOT NULL,\n payload_encoded bytea NOT NULL,\n payload jsonb NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.actions (\n id text PRIMARY KEY,\n context_id text NOT NULL,\n name text NOT NULL,\n description text,\n slot integer NOT NULL,\n scope_path integer[] NOT NULL,\n status text NOT NULL,\n created_at timestamptz NOT NULL,\n completed_at timestamptz,\n derivation jsonb,\n error jsonb,\n skip_reason text,\n action_dependency_ids text[] NOT NULL,\n event_dependency_ids text[] NOT NULL,\n signal_dependency_ids text[] NOT NULL,\n outcome_seq bigint,\n output_encoded bytea,\n output jsonb,\n output_sensitivity jsonb,\n max_attempts integer NOT NULL DEFAULT 3,\n replay_safety text\n);\nCREATE TABLE IF NOT EXISTS automate.action_attempts (\n id text PRIMARY KEY,\n action_invocation_id text NOT NULL,\n delivery_id text NOT NULL,\n attempt integer NOT NULL,\n status text NOT NULL,\n error jsonb,\n retry_at timestamptz,\n started_at timestamptz NOT NULL,\n completed_at timestamptz\n);\nCREATE TABLE IF NOT EXISTS automate.outputs (\n id text PRIMARY KEY,\n context_id text NOT NULL,\n action_invocation_id text NOT NULL,\n output_index integer NOT NULL,\n output_seq bigint NOT NULL,\n created_at timestamptz NOT NULL,\n type text,\n data jsonb,\n value_encoded bytea NOT NULL,\n value jsonb NOT NULL,\n value_sensitivity jsonb\n);\nCREATE TABLE IF NOT EXISTS automate.signal_coordinators (\n id text PRIMARY KEY,\n automation_id text NOT NULL,\n configuration_hash text NOT NULL,\n primary_position text,\n scope_path integer[] NOT NULL,\n slot integer NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.signal_decisions (\n id text PRIMARY KEY,\n context_id text NOT NULL,\n coordinator_id text NOT NULL,\n partition_id text,\n created_at timestamptz NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.signal_decision_offers (\n decision_id text NOT NULL,\n offer_id text NOT NULL,\n position integer NOT NULL,\n PRIMARY KEY (decision_id, offer_id)\n);\nCREATE TABLE IF NOT EXISTS automate.signal_invocations (\n id text PRIMARY KEY,\n context_id text NOT NULL,\n slot integer NOT NULL,\n scope_path integer[] NOT NULL,\n status text NOT NULL,\n created_at timestamptz NOT NULL,\n derivation jsonb,\n error jsonb,\n selected_index integer,\n action_dependency_ids text[] NOT NULL,\n event_dependency_ids text[] NOT NULL,\n signal_dependency_ids text[] NOT NULL,\n outcome_seq bigint,\n output_encoded bytea,\n output jsonb\n);\nCREATE TABLE IF NOT EXISTS automate.signal_offers (\n id text PRIMARY KEY,\n context_id text NOT NULL,\n coordinator_id text NOT NULL,\n decision_id text,\n lane text NOT NULL,\n status text NOT NULL,\n selected boolean NOT NULL,\n created_at timestamptz NOT NULL,\n derivation jsonb,\n ready_at timestamptz,\n expires_at timestamptz,\n burst_ends_at timestamptz,\n outcome_seq bigint NOT NULL,\n action_dependency_ids text[] NOT NULL,\n event_dependency_ids text[] NOT NULL,\n signal_dependency_ids text[] NOT NULL,\n partition_id text,\n settled_at timestamptz,\n key_hash text NOT NULL,\n key_encoded bytea NOT NULL,\n key jsonb NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate.signal_partitions (\n id text PRIMARY KEY,\n coordinator_id text NOT NULL,\n created_at timestamptz NOT NULL,\n key_hash text NOT NULL,\n key_encoded bytea NOT NULL,\n key jsonb NOT NULL,\n state jsonb,\n state_expires_at timestamptz,\n wake_at timestamptz\n);\nCREATE TABLE IF NOT EXISTS automate.logs (\n id text PRIMARY KEY,\n context_id text NOT NULL,\n action_invocation_id text NOT NULL,\n attempt integer NOT NULL,\n log_index integer NOT NULL,\n level text NOT NULL,\n message text NOT NULL,\n created_at timestamptz NOT NULL,\n fields_encoded bytea,\n fields jsonb,\n sensitivity jsonb\n);\nCREATE TABLE IF NOT EXISTS automate.search_documents (\n document_id text PRIMARY KEY,\n resource text NOT NULL,\n resource_id text NOT NULL,\n context_id text,\n project_id text,\n automation_id text,\n provider text,\n title text NOT NULL,\n content text NOT NULL,\n metadata text NOT NULL,\n identifiers text NOT NULL,\n created_at timestamptz,\n search_vector tsvector GENERATED ALWAYS AS (\n setweight(to_tsvector('simple', coalesce(title, '')), 'A') ||\n setweight(to_tsvector('simple', coalesce(content, '')), 'B') ||\n setweight(to_tsvector('simple', coalesce(metadata, '')), 'C') ||\n setweight(to_tsvector('simple', coalesce(identifiers, '')), 'D')\n ) STORED\n);\n\nCREATE INDEX IF NOT EXISTS automations_project_id_idx ON automate.automations (project_id);\nCREATE INDEX IF NOT EXISTS automation_invocations_action_idx ON automate.automation_invocations (idempotency_key, run_at);\nCREATE INDEX IF NOT EXISTS automation_invocations_event_idx ON automate.automation_invocations (event_id);\nCREATE INDEX IF NOT EXISTS contexts_automation_created_idx ON automate.contexts (automation_id, created_at DESC);\nCREATE INDEX IF NOT EXISTS context_parents_context_idx ON automate.context_parents (context_id);\nCREATE INDEX IF NOT EXISTS context_parents_parent_idx ON automate.context_parents (parent_context_id);\nCREATE INDEX IF NOT EXISTS event_links_context_idx ON automate.event_links (context_id);\nCREATE INDEX IF NOT EXISTS actions_context_created_idx ON automate.actions (context_id, created_at);\nCREATE INDEX IF NOT EXISTS outputs_context_seq_idx ON automate.outputs (context_id, output_seq);\nCREATE INDEX IF NOT EXISTS signal_coordinators_automation_idx ON automate.signal_coordinators (automation_id, scope_path, slot);\nCREATE INDEX IF NOT EXISTS signal_decisions_context_idx ON automate.signal_decisions (context_id, created_at);\nCREATE INDEX IF NOT EXISTS signal_decision_offers_decision_idx ON automate.signal_decision_offers (decision_id, position);\nCREATE INDEX IF NOT EXISTS signal_invocations_context_idx ON automate.signal_invocations (context_id, created_at);\nCREATE INDEX IF NOT EXISTS signal_offers_context_idx ON automate.signal_offers (context_id, created_at);\nCREATE INDEX IF NOT EXISTS signal_offers_coordinator_idx ON automate.signal_offers (coordinator_id, decision_id);\nCREATE INDEX IF NOT EXISTS signal_partitions_coordinator_idx ON automate.signal_partitions (coordinator_id, key_hash);\nCREATE INDEX IF NOT EXISTS events_type_created_idx ON automate.events (event_type, created_at DESC);\nCREATE INDEX IF NOT EXISTS logs_context_created_idx ON automate.logs (context_id, created_at);\nCREATE INDEX IF NOT EXISTS logs_level_created_idx ON automate.logs (level, created_at DESC);\nCREATE INDEX IF NOT EXISTS search_documents_vector_idx ON automate.search_documents USING gin (search_vector);\nCREATE INDEX IF NOT EXISTS search_documents_title_trgm_idx ON automate.search_documents USING gin (title automate_extensions.gin_trgm_ops);\nCREATE INDEX IF NOT EXISTS search_documents_content_trgm_idx ON automate.search_documents USING gin (content automate_extensions.gin_trgm_ops);\nCREATE INDEX IF NOT EXISTS search_documents_identifiers_trgm_idx ON automate.search_documents USING gin (identifiers automate_extensions.gin_trgm_ops);\nCREATE INDEX IF NOT EXISTS search_documents_context_created_idx ON automate.search_documents (context_id, created_at DESC);\n\nCREATE OR REPLACE VIEW automate.context_ancestors AS\nWITH RECURSIVE ancestors(context_id, ancestor_context_id, depth, path) AS (\n SELECT id, id, 0, ARRAY[id] FROM automate.contexts\n UNION ALL\n SELECT ancestors.context_id, parents.parent_context_id, ancestors.depth + 1,\n ancestors.path || parents.parent_context_id\n FROM ancestors\n INNER JOIN automate.context_parents AS parents\n ON parents.context_id = ancestors.ancestor_context_id\n WHERE NOT parents.parent_context_id = ANY(ancestors.path)\n)\nSELECT context_id, ancestor_context_id, depth FROM ancestors;\n\nCREATE OR REPLACE VIEW automate.context_descendants AS\nWITH RECURSIVE descendants(context_id, descendant_context_id, depth, path) AS (\n SELECT id, id, 0, ARRAY[id] FROM automate.contexts\n UNION ALL\n SELECT descendants.context_id, parents.context_id, descendants.depth + 1,\n descendants.path || parents.context_id\n FROM descendants\n INNER JOIN automate.context_parents AS parents\n ON parents.parent_context_id = descendants.descendant_context_id\n WHERE NOT parents.context_id = ANY(descendants.path)\n)\nSELECT context_id, descendant_context_id, depth FROM descendants;\n\nCREATE OR REPLACE VIEW automate.root_contexts AS\nSELECT\n contexts.*,\n automations.project_id,\n automations.identity_key AS automation_identity_key,\n projects.organization_id,\n projects.name AS project_name\nFROM automate.contexts\nINNER JOIN automate.automations ON automations.id = contexts.automation_id\nINNER JOIN automate.projects ON projects.id = automations.project_id\nWHERE NOT EXISTS (\n SELECT 1 FROM automate.context_parents\n WHERE context_parents.context_id = contexts.id\n);\n\nCREATE OR REPLACE VIEW automate.signal_outcomes AS\nSELECT\n signals.*,\n decisions.id AS decision_id,\n coalesce(partitions.coordinator_id, decisions.coordinator_id) AS coordinator_id,\n coordinators.configuration_hash AS coordinator_configuration_hash,\n coordinators.primary_position,\n coalesce(selected_offers.selected_offer_ids, ARRAY[]::text[]) AS selected_offer_ids,\n coalesce(selected_offers.selected_lanes, ARRAY[]::text[]) AS selected_lanes\nFROM automate.signal_invocations AS signals\nLEFT JOIN automate.contexts AS contexts ON contexts.id = signals.context_id\nLEFT JOIN automate.signal_decisions AS decisions\n ON decisions.context_id = signals.context_id\nLEFT JOIN automate.signal_partitions AS partitions\n ON partitions.id = decisions.partition_id\nLEFT JOIN automate.signal_coordinators AS coordinators\n ON coordinators.id = coalesce(partitions.coordinator_id, decisions.coordinator_id)\nLEFT JOIN LATERAL (\n SELECT\n array_agg(selected.id ORDER BY selected.position, selected.created_at, selected.id) AS selected_offer_ids,\n array_agg(selected.lane ORDER BY selected.position, selected.created_at, selected.id) AS selected_lanes\n FROM (\n SELECT offers.id, offers.lane, offers.created_at, membership.position\n FROM automate.signal_decision_offers AS membership\n INNER JOIN automate.signal_offers AS offers\n ON offers.id = membership.offer_id\n WHERE membership.decision_id = decisions.id\n\n UNION ALL\n\n -- DEPRECATED: supports datasets captured from a pre-AAX-332 process during\n -- rolling deployment. Remove after one full production release.\n SELECT\n offers.id,\n offers.lane,\n offers.created_at,\n row_number() over (ORDER BY offers.lane, offers.created_at, offers.id) - 1\n FROM automate.signal_offers AS offers\n WHERE offers.decision_id = decisions.id\n AND offers.selected\n AND NOT EXISTS (\n SELECT 1\n FROM automate.signal_decision_offers AS membership\n WHERE membership.decision_id = decisions.id\n )\n ) AS selected\n) AS selected_offers ON true;\n\nCREATE TABLE IF NOT EXISTS automate_internal.sync_state (\n singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),\n profile_id text NOT NULL,\n schema_version integer NOT NULL,\n organization_id text,\n project_id text,\n since_at timestamptz,\n synced_at timestamptz NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate_internal.resource_sync_state (\n resource text PRIMARY KEY,\n shape_offset text NOT NULL,\n synced_at timestamptz NOT NULL\n);\nCREATE TABLE IF NOT EXISTS automate_internal.local_state (\n singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),\n search_schema_version integer NOT NULL\n);\n\nDO $$ BEGIN\n CREATE ROLE automate_query;\nEXCEPTION WHEN duplicate_object THEN NULL;\nEND $$;\nREVOKE ALL ON SCHEMA automate, automate_internal, automate_extensions FROM PUBLIC;\nREVOKE ALL ON SCHEMA public FROM PUBLIC, automate_query;\nREVOKE ALL ON ALL TABLES IN SCHEMA automate, automate_internal FROM PUBLIC;\nREVOKE ALL ON ALL FUNCTIONS IN SCHEMA automate, automate_extensions, public FROM PUBLIC, automate_query;\nGRANT USAGE ON SCHEMA automate, automate_extensions TO automate_query;\nGRANT SELECT ON ALL TABLES IN SCHEMA automate TO automate_query;\nGRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA automate_extensions TO automate_query;\n"; export declare const EXECUTION_DATA_SEARCH_INSERT_SQL = "\nWITH context_metadata AS (\n SELECT\n contexts.id AS context_id,\n automations.id AS automation_id,\n automations.identity_key AS automation_identity_key,\n projects.id AS project_id,\n projects.name AS project_name,\n providers.provider\n FROM automate.contexts\n INNER JOIN automate.automations ON automations.id = contexts.automation_id\n INNER JOIN automate.projects ON projects.id = automations.project_id\n LEFT JOIN LATERAL (\n SELECT string_agg(\n DISTINCT split_part(events.event_type, '.', 1),\n ' ' ORDER BY split_part(events.event_type, '.', 1)\n ) AS provider\n FROM automate.event_links\n INNER JOIN automate.events ON events.id = event_links.event_id\n WHERE event_links.context_id = contexts.id\n ) AS providers ON true\n), documents (\n document_id,\n resource,\n resource_id,\n context_id,\n project_id,\n automation_id,\n provider,\n title,\n content,\n metadata,\n identifiers,\n created_at\n) AS (\nSELECT\n 'projects:' || projects.id,\n 'projects',\n projects.id,\n NULL,\n projects.id,\n NULL,\n NULL,\n projects.name,\n projects.name,\n concat_ws(' ', projects.organization_id, projects.name),\n concat_ws(' ', projects.id, projects.organization_id),\n projects.created_at\nFROM automate.projects\nUNION ALL\nSELECT\n 'automations:' || automations.id,\n 'automations',\n automations.id,\n NULL,\n projects.id,\n automations.id,\n NULL,\n automations.identity_key,\n concat_ws(' ', automations.identity_key, CASE WHEN automations.enabled THEN 'enabled' ELSE 'disabled' END),\n concat_ws(' ', projects.name, automations.identity_key),\n concat_ws(' ', automations.id, projects.id, projects.organization_id),\n automations.updated_at\nFROM automate.automations\nINNER JOIN automate.projects ON projects.id = automations.project_id\nUNION ALL\nSELECT\n 'automation-invocations:' || invocations.id,\n 'automation-invocations',\n invocations.id,\n actions.context_id,\n metadata.project_id,\n invocations.automation_id,\n metadata.provider,\n concat_ws(' ', 'scheduled invocation', invocations.entrypoint),\n concat_ws(E'\n', invocations.entrypoint, invocations.run_at::text, invocations.processed_at::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, metadata.provider),\n concat_ws(' ', invocations.id, invocations.automation_id, invocations.idempotency_key, invocations.event_id, actions.context_id, metadata.project_id),\n invocations.created_at\nFROM automate.automation_invocations AS invocations\nINNER JOIN automate.actions AS actions ON actions.id = invocations.idempotency_key\nINNER JOIN context_metadata AS metadata ON metadata.context_id = actions.context_id\nUNION ALL\nSELECT\n 'contexts:' || contexts.id,\n 'contexts',\n contexts.id,\n contexts.id,\n metadata.project_id,\n metadata.automation_id,\n metadata.provider,\n concat_ws(' ', 'context', contexts.status),\n concat_ws(E'\n', contexts.status, contexts.error::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, metadata.provider),\n concat_ws(' ', contexts.id, metadata.automation_id, metadata.project_id),\n contexts.created_at\nFROM automate.contexts\nINNER JOIN context_metadata AS metadata ON metadata.context_id = contexts.id\nUNION ALL\nSELECT\n concat_ws(':', 'events', events.id, coalesce(event_links.id, 'unlinked')),\n 'events',\n events.id,\n event_links.context_id,\n metadata.project_id,\n metadata.automation_id,\n split_part(events.event_type, '.', 1),\n events.event_type,\n concat_ws(E'\n', events.event_type, events.payload::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, split_part(events.event_type, '.', 1)),\n concat_ws(' ', events.id, events.event_source_id, event_links.id, event_links.event_subscription_id, event_links.context_id, metadata.project_id, metadata.automation_id),\n events.created_at\nFROM automate.events\nLEFT JOIN automate.event_links ON event_links.event_id = events.id\nLEFT JOIN context_metadata AS metadata ON metadata.context_id = event_links.context_id\nUNION ALL\nSELECT\n 'actions:' || actions.id,\n 'actions',\n actions.id,\n actions.context_id,\n metadata.project_id,\n metadata.automation_id,\n metadata.provider,\n concat_ws(' ', actions.name, actions.description),\n concat_ws(E'\n', actions.description, actions.status, actions.skip_reason, actions.error::text, actions.output::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, metadata.provider),\n concat_ws(' ', actions.id, actions.context_id, metadata.project_id, metadata.automation_id, array_to_string(actions.action_dependency_ids, ' '), array_to_string(actions.event_dependency_ids, ' '), array_to_string(actions.signal_dependency_ids, ' ')),\n actions.created_at\nFROM automate.actions\nINNER JOIN context_metadata AS metadata ON metadata.context_id = actions.context_id\nUNION ALL\nSELECT\n 'logs:' || logs.id,\n 'logs',\n logs.id,\n logs.context_id,\n metadata.project_id,\n metadata.automation_id,\n metadata.provider,\n logs.message,\n concat_ws(E'\n', logs.message, logs.level, logs.fields::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, metadata.provider),\n concat_ws(' ', logs.id, logs.context_id, logs.action_invocation_id, metadata.project_id, metadata.automation_id),\n logs.created_at\nFROM automate.logs\nINNER JOIN context_metadata AS metadata ON metadata.context_id = logs.context_id\nUNION ALL\nSELECT\n 'outputs:' || outputs.id,\n 'outputs',\n outputs.id,\n outputs.context_id,\n metadata.project_id,\n metadata.automation_id,\n metadata.provider,\n concat_ws(' ', outputs.type, 'output'),\n concat_ws(E'\n', outputs.type, outputs.data::text, outputs.value::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, metadata.provider),\n concat_ws(' ', outputs.id, outputs.context_id, outputs.action_invocation_id, metadata.project_id, metadata.automation_id),\n outputs.created_at\nFROM automate.outputs\nINNER JOIN context_metadata AS metadata ON metadata.context_id = outputs.context_id\nUNION ALL\nSELECT\n 'signal-invocations:' || signals.id,\n 'signal-invocations',\n signals.id,\n signals.context_id,\n metadata.project_id,\n metadata.automation_id,\n metadata.provider,\n concat_ws(' ', 'signal', signals.status),\n concat_ws(E'\n', signals.status, signals.error::text, signals.output::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, metadata.provider),\n concat_ws(' ', signals.id, signals.context_id, metadata.project_id, metadata.automation_id, array_to_string(signals.action_dependency_ids, ' '), array_to_string(signals.event_dependency_ids, ' '), array_to_string(signals.signal_dependency_ids, ' ')),\n signals.created_at\nFROM automate.signal_invocations AS signals\nINNER JOIN context_metadata AS metadata ON metadata.context_id = signals.context_id\nUNION ALL\nSELECT\n 'signal-offers:' || offers.id,\n 'signal-offers',\n offers.id,\n offers.context_id,\n metadata.project_id,\n metadata.automation_id,\n metadata.provider,\n concat_ws(' ', offers.lane, offers.status),\n concat_ws(E'\n', offers.lane, offers.status, offers.key::text),\n concat_ws(' ', metadata.project_name, metadata.automation_identity_key, metadata.provider),\n concat_ws(' ', offers.id, offers.context_id, offers.coordinator_id, offers.decision_id, offers.key_hash, metadata.project_id, metadata.automation_id, array_to_string(offers.action_dependency_ids, ' '), array_to_string(offers.event_dependency_ids, ' '), array_to_string(offers.signal_dependency_ids, ' ')),\n offers.created_at\nFROM automate.signal_offers AS offers\nINNER JOIN context_metadata AS metadata ON metadata.context_id = offers.context_id\n), upserted AS (\nINSERT INTO automate.search_documents AS current (\n document_id,\n resource,\n resource_id,\n context_id,\n project_id,\n automation_id,\n provider,\n title,\n content,\n metadata,\n identifiers,\n created_at\n)\nSELECT * FROM documents\nWHERE $1::text IS NULL OR resource = $1\nON CONFLICT (document_id) DO UPDATE SET\n resource = excluded.resource,\n resource_id = excluded.resource_id,\n context_id = excluded.context_id,\n project_id = excluded.project_id,\n automation_id = excluded.automation_id,\n provider = excluded.provider,\n title = excluded.title,\n content = excluded.content,\n metadata = excluded.metadata,\n identifiers = excluded.identifiers,\n created_at = excluded.created_at\nWHERE ROW(\n current.resource,\n current.resource_id,\n current.context_id,\n current.project_id,\n current.automation_id,\n current.provider,\n current.title,\n current.content,\n current.metadata,\n current.identifiers,\n current.created_at\n) IS DISTINCT FROM ROW(\n excluded.resource,\n excluded.resource_id,\n excluded.context_id,\n excluded.project_id,\n excluded.automation_id,\n excluded.provider,\n excluded.title,\n excluded.content,\n excluded.metadata,\n excluded.identifiers,\n excluded.created_at\n)\n)\nDELETE FROM automate.search_documents AS current\nWHERE ($1::text IS NULL OR current.resource = $1)\nAND NOT EXISTS (\n SELECT 1\n FROM documents\n WHERE ($1::text IS NULL OR documents.resource = $1)\n AND documents.document_id = current.document_id\n);\n"; export interface ExecutionDataSyncOptions { organizationId?: string; projectId?: string; since: string | null; } export interface ExecutionDataSearchOptions { limit?: number; query: string; } export interface ExecutionDataSearchResult { content: string; context: string | null; id: string; rank: number; resource: string; timestamp: string | null; } export interface ExecutionDataStatus { consistency: "eventual"; databasePath: string; profileId: string; resources: Record; schemaVersion: number; scope: ExecutionDatasetScope; syncedAt: string; } export interface ExecutionDataSyncResult extends ExecutionDataStatus { recovery: typeof EXECUTION_DATA_RECOVERY | null; } /** * Parses an ISO timestamp or compact lookback such as `7d`. * * @param value - User-supplied absolute time, lookback, or `all`. * @throws When the value is not a supported time expression. */ export declare function parseExecutionDataSince(value: string): string | null; /** * Synchronizes one authorized scope into its isolated local database. * * @param options - Organization, project, and history scope. */ export declare function syncExecutionData(options: ExecutionDataSyncOptions): Promise<{ recovery: { readonly localDatabaseRebuilt: true; readonly productionDataAffected: false; } | null; consistency: "eventual"; databasePath: string; profileId: string; resources: Record<"events" | "actions" | "projects" | "outputs" | "automations" | "contexts" | "logs" | "automation-invocations" | "context-parents" | "event-links" | "action-attempts" | "signal-invocations" | "signal-coordinators" | "signal-partitions" | "signal-offers" | "signal-decisions" | "signal-decision-offers", { offset: string; rows: number; syncedAt: string; }>; schemaVersion: number; scope: { organizationId: string | null; projectId: string | null; since: string | null; }; syncedAt: string; }>; /** * Keeps an authorized scope synchronized until the supplied signal aborts. * * @param options - Organization, project, and history scope. * @param signal - Cancellation signal for the live stream. * @param onChange - Optional callback after a materialized update. */ export declare function followExecutionData(options: ExecutionDataSyncOptions, signal: AbortSignal, onChange?: () => Promise): Promise; /** * Executes SQL as a restricted local role with read-only dataset access. * * @param sql - One or more PostgreSQL statements. */ export declare function queryExecutionData(sql: string): Promise<{ profileId: string; results: { affectedRows: number | undefined; fields: string[]; rows: unknown[]; }[]; }>; /** * Searches the active local execution dataset by relevance. * * @param options - Search text and optional result limit. */ export declare function searchExecutionData(options: ExecutionDataSearchOptions): Promise<{ profileId: string; query: string; results: { rank: number; timestamp: string | null; content: string; context: string | null; id: string; resource: string; }[]; }>; /** Returns metadata and synchronized row counts for the active profile. */ export declare function getExecutionDataStatus(): Promise<{ consistency: "eventual"; databasePath: string; profileId: string; resources: Record<"events" | "actions" | "projects" | "outputs" | "automations" | "contexts" | "logs" | "automation-invocations" | "context-parents" | "event-links" | "action-attempts" | "signal-invocations" | "signal-coordinators" | "signal-partitions" | "signal-offers" | "signal-decisions" | "signal-decision-offers", { offset: string; rows: number; syncedAt: string; }>; schemaVersion: number; scope: { organizationId: string | null; projectId: string | null; since: string | null; }; syncedAt: string; }>; /** * Exports the complete active PGlite database as a compressed archive. * * @param outputPath - Destination path for the archive. */ export declare function exportExecutionData(outputPath: string): Promise<{ outputPath: string; profileId: string; size: number; }>; /** Permanently removes the active profile's local execution database. */ export declare function clearExecutionData(): Promise<{ cleared: boolean; profileId: null; } | { cleared: boolean; profileId: string; }>; /** Removes every local execution-data profile for the configured origin. */ export declare function clearAllExecutionData(): Promise; /** Returns the active local database path without opening it. */ export declare function getActiveExecutionDataPath(): Promise; interface ProfileDatabaseOptions { rebuildOnCorruption: boolean; resetOnVersionMismatch: boolean; signal?: AbortSignal; } /** * Runs one local database operation and handles explicit PostgreSQL corruption. * * @param profileId - Opaque authorized profile identity. * @param options - Schema and one-shot rebuild behavior. * @param operation - Work to perform against the opened local database. */ export declare function useProfileDatabase(profileId: string, options: ProfileDatabaseOptions, operation: (database: PGlite, recoveredFromCorruption: boolean) => Promise): Promise; /** * Returns whether an error is an explicit PostgreSQL corruption condition. * * @param error - Unknown operation failure. */ export declare function isExecutionDataCorruptionError(error: unknown): boolean; /** * Initializes or intentionally replaces the managed local query schema. * * @param database - Local PGlite database to initialize. * @param resetOnVersionMismatch - Whether incompatible managed tables may be * replaced. */ export declare function ensureExecutionDataSchema(database: PGlite, resetOnVersionMismatch?: boolean): Promise; interface ResourceSnapshot { name: LocalExecutionDatasetResource; offset: string; rows: ElectricRow[]; syncedAt: string; } /** * Atomically replaces local tables with independently current shape snapshots. * * @param database - Active local PGlite database. * @param manifest - Authorized scope recorded with the snapshot. * @param resources - Complete initial resource snapshots. */ export declare function replaceDataset(database: PGlite, manifest: ExecutionDatasetManifest, resources: readonly ResourceSnapshot[]): Promise; /** * Replaces one live resource after Electric publishes an update. * * @param database - Active local PGlite database. * @param manifest - Authorized scope recorded with the update. * @param resource - Complete resource rows and independent freshness boundary. */ export declare function replaceResource(database: PGlite, manifest: ExecutionDatasetManifest, resource: ResourceSnapshot): Promise; /** * Rebuilds the full local corpus or one independently searchable resource. * * @param database - Local query executor or transaction. * @param resource - Optional search resource to replace incrementally. */ export declare function rebuildExecutionDataSearchDocuments(database: Pick, resource?: LocalExecutionDatasetResource): Promise; /** * Executes only query statements inside a database-enforced read-only boundary. * * @param database - Initialized local execution-data database. * @param sql - One or more PostgreSQL query statements. */ export declare function executeReadOnlyExecutionDataQuery(database: PGlite, sql: string): Promise[]>; /** * Searches a prepared execution-data database with full-text and trigram * ranking. * * @param database - Initialized local execution-data database. * @param options - Search text and optional result limit. */ export declare function searchExecutionDataDocuments(database: PGlite, options: ExecutionDataSearchOptions): Promise<{ rank: number; timestamp: string | null; content: string; context: string | null; id: string; resource: string; }[]>; /** * Converts a codec value to the dataset's loss-aware JSON projection. * * @param value - Decoded codec value. * @param encodedRef - Reference to the exact encoded owner column. */ export declare function projectExecutionDataValue(value: Encodable, encodedRef: string): Promise; /** * Atomically replaces a sensitive file with owner-only permissions. * * @param filePath - Destination file to replace. * @param contents - Complete string or binary contents. */ export declare function atomicWritePrivateFile(filePath: string, contents: string | Uint8Array): Promise; export {}; //# sourceMappingURL=execution-data.d.ts.map