mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
166 lines
4.6 KiB
TypeScript
166 lines
4.6 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
export const RepoStatusSchema = z.enum(['cloning', 'ready', 'error'])
|
|
|
|
export const RepoSchema = z.object({
|
|
id: z.number(),
|
|
name: z.string().optional(),
|
|
repoUrl: z.string().url().optional(),
|
|
localPath: z.string(),
|
|
fullPath: z.string(),
|
|
sourcePath: z.string().optional(),
|
|
branch: z.string().optional(),
|
|
defaultBranch: z.string(),
|
|
cloneStatus: RepoStatusSchema,
|
|
clonedAt: z.number(),
|
|
lastPulled: z.number().optional(),
|
|
lastAccessedAt: z.number().optional(),
|
|
gitCredentialId: z.string().optional(),
|
|
isWorktree: z.boolean().optional(),
|
|
isLocal: z.boolean().optional(),
|
|
})
|
|
|
|
export const InternalRepoListResponseSchema = z.object({
|
|
repos: z.array(RepoSchema),
|
|
})
|
|
|
|
export const InternalCloneRepoRequestSchema = z.object({
|
|
repoUrl: z.string().trim().min(1),
|
|
branch: z.string().trim().min(1).optional(),
|
|
directoryName: z.string().trim().min(1).optional(),
|
|
}).strict()
|
|
|
|
export const CreateRepoRequestSchema = z.object({
|
|
repoUrl: z.string().url().optional(),
|
|
localPath: z.string().optional(),
|
|
branch: z.string().optional(),
|
|
directoryName: z.string().optional(),
|
|
useWorktree: z.boolean().optional(),
|
|
skipSSHVerification: z.boolean().optional(),
|
|
}).refine(
|
|
(data) => data.repoUrl || data.localPath,
|
|
{
|
|
message: "Either repoUrl or localPath must be provided",
|
|
path: ["repoUrl"],
|
|
}
|
|
)
|
|
|
|
export const DiscoverReposRequestSchema = z.object({
|
|
rootPath: z.string().trim().min(1),
|
|
maxDepth: z.number().int().min(0).max(8).optional(),
|
|
})
|
|
|
|
export const UpdateRepoRequestSchema = z.object({
|
|
name: z.string().trim().max(100).nullable(),
|
|
})
|
|
|
|
export const DeleteRepoRequestSchema = z.object({
|
|
deleteBranch: z.enum(['none', 'local', 'local-and-remote']).default('none'),
|
|
})
|
|
|
|
export const DeleteRepoResultSchema = z.object({
|
|
success: z.literal(true),
|
|
branch: z.object({
|
|
name: z.string(),
|
|
deleted: z.boolean(),
|
|
remoteDeleted: z.boolean(),
|
|
error: z.string().optional(),
|
|
}).optional(),
|
|
})
|
|
|
|
export const DiscoverReposResponseSchema = z.object({
|
|
repos: z.array(RepoSchema),
|
|
discoveredCount: z.number().int().nonnegative(),
|
|
existingCount: z.number().int().nonnegative(),
|
|
errors: z.array(
|
|
z.object({
|
|
path: z.string(),
|
|
error: z.string(),
|
|
})
|
|
),
|
|
})
|
|
|
|
export const AssistantModeFileSchema = z.object({
|
|
path: z.string(),
|
|
exists: z.boolean(),
|
|
created: z.boolean(),
|
|
})
|
|
|
|
export const AssistantModeStatusSchema = z.object({
|
|
repoId: z.number(),
|
|
directory: z.string(),
|
|
relativePath: z.literal('repos/assistant'),
|
|
warnings: z.array(z.object({
|
|
code: z.string(),
|
|
path: z.string(),
|
|
message: z.string(),
|
|
})).optional(),
|
|
files: z.object({
|
|
agentsMd: AssistantModeFileSchema,
|
|
opencodeJson: AssistantModeFileSchema,
|
|
}),
|
|
|
|
schedulesSkill: z.object({
|
|
path: z.string(),
|
|
created: z.boolean(),
|
|
}).optional(),
|
|
notificationsSkill: z.object({
|
|
path: z.string(),
|
|
created: z.boolean(),
|
|
}).optional(),
|
|
settingsSkill: z.object({
|
|
path: z.string(),
|
|
created: z.boolean(),
|
|
}).optional(),
|
|
repoManagementSkill: z.object({
|
|
path: z.string(),
|
|
created: z.boolean(),
|
|
}).optional(),
|
|
sessionManagementSkill: z.object({
|
|
path: z.string(),
|
|
created: z.boolean(),
|
|
}).optional(),
|
|
defaultAgent: z.object({
|
|
name: z.literal('assistant'),
|
|
path: z.string(),
|
|
exists: z.boolean(),
|
|
created: z.boolean(),
|
|
}).optional(),
|
|
})
|
|
|
|
export const AssistantModeInitRequestSchema = z.object({
|
|
overwriteAgentsMd: z.boolean().optional(),
|
|
overwriteOpenCodeConfig: z.boolean().optional(),
|
|
})
|
|
|
|
export const MirrorTargetBranchRequestSchema = z.object({
|
|
branch: z.string().trim().min(1),
|
|
})
|
|
|
|
export type MirrorTargetBranchRequest = z.infer<typeof MirrorTargetBranchRequestSchema>
|
|
|
|
const MirrorTargetPlanBaseSchema = z.object({
|
|
fullPath: z.string().min(1),
|
|
localPath: z.string().min(1),
|
|
branch: z.string().min(1),
|
|
currentBranch: z.string().min(1).nullable(),
|
|
})
|
|
|
|
export const MirrorTargetPlanResponseSchema = z.discriminatedUnion('kind', [
|
|
MirrorTargetPlanBaseSchema.extend({ kind: z.literal('new'), repoId: z.literal(null) }),
|
|
MirrorTargetPlanBaseSchema.extend({ kind: z.literal('in-place'), repoId: z.number().int().positive() }),
|
|
MirrorTargetPlanBaseSchema.extend({ kind: z.literal('existing'), repoId: z.number().int().positive() }),
|
|
])
|
|
|
|
export type MirrorTargetPlanResponse = z.infer<typeof MirrorTargetPlanResponseSchema>
|
|
|
|
export const MirrorTargetEnsureResponseSchema = z.object({
|
|
repoId: z.number().int().positive(),
|
|
fullPath: z.string().min(1),
|
|
localPath: z.string().min(1),
|
|
branch: z.string().min(1),
|
|
created: z.boolean(),
|
|
})
|
|
|
|
export type MirrorTargetEnsureResponse = z.infer<typeof MirrorTargetEnsureResponseSchema>
|