import type { AgentTurnEvent, AgentTurnInput, AgentTurnOutput, AgentTurnSteer, RuntimeExecRequest, RuntimeExecResult } from '../agent-turn/types.js'; import type { AuthResult, ConnectorWebhookSchema, EventEnvelope, SyncCredentials, WebhookRegistration } from '@lobu/connector-sdk'; /** * Executor mode discriminator. The executor speaks the same V1 SDK shapes * the connector code expects: `SyncContext` / `ActionContext` / `AuthContext` * in, `SyncResult` / `ActionResult` / `AuthResult` out, no envelope. */ export type ExecutorJob = { mode: 'sync'; feedKey?: string | null; /** Feed-instance id (feeds.id) — namespaces emitted origin_ids per feed. */ feedId?: number | null; config: Record; checkpoint: Record | null; entityIds: number[]; credentials: SyncCredentials | null; sessionState: Record | null; env: Record; } | { mode: 'action'; actionKey: string; actionInput: Record; config: Record; credentials: SyncCredentials | null; sessionState: Record | null; env: Record; } | { mode: 'authenticate'; config: Record; previousCredentials: Record | null; env: Record; } | { mode: 'query'; query: string; config: Record; credentials: SyncCredentials | null; sessionState: Record | null; env: Record; limit?: number; offset?: number; sort?: { column: string; order: 'asc' | 'desc'; }; } | { mode: 'read'; feedKey: string; feedId?: number | null; query?: string; cursor?: string; window?: { start: string; end: string; }; config: Record; credentials: SyncCredentials | null; sessionState: Record | null; env: Record; limit?: number; offset?: number; sort?: { column: string; order: 'asc' | 'desc'; }; } | { mode: 'webhook_register'; config: Record; credentials: SyncCredentials | null; sessionState: Record | null; callbackUrl: string; env: Record; } | { mode: 'agent_turn'; turn: AgentTurnInput; config: Record; credentials: SyncCredentials | null; sessionState: Record | null; env: Record; } | { mode: 'webhook_unregister'; config: Record; credentials: SyncCredentials | null; sessionState: Record | null; externalId: string; env: Record; }; /** * Result shape returned by the executor. One discriminated union per mode * mirrors the SDK's `ActionResult` / `AuthResult` directly. Sync is * streaming-only: events leave via `hooks.onEventChunk`, never collected * onto the result — callers that need a list build it themselves in the * hook (see e.g. `packages/cli/src/commands/_lib/connector-run-cmd.ts`). */ export type ExecutorResult = { mode: 'sync'; checkpoint: Record | null; auth_update?: Record | null; metadata?: Record; } | { mode: 'action'; output: Record; } | { mode: 'authenticate'; auth: AuthResult; } | { mode: 'query'; rows: Record[]; columns?: { name: string; type: string; }[]; total?: number; } | { mode: 'read'; rows: Record[]; columns?: { name: string; type: string; }[]; total?: number; nextCursor?: string; hasMore?: boolean; window?: { start: string; end: string; axis: string; }; } | { mode: 'webhook_register'; registration: WebhookRegistration; /** * The connector's declarative `definition.webhook` scheme. The verifier * (gateway ingest hot path) needs `signatureHeader`/`algorithm`/etc. to * check provider HMACs, but those fields are NOT persisted to the * `connector_definitions` catalog. Returning the scheme here lets the * server stamp it onto the connection in the same round-trip as the * minted secret + externalId — no extra catalog column / migration. */ webhookScheme: ConnectorWebhookSchema | null; } | { mode: 'agent_turn'; turn: AgentTurnOutput; } | { mode: 'webhook_unregister'; }; export interface ExecutionHooks { /** * Stop the run from outside: the guest is terminated and `execute` rejects * with the abort as its error. An agent turn arms this when the gateway's * heartbeat answers `continue: false` — the human cancelled — so the model * stops mid-turn instead of spending the rest of the wall clock. */ signal?: AbortSignal; /** Agent turns: the guest emitted a token or ended a message, mid-stream. */ onTurnEvent?: (event: AgentTurnEvent) => Promise | void; /** * Agent turns: messages that arrived for the conversation while the turn * was running, taken once each in arrival order. The guest asks at the * points pi drains steering — after an assistant message and after a tool * result — and hands what it gets to `agent.steer()`. */ takeSteering?: () => ReadonlyArray; /** * Agent turns on a sandbox-pinned conversation: run one bash command in the * remote runtime. The host owns the call — the gateway's exec route, the * turn's own token — so the guest never holds a credential or an egress. */ onRuntimeExec?: (request: RuntimeExecRequest) => Promise; /** Sync runs: connector streamed a chunk of events (and we should persist them). */ onEventChunk?: (events: EventEnvelope[]) => Promise | void; /** Sync runs: connector pushed an incremental checkpoint update. */ onCheckpointUpdate?: (checkpoint: Record | null) => Promise | void; /** Auth runs: connector emitted an artifact (QR/redirect/prompt/status). */ onAuthArtifact?: (artifact: Record) => Promise | void; /** Auth runs: connector paused until a named signal arrives. */ onAwaitAuthSignal?: (name: string, options?: { timeoutMs?: number; }) => Promise>; /** * Sync runs: connector code invoked * `ctx.sessionState.chrome_dispatcher.dispatch(actionKey, actionInput)`. * The host (connector-worker daemon) forwards the call to the gateway * (POST /api/workers/dispatch-chrome-action), which inserts a chrome * connector action run, waits for the paired Owletto extension to claim * and complete it, and returns the observation. Implementations MUST * reject when no extension is reachable. */ onChromeDispatch?: (actionKey: string, actionInput: Record) => Promise>; } /** * Pluggable executor interface. The canonical implementation is `IsolateExecutor`; * the seam stays around so tests can stub it. */ export interface SyncExecutor { execute(compiledCode: string, job: ExecutorJob, hooks?: ExecutionHooks): Promise; } export type ConnectorExitReason = 'ok' | 'error_message' | 'timeout' | 'oom' | 'crash'; export interface ConnectorExecutionDiagnostics { exitCode: number | null; exitSignal: string | null; outputTail: string; exitReason: ConnectorExitReason; httpStatus?: number; } export declare class ConnectorExecutionError extends Error implements ConnectorExecutionDiagnostics { exitCode: number | null; exitSignal: string | null; outputTail: string; exitReason: ConnectorExitReason; httpStatus?: number; constructor(message: string, diagnostics: ConnectorExecutionDiagnostics, options?: { cause?: unknown; }); } /** Per-stream ring buffer that preserves the most recent bytes. */ export declare class RingBuffer { private readonly cap; private chunks; private size; constructor(cap: number); append(chunk: string): void; toString(): string; } //# sourceMappingURL=interface.d.ts.map