Archived
上一版是把字段倒在地上:整页宽的内联卡、输入框拉到 1100px、动作钮掉出屏幕。 照模型接入面的通行做法重排 —— 520px 右侧抽屉,头固定 / 身滚动 / 底动作栏常驻: ① **供应商**:一排可点的牌子,挑中即预填它的默认端点(没有默认的标「端点自填」); ② **连接**:API 端点 + API Key(密码框带显示切换),下面就是「测试连接」; ③ **型号与用途**:模型(厂商侧型号名)+ 用途名(活动里声明的那个)+ 两枚开关。 遮罩点击与 Esc 都关得掉 —— 抽屉盖住整屏,不给键盘出路是把人关在里面。 **默认端点从服务端取**(新 `GET /api/gov/llm/providers`):前端不自带一份 URL 表 —— 那种表迟早与 provider 档案漂移,而漂移那天没人会发现(端点错了只表现为「连不上」)。 **「测试连接」只测不存**(新 `POST /api/gov/llm/probe` + `llm.probeDraft`): 拿表单上正填的四元真发一次最小调用,一个字节不落库;密钥留空则取该实例已存的密文, 改端点、换型号不必重打钥匙。上一版是「先存再试」—— 人只想知道钥匙对不对, 结果端点被改了、实例被建了,点取消也收不回来。实测:改错端点后测试, 库里 instances 逐字节未变(测过 before/after 全等)。 顺带补 `eye-off` 图标。五闸绿。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
179 lines
7.1 KiB
TypeScript
179 lines
7.1 KiB
TypeScript
/**
|
|
* 治理台取数 —— 每个查询一把键,写动作后按键失效。
|
|
* 前端零过程状态:所有画面都是服务端投影的函数,刷新即重建(§9.2)。
|
|
*/
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
import type {
|
|
ClosureReport,
|
|
GovActivitiesOutput,
|
|
GovApprovalsOutput,
|
|
GovChannelsOutput,
|
|
GovGrantsOutput,
|
|
GovLedgerPageOutput,
|
|
GovLlmOutput,
|
|
GovMemoryOutput,
|
|
GovMetricsOutput,
|
|
GovObjectsOutput,
|
|
GovPackagesOutput,
|
|
GovStaffOutput,
|
|
GovTaskLogOutput,
|
|
GovTasksOutput,
|
|
GovToolsOutput,
|
|
GovTriggersOutput,
|
|
GovWorkGroupsOutput,
|
|
GovWorkflowOutput,
|
|
ProcessPackage,
|
|
} from '@contracts';
|
|
import type { ApprovalTemplate } from '@contracts';
|
|
import {
|
|
browseLedgerRoute,
|
|
govMetricsRoute,
|
|
govTaskLogRoute,
|
|
govWorkflowRoute,
|
|
listActivitiesRoute,
|
|
listApprovalTemplatesRoute,
|
|
listActivityMemoryRoute,
|
|
listApprovalsRoute,
|
|
listChannelsRoute,
|
|
listGovTasksRoute,
|
|
listGrantsRoute,
|
|
listLedgerObjectsRoute,
|
|
listLlmInstancesRoute,
|
|
listLlmProvidersRoute,
|
|
listProcessPackagesRoute,
|
|
listStaffRoute,
|
|
listToolsRoute,
|
|
listTriggersRoute,
|
|
listWorkGroupsRoute,
|
|
validateProcessRoute,
|
|
} from '@contracts';
|
|
import { call } from '@web-shared/typed-fetch.ts';
|
|
|
|
export type GovTasks = GovTasksOutput;
|
|
export type GovApprovals = GovApprovalsOutput;
|
|
export type GovStaff = GovStaffOutput;
|
|
export type GovActivities = GovActivitiesOutput;
|
|
export type GovTools = GovToolsOutput;
|
|
export type GovObjects = GovObjectsOutput;
|
|
export type GovLedgerPage = GovLedgerPageOutput;
|
|
export type GovMemory = GovMemoryOutput;
|
|
export type GovMetrics = GovMetricsOutput;
|
|
export type GovChannels = GovChannelsOutput;
|
|
export type GovLlm = GovLlmOutput;
|
|
export type GovWorkflow = GovWorkflowOutput;
|
|
export type GovTaskLog = GovTaskLogOutput;
|
|
export type GovGrants = GovGrantsOutput;
|
|
|
|
/** `enabled: false` 供设计中心用 —— 那一面不看运行态,别去要一份自己无权也无用的数据 */
|
|
export const useGovTasks = (opts?: { enabled?: boolean }): UseQueryResult<GovTasks> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'tasks'],
|
|
queryFn: () => call<GovTasks>(listGovTasksRoute),
|
|
enabled: opts?.enabled ?? true,
|
|
});
|
|
|
|
export const useGovApprovals = (): UseQueryResult<GovApprovals> =>
|
|
useQuery({ queryKey: ['gov', 'approvals'], queryFn: () => call<GovApprovals>(listApprovalsRoute) });
|
|
|
|
export const useGovStaff = (): UseQueryResult<GovStaff> =>
|
|
useQuery({ queryKey: ['gov', 'staff'], queryFn: () => call<GovStaff>(listStaffRoute) });
|
|
|
|
export const useGovGrants = (positionId: string | undefined): UseQueryResult<GovGrants> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'grants', positionId],
|
|
queryFn: () => call<GovGrants>(listGrantsRoute, { params: { positionId: positionId! } }),
|
|
enabled: positionId !== undefined,
|
|
});
|
|
|
|
export const useGovPackages = (): UseQueryResult<GovPackagesOutput> =>
|
|
useQuery({ queryKey: ['gov', 'process'], queryFn: () => call<GovPackagesOutput>(listProcessPackagesRoute) });
|
|
|
|
/**
|
|
* 每个包一份闭合报告 —— 磁贴上的「边 n/m」、待补清单、发布门、驾驶舱的未闭合草稿数都读它。
|
|
* 一处算、多处读:两张首页各算一遍就会各说各话。
|
|
*/
|
|
export const useGovPkgReports = (
|
|
packages: readonly ProcessPackage[],
|
|
): UseQueryResult<Map<string, ClosureReport>> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'process-reports', packages.map((p) => `${p.id}@${p.version}`).join(',')],
|
|
enabled: packages.length > 0,
|
|
queryFn: async () => {
|
|
const entries = await Promise.all(
|
|
packages.map(
|
|
async (p) =>
|
|
[`${p.id}@${p.version}`, await call<ClosureReport>(validateProcessRoute, { body: { pkg: p } })] as const,
|
|
),
|
|
);
|
|
return new Map(entries);
|
|
},
|
|
});
|
|
|
|
export type GovWorkGroups = GovWorkGroupsOutput;
|
|
|
|
export const useGovWorkGroups = (): UseQueryResult<GovWorkGroups> =>
|
|
useQuery({ queryKey: ['gov', 'work-groups'], queryFn: () => call<GovWorkGroups>(listWorkGroupsRoute) });
|
|
|
|
export const useGovTriggers = (): UseQueryResult<GovTriggersOutput> =>
|
|
useQuery({ queryKey: ['gov', 'triggers'], queryFn: () => call<GovTriggersOutput>(listTriggersRoute) });
|
|
|
|
export const useGovActivities = (): UseQueryResult<GovActivities> =>
|
|
useQuery({ queryKey: ['gov', 'activities'], queryFn: () => call<GovActivities>(listActivitiesRoute) });
|
|
|
|
/** 审批模板(审批活动)—— 活动库的第二格、编排里审批点的选项 */
|
|
export type GovApprovalTemplates = { templates: ReadonlyArray<ApprovalTemplate & { usedBy: ReadonlyArray<{ packageId: string; nodeId: string }> }> };
|
|
export const useGovApprovalTemplates = (): UseQueryResult<GovApprovalTemplates> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'approval-templates'],
|
|
queryFn: () => call<GovApprovalTemplates>(listApprovalTemplatesRoute),
|
|
});
|
|
|
|
export const useGovTools = (): UseQueryResult<GovTools> =>
|
|
useQuery({ queryKey: ['gov', 'tools'], queryFn: () => call<GovTools>(listToolsRoute) });
|
|
|
|
export const useGovObjects = (opts?: { enabled?: boolean }): UseQueryResult<GovObjects> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'objects'],
|
|
queryFn: () => call<GovObjects>(listLedgerObjectsRoute),
|
|
enabled: opts?.enabled ?? true,
|
|
});
|
|
|
|
export const useGovLedger = (domain: string | undefined, object: string | undefined): UseQueryResult<GovLedgerPage> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'ledger', domain, object],
|
|
queryFn: () => call<GovLedgerPage>(browseLedgerRoute, { params: { domain: domain!, object: object! } }),
|
|
enabled: domain !== undefined && object !== undefined,
|
|
});
|
|
|
|
export const useGovMemory = (activityId: string | undefined): UseQueryResult<GovMemory> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'memory', activityId],
|
|
queryFn: () => call<GovMemory>(listActivityMemoryRoute, { params: { activityId: activityId! } }),
|
|
enabled: activityId !== undefined,
|
|
});
|
|
|
|
export const useGovMetrics = (): UseQueryResult<GovMetrics> =>
|
|
useQuery({ queryKey: ['gov', 'metrics'], queryFn: () => call<GovMetrics>(govMetricsRoute) });
|
|
|
|
export const useGovChannels = (): UseQueryResult<GovChannels> =>
|
|
useQuery({ queryKey: ['gov', 'channels'], queryFn: () => call<GovChannels>(listChannelsRoute) });
|
|
|
|
/** Provider 档案 —— 建实例表单预填默认端点用;一次取,基本不变 */
|
|
export type GovLlmProviders = { providers: ReadonlyArray<{ provider: string; label: string; defaultBaseUrl: string; structuredOutput: string }> };
|
|
export const useGovLlmProviders = (): UseQueryResult<GovLlmProviders> =>
|
|
useQuery({
|
|
queryKey: ['gov', 'llm-providers'],
|
|
queryFn: () => call<GovLlmProviders>(listLlmProvidersRoute),
|
|
staleTime: 10 * 60_000,
|
|
});
|
|
|
|
export const useGovLlm = (): UseQueryResult<GovLlm> =>
|
|
useQuery({ queryKey: ['gov', 'llm'], queryFn: () => call<GovLlm>(listLlmInstancesRoute) });
|
|
|
|
export const useGovWorkflow = (id: string): UseQueryResult<GovWorkflow> =>
|
|
useQuery({ queryKey: ['gov', 'workflow', id], queryFn: () => call<GovWorkflow>(govWorkflowRoute, { params: { id } }) });
|
|
|
|
export const useGovTaskLog = (taskId: string): UseQueryResult<GovTaskLog> =>
|
|
useQuery({ queryKey: ['gov', 'tasklog', taskId], queryFn: () => call<GovTaskLog>(govTaskLogRoute, { params: { taskId } }) });
|