fix(mobile): recover pending permission prompts after reconnect and resume (#497)
This commit is contained in:
@@ -992,14 +992,50 @@ class OpencodeService {
|
||||
return result.data || false;
|
||||
}
|
||||
|
||||
async listPendingPermissions(): Promise<PermissionRequest[]> {
|
||||
try {
|
||||
// Permission requests are global across sessions; do not scope by directory.
|
||||
const result = await this.client.permission.list();
|
||||
return (result.data || []) as unknown as PermissionRequest[];
|
||||
} catch {
|
||||
return [];
|
||||
async listPendingPermissions(options?: { directories?: Array<string | null | undefined> }): Promise<PermissionRequest[]> {
|
||||
const fetches: Array<Promise<PermissionRequest[]>> = [];
|
||||
|
||||
const fetchForDirectory = async (directory?: string | null): Promise<PermissionRequest[]> => {
|
||||
try {
|
||||
const trimmed = typeof directory === 'string' ? directory.trim() : '';
|
||||
const result = await this.client.permission.list(trimmed ? { directory: trimmed } : undefined);
|
||||
return (result.data || []) as unknown as PermissionRequest[];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
// Try unscoped first (server may return global pending items).
|
||||
fetches.push(fetchForDirectory(null));
|
||||
|
||||
const uniqueDirectories = new Set<string>();
|
||||
for (const entry of options?.directories ?? []) {
|
||||
const normalized = this.normalizeCandidatePath(entry ?? null);
|
||||
if (normalized) {
|
||||
uniqueDirectories.add(normalized);
|
||||
}
|
||||
}
|
||||
|
||||
for (const directory of uniqueDirectories) {
|
||||
fetches.push(fetchForDirectory(directory));
|
||||
}
|
||||
|
||||
const results = await Promise.all(fetches);
|
||||
const merged: PermissionRequest[] = [];
|
||||
const seenIds = new Set<string>();
|
||||
|
||||
for (const list of results) {
|
||||
for (const item of list) {
|
||||
if (!item || typeof item !== 'object') continue;
|
||||
const id = (item as { id?: unknown }).id;
|
||||
if (typeof id !== 'string' || id.length === 0) continue;
|
||||
if (seenIds.has(id)) continue;
|
||||
seenIds.add(id);
|
||||
merged.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
// Questions ("ask" tool)
|
||||
|
||||
Reference in New Issue
Block a user