应用平台集成(前端):钩子按名字管理并只显示一次密钥、按新口径补算、应用助手对话历史、设置页按角色收起与身份设置补管理员用户名、按需视图每日上限、界面偏好按角色只存本地、使用者问数据用数据源名单并在运行流连不上时改轮询、能力字段待审阅、记录页按来源筛选与待办 id、编辑器的入口 / 表单 / 待办外观 JSON 分区、画布 ?publish=1、工具页绑定端点与 MCP 认证头掩码编辑、派给自己的新待办系统通知、样例与检查脚本改走待办接口(含统一复核后的修复)

This commit is contained in:
ThearchyHelios
2026-10-14 21:55:51 +08:00
parent d67349562a
commit 1dd4f93579
48 changed files with 2651 additions and 308 deletions
+100 -1
View File
@@ -2,9 +2,84 @@
* 能力登记、端点、通知渠道的接口(/api/capabilities、/api/endpoints、/api/notify),挂在 api.capabilities /
* api.endpoints / api.notify 上。形状见 typesApp.ts。端点和渠道的密钥只回掩码;提交掩码值表示保持原值。
*/
import type { CapabilityRow, EndpointRow, NotifyChannelRow } from '../typesApp'
import type { CatalogReviewAction, CatalogSource, CatalogStatus } from '../types'
import type { CapabilityEffect, 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
}
const str = (v: unknown): string | null => (typeof v === 'string' && v ? v : null)
const num = (...vs: unknown[]): number => Number(vs.find((v) => typeof v === 'number') ?? 0)
/** 队列一项的键:字段@位置。字段只有几个固定的英文名,不含 @,拆的时候按第一个 @ 拆 */
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: Record<string, any>): CapabilityReviewItem {
const pointer = String(raw.pointer ?? '')
const field = String(raw.field ?? '')
const short = String(raw.field_text ?? raw.field ?? '')
return {
name: String(raw.capability ?? raw.name ?? ''),
title: str(raw.title),
path: reviewPathOf(field, pointer),
pointer,
field,
// 服务端写好的位置说法;老写法只给了字段名时自己拼
where: str(raw.field_label) ?? (pointer ? `${pointer} 的${short}` : short),
value: raw.value,
display: typeof raw.display === 'string' ? raw.display : raw.value == null ? '' : String(raw.value),
source: raw.source,
status: raw.status ?? 'proposed',
note: str(raw.note),
priority: num(raw.priority),
reasons: Array.isArray(raw.reasons) ? raw.reasons.map(String) : [],
usage: num(raw.runs, raw.usage, raw.run_count),
effect: raw.effect ?? null,
version: num(raw.version),
}
}
export const capabilities = {
list: (params?: { system?: string; effect?: string; q?: string }, opts?: RequestOptions) =>
get<{ items: CapabilityRow[] }>(`/capabilities${qs(params)}`, opts),
@@ -14,6 +89,30 @@ export const capabilities = {
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?: Record<string, any>[] }>(`/capabilities/review-queue${qs({
limit: params.limit, offset: params.offset, capability: params.capability || undefined,
})}`, opts)
const items = (raw?.items ?? []).map(reviewItemOf).filter((i) => i.name && i.field)
return { total: typeof raw?.total === 'number' ? raw.total : items.length, items }
},
/**
* 成批审阅(只给管理员):逐个能力按治理版本做乐观锁,逐条交回结果(一个能力冲突只记在那几条上,code 为
* capability_conflict);写审计。path 是队列一项的键(字段@位置),这里拆回位置和字段
*/
reviewBatch: async (items: { name: string; path: string; action: CatalogReviewAction; if_version: number }[]) => {
const raw = await post<{ results?: Record<string, any>[] }>('/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: String(r.capability ?? r.name ?? ''), path: reviewPathOf(String(r.field ?? ''), String(r.pointer ?? '')),
ok: r.ok === true, version: typeof r.version === 'number' ? r.version : null,
error: str(r.error) ?? str(r.message), code: str(r.code),
})),
}
},
}
export const endpoints = {