Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): 复用安装请求时沿用首次邀请的语言

nanafcfa54ad1b92
diff --git a/apps/desktop/src/main/bot-import/__tests__/host.test.ts b/apps/desktop/src/main/bot-import/__tests__/host.test.ts
index e83b33cb13..ca68d2266b 100644
--- a/apps/desktop/src/main/bot-import/__tests__/host.test.ts
+++ b/apps/desktop/src/main/bot-import/__tests__/host.test.ts
@@ -217,6 +217,21 @@ it('restarts an older install that never saved its checkpoint, as the same reque
expect(createBotProfile).toHaveBeenCalledTimes(1);
expect(h.importDocument).toHaveBeenCalledTimes(1);
});
+it('restarts an older install that never saved its checkpoint in the language it was first invited in', async () => {
+ h.native = true;
+ const entry = (await listNativeBotPackages())[0]!;
+ vi.spyOn(h.store, 'write').mockRejectedValueOnce(new Error('fixture failure before checkpoint'));
+ await inviteNativeBotPackage({ ...entry, locale: 'ja' }, 'renderer:1').catch(() => undefined);
+ const indexes = await fs.readdir(path.join(h.root, 'companion-imports'));
+ expect(indexes).toHaveLength(1);
+ const requestId = indexes[0]!.slice(0, -'.json'.length);
+ await olderInstall(requestId);
+ // The profile name is part of the stored selection identity, so a language switched since then must not change it.
+ const complete = await nativeFinished(await inviteNativeBotPackage({ ...entry, locale: 'en' }, 'renderer:2'));
+ expect(complete.status).toBe('complete'); expect(complete.requestId).toBe(requestId);
+ expect(createBotProfile).toHaveBeenCalledTimes(1);
+ expect(createBotProfile).toHaveBeenCalledWith(expect.objectContaining({ name: entry.locales!.ja!.name }));
+});
it('saves the teammate, opening and routine names in the language the invite was made in', async () => {
h.native = true;
const entry = (await listNativeBotPackages()).find(entry => entry.packageId === 'engineer-bot')!;
diff --git a/apps/desktop/src/main/bot-import/host.ts b/apps/desktop/src/main/bot-import/host.ts
index 6c4cf98336..e05e7952ab 100644
--- a/apps/desktop/src/main/bot-import/host.ts
+++ b/apps/desktop/src/main/bot-import/host.ts
@@ -120,10 +120,12 @@ export async function inviteNativeBotPackage(input: BotPackageIdentity & { local
// The original checkpoint may not have committed. Reuse this request, not
// a second package progress ledger or another companion.
}
+ // A reused request keeps the language it was made in: the profile name is part of its selection identity.
+ const locale = existing ? existing.nativePackage?.locale : input.locale;
const previewId = randomUUID();
- pkg.snapshot.nativePackage!.locale = input.locale;
+ pkg.snapshot.nativePackage!.locale = locale;
// Profile name and description, the opening and the routine names follow the language the invite was made in.
- applyNativeLocale(pkg, input.locale);
+ applyNativeLocale(pkg, locale);
await retainPreview(previewId, { owner: scope.scope, controller, value: pkg.snapshot, createdAt: Date.now() }, scope.assert);
return startCompanionImport({ previewId, requestId: existing?.result.requestId ?? randomUUID(),
name: pkg.snapshot.source.name, avatarImageBase64: pkg.snapshot.avatarImageBase64,