3203
return new Map();
3204
}
3206
>
const raw = await ref.object.getMetadata(CopilotAgent._META_CHATS);
3207
>
if (!raw) {
3208
return new Map();
3209
}
3210
>
const parsed = JSON.parse(raw) as Record<string, unknown>;
copilotAgent.ts
3211
>
const result = new Map<string, IPersistedChat>();
3212
>
for (const [chatId, value] of Object.entries(parsed)) {
3213
>
// The metadata blob is client-influenced and may be corrupted or
3214
>
// tampered: drop entries that don't carry a usable SDK session id
3215
>
// rather than letting an invalid id reach `client.deleteSession`.
3216
>
if (!value || typeof value !== 'object') {
3217
continue;
3218
}
3219
>
const { sdkSessionId, model } = value as { sdkSessionId?: unknown; model?: unknown };
copilotAgent.ts
3220
>
if (typeof sdkSessionId !== 'string' || !sdkSessionId) {
3221
continue;
3222
}
3223
>
result.set(chatId, { sdkSessionId, ...(model ? { model: model as ModelSelection } : {}) });
copilotAgent.ts
3224
>
}
3225
>
return result;
3226
>
} catch (err) {
3227
this._logService.warn(`[Copilot] Failed to read persisted chats for ${session.toString()}: ${err instanceof Error ? err.message : String(err)}`);
3228
return new Map();
3230
>
ref.dispose();
3231
>
}
3232
}
3233