Match T3 Code's sidebar, timeline and composer
Reuse the web app's timeline derivation (turn folds, work groups, live work), its sidebar sections and status words, steer-by-default sending, the question panel, decline-with-feedback, and visit/read marking.
This commit is contained in:
1 parent
4f42407099
commit
2dac4763d2
17 files changed
+988
-430
No files matched your search
@@ -0,0 +1,102 @@
|
||||
import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts";
|
||||
import {
|
||||
deriveRunlessWorkStartedAt,
|
||||
deriveThreadActivityRun,
|
||||
deriveThreadStructureRuntime,
|
||||
} from "@t3tools/client-runtime/state/thread-execution";
|
||||
import { derivePendingThreadRequests, type PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests";
|
||||
|
||||
// The web app's own timeline derivation: tui3 shows the same rows, folds and labels.
|
||||
import {
|
||||
computeStableMessagesTimelineRows,
|
||||
deriveMessagesTimelineRowsWithState,
|
||||
type MessagesTimelineRow,
|
||||
type MessagesTimelineRowsInput,
|
||||
type StableMessagesTimelineRowsState,
|
||||
} from "../../vendor/t3code/apps/web/src/components/chat/MessagesTimeline.logic.ts";
|
||||
import {
|
||||
deriveActiveWorkStartedAt,
|
||||
derivePhase,
|
||||
deriveTimelineEntriesFromVisibleTurnItemsWithState,
|
||||
type TimelineEntriesProjection,
|
||||
} from "../../vendor/t3code/apps/web/src/session-logic.ts";
|
||||
|
||||
export type { MessagesTimelineRow } from "../../vendor/t3code/apps/web/src/components/chat/MessagesTimeline.logic.ts";
|
||||
export type { WorkLogEntry } from "../../vendor/t3code/apps/web/src/session-logic.ts";
|
||||
export { liveWorkEntryLabel, workEntryDisplayLabel } from "../../vendor/t3code/apps/web/src/components/chat/MessagesTimeline.logic.ts";
|
||||
|
||||
export interface Timeline {
|
||||
readonly rows: readonly MessagesTimelineRow[];
|
||||
readonly pending: PendingThreadRequests;
|
||||
readonly isWorking: boolean;
|
||||
/** When the current run started working, for "Working for 12s". */
|
||||
readonly workStartedAt: string | null;
|
||||
/** Carried into the next build so unchanged rows keep their identity. */
|
||||
readonly cache: TimelineCache;
|
||||
}
|
||||
|
||||
interface TimelineCache {
|
||||
readonly entries: TimelineEntriesProjection;
|
||||
readonly rows: { readonly input: MessagesTimelineRowsInput; readonly rows: MessagesTimelineRow[] };
|
||||
readonly stable: StableMessagesTimelineRowsState;
|
||||
readonly expandAll: boolean;
|
||||
}
|
||||
|
||||
/** Answers yes for every id: "expand everything" without knowing the group ids up front. */
|
||||
class EverySet<T> extends Set<T> {
|
||||
override has(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const EVERYTHING = new EverySet<never>();
|
||||
const NOTHING = new Set<never>();
|
||||
|
||||
export function buildTimeline(
|
||||
projection: OrchestrationV2ThreadProjection,
|
||||
options: { readonly expandAll: boolean },
|
||||
previous: Timeline | null,
|
||||
): Timeline {
|
||||
const cache = previous?.cache.expandAll === options.expandAll ? previous.cache : null;
|
||||
const entries = deriveTimelineEntriesFromVisibleTurnItemsWithState(
|
||||
{
|
||||
visibleTurnItems: projection.visibleTurnItems,
|
||||
optimisticMessages: [],
|
||||
attempts: projection.attempts,
|
||||
nodes: projection.nodes,
|
||||
plans: projection.plans,
|
||||
},
|
||||
cache?.entries ?? null,
|
||||
);
|
||||
const runtime = deriveThreadStructureRuntime(projection);
|
||||
const latestRun = deriveThreadActivityRun(projection);
|
||||
const runlessStartedAt = deriveRunlessWorkStartedAt(projection);
|
||||
const isWorking = derivePhase(runtime) === "running" || runlessStartedAt !== null;
|
||||
const workStartedAt = deriveActiveWorkStartedAt(latestRun, runtime, null) ?? runlessStartedAt;
|
||||
const pending = derivePendingThreadRequests(projection);
|
||||
const expanded = options.expandAll ? EVERYTHING : NOTHING;
|
||||
const rows = deriveMessagesTimelineRowsWithState(
|
||||
{
|
||||
timelineEntries: entries.entries,
|
||||
pendingApprovalRequestIds: new Set(pending.approvals.map((approval) => approval.requestId)),
|
||||
latestRun,
|
||||
runningRunId: runtime?.activeRunId ?? null,
|
||||
expandedRunIds: expanded,
|
||||
expandedAttemptIds: expanded,
|
||||
expandedWorkGroupIds: expanded,
|
||||
isWorking,
|
||||
runlessWorkActive: runlessStartedAt !== null,
|
||||
activeTurnStartedAt: workStartedAt,
|
||||
turnDiffSummaries: [],
|
||||
supportsConversationRollback: false,
|
||||
},
|
||||
cache?.rows ?? null,
|
||||
);
|
||||
const stable = computeStableMessagesTimelineRows(rows.rows, cache?.stable ?? { byId: new Map(), result: [] });
|
||||
return {
|
||||
rows: stable.result,
|
||||
pending,
|
||||
isWorking,
|
||||
workStartedAt,
|
||||
cache: { entries, rows, stable, expandAll: options.expandAll },
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user