GeezerVison is showing github.com — fix(web): skill chips in chat open the same details popover as the co… · pingdotgg/t3code@278588a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatMarkdown.browser.test.tsx +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts"; | 2 | 2 | import { AsyncResult } from "effect/reactivity"; | 3 | 3 | import { type ReactElement } from "react"; | 4 | 4 | import { describe, expect, it, vi } from "vite-plus/test"; | | 5 | +import { page, userEvent } from "vite-plus/test/browser"; | 5 | 6 |
| 6 | 7 | import { act, render } from "../../test/render"; | 7 | 8 | import "../index.css"; | @@ -260,6 +261,37 @@ describe("ChatMarkdown workspace file opens", () => { | 260 | 261 | }); | 261 | 262 | }); | 262 | 263 |
| | 264 | +describe("ChatMarkdown skill chips", () => { | | 265 | + it("shows the skill's details and opens its instructions", async () => { | | 266 | + setup(); | | 267 | + const threadRef = { | | 268 | + environmentId: EnvironmentId.make("workspace"), | | 269 | + threadId: ThreadId.make("thread"), | | 270 | + }; | | 271 | + await using screen = await renderText("Run $review now", { | | 272 | + threadRef, | | 273 | + skills: [ | | 274 | + { | | 275 | + name: "review", | | 276 | + displayName: "Review", | | 277 | + description: "Reviews the current branch.", | | 278 | + path: "/skills/review/SKILL.md", | | 279 | + enabled: true, | | 280 | + }, | | 281 | + ], | | 282 | + }); | | 283 | + using openFile = vi | | 284 | + .spyOn(useRightPanelStore.getState(), "openFile") | | 285 | + .mockImplementation(() => {}); | | 286 | + | | 287 | + await userEvent.click(screen.getByRole("button", { name: "Skill Review. Show details" })); | | 288 | + await expect.element(page.getByText("Reviews the current branch.")).toBeVisible(); | | 289 | + await userEvent.click(page.getByRole("button", { name: "View instructions" })); | | 290 | + | | 291 | + expect(openFile).toHaveBeenCalledExactlyOnceWith(threadRef, "/skills/review/SKILL.md"); | | 292 | + }); | | 293 | +}); | | 294 | + | 263 | 295 | describe("ChatMarkdown headings", () => { | 264 | 296 | it("never gives two headings the same id, even when a suffix matches another heading", async () => { | 265 | 297 | setup(); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatMarkdown.tsx +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -227,7 +227,7 @@ interface ChatMarkdownProps { | 227 | 227 | environmentId?: EnvironmentId | undefined; | 228 | 228 | onTaskListChange?: ((input: { markerOffset: number; checked: boolean }) => void) | undefined; | 229 | 229 | isStreaming?: boolean; | 230 | | - skills?: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>; | | 230 | + skills?: ReadonlyArray<ServerProviderSkill>; | 231 | 231 | className?: string; | 232 | 232 | lineBreaks?: boolean; | 233 | 233 | parseRawHtml?: boolean; | @@ -250,7 +250,7 @@ export interface ChatMarkdownContextReference { | 250 | 250 | label: string; | 251 | 251 | } | 252 | 252 |
| 253 | | -const EMPTY_MARKDOWN_SKILLS: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">> = []; | | 253 | +const EMPTY_MARKDOWN_SKILLS: ReadonlyArray<ServerProviderSkill> = []; | 254 | 254 | const EMPTY_REMARK_PLUGINS: NonNullable<ReactMarkdownOptions["remarkPlugins"]> = []; | 255 | 255 |
| 256 | 256 | const ARTIFACT_TEMPLATE_ICON_BY_KIND = { | @@ -958,8 +958,8 @@ const CHAT_MARKDOWN_COMPONENTS = { | 958 | 958 | return <div {...props}>{children}</div>; | 959 | 959 | }, | 960 | 960 | p: function MarkdownParagraph({ node: _node, children, ...props }) { | 961 | | - const { skills } = use(ChatMarkdownRendererContext); | 962 | | - return <p {...props}>{renderSkillInlineMarkdownChildren(children, skills)}</p>; | | 961 | + const { skills, threadRef } = use(ChatMarkdownRendererContext); | | 962 | + return <p {...props}>{renderSkillInlineMarkdownChildren(children, skills, threadRef)}</p>; | 963 | 963 | }, | 964 | 964 | blockquote: function MarkdownBlockquote({ node: _node, children, ...props }) { | 965 | 965 | const alert = | @@ -994,12 +994,12 @@ const CHAT_MARKDOWN_COMPONENTS = { | 994 | 994 | ); | 995 | 995 | }, | 996 | 996 | li: function MarkdownListItem({ node, children, ...props }) { | 997 | | - const { skills } = use(ChatMarkdownRendererContext); | | 997 | + const { skills, threadRef } = use(ChatMarkdownRendererContext); | 998 | 998 | // Resolve checkbox markers by offset to avoid rerendering list items on every streamed token. | 999 | 999 | const isTaskItem = String(props.className ?? "").includes("task-list-item"); | 1000 | 1000 | return ( | 1001 | 1001 | <li {...props} data-list-item-offset={isTaskItem ? node?.position?.start.offset : undefined}> | 1002 | | - {renderSkillInlineMarkdownChildren(children, skills)} | | 1002 | + {renderSkillInlineMarkdownChildren(children, skills, threadRef)} | 1003 | 1003 | </li> | 1004 | 1004 | ); | 1005 | 1005 | }, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditorTiptap.tsx +7-21Lines changed: 7 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -108,11 +108,9 @@ import { cn, isMacPlatform } from "~/lib/utils"; | 108 | 108 | import { basenameOfPath } from "~/pierre-icons"; | 109 | 109 | import { WorkspaceEntryTooltip } from "./chat/WorkspaceEntryIcon"; | 110 | 110 | import { FileTagChipContent } from "./chat/FileTagChip"; | 111 | | -import { SkillChipIcon } from "./chat/SkillInlineText"; | | 111 | +import { SkillChipPopover, skillPopoverDescription } from "./chat/SkillInlineText"; | 112 | 112 | import { AssistantCitationChip } from "./chat/AssistantCitationChip"; | 113 | 113 | import { getTimelinePageScrollKey } from "./chat/pageScrollController"; | 114 | | -import { ContextChipPopover } from "./contextChipParts"; | 115 | | -import { Button } from "./ui/button"; | 116 | 114 | import { ContextChip } from "./ContextChip"; | 117 | 115 | import { | 118 | 116 | ComposerContextActionsContext, | @@ -348,31 +346,19 @@ function ComposerSkillNodeView({ node }: NodeViewProps) { | 348 | 346 | const skill = skills.find( | 349 | 347 | (candidate) => candidate.name === skillName && isProviderSkillUserInvocable(candidate), | 350 | 348 | ); | 351 | | - const description = skill | 352 | | - ? skill.description?.trim() || skill.shortDescription?.trim() | 353 | | - : skillDescription; | 354 | 349 | // The node outlives a provider switch, so its stored label can be another provider's. | 355 | 350 | const skillLabel = skill | 356 | 351 | ? formatProviderSkillDisplayName(skill) | 357 | 352 | : (node.attrs.skillLabel as string) || skillName; | 358 | 353 | return ( | 359 | 354 | <NodeViewWrapper as="span" className={CHIP_NODE_SELECTION_CLASS_NAME}> | 360 | | - <ContextChipPopover | 361 | | - kind="skill" | 362 | | - icon={<SkillChipIcon />} | | 355 | + <SkillChipPopover | 363 | 356 | label={skillLabel} | 364 | | - accessibleLabel={`Skill ${skillLabel}`} | 365 | | - > | 366 | | - <div className="space-y-3 p-2 text-sm"> | 367 | | - <p className="font-medium">{skillLabel}</p> | 368 | | - <p>{description || "No description is available for this skill."}</p> | 369 | | - {skill?.path && actions.environmentId ? ( | 370 | | - <Button variant="outline" size="sm" onClick={() => actions.openMention(skill.path)}> | 371 | | - View instructions | 372 | | - </Button> | 373 | | - ) : null} | 374 | | - </div> | 375 | | - </ContextChipPopover> | | 357 | + description={skill ? skillPopoverDescription(skill) : skillDescription} | | 358 | + onViewInstructions={ | | 359 | + skill?.path && actions.environmentId ? () => actions.openMention(skill.path) : undefined | | 360 | + } | | 361 | + /> | 376 | 362 | </NodeViewWrapper> | 377 | 363 | ); | 378 | 364 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/MessagesTimeline.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -157,7 +157,7 @@ function TimelineListFooter({ | 157 | 157 | ); | 158 | 158 | } | 159 | 159 |
| 160 | | -const EMPTY_TIMELINE_SKILLS: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">> = []; | | 160 | +const EMPTY_TIMELINE_SKILLS: ReadonlyArray<ServerProviderSkill> = []; | 161 | 161 | const TIMELINE_MAINTAIN_SCROLL_AT_END = { | 162 | 162 | animated: false, | 163 | 163 | on: { | @@ -253,7 +253,7 @@ interface MessagesTimelineProps { | 253 | 253 | resolvedTheme: "light" | "dark"; | 254 | 254 | timestampFormat: TimestampFormat; | 255 | 255 | workspaceRoot: string | undefined; | 256 | | - skills?: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>; | | 256 | + skills?: ReadonlyArray<ServerProviderSkill>; | 257 | 257 | runs: ReadonlyArray<HandoffTimelineRun>; | 258 | 258 | anchorMessageId: MessageId | null; | 259 | 259 | onAnchorReady: (messageId: MessageId, anchorIndex: number) => void; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/SkillInlineText.tsx +61-13Lines changed: 61 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { ScopedThreadRef, ServerProviderSkill } from "@t3tools/contracts"; | 1 | 2 | import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills"; | 2 | 3 | import { Children, cloneElement, isValidElement, type ReactNode } from "react"; | 3 | | -import { matchInlineSkills, type InlineSkill } from "@t3tools/shared/inlineSkills"; | | 4 | +import { matchInlineSkills } from "@t3tools/shared/inlineSkills"; | 4 | 5 |
| | 6 | +import { useRightPanelStore } from "~/rightPanelStore"; | 5 | 7 | import { SKILL_CHIP_ICON_SVG } from "../composerInlineChip"; | 6 | | -import { ContextChip, ContextChipLabel } from "../ContextChip"; | | 8 | +import { ContextChipPopover } from "../contextChipParts"; | | 9 | +import { Button } from "../ui/button"; | 7 | 10 |
| 8 | | -function SkillInlineText(props: { text: string; skills: ReadonlyArray<InlineSkill> }) { | | 11 | +function SkillInlineText(props: { | | 12 | + text: string; | | 13 | + skills: ReadonlyArray<ServerProviderSkill>; | | 14 | + threadRef: ScopedThreadRef | undefined; | | 15 | +}) { | 9 | 16 | const nodes: ReactNode[] = []; | 10 | 17 | let cursor = 0; | 11 | 18 |
| 12 | 19 | for (const { start, end, skill, rawText } of matchInlineSkills(props.text, props.skills)) { | 13 | 20 | if (start > cursor) { | 14 | 21 | nodes.push(props.text.slice(cursor, start)); | 15 | 22 | } | 16 | | - nodes.push(<SkillChip key={`${start}:${skill.name}`} skill={skill} rawText={rawText} />); | | 23 | + nodes.push( | | 24 | + <SkillChipPopover | | 25 | + key={`${start}:${skill.name}`} | | 26 | + label={formatProviderSkillDisplayName(skill)} | | 27 | + description={skillPopoverDescription(skill)} | | 28 | + copyMarkdown={rawText} | | 29 | + onViewInstructions={skillInstructionsOpener(props.threadRef, skill)} | | 30 | + />, | | 31 | + ); | 17 | 32 | cursor = end; | 18 | 33 | } | 19 | 34 |
| @@ -28,11 +43,12 @@ function SkillInlineText(props: { text: string; skills: ReadonlyArray<InlineSkil | 28 | 43 |
| 29 | 44 | export function renderSkillInlineMarkdownChildren( | 30 | 45 | children: ReactNode, | 31 | | - skills: ReadonlyArray<InlineSkill>, | | 46 | + skills: ReadonlyArray<ServerProviderSkill>, | | 47 | + threadRef: ScopedThreadRef | undefined, | 32 | 48 | ): ReactNode { | 33 | 49 | return Children.map(children, (child) => { | 34 | 50 | if (typeof child === "string") { | 35 | | - return <SkillInlineText text={child} skills={skills} />; | | 51 | + return <SkillInlineText text={child} skills={skills} threadRef={threadRef} />; | 36 | 52 | } | 37 | 53 | if (!isValidElement<{ children?: ReactNode; node?: { tagName?: string } }>(child)) { | 38 | 54 | return child; | @@ -48,21 +64,53 @@ export function renderSkillInlineMarkdownChildren( | 48 | 64 | return cloneElement( | 49 | 65 | child, | 50 | 66 | undefined, | 51 | | - renderSkillInlineMarkdownChildren(child.props.children, skills), | | 67 | + renderSkillInlineMarkdownChildren(child.props.children, skills, threadRef), | 52 | 68 | ); | 53 | 69 | }); | 54 | 70 | } | 55 | 71 |
| 56 | | -function SkillChip(props: { skill: InlineSkill; rawText: string }) { | | 72 | +export function skillPopoverDescription( | | 73 | + skill: Pick<ServerProviderSkill, "description" | "shortDescription">, | | 74 | +) { | | 75 | + return skill.description?.trim() || skill.shortDescription?.trim() || null; | | 76 | +} | | 77 | + | | 78 | +export function skillInstructionsOpener( | | 79 | + threadRef: ScopedThreadRef | null | undefined, | | 80 | + skill: Pick<ServerProviderSkill, "path"> | undefined, | | 81 | +) { | | 82 | + if (!threadRef || !skill?.path) return undefined; | | 83 | + return () => useRightPanelStore.getState().openFile(threadRef, skill.path); | | 84 | +} | | 85 | + | | 86 | +export function SkillChipPopover(props: { | | 87 | + label: string; | | 88 | + description: string | null | undefined; | | 89 | + copyMarkdown?: string | undefined; | | 90 | + onViewInstructions: (() => void) | undefined; | | 91 | +}) { | 57 | 92 | return ( | 58 | | - <ContextChip kind="skill" data-markdown-copy={props.rawText}> | 59 | | - <SkillChipIcon /> | 60 | | - <ContextChipLabel>{formatProviderSkillDisplayName(props.skill)}</ContextChipLabel> | 61 | | - </ContextChip> | | 93 | + <ContextChipPopover | | 94 | + kind="skill" | | 95 | + icon={<SkillChipIcon />} | | 96 | + label={props.label} | | 97 | + accessibleLabel={`Skill ${props.label}`} | | 98 | + copyMarkdown={props.copyMarkdown} | | 99 | + > | | 100 | + <div className="space-y-3 p-2 text-sm"> | | 101 | + <p className="font-medium">{props.label}</p> | | 102 | + <p>{props.description || "No description is available for this skill."}</p> | | 103 | + {props.onViewInstructions ? ( | | 104 | + <Button variant="outline" size="sm" onClick={props.onViewInstructions}> | | 105 | + View instructions | | 106 | + </Button> | | 107 | + ) : null} | | 108 | + </div> | | 109 | + </ContextChipPopover> | 62 | 110 | ); | 63 | 111 | } | 64 | 112 |
| 65 | | -export function SkillChipIcon() { | | 113 | +function SkillChipIcon() { | 66 | 114 | return ( | 67 | 115 | <span | 68 | 116 | aria-hidden="true" | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/TimelineUserMessageRow.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -735,7 +735,7 @@ const COLLAPSED_USER_MESSAGE_FADE_MASK = `linear-gradient(to bottom, black calc( | 735 | 735 | const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(props: { | 736 | 736 | text: string; | 737 | 737 | renderContextReference: (reference: ChatMarkdownContextReference) => ReactNode; | 738 | | - skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>; | | 738 | + skills: ReadonlyArray<ServerProviderSkill>; | 739 | 739 | markdownCwd: string | undefined; | 740 | 740 | collapsible?: boolean; | 741 | 741 | footer?: ReactNode; | @@ -811,7 +811,7 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop | 811 | 811 | const UserMessageBody = memo(function UserMessageBody(props: { | 812 | 812 | text: string; | 813 | 813 | renderContextReference?: (reference: ChatMarkdownContextReference) => ReactNode; | 814 | | - skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>; | | 814 | + skills: ReadonlyArray<ServerProviderSkill>; | 815 | 815 | markdownCwd: string | undefined; | 816 | 816 | }) { | 817 | 817 | const ctx = use(TimelineRowCtx); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/UserMessageContextChips.tsx +16-23Lines changed: 16 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,7 +31,6 @@ import { TerminalContextInlineChip } from "./TerminalContextInlineChip"; | 31 | 31 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; | 32 | 32 | import { | 33 | 33 | ContextChipPopover as UserMessageContextPopover, | 34 | | - ContextChipShell, | 35 | 34 | FileChip, | 36 | 35 | ImageChipButton, | 37 | 36 | PULL_REQUEST_CHIP_KINDS, | @@ -48,7 +47,11 @@ import { formatComposerContextReference } from "@t3tools/shared/composerContextR | 48 | 47 | import { ContextChip, ContextChipLabel, type ContextChipKind } from "../ContextChip"; | 49 | 48 | import { createContextPresentationRegistry } from "../contextPresentationRegistry"; | 50 | 49 | import type { ChatMarkdownContextReference } from "../ChatMarkdown"; | 51 | | -import { SkillChipIcon } from "./SkillInlineText"; | | 50 | +import { | | 51 | + SkillChipPopover, | | 52 | + skillInstructionsOpener, | | 53 | + skillPopoverDescription, | | 54 | +} from "./SkillInlineText"; | 52 | 55 | import { formatWorkspaceRelativePath } from "../../filePathDisplay"; | 53 | 56 | import { | 54 | 57 | buildReviewCommentRenderablePatch, | @@ -99,22 +102,18 @@ function UserMessageMentionChip(props: { | 99 | 102 | ); | 100 | 103 | } | 101 | 104 |
| 102 | | -function UserMessageContextChip(props: { | 103 | | - icon: ReactNode; | 104 | | - label: string; | 105 | | - kindLabel?: string; | | 105 | +function UserMessageSkillChip(props: { | | 106 | + record: Extract<KnownComposerContextRecord, { kind: "skill" }>; | 106 | 107 | copyMarkdown: string; | 107 | | - tooltip?: string; | 108 | | - kind: ContextChipKind; | 109 | 108 | }) { | | 109 | + const { skills, threadRef } = use(TimelineRowCtx); | | 110 | + const skill = skills.find((candidate) => candidate.name === props.record.name); | 110 | 111 | return ( | 111 | | - <ContextChipShell | 112 | | - kind={props.kind} | 113 | | - icon={props.icon} | 114 | | - label={props.label} | 115 | | - aria-label={props.kindLabel ? `${props.kindLabel}, ${props.label}` : undefined} | 116 | | - data-markdown-copy={props.copyMarkdown} | 117 | | - tooltip={props.tooltip} | | 112 | + <SkillChipPopover | | 113 | + label={props.record.label || props.record.name} | | 114 | + description={skill ? skillPopoverDescription(skill) : null} | | 115 | + copyMarkdown={props.copyMarkdown} | | 116 | + onViewInstructions={skillInstructionsOpener(threadRef, skill)} | 118 | 117 | /> | 119 | 118 | ); | 120 | 119 | } | @@ -315,14 +314,7 @@ const userMessageContextPresentationRegistry = createContextPresentationRegistry | 315 | 314 | canRender: (record) => record.kind === "skill", | 316 | 315 | render: (record, context) => | 317 | 316 | record.kind === "skill" ? ( | 318 | | - <UserMessageContextChip | 319 | | - icon={<SkillChipIcon />} | 320 | | - label={record.label || record.name} | 321 | | - kindLabel="Skill" | 322 | | - tooltip={`$${record.name}`} | 323 | | - copyMarkdown={context.copyMarkdown} | 324 | | - kind="skill" | 325 | | - /> | | 317 | + <UserMessageSkillChip record={record} copyMarkdown={context.copyMarkdown} /> | 326 | 318 | ) : ( | 327 | 319 | <UnavailableUserMessageContextChip {...context} /> | 328 | 320 | ), | @@ -562,6 +554,7 @@ function UserMessageReviewCommentCard({ comment }: { comment: ReviewCommentConte | 562 | 554 | <ChatMarkdown | 563 | 555 | text={comment.text} | 564 | 556 | cwd={ctx.markdownCwd} | | 557 | + threadRef={ctx.threadRef ?? undefined} | 565 | 558 | skills={ctx.skills} | 566 | 559 | parseRawHtml={false} | 567 | 560 | lineBreaks | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/timelineRowContext.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -45,7 +45,7 @@ export interface TimelineRowSharedState { | 45 | 45 | markdownCwd: string | undefined; | 46 | 46 | resolvedTheme: "light" | "dark"; | 47 | 47 | workspaceRoot: string | undefined; | 48 | | - skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>; | | 48 | + skills: ReadonlyArray<ServerProviderSkill>; | 49 | 49 | runs: ReadonlyArray<HandoffTimelineRun>; | 50 | 50 | activeThreadEnvironmentId: EnvironmentId; | 51 | 51 | onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/contextChipParts.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,7 +65,7 @@ export function ContextChipPopover(props: { | 65 | 65 | kind: ContextChipKind; | 66 | 66 | icon: ReactNode; | 67 | 67 | label: string; | 68 | | - copyMarkdown?: string; | | 68 | + copyMarkdown?: string | undefined; | 69 | 69 | accessibleLabel: string; | 70 | 70 | children: ReactNode; | 71 | 71 | }) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/inlineSkills.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,10 @@ export function formatProviderSkillDisplayName( | 24 | 24 | const SKILL_TOKEN_REGEX = | 25 | 25 | /(^|\s)\p{Sc}(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/gu; | 26 | 26 |
| 27 | | -export function* matchInlineSkills(text: string, skills: readonly InlineSkill[]) { | | 27 | +export function* matchInlineSkills<Skill extends InlineSkill>( | | 28 | + text: string, | | 29 | + skills: readonly Skill[], | | 30 | +) { | 28 | 31 | for (const match of text.matchAll(SKILL_TOKEN_REGEX)) { | 29 | 32 | const name = match[2] ?? ""; | 30 | 33 | const skill = skills.find((candidate) => candidate.name === name); | |
|