85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
import { StringEnum } from "@mariozechner/pi-ai";
|
|
import { Type, type Static } from "@sinclair/typebox";
|
|
|
|
function createTaskModelSchema(availableModels: readonly string[]) {
|
|
return Type.Optional(
|
|
StringEnum(availableModels, {
|
|
description: "Optional child model override. Must be one of the currently available models.",
|
|
}),
|
|
);
|
|
}
|
|
|
|
export function createTaskItemSchema(availableModels: readonly string[]) {
|
|
return Type.Object({
|
|
agent: Type.String({ description: "Name of the agent to invoke" }),
|
|
task: Type.String({ description: "Task to delegate to the child agent" }),
|
|
model: createTaskModelSchema(availableModels),
|
|
cwd: Type.Optional(Type.String({ description: "Optional working directory override" })),
|
|
});
|
|
}
|
|
|
|
export function createChainItemSchema(availableModels: readonly string[]) {
|
|
return Type.Object({
|
|
agent: Type.String({ description: "Name of the agent to invoke" }),
|
|
task: Type.String({ description: "Task with optional {previous} placeholder" }),
|
|
model: createTaskModelSchema(availableModels),
|
|
cwd: Type.Optional(Type.String({ description: "Optional working directory override" })),
|
|
});
|
|
}
|
|
|
|
export const TaskItemSchema = createTaskItemSchema([]);
|
|
export const ChainItemSchema = createChainItemSchema([]);
|
|
|
|
export const AgentScopeSchema = StringEnum(["user", "project", "both"] as const, {
|
|
description: "Which markdown agent sources to use",
|
|
default: "user",
|
|
});
|
|
|
|
export function createSubagentParamsSchema(availableModels: readonly string[]) {
|
|
return Type.Object({
|
|
agent: Type.Optional(Type.String({ description: "Single-mode agent name" })),
|
|
task: Type.Optional(Type.String({ description: "Single-mode delegated task" })),
|
|
model: StringEnum(availableModels, {
|
|
description: "Required top-level child model. Must be one of the currently available models.",
|
|
}),
|
|
tasks: Type.Optional(Type.Array(createTaskItemSchema(availableModels), { description: "Parallel tasks" })),
|
|
chain: Type.Optional(Type.Array(createChainItemSchema(availableModels), { description: "Sequential tasks" })),
|
|
agentScope: Type.Optional(AgentScopeSchema),
|
|
confirmProjectAgents: Type.Optional(Type.Boolean({ default: true })),
|
|
cwd: Type.Optional(Type.String({ description: "Single-mode working directory override" })),
|
|
});
|
|
}
|
|
|
|
export const SubagentParamsSchema = createSubagentParamsSchema([]);
|
|
|
|
export type TaskItem = Static<typeof TaskItemSchema>;
|
|
export type ChainItem = Static<typeof ChainItemSchema>;
|
|
export type SubagentParams = Static<typeof SubagentParamsSchema>;
|
|
export type AgentScope = Static<typeof AgentScopeSchema>;
|
|
|
|
export interface SubagentRunResult {
|
|
runId: string;
|
|
agent: string;
|
|
agentSource: "builtin" | "user" | "project" | "unknown";
|
|
task: string;
|
|
requestedModel?: string;
|
|
resolvedModel?: string;
|
|
paneId?: string;
|
|
windowId?: string;
|
|
sessionPath?: string;
|
|
exitCode: number;
|
|
stopReason?: string;
|
|
finalText: string;
|
|
stdoutPath?: string;
|
|
stderrPath?: string;
|
|
resultPath?: string;
|
|
eventsPath?: string;
|
|
}
|
|
|
|
export interface SubagentToolDetails {
|
|
mode: "single" | "parallel" | "chain";
|
|
agentScope: AgentScope;
|
|
projectAgentsDir: string | null;
|
|
results: SubagentRunResult[];
|
|
}
|