subagent-profile.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { z } from "zod";
  2. import { modelSelectionSchema, type ModelSelection } from "./model-selection.js";
  3. import type { AgentPermissionMode } from "./subagents-types.js";
  4. export type AgentProfileSource = "built-in" | "project" | "user";
  5. export type AgentMemoryScope = "user" | "project" | "local";
  6. export interface AgentProfile {
  7. background?: boolean;
  8. color?: "red" | "blue" | "green" | "yellow" | "purple" | "orange" | "pink" | "cyan";
  9. description: string;
  10. disallowedTools?: readonly string[];
  11. injectAgentsMd?: boolean;
  12. maxTurns?: number;
  13. mcpServers?: readonly string[];
  14. memory?: AgentMemoryScope;
  15. modelSelection?: ModelSelection;
  16. name: string;
  17. path?: string;
  18. permissionMode?: AgentPermissionMode;
  19. skills?: readonly string[];
  20. source: AgentProfileSource;
  21. systemPrompt: string;
  22. tools?: readonly string[];
  23. }
  24. export interface AgentProfileParseDiagnostic {
  25. code: string;
  26. message: string;
  27. path?: string;
  28. }
  29. export interface AgentProfileLoadResult {
  30. diagnostics: AgentProfileParseDiagnostic[];
  31. profiles: AgentProfile[];
  32. }
  33. /** 完整运行时 profile 的跨进程边界,不使用 Settings 摘要代替。 */
  34. export const agentProfileSchema = z
  35. .object({
  36. name: z.string().min(1),
  37. description: z.string(),
  38. source: z.enum(["built-in", "project", "user"]),
  39. systemPrompt: z.string(),
  40. path: z.string().optional(),
  41. modelSelection: modelSelectionSchema.optional(),
  42. background: z.boolean().optional(),
  43. injectAgentsMd: z.boolean().optional(),
  44. color: z
  45. .enum(["red", "blue", "green", "yellow", "purple", "orange", "pink", "cyan"])
  46. .optional(),
  47. permissionMode: z
  48. .enum(["acceptEdits", "auto", "bypassPermissions", "default", "dontAsk", "plan"])
  49. .optional(),
  50. memory: z.enum(["user", "project", "local"]).optional(),
  51. maxTurns: z.number().int().positive().optional(),
  52. tools: z.array(z.string()).readonly().optional(),
  53. disallowedTools: z.array(z.string()).readonly().optional(),
  54. skills: z.array(z.string()).readonly().optional(),
  55. mcpServers: z.array(z.string()).readonly().optional(),
  56. })
  57. .strict();