应用平台契约骨架:新表(身份、能力与端点、应用、待办与生效记录、通知)与迁移(补列、多列索引),运行来源与新事件类型,「人」的唯一入口 api/deps.py(关登录时行为不变),应用描述与表单的形状、受信组件目录 v1,各包跨包函数的签名桩,新路由登记,发布门禁的扩展钩子 EXTRA_LINTS;前端接口约定 typesApp.ts、各接口文件、SchemaForm / TaskCard 的 props 与最简实现、应用相关路由与占位页

This commit is contained in:
ThearchyHelios
2026-10-14 17:53:40 +08:00
parent fc002bd3b3
commit 220fd0e365
59 changed files with 2364 additions and 16 deletions
+55
View File
@@ -0,0 +1,55 @@
/**
* 应用的接口(/api/apps、/api/ledger),挂在 api.apps 上。形状见 typesApp.ts(应用平台的接口约定)。
*
* 请求函数从 ./http 导入,不要从 ./client 导入(循环导入,见 http.ts 开头)。
* 入口提交校验失败回 422,ApiError 的 body 里带 {errors: FormError[]}。
*/
import type {
AppBindings, AppDetail, AppGrant, AppSpec, AppSummary, AppVersionRow, ComponentCatalog, Disposition, InstanceRow,
LintIssue, PublishResult, ViewModel,
} from '../typesApp'
import { get, patch, post, put, qs, type RequestOptions } from './http'
const at = (id: string) => `/apps/${encodeURIComponent(id)}`
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<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<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> }) =>
post<PublishResult>(`${at(id)}/publish`, body),
versions: (id: string) => get<{ items: AppVersionRow[] }>(`${at(id)}/versions`),
version: (id: string, v: number) => get<AppVersionRow & { spec: AppSpec; bindings: AppBindings }>(`${at(id)}/versions/${v}`),
grants: (id: string) => get<{ items: AppGrant[] }>(`${at(id)}/grants`),
setGrants: (id: string, items: AppGrant[]) => put<{ items: AppGrant[] }>(`${at(id)}/grants`, { items }),
/** 页面解析:服务端解析好的视图模型(不可见的组件不下发,遮罩值不出服务端) */
page: (id: string, page: string, params?: { instance?: string; params?: Record<string, unknown> }, opts?: RequestOptions) =>
get<ViewModel>(`${at(id)}/pages/${encodeURIComponent(page)}${qs({
instance: params?.instance, params: params?.params ? JSON.stringify(params.params) : undefined,
})}`, opts),
/** 发起一个实例 */
start: (id: string, entry: string, values: Record<string, unknown>) =>
post<{ run_id: string; title: string }>(`${at(id)}/entries/${encodeURIComponent(entry)}`, { values }),
instances: (id: string, params?: { who?: 'mine' | 'all'; entry?: string; status?: string; limit?: number }) =>
get<{ items: InstanceRow[] }>(`${at(id)}/instances${qs(params)}`),
instance: (id: string, runId: string) => get<InstanceRow & { view: ViewModel }>(`${at(id)}/instances/${encodeURIComponent(runId)}`),
/** 按需视图:发起一次运行(或命中缓存) */
refreshView: (id: string, view: string, params?: Record<string, unknown>) =>
post<{ run_id: string; cached: boolean }>(`${at(id)}/views/${encodeURIComponent(view)}/refresh`, { params: params ?? {} }),
}
export const ledger = {
/** 一个工作流版本被哪些应用钉住、生效记录数、正式运行数 */
version: (workflowId: string, version: number) =>
get<{ apps: { app_id: string; name: string; app_version: number }[]; effects: number; formal_runs: number }>(
`/ledger/workflow-versions/${encodeURIComponent(workflowId)}/${version}`),
}
+32
View File
@@ -0,0 +1,32 @@
/**
* 身份的接口(/api/auth、/api/users、/api/groups、/api/audit),挂在 api.auth / api.identity 上。形状见 typesApp.ts。
* 开登录时:没登录的请求回 401(前端跳 /login),角色不够回 403。关登录时 /me 恒为 mode='off'。
*/
import type { AuditRow, AuthMode, GroupRow, Principal, Role, UserRow } from '../typesApp'
import { del, get, patch, post, put, qs, type RequestOptions } from './http'
export const auth = {
me: (opts?: RequestOptions) => get<Principal>('/auth/me', opts),
login: (body: { username: string; password: string }) => post<Principal>('/auth/login', body),
logout: () => post<void>('/auth/logout'),
/** OIDC:浏览器整页跳转到这里 */
oidcStartUrl: (next?: string) => `/api/auth/oidc/start${qs({ next })}`,
settings: () => get<{ mode: AuthMode; env_locked: boolean; oidc: Record<string, any>; user_can_chat: boolean }>(
'/auth/settings'),
saveSettings: (body: { mode?: AuthMode; oidc?: Record<string, any>; user_can_chat?: boolean;
bootstrap?: { username: string; password: string; display_name?: string } }) => put<any>('/auth/settings', body),
}
export const identity = {
users: () => get<{ items: UserRow[] }>('/users'),
createUser: (body: { username: string; display_name?: string; email?: string; role: Role; password?: string }) =>
post<UserRow>('/users', body),
updateUser: (id: string, body: { display_name?: string; email?: string; role?: Role; disabled?: boolean;
password?: string }) => patch<UserRow>(`/users/${encodeURIComponent(id)}`, body),
groups: () => get<{ items: GroupRow[] }>('/groups'),
createGroup: (body: { name: string; label?: string }) => post<GroupRow>('/groups', body),
setMembers: (id: string, members: string[]) => put<GroupRow>(`/groups/${encodeURIComponent(id)}/members`, { members }),
deleteGroup: (id: string) => del(`/groups/${encodeURIComponent(id)}`),
audit: (params?: { subject_kind?: string; subject_id?: string; limit?: number }) =>
get<{ items: AuditRow[] }>(`/audit${qs(params)}`),
}
+37
View File
@@ -0,0 +1,37 @@
/**
* 能力登记、端点、通知渠道的接口(/api/capabilities、/api/endpoints、/api/notify),挂在 api.capabilities /
* api.endpoints / api.notify 上。形状见 typesApp.ts。端点和渠道的密钥只回掩码;提交掩码值表示保持原值。
*/
import type { CapabilityRow, EndpointRow, NotifyChannelRow } from '../typesApp'
import { del, get, patch, post, put, qs, type RequestOptions } from './http'
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'),
}
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)}`),
test: (id: string, env: 'test' | 'prod') =>
post<{ ok: 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)}`),
}
+16
View File
@@ -23,6 +23,11 @@ import { inquiry } from './inquiry'
import { schedules } from './schedules'
import { whatif } from './whatif'
import { reportExport } from './reportExport'
// 应用平台:各自的接口文件,这里只挂上去
import { apps, ledger } from './apps'
import { actions, tasks } from './tasks'
import { auth, identity } from './auth'
import { capabilities, endpoints, notify } from './capabilities'
// 请求层搬到了 http.ts(见那边的说明)。原先从这里导出的照旧从这里导出,调用方不用改;
// 请求函数也一并转出,给不在 api/ 下、又想直接发请求的地方用。api/ 下的命名空间文件请直接从 http.ts 导入
@@ -832,6 +837,17 @@ export const api = {
inquiry,
whatif,
reportExport,
// ---- 应用平台(typesApp.ts 是接口约定) ----
apps,
ledger,
tasks,
actions,
auth,
identity,
capabilities,
endpoints,
notify,
}
/**
+26
View File
@@ -0,0 +1,26 @@
/**
* 待办与生效记录的接口(/api/tasks、/api/actions),挂在 api.tasks / api.actions 上。形状见 typesApp.ts。
* 回复被拒(不是派给你的、已处理过、哈希对不上)回 403 / 409 / 422,ApiError.message 是服务端的中文说明。
*/
import type { ActionRecordRow, Task, TaskRespond } from '../typesApp'
import { get, post, qs, type RequestOptions } from './http'
const at = (id: string) => `/tasks/${encodeURIComponent(id)}`
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),
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 }) =>
post<Task>(`${at(id)}/reassign`, body),
remind: (id: string) => post<{ sent: number }>(`${at(id)}/remind`),
}
export const actions = {
list: (params?: { run_id?: string; app_id?: string; state?: string; limit?: number }) =>
get<{ items: ActionRecordRow[] }>(`/actions${qs(params)}`),
get: (id: string) => get<ActionRecordRow>(`/actions/${encodeURIComponent(id)}`),
}