diff --git a/dsh-pet/src/host/chat.ts b/dsh-pet/src/host/chat.ts index a290d57e0..394d2be2b 100644 --- a/dsh-pet/src/host/chat.ts +++ b/dsh-pet/src/host/chat.ts @@ -13,7 +13,7 @@ import { BlockAssembler, createAssistantMessage, createUserMessage, ReasoningEffortId } from '@deepseek-ai/dsh-llm'; import { actionInstruction, extractChatAction } from './chat-action.ts'; import type { PetImageRef } from './image-attachment.ts'; -import { PET_CALL_IDENTITY, noTextReason } from './llm-call.ts'; +import { PET_CALL_IDENTITY, PET_CHAT_PURPOSE, noTextReason } from './llm-call.ts'; import { supportsReasoningOff } from './llm-reasoning.ts'; import { defaultLog } from './log-file.ts'; import { extractChatImage, memeCatalog, type MemeEntry } from './memes.ts'; @@ -205,6 +205,8 @@ async function generateWith(ctx: { llm?: unknown }, once: GenerateOnce): Promise model: sel.model, // 调用身份(见 llm-call.ts):缺它时 opencode-go 回 400 sessionId: PET_CALL_IDENTITY, + // 调用性质(见 llm-call.ts):声明为辅助调用,代理据此不再按 system 指纹另开会话 + purpose: PET_CHAT_PURPOSE, messages: [ ...historyMessages, createUserMessage({ diff --git a/dsh-pet/src/host/llm-call.test.ts b/dsh-pet/src/host/llm-call.test.ts new file mode 100644 index 000000000..cd2cfebc6 --- /dev/null +++ b/dsh-pet/src/host/llm-call.test.ts @@ -0,0 +1,36 @@ +/** + * 调用性质常量测试 —— 钉住「声明值必须能安全进请求头」这条约束:代理把 `purpose` 原样放进 + * `x-bili-plugin-purpose`,只收可打印 ASCII、长度 ≤64;而 `conversation` 是它的保留值, + * 等值声明会被丢弃,分车道问题随即静默复发。 + * + * 只 import 纯常量模块,不拉起 dsh-llm 依赖链。 + * + * 跑法:node --experimental-strip-types --test src/host/llm-call.test.ts + */ +import { test, describe } from 'node:test'; +import assert from 'node:assert/strict'; + +import { PET_CHAT_PURPOSE, PET_WHISPER_PURPOSE } from './llm-call.ts'; + +/** 代理侧请求头校验的等价规则:可打印 ASCII(无空格/控制符)、非空、长度 ≤64。 */ +const HEADER_SAFE = /^[\x21-\x7e]{1,64}$/; + +describe('调用性质 —— 代理请求头约束', () => { + for (const [label, value] of [ + ['碎碎念', PET_WHISPER_PURPOSE], + ['陪聊', PET_CHAT_PURPOSE], + ] as const) { + test(`${label}的声明值可直接进请求头`, () => { + assert.match(value, HEADER_SAFE); + }); + } + + test('两者互不相同 —— 否则代理的 lane 标签分不出两条调用路径', () => { + assert.notEqual(PET_WHISPER_PURPOSE, PET_CHAT_PURPOSE); + }); + + test('都不落在代理保留值 conversation 上 —— 等值声明会被丢弃,问题静默复发', () => { + assert.notEqual(PET_WHISPER_PURPOSE, 'conversation'); + assert.notEqual(PET_CHAT_PURPOSE, 'conversation'); + }); +}); diff --git a/dsh-pet/src/host/llm-call.ts b/dsh-pet/src/host/llm-call.ts index 274de0bb1..b5ba6bc5f 100644 --- a/dsh-pet/src/host/llm-call.ts +++ b/dsh-pet/src/host/llm-call.ts @@ -13,6 +13,19 @@ */ export const PET_CALL_IDENTITY = 'dsh-pet'; +/** + * 碎碎念的调用性质(dsh-llm `GenerateOptions.purpose`):辅助调用,不是对话。 + * + * 不声明时下游只能按内容猜:billion-context 对 dsh 插件流量按 `system` 指纹分车道, + * 而碎碎念的 system 带实时时间,于是每条都派生一条 `<身份>|sub:` 会话记录, + * 几分钟一条,把正常会话挤出列表。声明后走 side 车道并归并到调用身份(#6880/#6883)。 + * 只为可打印 ASCII、长度 ≤64:该值会被代理原样放进请求头。 + */ +export const PET_WHISPER_PURPOSE = 'pet-whisper'; + +/** 陪聊的调用性质:同样是辅助调用,不占会话车道(理由同 `PET_WHISPER_PURPOSE`)。 */ +export const PET_CHAT_PURPOSE = 'pet-chat'; + /** * 没有正文时,按流终止原因给出要展示的原因。 * @param finish - 流终止块(`BlockAssembler.finish`;dsh-llm 把适配器抛错折进这里,不在流里抛出)。 diff --git a/dsh-pet/src/host/whisper.ts b/dsh-pet/src/host/whisper.ts index ce36c9933..a2021a592 100644 --- a/dsh-pet/src/host/whisper.ts +++ b/dsh-pet/src/host/whisper.ts @@ -11,7 +11,7 @@ */ import { BlockAssembler, createUserMessage, ReasoningEffortId } from '@deepseek-ai/dsh-llm'; -import { PET_CALL_IDENTITY, noTextReason } from './llm-call.ts'; +import { PET_CALL_IDENTITY, PET_WHISPER_PURPOSE, noTextReason } from './llm-call.ts'; import { supportsReasoningOff } from './llm-reasoning.ts'; import { defaultLog } from './log-file.ts'; import { modelCandidates, modelLabel, type ModelRef } from './model-selection.ts'; @@ -120,6 +120,8 @@ async function generateWith( model: sel.model, // 调用身份(见 llm-call.ts):缺它时 opencode-go 回 400 sessionId: PET_CALL_IDENTITY, + // 调用性质(见 llm-call.ts):声明为辅助调用,代理据此不再按 system 指纹另开会话 + purpose: PET_WHISPER_PURPOSE, messages: [ createUserMessage({ content: [