Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companions): make bulk import selection linear
Chrisaa57a71f29fa
diff --git a/packages/maker-shared/src/__tests__/companionImport.test.ts b/packages/maker-shared/src/__tests__/companionImport.test.tsindex 1da6e6c2de..7919a7428b 100644--- a/packages/maker-shared/src/__tests__/companionImport.test.ts+++ b/packages/maker-shared/src/__tests__/companionImport.test.ts@@ -19,6 +19,26 @@ it('switches credentials in the existing selection and keeps bulk selection unamexpect(toggleCompanionImportEntries(entries, personal, all, false)).toEqual([]);});+it.each([false, true])('handles 100,000-entry bulk selection with bounded input reads (%s)', checked => {+ const catalog: CompanionImportEntry[] = Array.from({ length: 100_000 }, (_, index) => ({+ id: `entry-${index}`, name: `Entry ${index}`, category: index < 50_000 ? 'memory' : 'connections', selected: true,+ ...(index < 50_000 ? {} : { exclusiveWith: [`entry-${index ^ 1}`] }),+ }));+ const all = catalog.map(entry => entry.id);+ let reads = 0;+ // Count input work instead of using a machine-dependent timing threshold.+ const requested = new Proxy(all, { get(target, property, receiver) {+ if (typeof property === 'string' && /^\d+$/.test(property) && ++reads > all.length * 4) throw Error('Bulk selection repeatedly rescanned its input');+ return Reflect.get(target, property, receiver);+ } });+ const current = checked ? ['keep-first', 'keep-last'] : ['keep-first', ...all, 'keep-last'];+ expect(toggleCompanionImportEntries(catalog, current, requested, checked)).toEqual(+ checked ? ['keep-first', 'keep-last', ...all.slice(0, 50_000)] : ['keep-first', 'keep-last'],+ );+ expect(all).toEqual(catalog.map(entry => entry.id));+ expect(current).toEqual(checked ? ['keep-first', 'keep-last'] : ['keep-first', ...all, 'keep-last']);+});+it.each([false, true])('negotiates compact selections only when the host advertises support (%s)', async supported => {const many = Array.from({ length: 2100 }, (_, index) => ({ id: `memory-${index}`, name: `Memory ${index}`, category: 'memory' as const, selected: true }));const preview: CompanionImportPreview = { id: 'preview', source: { id: 'source', name: 'Ada', kind: 'hermes' }, name: 'Ada', entries: many, ...(supported ? { selectionRanges: true as const } : {}) };diff --git a/packages/maker-shared/src/companionImport.ts b/packages/maker-shared/src/companionImport.tsindex 7cb2236c50..9edc3d3e54 100644--- a/packages/maker-shared/src/companionImport.ts+++ b/packages/maker-shared/src/companionImport.ts@@ -116,15 +116,17 @@ export function areCompanionImportEntriesSelected(entries: CompanionImportEntry[/** Reuse the existing checkboxes; bulk selection never guesses a credential account. */export function toggleCompanionImportEntries(entries: CompanionImportEntry[], current: string[], ids: string[], checked: boolean): string[] {- if (!checked) return current.filter(id => !ids.includes(id));+ const requested = new Set(ids);+ if (!checked) return current.filter(id => !requested.has(id));const byId = new Map(entries.map(entry => [entry.id, entry]));if (ids.length === 1) {const conflicts = new Set(byId.get(ids[0]!)?.exclusiveWith ?? []);return [...new Set([...current.filter(id => !conflicts.has(id)), ...ids])];}+ const selected = new Set(current);return [...new Set([...current, ...ids.filter(id => {const conflicts = byId.get(id)?.exclusiveWith ?? [];- return !conflicts.some(other => current.includes(other) || ids.includes(other));+ return !conflicts.some(other => selected.has(other) || requested.has(other));})])];}