mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 14:22:07 +00:00
集成收尾:前端约定写入后端实际返回的形状(应用详情只对 manage 给草稿、补算计划与结果、按名字的钩子行、能力字段审阅),去掉多种字段名都认的兼容解析;钩子按(应用, 名字)、应用助手对话按(应用, 建立人)加唯一索引,迁移前去重,插入改在保存点里、撞上就改用已有的那一行;口径卡固定的版本也须已发布且未退役,记级别之前有正式运行凭据的老版本启动时补记为已发布;证据面板和应用视图按列名遮端点快照(同一个函数),不再整张表遮掉;待办计数带上最新一条的时间,新待办通知不再漏;非管理员的搭建者不出模型接入的改动按钮
This commit is contained in:
@@ -1155,7 +1155,7 @@ function watchApprovals(go: Go): () => void {
|
||||
|
||||
/**
|
||||
* 派给自己的新待办:规则同待审批——拿到过一次真列表才记底,之后新来的、标签页在后台时发系统通知。不每拍都取列表:
|
||||
* 心跳取的「派给我的」待办数(taskCounts.mine)变了才取一次派给我的待处理待办。搭建者以上已经按待审批发过通知的
|
||||
* 心跳取的「派给我的」待办数或最新一条的时间(taskCounts.mine / latest)变了才取一次派给我的待处理待办。搭建者以上已经按待审批发过通知的
|
||||
* (待办带着那条审批)不再发第二条;核实、等外部系统这类没有审批的待办只在这里通知
|
||||
*/
|
||||
function watchTasks(go: Go): () => void {
|
||||
@@ -1192,7 +1192,7 @@ function watchTasks(go: Go): () => void {
|
||||
}
|
||||
return useCatalog.subscribe((s, p) => {
|
||||
if (s.taskCounts === p.taskCounts || !s.taskCounts) return
|
||||
if (seen && s.taskCounts.mine === p.taskCounts?.mine) return
|
||||
if (seen && s.taskCounts.mine === p.taskCounts?.mine && s.taskCounts.latest === p.taskCounts?.latest) return
|
||||
if (needsLogin(useAuth.getState().me)) return
|
||||
void pull()
|
||||
})
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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,
|
||||
})),
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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 }) =>
|
||||
|
||||
@@ -107,6 +107,8 @@ function ProvidersTab() {
|
||||
const loaded = useCatalog((s) => s.loaded)
|
||||
const [catalog, setCatalog] = useState<any>(null)
|
||||
const [editing, setEditing] = useState<Provider | 'new' | null>(null)
|
||||
// 模型接入只有管理员能改(服务端 role_by_method(write=admin));开登录的搭建者只看,不出改动的按钮,免得点了才 403
|
||||
const canWrite = atLeast(usePrincipal(), 'admin')
|
||||
|
||||
const loadCatalog = () => api.providers.catalog().then(setCatalog, () => {})
|
||||
useEffect(() => { void loadCatalog() }, [])
|
||||
@@ -144,10 +146,13 @@ function ProvidersTab() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<SectionBar title="模型接入" hint="API Key 加密保存在本地,不会返回给浏览器。状态圆点表示上次连接测试的结果,与是否启用无关。">
|
||||
<button className="btn btn-primary btn-sm" onClick={() => setEditing('new')}>
|
||||
<Plus size={12} aria-hidden /> 添加接入
|
||||
</button>
|
||||
<SectionBar title="模型接入" hint={`API Key 加密保存在本地,不会返回给浏览器。状态圆点表示上次连接测试的结果,与是否启用无关。${
|
||||
canWrite ? '' : '只有管理员能添加、修改和测试模型接入。'}`}>
|
||||
{canWrite && (
|
||||
<button className="btn btn-primary btn-sm" onClick={() => setEditing('new')}>
|
||||
<Plus size={12} aria-hidden /> 添加接入
|
||||
</button>
|
||||
)}
|
||||
</SectionBar>
|
||||
|
||||
{!loaded ? (
|
||||
@@ -158,12 +163,14 @@ function ProvidersTab() {
|
||||
title="还没有配置模型"
|
||||
source="providers"
|
||||
body="接入 Anthropic、OpenAI 或任何 OpenAI 兼容的服务(DeepSeek、通义、本机 Ollama…)后,Agent 才能运行。"
|
||||
action={<button className="btn btn-primary btn-sm" onClick={() => setEditing('new')}><Plus size={12} aria-hidden /> 添加接入</button>}
|
||||
action={canWrite
|
||||
? <button className="btn btn-primary btn-sm" onClick={() => setEditing('new')}><Plus size={12} aria-hidden /> 添加接入</button>
|
||||
: undefined}
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-2.5">
|
||||
{providers.map((p) => (
|
||||
<ProviderCard key={p.id} provider={p} kindLabel={kindLabel(p.kind)}
|
||||
<ProviderCard key={p.id} provider={p} kindLabel={kindLabel(p.kind)} canWrite={canWrite}
|
||||
onEdit={() => setEditing(p)} onRemove={() => void remove(p)} />
|
||||
))}
|
||||
</div>
|
||||
@@ -189,8 +196,8 @@ function ProvidersTab() {
|
||||
)
|
||||
}
|
||||
|
||||
function ProviderCard({ provider: p, kindLabel, onEdit, onRemove }: {
|
||||
provider: Provider; kindLabel: string; onEdit: () => void; onRemove: () => void
|
||||
function ProviderCard({ provider: p, kindLabel, canWrite, onEdit, onRemove }: {
|
||||
provider: Provider; kindLabel: string; canWrite: boolean; onEdit: () => void; onRemove: () => void
|
||||
}) {
|
||||
const key = `provider:${p.id}`
|
||||
// 后端记着上次测的结果:换了浏览器、清了缓存也还在。本机刚测过的更新就用本机的
|
||||
@@ -213,14 +220,16 @@ function ProviderCard({ provider: p, kindLabel, onEdit, onRemove }: {
|
||||
{!p.enabled && <span className="chip" title={PROVIDER_REF_TEXT.disabledChip}>已停用</span>}
|
||||
<span className="flex-1" />
|
||||
<HealthPill record={record} checkingSince={checkingSince} />
|
||||
<div className="flex items-center gap-1">
|
||||
<button className="btn btn-sm" disabled={!!checkingSince} onClick={() => void test()}
|
||||
title={`向 ${p.default_model || '默认模型'} 发送一条测试消息`}>
|
||||
<Plug size={11} aria-hidden /> 测试连接
|
||||
</button>
|
||||
<button className="btn btn-sm btn-ghost" onClick={onEdit}>编辑</button>
|
||||
<DeleteButton label={`删除模型接入 ${p.name}`} onClick={onRemove} />
|
||||
</div>
|
||||
{canWrite && (
|
||||
<div className="flex items-center gap-1">
|
||||
<button className="btn btn-sm" disabled={!!checkingSince} onClick={() => void test()}
|
||||
title={`向 ${p.default_model || '默认模型'} 发送一条测试消息`}>
|
||||
<Plug size={11} aria-hidden /> 测试连接
|
||||
</button>
|
||||
<button className="btn btn-sm btn-ghost" onClick={onEdit}>编辑</button>
|
||||
<DeleteButton label={`删除模型接入 ${p.name}`} onClick={onRemove} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-1.5 flex flex-wrap gap-x-3 gap-y-1 text-2xs text-faint">
|
||||
{p.base_url && <span className="mono break-all">{p.base_url}</span>}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { History } from 'lucide-react'
|
||||
import { api } from '../../api/client'
|
||||
import type { BackfillPlan } from '../../api/apps'
|
||||
import type { BackfillPlan } from '../../typesApp'
|
||||
import { Spinner, confirmDialog, toast } from '../../components/ui'
|
||||
import { APP_EDITOR_TEXT as T } from '../../lib/terms'
|
||||
import { useAtLeast } from '../../store/auth'
|
||||
@@ -121,7 +121,7 @@ export function BackfillButton({ appId, target, onDone }: { appId: string; targe
|
||||
setBusy(true)
|
||||
try {
|
||||
const res = await api.apps.backfill(appId, target.view)
|
||||
toast.ok(T.backfillDone(res.started, res.skipped))
|
||||
toast.ok(T.backfillDone(res.launched, res.skipped))
|
||||
if (res.refused) toast.warn(res.refused)
|
||||
onDone?.()
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { KeyRound, Plus } from 'lucide-react'
|
||||
import { api } from '../../../api/client'
|
||||
import type { AppHookState } from '../../../api/apps'
|
||||
import type { AppHookRow } from '../../../typesApp'
|
||||
import {
|
||||
CopyButton, DeleteButton, EmptyState, ErrorState, Field, SectionBar, Skeleton, Spinner, confirmDialog, toast,
|
||||
} from '../../../components/ui'
|
||||
@@ -133,7 +133,7 @@ function Grants() {
|
||||
*/
|
||||
export function HooksSection() {
|
||||
const { appId, draft, setDraft, dirty, save } = useEditor()
|
||||
const [rows, setRows] = useState<AppHookState[] | null>(null)
|
||||
const [rows, setRows] = useState<AppHookRow[] | null>(null)
|
||||
const [loadError, setLoadError] = useState<unknown>(null)
|
||||
const [busy, setBusy] = useState<string | null>(null)
|
||||
const [shown, setShown] = useState<{ name: string; secret: string; path: string | null } | null>(null)
|
||||
@@ -261,7 +261,7 @@ export function HooksSection() {
|
||||
/** 一行钩子的服务端状态:发布版里有没有、生成过密钥没有、启用;生成 / 轮换、删除密钥 */
|
||||
function HookStatus({ name, state, declared, busy, loaded, onRotate, onToggle, onRemove }: {
|
||||
name: string
|
||||
state: AppHookState | undefined
|
||||
state: AppHookRow | undefined
|
||||
declared: boolean
|
||||
busy: boolean
|
||||
loaded: boolean
|
||||
@@ -273,13 +273,13 @@ function HookStatus({ name, state, declared, busy, loaded, onRotate, onToggle, o
|
||||
const has = !!state?.has_secret
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs" data-app-hook-state={has ? 'secret' : 'none'}
|
||||
data-app-hook-published={state?.published ? '1' : '0'}>
|
||||
data-app-hook-published={state?.in_published ? '1' : '0'}>
|
||||
<span className="chip" style={has ? { color: 'var(--ok)', borderColor: 'var(--ok)' } : undefined}>
|
||||
{has ? T.hookSecretSet : T.hookSecretNone}
|
||||
</span>
|
||||
{!declared
|
||||
? <span style={{ color: 'var(--st-waiting)' }}>{T.hookNotDeclared}</span>
|
||||
: state?.published ? <span className="text-faint">{T.hookPublished}</span>
|
||||
: state?.in_published ? <span className="text-faint">{T.hookPublished}</span>
|
||||
: <span style={{ color: 'var(--st-waiting)' }}>{T.hookNotPublished}</span>}
|
||||
<span className="flex-1" />
|
||||
{has && (
|
||||
|
||||
@@ -20,8 +20,7 @@ import { matchShortcut } from '../../../lib/keys'
|
||||
import { useLeaveGuard } from '../../../lib/leave'
|
||||
import { APP_EDITOR_TEXT as T } from '../../../lib/terms'
|
||||
import { useCatalog } from '../../../store/catalog'
|
||||
import type { AppDetailOut } from '../../../api/apps'
|
||||
import type { AppBindings, AppSpec, ComponentCatalog } from '../../../typesApp'
|
||||
import type { AppBindings, AppDetail, AppSpec, ComponentCatalog } from '../../../typesApp'
|
||||
import { EditorContext, type EditorState } from './context'
|
||||
import { PinsSection, PublishedVersionPicker } from './PinsSection'
|
||||
import { PagesSection } from './PagesSection'
|
||||
@@ -117,7 +116,7 @@ function EditApp({ appId }: { appId: string }) {
|
||||
const { section: raw } = useParams()
|
||||
const navigate = useNavigate()
|
||||
const section: Section = (SECTIONS as readonly string[]).includes(raw ?? '') ? raw as Section : 'pages'
|
||||
const [detail, setDetail] = useState<AppDetailOut | null>(null)
|
||||
const [detail, setDetail] = useState<AppDetail | null>(null)
|
||||
const [error, setError] = useState<unknown>(null)
|
||||
const [draft, setDraftState] = useState<AppSpec | null>(null)
|
||||
const [bindings, setBindingsState] = useState<AppBindings>({ slots: {} })
|
||||
@@ -136,7 +135,7 @@ function EditApp({ appId }: { appId: string }) {
|
||||
try {
|
||||
const d = await api.apps.get(appId)
|
||||
setDetail(d)
|
||||
setDraftState(d.draft)
|
||||
setDraftState(d.draft ?? null)
|
||||
setBindingsState(d.draft_bindings ?? { slots: {} })
|
||||
setDirty(false)
|
||||
setError(null)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
import type { AppDetailOut } from '../../../api/apps'
|
||||
import type { AppDetail } from '../../../typesApp'
|
||||
import type { AppBindings, AppSpec, ComponentCatalog } from '../../../typesApp'
|
||||
|
||||
/** 应用编辑器各节共用的状态:草稿、岗位绑定、组件目录、保存、选中的组件、切到哪一节 */
|
||||
export interface EditorState {
|
||||
appId: string
|
||||
/** 应用详情(manage):带着草稿、岗位绑定和能按新口径补算的视图 */
|
||||
detail: AppDetailOut
|
||||
detail: AppDetail
|
||||
draft: AppSpec
|
||||
/** 改草稿:传函数拿到最新的那一份(助手的操作和人的编辑可能挨着到) */
|
||||
setDraft: (fn: (spec: AppSpec) => AppSpec) => void
|
||||
|
||||
@@ -45,6 +45,8 @@ export interface TaskCounts {
|
||||
mine: number
|
||||
apps: number
|
||||
other: number
|
||||
/** 其中最新一条的开出时间:数不变、却换了一条(一条处理掉、一条新来)时,新待办通知看它 */
|
||||
latest?: string | null
|
||||
}
|
||||
|
||||
/** 心跳间隔:连着时复用 4 秒一次的待审批轮询,不另起请求 */
|
||||
|
||||
@@ -213,9 +213,36 @@ export interface AppSummary {
|
||||
}
|
||||
|
||||
export interface AppDetail extends AppSummary {
|
||||
draft: AppSpec
|
||||
draft_bindings: AppBindings
|
||||
created_by: string | null
|
||||
/** 草稿和岗位绑定只给 manage(D-m);use / observe 拿到的详情里没有 */
|
||||
draft?: AppSpec
|
||||
draft_bindings?: AppBindings
|
||||
created_by?: string | null
|
||||
/** 当前发布版的页面和入口目录:没有 manage 的人靠它找首页、入口名 */
|
||||
published?: { version: number; pages: { id: string; title: string }[]; entries: { id: string; label: string }[] } | null
|
||||
/** 能按新口径补算的视图(只在 manage 取详情时算,D-f) */
|
||||
backfill?: BackfillPlan[]
|
||||
}
|
||||
|
||||
/** 按新口径补算会发起几次(GET /api/apps/{id}/views/{view}/backfill,不发起运行) */
|
||||
export interface BackfillPlan {
|
||||
view: string
|
||||
alias: string
|
||||
/** schedule:<id> 或 formal */
|
||||
source: string
|
||||
from_version: number
|
||||
to_version: number
|
||||
/** 趋势画几期 */
|
||||
periods: number
|
||||
will_launch: number
|
||||
will_skip: number
|
||||
}
|
||||
|
||||
/** POST 同一路径的结果:发起了几次、跳过了几次(同一输入已经补算过);发起到一半被拒的原因照实交回 */
|
||||
export interface BackfillResult extends BackfillPlan {
|
||||
launched: number
|
||||
skipped: number
|
||||
run_ids: string[]
|
||||
refused?: string | null
|
||||
}
|
||||
|
||||
export interface AppVersionRow {
|
||||
@@ -534,14 +561,23 @@ export interface LookEvent {
|
||||
// 入站钩子(§2.4)与助手流(§2.9 L1、§3.11)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** 钩子管理里的一行(D-g):草稿或发布版里声明的 ∪ 已经生成过密钥的,按名字一行 */
|
||||
export interface AppHookRow {
|
||||
id: string
|
||||
/** app_hooks 那一行的 id;还没生成密钥时为 null */
|
||||
id: string | null
|
||||
name: string
|
||||
kind: 'start' | 'signal'
|
||||
kind: 'start' | 'signal' | null
|
||||
entry_id: string | null
|
||||
enabled: boolean
|
||||
created_at: string
|
||||
/** 只在新建和轮换时出现一次 */
|
||||
has_secret: boolean
|
||||
/** 草稿的 spec.hooks 里有这个名字 */
|
||||
in_draft: boolean
|
||||
/** 当前发布版里有(入站请求按发布版认种类和入口,没有就拒收) */
|
||||
in_published: boolean
|
||||
/** 收请求的地址 /api/hooks/{id};还没生成密钥时为 null */
|
||||
url_path: string | null
|
||||
created_at: string | null
|
||||
/** 只在生成、轮换的回包里出现一次 */
|
||||
secret?: string
|
||||
}
|
||||
|
||||
@@ -568,3 +604,42 @@ export interface AppStreamFinal {
|
||||
issues: LintIssue[]
|
||||
explanation: string
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 能力字段语义的审阅(D-i,GET /api/capabilities/review-queue、POST /api/capabilities/review/batch)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export interface CapabilityReviewRow {
|
||||
capability: string
|
||||
system: string
|
||||
title: string
|
||||
effect: CapabilityEffect
|
||||
/** 返回里的位置(JSON 指针) */
|
||||
pointer: string
|
||||
/** label / meaning / unit / measure / codes */
|
||||
field: string
|
||||
field_text: string
|
||||
/** 服务端写好的位置说法(「返回字段 /amount 的单位」) */
|
||||
field_label: string
|
||||
value: unknown
|
||||
display: string
|
||||
source: string
|
||||
status: string
|
||||
note: string | null
|
||||
priority: number
|
||||
reasons: string[]
|
||||
/** 用到这个能力的运行次数 */
|
||||
runs: number
|
||||
/** 能力的治理版本:成批审阅时带上(乐观锁) */
|
||||
version: number
|
||||
}
|
||||
|
||||
export interface CapabilityReviewOutcome {
|
||||
capability: string
|
||||
pointer: string
|
||||
field: string
|
||||
ok: boolean
|
||||
version: number | null
|
||||
error: string | null
|
||||
code: string | null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user