24 lines
725 B
TypeScript
24 lines
725 B
TypeScript
import type { RunEvent } from "../domain/agent-run";
|
|
import type { Conversation } from "../domain/conversation";
|
|
import { CoreError } from "../errors/core-error";
|
|
|
|
export function lastSequence(events: readonly RunEvent[]): number {
|
|
return events.at(-1)?.sequence ?? 0;
|
|
}
|
|
|
|
export function safeErrorMessage(cause: unknown): string {
|
|
return cause instanceof CoreError ? cause.message : "模型服务暂时不可用";
|
|
}
|
|
|
|
export function messagesThroughTrigger(
|
|
conversation: Conversation,
|
|
triggerMessageId: string,
|
|
) {
|
|
const index = conversation.messages.findIndex(
|
|
(message) => message.id === triggerMessageId,
|
|
);
|
|
return index < 0
|
|
? conversation.messages
|
|
: conversation.messages.slice(0, index + 1);
|
|
}
|