feat(xiaoyi): preflight selected output capabilities
This commit is contained in:
parent
bd5e425c77
commit
e26df068ef
@ -100,7 +100,13 @@ export async function runSession(config, call, sharedBroker, recovery, signal) {
|
||||
try {
|
||||
signal?.throwIfAborted();
|
||||
signal?.addEventListener('abort',abort,{once:true});
|
||||
const [{DetailPiAgent},{Native98kBroker},{ProjectStore,atomic},{StdioCanvas},{resolveRules}] = await Promise.all([import('./agent.mjs'),import('./native-bridge.mjs'),import('./store.mjs'),import('./stdio-canvas.mjs'),import('./rules.mjs')]);
|
||||
const [{DetailPiAgent},{Native98kBroker},{ProjectStore,atomic},{StdioCanvas},{resolveRules},{productionGoalPreflight}] =
|
||||
await Promise.all([import('./agent.mjs'),import('./native-bridge.mjs'),import('./store.mjs'),
|
||||
import('./stdio-canvas.mjs'),import('./rules.mjs'),import('./production-goal.mjs')]);
|
||||
if (productionGoal) {
|
||||
const blocked = productionGoalPreflight(productionGoal);
|
||||
if (blocked) return blocked;
|
||||
}
|
||||
const modelRole=config.mode==='recover'?config.modelRole||'chat':config.wholeDetail?'detail':'chat';
|
||||
const bindingConfig={binary:config.binary,profile:config.profile,project:config.project,scope:config.scope,modelRole};
|
||||
broker=sharedBroker??new Native98kBroker(bindingConfig);
|
||||
|
||||
76
apps/detail-agent-pi/src/output-capabilities.mjs
Normal file
76
apps/detail-agent-pi/src/output-capabilities.mjs
Normal file
@ -0,0 +1,76 @@
|
||||
import { Type } from '@sinclair/typebox';
|
||||
|
||||
const outputCapabilities = new Map([
|
||||
['detail', { label: '详情页', binding: 'native' }],
|
||||
['main_images', { label: '主图', binding: 'native' }],
|
||||
['sku_images', { label: 'SKU 图', binding: 'native' }],
|
||||
['main_video', {
|
||||
label: '主图视频', templateRoles: ['original', 'mapping'],
|
||||
skillId: 'main-video-production', adapterId: 'main-video-render',
|
||||
}],
|
||||
['seeding_images', {
|
||||
label: '种草图', templateRoles: ['original', 'mapping'],
|
||||
skillId: 'seeding-images-production', adapterId: 'seeding-images-render',
|
||||
}],
|
||||
]);
|
||||
|
||||
const issueSchema = Type.Object({
|
||||
outputId: Type.String({ minLength: 1 }),
|
||||
variantId: Type.Optional(Type.String({ minLength: 1 })),
|
||||
code: Type.Union([
|
||||
Type.Literal('unsupported_output'),
|
||||
Type.Literal('missing_template_resource'),
|
||||
Type.Literal('missing_published_skill'),
|
||||
Type.Literal('missing_render_adapter'),
|
||||
]),
|
||||
requirements: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }),
|
||||
message: Type.String({ minLength: 1 }),
|
||||
}, { additionalProperties: false });
|
||||
|
||||
export const outputPreflightSchema = Type.Union([
|
||||
Type.Object({
|
||||
schemaVersion: Type.Literal(1), status: Type.Literal('ready'), issues: Type.Tuple([]),
|
||||
}, { additionalProperties: false }),
|
||||
Type.Object({
|
||||
schemaVersion: Type.Literal(1), status: Type.Literal('blocked'),
|
||||
issues: Type.Array(issueSchema, { minItems: 1 }),
|
||||
}, { additionalProperties: false }),
|
||||
]);
|
||||
|
||||
// These bindings come from the host's resolved releases, never from requestedOutputs.
|
||||
export function checkOutputCapabilities(requestedOutputs, {
|
||||
componentRoles = new Map(), publishedSkills = new Set(), renderAdapters = new Set(),
|
||||
} = {}) {
|
||||
if (!Array.isArray(requestedOutputs) || !requestedOutputs.length) {
|
||||
throw Error('制作目标与当前项目不匹配');
|
||||
}
|
||||
const issues = [];
|
||||
for (const row of requestedOutputs) {
|
||||
const { outputId, variantId } = row ?? {};
|
||||
if (typeof outputId !== 'string' || !outputId) throw Error('制作目标与当前项目不匹配');
|
||||
const capability = outputCapabilities.get(outputId);
|
||||
const stage = { outputId, ...(typeof variantId === 'string' && variantId ? { variantId } : {}) };
|
||||
const name = (capability?.label ?? outputId) + (stage.variantId ? `(${stage.variantId})` : '');
|
||||
const missing = (code, requirements, reason) => {
|
||||
issues.push({ ...stage, code, requirements, message: `${name}${reason}` });
|
||||
};
|
||||
if (!capability) {
|
||||
missing('unsupported_output', [outputId], '没有注册输出能力');
|
||||
continue;
|
||||
}
|
||||
if (capability.binding === 'native') continue;
|
||||
|
||||
const roles = componentRoles.get(outputId);
|
||||
const missingRoles = capability.templateRoles.filter(role => !roles?.has(role));
|
||||
if (missingRoles.length) {
|
||||
missing('missing_template_resource', missingRoles, '缺少模板资源(' + missingRoles.join('、') + ')');
|
||||
}
|
||||
if (!publishedSkills.has(capability.skillId)) {
|
||||
missing('missing_published_skill', [capability.skillId], '缺少已发布的制作 Skill');
|
||||
}
|
||||
if (!renderAdapters.has(capability.adapterId)) {
|
||||
missing('missing_render_adapter', [capability.adapterId], '缺少已发布的渲染适配器');
|
||||
}
|
||||
}
|
||||
return { schemaVersion: 1, status: issues.length ? 'blocked' : 'ready', issues };
|
||||
}
|
||||
@ -4,7 +4,17 @@ import lockfile from 'proper-lockfile';
|
||||
import { productionKnowledge } from './production-knowledge.mjs';
|
||||
import { SessionManager } from '@earendil-works/pi-coding-agent';
|
||||
import { openProductionOperations, productionOperationTools } from './production-operations.mjs';
|
||||
|
||||
import { BridgeError } from './bridge-error.mjs';
|
||||
import { checkOutputCapabilities } from './output-capabilities.mjs';
|
||||
|
||||
export function productionGoalPreflight(goal) {
|
||||
const outputPreflight = checkOutputCapabilities(goal.requestedOutputs);
|
||||
if (outputPreflight.status === 'ready') return;
|
||||
const error = '制作未启动:' + outputPreflight.issues.map(issue => issue.message).join(';');
|
||||
const failure = new BridgeError(error, 'output_preflight_blocked').wire();
|
||||
return {error,failure,outputPreflight,unknown:false,pending:[],reposted:false};
|
||||
}
|
||||
|
||||
export function productionObjective(requestedOutputs) {
|
||||
const outputs = [...new Set(requestedOutputs.map(row=>row.label || row.outputId))].join('、');
|
||||
return '按适用 Skill 和模板制作并交付本轮所选输出:'+outputs+'。按需读取产品资料并决定制作顺序、图文与返工。';
|
||||
|
||||
91
apps/detail-agent-pi/test/output-capabilities.test.mjs
Normal file
91
apps/detail-agent-pi/test/output-capabilities.test.mjs
Normal file
@ -0,0 +1,91 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { Value } from '@sinclair/typebox/value';
|
||||
import { runSession } from '../src/desktop-host.mjs';
|
||||
import { checkOutputCapabilities, outputPreflightSchema } from '../src/output-capabilities.mjs';
|
||||
|
||||
const stage = outputId => ({ outputId, variantId: 'oak' });
|
||||
const nativeOutputs = ['detail', 'main_images', 'sku_images'].map(stage);
|
||||
const video = stage('main_video');
|
||||
const seeding = stage('seeding_images');
|
||||
const ready = { schemaVersion: 1, status: 'ready', issues: [] };
|
||||
const allMissing = ['missing_template_resource', 'missing_published_skill', 'missing_render_adapter'];
|
||||
|
||||
test('existing outputs pass preflight for each single selection and the mixed selection', () => {
|
||||
for (const selection of [...nativeOutputs.map(output => [output]), nativeOutputs]) {
|
||||
const receipt = checkOutputCapabilities(selection);
|
||||
assert.deepEqual(receipt, ready);
|
||||
assert.ok(Value.Check(outputPreflightSchema, receipt));
|
||||
}
|
||||
});
|
||||
|
||||
test('unreleased outputs report each missing prerequisite for single and mixed selections', () => {
|
||||
for (const [selection, blocked] of [
|
||||
[[video], [video]],
|
||||
[[seeding], [seeding]],
|
||||
[[nativeOutputs[0], video, seeding], [video, seeding]],
|
||||
]) {
|
||||
const receipt = checkOutputCapabilities(selection);
|
||||
assert.equal(receipt.status, 'blocked');
|
||||
assert.deepEqual(receipt.issues.map(({outputId, variantId, code}) => ({outputId, variantId, code})),
|
||||
blocked.flatMap(output => allMissing.map(code => ({ ...output, code }))));
|
||||
assert.ok(Value.Check(outputPreflightSchema, receipt));
|
||||
}
|
||||
});
|
||||
|
||||
test('missing roles, Skills and adapters are evaluated against their own resolved bindings', () => {
|
||||
const bindings = {
|
||||
componentRoles: new Map([
|
||||
['main_video', new Set(['original', 'mapping'])],
|
||||
['seeding_images', new Set(['original'])],
|
||||
]),
|
||||
publishedSkills: new Set(['main-video-production']),
|
||||
renderAdapters: new Set(['seeding-images-render']),
|
||||
};
|
||||
assert.deepEqual(checkOutputCapabilities([video, seeding], bindings).issues.map(issue =>
|
||||
[issue.outputId, issue.code, issue.requirements]), [
|
||||
['main_video', 'missing_render_adapter', ['main-video-render']],
|
||||
['seeding_images', 'missing_template_resource', ['mapping']],
|
||||
['seeding_images', 'missing_published_skill', ['seeding-images-production']],
|
||||
]);
|
||||
bindings.componentRoles.get('seeding_images').add('mapping');
|
||||
bindings.publishedSkills.add('seeding-images-production');
|
||||
bindings.renderAdapters.add('main-video-render');
|
||||
assert.deepEqual(checkOutputCapabilities([...nativeOutputs, video, seeding], bindings), ready);
|
||||
});
|
||||
|
||||
test('receipt schema rejects invalid versions, issue codes and status combinations', () => {
|
||||
const blocked = checkOutputCapabilities([{outputId:'unknown_output'}]);
|
||||
assert.equal(blocked.issues[0].code, 'unsupported_output');
|
||||
assert.ok(Value.Check(outputPreflightSchema, blocked));
|
||||
for (const invalid of [
|
||||
{...blocked, schemaVersion:2},
|
||||
{...blocked, status:'ready'},
|
||||
{...blocked, issues:[]},
|
||||
{...blocked, issues:[{...blocked.issues[0], code:'missing'}]},
|
||||
{...blocked, issues:[{...blocked.issues[0], requirements:[]}]},
|
||||
{...blocked, issues:[{...blocked.issues[0], outputId:''}]},
|
||||
]) {
|
||||
assert.equal(Value.Check(outputPreflightSchema, invalid), false);
|
||||
}
|
||||
});
|
||||
|
||||
test('production startup rejects the full requested scope before broker or canvas calls', async () => {
|
||||
const brokerBind = test.mock.fn();
|
||||
const canvasCall = test.mock.fn();
|
||||
const result = await runSession({
|
||||
mode:'prompt', wholeDetail:true, productProduction:true,
|
||||
outputId:'detail', variantId:'oak',
|
||||
requestedOutputs:[nativeOutputs[0], {...video, templateRoles:['original', 'mapping']}],
|
||||
pendingOutputs:[nativeOutputs[0]],
|
||||
}, canvasCall, { bind:brokerBind });
|
||||
assert.equal(brokerBind.mock.callCount(), 0);
|
||||
assert.equal(canvasCall.mock.callCount(), 0);
|
||||
assert.match(result.error, /主图视频.*缺少模板资源.*缺少已发布的制作 Skill.*缺少已发布的渲染适配器/u);
|
||||
assert.deepEqual(result.failure, {
|
||||
message:result.error, category:'output_preflight_blocked', retryable:false, dispatched:false,
|
||||
});
|
||||
assert.deepEqual(result.outputPreflight, checkOutputCapabilities([video]));
|
||||
assert.equal(result.unknown, false);
|
||||
assert.equal(result.reposted, false);
|
||||
});
|
||||
65
docs/development/xiaoyi/output-capabilities.md
Normal file
65
docs/development/xiaoyi/output-capabilities.md
Normal file
@ -0,0 +1,65 @@
|
||||
# 小壹输出能力契约
|
||||
|
||||
适用范围为 Harness 1.2 阶段 E、A29 和 ADR14。一次制作以 `requestedOutputs` 中的 `outputId` 和 `variantId` 确定交付范围。项目可以单选或混选。主代理可以决定制作顺序和素材复用,完成判定覆盖本轮全部所选输出及变体。
|
||||
|
||||
## 登记与发布
|
||||
|
||||
每项能力声明输出 ID、资源地图组件、必需 Skill、适配器、交付角色和文件验证方式。项目按所选资源组锁定组件 ID 和版本、原稿与映射的文件 ID 和 revision、必需依赖、Skill 版本和适配器版本。出图数量、规格、时长和平台规则由组件映射与项目合同确定。Skill 负责使用同版资源进行策划、制作、审稿和返工。
|
||||
|
||||
| 输出 ID | 资源地图组件与必需 Skill | 制作与渲染适配器 | 必需交付与验证 |
|
||||
| --- | --- | --- | --- |
|
||||
| `detail` | `detail` 组件提供原稿、屏及字段映射和必需附件。使用所选组件已发布的详情制作 Skill 及其必需引用,或当前自主策划路线绑定的制作规则。 | 现有 PhotoCraft 详情画布和导出 | 长图与约定可编辑工程,分屏按合同交付。重开工程核对屏序、替换字段和可见范围,解码长图核对尺寸、屏序、接缝和文字。 |
|
||||
| `main_images` | `main_images` 组件提供原稿、图位与字段映射、平台和用途要求及必需附件。使用所选组件已发布的主图制作 Skill 及其必需引用,或当前自主策划路线绑定的制作规则。 | 现有 PhotoCraft 主图画布和导出 | 所需图集与约定源文件。按图位核对实际解码的尺寸、商品、裁切和文字,重开源检查相应图位和图层。 |
|
||||
| `sku_images` | `sku_images` 组件提供原稿、字段映射和必需附件,由产品资料提供真实变体矩阵。使用所选组件已发布的 SKU 制作 Skill 及其必需引用,或当前自主策划路线绑定的制作规则。 | 现有 PhotoCraft SKU 画布和导出 | SKU 图、SKU 对应清单和约定源文件。逐项解码并核对颜色、结构、规格和覆盖率,重开源核对变体与图位。 |
|
||||
| `main_video` | `main_video` 组件提供可编辑时间线原稿(`original`)、分镜及输出约束(`mapping`)和必需附件。必需 Skill 为 `main-video-production`。 | 独立 `main-video-render` | 视频、可编辑时间线和重开所需素材,按合同附封面和字幕文件。重开源逐段验证,完整解码交付视频及要求的音轨。 |
|
||||
| `seeding_images` | `seeding_images` 组件提供可编辑版式原稿(`original`)、套图序列及字段映射(`mapping`)和必需附件。必需 Skill 为 `seeding-images-production`。 | `seeding-images-render`,可对接现有画布与图片导出能力 | 有序套图、顺序清单和可编辑源。逐张解码,重开源并按正式顺序审整套。 |
|
||||
|
||||
发布方需验证同一版本组合下可读取组件原稿、映射和必需附件,可加载 Skill 正文及必需引用,适配器已注册并通过对应输出的真实业务样例。每项输出和面向用户开放的组合按 A29 验证。混选时任一所选项缺少前置条件,整轮留在开工前。
|
||||
|
||||
### Node 开工回执
|
||||
|
||||
`checkOutputCapabilities(requestedOutputs, bindings)` 在 Node 启动制作会话前检查整组请求。发布绑定由宿主解析后提供。`componentRoles` 是按输出 ID 索引的可用角色集合,只有组件版本一致、所要求的附件可读时才提供已确认角色。`publishedSkills` 和 `renderAdapters` 只包含本次可加载的已发布 Skill ID 和已注册且已获准运行的适配器 ID。三类现行画布输出继续使用原生绑定与验证。当前宿主尚无视频或种草的已解析发布绑定,向 Node 请求这两类输出会收到阻断回执。
|
||||
|
||||
当前资源地图模板入口和 `template-packs.ts` 校验器使用三类画布组件,`jiansun_production_profile.rs` 按当前画布组件选取规则。接入新输出时,资源解析按输出 ID 读取并锁定发布组件,分别交给时间线适配器和套图适配器,并把已解析的绑定交给预检。视频采用独立的编排源与适配器路由。种草图可借用原画布的图层和导出能力,并按套图合同规划和验收。
|
||||
|
||||
回执 schema 版本为 `1`。状态为 `ready` 时 `issues` 为空,状态为 `blocked` 时 `issues` 至少有一项。每项包含 `outputId`、有值时的 `variantId`、`code`、具体缺项 `requirements` 和可直接展示的 `message`。
|
||||
|
||||
| `code` | `requirements` |
|
||||
| --- | --- |
|
||||
| `missing_template_resource` | 缺少的资源角色,如 `original` 或 `mapping` |
|
||||
| `missing_published_skill` | 所需的 Skill ID |
|
||||
| `missing_render_adapter` | 所需的渲染适配器 ID |
|
||||
| `unsupported_output` | 请求中尚未注册的输出 ID |
|
||||
|
||||
阻断时本地会话返回 `outputPreflight`、供客户端显示的 `error`,以及 `failure.category = output_preflight_blocked`、`failure.dispatched = false`。就绪回执用于判断能否开工。正式交付以通过真文件验收的 generation 为准。
|
||||
|
||||
## 适配器接口与交付门禁
|
||||
|
||||
能力适配器接收项目及运行 ID、输出及变体 ID、已锁定的资源和商品事实、Skill 生成的计划、源版本、目标规格及取消信号。接口按以下职责实现,现有原生适配器可以通过对应工具组合完成。
|
||||
|
||||
| 操作 | 输入与结果 |
|
||||
| --- | --- |
|
||||
| `saveSource` | 将计划和已采用的素材写入可编辑工程,返回实际源文件引用、源 revision 及可重开的依赖。 |
|
||||
| `reopenSource` | 用该输出支持的编辑器或适配器加载磁盘上的保存源及依赖,返回可渲染的源和重开检查结果。 |
|
||||
| `render` | 从锁定的源按合同规格渲染到本次 generation,返回真实文件及其角色。异步渲染保留原作业 ID,恢复按原编号查询。 |
|
||||
| `verify` | 逐文件重新打开或解码,检查规格、源与交付的对应关系,关联实际审稿结果并返回证据。 |
|
||||
|
||||
可编辑保真交付采用 `full`。正式渲染使用实际重开的源,或证明重开源和冻结渲染快照的视觉一致性。政策与输出合同都允许且明确选择 `none` 时,记录省略的检查,绑定同一冻结源并实际解码交付文件。视频和种草首发要求 `full`。若合同声明第三方编辑器兼容,使用该软件另外重开验证。
|
||||
|
||||
文件清单逐项记录角色、文件身份、大小、格式、实际尺寸或时长、`sourceRevision` 和验证结果。全部必需文件通过后才发布 generation 并更新当前交付引用。项目清单汇总本轮所选输出和变体的已验证 generation。中途失败保留上一版完整交付,已做完的部分可以作为阶段成果供查看。
|
||||
|
||||
## 主图视频
|
||||
|
||||
- **分镜。** 每镜头保留 ID、顺序、销售意图、商品与变体 ID、素材或片段来源、镜头长度、裁切与转场。使用已验收的静态素材、实拍或已批准的生成片段。逐镜头核对商品结构、材质、颜色、尺寸观感和宣称依据。
|
||||
- **时间线。** 使用明确的有理数时间基和整数起止位置,保存轨道、裁切、素材引用、转场及封面帧。记录画幅、尺寸、帧率、时长、容器和编码参数。编辑工程包含素材或可按锁定版本重新定位的素材。
|
||||
- **字幕与音轨。** 合同明确无声或需要音乐、配音、音效,明确字幕烧录或独立文件。保存字幕文本、时间段、轨道来源与使用授权。检查边界、文字可读性、音量、音画同步和有声段覆盖。
|
||||
- **真文件验收。** 从磁盘重开时间线,确认素材、字幕和音轨齐全。顺序解码视频和要求的音轨至结尾,验证编码、画幅、帧率、时长与轨道。检查首尾、镜头切换、关键商品展示和字幕可读区间。封面与独立字幕按合同回读并核对时间线。
|
||||
|
||||
PhotoCraft 的 `crates/doc/src/video.rs` 已有逐帧时钟、播放头、工作区和内存光栅帧栈,可评估复用来预览或合成短段。现有 `crates/engine/src/cmd/video_cmds.rs` 可输出图片序列或动画 GIF。正式视频适配器需负责可编辑多轨编排、音频混合、字幕、编码封装和完成后的完整解码。时间线源格式由发布适配器选定。
|
||||
|
||||
## 种草图
|
||||
|
||||
- **主题与场景。** 每套确定受众、主题、卖点、视觉调性和场景规则。逐张记录内容意图、产品变体、引用素材和来源,场景道具、光线、比例与摆放符合使用情境。
|
||||
- **套图顺序。** 映射定义稳定的图位 ID、顺序、用途、文本区域与规格。交付清单保留主题及图位到图片和源的关系。按合同检查封面、各图分工和浏览顺序。
|
||||
- **可编辑源。** 保留排版、图层、可编辑文字、已采用素材及必要字体。重开实际保存工程,核对图层、字段、尺寸和裁切,再与正式套图对照。
|
||||
- **套图审稿。** 顺序查看整套实图,检查主题连续性、商品外观及变体一致性、场景合理性、色调、重复信息、文字可读性和发布规格。返工一张后重新核对它与相邻图的衔接及对应清单。
|
||||
Loading…
x
Reference in New Issue
Block a user