普通用户建应用的契约骨架(docs/design/normal-user-apps.md 第五部分):蓝图、蓝图留痕、发布单、文件、记录表的模型和迁移,应用的 scope / owner / blueprint_id;运行来源加 trial、personal_app;应用描述的固定版本可以没有版本号(试运行派生的草稿)或改钉蓝图(个人应用),视图来源加 exploratory,组件加 hidden,表单加文件控件;agentlab.blueprint/1 与 bp_* 操作、agentlab.template/1 与关节类型的定义;实例化、试运行、发布单、个人应用、记录表、文件、白话层的接口签名;蓝图、模板、文件、个人应用、蓝图助手的路由桩(501);前端约定 typesBlueprint.ts、接口桩、新建应用与蓝图页的占位路由、termsBlueprint.ts

This commit is contained in:
ThearchyHelios
2026-10-15 09:49:45 +08:00
parent 69c5c74806
commit 7088f4557e
35 changed files with 1144 additions and 17 deletions
+58
View File
@@ -0,0 +1,58 @@
/**
* 普通用户建应用的接口(docs/design/normal-user-apps.md §3.10):蓝图、试运行、发布单、模板、文件、个人应用、页面编辑候选、记录。
* 约定在 typesBlueprint.ts。流式的蓝图助手、填关节走 store 里的 SSE(同 copilot),不在这里。
*/
import type { AppSpec } from '../typesApp'
import type {
AppCandidate, Blueprint, BlueprintScope, BlueprintSourceKind, BpOp, FileRef, PlainIssue, PublishPlanRow, RecordsPage,
TemplateInfo, TrialPage, TrialStart,
} from '../typesBlueprint'
import { del, get, patch, post, qs, upload, type UploadOptions } from './http'
export const blueprints = {
create: (body: { source: { kind: BlueprintSourceKind; id?: string; version?: number }; scope: BlueprintScope; name?: string;
template?: string }) => post<Blueprint>('/blueprints', body),
list: (q: { scope?: BlueprintScope } = {}) => get<{ items: Blueprint[] }>(`/blueprints${qs(q)}`),
get: (id: string) => get<Blueprint>(`/blueprints/${encodeURIComponent(id)}`),
/** 卡片上的修改:bp_* 操作,来源记成 user */
patch: (id: string, body: { ops?: BpOp[]; name?: string }) => patch<Blueprint>(`/blueprints/${encodeURIComponent(id)}`, body),
instantiate: (id: string) =>
post<{ blueprint: Blueprint; app_spec: AppSpec; problems: PlainIssue[] }>(`/blueprints/${encodeURIComponent(id)}/instantiate`, {}),
trial: (id: string, body: { inputs?: Record<string, unknown> } = {}) =>
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 }) =>
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`, {}),
copyForReview: (id: string) => post<Blueprint>(`/blueprints/${encodeURIComponent(id)}/copy`, {}),
}
export const templates = {
list: () => get<{ items: TemplateInfo[] }>('/templates'),
}
export const files = {
/** 先上传拿引用,再把引用作为表单值提交(N9) */
upload: (file: File, context: Record<string, string>, opts?: UploadOptions) => {
const form = new FormData()
form.append('file', file)
form.append('context', JSON.stringify(context))
return upload<FileRef>('/files', form, opts)
},
url: (fileId: string) => `/api/files/${encodeURIComponent(fileId)}`,
remove: (fileId: string) => del(`/files/${encodeURIComponent(fileId)}`),
}
export const personal = {
refresh: (appId: string) => post<{ run_id: string; remaining: number }>(`/apps/${encodeURIComponent(appId)}/refresh`, {}),
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 } = {}) =>
get<RecordsPage>(`/apps/${encodeURIComponent(appId)}/records${qs(q)}`),
}
+8
View File
@@ -28,6 +28,8 @@ import { apps, ledger } from './apps'
import { actions, tasks } from './tasks'
import { auth, identity } from './auth'
import { capabilities, endpoints, notify } from './capabilities'
// 普通用户建应用(typesBlueprint.ts 是接口约定)
import { blueprints, files, personal, templates } from './blueprints'
// 请求层搬到了 http.ts(见那边的说明)。原先从这里导出的照旧从这里导出,调用方不用改;
// 请求函数也一并转出,给不在 api/ 下、又想直接发请求的地方用。api/ 下的命名空间文件请直接从 http.ts 导入
@@ -865,6 +867,12 @@ export const api = {
capabilities,
endpoints,
notify,
// ---- 普通用户建应用(typesBlueprint.ts 是接口约定) ----
blueprints,
templates,
files,
personal,
}
/**