fix(session): ignore internal synthetic turns
This commit is contained in:
@@ -3,7 +3,11 @@ import { describe, expect, it } from "bun:test"
|
||||
import { TeamModeConfigSchema } from "../../config/schema/team-mode"
|
||||
import { createTeamModeStatusInjector } from "./hook"
|
||||
|
||||
function createOutput(sessionID: string, text = "original message"): {
|
||||
function createOutput(
|
||||
sessionID: string,
|
||||
text = "original message",
|
||||
options?: { synthetic?: boolean }
|
||||
): {
|
||||
messages: Array<{
|
||||
info: { role: string; sessionID: string }
|
||||
parts: Array<{ type: string; text?: string; synthetic?: boolean }>
|
||||
@@ -16,7 +20,13 @@ function createOutput(sessionID: string, text = "original message"): {
|
||||
role: "user",
|
||||
sessionID,
|
||||
},
|
||||
parts: [{ type: "text", text }],
|
||||
parts: [
|
||||
{
|
||||
type: "text",
|
||||
text,
|
||||
...(options?.synthetic === true ? { synthetic: true } : {}),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -111,6 +121,22 @@ describe("createTeamModeStatusInjector", () => {
|
||||
expect(output.messages[0]?.parts[0]?.text).toBe(".")
|
||||
})
|
||||
|
||||
it("does not inject team mode status for synthetic team prompts", async () => {
|
||||
// given
|
||||
const hook = createTeamModeStatusInjector(TeamModeConfigSchema.parse({ enabled: true }))
|
||||
const output = createOutput("session-team-mode", "team mode please", { synthetic: true })
|
||||
|
||||
// when
|
||||
await hook["experimental.chat.messages.transform"]?.(
|
||||
{ sessionID: "session-team-mode" },
|
||||
output,
|
||||
)
|
||||
|
||||
// then
|
||||
expect(output.messages).toHaveLength(1)
|
||||
expect(output.messages[0]?.parts[0]?.text).toBe("team mode please")
|
||||
})
|
||||
|
||||
it("does not inject team mode status when the team keyword is disabled", async () => {
|
||||
// given
|
||||
const hook = createTeamModeStatusInjector(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { TeamModeConfig } from "../../config/schema/team-mode"
|
||||
import type { KeywordDetectorConfig } from "../../config/schema/keyword-detector"
|
||||
import type { TeamModeConfig } from "../../config/schema/team-mode"
|
||||
import { isRealUserMessage } from "../../shared/internal-initiator-marker"
|
||||
import { detectKeywordsWithType, extractPromptText } from "../keyword-detector/detector"
|
||||
|
||||
type TransformPart = {
|
||||
@@ -58,7 +59,8 @@ function resolveSessionID(
|
||||
|
||||
function findLastUserMessageIndex(messages: MessageWithParts[]): number {
|
||||
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
||||
if (messages[index]?.info.role === "user") {
|
||||
const message = messages[index]
|
||||
if (message?.info.role === "user") {
|
||||
return index
|
||||
}
|
||||
}
|
||||
@@ -83,6 +85,9 @@ function latestUserMessageRequestsTeamMode(
|
||||
if (message === undefined) {
|
||||
return false
|
||||
}
|
||||
if (!isRealUserMessage(message)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const promptText = extractPromptText(message.parts)
|
||||
return detectKeywordsWithType(
|
||||
|
||||
Reference in New Issue
Block a user