Files
shumai/packages/dtos/src/team.ts
T
Yiling-J 4ac274cdd4 feat(runner): replace server-side bash sandbox with remote runner (#530)
* feat(runner): replace server-side bash sandbox with remote runner

* fix(runner): address review findings for output bounds, key rotation, defaults, and generated uploads

* chore(docker): remove sandbox privileges and env vars from remaining compose files

* feat(cli): add runner start with bundled SRT sandboxing (#535)

* refactor(agent): expose runner bash without skill gating

* feat(cli): add runner start with optional SRT sandboxing

* refactor(cli): remove runner Python dependency

* feat(cli): bundle SRT and use platform-native runner shells

* refactor(cli): delegate runner processes to Execa

* chore(cli): upgrade @anthropic-ai/sandbox-runtime to 0.0.83

* feat(cli): discover Bash for Windows runners

Use Pi-style Bash discovery and launch behavior, exercise the packaged CLI shell, and wait for pending ZIP metadata reads before closing cancelled downloads.

* fix(runner): enforce ownership and safe reconnects

Gate dispatch on reconciliation, retain cancellations across disconnects, and stop replaced clients. Guard the single-server runner topology with a database lease. Restage missing generated inputs, report signal exits, and bound generated-file cleanup.

* feat(webui): add Korean translations for agent runners

* feat(cli): add runner event logging and --verbose flag (#536)

* feat(cli): add runner event logging and --verbose flag

* fix(cli): log runner capacity rejections accurately and use monotonic duration
2026-11-18 15:58:57 +08:00

275 lines
7.7 KiB
TypeScript

import { z } from 'zod'
import { UserType, TeamMemberScope } from '@shumai/db/enums'
import { paginationPageInfoSchema, paginationParamsSchema } from './pagination'
export { UserType, TeamMemberScope }
export const teamInfoSchema = z.object({
id: z.string(),
name: z.string(),
rootFolder: z.string().optional(),
updatedAt: z.union([z.string(), z.date()]),
})
export type TeamInfo = z.infer<typeof teamInfoSchema>
export const getUserTeamsRequestSchema = paginationParamsSchema
export type GetUserTeamsRequest = z.infer<typeof getUserTeamsRequestSchema>
export const getUserTeamsResponseSchema = z.object({
data: z.array(teamInfoSchema),
pageInfo: paginationPageInfoSchema,
})
export type GetUserTeamsResponse = z.infer<typeof getUserTeamsResponseSchema>
export const joinTeamRequestSchema = z.object({
teamId: z.string(),
userId: z.string(),
})
export type JoinTeamRequest = z.infer<typeof joinTeamRequestSchema>
export const getMeResponseSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().optional(),
role: z.enum(['owner', 'editor', 'reviewer', 'bot', 'unknown']),
image: z.string().optional(),
unreadNotificationCount: z.number().optional(),
})
export type GetMeResponse = z.infer<typeof getMeResponseSchema>
export const updateMeRequestSchema = z.object({
name: z.string().optional(),
imageKey: z.string().nullable().optional(),
})
export type UpdateMeRequest = z.infer<typeof updateMeRequestSchema>
export const userInfoSchema = z.object({
id: z.string(),
name: z.string(),
role: z.enum(['owner', 'editor', 'reviewer', 'bot', 'unknown']),
email: z.string().optional(),
type: z.nativeEnum(UserType).optional(),
image: z.string().optional(),
scope: z.nativeEnum(TeamMemberScope).optional(),
})
export type UserInfo = z.infer<typeof userInfoSchema>
export const listMembersQuerySchema = z.object({
includeAgents: z
.string()
.optional()
.transform((v) => v === 'true'),
})
export const VideoTranscodeStrategy = {
// eslint-disable-next-line @typescript-eslint/naming-convention
best_match: 'best_match',
multi: 'multi',
all: 'all',
} as const
export type VideoTranscodeStrategy =
(typeof VideoTranscodeStrategy)[keyof typeof VideoTranscodeStrategy]
export const VideoResolutionLadder = {
r480p: '480p',
r720p: '720p',
r1080p: '1080p',
r1440p: '1440p',
r2160p: '2160p',
} as const
export type VideoResolutionLadder =
(typeof VideoResolutionLadder)[keyof typeof VideoResolutionLadder]
export const DEFAULT_VIDEO_RESOLUTIONS: VideoResolutionLadder[] = [
'480p',
'720p',
'1080p',
'1440p',
'2160p',
]
export const HardwareAcceleration = {
off: 'off',
auto: 'auto',
} as const
export type HardwareAcceleration = (typeof HardwareAcceleration)[keyof typeof HardwareAcceleration]
export const HlsResolutionLadder = {
r480p: '480p',
r720p: '720p',
r1080p: '1080p',
r1440p: '1440p',
r2160p: '2160p',
} as const
export type HlsResolutionLadder = (typeof HlsResolutionLadder)[keyof typeof HlsResolutionLadder]
export const DEFAULT_HLS_RESOLUTIONS: HlsResolutionLadder[] = ['480p', '720p', '1080p']
export const autoArchiveMethodSchema = z.enum(['not_updated', 'after_created'])
export type AutoArchiveMethod = z.infer<typeof autoArchiveMethodSchema>
export const autoArchiveSettingsSchema = z.object({
enabled: z.boolean(),
method: autoArchiveMethodSchema,
days: z.number().int().min(1).max(3650),
postRestoreGraceDays: z.number().int().min(1).max(3650).default(30),
})
export type AutoArchiveSettings = z.infer<typeof autoArchiveSettingsSchema>
export const DEFAULT_AUTO_ARCHIVE_SETTINGS: AutoArchiveSettings = {
enabled: false,
method: 'not_updated',
days: 30,
postRestoreGraceDays: 30,
}
export interface ArchiveStorageInfo {
enabled: boolean
backend?: 'local' | 's3'
endpoint?: string
bucket?: string
localRoot?: string
}
export const updateTeamSettingsRequestSchema = z.union([
z.object({
key: z.literal('transcode.videoStrategy'),
value: z.nativeEnum(VideoTranscodeStrategy),
}),
z.object({
key: z.literal('transcode.videoResolutions'),
value: z.array(z.nativeEnum(VideoResolutionLadder)),
}),
z.object({
key: z.literal('transcode.hardwareAcceleration'),
value: z.nativeEnum(HardwareAcceleration),
}),
z.object({
key: z.literal('transcode.threads'),
value: z.number().int().min(0).max(32),
}),
z.object({
key: z.literal('transcode.hlsEnabled'),
value: z.boolean(),
}),
z.object({
key: z.literal('transcode.hlsResolutions'),
value: z.array(z.nativeEnum(HlsResolutionLadder)),
}),
z.object({
key: z.literal('appearance.hideAgent'),
value: z.boolean(),
}),
z.object({
key: z.literal('autoArchive'),
value: autoArchiveSettingsSchema,
}),
z.object({
key: z.literal('autoArchive.enabled'),
value: z.boolean(),
}),
z.object({
key: z.literal('autoArchive.method'),
value: autoArchiveMethodSchema,
}),
z.object({
key: z.literal('autoArchive.days'),
value: z.number().int().min(1).max(3650),
}),
z.object({
key: z.literal('autoArchive.postRestoreGraceDays'),
value: z.number().int().min(1).max(3650),
}),
])
export type UpdateTeamSettingsRequest = z.infer<typeof updateTeamSettingsRequestSchema>
export const turntableSettingsResponseSchema = z.object({
url: z.string().optional(),
username: z.string().optional(),
hasPassword: z.boolean(),
isEnvConfigured: z.boolean(),
})
export type TurntableSettingsResponse = z.infer<typeof turntableSettingsResponseSchema>
export const updateTurntableSettingsRequestSchema = z.object({
url: z.string().optional(),
username: z.string().optional(),
password: z.string().optional(),
})
export type UpdateTurntableSettingsRequest = z.infer<typeof updateTurntableSettingsRequestSchema>
export const gotenbergSettingsResponseSchema = z.object({
url: z.string().optional(),
username: z.string().optional(),
hasPassword: z.boolean(),
isEnvConfigured: z.boolean(),
})
export type GotenbergSettingsResponse = z.infer<typeof gotenbergSettingsResponseSchema>
export const updateGotenbergSettingsRequestSchema = z.object({
url: z.string().optional(),
username: z.string().optional(),
password: z.string().optional(),
})
export type UpdateGotenbergSettingsRequest = z.infer<typeof updateGotenbergSettingsRequestSchema>
export interface TeamAppearanceSettings {
hideAgent?: boolean
}
export interface TeamSettingsResponse {
transcode?: {
videoStrategy?: VideoTranscodeStrategy
videoResolutions?: VideoResolutionLadder[]
hardwareAcceleration?: HardwareAcceleration
threads?: number
hlsEnabled?: boolean
hlsResolutions?: HlsResolutionLadder[]
}
turntable?: TurntableSettingsResponse
gotenberg?: GotenbergSettingsResponse
appearance?: TeamAppearanceSettings
semanticSearchEnabled?: boolean
archiveStorage?: ArchiveStorageInfo
autoArchive?: AutoArchiveSettings
[key: string]: unknown
}
export const updateTeamMemberRoleRequestSchema = z.object({
role: z.enum(['editor', 'reviewer']),
})
export type UpdateTeamMemberRoleRequest = z.infer<typeof updateTeamMemberRoleRequestSchema>
// Service Layer Interfaces
export interface ServiceCreateTeamRequest {
name: string
}
export interface ServiceGetUserTeamsRequest {
userId: string
pagination: z.infer<typeof paginationParamsSchema>
}
export interface ServiceJoinTeamRequest {
teamId: string
userId: string
}
export interface ServiceGetMeRequest {
teamId: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
user: any
}
export interface ServiceGetTeamMembersRequest {
teamId: string
userId: string
includeAgents?: boolean
}
export interface ServiceUpdateTeamMemberRoleRequest {
teamId: string
userId: string
role: 'editor' | 'reviewer'
}