Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.3 KB
Raw Blame
import {
  deriveOperationEditedFiles,
  type OperationEditedFile,
} from '@lobechat/builtin-tools/operationArtifacts';
import type { AssistantContentBlock } from '@lobechat/types';
import { useMemo } from 'react';

/**
 * Derived, non-persisted list of files edited across one assistant round.
 *
 * Pass the assistant group's `children` blocks β€” the display selector returns a
 * stable reference across unrelated store ticks (guarded by `isEqual`), so the
 * scan runs once per real message snapshot instead of on every streamed token.
 *
 * The card is a turn-end product, so callers should gate this on generation
 * state and pass `undefined` (β†’ empty result, no card) while the round is still
 * streaming: `children` is rebuilt on every token during generation, which would
 * otherwise re-run the scan continuously for a card nobody sees until the end.
 *
 * `hasWorkSurface` β€” whether the round carries a work anchor (server-runtime
 * operation): only then are sandbox-entity edits dropped in favor of their
 * `file` Work card (see {@link deriveOperationEditedFiles}).
 */
export const useOperationEditedFiles = (
  blocks?: AssistantContentBlock[],
  hasWorkSurface?: boolean,
): OperationEditedFile[] =>
  useMemo(() => deriveOperationEditedFiles(blocks ?? [], hasWorkSurface), [blocks, hasWorkSurface]);