合入 W1-b 已知遗留:人工驳回记成已取消 + end_reason=rejected(不重试、不被出错时继续吞掉),各处照实写「被驳回」;个人渠道「我发起的实例完成 / 失败」生效;导入清单如实记「是否认证」;使用者选人按候选池、开登录时服务端核对;自由形蓝图按导入的图列「谁来做」;tick 按 id 断言

This commit is contained in:
ThearchyHelios
2026-10-16 12:51:43 +08:00
99 changed files with 2770 additions and 263 deletions
+4 -1
View File
@@ -2,7 +2,7 @@
* 身份的接口(/api/auth、/api/users、/api/groups、/api/audit),挂在 api.auth / api.identity 上。形状见 typesApp.ts。
* 开登录时:没登录的请求回 401(前端跳 /login),角色不够回 403。关登录时 /me 恒为 mode='off'。
*/
import type { AuditRow, AuthMode, Directory, GroupRow, Principal, Role, UserRow } from '../typesApp'
import type { AuditRow, AuthMode, CandidateSource, Candidates, Directory, GroupRow, Principal, Role, UserRow } from '../typesApp'
import { del, get, patch, post, put, qs, type RequestOptions } from './http'
export const auth = {
@@ -29,6 +29,9 @@ export const identity = {
groups: () => get<{ items: GroupRow[] }>('/groups'),
/** 选人用的名录:搭建者及以上只读(/users、/groups 只给管理员) */
directory: () => get<Directory>('/directory'),
/** 使用者选人的候选:按用途给的池,只有名字(任何登录的人都能调;用不了那个应用的 403)。q 按开头筛 */
candidates: (source: CandidateSource, q?: string, limit = 20) =>
get<Candidates>(`/directory/candidates${qs({ ...source, q: q || undefined, limit })}`),
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)}`),
+67 -14
View File
@@ -5,15 +5,18 @@
* 名录里没有的、停用了的不让添加,说清是哪一个(账号密码登录时人和组都在本系统里建,名录里没有就是填错了);单点登录的
* 人和组第一次登录后才进名录,名录里没有的照实提醒,点「仍然添加」才加上。已选的里头名录里没有的、停用了的在标签上
* 标出来,不静默放着。
* 使用者读不到名录:照填,服务端按名字认。关登录时没有用户表,只能手填名字——签批记的也是各自填的署名,这里不假装能核对。
* 使用者读不到名录(只读与最小可见):给了 source 的(表单里的选人控件、个人应用提交审核)边输入边按开头取候选
* (GET /api/directory/candidates,05-已知遗留 (b)),只有这件事能选的人、只有名字;加的时候按同一个池问一次服务端,不在池里的
* 当场说清。提交时服务端照同一个池核对(不在池里 422),这里只是提前说。没给 source 的照填,服务端按名字认。
* 关登录时没有用户表,只能手填名字——签批记的也是各自填的署名,这里不假装能核对。
*/
import { useEffect, useId, useState } from 'react'
import { useEffect, useId, useRef, useState } from 'react'
import { Plus, Users, UserRound, X } from 'lucide-react'
import clsx from 'clsx'
import { api } from '../api/client'
import { PRINCIPAL_TEXT } from '../lib/termsApp'
import { useAtLeast, useAuth, useLoginOn } from '../store/auth'
import type { Directory } from '../typesApp'
import type { CandidateSource, Candidates, Directory } from '../typesApp'
import { isComposing } from './ui'
export interface Principal {
@@ -29,8 +32,16 @@ export interface PrincipalPickerProps {
/** 只能选一个 */
single?: boolean
label?: string
/**
* 使用者取候选的池(服务端按用途算):表单里的选人控件(入口、待办)、个人应用提交审核。搭建者及以上照旧用整份名录,
* 不看它
*/
source?: CandidateSource
}
/** 边输入边取候选:停手这么久再去问,不是每敲一个字问一次 */
const ASK_DELAY_MS = 250
/** 名录只取一次,同一页上几个选择器共用;没取到(断线)下次打开再取 */
let directory: Promise<Directory | null> | null = null
function loadDirectory(): Promise<Directory | null> {
@@ -46,15 +57,21 @@ function problemOf(p: Principal, known: Directory | null): 'missing' | 'disabled
return !user ? 'missing' : user.disabled ? 'disabled' : null
}
export function PrincipalPicker({ value, onChange, allowEveryone = false, single = false, label }: PrincipalPickerProps) {
export function PrincipalPicker({ value, onChange, allowEveryone = false, single = false, label, source }: PrincipalPickerProps) {
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, '')
const loginOn = useLoginOn()
// 名录给搭建者及以上(使用者读不到,不去取:取了也是 403)
const listable = useAtLeast('builder') && loginOn
// 使用者:有 source 就按池取候选
const asking = !listable && loginOn && !!source
const sourceKey = source ? JSON.stringify(source) : ''
const oidc = useAuth((s) => s.me?.mode === 'oidc')
const [kind, setKind] = useState<'user' | 'group'>('user')
const [text, setText] = useState('')
const [known, setKnown] = useState<Directory | null>(null)
const [pool, setPool] = useState<Candidates | null>(null)
/** 取到过的候选:用户名 → 显示名(标签上写显示名,悬停给用户名) */
const shown = useRef(new Map<string, string>())
/** 刚才要加、名录里对不上的那一项:soft 是单点登录下名录里还没有(可以「仍然添加」),其余不让加 */
const [refused, setRefused] = useState<{ item: Principal; message: string; soft: boolean } | null>(null)
useEffect(() => {
@@ -63,12 +80,38 @@ export function PrincipalPicker({ value, onChange, allowEveryone = false, single
void loadDirectory().then((d) => { if (alive) setKnown(d) })
return () => { alive = false }
}, [listable])
useEffect(() => {
if (!asking || !source) return
let alive = true
const timer = window.setTimeout(() => {
api.identity.candidates(source, text.trim())
.then((c) => {
if (!alive) return
for (const u of c.users) shown.current.set(u.username, u.display_name)
setPool(c)
})
.catch(() => { if (alive) setPool(null) })
}, ASK_DELAY_MS)
return () => { alive = false; window.clearTimeout(timer) }
// sourceKey 代替 source:调用方每次渲染都给一个新对象
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [asking, sourceKey, text])
const has = (p: Principal) => value.some((x) => x.kind === p.kind && x.name === p.name)
const add = (p: Principal, anyway = false) => {
const add = async (p: Principal, anyway = false) => {
const item = { ...p, name: p.name.trim() }
if (!item.name) return
if (has(item)) { setText(''); setRefused(null); return }
if (asking && source && item.kind !== 'everyone') {
// 按同一个池问一次服务端:不在池里的当场说清(提交时服务端照样拒)。问不到(断线)就先收下,提交时由服务端判
const found = await api.identity.candidates(source, item.name, 50).catch(() => null)
const listed = found && (item.kind === 'group' ? found.groups.some((g) => g.name === item.name)
: found.users.some((u) => u.username === item.name))
if (found && !listed) {
setRefused({ item, soft: false, message: PRINCIPAL_TEXT.notCandidate(item.name) })
return
}
}
const problem = problemOf(item, known)
const soft = problem === 'missing' && oidc
if (problem && !(soft && anyway)) {
@@ -87,9 +130,16 @@ export function PrincipalPicker({ value, onChange, allowEveryone = false, single
const remove = (p: Principal) => onChange(value.filter((x) => !(x.kind === p.kind && x.name === p.name)))
const listId = `${uid}-list`
const errorId = `${uid}-error`
const options = !known ? [] : kind === 'user'
? known.users.filter((u) => !u.disabled).map((u) => ({ value: u.username, label: u.display_name }))
: known.groups.map((g) => ({ value: g.name, label: g.label }))
const options = asking
? (!pool ? [] : kind === 'user' ? pool.users.map((u) => ({ value: u.username, label: u.display_name }))
: pool.groups.map((g) => ({ value: g.name, label: g.label })))
: !known ? [] : kind === 'user'
? known.users.filter((u) => !u.disabled).map((u) => ({ value: u.username, label: u.display_name }))
: known.groups.map((g) => ({ value: g.name, label: g.label }))
/** 候选池要先输入开头才列(应用授权给了所有人)、列不全(超过上限) */
const poolHint = asking && pool
? (pool.needs_query && !text.trim() ? PRINCIPAL_TEXT.typeToSearch : pool.truncated ? PRINCIPAL_TEXT.truncated : null)
: null
return (
<div className="min-w-0" data-principal-picker="">
@@ -102,7 +152,9 @@ export function PrincipalPicker({ value, onChange, allowEveryone = false, single
data-principal-problem={problem ?? undefined}
style={problem ? { color: 'var(--st-waiting)', borderColor: 'var(--st-waiting)' } : undefined}>
{p.kind === 'group' ? <Users size={11} aria-hidden /> : p.kind === 'user' ? <UserRound size={11} aria-hidden /> : null}
<span>{p.kind === 'everyone' ? PRINCIPAL_TEXT.everyone : p.name}</span>
<span title={p.kind === 'user' && shown.current.get(p.name) ? p.name : undefined}>
{p.kind === 'everyone' ? PRINCIPAL_TEXT.everyone : shown.current.get(p.name) ?? p.name}
</span>
<span className="sr-only">({PRINCIPAL_TEXT[p.kind]})</span>
{problem && <span className="text-2xs">· {problem === 'disabled' ? PRINCIPAL_TEXT.disabledTag : PRINCIPAL_TEXT.missingTag}</span>}
<button type="button" className="-mr-0.5 rounded text-faint hover:text-fg" aria-label={PRINCIPAL_TEXT.remove(p.kind === 'everyone' ? PRINCIPAL_TEXT.everyone : p.name)}
@@ -127,21 +179,21 @@ export function PrincipalPicker({ value, onChange, allowEveryone = false, single
onKeyDown={(e) => {
if (e.key !== 'Enter' || isComposing(e)) return
e.preventDefault()
add({ kind, name: text })
void add({ kind, name: text })
}}
// 单选时填完就算选好,不用再点「添加」:表单里的选人控件和普通输入框一样,失焦即生效
onBlur={() => { if (single && text.trim()) add({ kind, name: text }) }} />
onBlur={() => { if (single && text.trim()) void add({ kind, name: text }) }} />
{options.length > 0 && (
<datalist id={listId}>
{options.map((o) => <option key={o.value} value={o.value}>{o.label !== o.value ? o.label : undefined}</option>)}
</datalist>
)}
<button type="button" className="btn btn-sm shrink-0" disabled={!text.trim()} onClick={() => add({ kind, name: text })}>
<button type="button" className="btn btn-sm shrink-0" disabled={!text.trim()} onClick={() => void add({ kind, name: text })}>
<Plus size={12} aria-hidden /> {PRINCIPAL_TEXT.add}
</button>
{allowEveryone && (
<button type="button" className={clsx('btn btn-sm shrink-0', has({ kind: 'everyone', name: '*' }) && 'opacity-50')}
disabled={has({ kind: 'everyone', name: '*' })} onClick={() => add({ kind: 'everyone', name: '*' })}>
disabled={has({ kind: 'everyone', name: '*' })} onClick={() => void add({ kind: 'everyone', name: '*' })}>
{PRINCIPAL_TEXT.everyone}
</button>
)}
@@ -151,12 +203,13 @@ export function PrincipalPicker({ value, onChange, allowEveryone = false, single
style={{ color: refused.soft ? 'var(--st-waiting)' : 'var(--err)' }} data-principal-refused={refused.soft ? 'soft' : 'hard'}>
<span>{refused.message}</span>
{refused.soft && (
<button type="button" className="btn btn-xs" onClick={() => add(refused.item, true)} data-principal-add-anyway="">
<button type="button" className="btn btn-xs" onClick={() => void add(refused.item, true)} data-principal-add-anyway="">
{PRINCIPAL_TEXT.addAnyway}
</button>
)}
</div>
)}
{poolHint && <div className="mt-1 text-2xs text-faint" data-principal-pool-hint="">{poolHint}</div>}
{!loginOn && <div className="mt-1 text-2xs text-faint">{PRINCIPAL_TEXT.manualHint}</div>}
</div>
)
+12 -2
View File
@@ -12,7 +12,7 @@
import { useEffect, useId, useState } from 'react'
import type { CSSProperties, KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react'
import clsx from 'clsx'
import type { FormError, FormField, FormSchema } from '../typesApp'
import type { CandidateSource, FormError, FormField, FormSchema } from '../typesApp'
import { FORM_TEXT } from '../lib/termsApp'
import {
fieldOfPath, fieldOrder, fileLimitsOf, localToRfc3339, optionsOf, rfc3339ToLocal, widgetOf,
@@ -88,6 +88,16 @@ export function SchemaForm({ schema, value, onChange, errors, readOnly, onSubmit
)
}
/**
* 选人控件的候选从哪个池取:表单用在入口(app_id + entry)、待办(task_id)上时,按这个字段问服务端(05-已知遗留 (b));
* 蓝图试运行之类没有应用的地方不给(搭建者用整份名录)
*/
function principalSource(context: Record<string, string> | undefined, field: string): CandidateSource | undefined {
if (context?.task_id) return { purpose: 'form', task_id: context.task_id, field }
if (context?.app_id && context.entry) return { purpose: 'form', app_id: context.app_id, entry: context.entry, field }
return undefined
}
function FieldRow({ id, name, field, required, value, error, readOnly, onChange, fileContext }: {
id: string; name: string; field: FormField; required: boolean; value: unknown; error?: FormError
readOnly: boolean; onChange: (v: unknown) => void; fileContext?: Record<string, string>
@@ -143,7 +153,7 @@ function FieldRow({ id, name, field, required, value, error, readOnly, onChange,
<div className="label">{label}</div>
{readOnly
? <div className="text-xs text-fg">{typeof value === 'string' && value ? value : '—'}</div>
: <PrincipalPicker single label={title}
: <PrincipalPicker single label={title} source={principalSource(fileContext, name)}
value={typeof value === 'string' && value ? [{ kind: 'user', name: value }] : []}
onChange={(list) => onChange(list[0]?.name || undefined)} />}
{foot}
+7 -3
View File
@@ -295,11 +295,15 @@ export function explainRunError(error: string | null | undefined, detail?: strin
raw,
}
}
// 后端有一条路径以前写「人工拒绝:」(现在统一为「人工驳回:」),历史运行里两种都有
if (/人工(?:驳回|拒绝)/.test(text)) {
// 只留给存量:加 end_reason 之前被驳回的运行记的是 failed,报错原文是这几种说法。新的驳回结束在 cancelled +
// end_reason=rejected,界面按那个字段说(lib/status、REJECTED_TEXT),不走这里(05-已知遗留 (a))。后端有一条路径
// 以前写「人工拒绝:」(现在统一为「人工驳回:」);动作确认、工具调用审批、代码执行审批的驳回各有一种原话。
// 接着跑只会读到同一个驳回答复、再停一次,所以都不给「继续运行」
if (/人工(?:驳回|拒绝)|未确认(被驳回)|的调用已被驳回|代码执行已被驳回/.test(text)) {
const human = /^人工(?:驳回|拒绝)/.test(plain)
return {
title: '人工审批驳回,运行终止',
reason: plain.replace(/^人工(?:驳回|拒绝)[::]?\s*/, '') || undefined,
reason: (human ? plain.replace(/^人工(?:驳回|拒绝)[::]?\s*/, '') : plain) || undefined,
action: '这是审批人的决定,不是故障。如有需要,请修改内容后重新发起运行。',
continuable: false,
raw,
+24 -6
View File
@@ -22,6 +22,7 @@ export type StatusCode =
| 'succeeded' // 运行跑完
| 'failed'
| 'cancelled'
| 'rejected' // 运行:被人驳回结束(后端是 cancelled + end_reason=rejected,05-已知遗留 (a))
| 'suspended' // 服务重启后挂起,可续跑
| 'held' // 后端的 interrupted 但没有待审批:已挂起 · 可续跑
| 'skipped' // 被 skip_if 跳过
@@ -104,6 +105,11 @@ export const STATUS: Record<StatusCode, StatusMeta> = {
code: 'cancelled', label: '已取消', short: '已取消', shape: 'stop', alert: false, terminal: true,
...tok('cancelled', 'var(--text-faint)'),
},
// 人的决定,不是故障:不画红、不给继续运行;和手动停止同一个剪影,叫法分开
rejected: {
code: 'rejected', label: '被驳回', short: '被驳回', shape: 'stop', alert: false, terminal: true,
hint: '审批人驳回了这次运行,运行到这里结束;改好内容后重新发起', ...tok('cancelled', 'var(--text-faint)'),
},
suspended: {
code: 'suspended', label: '已中断(服务重启)', short: '已中断', shape: 'pause', alert: true, terminal: true,
hint: '服务重启时本次运行尚未结束,已在断点处挂起,可继续运行', ...tok('suspended', 'var(--warn)'),
@@ -141,15 +147,25 @@ const ALIAS: Record<string, StatusCode> = {
* 才分得开——传 pendingApproval。不知道时(没传)按等待审批处理,这是
* interrupted 最常见的来源,也是改造前的说法,不会比原来更错。
*/
export function resolveStatus(status: string | null | undefined, opts?: { pendingApproval?: boolean }): StatusCode {
export function resolveStatus(status: string | null | undefined, opts?: StatusOpts): StatusCode {
if (!status) return 'idle'
if (status === 'interrupted') return opts?.pendingApproval === false ? 'held' : 'waiting'
// 被驳回只看服务端给的 end_reason,不解析报错原文(界面层不放逻辑)
if (status === 'cancelled' && opts?.endReason === 'rejected') return 'rejected'
if (status in STATUS) return status as StatusCode
return ALIAS[status] ?? 'idle'
}
/**
* 落状态要的旁证:pendingApproval 分 interrupted 的两种;endReason 是运行的 end_reason(cancelled 时分被驳回和手动停止)
*/
export interface StatusOpts {
pendingApproval?: boolean
endReason?: string | null
}
/** 状态的完整外观。未知状态码回落到 idle 的外观,文字写原码,免得静默吞掉 */
export function statusMeta(status: string | null | undefined, opts?: { pendingApproval?: boolean }): StatusMeta {
export function statusMeta(status: string | null | undefined, opts?: StatusOpts): StatusMeta {
const code = resolveStatus(status, opts)
const meta = STATUS[code]
if (status && code === 'idle' && status !== 'idle' && !(status in ALIAS)) {
@@ -159,7 +175,7 @@ export function statusMeta(status: string | null | undefined, opts?: { pendingAp
}
/** 只要文字 */
export function statusLabel(status: string | null | undefined, opts?: { pendingApproval?: boolean; short?: boolean }): string {
export function statusLabel(status: string | null | undefined, opts?: StatusOpts & { short?: boolean }): string {
const meta = statusMeta(status, opts)
return opts?.short ? meta.short : meta.label
}
@@ -167,10 +183,11 @@ export function statusLabel(status: string | null | undefined, opts?: { pendingA
/**
* 运行列表的状态筛选用:按显示顺序排好的运行状态。
* 这是显示用的码,不能直接当查询参数——waiting / held 在后端都是 interrupted,
* 查询前用 serverStatusOf 换回去。
* rejected 在后端是 cancelled(+ end_reason=rejected),查询前用 serverStatusOf 换回去。
* 被驳回单独一项、紧跟在已取消后面:不在这里的码,分段、计数、搜索词表里都没有它,被驳回的运行只剩「全部」里看得到
*/
export const RUN_STATUS_ORDER: StatusCode[] = [
'running', 'waiting', 'held', 'failed', 'succeeded', 'cancelled', 'queued',
'running', 'waiting', 'held', 'failed', 'succeeded', 'cancelled', 'rejected', 'queued',
]
/**
@@ -178,7 +195,7 @@ export const RUN_STATUS_ORDER: StatusCode[] = [
*
* waiting、held、suspended 在后端都是 interrupted:按它查回来的是两种混在一起,
* 要再用 resolveStatus(run.status, {pendingApproval: hasPendingApproval(approvals,
* run.id)}) 在前端分开。节点才有的状态(idle / skipped / blocked / unreached)
* run.id)}) 在前端分开。rejected 同理查 cancelled,回来按 end_reason 分开(被驳回 / 手动停止)。节点才有的状态(idle / skipped / blocked / unreached)
* 不是运行状态,返回 null。
*/
export function serverStatusOf(code: StatusCode): RunStatus | null {
@@ -186,6 +203,7 @@ export function serverStatusOf(code: StatusCode): RunStatus | null {
case 'waiting': case 'held': case 'suspended': return 'interrupted'
case 'done': case 'succeeded': return 'succeeded'
case 'queued': case 'running': case 'failed': case 'cancelled': return code
case 'rejected': return 'cancelled'
default: return null
}
}
+19
View File
@@ -5163,6 +5163,25 @@ export const SYSTEM_RUNS_TEXT = {
hint: '评测、口径对账、口径召回是系统代为发起的运行:证据仍可查看,但不计入使用统计,记录页默认不列',
}
/**
* 驳回 ≠ 失败(docs/design/next-round/05-已知遗留.md (a)):人的驳回让运行结束在 cancelled + end_reason=rejected,
* run.cancelled 带着在哪一步(label)、谁(actor)、结论(decision)、备注(note)。时间线、问数据的终态、记录页都照这一份说,
* 不再按报错原文猜
*/
export const REJECTED_TEXT = {
title: '被驳回',
/** 副标题:谁在哪一步驳回、备注;超时驳回写按设置驳回(备注是系统写的那句,不重复) */
sub: (d: { actor?: unknown; label?: unknown; note?: unknown; decision?: unknown }): string => {
const who = typeof d.actor === 'string' ? d.actor.trim() : ''
const where = typeof d.label === 'string' && d.label.trim() ? `「${d.label.trim()}」` : '这一步'
const note = typeof d.note === 'string' ? d.note.trim() : ''
if (d.decision === 'expired_reject') return `${where}超过时限,按设置驳回`
return `${who ? `${who} 驳回了${where}` : `${where}被驳回`}${note ? `:${note}` : ''}`
},
/** 问数据:这一轮的运行被驳回结束时,补救区的那一句 */
chatReason: '这一轮的运行被审批人驳回,已经结束。这是人的决定,不是故障;改好内容后可以重新运行。',
}
/** 来源标签:老运行没有来源时写「来源未记录」 */
export const originLabel = (kind: string | null | undefined): string =>
kind && kind in ORIGIN_LABEL ? ORIGIN_LABEL[kind as OriginKind] : ORIGIN_TEXT.unknown
+13
View File
@@ -368,6 +368,10 @@ export const PRINCIPAL_TEXT = {
/** 已选的那一项不在名录里、或已停用:标在标签上 */
missingTag: '名录里没有',
disabledTag: '已停用',
/** 使用者选人:候选按这件事能选的人给(服务端 auth/directory 的候选池,05-已知遗留 (b)) */
notCandidate: (name: string) => `「${name}」不在可选的人里,请从候选中选择`,
typeToSearch: '能选的人较多:输入名字的开头查找',
truncated: '只列出了一部分:多输入几个字缩小范围',
}
/** 身份:登录、账户菜单、角色(§4.4 AUTH_TEXT) */
@@ -445,6 +449,15 @@ export const SIGNER_TEXT = {
record: '记入留痕',
}
/**
* 个人渠道(设置 → 通知,范围是「仅自己」)里实例结束的两个事件:只推自己发起、而且是登录身份发起的实例(服务端
* notify/service.notify_run,04-对外集成与触达 B1)。以前叫「实例完成 / 失败」,勾了却永远收不到
*/
export const NOTIFY_PERSONAL_EVENT_LABEL: Record<string, string> = {
'run.finished': '我发起的实例完成',
'run.failed': '我发起的实例失败',
}
/** 发布弹窗按角色收起的档位(Q8:受管级发布只给管理员,服务端 api/workflows 同样拒) */
export const PUBLISH_ROLE_TEXT = {
governedAdminOnly: '需要管理员:以受管级发布只给管理员,请联系管理员发布',
+7
View File
@@ -356,6 +356,13 @@ export const BP_EDIT_TEXT = {
reconcilerHint: '这项写入能力没登记查询:写回的结果不明时(请求发出去了、没拿到答复),平台查不了,也不会自动重发,'
+ '要有人去目标系统里看写进去没有。只能由你来选。',
reconcilerUnused: '这项写入能力已经登记了查询,结果不明时平台自己去查:这一项用不上了,发布时不会派给他们。',
/**
* 自由形的「谁来做」(05-已知遗留 (d)):按导入的图列出,只定由谁做;行名、会签、时限、超时都来自图,要改回画布
*/
freeformPeopleHint: '按导入的图列出:这里只定每一步由谁做,会签、时限、超时和步骤本身在画布上改。',
freeformPeopleEmpty: '导入的图里没有要指定由谁处理的步骤。',
freeformWho: '谁来做',
freeformReadOnly: '图上已经写定,这里不用选',
removeTitle: (where: string) => `删掉${where}?`,
removeConfirm: '删掉',
template: '换一个场景',
+5 -3
View File
@@ -17,7 +17,7 @@ import { humanizeError } from '../lib/errors'
import { explainRunError } from '../lib/explain'
import { canLeave, leavePass } from '../lib/leave'
import { formatNumber, formatTime } from '../lib/format'
import { CHAT_BLUEPRINT_TEXT, TURN_COST_TEXT, runCostText } from '../lib/terms'
import { CHAT_BLUEPRINT_TEXT, REJECTED_TEXT, TURN_COST_TEXT, runCostText } from '../lib/terms'
import { useCatalog, useCatalogListState, useDatasources, useOnReconnect, type CatalogListState } from '../store/catalog'
import { useAtLeast } from '../store/auth'
import { useBlueprint } from '../store/blueprint'
@@ -384,7 +384,8 @@ function toStreamTurn(turn: ChatTurn): StreamTurn {
: turn.phase === 'error' ? 'error'
: live || turn.phase === 'checking' ? 'running' : 'done',
// 没核对上的不知道结局,用「未运行」那个空心点,不画成完成也不画成失败
statusCode: turn.phase === 'cancelled' ? 'cancelled'
// 被人驳回的(turn.rejected,服务端 end_reason=rejected)照 lib/status 写「被驳回」,不写「已取消」
statusCode: turn.phase === 'cancelled' ? (turn.rejected ? 'rejected' : 'cancelled')
: turn.phase === 'suspended' ? 'suspended'
// 助手反问:这一轮结束了,在等用户回答
: turn.asked && turn.phase === 'done' ? 'waiting'
@@ -753,6 +754,7 @@ function Remedies({ conversationId, turnId, last, onRephrase, readOnly }: {
// 中断、取消、没核对上在流里不出红框(它们不是故障),为什么停、停了意味着什么在这里说
const note = kind === 'suspended' || kind === 'unknown' ? turn.failure
: kind === 'cancelled' && turn.rejected ? { title: '', reason: REJECTED_TEXT.chatReason, hint: turn.rejected.sub }
: kind === 'cancelled' ? { title: '', reason: turn.run ? '你已停止本轮,对应的运行也已一并取消。' : '你在搭建工作流时停止了本轮。' }
: null
@@ -824,7 +826,7 @@ function remedyOf(t: ChatTurn): Remedy | null {
}
const OUTCOME: Record<Attempt['outcome'], string> = {
failed: 'failed', cancelled: 'cancelled', suspended: 'suspended',
failed: 'failed', cancelled: 'cancelled', rejected: 'rejected', suspended: 'suspended',
unusable: 'failed', partial: 'waiting', done: 'succeeded',
}
+6 -2
View File
@@ -473,6 +473,9 @@ export async function purgeConversation(c: Conversation, navigate: NavigateFunct
/**
* 这个会话此刻值得标出来的状态(已经取回内存的)。正常完成的不标:正常态安静,
* 异常态才醒目。
*
* 被驳回的标(不画异常色):是审批人的决定,发问的人不一定知道——在等审批的那一问被驳回之后,不标就像是答完了。以前
* 驳回记成失败,标的是「失败」
*/
function liveStatus(turns: ChatTurn[]): string | null {
if (!turns.length) return null
@@ -481,12 +484,13 @@ function liveStatus(turns: ChatTurn[]): string | null {
const last = turns[turns.length - 1]
if (last.phase === 'error') return 'failed'
if (last.phase === 'suspended') return 'suspended'
if (last.phase === 'cancelled' && last.rejected) return 'rejected'
return null
}
/** 没打开过的会话:列表接口带来的最后一轮状态。完成、取消的不标,同上 */
/** 没打开过的会话:列表接口带来的最后一轮状态。完成、取消的不标,被驳回的标,同上 */
const LIST_STATUS: Partial<Record<NonNullable<Conversation['last_status']>, string>> = {
running: 'running', waiting: 'waiting', error: 'failed', suspended: 'suspended',
running: 'running', waiting: 'waiting', error: 'failed', suspended: 'suspended', rejected: 'rejected',
}
const listStatus = (c: Conversation): string | null => (c.last_status && LIST_STATUS[c.last_status]) || null
+1 -1
View File
@@ -171,7 +171,7 @@ function ReviewDialog({ appId, onClose, onSent }: {
<p className="text-xs leading-relaxed text-dim">{T.reviewIntro}</p>
<div>
<div className="label"><UserRound size={11} aria-hidden className="mr-1 inline" />{T.reviewTo}</div>
<PrincipalPicker single value={to} onChange={setTo} label={T.reviewTo} />
<PrincipalPicker single value={to} onChange={setTo} label={T.reviewTo} source={{ purpose: 'review' }} />
<p className="mt-1 text-2xs text-faint">{T.reviewToHint}</p>
</div>
<div>
@@ -7,6 +7,7 @@
* 哪些项必填(P7)。
*
* 写回卡片上「结果不明时谁去核实」只在目标能力没登记查询时摆(服务端 Blueprint.reconciler_needed),只能由人选(同「谁能看」)。
* 自由形的「谁来做」按服务端给的 derived_people 摆(FreeformPeople):骨架是导入的图,卡片只定每一步由谁做。
*
* 每一项可以点「修改」:改完发一个 bp_set(值是纯值,服务端记成来源「你」、已确认);待确认的可以直接点「确认」(只改状态,
* 来源不变),一张卡片上待确认的不止一项时卡头另有「确认全部」,一次修改带上这几项的状态(服务端整批落或整批不落)。
@@ -26,7 +27,7 @@ import {
} from '../../lib/terms'
import { chatBusy, useBlueprint } from '../../store/blueprint'
import type {
Blueprint, BpDataItem, BpField, BpItem, BpOp, BpStep, ItemStatus, JointState, PlainIssue, TemplateInfo,
Blueprint, BpDataItem, BpField, BpItem, BpOp, BpStep, DerivedPerson, ItemStatus, JointState, PlainIssue, TemplateInfo,
} from '../../typesBlueprint'
import { SELF_RECORDS, ValueEditor, valueText, type EditorKind, type EditorScope } from './editors'
import { isItem, missingPaths, visibleCards, type CardKey } from './shared'
@@ -175,6 +176,7 @@ function CardFor({ card, ctx, template }: { card: CardKey; ctx: CardCtx; templat
</Card>
)
case 'people': {
if (ctx.bp.derived_people) return <FreeformPeople ctx={ctx} rows={ctx.bp.derived_people} note={note} />
const items = spec.people.flatMap((s, i) => STEP_KEYS.map((k) => [`/people/${i}/${k}`, s[k] as BpItem] as [string, BpItem]))
return (
<Card card={card} note={note} issues={issues} status={cardStatus(ctx, card, items)}
@@ -254,6 +256,45 @@ function Empty() {
return <p className="text-2xs text-faint">{BLUEPRINT_TEXT.empty}</p>
}
/**
* 自由形的「谁来做」(05-已知遗留 (d)):按服务端给的 derived_people 一行一行摆,不自己从图里推。岗位行、核实人那一行只定
* 由谁做(改了发 bp_set 到那一行的 path);发起人、表达式、外部系统回调的步骤只读。不能加减步骤、不能改会签和时限:骨架是
* 导入的图,要改回画布
*/
function FreeformPeople({ ctx, rows, note }: { ctx: CardCtx; rows: DerivedPerson[]; note?: string }) {
const spec = ctx.bp.spec
const itemOf = (row: DerivedPerson): BpItem | null => {
if (row.kind === 'reconciler') return spec.writeback?.reconciler ?? UNSET
if (row.kind !== 'slot') return null
return spec.people.find((s) => s.id === row.slot)?.who ?? UNSET
}
const items = rows.flatMap((r): [string, BpItem][] => {
const item = itemOf(r)
return r.path && item ? [[r.path, item]] : []
})
const paths = new Set(items.map(([p]) => p))
const issues = (ctx.bp.issues ?? []).filter((i) => i.path === '/people' || (i.path != null && paths.has(i.path)))
return (
<Card card="people" note={note} issues={issues} status={cardStatus(ctx, 'people', items)}>
<p className="text-2xs leading-relaxed text-dim" data-bp-freeform-people={rows.length}>{BP_EDIT_TEXT.freeformPeopleHint}</p>
{rows.length === 0 && <p className="text-2xs text-faint">{BP_EDIT_TEXT.freeformPeopleEmpty}</p>}
{rows.map((row, i) => {
const item = itemOf(row)
return (
<div key={`${row.kind}-${row.slot ?? i}`} className="rounded-md border p-2" data-bp-derived={row.kind}
data-bp-slot={row.slot ?? undefined}>
<div className="mb-1 text-xs font-medium text-fg">{row.label}</div>
<p className="mb-1 text-2xs leading-relaxed text-dim">{row.detail}</p>
{row.path && item
? <ItemRow ctx={ctx} path={row.path} item={item} label={BP_EDIT_TEXT.freeformWho} kind="grantees" />
: <p className="text-2xs text-faint">{BP_EDIT_TEXT.freeformReadOnly}</p>}
</div>
)
})}
</Card>
)
}
function Card({ card, status, note, actions, issues, children }: {
card: CardKey; status: ItemStatus | null; note?: string; actions?: ReactNode; issues?: PlainIssue[]; children: ReactNode
}) {
+17 -3
View File
@@ -3,7 +3,7 @@ import clsx from 'clsx'
import type { CheckResult, ImportAcceptance, ManifestOut } from '../../types'
import { CopyButton, Notice } from '../../components/ui'
import { formatBytes, formatCost, formatDateTime, formatTokens } from '../../lib/format'
import { RAW_STATE_LABEL, RECIPE_ORIGIN_LABEL, RECIPE_TEXT, VERSIONS_TEXT as VT } from '../../lib/terms'
import { RAW_STATE_LABEL, RECIPE_ORIGIN_LABEL, RECIPE_TEXT, SIGNER_TEXT, VERSIONS_TEXT as VT } from '../../lib/terms'
import { CheckStatusChip } from './ImportReceipt'
import { ReceiptSummary } from './ReceiptBlocks'
@@ -79,7 +79,11 @@ export function ManifestBody({ m, fileName, rawState, recipeSeq }: {
{short(c.file?.raw_sha256) && <span className="mono text-dim">{VT.sha(short(c.file?.raw_sha256))}</span>}
{rawState != null && <span className="chip">{RAW_STATE_LABEL[rawState] ?? rawState}</span>}
</div>
{c.signed_by?.name && <div className="text-2xs text-faint">{VT.signedBy(c.signed_by.name)}</div>}
{c.signed_by?.name && (
<div className="text-2xs text-faint" data-manifest-signer={c.signed_by.verified ? 'verified' : 'self'}>
{signerText(c.signed_by.name, !!c.signed_by.verified)}
</div>
)}
</Block>
<Block id="recipe" title={B.recipe}>
@@ -146,7 +150,9 @@ export function ManifestBody({ m, fileName, rawState, recipeSeq }: {
</span>
</div>
<div className="flex flex-wrap gap-x-2 text-2xs text-faint">
<span>{VT.signedBy(a.signed_by || VT.unsigned)}</span>
{/* 接受理由由提交这一期的人写,署名同清单的 signed_by:是不是登录身份按清单里记下的说 */}
<span>{a.signed_by ? signerText(a.signed_by, !!c.signed_by?.verified && a.signed_by === c.signed_by.name)
: VT.signedBy(VT.unsigned)}</span>
{a.at && <span className="tnum">{formatDateTime(a.at)}</span>}
</div>
</li>
@@ -235,3 +241,11 @@ function RawJson({ summary, value, attr }: { summary: string; value: unknown; at
</details>
)
}
/**
* 留痕里的署名怎么说:按记下的「是否认证」写「登录身份:x」或「署名(未认证):x」(05-已知遗留 (c)),和确认框里那一行
* (VersionsDialog 的 signerLine)同一套说法。旧清单记的是未认证,照记下的说
*/
export function signerText(name: string, verified: boolean): string {
return verified ? SIGNER_TEXT.signedIn(name) : VT.signedBy(name)
}
+16 -8
View File
@@ -14,7 +14,7 @@ import { signerNow } from '../../store/auth'
import { humanizeError } from '../../lib/errors'
import { formatBytes, formatDateTime, formatTime, parseServerTime } from '../../lib/format'
import { RAW_STATE_LABEL, SIGNER_TEXT, VERSIONS_TEXT as VT } from '../../lib/terms'
import { ManifestBody } from './ManifestBody'
import { ManifestBody, signerText } from './ManifestBody'
// ===========================================================================
// 版本页(数据源卡片上的「版本」,P3-SPEC 7.8):当前版本的各期、历史版本、全部导入记录三个页签,
@@ -447,10 +447,10 @@ function CurrentTab({ cur, recOf, busy, onManifest, onRemove, onRevoke, onPurge
{acceptN > 0 && (
<details className="text-xs" data-part-acceptances={acceptN}>
<summary className="cursor-pointer select-none text-dim hover:text-fg">{VT.acceptCount(acceptN)}</summary>
<AcceptanceList items={accepted} className="mt-1.5" />
<AcceptanceList items={accepted} className="mt-1.5" signer={rec} />
</details>
)}
{rec?.signed_by && <div className="text-2xs text-faint">{VT.signedBy(rec.signed_by)}</div>}
{rec?.signed_by && <div className="text-2xs text-faint">{signerText(rec.signed_by, !!rec.signed_by_verified)}</div>}
<div className="flex flex-wrap items-center gap-1.5">
<button type="button" className="btn btn-xs" data-manifest-open={p.import_id} disabled={!rec}
onClick={() => rec && onManifest(rec)}>
@@ -522,8 +522,12 @@ function TableRows({ rows, label, attr }: { rows: Record<string, number> | null
)
}
/** 接受逐条:种类、核对、理由、署名(未认证)、时间 */
function AcceptanceList({ items, className }: { items: ImportAcceptance[]; className?: string }) {
/**
* 接受逐条:种类、核对、理由、署名、时间。理由由提交这一期的人写:署名和导入记录的一样时,是不是登录身份按记录(清单里记下的)说
*/
function AcceptanceList({ items, className, signer }: {
items: ImportAcceptance[]; className?: string; signer?: { signed_by: string | null; signed_by_verified?: boolean } | null
}) {
if (!items.length) return null
return (
<ul className={clsx('space-y-1', className)}>
@@ -534,7 +538,9 @@ function AcceptanceList({ items, className }: { items: ImportAcceptance[]; class
<span className="min-w-0 flex-1 break-words">{VT.acceptRow(a.check_id, a.reason)}</span>
</div>
<div className="flex flex-wrap gap-x-2 text-2xs text-faint">
<span>{VT.signedBy(a.signed_by || VT.unsigned)}</span>
<span>{a.signed_by
? signerText(a.signed_by, !!signer?.signed_by_verified && a.signed_by === signer.signed_by)
: VT.signedBy(VT.unsigned)}</span>
{a.at && <span className="tnum">{formatDateTime(a.at)}</span>}
</div>
</li>
@@ -654,10 +660,12 @@ function ImportsTab({ imports, busy, onManifest, onPurge }: {
<div className="flex flex-wrap gap-x-3 gap-y-1 text-2xs text-faint">
<span>{r.recipe_seq != null ? VT.recipeSeq(r.recipe_seq) : r.recipe_id ? '' : VT.simpleImport}</span>
{r.created_at && <span className="tnum">{formatDateTime(r.created_at)}</span>}
{r.signed_by && <span>{VT.signedBy(r.signed_by)}</span>}
{r.signed_by && <span data-record-signer={r.signed_by_verified ? 'verified' : 'self'}>
{signerText(r.signed_by, !!r.signed_by_verified)}
</span>}
</div>
<TableRows rows={r.rows} attr="data-record-rows" />
<AcceptanceList items={r.acceptances ?? []} />
<AcceptanceList items={r.acceptances ?? []} signer={r} />
<div className="flex flex-wrap items-center gap-1.5">
<button type="button" className="btn btn-xs" data-manifest-open={r.id} onClick={() => onManifest(r)}>
<FileText size={11} aria-hidden /> {VT.manifest}
+5 -2
View File
@@ -205,7 +205,7 @@ export function RunDetailView({ runId, onChange, onDeleted }: {
const aimed = focus && !goneFromCanvas(focus) ? focus : null
const canvasHref = hrefFor(aimed)
// 还在往前走的叫「打开」(接着看实时的、去处理),停下的叫「回放」
const replayable = code === 'succeeded' || code === 'failed' || code === 'cancelled'
const replayable = code === 'succeeded' || code === 'failed' || code === 'cancelled' || code === 'rejected'
const dup = !!run.workflow_id && duplicateNames(workflows.map((w) => ({ id: w.id, name: w.name }))).has(run.workflow_name)
// ---- 动作 ----
@@ -730,7 +730,10 @@ export function RunDetailView({ runId, onChange, onDeleted }: {
/** 事件之外的事实(查到的状态、有没有审批)和事件推出的相位合成一个显示码 */
function displayCode(run: Run, phase: RunPhase, pending: boolean | undefined): StatusCode {
switch (phase) {
case 'running': case 'queued': case 'waiting': case 'succeeded': case 'failed': case 'cancelled':
case 'cancelled':
// 被驳回只看服务端的 end_reason(05-已知遗留 (a))
return run.end_reason === 'rejected' ? 'rejected' : 'cancelled'
case 'running': case 'queued': case 'waiting': case 'succeeded': case 'failed':
return phase
case 'suspended':
// 后端写的是 interrupted:服务重启打断、没有审批,叫「已挂起 · 可续跑」
+9 -2
View File
@@ -7,8 +7,8 @@ import {
formatCost, formatDateTime, formatDay, formatSpan, formatTime, formatTokens, parseServerTime, shortId,
} from '../../lib/format'
import {
ORIGIN_LABEL, ORIGIN_TEXT, RUN_CLASS_LABEL, SYSTEM_RUNS_TEXT, TASK_KIND_LABEL, TASK_LOG_TEXT, UNSAVED_HINT, UNSAVED_NAME, isUnsaved,
originLabel, runName,
ORIGIN_LABEL, ORIGIN_TEXT, REJECTED_TEXT, RUN_CLASS_LABEL, SYSTEM_RUNS_TEXT, TASK_KIND_LABEL, TASK_LOG_TEXT, UNSAVED_HINT,
UNSAVED_NAME, isUnsaved, originLabel, runName,
} from '../../lib/terms'
import { summarizeRun } from '../../run/decode'
import type { Approval, Run, Workflow } from '../../types'
@@ -490,6 +490,13 @@ function RowContext({ run, code, approval, now }: {
const reason = cancelReason(run.error)
return <div className={clsx(line, 'text-faint')} title={run.error ?? undefined}>已取消{reason ? ` · ${reason}` : ''}</div>
}
case 'rejected':
// 人的驳回(end_reason=rejected):报错原文就是给人看的那一句(「「付款」未确认(被驳回),没有发送:…」)
return (
<div className={clsx(line, 'text-faint')} title={run.error ?? undefined} data-run-reason="rejected">
{REJECTED_TEXT.title}{run.error ? ` · ${run.error}` : ''}
</div>
)
default: {
const summary = summarizeRun(run.input, run.output)
return summary
+5 -1
View File
@@ -10,7 +10,7 @@ import { type StatusCode } from '../../lib/status'
import { isExecuting, liveAt, project, type Projection, type RunPhase, type Trace } from '../../run/trace'
import { useRunClock } from '../../run/useRunClock'
import type { Approval, Run } from '../../types'
import { BUNDLE_TEXT, COST_TEXT, UNSAVED_HINT, isUnsaved, runCostText, runName } from '../../lib/terms'
import { BUNDLE_TEXT, COST_TEXT, REJECTED_TEXT, UNSAVED_HINT, isUnsaved, runCostText, runName } from '../../lib/terms'
import {
LONG_WAIT_MS, ageMs, cancelReason, runScope, runTiming, type RunTiming,
} from './model'
@@ -116,6 +116,10 @@ export function Telemetry({ run, trace, phase, code, streaming, pending, labelOf
sub = '断点完好,可继续运行'
} else if (code === 'cancelled') {
sub = cancelNote(run.error, cancelled)
} else if (code === 'rejected') {
// 谁在哪一步驳回、备注:和时间线那一行同一句(REJECTED_TEXT.sub)。run.cancelled 还没取到时按驳回的那一步说
sub = cancelled?.reason === 'rejected' ? REJECTED_TEXT.sub(cancelled)
: REJECTED_TEXT.sub({ label: labelOf(run.error_node_id) })
}
const nodesTotal = proj?.nodesTotal ?? 0
+3 -1
View File
@@ -11,7 +11,7 @@ import { explainRunError } from '../../lib/explain'
import {
NONE, formatCost, formatDateTime, formatNumber, formatOffset, formatSpan, formatTokens, shortId,
} from '../../lib/format'
import { COST_TEXT, runClassLabel, nodeTypeLabel, runCostText } from '../../lib/terms'
import { COST_TEXT, REJECTED_TEXT, runClassLabel, nodeTypeLabel, runCostText } from '../../lib/terms'
import { topology, type GraphLike } from '../../run/derive'
import {
isActivePhase, isSettled, liveAt, project, type NodeState, type Projection, type RunPhase, type Trace,
@@ -449,6 +449,7 @@ function momentsOf(
const failed = trace.phase === 'failed' ? trace.failedNodeId : undefined
const why = trace.phase === 'failed'
? explainRunError((failed && trace.nodes[failed]?.error) || error).title
: code === 'rejected' ? error?.trim() || undefined
: trace.phase === 'cancelled' ? cancelReason(error) ?? undefined
: trace.phase === 'suspended' ? error?.trim() || undefined : undefined
out.push({
@@ -458,6 +459,7 @@ function momentsOf(
text: trace.phase === 'succeeded' ? '运行完成'
: failed ? `失败于${name(failed)}`
: trace.phase === 'failed' ? '运行失败'
: code === 'rejected' ? REJECTED_TEXT.title
: trace.phase === 'cancelled' ? '运行取消' : '运行挂起',
sub: why,
})
+6 -4
View File
@@ -49,8 +49,8 @@ export const SEGMENT_CODES: StatusCode[] = RUN_STATUS_ORDER
* 打断后没有审批——要看待审批列表才分得开。approvals 还没加载时传 null,按
* 等待审批算(最常见的来源),不会在加载的那一瞬间闪成「已挂起」。
*/
export function runCode(run: Pick<Run, 'id' | 'status'>, approvals: Approval[] | null): StatusCode {
if (run.status !== 'interrupted') return resolveStatus(run.status)
export function runCode(run: Pick<Run, 'id' | 'status' | 'end_reason'>, approvals: Approval[] | null): StatusCode {
if (run.status !== 'interrupted') return resolveStatus(run.status, { endReason: run.end_reason })
return resolveStatus(run.status, {
pendingApproval: approvals == null ? undefined : hasPendingApproval(approvals, run.id),
})
@@ -93,6 +93,8 @@ for (const [word, codes] of [
['挂起', ['held']], ['中断', ['held']], ['已中断', ['held']], ['可继续运行', ['held']],
['interrupted', ['waiting', 'held']],
['取消', ['cancelled']], ['canceled', ['cancelled']],
// 被驳回(审批人的决定,不是失败):屏幕上写「被驳回」,人也会只搜「驳回」
['驳回', ['rejected']], ['已驳回', ['rejected']],
['出错', ['failed']], ['报错', ['failed']], ['error', ['failed']],
['排队', ['queued']], ['执行中', ['running']], ['进行中', ['running']],
] as [string, StatusCode[]][]) addWord(word, codes)
@@ -217,7 +219,7 @@ export type ShapeKind = 'active' | 'wait' | 'other' | 'unknown' | 'live'
export interface RunShape {
/** 各段占墙钟的比例,加起来是 1;空数组 = 连墙钟都不知道 */
segs: { kind: ShapeKind; frac: number; open?: boolean }[]
/** 收在哪种结局上:只给要注意的几种,已完成不标 */
/** 收在哪种结局上:只给要注意的几种,已完成不标。被驳回和已取消同一个结束标记(同 lib/status 的剪影和颜色) */
end: 'failed' | 'cancelled' | 'suspended' | null
title: string
}
@@ -266,7 +268,7 @@ export function runShape(
}
}
const end: RunShape['end'] = code === 'failed' ? 'failed' : code === 'cancelled' ? 'cancelled'
const end: RunShape['end'] = code === 'failed' ? 'failed' : code === 'cancelled' || code === 'rejected' ? 'cancelled'
: code === 'held' || code === 'suspended' ? 'suspended' : null
if (t.wallMs == null || t.wallMs <= 0) {
return { segs: [], end, title: t.activeMs != null ? timingTitle(t) : '没有时长记录' }
+5 -2
View File
@@ -152,8 +152,11 @@ export function useUnlistedRuns(filters: ListFilters, epoch: number, enabled: bo
// 计数
// -------------------------------------------------------------------------
/** 数的是"需要看一眼"的几类;已完成不数——它是常态,数字只会分散注意力 */
const COUNTED: StatusCode[] = ['running', 'queued', 'waiting', 'held', 'failed', 'cancelled']
/**
* 数的是"需要看一眼"的几类;已完成不数——它是常态,数字只会分散注意力。被驳回以前记成失败、算在「失败」里,现在单独
* 一类,不数就哪个计数里都没有它
*/
const COUNTED: StatusCode[] = ['running', 'queued', 'waiting', 'held', 'failed', 'cancelled', 'rejected']
const COUNT_LIMIT = 200
export interface StatusCounts {
+6 -2
View File
@@ -6,6 +6,7 @@ import {
} from '../../components/ui'
import { formatDateTime } from '../../lib/format'
import { NOTIFY_TEXT as T, SETTINGS_ROLE_TEXT } from '../../lib/terms'
import { NOTIFY_PERSONAL_EVENT_LABEL } from '../../lib/termsApp'
import { useAtLeast } from '../../store/auth'
import type { NotifyChannelRow, NotifyEventRow } from '../../typesApp'
@@ -18,6 +19,9 @@ import type { NotifyChannelRow, NotifyEventRow } from '../../typesApp'
const FORMATS = ['generic', 'feishu', 'wecom', 'dingtalk'] as const
const EVENTS = Object.keys(T.eventLabel)
/** 事件在这个范围的渠道上怎么叫:个人渠道的实例结束只推自己发起的,叫「我发起的实例完成 / 失败」 */
const eventLabel = (event: string, scope: string): string =>
(scope === 'user' ? NOTIFY_PERSONAL_EVENT_LABEL[event] : undefined) ?? T.eventLabel[event] ?? event
export function NotifyTab() {
const builder = useAtLeast('builder')
@@ -86,7 +90,7 @@ export function NotifyTab() {
</div>
<div className="truncate text-2xs text-faint">
<span className="mono">{row.url_host}</span>
{row.events.length > 0 && ` · ${row.events.map((e) => T.eventLabel[e] ?? e).join('、')}`}
{row.events.length > 0 && ` · ${row.events.map((e) => eventLabel(e, row.scope)).join('、')}`}
</div>
</div>
<label className="flex items-center gap-1 text-2xs">
@@ -218,7 +222,7 @@ function ChannelEditor({ row, onClose, onSaved }: {
<label key={ev} className="flex items-center gap-1.5 text-xs" data-notify-event={ev}>
<input type="checkbox" className="accent-[var(--accent)]" checked={form.events.includes(ev)}
onChange={(e) => setForm({ ...form, events: e.target.checked ? [...form.events, ev] : form.events.filter((x) => x !== ev) })} />
{T.eventLabel[ev]}
{eventLabel(ev, form.scope)}
</label>
))}
</div>
+28 -13
View File
@@ -8,7 +8,7 @@ import { confirmDialog, Kbd, Spinner, StatusBadge, toast } from '../components/u
import { formatCost, formatDuration, formatLapse, formatOffset, formatSpan, formatTokens, NONE } from '../lib/format'
import { isTypingTarget, matchShortcut } from '../lib/keys'
import { statusMeta, STATUS, type StatusCode } from '../lib/status'
import { COST_TEXT, issuanceLabel, runClassLabel, runCostText } from '../lib/terms'
import { COST_TEXT, REJECTED_TEXT, issuanceLabel, runClassLabel, runCostText } from '../lib/terms'
import { lastStampOf, projectSettled, useDock, waitedMs } from '../canvas/RunTimeline'
import { structureSig, useStudio } from '../store/studio'
import type { RunEvent } from '../types'
@@ -111,29 +111,35 @@ export function phaseLabel(phase: RunPhase): string {
/**
* 这次运行是怎么取消的:run.cancelled 带着谁放弃的(actor)和一句说明(放弃等审批、
* 挂起的运行时才有,如「放弃了这次运行,1 条待审批一并关闭」)。按事件数组缓存
* 挂起的运行时才有,如「放弃了这次运行,1 条待审批一并关闭」)。按事件数组缓存。
*
* 被人驳回结束的也是 run.cancelled(reason=rejected,05-已知遗留 (a)):rejected 为真,note 写谁在哪一步驳回、备注
* (REJECTED_TEXT.sub,同时间线那一行)。以前一律写「张工 取消了本次运行」,驳回的人并没有停过它
*/
const cancelCache = new WeakMap<RunEvent[], string>()
function cancelNote(events: RunEvent[]): string {
const cancelCache = new WeakMap<RunEvent[], { note: string; rejected: boolean }>()
function cancelNote(events: RunEvent[]): { note: string; rejected: boolean } {
const hit = cancelCache.get(events)
if (hit != null) return hit
let note = ''
let out = { note: '', rejected: false }
for (let i = events.length - 1; i >= 0; i -= 1) {
const e = events[i]
if (!String(e.type).startsWith('run.')) continue
if (e.type === 'run.cancelled') {
if (e.type === 'run.cancelled' && e.data?.reason === 'rejected') {
out = { note: REJECTED_TEXT.sub(e.data), rejected: true }
} else if (e.type === 'run.cancelled') {
const who = typeof e.data?.actor === 'string' ? e.data.actor.trim() : ''
const what = typeof e.data?.message === 'string' ? e.data.message.trim() : ''
note = what ? `${who ? `${who} ` : ''}${what}` : who ? `${who} 取消了本次运行` : ''
out = { note: what ? `${who ? `${who} ` : ''}${what}` : who ? `${who} 取消了本次运行` : '', rejected: false }
}
break
}
cancelCache.set(events, note)
return note
cancelCache.set(events, out)
return out
}
function headlineOf(t: Trace, phase: RunPhase, states: Record<string, NodeState>, at: number,
label: (id: string) => string, errorText: string | null | undefined, cancelled = ''): string {
label: (id: string) => string, errorText: string | null | undefined, cancelled = '',
rejected = false): string {
const running = Object.keys(states).filter((id) => states[id] === 'running')
switch (phase) {
case 'queued':
@@ -167,6 +173,8 @@ function headlineOf(t: Trace, phase: RunPhase, states: Record<string, NodeState>
case 'succeeded':
return t.issuance?.tier ? `运行完成 · ${issuanceLabel(t.issuance.tier)}` : '运行完成'
case 'cancelled': {
// 被驳回:那一句已经写了在哪一步(「张工 驳回了「付款」:…」),不再接「停在「付款」」
if (rejected) return cancelled || REJECTED_TEXT.title
const stopped = Object.keys(states).filter((id) => states[id] === 'cancelled')
const where = stopped.length ? `停在「${label(stopped[0])}」` : '已取消'
return cancelled ? `${cancelled} · ${where}` : where
@@ -187,7 +195,9 @@ export function useRunGlance(active: boolean): RunGlance {
const runError = useStudio((s) => s.run?.error)
const nodes = useStudio((s) => s.nodes)
const edges = useStudio((s) => s.edges)
const cancelled = useStudio((s) => (s.runPhase === 'cancelled' ? cancelNote(s.events) : ''))
const ending = useStudio((s) => (s.runPhase === 'cancelled' ? cancelNote(s.events) : null))
// 被驳回只看服务端说的(run.cancelled 的 reason,或运行记录的 end_reason),不按报错原文猜
const runRejected = useStudio((s) => s.run?.end_reason === 'rejected')
const limitMs = useRunLimit()
const ticking = active && replayAt == null && isActivePhase(phaseLive)
const now = useRunClock(ticking)
@@ -229,6 +239,11 @@ export function useRunGlance(active: boolean): RunGlance {
const remainingMs = limitMs != null && phase === 'running' && drive && drive[1] == null
? Math.max(0, limitMs - (at - drive[0])) : null
// 结局是被驳回:只在没拖游标、停在最后时这么说(回放到中途说的是那一刻的相位)
const rejectedEnd = replayAt == null && phase === 'cancelled' && (!!ending?.rejected || runRejected)
const cancelled = ending?.note ?? ''
const code: StatusCode = rejectedEnd ? 'rejected' : phase
const attention: Attention[] = []
for (const c of cells) {
if (c.state !== 'failed') continue
@@ -251,9 +266,9 @@ export function useRunGlance(active: boolean): RunGlance {
}
return {
phase, code: phase, label: phaseLabel(phase), replay: replayAt != null, at,
phase, code, label: code === 'rejected' ? STATUS.rejected.label : phaseLabel(phase), replay: replayAt != null, at,
elapsedMs: proj.elapsedMs, activeMs: proj.activeMs, waitMs: proj.waitMs,
headline: headlineOf(trace, phase, states, at, label, runError, replayAt == null ? cancelled : ''),
headline: headlineOf(trace, phase, states, at, label, runError, replayAt == null ? cancelled : '', rejectedEnd),
executing: phase === 'running' && cells.some((c) => c.state === 'running' && !trace.nodes[c.id]?.looping),
cells, done, visited, parallelNow: proj.parallelNow, series: trace.parallelSeries,
tokens, cost, unpriced, remainingMs, limitMs, attention,
+7 -1
View File
@@ -6,7 +6,7 @@ import {
ABSENCE_CLAIM_TEXT, ACTION_CONFIRM_TEXT, ACTION_ENV_LABEL, ACTION_LOG_TEXT, CATALOG_DRIFT_TEXT, CATALOG_PATCH_TEXT, COPILOT_CONTEXT_TEXT, JUDGE_TEXT, LOOK_TEXT, MERGE_TEXT,
ORIGIN_TEXT, RUN_SQL_CHECK_TEXT, SQL_CHECK_TEXT, TASK_KIND_LABEL, TASK_LOG_TEXT, TASK_STATUS_LABEL, TASK_TEXT, TYPE_LABEL, originLabel,
CATALOG_TABLE_FIELD_LABEL, CHALLENGE_TEXT, DUAL_CHECK_TEXT, INQUIRY_TEXT, JUDGE_TRUNCATED_TEXT, MASKED_CELL_TEXT, NODE_TYPE_LABEL,
VERIFY_TRUNCATED_TEXT, BP_OP_TEXT, TEMPLATE_LABEL, bpPathText, FILE_TEXT,
VERIFY_TRUNCATED_TEXT, BP_OP_TEXT, TEMPLATE_LABEL, bpPathText, FILE_TEXT, REJECTED_TEXT,
claimTally,
evidenceTally, issuanceLabel, nodeTypeLabel,
} from '../lib/terms'
@@ -2673,6 +2673,12 @@ export function decodeRun(events: RunEvent[], final?: RunFinal, opts?: DecodeOpt
// 用户主动停下的,不是出错:收成中性的"已取消",不画红色的失败。谁停的、放弃等
// 审批时一并关了几条,写在副标题上——多人用时「怎么没了」得有个交代
settle(endingOf(event, awaiting)!)
if (d.reason === 'rejected') {
// 人的驳回(05-已知遗留 (a)):同样不是出错,标题写「被驳回」,副标题写谁在哪一步驳回、备注
out.push({ id: `rc-${seq}`, seq, kind: 'lifecycle', status: 'cancelled', title: REJECTED_TEXT.title,
sub: REJECTED_TEXT.sub(d), ...(d.node_id ? { nodeId: String(d.node_id) } : {}) })
break
}
// 说法和画布胶囊的那一句一致:「张工 放弃了这次运行,1 条待审批一并关闭」
const who = typeof d.actor === 'string' && d.actor.trim() ? d.actor.trim() : ''
const said = String(d.message ?? '').trim()
+32 -6
View File
@@ -2,7 +2,7 @@ import { create } from 'zustand'
import { ApiError, api, streamCopilot, streamRun } from '../api/client'
import type { CopilotOp, FixKind, RunFinal } from '../run/decode'
import { copilotContext, copilotLook, decodeRun, looksOf } from '../run/decode'
import { CHAT_BLUEPRINT_TEXT, LOOK_TEXT } from '../lib/terms'
import { CHAT_BLUEPRINT_TEXT, LOOK_TEXT, REJECTED_TEXT } from '../lib/terms'
import type { LookEvent } from '../typesApp'
import { errorMessage, humanizeError, isNetworkError } from '../lib/errors'
import { guardReview, hasEvidence } from '../lib/evidence'
@@ -87,6 +87,11 @@ export interface Failure {
fixFirst?: true
}
/** 被驳回的那一句:事件流里来的按 run.cancelled 的谁、哪一步、备注拼(REJECTED_TEXT.sub);核对状态时只有报错原文 */
export interface Rejected {
sub: string
}
/** 限定这一问只查哪些数据源。名字跟着存:库删了之后,这一轮查的是谁还得说得出来 */
export interface ScopeSource {
id: string
@@ -101,7 +106,8 @@ export interface ScopeSource {
*/
export interface Attempt {
n: number
outcome: 'failed' | 'cancelled' | 'suspended' | 'unusable' | 'partial' | 'done'
/** rejected:那一次的运行被人驳回结束(不是手动停止,也不是故障)。老的留档里被驳回的那次记的是 cancelled,不改写 */
outcome: 'failed' | 'cancelled' | 'rejected' | 'suspended' | 'unusable' | 'partial' | 'done'
summary: string
detail?: string
runId?: string | null
@@ -127,6 +133,8 @@ export interface TurnMeta {
issuance?: Record<string, any>
noQuery?: boolean
outcome?: 'cancelled' | 'suspended'
/** 运行被人驳回结束(outcome 是 cancelled):副标题那一句,刷新之后照样写「被驳回」,不退回成「你已停止本轮」 */
rejected?: Rejected
failure?: Failure
attempts?: Attempt[]
/** 这一轮从开问到交付的墙钟毫秒 */
@@ -206,6 +214,11 @@ export interface ChatTurn {
/** 一行错误文案(兼容老数据和流式头部)。结构化的在 failure 里 */
error: string
failure?: Failure | null
/**
* 这一轮的运行被人驳回结束(服务端 cancelled + end_reason=rejected,05-已知遗留 (a))。phase 照旧是 cancelled(不是故障、
* 不给继续运行),说法另写「被驳回」和谁、在哪一步、备注
*/
rejected?: Rejected | null
startedAt: number
/** 交付、失败、取消或中断的时刻。计时器停在这里 */
endedAt?: number
@@ -468,6 +481,7 @@ function buildMeta(t: ChatTurn): TurnMeta {
issuance: slimIssuance(t.output?._issuance ?? t.rawOutput?._issuance) ?? t.meta?.issuance,
noQuery: t.noQuery || undefined,
outcome: t.phase === 'cancelled' ? 'cancelled' : t.phase === 'suspended' ? 'suspended' : undefined,
rejected: t.phase === 'cancelled' && t.rejected ? t.rejected : undefined,
failure: t.failure ?? undefined,
attempts: t.attempts?.length ? t.attempts : undefined,
ms: t.endedAt ? t.endedAt - t.startedAt : t.meta?.ms,
@@ -754,6 +768,7 @@ function restoreTurn(t: ConversationTurn): ChatTurn {
output,
error: phase === 'error' ? (failure ? lineOf(failure) : t.status === 'running' ? buildInterrupted.title : '') : '',
failure: phase === 'error' ? (t.status === 'running' ? buildInterrupted : failure) : phase === 'suspended' ? SUSPENDED : null,
rejected: phase === 'cancelled' ? meta?.rejected ?? null : null,
startedAt: Date.parse(t.created_at ?? '') || Date.now(),
endedAt: meta?.ms != null ? (Date.parse(t.created_at ?? '') || 0) + meta.ms : undefined,
lastSeq: 0,
@@ -1121,7 +1136,10 @@ export const useChat = create<ChatState>((set, get) => ({
}
if (run.status === 'cancelled') {
if (cur.phase !== 'done' && cur.phase !== 'cancelled') {
conclude({ phase: 'cancelled', status: PHASE_TEXT.cancelled, failure: null, error: '' }, '已取消')
// 被驳回只看服务端的 end_reason:核对时手上只有运行记录,副标题用报错原文(它就是给人看的那句)
const rejected = run.end_reason === 'rejected' ? { sub: run.error || REJECTED_TEXT.title } : null
conclude({ phase: 'cancelled', status: rejected ? REJECTED_TEXT.title : PHASE_TEXT.cancelled, failure: null,
error: '', rejected }, '已取消')
}
return
}
@@ -1242,6 +1260,11 @@ function attemptOf(t: ChatTurn): Attempt {
answer: answer && answer.length > ATTEMPT_ANSWER_CAP ? answer.slice(0, ATTEMPT_ANSWER_CAP) + '…' : answer,
}
const signals = (t.review?.signals ?? []).map((s) => s.detail).join('\n') || undefined
// 被驳回的那次照实写谁在哪一步驳回(以前写「已手动停止」,用户其实没有停过它)
if (t.phase === 'cancelled' && t.rejected) {
const sub = t.rejected.sub && t.rejected.sub !== REJECTED_TEXT.title ? `:${t.rejected.sub}` : ''
return { ...base, outcome: 'rejected', summary: `${REJECTED_TEXT.title}${sub}` }
}
if (t.phase === 'cancelled') return { ...base, outcome: 'cancelled', summary: '已手动停止' }
if (t.phase === 'suspended') return { ...base, outcome: 'suspended', summary: '服务重启,运行中断' }
if (t.phase === 'error' || t.failure) {
@@ -1776,15 +1799,18 @@ function watch(
// 服务在关停:这一轮会停在断点上。停在审批上的仍然是在等人
if (d.code === 'server_shutdown' && current()?.phase !== 'waiting') suspend()
break
case 'run.cancelled':
case 'run.cancelled': {
ended = true
batch.now()
// 人的驳回(reason=rejected)也收成 cancelled:不是故障、不给继续运行,说法写「被驳回」和谁、哪一步、备注
const rejected = d.reason === 'rejected' ? { sub: REJECTED_TEXT.sub(d) } : null
patch(() => ({
phase: 'cancelled', status: PHASE_TEXT.cancelled, cancel: null, endedAt: Date.now(),
runStatus: 'cancelled', final: { status: 'cancelled' },
phase: 'cancelled', status: rejected ? REJECTED_TEXT.title : PHASE_TEXT.cancelled, cancel: null,
endedAt: Date.now(), runStatus: 'cancelled', final: { status: 'cancelled' }, rejected,
}))
void flow.persist({ status: 'error', error: '已取消' })
break
}
case 'run.failed': {
ended = true
batch.now()
+15 -3
View File
@@ -1260,6 +1260,8 @@ export interface ImportRecord {
period_start: string | null
period_end: string | null
signed_by: string | null
/** 署名是不是认证过的身份:按这一期导入清单里记下的(05-已知遗留 (c)),旧清单记的是 false。老后端不给 */
signed_by_verified?: boolean
/** 接受的条数 */
overrides: number
waivers: number
@@ -1582,10 +1584,10 @@ export interface Conversation {
/** 列表里的副标题,让人一眼认出是哪次聊天 */
last_question: string
/**
* 最后一轮停在哪。左栏对这次没打开过的会话也能标出运行中、待审批、失败。
* 没有轮次时为 null;老后端不给
* 最后一轮停在哪。左栏对这次没打开过的会话也能标出运行中、待审批、失败、被驳回(rejected:运行被审批人驳回结束,
* 服务端 cancelled + end_reason=rejected)。没有轮次时为 null;老后端不给
*/
last_status?: 'running' | 'waiting' | 'error' | 'cancelled' | 'suspended' | 'done' | null
last_status?: 'running' | 'waiting' | 'error' | 'cancelled' | 'rejected' | 'suspended' | 'done' | null
/** 最后一轮的运行。建图阶段就断了的没有 */
last_run_id?: string | null
}
@@ -4482,3 +4484,13 @@ export interface DataSourceName {
kind?: string
enabled?: boolean
}
// ---------------------------------------------------------------------------
// 驳回 ≠ 失败(docs/design/next-round/05-已知遗留.md (a),总方案 X9)
/** 运行为什么结束在 cancelled(服务端 Run.end_reason):rejected 人工驳回,stopped 手动停止。其余终态、老运行为空 */
export type RunEndReason = 'rejected' | 'stopped'
export interface Run {
end_reason?: RunEndReason | null
}
+27 -2
View File
@@ -54,6 +54,25 @@ export interface Directory {
groups: { name: string; label: string }[]
}
/**
* 使用者选人的候选从哪个池取(GET /api/directory/candidates,05-已知遗留 (b)):form 是表单里的选人控件(入口表单带 app_id、
* entry,待办表单带 task_id,都带 field),review 是个人应用提交审核
*/
export type CandidateSource =
| { purpose: 'form'; app_id?: string; entry?: string; task_id?: string; field: string }
| { purpose: 'review' }
/**
* 候选池给的那一份:只有用户名和显示名(不给是否停用、角色、邮箱,停用的不列)。needs_query:应用授权给了所有人,
* 不输入开头不列;truncated:符合的超过了上限(最多 50 位)
*/
export interface Candidates {
users: { username: string; display_name: string }[]
groups: { name: string; label: string }[]
truncated: boolean
needs_query?: boolean
}
export interface AuditRow {
id: string
at: string
@@ -100,6 +119,11 @@ export interface FormField {
'x-widget'?: FormWidget
/** 文件控件的限制,只配 x-widget: file */
'x-file'?: FileLimits
/**
* 选人控件的候选池,只配 x-widget: principal:app(能用这个应用的人,缺省)、group:<组>、slot:<岗位>
* (服务端 auth/directory.pool_problem,05-已知遗留 (b))
*/
'x-principal'?: { pool: string }
}
export interface FormSchema {
@@ -113,11 +137,12 @@ export interface FormSchema {
/**
* 前后端同一种错误格式(服务端 apps/spec.FORM_ERROR_CODES)。file:文件控件的值不是上传后拿回的引用、类型或大小不合
* x-file 的限制,或提交时核对引用没过(不是这个人传的、已经用过)
* x-file 的限制,或提交时核对引用没过(不是这个人传的、已经用过);principal:开了登录时选人控件的值不在候选池里
* (服务端 auth/directory.principal_errors,05-已知遗留 (b))
*/
export interface FormError {
path: string
code: 'required' | 'type' | 'enum' | 'minimum' | 'maximum' | 'min_length' | 'max_length' | 'max_items' | 'format' | 'file'
code: 'required' | 'type' | 'enum' | 'minimum' | 'maximum' | 'min_length' | 'max_length' | 'max_items' | 'format' | 'file' | 'principal'
message: string
}
+20
View File
@@ -45,6 +45,21 @@ export interface BpStep {
export interface BpField { name: string; spec: BpItem<Record<string, any>>; sensitive: boolean }
/**
* 自由形「谁来做」的一行。slot:图里引用的一个岗位(path 是 /people/<i>/who,只定由谁做);reconciler:写入能力没登记查询时
* 的核实人(path 是 /writeback/reconciler);initiator / expression / hook:不按岗位派的步骤,只读(path 为空)。
* label 是节点在图上的名字,detail 写全每一处用途
*/
export interface DerivedPerson {
kind: 'slot' | 'reconciler' | 'initiator' | 'expression' | 'hook'
slot: string | null
label: string
detail: string
path: string | null
who: BpPrincipal[] | null
uses: { node_id: string; title: string; role: string }[]
}
export interface BpWriteback {
capability: BpItem<string>
mapping: BpItem<Record<string, string>>
@@ -132,6 +147,11 @@ export interface Blueprint {
* templates/_common.needs_reconciler,界面不自己判)。老服务端不给时按不要
*/
reconciler_needed?: boolean
/**
* 自由形按导入的图列出的「谁来做」(服务端 templates/freeform.people_rows,05-已知遗留 (d)):界面照这一份画,不自己从图里推。
* 别的模板、老服务端为空
*/
derived_people?: DerivedPerson[] | null
/** 蓝图检查(bp.* / tpl.*),带白话 */
issues?: PlainIssue[]
created_at: string