Compare commits
5 Commits
fix/repl-a
...
fix/472-se
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d51256df6f | ||
|
|
3188f6ac66 | ||
|
|
69ea1f1e4a | ||
|
|
f9ce81bfb3 | ||
|
|
4975cfc2e0 |
@@ -1,5 +1,4 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
import { isDeepStrictEqual } from 'util'
|
||||
import { useRegisterOverlay } from '../../context/overlayContext.js'
|
||||
import type { InputEvent } from '../../ink/events/input-event.js'
|
||||
// eslint-disable-next-line custom-rules/prefer-use-keybindings -- raw space/arrow multiselect input
|
||||
@@ -9,6 +8,7 @@ import {
|
||||
normalizeFullWidthSpace,
|
||||
} from '../../utils/stringUtils.js'
|
||||
import type { OptionWithDescription } from './select.js'
|
||||
import { optionsNavigateEqual } from './use-select-navigation.js'
|
||||
import { useSelectNavigation } from './use-select-navigation.js'
|
||||
|
||||
export type UseMultiSelectStateProps<T> = {
|
||||
@@ -174,7 +174,7 @@ export function useMultiSelectState<T>({
|
||||
// and the deleted ui/useMultiSelectState.ts — without this, MCPServerDesktopImportDialog
|
||||
// keeps colliding servers checked after getAllMcpConfigs() resolves.
|
||||
const [lastOptions, setLastOptions] = useState(options)
|
||||
if (options !== lastOptions && !isDeepStrictEqual(options, lastOptions)) {
|
||||
if (options !== lastOptions && !optionsNavigateEqual(options, lastOptions)) {
|
||||
setSelectedValues(defaultValue)
|
||||
setLastOptions(options)
|
||||
}
|
||||
|
||||
@@ -6,10 +6,34 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { isDeepStrictEqual } from 'util'
|
||||
import OptionMap from './option-map.js'
|
||||
import type { OptionWithDescription } from './select.js'
|
||||
|
||||
/**
|
||||
* Compare two option arrays for structural equality on properties that
|
||||
* affect navigation behavior. ReactNode `label` and function `onChange`
|
||||
* are intentionally excluded — they are identity-unstable (new reference
|
||||
* each render) but don't change navigation semantics.
|
||||
*/
|
||||
export function optionsNavigateEqual<T>(
|
||||
a: OptionWithDescription<T>[],
|
||||
b: OptionWithDescription<T>[],
|
||||
): boolean {
|
||||
if (a.length !== b.length) return false
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
const ao = a[i]!
|
||||
const bo = b[i]!
|
||||
if (
|
||||
ao.value !== bo.value ||
|
||||
ao.disabled !== bo.disabled ||
|
||||
ao.type !== bo.type
|
||||
) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type State<T> = {
|
||||
/**
|
||||
* Map where key is option's value and value is option's index.
|
||||
@@ -524,7 +548,7 @@ export function useSelectNavigation<T>({
|
||||
|
||||
const [lastOptions, setLastOptions] = useState(options)
|
||||
|
||||
if (options !== lastOptions && !isDeepStrictEqual(options, lastOptions)) {
|
||||
if (options !== lastOptions && !optionsNavigateEqual(options, lastOptions)) {
|
||||
dispatch({
|
||||
type: 'reset',
|
||||
state: createDefaultState({
|
||||
|
||||
@@ -68,11 +68,11 @@ When a user describes what they want an agent to do, you will:
|
||||
assistant: "Now let me use the test-runner agent to run the tests"
|
||||
</example>
|
||||
- <example>
|
||||
Context: User is creating an agent to respond to the word "hello" with a friendly jok.
|
||||
user: "Hello"
|
||||
assistant: "I'm going to use the ${AGENT_TOOL_NAME} tool to launch the greeting-responder agent to respond with a friendly joke"
|
||||
Context: User is creating an agent for Claude Code product questions.
|
||||
user: "How do I configure Claude Code hooks?"
|
||||
assistant: "I'm going to use the ${AGENT_TOOL_NAME} tool to launch the claude-code-guide agent to answer the question"
|
||||
<commentary>
|
||||
Since the user is greeting, use the greeting-responder agent to respond with a friendly joke.
|
||||
Since the user is asking how to use Claude Code, use the claude-code-guide agent.
|
||||
</commentary>
|
||||
</example>
|
||||
- If the user mentioned or implied that the agent should be used proactively, you should include examples of this.
|
||||
|
||||
@@ -195,10 +195,12 @@ function convertContentBlocks(
|
||||
// handled separately
|
||||
break
|
||||
case 'thinking':
|
||||
// Append thinking as text with a marker for models that support reasoning
|
||||
if (block.thinking) {
|
||||
parts.push({ type: 'text', text: `<thinking>${block.thinking}</thinking>` })
|
||||
}
|
||||
case 'redacted_thinking':
|
||||
// Strip thinking blocks for OpenAI-compatible providers.
|
||||
// These are Anthropic-specific content types that 3P providers
|
||||
// don't understand. Serializing them as <thinking> text corrupts
|
||||
// multi-turn context: the model sees the tags as part of its
|
||||
// previous reply and may mimic or misattribute them.
|
||||
break
|
||||
default:
|
||||
if (block.text) {
|
||||
|
||||
33
src/services/tools/toolExecution.test.ts
Normal file
33
src/services/tools/toolExecution.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
|
||||
import { SkillTool } from '../../tools/SkillTool/SkillTool.js'
|
||||
import {
|
||||
getSchemaValidationErrorOverride,
|
||||
getSchemaValidationToolUseResult,
|
||||
} from './toolExecution.js'
|
||||
|
||||
describe('getSchemaValidationErrorOverride', () => {
|
||||
test('returns actionable missing-skill error for SkillTool', () => {
|
||||
expect(getSchemaValidationErrorOverride(SkillTool, {})).toBe(
|
||||
'Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||
)
|
||||
})
|
||||
|
||||
test('does not override unrelated tool schema failures', () => {
|
||||
expect(getSchemaValidationErrorOverride({ name: 'Read' } as never, {})).toBe(
|
||||
null,
|
||||
)
|
||||
})
|
||||
|
||||
test('does not override SkillTool when skill is present', () => {
|
||||
expect(
|
||||
getSchemaValidationErrorOverride(SkillTool, { skill: 'commit' }),
|
||||
).toBe(null)
|
||||
})
|
||||
|
||||
test('uses the actionable override for structured toolUseResult too', () => {
|
||||
expect(getSchemaValidationToolUseResult(SkillTool, {} as never)).toBe(
|
||||
'InputValidationError: Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -43,6 +43,7 @@ import { FILE_READ_TOOL_NAME } from '../../tools/FileReadTool/prompt.js'
|
||||
import { FILE_WRITE_TOOL_NAME } from '../../tools/FileWriteTool/prompt.js'
|
||||
import { NOTEBOOK_EDIT_TOOL_NAME } from '../../tools/NotebookEditTool/constants.js'
|
||||
import { POWERSHELL_TOOL_NAME } from '../../tools/PowerShellTool/toolName.js'
|
||||
import { SKILL_TOOL_NAME } from '../../tools/SkillTool/constants.js'
|
||||
import { parseGitCommitId } from '../../tools/shared/gitOperationTracking.js'
|
||||
import {
|
||||
isDeferredTool,
|
||||
@@ -596,6 +597,31 @@ export function buildSchemaNotSentHint(
|
||||
)
|
||||
}
|
||||
|
||||
export function getSchemaValidationErrorOverride(
|
||||
tool: Tool,
|
||||
input: unknown,
|
||||
): string | null {
|
||||
if (tool.name !== SKILL_TOOL_NAME || !input || typeof input !== 'object') {
|
||||
return null
|
||||
}
|
||||
|
||||
const skill = (input as { skill?: unknown }).skill
|
||||
if (skill === undefined || skill === null) {
|
||||
return 'Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).'
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function getSchemaValidationToolUseResult(
|
||||
tool: Tool,
|
||||
input: unknown,
|
||||
fallbackMessage?: string,
|
||||
): string {
|
||||
const override = getSchemaValidationErrorOverride(tool, input)
|
||||
return `InputValidationError: ${override ?? fallbackMessage ?? ''}`
|
||||
}
|
||||
|
||||
async function checkPermissionsAndCallTool(
|
||||
tool: Tool,
|
||||
toolUseID: string,
|
||||
@@ -614,7 +640,9 @@ async function checkPermissionsAndCallTool(
|
||||
// Validate input types with zod (surprisingly, the model is not great at generating valid input)
|
||||
const parsedInput = tool.inputSchema.safeParse(input)
|
||||
if (!parsedInput.success) {
|
||||
let errorContent = formatZodValidationError(tool.name, parsedInput.error)
|
||||
const fallbackErrorContent = formatZodValidationError(tool.name, parsedInput.error)
|
||||
let errorContent =
|
||||
getSchemaValidationErrorOverride(tool, input) ?? fallbackErrorContent
|
||||
|
||||
const schemaHint = buildSchemaNotSentHint(
|
||||
tool,
|
||||
@@ -672,7 +700,11 @@ async function checkPermissionsAndCallTool(
|
||||
tool_use_id: toolUseID,
|
||||
},
|
||||
],
|
||||
toolUseResult: `InputValidationError: ${parsedInput.error.message}`,
|
||||
toolUseResult: getSchemaValidationToolUseResult(
|
||||
tool,
|
||||
input,
|
||||
parsedInput.error.message,
|
||||
),
|
||||
sourceToolAssistantUUID: assistantMessage.uuid,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -156,34 +156,24 @@ ${AGENT_TOOL_NAME}({
|
||||
const currentExamples = `Example usage:
|
||||
|
||||
<example_agent_descriptions>
|
||||
"test-runner": use this agent after you are done writing code to run tests
|
||||
"greeting-responder": use this agent to respond to user greetings with a friendly joke
|
||||
"claude-code-guide": use this agent when the user asks how Claude Code works or how to use its features
|
||||
"statusline-setup": use this agent to configure the user's Claude Code status line setting
|
||||
</example_agent_descriptions>
|
||||
|
||||
<example>
|
||||
user: "Please write a function that checks if a number is prime"
|
||||
assistant: I'm going to use the ${FILE_WRITE_TOOL_NAME} tool to write the following code:
|
||||
<code>
|
||||
function isPrime(n) {
|
||||
if (n <= 1) return false
|
||||
for (let i = 2; i * i <= n; i++) {
|
||||
if (n % i === 0) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
</code>
|
||||
user: "How do I configure Claude Code hooks?"
|
||||
<commentary>
|
||||
Since a significant piece of code was written and the task was completed, now use the test-runner agent to run the tests
|
||||
This is a Claude Code usage question, so use the claude-code-guide agent
|
||||
</commentary>
|
||||
assistant: Uses the ${AGENT_TOOL_NAME} tool to launch the test-runner agent
|
||||
assistant: Uses the ${AGENT_TOOL_NAME} tool to launch the claude-code-guide agent
|
||||
</example>
|
||||
|
||||
<example>
|
||||
user: "Hello"
|
||||
user: "Set up my Claude Code status line"
|
||||
<commentary>
|
||||
Since the user is greeting, use the greeting-responder agent to respond with a friendly joke
|
||||
This matches the statusline-setup agent, so use it to configure the setting
|
||||
</commentary>
|
||||
assistant: "I'm going to use the ${AGENT_TOOL_NAME} tool to launch the greeting-responder agent"
|
||||
assistant: "I'm going to use the ${AGENT_TOOL_NAME} tool to launch the statusline-setup agent"
|
||||
</example>
|
||||
`
|
||||
|
||||
|
||||
31
src/tools/SkillTool/SkillTool.test.ts
Normal file
31
src/tools/SkillTool/SkillTool.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
|
||||
import { SkillTool } from './SkillTool.js'
|
||||
|
||||
describe('SkillTool missing parameter handling', () => {
|
||||
test('missing skill stays required at the schema level', async () => {
|
||||
const parsed = SkillTool.inputSchema.safeParse({})
|
||||
|
||||
expect(parsed.success).toBe(false)
|
||||
})
|
||||
|
||||
test('validateInput still returns an actionable error when called with missing skill', async () => {
|
||||
const result = await SkillTool.validateInput?.({} as never, {
|
||||
options: { tools: [] },
|
||||
messages: [],
|
||||
} as never)
|
||||
|
||||
expect(result).toEqual({
|
||||
result: false,
|
||||
message:
|
||||
'Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||
errorCode: 1,
|
||||
})
|
||||
})
|
||||
|
||||
test('valid skill input still parses and validates', async () => {
|
||||
const parsed = SkillTool.inputSchema.safeParse({ skill: 'commit' })
|
||||
|
||||
expect(parsed.success).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -352,6 +352,16 @@ export const SkillTool: Tool<InputSchema, Output, Progress> = buildTool({
|
||||
toAutoClassifierInput: ({ skill }) => skill ?? '',
|
||||
|
||||
async validateInput({ skill }, context): Promise<ValidationResult> {
|
||||
if (!skill || typeof skill !== 'string') {
|
||||
return {
|
||||
result: false,
|
||||
message:
|
||||
'Missing skill name. Pass the slash command name as the skill parameter ' +
|
||||
'(e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||
errorCode: 1,
|
||||
}
|
||||
}
|
||||
|
||||
// Skills are just skill names, no arguments
|
||||
const trimmed = skill.trim()
|
||||
if (!trimmed) {
|
||||
@@ -434,7 +444,7 @@ export const SkillTool: Tool<InputSchema, Output, Progress> = buildTool({
|
||||
context,
|
||||
): Promise<PermissionDecision> {
|
||||
// Skills are just skill names, no arguments
|
||||
const trimmed = skill.trim()
|
||||
const trimmed = skill ?? ''
|
||||
|
||||
// Remove leading slash if present (for compatibility)
|
||||
const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
|
||||
@@ -592,7 +602,7 @@ export const SkillTool: Tool<InputSchema, Output, Progress> = buildTool({
|
||||
// - Skill is a prompt-based skill
|
||||
|
||||
// Skills are just names, with optional arguments
|
||||
const trimmed = skill.trim()
|
||||
const trimmed = skill ?? ''
|
||||
|
||||
// Remove leading slash if present (for compatibility)
|
||||
const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { expect, test } from 'bun:test'
|
||||
import { z } from 'zod/v4'
|
||||
import { getEmptyToolPermissionContext, type Tool, type Tools } from '../Tool.js'
|
||||
import { SkillTool } from '../tools/SkillTool/SkillTool.js'
|
||||
import { toolToAPISchema } from './api.js'
|
||||
|
||||
test('toolToAPISchema preserves provider-specific schema keywords in input_schema', async () => {
|
||||
@@ -64,3 +65,16 @@ test('toolToAPISchema preserves provider-specific schema keywords in input_schem
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('toolToAPISchema keeps skill required for SkillTool', async () => {
|
||||
const schema = await toolToAPISchema(SkillTool, {
|
||||
getToolPermissionContext: async () => getEmptyToolPermissionContext(),
|
||||
tools: [] as unknown as Tools,
|
||||
agents: [],
|
||||
})
|
||||
|
||||
expect((schema as { input_schema: unknown }).input_schema).toMatchObject({
|
||||
type: 'object',
|
||||
required: ['skill'],
|
||||
})
|
||||
})
|
||||
|
||||
@@ -94,3 +94,22 @@ test('gpt-5.4 family keeps large max output overrides within provider limits', (
|
||||
expect(getMaxOutputTokensForModel('gpt-5.4-mini')).toBe(128_000)
|
||||
expect(getMaxOutputTokensForModel('gpt-5.4-nano')).toBe(128_000)
|
||||
})
|
||||
|
||||
test('MiniMax-M2.7 uses explicit provider-specific context and output caps', () => {
|
||||
process.env.CLAUDE_CODE_USE_OPENAI = '1'
|
||||
delete process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS
|
||||
|
||||
expect(getContextWindowForModel('MiniMax-M2.7')).toBe(204_800)
|
||||
expect(getModelMaxOutputTokens('MiniMax-M2.7')).toEqual({
|
||||
default: 131_072,
|
||||
upperLimit: 131_072,
|
||||
})
|
||||
expect(getMaxOutputTokensForModel('MiniMax-M2.7')).toBe(131_072)
|
||||
})
|
||||
|
||||
test('unknown openai-compatible models still use the conservative fallback window', () => {
|
||||
process.env.CLAUDE_CODE_USE_OPENAI = '1'
|
||||
delete process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS
|
||||
|
||||
expect(getContextWindowForModel('some-unknown-3p-model')).toBe(8_000)
|
||||
})
|
||||
|
||||
@@ -72,16 +72,23 @@ export function getContextWindowForModel(
|
||||
return 1_000_000
|
||||
}
|
||||
|
||||
// OpenAI-compatible provider — use known context windows for the model
|
||||
if (
|
||||
// OpenAI-compatible provider — use known context windows for the model.
|
||||
// Unknown models get a conservative 8k default so auto-compact triggers
|
||||
// before hitting a hard context_window_exceeded error.
|
||||
const isOpenAIProvider =
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_OPENAI) ||
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_GEMINI) ||
|
||||
isEnvTruthy(process.env.CLAUDE_CODE_USE_GITHUB)
|
||||
) {
|
||||
if (isOpenAIProvider) {
|
||||
const openaiWindow = getOpenAIContextWindow(model)
|
||||
if (openaiWindow !== undefined) {
|
||||
return openaiWindow
|
||||
}
|
||||
console.error(
|
||||
`[context] Warning: model "${model}" not in context window table — using conservative 8k default. ` +
|
||||
'Add it to src/utils/model/openaiContextWindows.ts for accurate compaction.',
|
||||
)
|
||||
return 8_000
|
||||
}
|
||||
|
||||
const cap = getModelCapability(model)
|
||||
|
||||
@@ -69,3 +69,93 @@ test('loadConversationForResume rejects oversized transcripts before resume hook
|
||||
)
|
||||
expect(hookSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('deserializeMessagesWithInterruptDetection strips thinking blocks only for OpenAI-compatible providers', async () => {
|
||||
const serializedMessages = [
|
||||
user(id(10), 'hello'),
|
||||
{
|
||||
type: 'assistant',
|
||||
uuid: id(11),
|
||||
parentUuid: id(10),
|
||||
timestamp: ts,
|
||||
cwd: '/tmp',
|
||||
sessionId,
|
||||
version: 'test',
|
||||
message: {
|
||||
role: 'assistant',
|
||||
content: [
|
||||
{ type: 'thinking', thinking: 'secret reasoning' },
|
||||
{ type: 'text', text: 'visible reply' },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'assistant',
|
||||
uuid: id(12),
|
||||
parentUuid: id(11),
|
||||
timestamp: ts,
|
||||
cwd: '/tmp',
|
||||
sessionId,
|
||||
version: 'test',
|
||||
message: {
|
||||
role: 'assistant',
|
||||
content: [{ type: 'thinking', thinking: 'only hidden reasoning' }],
|
||||
},
|
||||
},
|
||||
user(id(13), 'follow up'),
|
||||
]
|
||||
|
||||
mock.module('./model/providers.js', () => ({
|
||||
getAPIProvider: () => 'openai',
|
||||
isOpenAICompatibleProvider: (provider: string) =>
|
||||
provider === 'openai' ||
|
||||
provider === 'gemini' ||
|
||||
provider === 'github' ||
|
||||
provider === 'codex',
|
||||
}))
|
||||
|
||||
const openaiModule = await import(`./conversationRecovery.ts?provider=openai-${Date.now()}`)
|
||||
const thirdParty = openaiModule.deserializeMessagesWithInterruptDetection(serializedMessages as never[])
|
||||
const thirdPartyAssistantMessages = thirdParty.messages.filter(
|
||||
message => message.type === 'assistant',
|
||||
)
|
||||
|
||||
expect(thirdPartyAssistantMessages).toHaveLength(2)
|
||||
expect(thirdPartyAssistantMessages[0]?.message?.content).toEqual([
|
||||
{ type: 'text', text: 'visible reply' },
|
||||
])
|
||||
expect(
|
||||
JSON.stringify(thirdPartyAssistantMessages.map(message => message.message?.content)),
|
||||
).not.toContain('secret reasoning')
|
||||
expect(
|
||||
JSON.stringify(thirdPartyAssistantMessages.map(message => message.message?.content)),
|
||||
).not.toContain('only hidden reasoning')
|
||||
|
||||
mock.restore()
|
||||
mock.module('./model/providers.js', () => ({
|
||||
getAPIProvider: () => 'bedrock',
|
||||
isOpenAICompatibleProvider: (provider: string) =>
|
||||
provider === 'openai' ||
|
||||
provider === 'gemini' ||
|
||||
provider === 'github' ||
|
||||
provider === 'codex',
|
||||
}))
|
||||
|
||||
const bedrockModule = await import(`./conversationRecovery.ts?provider=bedrock-${Date.now()}`)
|
||||
const anthropicCompatible = bedrockModule.deserializeMessagesWithInterruptDetection(serializedMessages as never[])
|
||||
const anthropicAssistantMessages = anthropicCompatible.messages.filter(
|
||||
message => message.type === 'assistant',
|
||||
)
|
||||
|
||||
expect(anthropicAssistantMessages).toHaveLength(2)
|
||||
expect(anthropicAssistantMessages[0]?.message?.content).toEqual([
|
||||
{ type: 'thinking', thinking: 'secret reasoning' },
|
||||
{ type: 'text', text: 'visible reply' },
|
||||
])
|
||||
expect(
|
||||
JSON.stringify(anthropicAssistantMessages.map(message => message.message?.content)),
|
||||
).toContain('secret reasoning')
|
||||
expect(
|
||||
JSON.stringify(anthropicAssistantMessages.map(message => message.message?.content)),
|
||||
).not.toContain('only hidden reasoning')
|
||||
})
|
||||
|
||||
@@ -13,6 +13,7 @@ const originalSimple = process.env.CLAUDE_CODE_SIMPLE
|
||||
const sessionId = '00000000-0000-4000-8000-000000001999'
|
||||
const ts = '2026-04-02T00:00:00.000Z'
|
||||
|
||||
|
||||
function id(n: number): string {
|
||||
return `00000000-0000-4000-8000-${String(n).padStart(12, '0')}`
|
||||
}
|
||||
@@ -76,4 +77,3 @@ test('loadConversationForResume rejects oversized reconstructed transcripts', as
|
||||
'Reconstructed transcript is too large to resume safely',
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
type FileHistorySnapshot,
|
||||
} from './fileHistory.js'
|
||||
import { logError } from './log.js'
|
||||
import { getAPIProvider } from './model/providers.js'
|
||||
import {
|
||||
createAssistantMessage,
|
||||
createUserMessage,
|
||||
@@ -177,6 +178,25 @@ export type DeserializeResult = {
|
||||
turnInterruptionState: TurnInterruptionState
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove thinking/redacted_thinking content blocks from assistant messages.
|
||||
* Messages that become empty after stripping are removed entirely.
|
||||
*/
|
||||
function stripThinkingBlocks(messages: NormalizedMessage[]): NormalizedMessage[] {
|
||||
return messages.reduce<NormalizedMessage[]>((acc, msg) => {
|
||||
if (msg.type !== 'assistant' || !Array.isArray(msg.message?.content)) {
|
||||
acc.push(msg)
|
||||
return acc
|
||||
}
|
||||
const filtered = msg.message.content.filter(
|
||||
(block: { type?: string }) => block.type !== 'thinking' && block.type !== 'redacted_thinking',
|
||||
)
|
||||
if (filtered.length === 0) return acc
|
||||
acc.push({ ...msg, message: { ...msg.message, content: filtered } })
|
||||
return acc
|
||||
}, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes messages from a log file into the format expected by the REPL.
|
||||
* Filters unresolved tool uses, orphaned thinking messages, and appends a
|
||||
@@ -227,10 +247,19 @@ export function deserializeMessagesWithInterruptDetection(
|
||||
filteredToolUses,
|
||||
) as NormalizedMessage[]
|
||||
|
||||
// Strip thinking/redacted_thinking content blocks from assistant messages
|
||||
// when resuming against a 3P provider. These Anthropic-specific blocks cause
|
||||
// 400 errors or context corruption on OpenAI-compatible providers (issue #248 finding 5).
|
||||
const provider = getAPIProvider()
|
||||
const isThirdPartyProvider = provider !== 'firstParty' && provider !== 'bedrock' && provider !== 'vertex' && provider !== 'foundry'
|
||||
const thinkingStripped = isThirdPartyProvider
|
||||
? stripThinkingBlocks(filteredThinking)
|
||||
: filteredThinking
|
||||
|
||||
// Filter out assistant messages with only whitespace text content.
|
||||
// This can happen when model outputs "\n\n" before thinking, user cancels mid-stream.
|
||||
const filteredMessages = filterWhitespaceOnlyAssistantMessages(
|
||||
filteredThinking,
|
||||
thinkingStripped,
|
||||
) as NormalizedMessage[]
|
||||
|
||||
const internalState = detectTurnInterruption(filteredMessages)
|
||||
|
||||
@@ -44,6 +44,10 @@ const OPENAI_CONTEXT_WINDOWS: Record<string, number> = {
|
||||
'mistral-large-latest': 131_072,
|
||||
'mistral-small-latest': 131_072,
|
||||
|
||||
// MiniMax
|
||||
'MiniMax-M2.7': 204_800,
|
||||
'minimax-m2.7': 204_800,
|
||||
|
||||
// Google (via OpenRouter)
|
||||
'google/gemini-2.0-flash':1_048_576,
|
||||
'google/gemini-2.5-pro': 1_048_576,
|
||||
@@ -110,6 +114,10 @@ const OPENAI_MAX_OUTPUT_TOKENS: Record<string, number> = {
|
||||
'mistral-large-latest': 32_768,
|
||||
'mistral-small-latest': 32_768,
|
||||
|
||||
// MiniMax
|
||||
'MiniMax-M2.7': 131_072,
|
||||
'minimax-m2.7': 131_072,
|
||||
|
||||
// Google (via OpenRouter)
|
||||
'google/gemini-2.0-flash': 8_192,
|
||||
'google/gemini-2.5-pro': 65_536,
|
||||
|
||||
Reference in New Issue
Block a user