MCPcopy
hub / github.com/coder/mux / create

Method create

src/node/services/taskService.ts:3182–3719  ·  view source on GitHub ↗
(args: TaskCreateArgs)

Source from the content-addressed store, hash-verified

3180 }
3181
3182 async create(args: TaskCreateArgs): Promise<Result<TaskCreateResult, string>> {
3183 const parentWorkspaceId = coerceNonEmptyString(args.parentWorkspaceId);
3184 if (!parentWorkspaceId) {
3185 return Err("Task.create: parentWorkspaceId is required");
3186 }
3187 if (args.kind !== "agent") {
3188 return Err("Task.create: unsupported kind");
3189 }
3190
3191 const prompt = coerceNonEmptyString(args.prompt);
3192 if (!prompt) {
3193 return Err("Task.create: prompt is required");
3194 }
3195
3196 const normalizedAgentId = normalizeAgentId(args.agentId ?? args.agentType, "");
3197 if (!normalizedAgentId) {
3198 return Err("Task.create: agentId is required");
3199 }
3200
3201 const parsedAgentId = AgentIdSchema.safeParse(normalizedAgentId);
3202 if (!parsedAgentId.success) {
3203 return Err(`Task.create: invalid agentId (${normalizedAgentId})`);
3204 }
3205
3206 let normalizedBestOf: TaskCreateArgs["bestOf"];
3207 const bestOf = args.bestOf;
3208 if (bestOf) {
3209 const groupId = coerceNonEmptyString(bestOf.groupId);
3210 if (!groupId) {
3211 return Err("Task.create: bestOf.groupId is required when bestOf is provided");
3212 }
3213 if (!Number.isInteger(bestOf.index) || bestOf.index < 0) {
3214 return Err("Task.create: bestOf.index must be a non-negative integer");
3215 }
3216 if (!Number.isInteger(bestOf.total) || bestOf.total < 2) {
3217 return Err("Task.create: bestOf.total must be an integer >= 2");
3218 }
3219 if (bestOf.index >= bestOf.total) {
3220 return Err("Task.create: bestOf.index must be less than bestOf.total");
3221 }
3222
3223 const kind = normalizeTaskGroupKind(bestOf.kind);
3224 const label = normalizeTaskGroupLabel(bestOf.label);
3225 if (kind === TASK_GROUP_KIND.VARIANTS && !label) {
3226 return Err("Task.create: bestOf.label is required when bestOf.kind is variants");
3227 }
3228 if (kind !== TASK_GROUP_KIND.VARIANTS && label) {
3229 return Err("Task.create: bestOf.label is only allowed when bestOf.kind is variants");
3230 }
3231
3232 normalizedBestOf = {
3233 groupId,
3234 index: bestOf.index,
3235 total: bestOf.total,
3236 kind,
3237 ...(label ? { label } : {}),
3238 };
3239 }

Callers

nothing calls this directly

Calls 15

getTaskDepthMethod · 0.95
countActiveAgentTasksMethod · 0.95
resolveTaskAISettingsMethod · 0.95
emitWorkspaceMetadataMethod · 0.95
maybeStartQueuedTasksMethod · 0.95
startWorkspaceInitMethod · 0.95
coerceNonEmptyStringFunction · 0.90
ErrFunction · 0.90
normalizeAgentIdFunction · 0.90

Tested by

no test coverage detected