45 lines
7.0 KiB
TypeScript
45 lines
7.0 KiB
TypeScript
import {shadowPuppetResources,shadowPuppetDocuments} from "./shadow-puppet";
|
|
import {streetPeople} from "@/lib/street-people";
|
|
export type Resource={id:string;kind:'document'|'image'|'api';title:string;href:string;human?:string;method?:string;description?:string;detail?:unknown;template?:boolean};
|
|
export type Block={type:'paragraph'|'heading'|'code'|'links';text?:string;refs?:string[]};
|
|
export type SkillDocument={id:string;title:string;blocks:Block[]};
|
|
export const skillResources:Resource[]=[
|
|
{id:'index',kind:'document',title:'入口文档 · SKILL.md',href:'/skills/street-people/SKILL.md',human:'/tools/skills/street-people'},
|
|
{id:'style',kind:'document',title:'画风与生成提示词',href:'/skills/street-people/style.md',human:'/tools/skills/street-people/style'},
|
|
{id:'upload',kind:'document',title:'上传与返回结果',href:'/skills/street-people/upload.md',human:'/tools/skills/street-people/upload'},
|
|
{id:'checks',kind:'document',title:'交付检查清单',href:'/skills/street-people/checks.md',human:'/tools/skills/street-people/checks'},
|
|
{id:'reference',kind:'image',title:'画风参考图',href:'/skills/street-people/reference.png'},
|
|
{id:'sample',kind:'image',title:'透明人物示意图',href:'/skills/street-people/sample.png'},
|
|
{id:'spec',kind:'api',title:'机器可读接口规范',href:'/api/skills/street-people',method:'GET'},
|
|
{id:'submit',kind:'api',title:'提交透明 PNG 图包',href:'/api/skills/street-people',method:'POST'},
|
|
];
|
|
export const skillDocuments:SkillDocument[]=[
|
|
{id:'index',title:'街头小人',blocks:[
|
|
{type:'paragraph',text:'用松散的线条、冬天的衣着与奶油色剪纸边,留住街上的一个瞬间。此文档是交给 coding agent 的入口;先阅读说明,再按链接选择需要的子文档与接口。'},
|
|
{type:'heading',text:'从这里开始'},
|
|
{type:'paragraph',text:'绘图由 agent 自己的图像工具执行。网站负责提供风格规范、检查透明 PNG,并存储发布素材包;不在网站配置模型密钥。'},
|
|
{type:'links',refs:['style','reference','sample']},
|
|
{type:'heading',text:'生成与交付'},
|
|
{type:'paragraph',text:'每张图只包含一个完整人物及其随身物件。明确启用透明背景,检查外部透明、内部纸张与完整轮廓,再按上传文档提交。多个文件组成一篇素材笔记,同一图片仍可被其他笔记引用。'},
|
|
{type:'links',refs:['upload','checks']},
|
|
{type:'paragraph',text:'所有文档、图片与 API 的完整索引见下方。入口与子文档均为纯文本 Markdown,图片始终以链接提供。'},
|
|
{type:'links',refs:skillResources.map(r=>r.id)},
|
|
]},
|
|
{id:'style',title:'画风与生成提示词',blocks:[{type:'paragraph',text:'完整单人、成人比例、稀疏五官;不规则毡头笔线条,头发与裤子用涂抹排线。保留纸片内部的奶油色,纸片以外是真实透明通道。'}, {type:'links',refs:['reference','sample']},{type:'heading',text:'生成提示词'},{type:'paragraph',text:'将 {{subject}} 替换成衣着与动作。每张单独生成,使用绘图工具的透明背景选项。'},{type:'code',text:streetPeople.prompt},{type:'links',refs:['checks','upload','index']}]},
|
|
{id:'upload',title:'上传与返回结果',blocks:[{type:'paragraph',text:'先由 agent 生成 PNG,再以 multipart/form-data 提交。API 不负责绘图。'}, {type:'links',refs:['submit','spec']},{type:'code',text:`POST /api/skills/street-people\nContent-Type: multipart/form-data\n\n${Object.entries(streetPeople.upload.fields).map(([k,v])=>k+': '+v).join('\n')}\n\n201: { id, slug, url, assets }\n400: 文件或表单不符合规范\n409: slug 已存在\n413: 超出上传限制\n500: 服务器或存储错误`},{type:'heading',text:'调用示例'},{type:'code',text:`curl -X POST "$BASE/api/skills/street-people" \\\n -F 'title=街头小人 · 冬日片段' \\\n -F 'slug=winter-street-people' \\\n -F 'description=人物动作、提示词与生成来源' \\\n -F 'files=@person.png;type=image/png'`},{type:'paragraph',text:'最多 16 张,单文件 250 MB,总计 1 GB,每张最多 4000 万像素。重复 slug 返回 409,不会覆盖已有笔记。使用返回的 url 查看结果。'},{type:'links',refs:['checks','index']}]},
|
|
{id:'checks',title:'交付检查清单',blocks:[{type:'paragraph',text:'逐张检查完整人物、纸片边缘、衣着与动作。外部需要真实透明像素 alpha=0,内部需要接近不透明像素 alpha≥250。仅增加 alpha 通道而没有透明背景的 PNG 会被拒绝。'}, {type:'paragraph',text:'检查无截肢、无额外人物、无文字、无背景和外部阴影。记录生成来源与提示词;来源不同的图包分开提交。服务器的像素检查不能代替 agent 对画风和内容的检查。'}, {type:'links',refs:['style','sample','upload','index']}]},
|
|
];
|
|
export const skillCatalog=[{id:'street-people',title:'街头小人',category:'图片生成 · 透明 PNG',description:'松散的线条,冬天的衣着。把街上的一个瞬间,剪成一张小贴纸。',image:'/skills/street-people/sample.png',alt:'手绘街头小人,透明剪纸素材',href:'/skills/street-people',created_at:'2026-10-22T17:29:47Z'},{id:'shadow-puppet',title:'照片入皮影',category:'照片转译 · 3:4 海报',description:'把照片里的主角请上幕布,让它用一个姿态演完一整出戏。',image:'/skills/shadow-puppet/egret-example.png',alt:'白鹭照片与暖灯宣纸皮影的上下等分海报示例',href:'/skills/shadow-puppet',created_at:'2026-10-23T03:45:00Z'}];
|
|
export type SkillDefinition={id:string;title:string;documents:SkillDocument[];resources:Resource[]};
|
|
const definitions:Record<string,SkillDefinition>={
|
|
'street-people':{id:'street-people',title:'街头小人',documents:skillDocuments,resources:skillResources.map(r=>r.kind==='api'?{...r,detail:r.method==='POST'?streetPeople.upload:streetPeople,description:r.method==='POST'?'上传接口。阅读上传文档后,由 Agent 使用 multipart/form-data 提交文件。此处仅展示说明,不会发送请求。':'返回 JSON 规范。入口文档负责引导流程,JSON 用于查阅接口结构。'}:r)},
|
|
'shadow-puppet':{id:'shadow-puppet',title:'照片入皮影',documents:shadowPuppetDocuments,resources:shadowPuppetResources},
|
|
};
|
|
export function getSkill(id:string):SkillDefinition|undefined{return Object.hasOwn(definitions,id)?definitions[id]:undefined;}
|
|
export function skillDocumentMarkdown(skillId:string,id:string,origin='http://8.211.154.134:18131'){
|
|
const skill=getSkill(skillId);const doc=skill?.documents.find(d=>d.id===id);if(!skill||!doc)return null;
|
|
return `# ${doc.title}\n\n`+doc.blocks.map(b=>b.type==='heading'?`## ${b.text}`:b.type==='code'?`\x60\x60\x60\n${b.text}\n\x60\x60\x60`:b.type==='links'?b.refs!.map(id=>{const r=skill.resources.find(r=>r.id===id)!;return `- [${r.title}](${new URL(r.href,origin).href})${r.method?' — '+r.method:''}`}).join('\n'):b.text).join('\n\n')+'\n';
|
|
}
|
|
// Preserve the existing street-people document API.
|
|
export function documentMarkdown(id:string,origin?:string){return skillDocumentMarkdown('street-people',id,origin);}
|