import { type PlayerCodeBrokerOptions, type PlayerCodeGridBounds } from '../player-runtime/player-code-broker.js'; import type { PlayerComputeAPI } from '../domains/playerCompute.js'; import type { PlayerWalletAPI } from '../domains/playerWallet.js'; import { type CrowdyStudioDiagnostic } from './diagnostics.js'; import { type CrowdyStudioAtomicPatchInput, type CrowdyStudioAtomicPatchResult, type CrowdyStudioCheckpointMetadata, type CrowdyStudioFileRef, type CrowdyStudioPairingPreference, type CrowdyStudioProject, type CrowdyStudioProjectMetadata, type CrowdyStudioProjectProvider, type CrowdyStudioProjectSummary, type CrowdyStudioReferenceFile, type CrowdyStudioSaveState, type CrowdyStudioSynchronizationProvider, type CrowdyStudioTarget, type CrowdyStudioProjectSynchronization } from './models.js'; import { type CrowdyStudioNewProjectOptions } from './starter-projects.js'; export type CrowdyStudioPhase = 'IDLE' | 'TESTING_DRAFT' | 'DEPLOYING_LIVE' | 'COMPILING' | 'ENABLING' | 'RUNNING' | 'COMPILE_FAILED' | 'STOPPING' | 'STOPPED' | 'PARTIAL_FAILURE' | 'ERROR'; export type CrowdyStudioPolledSurface = 'runs' | 'logs' | 'usage'; export interface CrowdyStudioRuntimeStatus { phase: CrowdyStudioPhase; target?: CrowdyStudioTarget; message?: string; } export type CrowdyStudioRuntimeSyncState = 'NEVER_RUN' | 'RUNNING_SAVED' | 'RUNNING_STALE' | 'STOPPED'; export interface CrowdyStudioRuntimeSync { state: CrowdyStudioRuntimeSyncState; savedRevisionId?: string; runningRevisionId?: string; deployment?: 'DRAFT' | 'LIVE'; startedAt?: string; } export interface CrowdyStudioDeployResult { deployment: 'DRAFT' | 'LIVE'; status: 'RUNNING' | 'COMPILE_FAILED' | 'FAILED'; projectRevisionId: string; targets: readonly CrowdyStudioTarget[]; message: string; } export interface CrowdyStudioDeploymentPlan { expectedRevisionId: string; targets: readonly CrowdyStudioTarget[]; pairingPreference?: CrowdyStudioPairingPreference; projectContentHash?: string; } export interface CrowdyStudioAgentWorkContext { projectId?: string; projectRevisionId?: string; saveState: 'SAVED'; runtimeSync: CrowdyStudioRuntimeSync; } export interface CrowdyStudioUsageSnapshot { hourUnitsUsed: string; dayUnitsUsed: string; unitsPerHour: string | null; unitsPerDay: string | null; compilesThisHour: number; maxCompilesPerHour: number; gateStatus: string; gateReason: string | null; } export interface CrowdyStudioWalletSnapshot { balanceCents: string; currency: string; } export interface CrowdyStudioRun { runId: string; moduleName: string; triggerSource: string; startedAt: string; durationUs: number; fuelUsed: string; success: boolean; errorMessage?: string | null; } export interface CrowdyStudioInvokeResult { resultBase64?: string | null; resultJson?: string | null; fuelUsed?: string; durationUs?: number; } export interface CrowdyStudioState { projects: readonly CrowdyStudioProjectSummary[]; project: CrowdyStudioProject | null; personalLibraryFiles: readonly CrowdyStudioReferenceFile[]; commonFiles: readonly CrowdyStudioReferenceFile[]; openFiles: readonly CrowdyStudioFileRef[]; activeFile: CrowdyStudioFileRef | null; saveState: CrowdyStudioSaveState; saveMessage?: string; runtime: CrowdyStudioRuntimeStatus; runtimeSync: CrowdyStudioRuntimeSync; agentActivity: 'IDLE' | 'PREPARING' | 'WORKING' | 'PAUSED'; checkpoints: readonly CrowdyStudioCheckpointMetadata[]; buildOutput: string; authoritativeDiagnostics: readonly CrowdyStudioDiagnostic[]; localDiagnostics: readonly CrowdyStudioDiagnostic[]; runs: readonly CrowdyStudioRun[]; logs: readonly CrowdyStudioRun[]; usage: CrowdyStudioUsageSnapshot | null; wallet: CrowdyStudioWalletSnapshot | null; invokeResult: CrowdyStudioInvokeResult | null; } export type CrowdyStudioPlayerCompute = Pick; export type CrowdyStudioPlayerWallet = Pick; export interface CrowdyStudioBroker { start(bytes: ArrayBuffer): Promise; stop(): void; } export interface CrowdyStudioControllerOptions { projectProvider: CrowdyStudioProjectProvider; playerCompute: CrowdyStudioPlayerCompute; playerWallet?: CrowdyStudioPlayerWallet; appId: string; gridId: string; initialProjectId?: string; /** Required only when a project has a CLIENT target. */ grid?: PlayerCodeGridBounds; /** Platform-owned glue worker; required only for CLIENT execution. */ workerUrl?: string | URL; /** Page-side allow-listed host-call router; required only for CLIENT execution. */ onHostCall?: PlayerCodeBrokerOptions['onHostCall']; onPresentation?: PlayerCodeBrokerOptions['onPresentation']; /** Host-visible effective permissions; server authorization remains final. */ targetPermissions?: Partial>; clientTickIntervalMs?: number; autosaveMs?: number; retryMs?: number; compilePollMs?: number; compilePollLimit?: number; monitorPollMs?: number; /** Durable atomic-patch and checkpoint adapter, independent of GraphQL types. */ synchronizationProvider?: CrowdyStudioSynchronizationProvider; onProjectSynchronized?: (project: CrowdyStudioProject, synchronization: CrowdyStudioProjectSynchronization) => void; sleep?: (ms: number) => Promise; brokerFactory?: (options: PlayerCodeBrokerOptions) => CrowdyStudioBroker; isOnline?: () => boolean; onStateChange?: (state: CrowdyStudioState) => void; } export interface CrowdyStudioStopResult { serverStopped: boolean | null; clientStopped: boolean | null; failures: string[]; } /** * Headless project-first Crowdy Studio driver. It owns optimistic project saves, * file CRUD, deployment ordering, runtime polling, and client hot swaps; the * DOM mount is only a view over this state. */ export declare class CrowdyStudioController { private readonly options; private state; private readonly listeners; private readonly humanEditListeners; private autosaveTimer; private retryTimer; private savePromise; private editGeneration; private persistedGeneration; private conflictRemote; private broker; private operationGeneration; private agentOperationGeneration; private readonly visibleSurfaces; private readonly surfaceTimers; private pageVisible; private destroyed; constructor(options: CrowdyStudioControllerOptions); getState(): CrowdyStudioState; subscribe(listener: (state: CrowdyStudioState) => void): () => void; /** Subscribe to synchronous human-edit preemption signals. */ onHumanEdit(listener: () => void): () => void; /** * Flush autosave before a durable agent turn. Conflict/offline state fails * closed so Build never starts from an uncommitted browser snapshot. */ prepareForAgentWork(): Promise; finishAgentWork(paused?: boolean): void; beginAgentOperation(): number; /** Synchronously fence an in-flight agent compile/deploy/invoke operation. */ cancelAgentOperation(message?: string): void; canTarget(target: CrowdyStudioTarget, action: 'write' | 'run'): boolean; /** Credential-free context projection used by exact browser agent tools. */ getAgentContext(): { appRef: string; projectRef?: string; gridRef: string; contextVersion: string; projectContentHash?: string; }; initialize(): Promise; createProject(options: Omit): Promise; switchProject(projectId: string): Promise; private loadProject; private installProject; openFile(ref: CrowdyStudioFileRef): void; closeFile(ref: CrowdyStudioFileRef): void; fileContent(ref: CrowdyStudioFileRef): string; addFile(target: CrowdyStudioTarget, path: string, content?: string): void; renameFile(target: CrowdyStudioTarget, path: string, nextPath: string): void; deleteFile(target: CrowdyStudioTarget, path: string): void; importReferenceFile(reference: CrowdyStudioReferenceFile, destinationPath?: string): Promise; saveProjectFileToLibrary(target: CrowdyStudioTarget, path: string, title?: string): Promise; updateFile(target: CrowdyStudioTarget, path: string, content: string): void; updateSettings(patch: Partial>): void; setPairingPreference(preference: CrowdyStudioPairingPreference): void; setLocalDiagnostics(diagnostics: readonly CrowdyStudioDiagnostic[]): void; /** * Flush all edits in one optimistic-concurrency save. If edits arrive while * the request is in flight, a second atomic save follows with the new * revision instead of overwriting local content with the earlier response. */ saveNow(): Promise; retrySave(): Promise; acceptRemoteConflict(): Promise; overwriteConflict(): Promise; refreshCheckpoints(): Promise; /** * Validate every change against one immutable baseline, then persist and * synchronize all files or none. Routine agent patches cannot delete/rename. */ applyAtomicPatch(input: CrowdyStudioAtomicPatchInput): Promise; /** * Apply a server-published project revision to Monaco/kernel state. Pending * human edits win and turn the update into an explicit conflict. */ synchronizeProject(project: CrowdyStudioProject, synchronization: CrowdyStudioProjectSynchronization): void; restoreCheckpoint(checkpointId: string, approvalGrant: string, expectedRevisionId?: string): Promise; testDraft(agentOperation?: number): Promise; testDraftPlan(plan: CrowdyStudioDeploymentPlan, agentOperation?: number): Promise; deployLive(agentOperation?: number): Promise; deployLivePlan(plan: CrowdyStudioDeploymentPlan, agentOperation?: number): Promise; private deployProject; private compileTarget; private recordBuild; private enableServer; private runClient; stopProject(): Promise; invoke(exportName: string, paramsJson?: string, agentOperation?: number): Promise; setSurfaceVisible(surface: CrowdyStudioPolledSurface, visible: boolean): void; setPageVisible(visible: boolean): void; refreshSurface(surface: CrowdyStudioPolledSurface): Promise; destroy(): void; private performSaveLoop; private markEdited; private scheduleRetry; private scheduleSurfacePoll; private restartVisibleSurfacePolling; private stopSurfacePolling; private clearSurfaceTimer; private clearSaveTimers; private clearTimer; private clientRuntimeOptions; private assertDeploymentPlan; private checkOperation; private checkAgentOperation; private sleep; private requireProject; private requireFile; private assertProjectTarget; private scope; private setRuntime; private update; private ensureAlive; } //# sourceMappingURL=controller.d.ts.map