Files
AgentLab/frontend/src/api/caliberLedger.ts
T
ThearchyHelios b24aabefcf 账本前端:证据「口径」一步、数字上的小标记、问数据轮次摘要与出具 / 对账、可沉淀的问题、设置里的口径账本一组
第 2、3 波只有接口,这一波接上界面(docs/design/next-round/02-口径账本.md 做法 3–6、8 的界面、做法 11;总方案 X3、X10)。
界面层不放逻辑:标签、整题判断、能不能出具、能不能自动、不能的原因、要不要先核对参数都照 GET /api/runs/{id}/ledger 给的画。

- 比对结果不靠实时流(第 2 波遗留):ledger.matched 在封存之后追加、事件总线已经关了,打开着的页面收不到。store/ledger
  按退避轮询(1、2、3、5、8、13 秒,之后每 15 秒),服务端答 pending 时写「正在比对口径」,等满 2 分钟还没结论照实说、
  给「再取一次」;要自动出具的再等出具的那一次出现,出具、对账的运行没结束的等它们结束。只在有组件看着时轮询,同一次
  运行的正文、面板、轮次摘要共用一份
- 证据正文(EvidenceDoc):来自口径的数字后面挂一个小标记,写明受管 / 已发布,悬停写是哪一份口径、怎么认的;相关口径的
  数不加标记
- 证据面板出处链最上面加「口径」一步(run/LedgerStep):来自口径——「X」v3(受管)· 参数 · 等价已证明 / 助手选用 ·
  按口径正式出具;相关口径——差在哪 + 看差多少;这次的推理——没有相关的已发布口径;没比对的写原因;脚注写「封存后比对,
  不在封存范围内」,事后补比的写按哪种口径回看
- 口径对账(run/LedgerReconcile):核对参数(照动作里的入口字段画,推断的参数要先核对,遮罩值不回填)→ 发起(认不出列
  怎么配时照 409 带回的选项选对照的指标)→ 结果卡片:每组按你的问法、按口径、差值(附相对差)各自点得开出处链
  (apps/EvidenceDrawer,同应用页点数)
- 问数据轮次底部(run/LedgerTurn):一行摘要(几个数来自口径「X」vN、几个是这次的推理、几个没有比对)、整题等价时按口径
  正式出具(能自动的写正在自动出具;不能的照写原因,使用者没有应用授权写「请搭建者出具」)、有相关口径时对账;出具过的
  正式运行挂在下面,档位写完整出具 / 降档出具 / 不予出具,搭建者点开去运行;回收站里的对话只看不发起
- 可沉淀的问题(pages/ledger/CertifyQueue):工作流列表弹窗里的抽屉,确定性重复、问题聚类、被反复用的答案分开写;
  「固化成口径草稿」走 /copilot/from-run 的 freeze 并打开画布,聚类没有共同的 SQL、按人挑的那一轮固化;「不是口径」
  要写理由
- 设置(pages/settings/LedgerSettings,照 VerifySettings):自动按口径正式出具、每日上限、比对时限、升版后每次最多重算几组,
  和其余偏好共用保存条、整组写 ledger
- 类型 typesLedger.ts、接口 api/caliberLedger.ts(挂 api.caliberLedger)、文案 lib/termsLedger.ts;types.ts 的证据片段
  答复加 ledger、rendered 两个键
2026-10-16 20:02:08 +08:00

38 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 口径账本的接口(docs/design/next-round/02-口径账本.md),挂在 api.caliberLedger 上。形状见 typesLedger.ts。
*
* - run:GET /api/runs/{id}/ledger,一次运行里每个数的口径标签、整题判断、能做的动作、出具过的正式运行、对过的账;
* - issue:按口径正式出具(参数只由服务端从比对工件里取,这里只能选「按哪份口径」);
* - reconcile:口径对账(点开才跑一次确定性派生的只读图);
* - certifyQueue / dismiss:可沉淀的问题、「不是口径」(搭建者及以上);
* - freeze:固化成口径草稿(/copilot/from-run 的 freeze 选项,报告引用的查询变成固定 SQL 的取数节点)。
*
* 应用平台的「账本」(版本被哪些应用固定、生效记录)在 api.ledger(api/apps.ts),和这里不是一回事。
* 请求函数从 ./http 导入,不从 ./client 导入(client.ts 要导入这个文件,反过来就成了循环)。
*/
import type {
CertifyQueue, FreezeOut, LedgerIssueOut, LedgerReconcileIn, LedgerReconcileOut, RunLedger,
} from '../typesLedger'
import { get, post, type RequestOptions } from './http'
const at = (runId: string) => `/ledger/answers/${encodeURIComponent(runId)}`
export const caliberLedger = {
run: (runId: string, opts?: RequestOptions) => get<RunLedger>(`/runs/${encodeURIComponent(runId)}/ledger`, opts),
issue: (runId: string, body: { workflow_id: string; version: number }) => post<LedgerIssueOut>(`${at(runId)}/issue`, body),
reconcile: (runId: string, body: LedgerReconcileIn) => post<LedgerReconcileOut>(`${at(runId)}/reconcile`, body),
certifyQueue: (opts?: RequestOptions) => get<CertifyQueue>('/ledger/certify-queue', opts),
dismiss: (body: { item_id: string; kind?: string; note: string }) =>
post<{ ok: boolean; item_id: string }>('/ledger/certify-queue/dismiss', body),
/**
* 固化成口径草稿:代表运行里报告引用了的查询变成固定 SQL 的取数节点,peers(同一个 SQL 形状的别的运行)用来认哪些字面量
* 跨轮变了。落成新的草稿工作流,人在画布上审改、按受管级别发布
*/
freeze: (runId: string, opts: { peers?: string[]; conversation_id?: string | null; turn_id?: string | null } = {}) =>
post<FreezeOut>('/copilot/from-run', {
run_id: runId, freeze: true, peers: opts.peers ?? [],
...(opts.conversation_id ? { conversation_id: opts.conversation_id } : {}),
...(opts.turn_id ? { turn_id: opts.turn_id } : {}),
}),
}