Skip to content
TypeScript

fix(composer): typing a price no longer opens the skill menu (#21519)

MarcoDotIO1ee0241730ef
diff --git a/apps/web/src/composer-logic.test.ts b/apps/web/src/composer-logic.test.ts
index 69d02eb3bf8..6bbc30d0ade 100644
--- a/apps/web/src/composer-logic.test.ts
+++ b/apps/web/src/composer-logic.test.ts
@@ -266,6 +266,18 @@ describe("detectComposerTrigger", () => {
expect(trigger).toBeNull();
});
+ it.each([
+ "It costs $5",
+ "budget $9.99",
+ "only $.99",
+ "about €20",
+ "raise $10k",
+ "raise $10k.",
+ "is it $5?",
+ ])("does not detect a skill trigger for the amount in %j", (text) => {
+ expect(detectComposerTrigger(text, text.length)).toBeNull();
+ });
+
it("detects a pull request number at a token boundary", () => {
const text = "Compare this with #8737";
diff --git a/apps/web/src/composer-logic.ts b/apps/web/src/composer-logic.ts
index 7046abd6ed2..95e1d73c022 100644
--- a/apps/web/src/composer-logic.ts
+++ b/apps/web/src/composer-logic.ts
@@ -9,7 +9,7 @@ import {
serializeAssistantCitation,
withAssistantCitationComment,
} from "@t3tools/shared/assistantCitations";
-import { isPathWord } from "@t3tools/shared/composerTrigger";
+import { isCurrencyAmountQuery, isPathWord } from "@t3tools/shared/composerTrigger";
import {
splitPromptIntoComposerSegments,
type ComposerPromptSegment,
@@ -302,6 +302,7 @@ export function detectComposerTrigger(text: string, cursorInput: number): Compos
}
const skillPrefix = /^\p{Sc}/u.exec(token);
if (skillPrefix) {
+ if (isCurrencyAmountQuery(token.slice(skillPrefix[0].length))) return null;
return {
kind: "skill",
query: token.slice(skillPrefix[0].length),
diff --git a/packages/shared/src/composerTrigger.test.ts b/packages/shared/src/composerTrigger.test.ts
index 677f77c20a4..221ddb5b804 100644
--- a/packages/shared/src/composerTrigger.test.ts
+++ b/packages/shared/src/composerTrigger.test.ts
@@ -41,6 +41,28 @@ describe("detectComposerTrigger", () => {
rangeEnd: text.length,
});
});
+
+ it.each([
+ "It costs $5",
+ "budget $9.99",
+ "only $.99",
+ "about €20",
+ "raise $10k",
+ "$1,000",
+ "£2e6",
+ "raise $10k.",
+ "is it $5?",
+ "(about $9.99)",
+ ])("does not open the skill menu for the amount in %j", (text) =>
+ expect(detectComposerTrigger(text, text.length)).toBeNull(),
+ );
+
+ it.each(["$", "$1password", "$2fa"])("still detects the skill prefix %j", (text) => {
+ expect(detectComposerTrigger(text, text.length)).toMatchObject({
+ kind: "skill",
+ query: text.slice(1),
+ });
+ });
});
describe("serializeComposerFileLink", () => {
diff --git a/packages/shared/src/composerTrigger.ts b/packages/shared/src/composerTrigger.ts
index f8f77ffae3e..389a2cc916d 100644
--- a/packages/shared/src/composerTrigger.ts
+++ b/packages/shared/src/composerTrigger.ts
@@ -62,6 +62,15 @@ export function isPathWord(
return text.slice(wordStart + 1, wordEnd).includes("/");
}
+/**
+ * `$5`, `€9.99` and `$10k` are money, not skills. Matches the amounts the inline skill
+ * token regexes already refuse to render as skills, plus the punctuation prose puts after
+ * one (`$10k.`, `($5)`).
+ */
+export function isCurrencyAmountQuery(query: string): boolean {
+ return /^\.?[0-9][0-9,._]*(?:[kKmMbBtT]|[eE][0-9]+)?[.,;:!?)]*$/.test(query);
+}
+
export function detectComposerTrigger(
text: string,
cursorInput: number,
@@ -132,6 +141,7 @@ export function detectComposerTrigger(
};
const skillPrefix = /^\p{Sc}/u.exec(token);
if (skillPrefix) {
+ if (isCurrencyAmountQuery(token.slice(skillPrefix[0].length))) return null;
return {
kind: "skill",
query: token.slice(skillPrefix[0].length),