Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(calendar): an IME's confirming Enter no longer creates an event with a half-typed title
hadan897731af5956b554
diff --git a/src/components/RoutineCalendarPage.ime.test.ts b/src/components/RoutineCalendarPage.ime.test.tsnew file mode 100644index 0000000000..32ccef624d--- /dev/null+++ b/src/components/RoutineCalendarPage.ime.test.ts@@ -0,0 +1,96 @@+// @vitest-environment happy-dom+import { createElement } from "react";+import { flushSync } from "react-dom";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import type { Bot } from "@/state/store";++const fixture = vi.hoisted(() => ({ api: vi.fn(), dispatch: vi.fn() }));+vi.mock("@/state/store", async (importOriginal) => {+ const original = await importOriginal<typeof import("@/state/store")>();+ return {+ ...original,+ api: fixture.api,+ useStore: () => ({ state: original.initialState, dispatch: fixture.dispatch }),+ };+});++import { QuickComposer } from "./RoutineCalendarPage";++const bot: Bot = {+ id: "ime-bot", threadId: "ime-thread", name: "Atlas", title: "", description: "",+ color: "blue", notifications: false, unread: false, busy: false, messages: [], section: "",+ modelSelection: { instanceId: "claude", model: "fake" },+};++let root: Root;+let host: HTMLDivElement;+beforeEach(() => {+ fixture.api.mockReset();+ fixture.api.mockResolvedValue({ call: { id: "call-1", name: "周报 huiyi" } });+ host = document.createElement("div");+ document.body.append(host);+ root = createRoot(host);+});+afterEach(() => {+ flushSync(() => root.unmount());+ host.remove();+ vi.clearAllMocks();+});++function open() {+ const onClose = vi.fn();+ const onSavedCall = vi.fn();+ flushSync(() => root.render(createElement(QuickComposer, {+ seed: { kind: "call", at: Date.now() + 3_600_000, durationMinutes: 30, botIds: [bot.id] },+ bots: [bot],+ onClose,+ onMore: vi.fn(),+ onSavedRoutine: vi.fn(),+ onSavedCall,+ })));+ const input = host.querySelector<HTMLInputElement>('input[aria-label]')!;+ return { input, onClose, onSavedCall };+}++function type(input: HTMLInputElement, value: string) {+ const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!;+ flushSync(() => {+ setter.call(input, value);+ input.dispatchEvent(new Event("input", { bubbles: true }));+ });+}++function press(input: HTMLInputElement, init: KeyboardEventInit = {}) {+ return flushSync(() => input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true, ...init })));+}++const IME = [+ { name: "composition", init: { isComposing: true } },+ { name: "IME key code", init: { keyCode: 229 } },+];++describe("calendar quick composer with an input method", () => {+ it.each(IME)("does not create the event on the Enter that belongs to the $name", async ({ init }) => {+ const { input, onClose, onSavedCall } = open();+ type(input, "周报 huiyi");+ press(input, init);+ await Promise.resolve();+ await Promise.resolve();+ expect(fixture.api).not.toHaveBeenCalled();+ expect(onSavedCall).not.toHaveBeenCalled();+ expect(onClose).not.toHaveBeenCalled();+ expect(input.value).toBe("周报 huiyi");+ expect(host.querySelector("input")).toBe(input);+ });++ it("still creates the event on a plain Enter", async () => {+ const { input, onClose, onSavedCall } = open();+ type(input, "Weekly review");+ press(input);+ await vi.waitFor(() => expect(fixture.api).toHaveBeenCalledOnce());+ expect(fixture.api).toHaveBeenCalledWith("/api/calendar-calls", expect.objectContaining({ method: "POST" }));+ await vi.waitFor(() => expect(onSavedCall).toHaveBeenCalledOnce());+ expect(onClose).toHaveBeenCalledOnce();+ });+});diff --git a/src/components/RoutineCalendarPage.tsx b/src/components/RoutineCalendarPage.tsxindex 7216ca11f4..e92e284c3c 100644--- a/src/components/RoutineCalendarPage.tsx+++ b/src/components/RoutineCalendarPage.tsx@@ -1117,7 +1117,7 @@ export function QuickComposer({<button onClick={onClose} className="rounded-full p-1.5 text-ink-secondary hover:bg-inset hover:text-ink" aria-label={t("common.close")}><X size={16} /></button></div><div className="space-y-3 p-4">- <input autoFocus value={name} onChange={(event) => setName(event.target.value)} aria-label={t("routines.editor.titleLabel")} placeholder={t("routines.event.addTitle")} onKeyDown={(event) => { if (event.key === "Enter" && valid) void save(); }} className="w-full border-b border-hairline/60 bg-transparent pb-2 text-[18px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent" />+ <input autoFocus value={name} onChange={(event) => setName(event.target.value)} aria-label={t("routines.editor.titleLabel")} placeholder={t("routines.event.addTitle")} onKeyDown={(event) => { if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return; if (event.key === "Enter" && valid) void save(); }} className="w-full border-b border-hairline/60 bg-transparent pb-2 text-[18px] font-medium text-ink outline-none placeholder:text-ink-tertiary focus:border-accent" />{!routinesOnly && !seed.limitReset && (<div className="flex items-center gap-1 border-b border-hairline/35 pb-2"><button type="button" onClick={() => { setKind("routine"); setBotIds((ids) => ids.slice(0, 1)); }} className={cn("rounded-lg px-3 py-1.5 text-[12px] font-medium", kind === "routine" ? "bg-accent/15 text-accent" : "text-ink-secondary hover:bg-raised hover:text-ink")}>{t("routines.kind.routine")}</button>