diff --git a/src/index.ts b/src/index.ts index b87a6c0..628b920 100644 --- a/src/index.ts +++ b/src/index.ts @@ -656,232 +656,578 @@ export const ControlPlaneCutoverResponseSchema = z.object({ packages: z.array(ControlPlaneRunningPackageSchema), }); -export type ControlPlaneRunRequest = z.output< - typeof ControlPlaneRunRequestSchema ->; -export type ControlPlaneCheckRequest = z.output< - typeof ControlPlaneCheckRequestSchema ->; -export type ControlPlaneCutoverRequest = z.output< - typeof ControlPlaneCutoverRequestSchema ->; -export type ControlPlaneClearStateRequest = z.output< - typeof ControlPlaneClearStateRequestSchema ->; -export type ControlPlaneDescribeRequest = z.output< - typeof ControlPlaneDescribeRequestSchema ->; -export type ControlPlaneLogsRequest = z.output< - typeof ControlPlaneLogsRequestSchema ->; -export type ControlPlaneErrorsRequest = z.output< - typeof ControlPlaneErrorsRequestSchema ->; -export type ControlPlaneReplEvalRequest = z.output< - typeof ControlPlaneReplEvalRequestSchema ->; -export type ControlPlaneReplCloseRequest = z.output< - typeof ControlPlaneReplCloseRequestSchema ->; -export type ControlPlaneDeviceTarget = z.output< - typeof ControlPlaneDeviceTargetSchema ->; -export type ControlPlaneDeviceViewport = z.output< - typeof ControlPlaneDeviceViewportSchema ->; -export type ControlPlaneDevice = z.output; -export type ControlPlaneDevicesResponse = z.output< - typeof ControlPlaneDevicesResponseSchema ->; -export type ControlPlaneDeviceAssignRequest = z.output< - typeof ControlPlaneDeviceAssignRequestSchema ->; -export type ControlPlaneDeviceRenameRequest = z.output< - typeof ControlPlaneDeviceRenameRequestSchema ->; -export type ControlPlaneDeviceRemoveRequest = z.output< - typeof ControlPlaneDeviceRemoveRequestSchema ->; -export type ControlPlaneDeviceIdentifyRequest = z.output< - typeof ControlPlaneDeviceIdentifyRequestSchema ->; -export type ControlPlaneDeviceSessionRequest = z.output< - typeof ControlPlaneDeviceSessionRequestSchema ->; -export type ControlPlaneDeviceSessionResponse = z.output< - typeof ControlPlaneDeviceSessionResponseSchema ->; -export type ControlPlanePublicAccessTarget = z.output< - typeof ControlPlanePublicAccessTargetSchema ->; -export type ControlPlanePublicAuthGrantRequest = z.output< - typeof ControlPlanePublicAuthGrantRequestSchema ->; -export type ControlPlanePublicAuthGrantResponse = z.output< - typeof ControlPlanePublicAuthGrantResponseSchema ->; -export type ControlPlanePublicAuthGrantRevokeRequest = z.output< - typeof ControlPlanePublicAuthGrantRevokeRequestSchema ->; -export type ControlPlanePublicAuthGrantRevokeResponse = z.output< - typeof ControlPlanePublicAuthGrantRevokeResponseSchema ->; -export type ControlPlanePublicSessionRequest = z.output< - typeof ControlPlanePublicSessionRequestSchema ->; -export type ControlPlanePublicSessionResponse = z.output< - typeof ControlPlanePublicSessionResponseSchema ->; -export type ControlPlaneSurfaceSessionRequest = z.output< - typeof ControlPlaneSurfaceSessionRequestSchema ->; -export type ControlPlaneSurfaceSessionResponse = z.output< - typeof ControlPlaneSurfaceSessionResponseSchema ->; -export type ControlPlaneWorkspacePackage = z.output< - typeof ControlPlaneWorkspacePackageSchema ->; -export type ControlPlaneStateContext = z.output< - typeof ControlPlaneStateContextSchema ->; -export type ControlPlaneBrowserAuthMessage = z.output< - typeof ControlPlaneBrowserAuthMessageSchema ->; -export type ControlPlaneBrowserOpenRootContextParams = z.output< - typeof ControlPlaneBrowserOpenRootContextParamsSchema ->; -export type ControlPlaneBrowserOpenDerivedContextParams = z.output< - typeof ControlPlaneBrowserOpenDerivedContextParamsSchema ->; -export type ControlPlaneBrowserCloseStateContextParams = z.output< - typeof ControlPlaneBrowserCloseStateContextParamsSchema ->; -export type ControlPlaneBrowserCallParams = z.output< - typeof ControlPlaneBrowserCallParamsSchema ->; -export type ControlPlaneBrowserValueGetParams = z.output< - typeof ControlPlaneBrowserValueGetParamsSchema ->; -export type ControlPlaneBrowserSubscribeParams = z.output< - typeof ControlPlaneBrowserSubscribeParamsSchema ->; -export type ControlPlaneBrowserUnsubscribeParams = z.output< - typeof ControlPlaneBrowserUnsubscribeParamsSchema ->; -export type ControlPlaneBrowserSubscriptionReadyParams = z.output< - typeof ControlPlaneBrowserSubscriptionReadyParamsSchema ->; -export type ControlPlaneBrowserRequestMessage = z.output< - typeof ControlPlaneBrowserRequestMessageSchema ->; -export type ControlPlaneBrowserClientMessage = z.output< - typeof ControlPlaneBrowserClientMessageSchema ->; -export type ControlPlaneBrowserResponseMessage = z.output< - typeof ControlPlaneBrowserResponseMessageSchema ->; -export type ControlPlaneBrowserSubscriptionDataMessage = z.output< - typeof ControlPlaneBrowserSubscriptionDataMessageSchema ->; -export type ControlPlaneBrowserAuthAckMessage = z.output< - typeof ControlPlaneBrowserAuthAckMessageSchema ->; -export type ControlPlaneBrowserStatusInvalidatedMessage = z.output< - typeof ControlPlaneBrowserStatusInvalidatedMessageSchema ->; -export type ControlPlaneBrowserServerMessage = z.output< - typeof ControlPlaneBrowserServerMessageSchema ->; -export type ControlPlaneDeviceSocketConnectMessage = z.output< - typeof ControlPlaneDeviceSocketConnectMessageSchema ->; -export type ControlPlaneDeviceSocketUpdateMessage = z.output< - typeof ControlPlaneDeviceSocketUpdateMessageSchema ->; -export type ControlPlaneDeviceSocketClientMessage = z.output< - typeof ControlPlaneDeviceSocketClientMessageSchema ->; -export type ControlPlaneDeviceSocketReadyMessage = z.output< - typeof ControlPlaneDeviceSocketReadyMessageSchema ->; -export type ControlPlaneDeviceSocketStateMessage = z.output< - typeof ControlPlaneDeviceSocketStateMessageSchema ->; -export type ControlPlaneDeviceSocketRemovedMessage = z.output< - typeof ControlPlaneDeviceSocketRemovedMessageSchema ->; -export type ControlPlaneDeviceSocketServerMessage = z.output< - typeof ControlPlaneDeviceSocketServerMessageSchema ->; -export type ControlPlanePackageLogEntry = z.output< - typeof ControlPlanePackageLogEntrySchema ->; -export type ControlPlaneRuntimeErrorPhase = z.output< - typeof ControlPlaneRuntimeErrorPhaseSchema ->; -export type ControlPlanePackageErrorEntry = z.output< - typeof ControlPlanePackageErrorEntrySchema ->; -export type ControlPlaneLogsResponse = z.output< - typeof ControlPlaneLogsResponseSchema ->; -export type ControlPlaneErrorsResponse = z.output< - typeof ControlPlaneErrorsResponseSchema ->; -export type ControlPlaneReplLogEntry = z.output< - typeof ControlPlaneReplLogEntrySchema ->; -export type ControlPlaneReplSession = z.output< - typeof ControlPlaneReplSessionSchema ->; -export type ControlPlaneReplEvalResponse = z.output< - typeof ControlPlaneReplEvalResponseSchema ->; -export type ControlPlaneReplCloseResponse = z.output< - typeof ControlPlaneReplCloseResponseSchema ->; -export type ControlPlaneRemoteDomPayload = z.output< - typeof ControlPlaneRemoteDomPayloadSchema ->; -export type ControlPlaneDependencyInput = z.output< - typeof ControlPlaneDependencyInputSchema ->; -export type ControlPlaneDependencyNode = z.output< - typeof ControlPlaneDependencyNodeSchema ->; -export type ControlPlaneDependencyGraph = z.output< - typeof ControlPlaneDependencyGraphSchema ->; -export type ControlPlaneRunningPackage = z.output< - typeof ControlPlaneRunningPackageSchema ->; -export type ControlPlaneCheckStatus = z.output< - typeof ControlPlaneCheckResultSchema ->["status"]; -export type ControlPlaneCheckResult = z.output< - typeof ControlPlaneCheckResultSchema ->; -export type ControlPlaneSchemaResourceDescription = z.output< - typeof ControlPlaneSchemaResourceDescriptionSchema ->; -export type ControlPlanePackageSchemaDescription = z.output< - typeof ControlPlanePackageSchemaDescriptionSchema ->; -export type ControlPlaneSchemaDescriptionResult = z.output< - typeof ControlPlaneSchemaDescriptionResultSchema ->; -export type ControlPlaneRunResponse = z.output< - typeof ControlPlaneRunResponseSchema ->; -export type ControlPlaneClearStateResponse = z.output< - typeof ControlPlaneClearStateResponseSchema ->; -export type ControlPlaneStatusResponse = z.output< - typeof ControlPlaneStatusResponseSchema ->; -export type ControlPlaneCutoverResponse = z.output< - typeof ControlPlaneCutoverResponseSchema ->; +export type ControlPlaneRunRequest = { + target: string; +}; + +export type ControlPlaneCheckRequest = { + packageName: string; + rev: string; +}; + +export type ControlPlaneCutoverRequest = { + targets: string[]; +}; + +export type ControlPlaneClearStateRequest = { + packageName: string; + recursive?: boolean; +}; + +export type ControlPlaneDescribeRequest = ControlPlaneCheckRequest; + +export type ControlPlaneLogsRequest = { + packageName: string; + tail?: number; + stream?: "stdout" | "stderr" | "all"; +}; + +export type ControlPlaneErrorsRequest = { + packageName?: string; + stateContextId?: string; + tail?: number; + acknowledge?: boolean; +}; + +export type ControlPlaneReplEvalRequest = { + sessionId?: string; + code: string; + autoClose?: boolean; + defaultStateContextId: string | null; +}; + +export type ControlPlaneReplCloseRequest = { + sessionId: string; +}; + +export type ControlPlaneDeviceTarget = { + packageName: string; + stateContextId: string; + surfaceId: string; + requestFullscreen?: boolean; +}; + +export type ControlPlaneDeviceViewport = { + width: number; + height: number; + pixelRatio: number | null; +}; + +export type ControlPlaneDevice = { + deviceId: string; + name: string | null; + createdAt: string; + lastSeenAt: string | null; + connected: boolean; + assignment: ControlPlaneDeviceTarget | null; + configuredAssignment: ControlPlaneDeviceTarget | null; + identifyUntil: string | null; + lastUserAgent: string | null; + viewport: ControlPlaneDeviceViewport | null; +}; + +export type ControlPlaneDevicesResponse = { + devices: ControlPlaneDevice[]; +}; + +export type ControlPlaneDeviceAssignRequest = { + deviceId: string; + target: ControlPlaneDeviceTarget | null; +}; + +export type ControlPlaneDeviceRenameRequest = { + deviceId: string; + name: string | null; +}; + +export type ControlPlaneDeviceRemoveRequest = { + deviceId: string; +}; + +export type ControlPlaneDeviceIdentifyRequest = { + deviceId: string; + durationMs?: number; +}; + +export type ControlPlaneDeviceSessionRequest = { + deviceId: string; + sessionToken: string; + requestedTarget?: ControlPlaneDeviceTarget | null; + userAgent: string | null; + viewport: ControlPlaneDeviceViewport | null; +}; + +export type ControlPlaneDeviceSessionResponse = { + device: ControlPlaneDevice; +}; + +export type ControlPlanePublicAccessTarget = + | { + kind: "device"; + target?: ControlPlaneDeviceTarget | null; + } + | { + kind: "browser-surface"; + packageName?: string; + stateContextId: string; + surfaceId: string; + requestFullscreen?: boolean; + } + | { + kind: "remote-dom"; + packageName?: string; + stateContextId: string; + }; + +export type ControlPlanePublicAuthGrantRequest = { + target: ControlPlanePublicAccessTarget; +}; + +export type ControlPlanePublicAuthGrantResponse = { + authGrant: string; + target: ControlPlanePublicAccessTarget; +}; + +export type ControlPlanePublicAuthGrantRevokeRequest = { + authGrant: string; +}; + +export type ControlPlanePublicAuthGrantRevokeResponse = { + revoked: boolean; +}; + +export type ControlPlanePublicSessionRequest = { + authGrant: string; +}; + +export type ControlPlanePublicSessionResponse = { + sessionToken: string; + target: ControlPlanePublicAccessTarget; + expiresAt: string; +}; + +export type ControlPlaneSurfaceSessionRequest = { + target: Extract< + ControlPlanePublicAccessTarget, + { kind: "browser-surface" | "remote-dom" } + >; +}; + +export type ControlPlaneSurfaceSessionResponse = { + sessionToken: string; + target: ControlPlaneSurfaceSessionRequest["target"]; + expiresAt: string; +}; + +export type ControlPlaneWorkspacePackage = { + packageName: string; + headCommit: string; + ignored: boolean; +}; + +export type ControlPlaneStateContext = { + id: string; + packageName: string; + packageRef: string; + createdAt: string; + parentStateContextId: string | null; + namespace: string | null; + kind: "root" | "derived"; +}; + +export type ControlPlaneBrowserAuthMessage = { + type: "auth"; + secret: string; +}; + +export type ControlPlaneBrowserOpenRootContextParams = { + target: string; +}; + +export type ControlPlaneBrowserOpenDerivedContextParams = { + target: string; + targetPackageName?: string; + callerStateContextId: string; + contextNamespace: string | null; +}; + +export type ControlPlaneBrowserCloseStateContextParams = { + stateContextId: string; +}; + +export type ControlPlaneBrowserCallParams = { + target: string; + functionName: string; + params: unknown; + stateContextId: string; +}; + +export type ControlPlaneBrowserValueGetParams = { + target: string; + valueName: string; + params: unknown; + stateContextId: string; +}; + +export type ControlPlaneBrowserSubscribeParams = { + target: string; + resourceName: string; + params: unknown; + stateContextId: string; + subscriptionNamespace: string | null; +}; + +export type ControlPlaneBrowserUnsubscribeParams = { + subscriptionId: string; +}; + +export type ControlPlaneBrowserSubscriptionReadyParams = + ControlPlaneBrowserUnsubscribeParams; + +export type ControlPlaneBrowserRequestMessage = + | { + type: "request"; + requestId: string; + method: "open-root-context"; + params: ControlPlaneBrowserOpenRootContextParams; + } + | { + type: "request"; + requestId: string; + method: "open-derived-context"; + params: ControlPlaneBrowserOpenDerivedContextParams; + } + | { + type: "request"; + requestId: string; + method: "close-state-context"; + params: ControlPlaneBrowserCloseStateContextParams; + } + | { + type: "request"; + requestId: string; + method: "call"; + params: ControlPlaneBrowserCallParams; + } + | { + type: "request"; + requestId: string; + method: "value-get"; + params: ControlPlaneBrowserValueGetParams; + } + | { + type: "request"; + requestId: string; + method: "event-subscribe"; + params: ControlPlaneBrowserSubscribeParams; + } + | { + type: "request"; + requestId: string; + method: "value-watch"; + params: ControlPlaneBrowserSubscribeParams; + } + | { + type: "request"; + requestId: string; + method: "unsubscribe"; + params: ControlPlaneBrowserUnsubscribeParams; + } + | { + type: "request"; + requestId: string; + method: "subscription-ready"; + params: ControlPlaneBrowserSubscriptionReadyParams; + }; + +export type ControlPlaneBrowserClientMessage = + | ControlPlaneBrowserAuthMessage + | ControlPlaneBrowserRequestMessage; + +export type ControlPlaneBrowserResponseMessage = + | { + type: "response"; + requestId: string; + ok: true; + result?: unknown; + } + | { + type: "response"; + requestId: string; + ok: false; + error: string; + }; + +export type ControlPlaneBrowserSubscriptionDataMessage = { + type: "subscription-data"; + subscriptionId: string; + data: unknown; +}; + +export type ControlPlaneBrowserAuthAckMessage = { + type: "auth-ack"; +}; + +export type ControlPlaneBrowserStatusInvalidatedMessage = { + type: "status-invalidated"; + reason: + | "state-context-opened" + | "state-context-closed" + | "running-packages-changed" + | "repl-sessions-changed" + | "runtime-errors-changed" + | "devices-changed"; +}; + +export type ControlPlaneBrowserServerMessage = + | ControlPlaneBrowserAuthAckMessage + | ControlPlaneBrowserStatusInvalidatedMessage + | ControlPlaneBrowserResponseMessage + | ControlPlaneBrowserSubscriptionDataMessage; + +export type ControlPlaneDeviceSocketConnectMessage = { + type: "device-connect"; + deviceId: string; + sessionToken: string; + requestedTarget?: ControlPlaneDeviceTarget | null; + userAgent?: string | null; + viewport?: ControlPlaneDeviceViewport | null; +}; + +export type ControlPlaneDeviceSocketUpdateMessage = { + type: "device-update"; + viewport?: ControlPlaneDeviceViewport | null; +}; + +export type ControlPlaneDeviceSocketClientMessage = + | ControlPlaneDeviceSocketConnectMessage + | ControlPlaneDeviceSocketUpdateMessage; + +export type ControlPlaneDeviceSocketReadyMessage = { + type: "device-ready"; + device: ControlPlaneDevice; +}; + +export type ControlPlaneDeviceSocketStateMessage = { + type: "device-state"; + device: ControlPlaneDevice; +}; + +export type ControlPlaneDeviceSocketRemovedMessage = { + type: "device-removed"; + deviceId: string; +}; + +export type ControlPlaneDeviceSocketServerMessage = + | ControlPlaneDeviceSocketReadyMessage + | ControlPlaneDeviceSocketStateMessage + | ControlPlaneDeviceSocketRemovedMessage; + +export type ControlPlanePackageLogEntry = { + id: string; + createdAt: string; + packageName: string; + label: string; + processId: number | null; + stream: "stdout" | "stderr"; + text: string; +}; + +export type ControlPlaneRuntimeErrorPhase = + | "on-create" + | "on-destroy" + | "on-context-open" + | "on-context-close" + | "browser-surface" + | "function" + | "event-subscribe" + | "event-cleanup" + | "value-get" + | "value-watch" + | "value-cleanup" + | "subscription-publish" + | "internal"; + +export type ControlPlanePackageErrorEntry = { + id: string; + createdAt: string; + packageName: string; + label: string | null; + processId: number | null; + stateContextId: string | null; + phase: ControlPlaneRuntimeErrorPhase; + functionName: string | null; + resourceKind: "event" | "value" | null; + resourceName: string | null; + surfaceId: string | null; + hostSessionId: string | null; + message: string; + stack: string | null; + acknowledgedAt: string | null; +}; + +export type ControlPlaneLogsResponse = { + packageName: string; + entries: ControlPlanePackageLogEntry[]; +}; + +export type ControlPlaneErrorsResponse = { + entries: ControlPlanePackageErrorEntry[]; + acknowledgedCount: number; +}; + +export type ControlPlaneReplLogEntry = { + level: "log" | "info" | "warn" | "error"; + text: string; +}; + +export type ControlPlaneReplSession = { + sessionId: string; + createdAt: string; + lastActivityAt: string; + ownedStateContextIds: string[]; + borrowedStateContextIds: string[]; + subscriptionCount: number; + tempDirectory: string; +}; + +export type ControlPlaneReplEvalResponse = { + session: ControlPlaneReplSession; + created: boolean; + closed: boolean; + ok: boolean; + result: string | null; + logs: ControlPlaneReplLogEntry[]; + error: string | null; +}; + +export type ControlPlaneReplCloseResponse = { + sessionId: string; + closed: boolean; +}; + +export type ControlPlaneRemoteDomPayload = { + protocol: string; + revision: number; + baseRevision: number | null; + fromEmpty: boolean; + mutations: unknown[]; +}; + +export type ControlPlaneDependencyInput = { + inputName: string; + targetNodeId: string; +}; + +export type ControlPlaneDependencyNode = { + nodeId: string; + label: string; + originalRef: string | null; + lockedRef: string | null; + version: string | null; + inputs: ControlPlaneDependencyInput[]; +}; + +export type ControlPlaneDependencyGraph = { + rootNodeId: string; + nodes: ControlPlaneDependencyNode[]; +}; + +export type ControlPlaneRunningPackage = { + key: string; + label: string; + packageName: string; + flakeRef: string; + requestedRef: string | null; + connected: boolean; + processId: number | null; + openedStateContextIds: string[]; + rootStateContextIds: string[]; + resolvedRef: string | null; + version: string | null; + unreadErrorCount: number; + lastErrorAt: string | null; + dependencyGraph: ControlPlaneDependencyGraph | null; + dependencyGraphError: string | null; +}; + +export type ControlPlaneCheckStatus = "running" | "passed" | "failed"; + +export type ControlPlaneCheckResult = { + packageName: string; + rev: string; + status: ControlPlaneCheckStatus; + startedAt: string; + finishedAt: string | null; + summary: string | null; + logExcerpt: string | null; +}; + +export type ControlPlaneSchemaAnnotation = Record & { + type: string; +}; + +export type ControlPlaneSchemaResourceDescription = { + name: string; + description: string | null; + annotations: ControlPlaneSchemaAnnotation[]; + takesParams: boolean; + inputDescription: string | null; + inputJsonSchema: Record | null; + outputDescription: string | null; + outputJsonSchema: Record | null; + paramsDescription: string | null; + paramsJsonSchema: Record | null; + dataDescription: string | null; + dataJsonSchema: Record | null; + history?: boolean; + payloadMode: string | null; +}; + +export type ControlPlanePackageSchemaDescription = { + packageName: string; + schemaPackageName: string; + description: string | null; + annotations: ControlPlaneSchemaAnnotation[]; + functions: ControlPlaneSchemaResourceDescription[]; + events: ControlPlaneSchemaResourceDescription[]; + values: ControlPlaneSchemaResourceDescription[]; +}; + +export type ControlPlaneSchemaDescriptionResult = { + packageName: string; + rev: string; + generatedAt: string; + status: "available" | "unavailable"; + data: ControlPlanePackageSchemaDescription | null; + error: string | null; +}; + +export type ControlPlaneRunResponse = { + stateContextId: string; + package: ControlPlaneRunningPackage; +}; + +export type ControlPlaneClearStateResponse = { + packageNames: string[]; + clearedDirectories: string[]; + packages: ControlPlaneRunningPackage[]; +}; + +export type ControlPlaneStatusResponse = { + generatedAt: string; + workspacePackages: ControlPlaneWorkspacePackage[]; + stateContexts: ControlPlaneStateContext[]; + replSessions: ControlPlaneReplSession[]; + devices: ControlPlaneDevice[]; + packages: ControlPlaneRunningPackage[]; + checks: ControlPlaneCheckResult[]; + descriptions: ControlPlaneSchemaDescriptionResult[]; +}; + +export type ControlPlaneCutoverResponse = { + packages: ControlPlaneRunningPackage[]; +}; export const parseControlPlaneDeviceTarget = (value: unknown) => parseWith(ControlPlaneDeviceTargetSchema, value);