- CapabilityRegistry: descriptor(id/version/schema/scope/risk/idempotent/preview/replay), invoke = scope limit -> input schema -> server-side authorize -> idempotency key -> handler -> output schema -> audit; capability id <-> tool name mapping (download.submit <-> download__submit) - PiAgentRuntime (pi-agent-core AgentHarness 0.87.1): whitelist tools + before_tool re-check, redacted event stream, JSONL session at sessionDir/<runId>.jsonl, resume/abort/compact, tool-call/duration/token/cost budgets -> abort + run_failed(budget) - AgentSettings -> pi-ai createProvider (anthropic / openai-compatible), compaction mapping - FakeModelProvider + createFakeRuntime (scripted, transcript-derived, survives crash/resume) - buildSystemPrompt, redactForModel; 27 tests incl. SIGKILL + resume Co-Authored-By: Claude Fable 5.1 <[email protected]>
59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
import { z } from "zod";
|
|
|
|
export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
|
|
export type AgentThinkingLevel = (typeof THINKING_LEVELS)[number];
|
|
|
|
/**
|
|
* 设置页 → Agent 运行参数。apiKey 为调用方从 secret store 解密后的明文,
|
|
* 只在请求时经 provider auth.resolve 交给 SDK,不进入事件、日志、错误信息。
|
|
*/
|
|
export const AgentSettingsSchema = z.object({
|
|
provider: z.enum(["anthropic", "openai-compatible"]),
|
|
/** Anthropic 写不带 /v1 的根地址;OpenAI 兼容写带 /v1 的地址 */
|
|
baseUrl: z.string().url().optional(),
|
|
apiKey: z.string().min(1),
|
|
model: z.string().min(1),
|
|
thinkingLevel: z.enum(THINKING_LEVELS).default("off"),
|
|
/** 上下文预算 = 模型 contextWindow(可以比上游真实窗口小) */
|
|
contextBudgetTokens: z.number().int().min(1024).default(128_000),
|
|
/** 单次回复最大输出 token */
|
|
maxOutputTokens: z.number().int().min(256).default(8192),
|
|
compaction: z
|
|
.object({
|
|
mode: z.enum(["threshold", "manual"]),
|
|
/** 上下文占用达到预算的该比例时自动压缩(0.5~0.95) */
|
|
threshold: z.number().min(0.5).max(0.95).default(0.8),
|
|
})
|
|
.default({ mode: "threshold", threshold: 0.8 }),
|
|
/** v0.1 未实现子代理;false 时忽略,true 也只记录(由 agent.delegate 能力后续实现) */
|
|
subagentsEnabled: z.boolean().default(false),
|
|
maxToolCalls: z.number().int().min(1).default(40),
|
|
maxDurationMs: z
|
|
.number()
|
|
.int()
|
|
.min(1000)
|
|
.default(15 * 60_000),
|
|
costBudget: z
|
|
.object({
|
|
maxTotalTokens: z.number().int().positive().optional(),
|
|
maxCostUsd: z.number().positive().optional(),
|
|
})
|
|
.optional(),
|
|
/** 单次请求超时 */
|
|
requestTimeoutMs: z.number().int().positive().default(120_000),
|
|
maxRetries: z.number().int().min(0).max(10).default(2),
|
|
});
|
|
export type AgentSettings = z.input<typeof AgentSettingsSchema>;
|
|
export type ResolvedAgentSettings = z.output<typeof AgentSettingsSchema>;
|
|
|
|
export function resolveAgentSettings(settings: AgentSettings): ResolvedAgentSettings {
|
|
return AgentSettingsSchema.parse(settings);
|
|
}
|
|
|
|
/** 用于日志/展示:去掉 apiKey */
|
|
export function describeSettings(settings: ResolvedAgentSettings): Omit<ResolvedAgentSettings, "apiKey"> & {
|
|
apiKey: "[REDACTED]";
|
|
} {
|
|
return { ...settings, apiKey: "[REDACTED]" };
|
|
}
|