38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import type { BottomAnchorRouteRequest } from "@/agent-stream/bottom-anchor-controller";
|
|
|
|
export interface RouteBottomAnchorIntent {
|
|
routeKey: string;
|
|
reason: BottomAnchorRouteRequest["reason"];
|
|
}
|
|
|
|
export function deriveRouteBottomAnchorIntent(input: {
|
|
cachedIntent: RouteBottomAnchorIntent | null;
|
|
routeKey: string | null;
|
|
hasAppliedAuthoritativeHistoryAtEntry: boolean;
|
|
}): RouteBottomAnchorIntent | null {
|
|
if (!input.routeKey) {
|
|
return null;
|
|
}
|
|
if (input.cachedIntent?.routeKey === input.routeKey) {
|
|
return input.cachedIntent;
|
|
}
|
|
return {
|
|
routeKey: input.routeKey,
|
|
reason: input.hasAppliedAuthoritativeHistoryAtEntry ? "resume" : "initial-entry",
|
|
};
|
|
}
|
|
|
|
export function deriveRouteBottomAnchorRequest(input: {
|
|
intent: RouteBottomAnchorIntent | null;
|
|
effectiveAgentId: string | null;
|
|
}): BottomAnchorRouteRequest | null {
|
|
if (!input.intent || !input.effectiveAgentId) {
|
|
return null;
|
|
}
|
|
return {
|
|
reason: input.intent.reason,
|
|
agentId: input.effectiveAgentId,
|
|
requestKey: `${input.intent.routeKey}:${input.intent.reason}`,
|
|
};
|
|
}
|