mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-12-01 01:29:35 +08:00
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
/** Durable Session-message acceptance checks shared by provisioning and mailbox recovery. */
|
|
|
|
import type { UserMessage } from '@deepseek-ai/dsh-llm'
|
|
import type { SessionEvent } from '@deepseek-ai/dsh-session'
|
|
|
|
type InboxProjection = Record<'next-turn' | 'next-step', UserMessage[]>
|
|
|
|
/** Fold the durable inbox suffix into the messages still awaiting a claim. */
|
|
function pendingInboxMessages(events: readonly SessionEvent[]): UserMessage[] {
|
|
const inbox: InboxProjection = { 'next-turn': [], 'next-step': [] }
|
|
for (const event of events) {
|
|
if (event.type !== 'agent/inbox/spliced') continue
|
|
const pending = inbox[event.data.target]
|
|
pending.splice(event.data.start, event.data.removedCount ?? 0, ...event.data.inserted)
|
|
}
|
|
return [...inbox['next-turn'], ...inbox['next-step']]
|
|
}
|
|
|
|
/**
|
|
* Test whether one message is model-visible or still durably pending.
|
|
* @param events - one Session's non-inherited event suffix.
|
|
* @param predicate - identity check for the accepted message.
|
|
* @returns whether history or the current inbox contains a match.
|
|
*/
|
|
export function messageAccepted(
|
|
events: readonly SessionEvent[],
|
|
predicate: (message: UserMessage) => boolean,
|
|
): boolean {
|
|
return events.some(event => event.type === 'user/message' && predicate(event.data))
|
|
|| pendingInboxMessages(events).some(predicate)
|
|
}
|