Files
AgentLab/frontend/src/api/capabilities.ts
T
ThearchyHelios 941723b17c 端到端验收修复与指标出具:
- 身份与工具:登录页建第一个管理员(认人接口的 401 说明能不能建);搭建者有只读的人和组名录,选人给候选并核对名字;授权三行带标题;端点请求头名校验(空名、非法名存不进、发不出时说清原因);写入能力在工具页试运行一律演练、不发送,HTTP 状态照实说成败;写记忆不算只读、查询能力只能选同一端点上的只读能力;审批与遮罩的说法和实际规则一致;开登录时不要署名、导入和发布记登录的人;使用者不显示推演等只给搭建者的操作,403 按是否开登录说话;登录页只认一次人
- 流程与实例:图里用到的岗位(派给谁、超时升级给谁、发送确认派给谁)全部派生、没绑人的发布时报错;写外部系统的参数按能力声明的类型收拢后再算哈希和发送,收不成就不发;发起人的实例页只看这一步的状态,处理人才给待办卡;会签进度带登录核实和时间,升级后照实写规则;实例状态写流程的结论(已退回、未确认、等待核实写入结果),核实生效后不再挂失败原因;流程应用首页不派生最近封存运行的结果块,看板没数据时是安静的空态;样例⑩的金额带类型和下限、待办标题带金额,表单上下限前后端一起生效
- 看板与证据:定时任务模板加 ISO 周、上一 ISO 周、本月、上月;出处链穿过原样解析查询结果的整形节点,追不到原始数据的照实说停在哪里,样例⑨改用 cell();应用首页和版本历史都能做成应用;指标块单位不重复;版本列表带退役说明;定时任务页头跟着刷新;删视图要确认、新视图能起名;编辑器属性用中文名、术语带解释
- 指标出具(用户 2026-10-15 拍板):契约只写「指标来自」、上游没有报告撰写节点、成果里没有模型写的话时按指标出具——必需指标齐、指标输入追到原始数据、成果字段里的数回指得上才完整出具;受管级要求每个指标静态地追到原始数据(governed.metric_untraced);出具横幅和应用印章写明按指标
- 受管工作流降为已发布只给管理员(Q8 顺延,服务端同样拦);工作流接口带当前发布版的级别,画布上改过之后也认得出受管工作流
2026-10-15 07:15:37 +08:00

132 lines
6.4 KiB
TypeScript

