Files
Prompt-Envelope-Protocol/src/data/demos/prompt-envelope.schema.json
T
carry 742659df43 feat: 将 demo 数据迁移为 JSON 协议文件,激活 Raw Protocol 面板
- 新建 6 个 demo JSON 文件 (demo-a ~ demo-f),替代 TS 硬编码常量
- 新建 prompt-envelope.schema.json (JSON Schema Draft 2020-12)
- 新建 demos-loader.ts: validateEnvelope() 运行时验证 + hydrateSkills() 从 skills 源补全 body
- 新建 manifest.json 场景索引
- ProtocolPanel: Raw Protocol tab 已激活,可切换查看原始 PromptEnvelope JSON
- demo.ts 改为从 JSON import + loadEnvelope() 加载
- Skill body 不入协议,仅保留 name + description (L1),由加载器补全
- 时间戳改为固定 epoch 毫秒值
- 删除 6 个旧 demo-{a..f}.ts 文件

构建通过,26 个测试全部通过
2026-06-08 20:52:44 +08:00

206 lines
6.4 KiB
JSON

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://hci-demo.local/prompt-envelope.schema.json",
"title": "Prompt Envelope Protocol",
"description": "Prompt Envelope 协议格式 — 消息由若干带类型的 Segment 组成,每种 Segment 有独立的视觉呈现。",
"type": "object",
"required": ["version", "messages"],
"properties": {
"version": {
"type": "string",
"const": "1.0",
"description": "协议版本号"
},
"model": {
"type": "string",
"description": "导出时使用的模型名称"
},
"messages": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/Message" }
}
},
"$defs": {
"Message": {
"type": "object",
"required": ["id", "role", "segments", "timestamp"],
"properties": {
"id": { "type": "string" },
"role": {
"type": "string",
"enum": ["system", "user", "assistant", "tool"]
},
"segments": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/Segment" }
},
"timestamp": {
"type": "number",
"description": "Unix epoch 毫秒"
}
}
},
"Segment": {
"oneOf": [
{ "$ref": "#/$defs/TextSegment" },
{ "$ref": "#/$defs/StaticVarSegment" },
{ "$ref": "#/$defs/SystemPromptSegment" },
{ "$ref": "#/$defs/MemorySegment" },
{ "$ref": "#/$defs/SkillsSegment" },
{ "$ref": "#/$defs/ToolOverviewSegment" },
{ "$ref": "#/$defs/ToolCallRequestSegment" },
{ "$ref": "#/$defs/ToolCallResultSegment" },
{ "$ref": "#/$defs/DocumentSegment" },
{ "$ref": "#/$defs/LongTextSegment" },
{ "$ref": "#/$defs/MediaSegment" }
]
},
"TextSegment": {
"type": "object",
"required": ["kind", "content"],
"properties": {
"kind": { "type": "string", "const": "text" },
"content": { "type": "string" }
}
},
"StaticVarSegment": {
"type": "object",
"required": ["kind", "name", "value"],
"properties": {
"kind": { "type": "string", "const": "static_var" },
"name": { "type": "string", "description": "模板变量名" },
"value": { "type": "string", "description": "展开后的值" },
"description": { "type": "string", "description": "简短说明" }
}
},
"SystemPromptSegment": {
"type": "object",
"required": ["kind", "content", "collapsed"],
"properties": {
"kind": { "type": "string", "const": "system_prompt" },
"content": { "type": "string" },
"collapsed": { "type": "boolean" }
}
},
"MemorySegment": {
"type": "object",
"required": ["kind", "items", "collapsed"],
"properties": {
"kind": { "type": "string", "const": "memory" },
"description": { "type": "string" },
"items": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["title", "content"],
"properties": {
"title": { "type": "string" },
"content": { "type": "string" }
}
}
},
"collapsed": { "type": "boolean" }
}
},
"SkillsSegment": {
"type": "object",
"required": ["kind", "items", "collapsed"],
"properties": {
"kind": { "type": "string", "const": "skills" },
"description": { "type": "string" },
"items": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["name", "description"],
"properties": {
"name": { "type": "string" },
"description": { "type": "string" }
}
}
},
"collapsed": { "type": "boolean" }
}
},
"ToolOverviewSegment": {
"type": "object",
"required": ["kind", "items", "collapsed"],
"properties": {
"kind": { "type": "string", "const": "tool_overview" },
"items": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["name", "description", "parameters"],
"properties": {
"name": { "type": "string" },
"description": { "type": "string" },
"parameters": { "type": "string" },
"schema": { "type": "object" }
}
}
},
"collapsed": { "type": "boolean" }
}
},
"ToolCallRequestSegment": {
"type": "object",
"required": ["kind", "toolName", "arguments", "collapsed"],
"properties": {
"kind": { "type": "string", "const": "tool_call_request" },
"toolName": { "type": "string" },
"arguments": { "type": "object" },
"collapsed": { "type": "boolean" }
}
},
"ToolCallResultSegment": {
"type": "object",
"required": ["kind", "toolName", "result", "success", "collapsed"],
"properties": {
"kind": { "type": "string", "const": "tool_call_result" },
"toolName": { "type": "string" },
"result": { "type": "string" },
"success": { "type": "boolean" },
"collapsed": { "type": "boolean" }
}
},
"DocumentSegment": {
"type": "object",
"required": ["kind", "fileName", "mimeType", "snippet", "sizeBytes"],
"properties": {
"kind": { "type": "string", "const": "document" },
"fileName": { "type": "string" },
"mimeType": { "type": "string" },
"snippet": { "type": "string" },
"sizeBytes": { "type": "number" },
"parsedContent": { "type": "string" }
}
},
"LongTextSegment": {
"type": "object",
"required": ["kind", "content", "charCount", "collapsed"],
"properties": {
"kind": { "type": "string", "const": "long_text" },
"content": { "type": "string" },
"charCount": { "type": "number" },
"collapsed": { "type": "boolean" }
}
},
"MediaSegment": {
"type": "object",
"required": ["kind", "mediaType", "url"],
"properties": {
"kind": { "type": "string", "const": "media" },
"mediaType": { "type": "string", "enum": ["image", "audio", "video"] },
"url": { "type": "string" },
"altText": { "type": "string" }
}
}
}
}