import { type AgentErrorV1 } from './errors.js'; import type { CrowdyAgentBrowserToolDispatcher } from './browser-dispatcher.js'; import type { CrowdyAgentApprovalV1, CrowdyAgentBudgetV1, CrowdyAgentCheckpointV1, CrowdyAgentEventV1, CrowdyAgentLeaseV1, CrowdyAgentMessageV1, CrowdyAgentMode, CrowdyAgentPreemptionReason, CrowdyAgentRegisteredToolV1, CrowdyAgentSessionV1, CrowdyAgentToolTimelineItemV1 } from './types.js'; import type { CrowdyAgentCreateSessionInputV1, CrowdyStudioAgentTransportV1 } from './transport.js'; export type CrowdyStudioAgentConnectionState = 'DISCONNECTED' | 'ATTACHING' | 'REPLAYING' | 'CONNECTED' | 'RECONNECTING' | 'ERROR'; export interface CrowdyStudioAgentStateV1 { readonly connection: CrowdyStudioAgentConnectionState; readonly session: CrowdyAgentSessionV1 | null; readonly clientEpoch: string | null; readonly lastContiguousSeq: string; readonly lastAcknowledgedSeq: string; readonly events: readonly CrowdyAgentEventV1[]; readonly messages: readonly CrowdyAgentMessageV1[]; readonly streamingText: string; readonly tools: readonly CrowdyAgentToolTimelineItemV1[]; readonly approvals: readonly CrowdyAgentApprovalV1[]; readonly leases: readonly CrowdyAgentLeaseV1[]; readonly checkpoints: readonly CrowdyAgentCheckpointV1[]; readonly budget: CrowdyAgentBudgetV1 | null; readonly toolDescriptors: readonly CrowdyAgentRegisteredToolV1[]; readonly lastHeartbeatAt: string | null; readonly playLeaseFreshUntil: string | null; readonly lastError: AgentErrorV1 | null; readonly reconnectRequired: boolean; } export interface CrowdyStudioAgentControllerOptionsV1 { readonly transport: CrowdyStudioAgentTransportV1; readonly sessionId?: string; readonly createSession?: CrowdyAgentCreateSessionInputV1 | (() => CrowdyAgentCreateSessionInputV1 | Promise); /** Resolve the currently selected, fully saved Studio project at attach time. */ readonly resolveProjectBinding?: () => { readonly projectId?: string; readonly gridId?: string; } | Promise<{ readonly projectId?: string; readonly gridId?: string; }>; readonly browserDispatcher?: CrowdyAgentBrowserToolDispatcher; /** Stable browser UUID reused across fresh attach epochs. */ readonly clientInstanceId?: string; /** Flush autosave and validate conflicts before accepting a human turn. */ readonly beforeAgentWork?: (mode: CrowdyAgentMode) => void | Promise; /** Called synchronously for local preemption before transport cleanup. */ readonly onPreempt?: (reason: CrowdyAgentPreemptionReason) => void; readonly onEpochAttached?: (clientEpoch: string) => void; readonly onLeaseChanged?: (lease: CrowdyAgentLeaseV1) => void; readonly createIdempotencyKey?: (operation: string) => string; readonly historyPageSize?: number; readonly maxRetainedEvents?: number; readonly autoReconnect?: boolean; readonly reconnectDelayMs?: number; readonly maxReconnectAttempts?: number; readonly heartbeatIntervalMs?: number; readonly heartbeatStaleMs?: number; readonly workspaceRenewIntervalMs?: number; readonly onStateChange?: (state: CrowdyStudioAgentStateV1) => void; } /** * Durable session client for the `crowdy.studio-agent/1` protocol. The * transport is injectable and contains no generated GraphQL dependency. */ export declare class CrowdyStudioAgentController { private readonly options; private state; private readonly listeners; private readonly buffered; private readonly appliedEventIds; private subscription; private generation; private drainPromise; private acknowledgePromise; private reconnectTimer; private heartbeatTimer; private workspaceRenewTimer; private reconnectAttempts; private keySequence; private readonly clientInstanceId; private pageVisible; private destroyed; constructor(options: CrowdyStudioAgentControllerOptionsV1); getState(): CrowdyStudioAgentStateV1; subscribe(listener: (state: CrowdyStudioAgentStateV1) => void): () => void; setPageVisible(visible: boolean): void; initialize(): Promise; /** * Fail closed when the human selects another project. The v1 Game API has no * set-project mutation, so callers must create/remount a session for it. */ projectSelectionChanged(projectId: string | undefined): void; reconnect(): Promise; sendMessage(content: string): Promise<{ runId: string; }>; setMode(mode: CrowdyAgentMode): Promise; approveTool(toolCallId: string, expectedArgumentHash?: string): Promise; rejectTool(toolCallId: string, reason?: string): Promise; grantPlayLease(input: { readonly scopes: readonly string[]; readonly durationSeconds: number; readonly controlledEntityId: string; readonly hostCapabilityRevision: string; }): Promise; revokeLease(leaseId: string, reason?: CrowdyAgentPreemptionReason): Promise; pause(): Promise; resume(): Promise; cancelRun(runId?: string | undefined): Promise; /** Immediate human Stop: local preemption happens before transport calls. */ stop(): Promise; /** Editor changes synchronously preempt Build before best-effort cleanup. */ preemptForHumanEdit(): void; restoreCheckpoint(checkpointId: string): Promise; close(): Promise; destroy(): void; private attach; private replayHistory; private enqueueEvent; private startDrain; private bufferEvent; private drainBuffered; private applyEvent; private dispatchBrowserTool; private scheduleAcknowledge; private handleDisconnect; private refreshHeartbeat; private sendHeartbeat; private stopHeartbeat; private refreshWorkspaceRenewal; private renewWorkspaceLease; private stopWorkspaceRenewal; private scheduleReconnect; private loadRemoteContext; private assertProjectBinding; private mutationContext; private nextKey; private patchSession; private upsertLease; private disconnectSubscription; private requireSession; private preemptLocal; private update; private fail; private ensureAlive; } //# sourceMappingURL=controller.d.ts.map