普通用户建应用(前端):新建应用的三个起点(说需求、场景模板、从已有的开始);蓝图页(对话加卡片、反问选项、关节逐组进度、试运行、发布摘要按你来定 / 助手可以修 / 要找管理员分栏、逐步打勾、接着做);问数据「做成应用」改走蓝图;问数据和画布的反问收尾;页面上直接改(选中、改字、隐藏、挪动、删除、加数据卡片、自动存草稿);文件控件;我的记录列表;个人应用的界面(我的应用、刷新与剩余次数、提交审核、审核待办卡);设置页的个人应用开关;四个新检查脚本并加进完整关口

This commit is contained in:
ThearchyHelios
2026-10-15 12:09:29 +08:00
parent 277982ead3
commit a702a5c14b
49 changed files with 6953 additions and 133 deletions
+101
View File
@@ -0,0 +1,101 @@
/**
* 蓝图助手和填关节(docs/design/normal-user-apps.md §2.2、§2.3、§2.11):两条 SSE,帧同 streamCopilot(一帧一行
* `data: <JSON>`,空行分隔)。状态在 store/blueprint.ts,翻译在 run/decode.ts,这里只管收发。
*
* - POST /api/copilot/blueprint-stream {blueprint_id, instruction, model?}:蓝图对话(服务端 api/copilot_blueprint.py)。
* 操作有 model、thinking、heartbeat、look、plan、bp_set / bp_add / bp_remove / bp_template(模型提的,服务端落地)、
* bp_ask(问回来一句,带候选,这一轮到此结束)、check(自查)、reply(只回答、不改卡片)、done、
* final {blueprint, explanation, issues, asked?}(存好的整份蓝图以它为准;issues 是没采纳的操作)、error。
* 这一轮落进蓝图对话、回答上一轮的反问都由服务端做。
* - POST /api/copilot/fill-joints-stream {blueprint_id, groups?}:按模板填生成关节,不同组并行,每个操作带 group:
* group {group, status: started|retrying|filled|failed, joints?, issues?, message?}、各组自己的 look、plan、fill_joint、check;
* 最后 final {blueprint, groups, problems}。
*
* 开流之前就被拒(4xx/5xx)时 onEnd 带服务端那句话、状态码和机读码;流到一半断了和一开始就连不上一样,说无法连接服务。
* 请求函数从 ./http 导入,不要从 ./client 导入(循环导入,见 http.ts 开头)。
*/
import { ApiError, BASE, NETWORK_MESSAGE, actorHeader, codeOf, describeDetail, isGatewayFailure, parseBody, report } from './http'
export interface BlueprintStreamRequest {
blueprint_id: string
/** 想要什么、要怎么改,或者回答助手的反问 */
instruction: string
model?: string | null
}
export interface FillJointsRequest {
blueprint_id: string
/** 只填这几组;不给 = 还有没填上的关节的那几组 */
groups?: string[]
}
export type StreamEnd = (error?: string, info?: { status?: number; code?: string; aborted?: boolean }) => void
/** 一条 SSE:返回取消函数 */
function sse(path: string, body: unknown, onOp: (op: any) => void, onEnd: StreamEnd): () => void {
const controller = new AbortController()
void (async () => {
try {
const res = await fetch(`${BASE}${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream', ...actorHeader() },
body: JSON.stringify(body),
signal: controller.signal,
})
if (!res.ok || !res.body) {
const text = await res.text().catch(() => '')
let parsed: any
let isJson = false
try { parsed = JSON.parse(text); isJson = true } catch { /* 响应体不是 JSON */ }
if (isGatewayFailure(res.status, text, isJson)) {
report(false, new ApiError(res.status, NETWORK_MESSAGE, { kind: 'network' }))
onEnd(NETWORK_MESSAGE)
return
}
report(true)
onEnd(isJson ? describeDetail(parsed?.detail ?? parsed, path)
: res.status >= 500 ? `服务端错误(${res.status}),详情请查看服务日志`
: `请求失败(HTTP ${res.status})`, { status: res.status, code: isJson ? codeOf(parsed) : undefined })
return
}
report(true)
const reader = res.body.getReader()
const decoder = new TextDecoder()
let buffer = ''
const flush = (frame: string) => {
if (!frame.startsWith('data: ')) return
try {
onOp(parseBody(frame.slice(6)))
} catch { /* 半截帧,忽略 */ }
}
for (;;) {
const { done, value } = await reader.read()
if (done) break
buffer += decoder.decode(value, { stream: true })
let idx: number
while ((idx = buffer.indexOf('\n\n')) >= 0) {
flush(buffer.slice(0, idx))
buffer = buffer.slice(idx + 2)
}
}
buffer += decoder.decode()
if (buffer.trim()) flush(buffer.trim())
onEnd()
} catch (e: any) {
if (e?.name === 'AbortError') { onEnd(undefined, { aborted: true }); return }
if (e instanceof TypeError) {
report(false, new ApiError(0, NETWORK_MESSAGE, { kind: 'network', raw: String(e) }))
onEnd(NETWORK_MESSAGE)
return
}
onEnd(e?.message ?? NETWORK_MESSAGE)
}
})()
return () => controller.abort()
}
export const streamBlueprint = (body: BlueprintStreamRequest, onOp: (op: any) => void, onEnd: StreamEnd) =>
sse('/copilot/blueprint-stream', body, onOp, onEnd)
export const streamFillJoints = (body: FillJointsRequest, onOp: (op: any) => void, onEnd: StreamEnd) =>
sse('/copilot/fill-joints-stream', body, onOp, onEnd)
+7 -2
View File
@@ -2,6 +2,7 @@
* 普通用户建应用的接口(docs/design/normal-user-apps.md §3.10):蓝图、试运行、发布单、模板、文件、个人应用、页面编辑候选、记录。
* 约定在 typesBlueprint.ts。流式的蓝图助手、填关节走 store 里的 SSE(同 copilot),不在这里。
*/
import type { ConversationDetail } from '../types'
import type { AppSpec } from '../typesApp'
import type {
AppCandidate, Blueprint, BlueprintScope, BlueprintSourceKind, BpOp, FileRef, PlainIssue, PublishPlanRow, RecordsPage,
@@ -22,13 +23,17 @@ export const blueprints = {
post<TrialStart>(`/blueprints/${encodeURIComponent(id)}/trial`, body),
preview: (id: string, q: { page?: string; run?: string } = {}) =>
get<TrialPage>(`/blueprints/${encodeURIComponent(id)}/preview${qs(q)}`),
publishPlan: (id: string, body: { level: 'published' | 'governed'; first_run?: boolean }) =>
/** dispositions:固定版本升了版时每一项的处置(别名 → recompute / dual / incomparable),口径升版必须处置 */
publishPlan: (id: string, body: { level: 'published' | 'governed'; first_run?: boolean;
dispositions?: Record<string, 'recompute' | 'dual' | 'incomparable'> }) =>
post<PublishPlanRow>(`/blueprints/${encodeURIComponent(id)}/publish-plan`, body),
plan: (planId: string) => get<PublishPlanRow>(`/publish-plans/${encodeURIComponent(planId)}`),
runPlan: (planId: string) => post<PublishPlanRow>(`/publish-plans/${encodeURIComponent(planId)}/run`, {}),
resumePlan: (planId: string) => post<PublishPlanRow>(`/publish-plans/${encodeURIComponent(planId)}/resume`, {}),
// ---- 个人应用(N7)
savePersonal: (id: string) => post<{ app_id: string; blueprint: Blueprint }>(`/blueprints/${encodeURIComponent(id)}/save-personal`, {}),
/** 蓝图对话的历史:权限按蓝图判,没开问数据的使用者也读得到自己蓝图的对话 */
conversation: (id: string) => get<ConversationDetail>(`/blueprints/${encodeURIComponent(id)}/conversation`),
copyForReview: (id: string) => post<Blueprint>(`/blueprints/${encodeURIComponent(id)}/copy`, {}),
}
@@ -53,6 +58,6 @@ export const personal = {
submitReview: (appId: string, body: { to: { kind: 'user' | 'group'; name: string }[]; note?: string }) =>
post<{ task_id: string }>(`/apps/${encodeURIComponent(appId)}/submit-review`, body),
candidates: (appId: string) => get<{ items: AppCandidate[] }>(`/apps/${encodeURIComponent(appId)}/candidates`),
records: (appId: string, q: { table?: string; cursor?: string; history?: boolean } = {}) =>
records: (appId: string, q: { table?: string; who?: 'mine' | 'all'; cursor?: string; history?: boolean } = {}) =>
get<RecordsPage>(`/apps/${encodeURIComponent(appId)}/records${qs(q)}`),
}