refactor(contracts,agent): single capability spec and agent run event definitions in contracts

B3: CapabilityDescriptor gains replay; CapabilitySpec + capabilitySpec(id) assemble
CAPABILITY_CATALOG + CAPABILITY_IO; drop CapabilityDefinition/CapabilityRisk. agent
registry registers contracts CapabilitySpec (kind/allowedKinds instead of its own
scope enum; approve also requires authorize). AgentRun port renamed AgentRunHandle.

B9: contracts AgentRunEvent/AgentRunEventBody/AgentRunEventRow/AgentUsageTotals with
row and SSE mapping helpers; agent onEvent receives AgentRunEvent, delivered serially
in seq order, firstSeq continues numbering across processes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-27 19:15:49 +08:00
1 parent 8f59bf3772
commit db5352eecd
18 files changed
+553 -293

No files matched your search

+6 -3
View File
@@ -1,9 +1,9 @@
import { mkdtemp } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { AgentRunEvent } from "@umt/contracts";
import { z } from "zod";
import {
type AgentEvent,
type AgentSettings,
type AuthorizationChecker,
type CapabilityAuditRecord,
@@ -40,6 +40,7 @@ export function makeFixture(opts: { slowMs?: number } = {}): Fixture {
description: "按标题查询本地媒体库是否已有该作品及已有版本。",
inputSchema: z.object({ title: z.string().min(1), year: z.number().int().optional() }),
outputSchema: z.object({ title: z.string(), inLibrary: z.boolean(), versions: z.array(z.string()) }),
kind: "read",
scope: "read",
riskLevel: "low",
idempotent: true,
@@ -56,7 +57,8 @@ export function makeFixture(opts: { slowMs?: number } = {}): Fixture {
description: "提交下载计划到下载器。只代表已提交,不代表已入库。",
inputSchema: z.object({ title: z.string(), quality: z.enum(["720p", "1080p", "2160p"]) }),
outputSchema: z.object({ accepted: z.boolean(), idempotencyKey: z.string(), status: z.literal("submitted") }),
scope: "execute",
kind: "execute",
scope: "organize.execute",
riskLevel: "medium",
idempotent: true,
supportsPreview: true,
@@ -82,6 +84,7 @@ export function makeFixture(opts: { slowMs?: number } = {}): Fixture {
description: "查看站点发布详情(返回原始字段,可能含私有链接)。",
inputSchema: z.object({ releaseId: z.string() }),
outputSchema: z.object({ releaseId: z.string(), torrentUrl: z.string(), cookie: z.string(), note: z.string() }),
kind: "read",
scope: "read",
riskLevel: "low",
idempotent: true,
@@ -127,6 +130,6 @@ export function settings(patch: Partial<AgentSettings> = {}): AgentSettings {
return { ...FAKE_AGENT_SETTINGS, ...patch };
}
export function types(events: AgentEvent[]): string[] {
export function types(events: AgentRunEvent[]): string[] {
return events.filter((e) => e.type !== "text_delta" && e.type !== "thinking_delta").map((e) => e.type);
}