mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-29 06:28:23 +02:00
* fix(onboarding): refresh agent cache after import and agent creation Two paths could leave the workspace agent-list query cache stale by the time the dashboard rendered the welcome issue, causing the issue's agent assignee to resolve to "Unknown Agent": 1. StarterContentPrompt.onImport invalidated pins/projects/issues but not agents, and didn't await any of them before navigating — so the issue-detail page could mount and read the cache before TanStack Query had marked the relevant queries stale. 2. OnboardingFlow.handleAgentCreated created the agent without invalidating the agent list, so the dashboard's first mount would read whatever was already cached from earlier in onboarding. Both now invalidate workspaceKeys.agents, and the import flow awaits all invalidations via Promise.all before pushing the navigation, so the next page mount always refetches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(editor): drop editable prop, ContentEditor is editing-only ContentEditor's `editable` prop had zero true callsites left in the codebase — every read-only surface had migrated to ReadonlyContent (react-markdown), and the prop only invited misuse: Tiptap's `useEditor` reads `editable` at mount, so callers that toggled it post-mount (like a chat input that needs to disable on no-agent) silently got stuck in whichever mode the editor first created. Changes: - Remove `editable` prop and default; useEditor and createEditorExtensions no longer take it. - Remove the `"readonly"` className branch and the readonly content sync useEffect (only the editing path remains). - Remove the BubbleMenu and mouseDown editable guards. - Drop LinkReadonly; rename LinkEditable to LinkExtension and use it unconditionally. - Update the docstring to point readers at ReadonlyContent for display surfaces. ReadonlyContent's `.readonly` CSS class stays in content-editor.css — that file's selectors are still used by react-markdown's wrapper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(chat): empty-state by session history, no-agent disabled state Three independent improvements to the chat window's pre-conversation states, sharing a new three-state availability primitive: 1. New `useWorkspaceAgentAvailability()` hook (`"loading" | "none" | "available"`) so callers don't have to reinvent the loading-vs-empty distinction. Treating loading as "no agent" — the easy mistake — caused the chat input to flash a fake disabled state for the few hundred ms after mount, even when the workspace had agents. 2. EmptyState now branches on session history, not agent presence: never-chatted users get a short pitch ("They know your workspace — issues, projects, skills"), returning users get the existing starter prompts. Missing-agent feedback moved to the banner above the input, keeping this surface focused on "what is chat for". 3. No-agent disabled state: when availability resolves to "none", ChatInput dims and stops responding to clicks/keys, with cursor `not-allowed` on hover. The disable lives at the wrapper level (`pointer-events-none` on the inner card, `cursor-not-allowed` on the outer one — splitting layers so hover bubbles to where the browser reads cursor) — we no longer reach into the editor's editable mode, which never switched cleanly post-mount anyway. A `<NoAgentBanner>` (sibling of OfflineBanner, mutually exclusive) states the prerequisite without linking out — no one should be pulled out of chat mid-thought to a settings page. Also: default chat width 420 → 380, since the chat docks at the bottom-right and 420 was crowding everything else. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor(views): align PropRow labels using CSS subgrid The fixed `w-16` (64px) label column on PropRow broke whenever a label rendered wider than 64px (e.g. "Concurrency" in the agent inspector) — the label would overflow into the gap and collide with the value. Switch to subgrid: the parent declares `grid grid-cols-[auto_1fr]` and each PropRow becomes `col-span-2 grid grid-cols-subgrid`. The `auto` track sizes to the widest label across all rows in that parent, so labels always fit and value columns stay aligned across rows without picking a magic pixel width. Updated parents: - agent-detail-inspector Section wrapper - issue-detail Properties group Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
157 lines
5.6 KiB
TypeScript
157 lines
5.6 KiB
TypeScript
/**
|
|
* Shared extension factory for ContentEditor.
|
|
*
|
|
* One function builds the extension array for BOTH edit and readonly modes.
|
|
* This ensures visual consistency — the same extensions parse and render
|
|
* content identically regardless of mode.
|
|
*
|
|
* Split:
|
|
* - Both modes: StarterKit, CodeBlock, Link, Image, Table, Markdown, Mention
|
|
* - Edit only: Typography, Placeholder, markdownPaste, submitShortcut,
|
|
* fileUpload, Mention suggestion popup
|
|
*
|
|
* Link config differs: edit mode has autolink (detects URLs while typing),
|
|
* readonly does not (prevents false positives on display).
|
|
*
|
|
* Mention suggestion is only attached in edit mode — readonly doesn't need
|
|
* the autocomplete popup.
|
|
*
|
|
* All link styling is controlled by content-editor.css (var(--brand) color),
|
|
* not Tailwind HTMLAttributes, to keep a single source of truth.
|
|
*/
|
|
import type { RefObject } from "react";
|
|
import StarterKit from "@tiptap/starter-kit";
|
|
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
|
import { common, createLowlight } from "lowlight";
|
|
import Placeholder from "@tiptap/extension-placeholder";
|
|
import Link from "@tiptap/extension-link";
|
|
import Typography from "@tiptap/extension-typography";
|
|
import Image from "@tiptap/extension-image";
|
|
import TableRow from "@tiptap/extension-table-row";
|
|
import TableHeader from "@tiptap/extension-table-header";
|
|
import TableCell from "@tiptap/extension-table-cell";
|
|
import { Table } from "@tiptap/extension-table";
|
|
import { Markdown } from "@tiptap/markdown";
|
|
import { ReactNodeViewRenderer } from "@tiptap/react";
|
|
import type { AnyExtension } from "@tiptap/core";
|
|
import type { UploadResult } from "@multica/core/hooks/use-file-upload";
|
|
import { BaseMentionExtension } from "./mention-extension";
|
|
import { createMentionSuggestion } from "./mention-suggestion";
|
|
import { CodeBlockView } from "./code-block-view";
|
|
import { createMarkdownPasteExtension } from "./markdown-paste";
|
|
import { createMarkdownCopyExtension } from "./markdown-copy";
|
|
import { createSubmitExtension } from "./submit-shortcut";
|
|
import { createBlurShortcutExtension } from "./blur-shortcut";
|
|
import { createFileUploadExtension } from "./file-upload";
|
|
import { FileCardExtension } from "./file-card";
|
|
import { ImageView } from "./image-view";
|
|
import { BlockMathExtension, InlineMathExtension } from "./math";
|
|
|
|
const lowlight = createLowlight(common);
|
|
|
|
const LinkExtension = Link.extend({ inclusive: false }).configure({
|
|
openOnClick: false,
|
|
autolink: true,
|
|
linkOnPaste: true,
|
|
defaultProtocol: "https",
|
|
});
|
|
|
|
const ImageExtension = Image.extend({
|
|
addAttributes() {
|
|
return {
|
|
...this.parent?.(),
|
|
uploading: {
|
|
default: false,
|
|
renderHTML: (attrs: Record<string, unknown>) =>
|
|
attrs.uploading ? { "data-uploading": "" } : {},
|
|
parseHTML: (el: HTMLElement) => el.hasAttribute("data-uploading"),
|
|
},
|
|
};
|
|
},
|
|
addNodeView() {
|
|
return ReactNodeViewRenderer(ImageView);
|
|
},
|
|
}).configure({
|
|
inline: false,
|
|
allowBase64: false,
|
|
});
|
|
|
|
export interface EditorExtensionsOptions {
|
|
placeholder?: string;
|
|
queryClient?: import("@tanstack/react-query").QueryClient;
|
|
onSubmitRef?: RefObject<(() => void) | undefined>;
|
|
onUploadFileRef?: RefObject<
|
|
((file: File) => Promise<UploadResult | null>) | undefined
|
|
>;
|
|
/** When true, bare Enter also submits (chat-style). Default false. */
|
|
submitOnEnter?: boolean;
|
|
/**
|
|
* When true, the @mention extension is not registered at all. Use for
|
|
* editors where mentioning members/agents has no business meaning (e.g.
|
|
* agent system prompts) — typing `@` becomes inert and any pre-existing
|
|
* `[@user](mention://...)` markdown renders as plain text instead of being
|
|
* parsed into a mention node.
|
|
*/
|
|
disableMentions?: boolean;
|
|
}
|
|
|
|
export function createEditorExtensions(
|
|
options: EditorExtensionsOptions,
|
|
): AnyExtension[] {
|
|
const { placeholder: placeholderText } = options;
|
|
|
|
return [
|
|
StarterKit.configure({
|
|
heading: { levels: [1, 2, 3] },
|
|
link: false,
|
|
codeBlock: false,
|
|
}),
|
|
CodeBlockLowlight.extend({
|
|
addNodeView() {
|
|
return ReactNodeViewRenderer(CodeBlockView);
|
|
},
|
|
}).configure({ lowlight }),
|
|
// ⚠️ Link MUST appear before markdownPaste in this array.
|
|
// linkOnPaste relies on Link's handlePaste plugin firing first;
|
|
// markdownPaste's handlePaste is a catch-all that returns true.
|
|
LinkExtension,
|
|
ImageExtension,
|
|
Table.configure({ resizable: false }),
|
|
TableRow,
|
|
TableHeader,
|
|
TableCell,
|
|
BlockMathExtension,
|
|
InlineMathExtension,
|
|
// 3-space indent so nested ordered lists survive CommonMark in ReadonlyContent.
|
|
Markdown.configure({ indentation: { style: "space", size: 3 } }),
|
|
// Make Cmd+C / Cmd+X / drag write Markdown source to clipboard text/plain
|
|
// so users can copy rich content out as the original Markdown.
|
|
createMarkdownCopyExtension(),
|
|
FileCardExtension,
|
|
...(options.disableMentions
|
|
? []
|
|
: [
|
|
BaseMentionExtension.configure({
|
|
HTMLAttributes: { class: "mention" },
|
|
...(options.queryClient
|
|
? { suggestion: createMentionSuggestion(options.queryClient) }
|
|
: {}),
|
|
}),
|
|
]),
|
|
Typography,
|
|
Placeholder.configure({ placeholder: placeholderText }),
|
|
createMarkdownPasteExtension(),
|
|
createSubmitExtension(
|
|
() => {
|
|
const fn = options.onSubmitRef?.current;
|
|
if (!fn) return false; // no submit wired — let default Enter insert newline
|
|
fn();
|
|
return true;
|
|
},
|
|
{ submitOnEnter: options.submitOnEnter ?? false },
|
|
),
|
|
createBlurShortcutExtension(),
|
|
createFileUploadExtension(options.onUploadFileRef!),
|
|
];
|
|
}
|