Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

941 B
Raw Blame
import { CINDY_MAKE_ENABLED, isCindyMakeSource } from '@cindy/maker-shared/cindy-make-feature';
import type { DurableOutboxRecord } from './durableOutbox';
import type { OutboxSessionPolicy } from './durableOutboxDelivery';

type SessionSource = { id: string; source?: string | null };

export async function cindyMakeOutboxPolicy(record: DurableOutboxRecord, deps: {
  knownSession(): SessionSource | undefined;
  readSession(): Promise<SessionSource | null>;
  isCurrent(): boolean;
}): Promise<OutboxSessionPolicy> {
  if (CINDY_MAKE_ENABLED) return 'deliver';
  let session = deps.knownSession();
  if (session?.id !== record.item.sessionId || session.source === undefined) {
    try {
      session = await deps.readSession() ?? undefined;
    } catch {
      return 'wait';
    }
  }
  if (!deps.isCurrent() || session?.id !== record.item.sessionId) return 'wait';
  return isCindyMakeSource(session.source) ? 'discard' : 'deliver';
}