History

fix: address plugin command review findings

t3-code[bot] committed 2 months ago

Commit ceb36401 parent 12b8e9e5 files · +24 −9Browse files

Unified · Split

5 files
  1. apps/mobile/src/features/threads/NewTaskDraftScreen.tsx +3 −1
  2. apps/mobile/src/features/threads/plugin-command-menu.test.ts +7 −0
  3. apps/mobile/src/features/threads/plugin-command-menu.ts +5 −0
  4. apps/server/src/plugins/PluginCommandCatalog.ts +8 −8
  5. packages/contracts/src/pluginCommands.ts +1 −0
apps/mobile/src/features/threads/NewTaskDraftScreen.tsx+3−1
@@ -74,6 +74,7 @@ import { detectComposerTrigger, replaceTextRange } from "@t3tools/shared/compose · 73 unmodified lines
7474 import { ComposerCommandPopover, type ComposerCommandItem } from "./ComposerCommandPopover";
7575 import {
7676 buildMobilePluginCommandItems,
77+ isCollapsedComposerSelection,
7778 reconcileComposerSelectionForTextChange,
7879 } from "./plugin-command-menu";
7980 import { useMobilePluginCommands } from "./use-mobile-plugin-commands";
@@ -146,9 +147,10 @@ export function NewTaskDraftScreen(props: { · 66 unmodified lines
146147 selectedProject?.environmentId ?? null,
147148 );
148149 const pluginCommandTrigger = useMemo(() => {
150+ if (!isCollapsedComposerSelection(composerSelection)) return null;
149151 const trigger = detectComposerTrigger(flow.prompt, composerSelection.end);
150152 return trigger?.kind === "slash-command" ? trigger : null;
151− }, [composerSelection.end, flow.prompt]);
153+ }, [composerSelection, flow.prompt]);
152154 const pluginCommandItems = useMemo<ComposerCommandItem[]>(() => {
153155 if (pluginCommandTrigger === null) return [];
154156 return buildMobilePluginCommandItems(pluginCommands, pluginCommandTrigger.query);
apps/mobile/src/features/threads/plugin-command-menu.test.ts+7−0
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vite-plus/test"; · 1 unmodified line
22
33 import {
44 buildMobilePluginCommandItems,
5+ isCollapsedComposerSelection,
56 reconcileComposerSelectionForTextChange,
67 } from "./plugin-command-menu";
78
@@ -37,3 +38,9 @@ describe("reconcileComposerSelectionForTextChange", () => { · 29 unmodified lines
3738 });
3839 });
3940 });
41+
42+describe("isCollapsedComposerSelection", () => {
43+ it("rejects a highlighted range", () => {
44+ expect(isCollapsedComposerSelection({ start: 0, end: 7 })).toBe(false);
45+ });
46+});
apps/mobile/src/features/threads/plugin-command-menu.ts+5−0
@@ -2,6 +2,11 @@ import type { PluginCommand } from "@t3tools/contracts"; · 1 unmodified line
22
33 import type { ComposerCommandItem } from "./ComposerCommandPopover";
44
5+export const isCollapsedComposerSelection = (selection: {
6+ readonly start: number;
7+ readonly end: number;
8+}): boolean => selection.start === selection.end;
9+
510 export function reconcileComposerSelectionForTextChange(
611 selection: { readonly start: number; readonly end: number },
712 previousLength: number,
apps/server/src/plugins/PluginCommandCatalog.ts+8−8
@@ -55,8 +55,12 @@ type PluginCommandHandler = Effect.Effect< · 54 unmodified lines
5555
5656 export class PluginCommandDefinitionError extends Schema.TaggedErrorClass<PluginCommandDefinitionError>()(
5757 "PluginCommandDefinitionError",
58− { message: Schema.String },
59−) {}
58+ { cause: Schema.Defect(), id: Schema.String },
59+) {
60+ override get message(): string {
61+ return `Plugin command ${this.id} has invalid declarative metadata.`;
62+ }
63+}
6064
6165 export interface PluginCommandRegistration {
6266 readonly command: PluginCommand;
@@ -108,12 +112,7 @@ const catalogFromRuntime = Effect.fn("PluginCommandCatalog.catalogFromRuntime")( · 45 unmodified lines
108112 const snapshot = yield* runtime.contributions(COMMAND_SLOT);
109113 const commands = yield* Effect.forEach(snapshot.entries, (entry) =>
110114 decodePluginCommandEffect(commandInputFromContribution(entry)).pipe(
111− Effect.mapError(
112− () =>
113− new PluginCommandDefinitionError({
114− message: `Plugin command ${entry.id} has invalid declarative metadata.`,
115− }),
116− ),
115+ Effect.mapError((cause) => new PluginCommandDefinitionError({ cause, id: entry.id })),
117116 ),
118117 );
119118 const frozenCommands = commands.map((command) =>
@@ -197,6 +196,7 @@ export const make = Effect.gen(function* () { · 77 unmodified lines
197196 return new PluginCommandNotFoundError({ id: input.id });
198197 }
199198 return new PluginCommandInvocationError({
199+ cause: error,
200200 id: input.id,
201201 message: "Plugin command failed.",
202202 });
packages/contracts/src/pluginCommands.ts+1−0
@@ -58,6 +58,7 @@ export class PluginCommandCatalogChangedError extends Schema.TaggedErrorClass<Pl · 57 unmodified lines
5858 export class PluginCommandInvocationError extends Schema.TaggedErrorClass<PluginCommandInvocationError>()(
5959 "PluginCommandInvocationError",
6060 {
61+ cause: Schema.Defect(),
6162 id: PluginCommandId,
6263 message: TrimmedNonEmptyString.check(Schema.isMaxLength(500)),
6364 },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t