|
@@ -7,7 +7,7 @@
|
|
|
*/
|
|
*/
|
|
|
import { PHASE_REMINDER } from '../../config/constants';
|
|
import { PHASE_REMINDER } from '../../config/constants';
|
|
|
import { SLIM_INTERNAL_INITIATOR_MARKER } from '../../utils';
|
|
import { SLIM_INTERNAL_INITIATOR_MARKER } from '../../utils';
|
|
|
-import type { MessageWithParts } from '../types';
|
|
|
|
|
|
|
+import { isUserMessageWithParts, type MessageWithParts } from '../types';
|
|
|
|
|
|
|
|
export { PHASE_REMINDER };
|
|
export { PHASE_REMINDER };
|
|
|
|
|
|
|
@@ -20,9 +20,9 @@ export function createPhaseReminderHook() {
|
|
|
return {
|
|
return {
|
|
|
'experimental.chat.messages.transform': async (
|
|
'experimental.chat.messages.transform': async (
|
|
|
_input: Record<string, never>,
|
|
_input: Record<string, never>,
|
|
|
- output: { messages: MessageWithParts[] },
|
|
|
|
|
|
|
+ output: { messages?: unknown },
|
|
|
): Promise<void> => {
|
|
): Promise<void> => {
|
|
|
- const { messages } = output;
|
|
|
|
|
|
|
+ const messages = Array.isArray(output.messages) ? output.messages : [];
|
|
|
|
|
|
|
|
if (messages.length === 0) {
|
|
if (messages.length === 0) {
|
|
|
return;
|
|
return;
|
|
@@ -30,7 +30,7 @@ export function createPhaseReminderHook() {
|
|
|
|
|
|
|
|
let lastUserMessageIndex = -1;
|
|
let lastUserMessageIndex = -1;
|
|
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
|
- if (messages[i].info.role === 'user') {
|
|
|
|
|
|
|
+ if (isUserMessageWithParts(messages[i])) {
|
|
|
lastUserMessageIndex = i;
|
|
lastUserMessageIndex = i;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -41,6 +41,10 @@ export function createPhaseReminderHook() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const lastUserMessage = messages[lastUserMessageIndex];
|
|
const lastUserMessage = messages[lastUserMessageIndex];
|
|
|
|
|
+ if (!isUserMessageWithParts(lastUserMessage)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const agent = lastUserMessage.info.agent;
|
|
const agent = lastUserMessage.info.agent;
|
|
|
if (agent && agent !== 'orchestrator') {
|
|
if (agent && agent !== 'orchestrator') {
|
|
|
return;
|
|
return;
|