fix(hooks/thinking-block-validator): replace as any with typed interfaces
Add ThinkingPart and MessageInfoExtended local interfaces Replace 3 as any casts with proper unknown-to-typed casts Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
0cbc6b5410
commit
a82f4ee86a
@ -21,6 +21,18 @@ interface MessageWithParts {
|
|||||||
parts: Part[]
|
parts: Part[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ThinkingPart {
|
||||||
|
thinking?: string
|
||||||
|
text?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MessageInfoExtended {
|
||||||
|
id: string
|
||||||
|
role: string
|
||||||
|
sessionID?: string
|
||||||
|
modelID?: string
|
||||||
|
}
|
||||||
|
|
||||||
type MessagesTransformHook = {
|
type MessagesTransformHook = {
|
||||||
"experimental.chat.messages.transform"?: (
|
"experimental.chat.messages.transform"?: (
|
||||||
input: Record<string, never>,
|
input: Record<string, never>,
|
||||||
@ -91,7 +103,7 @@ function findPreviousThinkingContent(
|
|||||||
for (const part of msg.parts) {
|
for (const part of msg.parts) {
|
||||||
const type = part.type as string
|
const type = part.type as string
|
||||||
if (type === "thinking" || type === "reasoning") {
|
if (type === "thinking" || type === "reasoning") {
|
||||||
const thinking = (part as any).thinking || (part as any).text
|
const thinking = (part as unknown as ThinkingPart).thinking || (part as unknown as ThinkingPart).text
|
||||||
if (thinking && typeof thinking === "string" && thinking.trim().length > 0) {
|
if (thinking && typeof thinking === "string" && thinking.trim().length > 0) {
|
||||||
return thinking
|
return thinking
|
||||||
}
|
}
|
||||||
@ -114,7 +126,7 @@ function prependThinkingBlock(message: MessageWithParts, thinkingContent: string
|
|||||||
const thinkingPart = {
|
const thinkingPart = {
|
||||||
type: "thinking" as const,
|
type: "thinking" as const,
|
||||||
id: `prt_0000000000_synthetic_thinking`,
|
id: `prt_0000000000_synthetic_thinking`,
|
||||||
sessionID: (message.info as any).sessionID || "",
|
sessionID: (message.info as unknown as MessageInfoExtended).sessionID || "",
|
||||||
messageID: message.info.id,
|
messageID: message.info.id,
|
||||||
thinking: thinkingContent,
|
thinking: thinkingContent,
|
||||||
synthetic: true,
|
synthetic: true,
|
||||||
@ -138,7 +150,7 @@ export function createThinkingBlockValidatorHook(): MessagesTransformHook {
|
|||||||
|
|
||||||
// Get the model info from the last user message
|
// Get the model info from the last user message
|
||||||
const lastUserMessage = messages.findLast(m => m.info.role === "user")
|
const lastUserMessage = messages.findLast(m => m.info.role === "user")
|
||||||
const modelID = (lastUserMessage?.info as any)?.modelID || ""
|
const modelID = (lastUserMessage?.info as unknown as MessageInfoExtended)?.modelID || ""
|
||||||
|
|
||||||
// Only process if extended thinking might be enabled
|
// Only process if extended thinking might be enabled
|
||||||
if (!isExtendedThinkingModel(modelID)) {
|
if (!isExtendedThinkingModel(modelID)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user