feat(runtime): document 内容类型与持久化(design/24 S2)
- model 新增 ContentTypeDocument + Content 的四字段 + DocumentMessage 构造器 + ValidateDocumentParts(文档部件只允许 RoleUser,非 user ⇒ ErrDocumentOnNonUser,fail-loud)。 - 两个编码器入口(buildMessages / buildAnthropicMessages)对文档部件报 ErrBadRequest: 本期 document 永不抵达编码器,且绝不静默丢块。 - history:拆出 types.go(Message 增 Document 列),新增 document.go(DocumentRef 同时是 落库 JSON 与 DTO 形状,6 字段含 status ⇒ §4.4 的「读不到要可见」;坏列回 unreadable 不静默)。 - chat_messages 加 document 列(迁移 0015 + NewStore 幂等前滚);historyMessage.Document DTO; session_persist 的 messageTextImage → messageTextImageDocument(保留窄视图以免牵连 steer 配对)。 - 只落「引用 + 统计」,绝不落抽取正文(TestPersistedDocumentHoldsNoBody 把全部列拼起来扫正文)。 验收(主会话独立复跑,非自报):隔离 worktree(HEAD + 本切片)go build/vet 绿、 全树 58 包 0 FAIL、linux/amd64 + darwin/arm64 交叉编译绿、18 条 Document* 测试 PASS。 变异独立复现:ValidateDocumentParts 开头 return nil ⇒ 非 user 负例红。
This commit is contained in:
1 parent
407c934a05
commit
6b2b07cbef
15 files changed
+895
-101
No files matched your search
@@ -9,8 +9,13 @@ import (
|
||||
// 字符串与其余按 Anthropic 内容块形式表示的消息。所有
|
||||
// RoleSystem 消息拼接成单个 system 提示词(Anthropic
|
||||
// 把它放在请求根而非 messages 里);没有内容片段的消息
|
||||
// 会被丢弃,因为 Anthropic 拒绝空内容。
|
||||
// 会被丢弃,因为 Anthropic 拒绝空内容。挂在非用户回合上的
|
||||
// 文档部件在这里就被拒绝(design/24 §2.3-③):文档本期永不
|
||||
// 抵达编码器,漏网即编程错误,绝不静默丢块。
|
||||
func buildAnthropicMessages(msgs []Message) (string, []anthropicMessage, error) {
|
||||
if err := ValidateDocumentParts(msgs); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
var sys strings.Builder
|
||||
out := make([]anthropicMessage, 0, len(msgs))
|
||||
for _, m := range msgs {
|
||||
@@ -97,7 +102,10 @@ func encodeAnthropicToolResult(m Message) ([]any, error) {
|
||||
|
||||
// encodeAnthropicContent 把归一化内容片段转成 Anthropic 内容块。
|
||||
// 文本 / 图片 / tool_use(助手)片段在此处理;tool_result
|
||||
// 片段由 encodeAnthropicToolResult 在消息级渲染。
|
||||
// 片段由 encodeAnthropicToolResult 在消息级渲染。文档片段不走
|
||||
// 这里:本期 DeepSeek 的 anthropic 兼容端点明确不支持 document
|
||||
// 块,所以文档部件落到 default 分支被拒绝(design/24 §2.3-②,
|
||||
// fail-loud 绝不静默丢块)。
|
||||
func encodeAnthropicContent(parts []Content) ([]any, error) {
|
||||
blocks := make([]any, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
|
||||
Reference in new issue
Block a user