fix: replace hardcoded backend profile validation with isBackendProfile()
The session creation route had a hardcoded check for only codex/deepseek/minimax-m3 profiles. Since ofcx-go was added to BackendProfile type and backend-profiles.ts spec list, the validation must use isBackendProfile() from the shared module so that adding new profiles only requires one data change, not scattered string checks. Refs pikasTech/HWLAB#1034
This commit is contained in:
+2
-1
@@ -5,6 +5,7 @@ import type { AgentRunStore, ListQueueTasksInput, ListSessionsInput, SessionEven
|
|||||||
import { openAgentRunStoreFromEnv } from "./store.js";
|
import { openAgentRunStoreFromEnv } from "./store.js";
|
||||||
import { AgentRunError, errorToJson } from "../common/errors.js";
|
import { AgentRunError, errorToJson } from "../common/errors.js";
|
||||||
import { asRecord, validateBackendProfile, validateCreateCommand, validateCreateQueueTask, validateCreateRun, validateQueueTaskState, validateSessionListState } from "../common/validation.js";
|
import { asRecord, validateBackendProfile, validateCreateCommand, validateCreateQueueTask, validateCreateRun, validateQueueTaskState, validateSessionListState } from "../common/validation.js";
|
||||||
|
import { isBackendProfile } from "../common/backend-profiles.js";
|
||||||
import type { ApiErrorBody, ApiOkBody, JsonRecord, JsonValue, RunEvent } from "../common/types.js";
|
import type { ApiErrorBody, ApiOkBody, JsonRecord, JsonValue, RunEvent } from "../common/types.js";
|
||||||
import { createKubernetesRunnerJob } from "./kubernetes-runner-job.js";
|
import { createKubernetesRunnerJob } from "./kubernetes-runner-job.js";
|
||||||
import { dispatchQueueTask, refreshQueueTaskFromCore } from "./queue-dispatch.js";
|
import { dispatchQueueTask, refreshQueueTaskFromCore } from "./queue-dispatch.js";
|
||||||
@@ -187,7 +188,7 @@ async function route({ method, url, body, store, sourceCommit, runnerJobDefaults
|
|||||||
const tenantId = stringField(record, "tenantId");
|
const tenantId = stringField(record, "tenantId");
|
||||||
const projectId = stringField(record, "projectId");
|
const projectId = stringField(record, "projectId");
|
||||||
const backendProfileRaw = typeof record.backendProfile === "string" ? record.backendProfile : "codex";
|
const backendProfileRaw = typeof record.backendProfile === "string" ? record.backendProfile : "codex";
|
||||||
if (backendProfileRaw !== "codex" && backendProfileRaw !== "deepseek" && backendProfileRaw !== "minimax-m3") throw new AgentRunError("schema-invalid", `backendProfile ${backendProfileRaw} is not supported`, { httpStatus: 400 });
|
if (!isBackendProfile(backendProfileRaw)) throw new AgentRunError("schema-invalid", `backendProfile ${backendProfileRaw} is not supported`, { httpStatus: 400 });
|
||||||
const conversationId = typeof record.conversationId === "string" ? record.conversationId : null;
|
const conversationId = typeof record.conversationId === "string" ? record.conversationId : null;
|
||||||
const codexRolloutSubdir = typeof record.codexRolloutSubdir === "string" && record.codexRolloutSubdir.length > 0 ? record.codexRolloutSubdir : "sessions";
|
const codexRolloutSubdir = typeof record.codexRolloutSubdir === "string" && record.codexRolloutSubdir.length > 0 ? record.codexRolloutSubdir : "sessions";
|
||||||
const expiresAt = typeof record.expiresAt === "string" ? record.expiresAt : new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString();
|
const expiresAt = typeof record.expiresAt === "string" ? record.expiresAt : new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString();
|
||||||
|
|||||||
Reference in New Issue
Block a user