thought-level-display.fixture.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { useRef, useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import type { IServiceAccessor } from "@zcode/services";
  4. import type { IPlatformService, ZCodeConfigOption } from "@zcode/shared";
  5. import { ThoughtLevelCycleControl } from "@/chat-input-toolbar/ThoughtLevelCycleControl.js";
  6. import { getNextThoughtLevelValue } from "@/chat-input-toolbar/thoughtLevelOptions.js";
  7. import { TooltipProvider } from "@/components/ui/tooltip.js";
  8. import { PlatformProvider } from "@/hooks/usePlatform.js";
  9. import { ServiceProvider } from "@/hooks/useServices.js";
  10. import { ZCodeIntlProvider, useZCodeIntl } from "@/i18n/IntlProvider.js";
  11. import { SubagentReasoningField } from "@/settings/SubagentReasoningField.js";
  12. import { useToolbarShortcutBindings } from "@/v4/composer/toolbarShortcuts.js";
  13. import "@/styles.css";
  14. const params = new URLSearchParams(location.search);
  15. document.documentElement.className =
  16. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  17. const services = { settingService: { get: async () => ({}) } } as unknown as IServiceAccessor;
  18. const platform = {} as IPlatformService;
  19. const values = [
  20. "nothink",
  21. "minimal",
  22. "low",
  23. "medium",
  24. "high",
  25. "xhigh",
  26. "max",
  27. "ultra",
  28. "extra-high",
  29. "extra_high",
  30. "default",
  31. ];
  32. const options = values.map((value) => ({
  33. value,
  34. name: value === "default" ? "Provider default" : value,
  35. }));
  36. const noop = () => {};
  37. function Fixture() {
  38. const { intl } = useZCodeIntl();
  39. const [value, setValue] = useState("minimal");
  40. const [committed, setCommitted] = useState("");
  41. const selectRef = useRef<HTMLSpanElement>(null);
  42. const cycleRef = useRef<HTMLSpanElement>(null);
  43. const option: ZCodeConfigOption = {
  44. id: "thought_level",
  45. category: "thought_level",
  46. type: "select",
  47. currentValue: value,
  48. options,
  49. };
  50. const select = (next: string) => {
  51. setValue(next);
  52. setCommitted(next);
  53. };
  54. useToolbarShortcutBindings({
  55. hasAnyOption: true,
  56. toolbarDisabled: false,
  57. modelMenuDisabled: true,
  58. thoughtOption: option,
  59. onOpenModelMenu: noop,
  60. onCycleSessionMode: noop,
  61. onCycleThoughtLevel: () => {
  62. const next = getNextThoughtLevelValue(option);
  63. if (next !== null) select(next);
  64. },
  65. });
  66. return (
  67. <main className="min-h-screen bg-background p-4 text-ui-base text-foreground space-y-4">
  68. <div className="@container/composer rounded-xl border border-border p-3 space-y-3">
  69. <p>Composer</p>
  70. <div data-testid="select" ref={selectRef}>
  71. <ThoughtLevelCycleControl
  72. intl={intl}
  73. option={option}
  74. triggerRef={selectRef}
  75. onValueChange={select}
  76. indicatorClassName="hidden @xl/composer:block"
  77. restoreFocusSelector={null}
  78. />
  79. </div>
  80. <div data-testid="cycle" ref={cycleRef}>
  81. <ThoughtLevelCycleControl
  82. intl={intl}
  83. option={option}
  84. triggerRef={cycleRef}
  85. onValueChange={select}
  86. interactionMode="cycle"
  87. labelVisibilityClassName="inline-flex"
  88. restoreFocusSelector={null}
  89. />
  90. </div>
  91. </div>
  92. <div data-testid="subagent" className="rounded-xl border border-border p-3 space-y-3">
  93. <p>Subagent</p>
  94. <SubagentReasoningField
  95. disabled={false}
  96. intl={intl}
  97. state={{ kind: "supported", option }}
  98. labelVisibilityClassName="inline-flex"
  99. onValueCommit={select}
  100. />
  101. </div>
  102. <output data-testid="value">{value}</output>
  103. <output data-testid="committed">{committed}</output>
  104. </main>
  105. );
  106. }
  107. createRoot(document.getElementById("root")!).render(
  108. <ServiceProvider services={services}>
  109. <PlatformProvider platform={platform}>
  110. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  111. <TooltipProvider>
  112. <Fixture />
  113. </TooltipProvider>
  114. </ZCodeIntlProvider>
  115. </PlatformProvider>
  116. </ServiceProvider>,
  117. );