feat: Prompt Envelope Protocol MVP
- 定义 11 种 Segment 类型(text, static_var, system_prompt, memory, skills, tool_overview, tool_call_request/result, document, long_text, media) - 每种 Segment 有独立的颜色编码和折叠交互 - 通用 CollapsiblePanel + SegmentRenderer 路由架构 - 4 个 Demo 场景覆盖全部 9 种上下文类型 - 导出为 OpenAI Chat Completions Format(model + messages + tools) - tool_overview -> 请求级 tools[](含 JSON Schema) - tool_call_request -> assistant.tool_calls[] - tool_call_result -> tool-role message(ID 配对) - 17 个单元测试全部通过 - React 18 + TypeScript + Vite + Tailwind CSS
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
// ============================================================
|
||||
// Prompt Envelope Protocol — Type Definitions
|
||||
// ============================================================
|
||||
|
||||
// --- 顶层信封 ---
|
||||
export interface PromptEnvelope {
|
||||
version: '1.0'
|
||||
model?: string // 导出时使用的 model 名称,如 'gpt-4-turbo'
|
||||
messages: Message[]
|
||||
}
|
||||
|
||||
// --- 单条消息 ---
|
||||
export interface Message {
|
||||
id: string
|
||||
role: 'system' | 'user' | 'assistant'
|
||||
segments: Segment[]
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
// --- Segment 联合类型 ---
|
||||
export type Segment =
|
||||
| TextSegment
|
||||
| StaticVarSegment
|
||||
| SystemPromptSegment
|
||||
| MemorySegment
|
||||
| SkillSegment
|
||||
| ToolOverviewSegment
|
||||
| ToolCallRequestSegment
|
||||
| ToolCallResultSegment
|
||||
| DocumentSegment
|
||||
| LongTextSegment
|
||||
| MediaSegment
|
||||
|
||||
// --- 各 Segment 类型 ---
|
||||
|
||||
export interface TextSegment {
|
||||
kind: 'text'
|
||||
content: string
|
||||
}
|
||||
|
||||
export interface StaticVarSegment {
|
||||
kind: 'static_var'
|
||||
name: string // e.g. "user_name"
|
||||
value: string // e.g. "张三"
|
||||
}
|
||||
|
||||
export interface SystemPromptSegment {
|
||||
kind: 'system_prompt'
|
||||
content: string
|
||||
collapsed: boolean // default: true
|
||||
}
|
||||
|
||||
export interface MemorySegment {
|
||||
kind: 'memory'
|
||||
items: MemoryItem[]
|
||||
collapsed: boolean
|
||||
}
|
||||
|
||||
export interface MemoryItem {
|
||||
title: string
|
||||
content: string
|
||||
}
|
||||
|
||||
export interface SkillSegment {
|
||||
kind: 'skills'
|
||||
items: SkillItem[]
|
||||
collapsed: boolean
|
||||
}
|
||||
|
||||
export interface SkillItem {
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface ToolOverviewSegment {
|
||||
kind: 'tool_overview'
|
||||
items: ToolItem[]
|
||||
collapsed: boolean
|
||||
}
|
||||
|
||||
export interface ToolItem {
|
||||
name: string
|
||||
description: string
|
||||
parameters: string // 人类可读的参数摘要
|
||||
schema?: Record<string, unknown> // JSON Schema — 导出时作为 tools[].function.parameters
|
||||
}
|
||||
|
||||
export interface ToolCallRequestSegment {
|
||||
kind: 'tool_call_request'
|
||||
toolName: string
|
||||
arguments: Record<string, unknown>
|
||||
collapsed: boolean // default: false
|
||||
}
|
||||
|
||||
export interface ToolCallResultSegment {
|
||||
kind: 'tool_call_result'
|
||||
toolName: string
|
||||
result: string // 摘要文本
|
||||
success: boolean
|
||||
collapsed: boolean // default: true
|
||||
}
|
||||
|
||||
export interface DocumentSegment {
|
||||
kind: 'document'
|
||||
fileName: string
|
||||
mimeType: string
|
||||
snippet: string // 前 200 字符预览
|
||||
sizeBytes: number
|
||||
}
|
||||
|
||||
export interface LongTextSegment {
|
||||
kind: 'long_text'
|
||||
content: string
|
||||
charCount: number
|
||||
collapsed: boolean // default: true
|
||||
}
|
||||
|
||||
export interface MediaSegment {
|
||||
kind: 'media'
|
||||
mediaType: 'image' | 'audio' | 'video'
|
||||
url: string
|
||||
altText?: string
|
||||
}
|
||||
Reference in New Issue
Block a user