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。

1.3 KB
Raw Blame
import { useState } from 'react';
import type { RemoteSession } from '@/session/types';

/**
 * A Bot owns and may replace its canonical Session. Mobile may operate the
 * conversation and its permissions; identity, model and Session lifecycle stay with the host.
 */
export function isHostManagedSession(
  session: Pick<RemoteSession, 'source'> | null | undefined,
): boolean {
  return session?.source === 'bot';
}

/** Keep presentation stable while the same task's remote snapshot is unavailable. */
export function useHostManagedSession(
  scope: string,
  session: Pick<RemoteSession, 'source'> | null | undefined,
  pendingValue = true,
): boolean {
  const [observed, setObserved] = useState<{ scope: string; managed: boolean | null }>(
    () => ({ scope, managed: session ? isHostManagedSession(session) : null }),
  );
  const previous = observed.scope === scope ? observed.managed : null;
  // A Bot's ownership cannot turn into an ordinary task during a runtime refresh.
  const managed = previous === true ? true : session ? isHostManagedSession(session) : previous;
  if (observed.scope !== scope || observed.managed !== managed) {
    setObserved({ scope, managed });
  }
  // Controls stay conservative before a snapshot; transcript callers require
  // confirmed ownership so ordinary task history is never filtered on load.
  return managed ?? pendingValue;
}