实现小游戏与小程序项目创建发布

This commit is contained in:
2026-08-09 13:31:06 +08:00
parent a6fe14a8d6
commit 493b31cff0
26 changed files with 1827 additions and 39 deletions

View File

@@ -48,7 +48,11 @@ import {
upsertProjectSessionMetadata,
type ProjectConversationState,
} from '../../../shared/project-conversations';
import type { ProjectConfig } from '../../../shared/project-config';
import {
isProjectType,
type ProjectConfig,
type ProjectType,
} from '../../../shared/project-config';
import { initializeProjectDirectory } from '../../opencode/project-directory-initialization';
const bundledCourseSkillIds = new Set<string>(BUNDLED_COURSE_SKILL_IDS);
@@ -82,6 +86,13 @@ const COMMAND_IMAGE_DATA_URL_PATTERN =
/^data:(image\/[A-Za-z0-9.+-]+);base64,([A-Za-z0-9+/]*={0,2})$/iu;
const STRICT_BASE64_PATTERN =
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;
function parseOptionalProjectType(value: unknown): ProjectType | undefined {
if (value === undefined) return undefined;
if (!isProjectType(value)) {
throw new Error('Invalid project type');
}
return value;
}
function asRecord(value: unknown): Record<string, unknown> | null {
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
@@ -956,8 +967,10 @@ export async function handleOpencodeRoutes(
projectPath?: string;
parentPath?: string;
projectName?: string;
projectType?: unknown;
defaultModel?: unknown;
}>(req);
const projectType = parseOptionalProjectType(body.projectType);
const defaultModel = body.defaultModel === undefined || body.defaultModel === null
? null
: typeof body.defaultModel === 'string' && body.defaultModel.trim()
@@ -972,6 +985,7 @@ export async function handleOpencodeRoutes(
: buildNewProjectPath(body.parentPath, body.projectName);
const { config } = await initializeProjectDirectory({
projectPath,
projectType,
defaultModel,
allowExistingDirectory: useSelectedDirectory,
});