/**
* 能力登记、端点、通知渠道的接口(/api/capabilities、/api/endpoints、/api/notify),挂在 api.capabilities /
* api.endpoints / api.notify 上。形状见 typesApp.ts。端点和渠道的密钥只回掩码;提交掩码值表示保持原值。
*/
import type { CatalogReviewAction, CatalogSource, CatalogStatus } from '../types'
import type {
CapabilityEffect, CapabilityReviewOutcome, CapabilityReviewRow, CapabilityRow, EndpointRow, NotifyChannelRow,
} from '../typesApp'
import { del, get, patch, post, put, qs, type RequestOptions } from './http'
/**
* 能力字段语义的审阅(D-i):沿用数据目录「项」的状态(推断 / 已核实 / 已确认 / 已驳回,带理由),按被多少运行用过、
* 是不是写入能力、来源排好序(服务端 data/capability_review.py,同 data/catalog_review.py 的思路)。一项是某个能力
* 返回里某个位置(JSON 指针)的某个字段(中文名、含义、单位、度量类型、码值)
*/
export interface CapabilityReviewItem {
/** 能力名(同图里工具的名字) */
name: string
title: string | null
/** 审阅队列里这一项的键:字段@位置(同一个能力里不重复)。成批审阅时拆回位置和字段 */
path: string
/** 返回里的位置(JSON 指针) */
pointer: string
field: string
/** 给人看的位置(服务端写好的「返回字段 /amount 的单位」) */
where: string
value: unknown
display: string
source: CatalogSource
status: CatalogStatus
note: string | null
priority: number
reasons: string[]
/** 用到这个能力的运行次数 */
usage: number
effect: CapabilityEffect | null
/** 能力的治理版本:成批审阅时逐项带上(乐观锁) */
version: number
}
export interface CapabilityReviewResult {
name: string
path: string
ok: boolean
version?: number | null
error: string | null
code?: string | null
}
/** 队列一项的键:字段@位置。字段只有几个固定的英文名,不含 @,拆的时候按第一个 @ 拆 */
export const reviewPathOf = (field: string, pointer: string) => `${field}@${pointer}`
export function splitReviewPath(path: string): { field: string; pointer: string } {
const at = path.indexOf('@')
return at < 0 ? { field: '', pointer: path } : { field: path.slice(0, at), pointer: path.slice(at + 1) }
}
function reviewItemOf(raw: CapabilityReviewRow): CapabilityReviewItem {
return {
name: raw.capability,
title: raw.title,
path: reviewPathOf(raw.field, raw.pointer),
pointer: raw.pointer,
field: raw.field,
where: raw.field_label,
value: raw.value,
display: raw.display,
source: raw.source as CatalogSource,
status: raw.status as CatalogStatus,
note: raw.note,
priority: raw.priority,
reasons: raw.reasons,
usage: raw.runs,
effect: raw.effect,
version: raw.version,
}
}
export const capabilities = {
list: (params?: { system?: string; effect?: string; q?: string }, opts?: RequestOptions) =>
get<{ items: CapabilityRow[] }>(`/capabilities${qs(params)}`, opts),
get: (name: string) => get<CapabilityRow>(`/capabilities/${encodeURIComponent(name)}`),
/** 改治理字段(effect / approval / unattended_write / returns_schema / tabular / fields / masked /
* credential_mode / endpoint_id / lookup),带上读到的 version 做乐观锁 */
govern: (name: string, body: Partial<CapabilityRow> & { version: number }) =>
put<CapabilityRow>(`/capabilities/${encodeURIComponent(name)}/governance`, body),
sync: () => post<{ changed: number }>('/capabilities/sync'),
/** 待审阅的能力字段(D-i):顺序服务端排好;capability 只看这一个能力 */
reviewQueue: async (params: { limit?: number; offset?: number; capability?: string | null }, opts?: RequestOptions) => {
const raw = await get<{ total: number; items: CapabilityReviewRow[] }>(`/capabilities/review-queue${qs({
limit: params.limit, offset: params.offset, capability: params.capability || undefined,
})}`, opts)
return { total: raw.total, items: raw.items.map(reviewItemOf) }
},
/**
* 成批审阅(只给管理员):逐个能力按治理版本做乐观锁,逐条交回结果(一个能力冲突只记在那几条上,code 为
* capability_conflict);写审计。path 是队列一项的键(字段@位置),这里拆回位置和字段
*/
reviewBatch: async (items: { name: string; path: string; action: CatalogReviewAction; if_version: number }[]) => {
const raw = await post<{ results: CapabilityReviewOutcome[] }>('/capabilities/review/batch', {
items: items.map((i) => ({ capability: i.name, ...splitReviewPath(i.path), action: i.action, if_version: i.if_version })),
})
return {
results: raw.results.map((r): CapabilityReviewResult => ({
name: r.capability, path: reviewPathOf(r.field, r.pointer), ok: r.ok, version: r.version, error: r.error, code: r.code,
})),
}
},
}
export const endpoints = {
list: () => get<{ items: EndpointRow[] }>('/endpoints'),
create: (body: Omit<EndpointRow, 'id' | 'version'>) => post<EndpointRow>('/endpoints', body),
update: (id: string, body: Partial<EndpointRow> & { version: number }) =>
patch<EndpointRow>(`/endpoints/${encodeURIComponent(id)}`, body),
remove: (id: string) => del(`/endpoints/${encodeURIComponent(id)}`),
/** ok:基础地址回了 2xx;reachable:连上了、拿到了响应(回 404、401 时连上了但不算成功)。message 是服务端照实写的那句 */
test: (id: string, env: 'test' | 'prod') =>
post<{ ok: boolean; reachable?: boolean; status: number | null; message: string }>(
`/endpoints/${encodeURIComponent(id)}/test${qs({ env })}`),
}
export const notify = {
channels: () => get<{ items: NotifyChannelRow[] }>('/notify/channels'),
createChannel: (body: { name: string; scope: string; owner_id?: string | null; format: string; url: string;
secret?: string | null; events: string[] }) => post<NotifyChannelRow>('/notify/channels', body),
updateChannel: (id: string, body: Record<string, any>) => patch<NotifyChannelRow>(`/notify/channels/${encodeURIComponent(id)}`, body),
removeChannel: (id: string) => del(`/notify/channels/${encodeURIComponent(id)}`),
testChannel: (id: string) => post<{ ok: boolean; message: string }>(`/notify/channels/${encodeURIComponent(id)}/test`),
deliveries: (params?: { channel_id?: string; limit?: number }) => get<{ items: any[] }>(`/notify/deliveries${qs(params)}`),
}