Files
Prompt-Envelope-Protocol/src/types/protocol.ts
T
carry b8e4961d10 fix: 修正 SkillItem 类型为标准的 Anthropic SKILL.md 格式
将 SkillItem 从虚构的 detail/triggers/instructions/format 字段简化
为标准 SKILL.md 定义:name + description + body。

- protocol.ts: SkillItem 精简为 {name, description, body}
- SkillsView.tsx: 从 3 层改为 2 层渐进式披露
- skills.ts / skills-loader.ts: 去掉多余的映射字段
- .gitignore: 排除外部 skills/ 仓库克隆目录
2026-06-07 22:57:46 +08:00

150 lines
3.7 KiB
TypeScript
Raw 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
}
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
}