feat(background): add background registry and status tool with tests

This commit is contained in:
pi
2026-04-12 13:49:55 +01:00
parent afab606237
commit 21ae108bae
6 changed files with 306 additions and 0 deletions

35
src/background-schema.ts Normal file
View File

@@ -0,0 +1,35 @@
import { StringEnum } from "@mariozechner/pi-ai";
import { Type, type Static } from "@sinclair/typebox";
export function createBackgroundAgentSchema(availableModels: readonly string[]) {
return Type.Object(
{
preset: Type.String({ description: "Subagent preset name to use for this task" }),
task: Type.String({ description: "Task to delegate to the child agent" }),
model: Type.Optional(
StringEnum(availableModels, {
description: "Optional child model override. Must be one of the currently available models.",
}),
),
cwd: Type.Optional(Type.String({ description: "Optional working directory override" })),
},
{ description: "Parameters for launching a background_agent run" },
);
}
export const BackgroundAgentSchema = createBackgroundAgentSchema([]);
export function createBackgroundAgentStatusSchema() {
return Type.Object(
{
runId: Type.Optional(Type.String({ description: "Optional runId to query a single run" })),
includeCompleted: Type.Optional(Type.Boolean({ description: "Include completed/finished runs in listing" })),
},
{ description: "Parameters for background_agent_status tool" },
);
}
export const BackgroundAgentStatusSchema = createBackgroundAgentStatusSchema();
export type BackgroundAgentParams = Static<typeof BackgroundAgentSchema>;
export type BackgroundAgentStatusParams = Static<typeof BackgroundAgentStatusSchema>;