* fix(app): preserve New Workspace prompts across target changes The New Workspace draft was keyed by the selected host and project, so changing either target replaced the visible prompt with another draft scope. Treat the screen as one persistent draft surface and migrate the newest active legacy draft. * test(app): express draft persistence as user actions * fix(app): clear stale picker PR context * fix(app): persist picker attachment ownership * fix(app): keep workspace target context safe
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { generateMessageId } from "@/types/stream";
|
|
|
|
export const NEW_WORKSPACE_DRAFT_KEY = "new-workspace";
|
|
const NEW_WORKSPACE_FORK_DRAFT_PREFIX = `${NEW_WORKSPACE_DRAFT_KEY}:draft:`;
|
|
|
|
export function generateDraftId(): string {
|
|
return `draft_${generateMessageId()}`;
|
|
}
|
|
|
|
export function buildNewWorkspaceDraftKey(draftId?: string): string {
|
|
const explicitDraftId = draftId?.trim();
|
|
if (explicitDraftId) {
|
|
return `${NEW_WORKSPACE_FORK_DRAFT_PREFIX}${explicitDraftId}`;
|
|
}
|
|
return NEW_WORKSPACE_DRAFT_KEY;
|
|
}
|
|
|
|
export function isLegacyNewWorkspaceDraftKey(draftKey: string): boolean {
|
|
return (
|
|
draftKey.startsWith(`${NEW_WORKSPACE_DRAFT_KEY}:`) &&
|
|
!draftKey.startsWith(NEW_WORKSPACE_FORK_DRAFT_PREFIX)
|
|
);
|
|
}
|
|
|
|
export function buildDraftStoreKey(input: {
|
|
serverId: string;
|
|
agentId: string;
|
|
draftId?: string | null;
|
|
}): string {
|
|
const serverId = input.serverId.trim();
|
|
const explicitDraftId = input.draftId?.trim();
|
|
if (explicitDraftId) {
|
|
return `draft:${serverId}:${explicitDraftId}`;
|
|
}
|
|
return `agent:${serverId}:${input.agentId.trim()}`;
|
|
}
|