Browse Source

fix: guard message-transform against malformed messages

The experimental.chat.messages.transform handler iterated over
messages with an unsafe cast and accessed info.role and parts
without a type guard. Sub-hooks already use isMessageWithParts
from hooks/types, but the main handler did not, risking runtime
errors on malformed messages.

Import and apply isMessageWithParts before accessing message
properties, consistent with phase-reminder, filter-available-skills
and task-session-manager.

Closes #679
umi008 1 month ago
parent
commit
7b7813f47e
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/index.ts

+ 4 - 1
src/index.ts

@@ -34,7 +34,7 @@ import {
   SessionLifecycle,
 } from './hooks';
 import { processImageAttachments } from './hooks/image-hook';
-import type { MessageWithParts } from './hooks/types';
+import { isMessageWithParts, type MessageWithParts } from './hooks/types';
 import { createInterviewManager } from './interview';
 import { createBuiltinMcps } from './mcp';
 import {
@@ -1103,6 +1103,9 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
       const typedOutput = output as { messages: MessageWithParts[] };
 
       for (const message of typedOutput.messages) {
+        if (!isMessageWithParts(message)) {
+          continue;
+        }
         if (message.info.role !== 'user') {
           continue;
         }