集成收尾:前端约定写入后端实际返回的形状(应用详情只对 manage 给草稿、补算计划与结果、按名字的钩子行、能力字段审阅),去掉多种字段名都认的兼容解析;钩子按(应用, 名字)、应用助手对话按(应用, 建立人)加唯一索引,迁移前去重,插入改在保存点里、撞上就改用已有的那一行;口径卡固定的版本也须已发布且未退役,记级别之前有正式运行凭据的老版本启动时补记为已发布;证据面板和应用视图按列名遮端点快照(同一个函数),不再整张表遮掉;待办计数带上最新一条的时间,新待办通知不再漏;非管理员的搭建者不出模型接入的改动按钮

This commit is contained in:
ThearchyHelios
2026-10-14 22:08:33 +08:00
parent 1dd4f93579
commit bff3062a97
32 changed files with 419 additions and 246 deletions
+8 -83
View File
@@ -5,8 +5,8 @@
* 入口提交校验失败回 422,ApiError 的 body 里带 {errors: FormError[]}。
*/
import type {
AppBindings, AppDetail, AppGrant, AppHookRow, AppSpec, AppSummary, AppVersionRow, ComponentCatalog, Disposition,
InstanceRow, LintIssue, PublishResult, ViewModel,
AppBindings, AppDetail, AppGrant, AppHookRow, AppSpec, AppSummary, AppVersionRow, BackfillPlan, BackfillResult,
ComponentCatalog, Disposition, InstanceRow, LintIssue, PublishResult, ViewModel,
} from '../typesApp'
import type { ConversationDetail, EvidenceSegmentDetail } from '../types'
import { del, get, patch, post, put, qs, type RequestOptions } from './http'
@@ -14,85 +14,17 @@ import { del, get, patch, post, put, qs, type RequestOptions } from './http'
const at = (id: string) => `/apps/${encodeURIComponent(id)}`
const hookAt = (id: string, name: string) => `${at(id)}/hooks/${encodeURIComponent(name)}`
/**
* 钩子管理里的一行(D-g):草稿里声明的 ∪ 已经生成过密钥的,按名字合成一行。
* - declared:草稿的 spec.hooks 里有这个名字;published:当前发布版里有(入站请求按发布版认种类和入口,没有就拒收);
* - has_secret:已经生成过密钥(app_hooks 里有这一行)。密钥本身只在生成、轮换时交回一次(AppHookRow.secret)。
* 服务端几种写法都认(hookStateOf),缺的项按「没有」算
*/
export interface AppHookState {
name: string
kind: 'start' | 'signal' | null
entry_id: string | null
declared: boolean
published: boolean
has_secret: boolean
enabled: boolean
/** app_hooks 那一行的 id:入站地址是 /api/hooks/{id}。还没生成密钥时为 null */
id: string | null
/** 收请求的地址(服务端给的路径);没给时按 id 拼 */
url_path: string | null
created_at: string | null
}
function hookStateOf(raw: Record<string, any>): AppHookState {
const id = typeof raw.id === 'string' && raw.id ? raw.id : null
const flag = (...keys: string[]) => keys.some((k) => raw[k] === true)
return {
name: String(raw.name ?? ''),
kind: raw.kind === 'start' || raw.kind === 'signal' ? raw.kind : null,
entry_id: raw.entry_id ?? raw.entry ?? null,
declared: flag('declared', 'in_draft'),
published: flag('published', 'in_published'),
has_secret: raw.has_secret != null || raw.secret_set != null ? flag('has_secret', 'secret_set') : !!id,
enabled: raw.enabled !== false,
id,
url_path: typeof raw.url_path === 'string' && raw.url_path ? raw.url_path : id ? `/api/hooks/${encodeURIComponent(id)}` : null,
created_at: raw.created_at ?? null,
}
}
/** 按新口径补算的结果(D-f):发起了几次、跳过了几次(同一输入已经补算过) */
export interface BackfillResult {
started: number
skipped: number
run_ids?: string[]
/** 发起到一半被拒(比如版本刚被退役):已经发起的照算,原因照实交回 */
refused?: string | null
}
/** 补算会发起几次(服务端 apps/backfill.Plan.out,不发起运行):这个视图、哪个固定版本从几升到几、趋势画几期 */
export interface BackfillPlan {
view: string
alias: string
source: string
from_version: number
to_version: number
periods: number
will_launch: number
will_skip: number
}
/**
* 应用详情。manage 才有草稿和岗位绑定(D-m);另带能按新口径补算的视图(backfill,只在取详情时算)。use / observe
* 只有概况和当前发布版的页面、入口目录(published)
*/
export type AppDetailOut = AppDetail & {
backfill?: BackfillPlan[]
published?: { version: number; pages: { id: string; title: string }[]; entries: { id: string; label: string }[] } | null
}
export const apps = {
catalog: (opts?: RequestOptions) => get<ComponentCatalog>('/apps/catalog', opts),
list: (opts?: RequestOptions) => get<{ items: AppSummary[] }>('/apps', opts),
get: (id: string, opts?: RequestOptions) => get<AppDetailOut>(at(id), opts),
get: (id: string, opts?: RequestOptions) => get<AppDetail>(at(id), opts),
create: (body: { name: string; description?: string; spec?: AppSpec }) => post<AppDetail>('/apps', body),
/** 从工作流版本确定性派生一份应用草稿(不落库),编辑器拿去预览 / 新建 */
derive: (body: { workflow_id: string; version: number; name?: string }) =>
post<{ spec: AppSpec }>('/apps/derive', body),
/** 改草稿:spec、岗位绑定、名称等,只带改了的字段 */
update: (id: string, body: { name?: string; description?: string; icon?: string; draft?: AppSpec;
draft_bindings?: AppBindings }) => patch<AppDetailOut>(at(id), body),
draft_bindings?: AppBindings }) => patch<AppDetail>(at(id), body),
archive: (id: string) => post<AppDetail>(`${at(id)}/archive`),
lint: (id: string) => post<{ issues: LintIssue[]; level: string | null }>(`${at(id)}/lint`),
publish: (id: string, body: { note?: string; dispositions?: Record<string, Disposition> }) =>
@@ -129,21 +61,14 @@ export const apps = {
* 按新口径补算(D-f,manage):这个视图的固定版本相对上一个应用版本升了版、处置为按新口径重算时,取旧版本在同一来源上
* 最近几次封存的正式运行的输入,用新版本逐个发起正式运行(来源记为按新口径补算),同一输入补算过的跳过
*/
backfill: async (id: string, view: string): Promise<BackfillResult> => {
const raw = await post<Record<string, any>>(`${at(id)}/views/${encodeURIComponent(view)}/backfill`)
const n = (...keys: string[]) => Number(keys.map((k) => raw?.[k]).find((v) => typeof v === 'number') ?? 0)
return { started: n('launched', 'started'), skipped: n('skipped'), run_ids: Array.isArray(raw?.run_ids) ? raw.run_ids : undefined,
refused: typeof raw?.refused === 'string' ? raw.refused : null }
},
backfill: (id: string, view: string) =>
post<BackfillResult>(`${at(id)}/views/${encodeURIComponent(view)}/backfill`),
/** 补算会发起几次、跳过几次(不发起运行):确认框按它写明次数 */
backfillPlan: (id: string, view: string) => get<BackfillPlan>(`${at(id)}/views/${encodeURIComponent(view)}/backfill`),
/** 钩子(D-g):草稿声明 ∪ 已有的行,按名字 */
hooks: async (id: string): Promise<AppHookState[]> => {
const raw = await get<{ items: Record<string, any>[] } | Record<string, any>[]>(`${at(id)}/hooks`)
return (Array.isArray(raw) ? raw : raw?.items ?? []).map(hookStateOf).filter((h) => h.name)
},
hooks: async (id: string): Promise<AppHookRow[]> => (await get<{ items: AppHookRow[] }>(`${at(id)}/hooks`)).items,
/** 生成或轮换签名密钥:secret 只在这一次交回;url_path 是收请求的地址 */
rotateHook: (id: string, name: string) => post<AppHookRow & { url_path?: string | null }>(`${hookAt(id, name)}/rotate`),
rotateHook: (id: string, name: string) => post<AppHookRow>(`${hookAt(id, name)}/rotate`),
setHookEnabled: (id: string, name: string, enabled: boolean) => patch<AppHookRow>(hookAt(id, name), { enabled }),
/** 删掉这个名字的密钥行:外部系统再用旧密钥签的请求一律拒收 */
deleteHook: (id: string, name: string) => del(hookAt(id, name)),
+24 -31
View File
@@ -3,7 +3,9 @@
* api.endpoints / api.notify 上。形状见 typesApp.ts。端点和渠道的密钥只回掩码;提交掩码值表示保持原值。
*/
import type { CatalogReviewAction, CatalogSource, CatalogStatus } from '../types'
import type { CapabilityEffect, CapabilityRow, EndpointRow, NotifyChannelRow } from '../typesApp'
import type {
CapabilityEffect, CapabilityReviewOutcome, CapabilityReviewRow, CapabilityRow, EndpointRow, NotifyChannelRow,
} from '../typesApp'
import { del, get, patch, post, put, qs, type RequestOptions } from './http'
/**
@@ -45,8 +47,6 @@ export interface CapabilityReviewResult {
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}`
@@ -55,28 +55,24 @@ export function splitReviewPath(path: string): { field: string; pointer: string
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 ?? '')
function reviewItemOf(raw: CapabilityReviewRow): CapabilityReviewItem {
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),
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: 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),
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,
}
}
@@ -91,25 +87,22 @@ export const capabilities = {
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({
const raw = await get<{ total: number; items: CapabilityReviewRow[] }>(`/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 }
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?: Record<string, any>[] }>('/capabilities/review/batch', {
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: 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),
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,
})),
}
},
+2 -1
View File
@@ -11,7 +11,8 @@ export const tasks = {
list: (params?: { assigned?: 'me' | 'all'; status?: string; app_id?: string; run_id?: string; limit?: number },
opts?: RequestOptions) => get<{ items: Task[] }>(`/tasks${qs(params)}`, opts),
/** 导航徽标:派给我的、待处理的待办数(按来源分:应用里的 / 不属于应用的) */
count: (opts?: RequestOptions) => get<{ mine: number; apps: number; other: number }>('/tasks/count?mine=1', opts),
count: (opts?: RequestOptions) =>
get<{ mine: number; apps: number; other: number; latest: string | null }>('/tasks/count?mine=1', opts),
get: (id: string, opts?: RequestOptions) => get<Task>(at(id), opts),
respond: (id: string, body: TaskRespond) => post<{ task: Task; resolved: boolean }>(`${at(id)}/respond`, body),
reassign: (id: string, body: { to: { kind: 'user' | 'group'; name: string }[]; note?: string }) =>