Files
DeepTutor/web/components/space/learning/PathTitle.tsx
Bingxi Zhao (Frank) bd80a4d28a release: v1.5.17
Partners stop being a deployment-wide admin resource and become
per-user: three nested rights (manage / use / neither) replace the
blanket admin gate on the router, each member can build and own their
own, and every person's conversations with a partner stay private to
their account. Grants keep working and now offer only admin-managed
partners. Channel runtime state moves from one directory per channel to
one per partner — copied, not moved, and only when its owner is
unambiguous — so two partners can finally run the same channel.

Around that: a knowledge base can track GitHub repositories and re-sync
their Markdown (#903); Antigravity CLI joins My Agents now that Gemini
CLI is retired (#828); personal WeChat signs in from a QR code drawn in
the browser instead of the server log (#951); a chat account can be
linked to a DeepTutor account with /link; containers re-apply the extras
they declare instead of losing them at compose down (#762); and
`deeptutor doctor` answers whether a workspace is ready to run (#959).

Reliability, largely from community PRs: embeddings survive a
rate-limited provider through key rotation, a retry budget and a global
throttle (#962); MinerU parsing and code execution work on Windows
(#844, #964); indexing fails bounded instead of hanging (#946); MinerU
page-layout blocks stop being indexed as content (#949); voice uploads
carry a MIME the transcription API accepts (#945); and reasoning effort
can be overridden per conversation (#641).

Release plumbing: notes in assets/releases/ver1-5-17.md, v1.5.13
archived, __version__ 1.5.17, README Releases row and all eleven
translations synced.

Two defects found by the release gate and fixed here:

- Six partner routes — the four channel-onboarding endpoints and both
  WeChat QR endpoints — kept the _auth-only mount they had inherited
  from the blanket admin gate, so any signed-in account could start a
  QR login for someone else's partner and write a bot token into its
  channel config. All six now declare _MANAGEABLE, and a sweep test
  asserts no {partner_id} route is left ungated.
- A configured api_key became `str | list[str]` when key rotation
  landed, but ten call sites pass it somewhere that takes one key; a
  list would have rendered into an Authorization header verbatim.
  keypool.primary_api_key reduces at each boundary.

Gates: pre-commit (all 15 hooks), ruff check + format, pytest
5276 passed, web 605 node tests, docs build.
2026-08-25 02:24:35 +08:00

137 lines
4.5 KiB
TypeScript

"use client";
import { Check, Pencil, X } from "lucide-react";
import { useEffect, useRef, useState } from "react";
import type { Translate } from "./format";
/**
* The path's name, and the only place it can be changed.
*
* A path is named by the tutor when it is built, which makes that name a good
* default and a poor final answer — it is the learner's course, so the learner
* gets to say what it is called. Editing happens in place rather than through a
* dialog: the title is one line, and a modal for one line reads as a bigger
* commitment than renaming actually is.
*
* Submitting an empty name is allowed and meaningful — it hands the path back
* to its derived name (the tutor's, or the first module's) instead of pinning
* an empty string.
*
* Losing focus does NOT save. A rename is a deliberate act, and committing on
* blur turns "clicked somewhere else" into a silent rename — while also racing
* whatever focus the field was given when it opened. Blur only closes an
* editor the learner never changed.
*/
export function PathTitle({
name,
onRename,
tr,
}: {
name: string;
/** Resolves once the new name is committed; may reject. */
onRename: (name: string) => Promise<void>;
tr: Translate;
}) {
const [editing, setEditing] = useState(false);
const [draft, setDraft] = useState(name);
const [saving, setSaving] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
// Reopen on a different path (or after a rename lands) with that path's name,
// never with whatever was half-typed for the previous one.
useEffect(() => {
if (!editing) setDraft(name);
}, [name, editing]);
useEffect(() => {
if (editing) inputRef.current?.select();
}, [editing]);
const commit = async () => {
if (saving) return;
const next = draft.trim();
if (next === name.trim()) {
setEditing(false);
return;
}
setSaving(true);
try {
await onRename(next);
setEditing(false);
} catch {
// Keep the editor open with the text still in it — the alternative is
// silently discarding what they typed.
} finally {
setSaving(false);
}
};
const cancel = () => {
setDraft(name);
setEditing(false);
};
if (!editing) {
return (
<div className="flex min-w-0 items-center gap-1.5">
<h2 className="truncate text-sm font-semibold text-[var(--foreground)]">
{name}
</h2>
{/* Always present, like the reset/delete controls beside it. A
hover-revealed affordance does not exist on a touch screen. */}
<button
onClick={() => setEditing(true)}
title={tr("重命名", "Rename")}
className="shrink-0 cursor-pointer rounded p-1 text-[var(--muted-foreground)]/60 transition-colors hover:bg-[var(--accent)] hover:text-[var(--foreground)]"
>
<Pencil className="h-3 w-3" />
</button>
</div>
);
}
return (
<div className="flex min-w-0 items-center gap-1.5">
<input
ref={inputRef}
value={draft}
autoFocus
disabled={saving}
onChange={(event) => setDraft(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Enter") void commit();
if (event.key === "Escape") cancel();
}}
onBlur={() => {
if (draft.trim() === name.trim()) setEditing(false);
}}
maxLength={200}
placeholder={tr("这条路叫什么?", "What is this path called?")}
className="min-w-0 flex-1 rounded-md border border-[var(--border)] bg-[var(--background)] px-2 py-1 text-sm text-[var(--foreground)] outline-none focus:border-[var(--primary)] disabled:opacity-60"
/>
{/* mousedown, not click: blur fires first and would commit-then-cancel. */}
<button
onMouseDown={(event) => {
event.preventDefault();
void commit();
}}
title={tr("保存", "Save")}
className="shrink-0 cursor-pointer rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"
>
<Check className="h-3.5 w-3.5" />
</button>
<button
onMouseDown={(event) => {
event.preventDefault();
cancel();
}}
title={tr("取消", "Cancel")}
className="shrink-0 cursor-pointer rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"
>
<X className="h-3.5 w-3.5" />
</button>
</div>
);
}