feat(webui): add a host directory picker and refine composer controls
This commit is contained in:
1 parent
3865bde3fe
commit
66c8d41f66
32 files changed
+1974
-464
No files matched your search
@@ -46,6 +46,7 @@ import type {
|
||||
ThreadProjectionEvent,
|
||||
WebSearchSettingsUpdate,
|
||||
WorkspacesPayload,
|
||||
WorkspaceDirectoriesPayload,
|
||||
WebuiThreadPersistedPayload,
|
||||
WebuiThreadTraceDetailPayload,
|
||||
WorkspaceScopePayload,
|
||||
@@ -762,6 +763,22 @@ export async function fetchWorkspaces(
|
||||
);
|
||||
}
|
||||
|
||||
export async function fetchWorkspaceDirectories(
|
||||
token: string,
|
||||
path: string,
|
||||
query: string,
|
||||
showHidden: boolean,
|
||||
allowPartial = false,
|
||||
): Promise<WorkspaceDirectoriesPayload> {
|
||||
const params = new URLSearchParams({ path, q: query, hidden: showHidden ? "1" : "0", partial: allowPartial ? "1" : "0" });
|
||||
return request<WorkspaceDirectoriesPayload>(
|
||||
`/api/workspaces/directories?${params}`,
|
||||
token,
|
||||
undefined,
|
||||
API_READ_TIMEOUT_MS,
|
||||
);
|
||||
}
|
||||
|
||||
export async function fetchCliApps(
|
||||
token: string,
|
||||
base: string = "",
|
||||
|
||||
@@ -473,14 +473,35 @@ export interface WorkspaceScopePayload {
|
||||
};
|
||||
}
|
||||
|
||||
export interface ProjectDirectory {
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface WorkspaceDirectoriesPayload {
|
||||
partial?: boolean;
|
||||
path: string;
|
||||
parent: string | null;
|
||||
entries: ProjectDirectory[];
|
||||
truncated: boolean;
|
||||
host: string;
|
||||
platform: string;
|
||||
}
|
||||
|
||||
export interface WorkspacesPayload {
|
||||
schema_version: number;
|
||||
default_access_mode: WebuiDefaultAccessMode;
|
||||
default_scope: WorkspaceScopePayload;
|
||||
recent_projects?: ProjectDirectory[];
|
||||
favorite_projects?: ProjectDirectory[];
|
||||
host?: { name: string; platform: string };
|
||||
controls: {
|
||||
can_change_project: boolean;
|
||||
can_use_full_access: boolean;
|
||||
can_pick_folder?: boolean;
|
||||
can_browse_directories?: boolean;
|
||||
can_resolve_project?: boolean;
|
||||
can_manage_favorites?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { WorkspaceDirectoriesPayload } from "@/lib/types";
|
||||
import { normalizeWorkspacePath, type BrowseWorkspaceDirectories } from "@/lib/workspace";
|
||||
|
||||
const MAX_DIRECTORIES = 64;
|
||||
const DIRECTORY_TTL_MS = 30_000;
|
||||
|
||||
export function createWorkspaceDirectoryCache(browse: BrowseWorkspaceDirectories) {
|
||||
const entries = new Map<string, { result: WorkspaceDirectoriesPayload; expires: number }>();
|
||||
const pending = new Map<string, Promise<WorkspaceDirectoriesPayload>>();
|
||||
const keyFor = (path: string, query: string, hidden: boolean, partial = false) =>
|
||||
JSON.stringify([normalizeWorkspacePath(path.trim()), query, hidden, partial]);
|
||||
|
||||
function peek(path: string, query: string, hidden: boolean, partial = false) {
|
||||
const key = keyFor(path, query, hidden, partial);
|
||||
const entry = entries.get(key);
|
||||
if (!entry) return undefined;
|
||||
entries.delete(key);
|
||||
if (entry.expires <= Date.now()) return undefined;
|
||||
entries.set(key, entry);
|
||||
return entry.result;
|
||||
}
|
||||
|
||||
function load(path: string, query: string, hidden: boolean, partial = false) {
|
||||
const cached = peek(path, query, hidden, partial);
|
||||
if (cached) return Promise.resolve(cached);
|
||||
const key = keyFor(path, query, hidden, partial);
|
||||
const existing = pending.get(key);
|
||||
if (existing) return existing;
|
||||
const request = browse(path, query, hidden, partial).then(result => {
|
||||
entries.delete(key);
|
||||
entries.set(key, { result, expires: Date.now() + DIRECTORY_TTL_MS });
|
||||
if (entries.size > MAX_DIRECTORIES) entries.delete(entries.keys().next().value!);
|
||||
return result;
|
||||
}).finally(() => pending.delete(key));
|
||||
pending.set(key, request);
|
||||
return request;
|
||||
}
|
||||
|
||||
return { peek, load };
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { WorkspaceAccessMode, WorkspaceScopePayload } from "@/lib/types";
|
||||
import type { WorkspaceAccessMode, WorkspaceScopePayload, WorkspaceDirectoriesPayload } from "@/lib/types";
|
||||
|
||||
export function scopeWithAccessMode(
|
||||
scope: WorkspaceScopePayload,
|
||||
@@ -30,6 +30,7 @@ export function isAbsoluteWorkspacePath(path: string): boolean {
|
||||
|| trimmed.startsWith("~/")
|
||||
|| trimmed.startsWith("~\\")
|
||||
|| trimmed.startsWith("/")
|
||||
|| trimmed.startsWith("\\\\")
|
||||
|| /^[A-Za-z]:[\\/]/.test(trimmed)
|
||||
);
|
||||
}
|
||||
@@ -54,3 +55,18 @@ export function sameWorkspacePath(
|
||||
if (!a || !b) return false;
|
||||
return normalizeWorkspacePath(a) === normalizeWorkspacePath(b);
|
||||
}
|
||||
|
||||
export function workspacePathCompletionQuery(path: string): { path: string; query: string } | null {
|
||||
const draft = path.trim();
|
||||
if (!isAbsoluteWorkspacePath(draft)) return null;
|
||||
if (draft === "~") return { path: "~", query: "" };
|
||||
const parts = /^(.*[\\/])([^\\/]*)$/.exec(draft);
|
||||
return parts ? { path: parts[1], query: parts[2] } : null;
|
||||
}
|
||||
|
||||
export function workspaceDirectoryPrefix(path: string): string {
|
||||
const separator = path.includes("\\") ? "\\" : "/";
|
||||
return path.replace(/[\\/]+$/, "") + separator;
|
||||
}
|
||||
|
||||
export type BrowseWorkspaceDirectories = (path: string, query: string, showHidden: boolean, allowPartial?: boolean) => Promise<WorkspaceDirectoriesPayload>;
|
||||
Reference in new issue
Block a user