import { Option, Schema, SchemaIssue, Struct } from "effect";import { ApprovalRequestId, CheckpointRef, CommandId, EventId, IsoDateTime, MessageId, NonNegativeInt, ProjectId, ProviderItemId, ProviderSessionId, ProviderThreadId, ProviderTurnId, ThreadId, TrimmedNonEmptyString, TurnId,} from "./baseSchemas"; export const ORCHESTRATION_WS_METHODS = { getSnapshot: "orchestration.getSnapshot", dispatchCommand: "orchestration.dispatchCommand", getTurnDiff: "orchestration.getTurnDiff", getFullThreadDiff: "orchestration.getFullThreadDiff", replayEvents: "orchestration.replayEvents",} as const; export const ORCHESTRATION_WS_CHANNELS = { domainEvent: "orchestration.domainEvent",} as const; export const ProviderKind = Schema.Literals(["codex", "claudeCode"]);export type ProviderKind = typeof ProviderKind.Type;export const ProviderApprovalPolicy = Schema.Literals([ "untrusted", "on-failure", "on-request", "never",]);export type ProviderApprovalPolicy = typeof ProviderApprovalPolicy.Type;export const ProviderSandboxMode = Schema.Literals([ "read-only", "workspace-write", "danger-full-access",]);export type ProviderSandboxMode = typeof ProviderSandboxMode.Type;export const ProviderRequestKind = Schema.Literals(["command", "file-change"]);export type ProviderRequestKind = typeof ProviderRequestKind.Type;export const ProviderApprovalDecision = Schema.Literals([ "accept", "acceptForSession", "decline", "cancel",]);export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type; export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;export const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000; // Correlation id is command id by design in this model.export const CorrelationId = CommandId;export type CorrelationId = typeof CorrelationId.Type; export const ChatImageAttachment = Schema.Struct({ type: Schema.Literal("image"), name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)), mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100), Schema.isPattern(/^image\//i)), sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES)), dataUrl: TrimmedNonEmptyString.check( Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS), ),});export type ChatImageAttachment = typeof ChatImageAttachment.Type; export const ChatAttachment = Schema.Union([ChatImageAttachment]);export type ChatAttachment = typeof ChatAttachment.Type; export const ProjectScriptIcon = Schema.Literals([ "play", "test", "lint", "configure", "build", "debug",]);export type ProjectScriptIcon = typeof ProjectScriptIcon.Type; export const ProjectScript = Schema.Struct({ id: TrimmedNonEmptyString, name: TrimmedNonEmptyString, command: TrimmedNonEmptyString, icon: ProjectScriptIcon, runOnWorktreeCreate: Schema.Boolean,});export type ProjectScript = typeof ProjectScript.Type; export const OrchestrationProject = Schema.Struct({ id: ProjectId, title: TrimmedNonEmptyString, workspaceRoot: TrimmedNonEmptyString, defaultModel: Schema.NullOr(TrimmedNonEmptyString), scripts: Schema.Array(ProjectScript), createdAt: IsoDateTime, updatedAt: IsoDateTime, deletedAt: Schema.NullOr(IsoDateTime),});export type OrchestrationProject = typeof OrchestrationProject.Type; export const OrchestrationMessageRole = Schema.Literals(["user", "assistant", "system"]);export type OrchestrationMessageRole = typeof OrchestrationMessageRole.Type; export const OrchestrationMessage = Schema.Struct({ id: MessageId, role: OrchestrationMessageRole, text: Schema.String, attachments: Schema.optional(Schema.Array(ChatAttachment)), turnId: Schema.NullOr(TurnId), streaming: Schema.Boolean, createdAt: IsoDateTime, updatedAt: IsoDateTime,});export type OrchestrationMessage = typeof OrchestrationMessage.Type; export const OrchestrationSessionStatus = Schema.Literals([ "idle", "starting", "running", "ready", "interrupted", "stopped", "error",]);export type OrchestrationSessionStatus = typeof OrchestrationSessionStatus.Type; export const OrchestrationSession = Schema.Struct({ threadId: ThreadId, status: OrchestrationSessionStatus, providerName: Schema.NullOr(TrimmedNonEmptyString), providerSessionId: Schema.NullOr(ProviderSessionId), providerThreadId: Schema.NullOr(ProviderThreadId), activeTurnId: Schema.NullOr(TurnId), lastError: Schema.NullOr(TrimmedNonEmptyString), updatedAt: IsoDateTime,});export type OrchestrationSession = typeof OrchestrationSession.Type; export const OrchestrationCheckpointFile = Schema.Struct({ path: TrimmedNonEmptyString, kind: TrimmedNonEmptyString, additions: NonNegativeInt, deletions: NonNegativeInt,});export type OrchestrationCheckpointFile = typeof OrchestrationCheckpointFile.Type; export const OrchestrationCheckpointStatus = Schema.Literals(["ready", "missing", "error"]);export type OrchestrationCheckpointStatus = typeof OrchestrationCheckpointStatus.Type; export const OrchestrationCheckpointSummary = Schema.Struct({ turnId: TurnId, checkpointTurnCount: NonNegativeInt, checkpointRef: CheckpointRef, status: OrchestrationCheckpointStatus, files: Schema.Array(OrchestrationCheckpointFile), assistantMessageId: Schema.NullOr(MessageId), completedAt: IsoDateTime,});export type OrchestrationCheckpointSummary = typeof OrchestrationCheckpointSummary.Type; export const OrchestrationThreadActivityTone = Schema.Literals([ "info", "tool", "approval", "error",]);export type OrchestrationThreadActivityTone = typeof OrchestrationThreadActivityTone.Type; export const OrchestrationThreadActivity = Schema.Struct({ id: EventId, tone: OrchestrationThreadActivityTone, kind: TrimmedNonEmptyString, summary: TrimmedNonEmptyString, payload: Schema.Unknown, turnId: Schema.NullOr(TurnId), createdAt: IsoDateTime,});export type OrchestrationThreadActivity = typeof OrchestrationThreadActivity.Type; export const OrchestrationThread = Schema.Struct({ id: ThreadId, projectId: ProjectId, title: TrimmedNonEmptyString, model: TrimmedNonEmptyString, branch: Schema.NullOr(TrimmedNonEmptyString), worktreePath: Schema.NullOr(TrimmedNonEmptyString), latestTurnId: Schema.NullOr(TurnId), createdAt: IsoDateTime, updatedAt: IsoDateTime, deletedAt: Schema.NullOr(IsoDateTime), messages: Schema.Array(OrchestrationMessage), activities: Schema.Array(OrchestrationThreadActivity), checkpoints: Schema.Array(OrchestrationCheckpointSummary), session: Schema.NullOr(OrchestrationSession),});export type OrchestrationThread = typeof OrchestrationThread.Type; export const OrchestrationReadModel = Schema.Struct({ snapshotSequence: NonNegativeInt, projects: Schema.Array(OrchestrationProject), threads: Schema.Array(OrchestrationThread), updatedAt: IsoDateTime,});export type OrchestrationReadModel = typeof OrchestrationReadModel.Type; export const ProjectCreateCommand = Schema.Struct({ type: Schema.Literal("project.create"), commandId: CommandId, projectId: ProjectId, title: TrimmedNonEmptyString, workspaceRoot: TrimmedNonEmptyString, defaultModel: Schema.optional(TrimmedNonEmptyString), createdAt: IsoDateTime,}); export const ProjectMetaUpdateCommand = Schema.Struct({ type: Schema.Literal("project.meta.update"), commandId: CommandId, projectId: ProjectId, title: Schema.optional(TrimmedNonEmptyString), workspaceRoot: Schema.optional(TrimmedNonEmptyString), defaultModel: Schema.optional(TrimmedNonEmptyString), scripts: Schema.optional(Schema.Array(ProjectScript)),}); export const ProjectDeleteCommand = Schema.Struct({ type: Schema.Literal("project.delete"), commandId: CommandId, projectId: ProjectId,}); export const ThreadCreateCommand = Schema.Struct({ type: Schema.Literal("thread.create"), commandId: CommandId, threadId: ThreadId, projectId: ProjectId, title: TrimmedNonEmptyString, model: TrimmedNonEmptyString, branch: Schema.NullOr(TrimmedNonEmptyString), worktreePath: Schema.NullOr(TrimmedNonEmptyString), createdAt: IsoDateTime,}); export const ThreadDeleteCommand = Schema.Struct({ type: Schema.Literal("thread.delete"), commandId: CommandId, threadId: ThreadId,}); export const ThreadMetaUpdateCommand = Schema.Struct({ type: Schema.Literal("thread.meta.update"), commandId: CommandId, threadId: ThreadId, title: Schema.optional(TrimmedNonEmptyString), model: Schema.optional(TrimmedNonEmptyString), branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),}); export const ThreadTurnStartCommand = Schema.Struct({ type: Schema.Literal("thread.turn.start"), commandId: CommandId, threadId: ThreadId, message: Schema.Struct({ messageId: MessageId, role: Schema.Literal("user"), text: Schema.String, attachments: Schema.Array(ChatAttachment), }), model: Schema.optional(TrimmedNonEmptyString), effort: Schema.optional(TrimmedNonEmptyString), createdAt: IsoDateTime,}); export const ThreadTurnInterruptCommand = Schema.Struct({ type: Schema.Literal("thread.turn.interrupt"), commandId: CommandId, threadId: ThreadId, turnId: Schema.optional(TurnId), createdAt: IsoDateTime,}); export const ThreadApprovalRespondCommand = Schema.Struct({ type: Schema.Literal("thread.approval.respond"), commandId: CommandId, threadId: ThreadId, requestId: ApprovalRequestId, decision: ProviderApprovalDecision, createdAt: IsoDateTime,}); export const ThreadCheckpointRevertCommand = Schema.Struct({ type: Schema.Literal("thread.checkpoint.revert"), commandId: CommandId, threadId: ThreadId, turnCount: NonNegativeInt, createdAt: IsoDateTime,}); export const ThreadSessionStopCommand = Schema.Struct({ type: Schema.Literal("thread.session.stop"), commandId: CommandId, threadId: ThreadId, createdAt: IsoDateTime,}); export const ClientOrchestrationCommand = Schema.Union([ ProjectCreateCommand, ProjectMetaUpdateCommand, ProjectDeleteCommand, ThreadCreateCommand, ThreadDeleteCommand, ThreadMetaUpdateCommand, ThreadTurnStartCommand, ThreadTurnInterruptCommand, ThreadApprovalRespondCommand, ThreadCheckpointRevertCommand, ThreadSessionStopCommand,]);export type ClientOrchestrationCommand = typeof ClientOrchestrationCommand.Type; export const ThreadSessionSetCommand = Schema.Struct({ type: Schema.Literal("thread.session.set"), commandId: CommandId, threadId: ThreadId, session: OrchestrationSession, createdAt: IsoDateTime,}); export const ThreadMessageAssistantDeltaCommand = Schema.Struct({ type: Schema.Literal("thread.message.assistant.delta"), commandId: CommandId, threadId: ThreadId, messageId: MessageId, delta: Schema.String, turnId: Schema.optional(TurnId), createdAt: IsoDateTime,}); export const ThreadMessageAssistantCompleteCommand = Schema.Struct({ type: Schema.Literal("thread.message.assistant.complete"), commandId: CommandId, threadId: ThreadId, messageId: MessageId, turnId: Schema.optional(TurnId), createdAt: IsoDateTime,}); export const ThreadTurnDiffCompleteCommand = Schema.Struct({ type: Schema.Literal("thread.turn.diff.complete"), commandId: CommandId, threadId: ThreadId, turnId: TurnId, completedAt: IsoDateTime, checkpointRef: CheckpointRef, status: OrchestrationCheckpointStatus, files: Schema.Array(OrchestrationCheckpointFile), assistantMessageId: Schema.optional(MessageId), checkpointTurnCount: NonNegativeInt, createdAt: IsoDateTime,}); export const ThreadActivityAppendCommand = Schema.Struct({ type: Schema.Literal("thread.activity.append"), commandId: CommandId, threadId: ThreadId, activity: OrchestrationThreadActivity, createdAt: IsoDateTime,}); export const ThreadRevertCompleteCommand = Schema.Struct({ type: Schema.Literal("thread.revert.complete"), commandId: CommandId, threadId: ThreadId, turnCount: NonNegativeInt, createdAt: IsoDateTime,}); export const InternalOrchestrationCommand = Schema.Union([ ThreadSessionSetCommand, ThreadMessageAssistantDeltaCommand, ThreadMessageAssistantCompleteCommand, ThreadTurnDiffCompleteCommand, ThreadActivityAppendCommand, ThreadRevertCompleteCommand,]);export type InternalOrchestrationCommand = typeof InternalOrchestrationCommand.Type; export const OrchestrationCommand = Schema.Union([ ClientOrchestrationCommand, InternalOrchestrationCommand,]);export type OrchestrationCommand = typeof OrchestrationCommand.Type; export const OrchestrationEventType = Schema.Literals([ "project.created", "project.meta-updated", "project.deleted", "thread.created", "thread.deleted", "thread.meta-updated", "thread.message-sent", "thread.turn-start-requested", "thread.turn-interrupt-requested", "thread.approval-response-requested", "thread.checkpoint-revert-requested", "thread.reverted", "thread.session-stop-requested", "thread.session-set", "thread.turn-diff-completed", "thread.activity-appended",]);export type OrchestrationEventType = typeof OrchestrationEventType.Type; export const OrchestrationAggregateKind = Schema.Literals(["project", "thread"]);export type OrchestrationAggregateKind = typeof OrchestrationAggregateKind.Type;export const OrchestrationActorKind = Schema.Literals(["client", "server", "provider"]); export const ProjectCreatedPayload = Schema.Struct({ projectId: ProjectId, title: TrimmedNonEmptyString, workspaceRoot: TrimmedNonEmptyString, defaultModel: Schema.NullOr(TrimmedNonEmptyString), scripts: Schema.Array(ProjectScript), createdAt: IsoDateTime, updatedAt: IsoDateTime,}); export const ProjectMetaUpdatedPayload = Schema.Struct({ projectId: ProjectId, title: Schema.optional(TrimmedNonEmptyString), workspaceRoot: Schema.optional(TrimmedNonEmptyString), defaultModel: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), scripts: Schema.optional(Schema.Array(ProjectScript)), updatedAt: IsoDateTime,}); export const ProjectDeletedPayload = Schema.Struct({ projectId: ProjectId, deletedAt: IsoDateTime,}); export const ThreadCreatedPayload = Schema.Struct({ threadId: ThreadId, projectId: ProjectId, title: TrimmedNonEmptyString, model: TrimmedNonEmptyString, branch: Schema.NullOr(TrimmedNonEmptyString), worktreePath: Schema.NullOr(TrimmedNonEmptyString), createdAt: IsoDateTime, updatedAt: IsoDateTime,}); export const ThreadDeletedPayload = Schema.Struct({ threadId: ThreadId, deletedAt: IsoDateTime,}); export const ThreadMetaUpdatedPayload = Schema.Struct({ threadId: ThreadId, title: Schema.optional(TrimmedNonEmptyString), model: Schema.optional(TrimmedNonEmptyString), branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), updatedAt: IsoDateTime,}); export const ThreadMessageSentPayload = Schema.Struct({ threadId: ThreadId, messageId: MessageId, role: OrchestrationMessageRole, text: Schema.String, attachments: Schema.optional(Schema.Array(ChatAttachment)), turnId: Schema.NullOr(TurnId), streaming: Schema.Boolean, createdAt: IsoDateTime, updatedAt: IsoDateTime,}); export const ThreadTurnStartRequestedPayload = Schema.Struct({ threadId: ThreadId, messageId: MessageId, model: Schema.optional(TrimmedNonEmptyString), effort: Schema.optional(TrimmedNonEmptyString), createdAt: IsoDateTime,}); export const ThreadTurnInterruptRequestedPayload = Schema.Struct({ threadId: ThreadId, turnId: Schema.optional(TurnId),Lines 1–500 of 869. Load more
import { Option, Schema, SchemaIssue, Struct } from "effect"; import { ApprovalRequestId, CheckpointRef, CommandId, EventId, IsoDateTime, MessageId, NonNegativeInt, ProjectId, ProviderItemId, ProviderSessionId, ProviderThreadId, ProviderTurnId, ThreadId, TrimmedNonEmptyString, TurnId, } from "./baseSchemas"; export const ORCHESTRATION_WS_METHODS = { getSnapshot: "orchestration.getSnapshot", dispatchCommand: "orchestration.dispatchCommand", getTurnDiff: "orchestration.getTurnDiff", getFullThreadDiff: "orchestration.getFullThreadDiff", replayEvents: "orchestration.replayEvents", } as const; export const ORCHESTRATION_WS_CHANNELS = { domainEvent: "orchestration.domainEvent", } as const; export const ProviderKind = Schema.Literals(["codex", "claudeCode"]); export type ProviderKind = typeof ProviderKind.Type; export const ProviderApprovalPolicy = Schema.Literals([ "untrusted", "on-failure", "on-request", "never", ]); export type ProviderApprovalPolicy = typeof ProviderApprovalPolicy.Type; export const ProviderSandboxMode = Schema.Literals([ "read-only", "workspace-write", "danger-full-access", ]); export type ProviderSandboxMode = typeof ProviderSandboxMode.Type; export const ProviderRequestKind = Schema.Literals(["command", "file-change"]); export type ProviderRequestKind = typeof ProviderRequestKind.Type; export const ProviderApprovalDecision = Schema.Literals([ "accept", "acceptForSession", "decline", "cancel", ]); export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type; export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000; export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8; export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024; export const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000; // Correlation id is command id by design in this model. export const CorrelationId = CommandId; export type CorrelationId = typeof CorrelationId.Type; export const ChatImageAttachment = Schema.Struct({ type: Schema.Literal("image"), name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)), mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100), Schema.isPattern(/^image\//i)), sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES)), dataUrl: TrimmedNonEmptyString.check( Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS), ), }); export type ChatImageAttachment = typeof ChatImageAttachment.Type; export const ChatAttachment = Schema.Union([ChatImageAttachment]); export type ChatAttachment = typeof ChatAttachment.Type; export const ProjectScriptIcon = Schema.Literals([ "play", "test", "lint", "configure", "build", "debug", ]); export type ProjectScriptIcon = typeof ProjectScriptIcon.Type; export const ProjectScript = Schema.Struct({ id: TrimmedNonEmptyString, name: TrimmedNonEmptyString, command: TrimmedNonEmptyString, icon: ProjectScriptIcon, runOnWorktreeCreate: Schema.Boolean, }); export type ProjectScript = typeof ProjectScript.Type; export const OrchestrationProject = Schema.Struct({ id: ProjectId, title: TrimmedNonEmptyString, workspaceRoot: TrimmedNonEmptyString, defaultModel: Schema.NullOr(TrimmedNonEmptyString), scripts: Schema.Array(ProjectScript), createdAt: IsoDateTime, updatedAt: IsoDateTime, deletedAt: Schema.NullOr(IsoDateTime), }); export type OrchestrationProject = typeof OrchestrationProject.Type; export const OrchestrationMessageRole = Schema.Literals(["user", "assistant", "system"]); export type OrchestrationMessageRole = typeof OrchestrationMessageRole.Type; export const OrchestrationMessage = Schema.Struct({ id: MessageId, role: OrchestrationMessageRole, text: Schema.String, attachments: Schema.optional(Schema.Array(ChatAttachment)), turnId: Schema.NullOr(TurnId), streaming: Schema.Boolean, createdAt: IsoDateTime, updatedAt: IsoDateTime, }); export type OrchestrationMessage = typeof OrchestrationMessage.Type; export const OrchestrationSessionStatus = Schema.Literals([ "idle", "starting", "running", "ready", "interrupted", "stopped", "error", ]); export type OrchestrationSessionStatus = typeof OrchestrationSessionStatus.Type; export const OrchestrationSession = Schema.Struct({ threadId: ThreadId, status: OrchestrationSessionStatus, providerName: Schema.NullOr(TrimmedNonEmptyString), providerSessionId: Schema.NullOr(ProviderSessionId), providerThreadId: Schema.NullOr(ProviderThreadId), activeTurnId: Schema.NullOr(TurnId), lastError: Schema.NullOr(TrimmedNonEmptyString), updatedAt: IsoDateTime, }); export type OrchestrationSession = typeof OrchestrationSession.Type; export const OrchestrationCheckpointFile = Schema.Struct({ path: TrimmedNonEmptyString, kind: TrimmedNonEmptyString, additions: NonNegativeInt, deletions: NonNegativeInt, }); export type OrchestrationCheckpointFile = typeof OrchestrationCheckpointFile.Type; export const OrchestrationCheckpointStatus = Schema.Literals(["ready", "missing", "error"]); export type OrchestrationCheckpointStatus = typeof OrchestrationCheckpointStatus.Type; export const OrchestrationCheckpointSummary = Schema.Struct({ turnId: TurnId, checkpointTurnCount: NonNegativeInt, checkpointRef: CheckpointRef, status: OrchestrationCheckpointStatus, files: Schema.Array(OrchestrationCheckpointFile), assistantMessageId: Schema.NullOr(MessageId), completedAt: IsoDateTime, }); export type OrchestrationCheckpointSummary = typeof OrchestrationCheckpointSummary.Type; export const OrchestrationThreadActivityTone = Schema.Literals([ "info", "tool", "approval", "error", ]); export type OrchestrationThreadActivityTone = typeof OrchestrationThreadActivityTone.Type; export const OrchestrationThreadActivity = Schema.Struct({ id: EventId, tone: OrchestrationThreadActivityTone, kind: TrimmedNonEmptyString, summary: TrimmedNonEmptyString, payload: Schema.Unknown, turnId: Schema.NullOr(TurnId), createdAt: IsoDateTime, }); export type OrchestrationThreadActivity = typeof OrchestrationThreadActivity.Type; export const OrchestrationThread = Schema.Struct({ id: ThreadId, projectId: ProjectId, title: TrimmedNonEmptyString, model: TrimmedNonEmptyString, branch: Schema.NullOr(TrimmedNonEmptyString), worktreePath: Schema.NullOr(TrimmedNonEmptyString), latestTurnId: Schema.NullOr(TurnId), createdAt: IsoDateTime, updatedAt: IsoDateTime, deletedAt: Schema.NullOr(IsoDateTime), messages: Schema.Array(OrchestrationMessage), activities: Schema.Array(OrchestrationThreadActivity), checkpoints: Schema.Array(OrchestrationCheckpointSummary), session: Schema.NullOr(OrchestrationSession), }); export type OrchestrationThread = typeof OrchestrationThread.Type; export const OrchestrationReadModel = Schema.Struct({ snapshotSequence: NonNegativeInt, projects: Schema.Array(OrchestrationProject), threads: Schema.Array(OrchestrationThread), updatedAt: IsoDateTime, }); export type OrchestrationReadModel = typeof OrchestrationReadModel.Type; export const ProjectCreateCommand = Schema.Struct({ type: Schema.Literal("project.create"), commandId: CommandId, projectId: ProjectId, title: TrimmedNonEmptyString, workspaceRoot: TrimmedNonEmptyString, defaultModel: Schema.optional(TrimmedNonEmptyString), createdAt: IsoDateTime, }); export const ProjectMetaUpdateCommand = Schema.Struct({ type: Schema.Literal("project.meta.update"), commandId: CommandId, projectId: ProjectId, title: Schema.optional(TrimmedNonEmptyString), workspaceRoot: Schema.optional(TrimmedNonEmptyString), defaultModel: Schema.optional(TrimmedNonEmptyString), scripts: Schema.optional(Schema.Array(ProjectScript)), }); export const ProjectDeleteCommand = Schema.Struct({ type: Schema.Literal("project.delete"), commandId: CommandId, projectId: ProjectId, }); export const ThreadCreateCommand = Schema.Struct({ type: Schema.Literal("thread.create"), commandId: CommandId, threadId: ThreadId, projectId: ProjectId, title: TrimmedNonEmptyString, model: TrimmedNonEmptyString, branch: Schema.NullOr(TrimmedNonEmptyString), worktreePath: Schema.NullOr(TrimmedNonEmptyString), createdAt: IsoDateTime, }); export const ThreadDeleteCommand = Schema.Struct({ type: Schema.Literal("thread.delete"), commandId: CommandId, threadId: ThreadId, }); export const ThreadMetaUpdateCommand = Schema.Struct({ type: Schema.Literal("thread.meta.update"), commandId: CommandId, threadId: ThreadId, title: Schema.optional(TrimmedNonEmptyString), model: Schema.optional(TrimmedNonEmptyString), branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), }); export const ThreadTurnStartCommand = Schema.Struct({ type: Schema.Literal("thread.turn.start"), commandId: CommandId, threadId: ThreadId, message: Schema.Struct({ messageId: MessageId, role: Schema.Literal("user"), text: Schema.String, attachments: Schema.Array(ChatAttachment), }), model: Schema.optional(TrimmedNonEmptyString), effort: Schema.optional(TrimmedNonEmptyString), createdAt: IsoDateTime, }); export const ThreadTurnInterruptCommand = Schema.Struct({ type: Schema.Literal("thread.turn.interrupt"), commandId: CommandId, threadId: ThreadId, turnId: Schema.optional(TurnId), createdAt: IsoDateTime, }); export const ThreadApprovalRespondCommand = Schema.Struct({ type: Schema.Literal("thread.approval.respond"), commandId: CommandId, threadId: ThreadId, requestId: ApprovalRequestId, decision: ProviderApprovalDecision, createdAt: IsoDateTime, }); export const ThreadCheckpointRevertCommand = Schema.Struct({ type: Schema.Literal("thread.checkpoint.revert"), commandId: CommandId, threadId: ThreadId, turnCount: NonNegativeInt, createdAt: IsoDateTime, }); export const ThreadSessionStopCommand = Schema.Struct({ type: Schema.Literal("thread.session.stop"), commandId: CommandId, threadId: ThreadId, createdAt: IsoDateTime, }); export const ClientOrchestrationCommand = Schema.Union([ ProjectCreateCommand, ProjectMetaUpdateCommand, ProjectDeleteCommand, ThreadCreateCommand, ThreadDeleteCommand, ThreadMetaUpdateCommand, ThreadTurnStartCommand, ThreadTurnInterruptCommand, ThreadApprovalRespondCommand, ThreadCheckpointRevertCommand, ThreadSessionStopCommand, ]); export type ClientOrchestrationCommand = typeof ClientOrchestrationCommand.Type; export const ThreadSessionSetCommand = Schema.Struct({ type: Schema.Literal("thread.session.set"), commandId: CommandId, threadId: ThreadId, session: OrchestrationSession, createdAt: IsoDateTime, }); export const ThreadMessageAssistantDeltaCommand = Schema.Struct({ type: Schema.Literal("thread.message.assistant.delta"), commandId: CommandId, threadId: ThreadId, messageId: MessageId, delta: Schema.String, turnId: Schema.optional(TurnId), createdAt: IsoDateTime, }); export const ThreadMessageAssistantCompleteCommand = Schema.Struct({ type: Schema.Literal("thread.message.assistant.complete"), commandId: CommandId, threadId: ThreadId, messageId: MessageId, turnId: Schema.optional(TurnId), createdAt: IsoDateTime, }); export const ThreadTurnDiffCompleteCommand = Schema.Struct({ type: Schema.Literal("thread.turn.diff.complete"), commandId: CommandId, threadId: ThreadId, turnId: TurnId, completedAt: IsoDateTime, checkpointRef: CheckpointRef, status: OrchestrationCheckpointStatus, files: Schema.Array(OrchestrationCheckpointFile), assistantMessageId: Schema.optional(MessageId), checkpointTurnCount: NonNegativeInt, createdAt: IsoDateTime, }); export const ThreadActivityAppendCommand = Schema.Struct({ type: Schema.Literal("thread.activity.append"), commandId: CommandId, threadId: ThreadId, activity: OrchestrationThreadActivity, createdAt: IsoDateTime, }); export const ThreadRevertCompleteCommand = Schema.Struct({ type: Schema.Literal("thread.revert.complete"), commandId: CommandId, threadId: ThreadId, turnCount: NonNegativeInt, createdAt: IsoDateTime, }); export const InternalOrchestrationCommand = Schema.Union([ ThreadSessionSetCommand, ThreadMessageAssistantDeltaCommand, ThreadMessageAssistantCompleteCommand, ThreadTurnDiffCompleteCommand, ThreadActivityAppendCommand, ThreadRevertCompleteCommand, ]); export type InternalOrchestrationCommand = typeof InternalOrchestrationCommand.Type; export const OrchestrationCommand = Schema.Union([ ClientOrchestrationCommand, InternalOrchestrationCommand, ]); export type OrchestrationCommand = typeof OrchestrationCommand.Type; export const OrchestrationEventType = Schema.Literals([ "project.created", "project.meta-updated", "project.deleted", "thread.created", "thread.deleted", "thread.meta-updated", "thread.message-sent", "thread.turn-start-requested", "thread.turn-interrupt-requested", "thread.approval-response-requested", "thread.checkpoint-revert-requested", "thread.reverted", "thread.session-stop-requested", "thread.session-set", "thread.turn-diff-completed", "thread.activity-appended", ]); export type OrchestrationEventType = typeof OrchestrationEventType.Type; export const OrchestrationAggregateKind = Schema.Literals(["project", "thread"]); export type OrchestrationAggregateKind = typeof OrchestrationAggregateKind.Type; export const OrchestrationActorKind = Schema.Literals(["client", "server", "provider"]); export const ProjectCreatedPayload = Schema.Struct({ projectId: ProjectId, title: TrimmedNonEmptyString, workspaceRoot: TrimmedNonEmptyString, defaultModel: Schema.NullOr(TrimmedNonEmptyString), scripts: Schema.Array(ProjectScript), createdAt: IsoDateTime, updatedAt: IsoDateTime, }); export const ProjectMetaUpdatedPayload = Schema.Struct({ projectId: ProjectId, title: Schema.optional(TrimmedNonEmptyString), workspaceRoot: Schema.optional(TrimmedNonEmptyString), defaultModel: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), scripts: Schema.optional(Schema.Array(ProjectScript)), updatedAt: IsoDateTime, }); export const ProjectDeletedPayload = Schema.Struct({ projectId: ProjectId, deletedAt: IsoDateTime, }); export const ThreadCreatedPayload = Schema.Struct({ threadId: ThreadId, projectId: ProjectId, title: TrimmedNonEmptyString, model: TrimmedNonEmptyString, branch: Schema.NullOr(TrimmedNonEmptyString), worktreePath: Schema.NullOr(TrimmedNonEmptyString), createdAt: IsoDateTime, updatedAt: IsoDateTime, }); export const ThreadDeletedPayload = Schema.Struct({ threadId: ThreadId, deletedAt: IsoDateTime, }); export const ThreadMetaUpdatedPayload = Schema.Struct({ threadId: ThreadId, title: Schema.optional(TrimmedNonEmptyString), model: Schema.optional(TrimmedNonEmptyString), branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), updatedAt: IsoDateTime, }); export const ThreadMessageSentPayload = Schema.Struct({ threadId: ThreadId, messageId: MessageId, role: OrchestrationMessageRole, text: Schema.String, attachments: Schema.optional(Schema.Array(ChatAttachment)), turnId: Schema.NullOr(TurnId), streaming: Schema.Boolean, createdAt: IsoDateTime, updatedAt: IsoDateTime, }); export const ThreadTurnStartRequestedPayload = Schema.Struct({ threadId: ThreadId, messageId: MessageId, model: Schema.optional(TrimmedNonEmptyString), effort: Schema.optional(TrimmedNonEmptyString), createdAt: IsoDateTime, }); export const ThreadTurnInterruptRequestedPayload = Schema.Struct({ threadId: ThreadId, turnId: Schema.optional(TurnId),