botsDialogConfig.test.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { describe, expect, it } from "vitest";
  2. import type { BotConfig } from "@zcode/shared";
  3. import { ALL_BOT_WORKSPACES } from "@zcode/shared";
  4. import {
  5. BOT_PROVIDERS,
  6. BOT_REPLY_GRANULARITIES,
  7. getBotReplyGranularitiesForProvider,
  8. getBotReplyGranularityEntryForProvider,
  9. getBotProviderRegionTagLabelId,
  10. resolveBotProviderEntry,
  11. } from "../src/botsUi.js";
  12. import enUS from "../src/i18n/locales/en-US.js";
  13. import zhCN from "../src/i18n/locales/zh-CN.js";
  14. describe("BotsDialog config", () => {
  15. it("keeps reply granularity labels localized", () => {
  16. expect(BOT_REPLY_GRANULARITIES.map((item) => item.id)).toEqual([
  17. "assistant_changes",
  18. "assistant_toolcalls_changes",
  19. "summary_changes",
  20. "streaming_card",
  21. ]);
  22. for (const granularity of BOT_REPLY_GRANULARITIES) {
  23. expect(enUS[granularity.labelId]).toBeTruthy();
  24. expect(zhCN[granularity.labelId]).toBeTruthy();
  25. expect(enUS[granularity.descriptionId]).toBeTruthy();
  26. expect(zhCN[granularity.descriptionId]).toBeTruthy();
  27. }
  28. });
  29. it("limits Feishu and Lark reply granularity to streaming cards", () => {
  30. expect(getBotReplyGranularitiesForProvider("feishu").map((item) => item.id)).toEqual([
  31. "streaming_card",
  32. ]);
  33. expect(getBotReplyGranularitiesForProvider("lark").map((item) => item.id)).toEqual([
  34. "streaming_card",
  35. ]);
  36. expect(getBotReplyGranularitiesForProvider("telegram").map((item) => item.id)).toEqual([
  37. "assistant_changes",
  38. "assistant_toolcalls_changes",
  39. "summary_changes",
  40. ]);
  41. expect(
  42. getBotReplyGranularityEntryForProvider("feishu", "assistant_changes").id,
  43. ).toBe("streaming_card");
  44. expect(
  45. getBotReplyGranularityEntryForProvider("telegram", "streaming_card").id,
  46. ).toBe("assistant_changes");
  47. });
  48. it("keeps bind state actions localized", () => {
  49. for (const key of [
  50. "bots.bind",
  51. "bots.unbind",
  52. "bots.unbindSuccess",
  53. "bots.unbindFailed",
  54. "bots.copyBindCommand",
  55. "bots.bindCommandGuide",
  56. "bots.bindCommandStep.copy",
  57. "bots.bindCommandStep.openChat",
  58. "bots.bindCommandStep.send",
  59. "bots.bindCommandCopied",
  60. ]) {
  61. expect(enUS[key]).toBeTruthy();
  62. expect(zhCN[key]).toBeTruthy();
  63. }
  64. });
  65. it("shows Lark as a supported new bot entry and keeps DingTalk coming soon", () => {
  66. expect(BOT_PROVIDERS.find((provider) => provider.id === "lark")).toEqual({
  67. id: "lark",
  68. label: "Lark",
  69. implemented: true,
  70. });
  71. expect(BOT_PROVIDERS.find((provider) => provider.id === "dingding")).toEqual(
  72. {
  73. id: "dingding",
  74. label: "DingTalk",
  75. implemented: false,
  76. },
  77. );
  78. expect(enUS["bots.channel.dingding"]).toBeTruthy();
  79. expect(zhCN["bots.channel.dingding"]).toBeTruthy();
  80. expect(enUS["bots.newBot.providerDescription.lark"]).toBeTruthy();
  81. expect(zhCN["bots.newBot.providerDescription.lark"]).toBeTruthy();
  82. expect(enUS["bots.newBot.providerDescription.dingding"]).toBeTruthy();
  83. expect(zhCN["bots.newBot.providerDescription.dingding"]).toBeTruthy();
  84. });
  85. it("uses welcome screen region tags for Feishu and Lark bot entries", () => {
  86. expect(getBotProviderRegionTagLabelId("lark")).toBe(
  87. "login.oauth.regionTag.zai",
  88. );
  89. expect(getBotProviderRegionTagLabelId("feishu")).toBe(
  90. "login.oauth.regionTag.bigmodel",
  91. );
  92. expect(getBotProviderRegionTagLabelId("telegram")).toBeNull();
  93. expect(enUS["login.oauth.regionTag.zai"]).toBe("Global");
  94. expect(zhCN["login.oauth.regionTag.zai"]).toBe("全球");
  95. expect(enUS["login.oauth.regionTag.bigmodel"]).toBe("CN");
  96. expect(zhCN["login.oauth.regionTag.bigmodel"]).toBe("中国");
  97. });
  98. it("resolves remote-control bot entry to the first existing provider bot", () => {
  99. const bots: BotConfig[] = [
  100. createBot("feishu-later", "feishu"),
  101. createBot("telegram-first", "telegram"),
  102. createBot("telegram-second", "telegram"),
  103. ];
  104. expect(resolveBotProviderEntry(bots, "telegram")).toEqual({
  105. mode: "select",
  106. botId: "telegram-first",
  107. });
  108. });
  109. it("resolves remote-control bot entry to provider creation when no bot exists", () => {
  110. expect(
  111. resolveBotProviderEntry([createBot("weixin-one", "weixin")], "feishu"),
  112. ).toEqual({
  113. mode: "create",
  114. provider: "feishu",
  115. });
  116. });
  117. });
  118. function createBot(id: string, provider: BotConfig["provider"]): BotConfig {
  119. return {
  120. id,
  121. name: "",
  122. provider,
  123. enabled: true,
  124. allowedWorkspaces: [ALL_BOT_WORKSPACES],
  125. allowedCommands: {
  126. readFile: "always",
  127. writeFile: "ask",
  128. runCommand: "ask",
  129. },
  130. currentOptions: {},
  131. replyMode: "assistant_changes",
  132. };
  133. }