Files
carry 290cc55abf feat: 场景 C 重写为文档解析场景,DocumentCard 增加「查看解析」交互
- DocumentSegment 新增 parsedContent 字段,存储 AI 对文档的解析结果
- DocumentCard 增加「查看解析 / 收起解析」按钮,展开后以 Markdown 渲染解析内容
- 场景 C 从「长文本+文档+多模态」改为「单文档解析」场景,聚焦展示解析功能
- ChatContext 默认 activeDemo 索引修正为 4
2026-06-07 23:12:34 +08:00

151 lines
3.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ============================================================
// 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' | 'tool'
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
}
/**
* 会话级静态变量 —— 在对话开始时注入到 System Prompt 模板中展开。
* 例如 {{current_date}} 在模板中展开为 "2026年6月7日"。
* 这些变量对用户可见,解释了模型"看到"的上下文配置。
*/
export interface StaticVarSegment {
kind: 'static_var'
name: string // 模板变量名,e.g. "current_date"
value: string // 展开后的值,e.g. "2026年6月7日"
description?: string // 简短说明该变量的用途
}
export interface SystemPromptSegment {
kind: 'system_prompt'
content: string
collapsed: boolean // default: true
}
export interface MemorySegment {
kind: 'memory'
description?: string // 简短解释 memory 的作用
items: MemoryItem[]
collapsed: boolean
}
export interface MemoryItem {
title: string
content: string
}
export interface SkillSegment {
kind: 'skills'
description?: string // 简短解释 skills 是什么
items: SkillItem[]
collapsed: boolean
}
/**
* Skill 遵循 Anthropic 渐进式披露机制:
*
* 第 1 层 — 名称 + 一句话描述(始终可见,在 skills 面板中)
* 第 2 层 — 详细描述 + 触发条件(点击展开单个 skill)
* 第 3 层 — 完整指令(再次点击展开 —— 触发时作为一条新消息追加到对话中)
*/
/**
* Skill — 遵循 Anthropic SKILL.md 规范。
*
* 标准 YAML frontmatter 只有两个必填字段:name + description。
* Markdown body 是指令正文,在 skill 被触发时加载到 LLM 上下文。
*
* 渐进式披露 2 层:
* L1 — name + description(始终在上下文中,约 100 词)
* L2 — bodyskill 触发时加载,建议 <500 行)
*/
export interface SkillItem {
name: string
description: string
body: string // Markdown 正文 —— 触发 skill 时加载到 LLM 上下文的指令
}
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
parsedContent?: string // 解析后的完整文本内容(点击"查看解析"时展示)
}
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
}