fix(anki): avoid unintended kiku grouping on lookup

This commit is contained in:
2026-02-28 02:19:27 -08:00
parent f0c9c8b668
commit 3229485fa6
7 changed files with 188 additions and 23 deletions

View File

@@ -179,6 +179,7 @@ export class AnkiConnectProxyServer {
if (action !== 'addNote' && action !== 'addNotes' && action !== 'multi') {
return;
}
const shouldFallbackToLatestAdded = this.requestIncludesAddAction(action, requestJson);
const parsedResponse = this.tryParseJsonValue(responseBody);
if (parsedResponse === null || parsedResponse === undefined) {
@@ -194,7 +195,7 @@ export class AnkiConnectProxyServer {
action === 'multi'
? this.collectMultiResultIds(requestJson, responseResult)
: this.collectNoteIdsForAction(action, responseResult);
if (noteIds.length === 0) {
if (noteIds.length === 0 && shouldFallbackToLatestAdded) {
void this.enqueueMostRecentAddedNote();
return;
}
@@ -202,6 +203,28 @@ export class AnkiConnectProxyServer {
this.enqueueNotes(noteIds);
}
private requestIncludesAddAction(action: string, requestJson: Record<string, unknown>): boolean {
if (action === 'addNote' || action === 'addNotes') {
return true;
}
if (action !== 'multi') {
return false;
}
const params =
requestJson.params && typeof requestJson.params === 'object'
? (requestJson.params as Record<string, unknown>)
: null;
const actions = Array.isArray(params?.actions) ? params.actions : [];
if (actions.length === 0) {
return false;
}
return actions.some((entry) => {
if (!entry || typeof entry !== 'object') return false;
const actionName = (entry as Record<string, unknown>).action;
return actionName === 'addNote' || actionName === 'addNotes';
});
}
private async enqueueMostRecentAddedNote(): Promise<void> {
const findNotes = this.deps.findNotes;
if (!findNotes) {