-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(chat): natural-language tool titles, past-tense completion, and smooth agent-group narration #5660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(chat): natural-language tool titles, past-tense completion, and smooth agent-group narration #5660
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
35efb1c
feat(chat): natural-language tool titles, past-tense completion, and …
waleedlatif1 f837a5a
improvement(chat): drop per-row status icons on subagent tool calls
waleedlatif1 77c7589
fix(chat): restrict narration seam space to sentence boundaries
waleedlatif1 8d3b21f
improvement(chat): promote inline comments to TSDoc, support bold-ita…
waleedlatif1 4069af9
fix(chat): gate narration seam repair on channel transitions, render …
waleedlatif1 d688239
improvement(chat): flip Gathering thoughts to past tense on completion
waleedlatif1 74babad
fix(chat): classify inline-markdown tokens by split parity, require n…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...kspaceId]/home/components/message-content/components/agent-group/inline-markdown.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { isValidElement } from 'react' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { renderInlineMarkdown } from './inline-markdown' | ||
|
|
||
| function flattenText(node: React.ReactNode): string { | ||
| if (typeof node === 'string') return node | ||
| if (Array.isArray(node)) return node.map(flattenText).join('') | ||
| if (isValidElement<{ children?: React.ReactNode }>(node)) return flattenText(node.props.children) | ||
| return '' | ||
| } | ||
|
|
||
| function findByType(parts: React.ReactNode[], type: string): React.ReactNode { | ||
| return parts.find((p) => isValidElement(p) && p.type === type) | ||
| } | ||
|
|
||
| describe('renderInlineMarkdown', () => { | ||
| it('renders **bold** spans as strong elements', () => { | ||
| const parts = renderInlineMarkdown('The failing block is **ModalDenied** (a Slack block).') | ||
| const bold = findByType(parts, 'strong') | ||
| expect(bold).toBeDefined() | ||
| expect(flattenText(bold)).toBe('ModalDenied') | ||
| expect(flattenText(parts)).toBe('The failing block is ModalDenied (a Slack block).') | ||
| }) | ||
|
|
||
| it('renders `code` spans as mono elements', () => { | ||
| const parts = renderInlineMarkdown('check the `webhook` payload') | ||
| expect(flattenText(findByType(parts, 'span'))).toBe('webhook') | ||
| expect(flattenText(parts)).toBe('check the webhook payload') | ||
| }) | ||
|
|
||
| it('renders *italic* spans as em elements', () => { | ||
| const parts = renderInlineMarkdown('this is *important* context') | ||
| expect(flattenText(findByType(parts, 'em'))).toBe('important') | ||
| }) | ||
|
|
||
| it('renders ***bold-italic*** as nested strong and em', () => { | ||
| const parts = renderInlineMarkdown('a ***wrapped*** word') | ||
| const bold = findByType(parts, 'strong') | ||
| expect(bold).toBeDefined() | ||
| expect(flattenText(parts)).toBe('a wrapped word') | ||
| }) | ||
|
|
||
| it('renders links as their label text', () => { | ||
| const parts = renderInlineMarkdown('see [the docs](https://sim.ai/docs) for more') | ||
| expect(flattenText(parts)).toBe('see the docs for more') | ||
| }) | ||
|
|
||
| it('keeps emphasis markers inside code spans verbatim', () => { | ||
| const parts = renderInlineMarkdown('pass `*args` and `**kwargs` through') | ||
| const codeTexts = parts | ||
| .filter((p) => isValidElement(p) && p.type === 'span') | ||
| .map((p) => flattenText(p)) | ||
| expect(codeTexts).toEqual(['*args', '**kwargs']) | ||
| expect(flattenText(parts)).toBe('pass *args and **kwargs through') | ||
| }) | ||
|
|
||
| it('renders nested markers inside emphasis and link labels', () => { | ||
| expect( | ||
| flattenText(renderInlineMarkdown('read [**the docs**](https://sim.ai/docs) first')) | ||
| ).toBe('read the docs first') | ||
| expect(flattenText(renderInlineMarkdown('use *`glob`* patterns'))).toBe('use glob patterns') | ||
| }) | ||
|
|
||
| it('leaves unterminated markers verbatim', () => { | ||
| expect(renderInlineMarkdown('a **dangling marker')).toEqual(['a **dangling marker']) | ||
| expect(renderInlineMarkdown('a `dangling tick')).toEqual(['a `dangling tick']) | ||
| }) | ||
|
|
||
| it('does not italicize bare asterisks in math-like text', () => { | ||
| expect(renderInlineMarkdown('2 * 3 * 4')).toEqual(['2 * 3 * 4']) | ||
| }) | ||
|
|
||
| it('never reclassifies plain text the tokenizer rejected', () => { | ||
| expect(renderInlineMarkdown('* x *')).toEqual(['* x *']) | ||
| expect(renderInlineMarkdown('** spaced bullets **')).toEqual(['** spaced bullets **']) | ||
| }) | ||
|
|
||
| it('passes plain text through untouched', () => { | ||
| expect(renderInlineMarkdown('no markup here.')).toEqual(['no markup here.']) | ||
| }) | ||
| }) |
56 changes: 56 additions & 0 deletions
56
.../[workspaceId]/home/components/message-content/components/agent-group/inline-markdown.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { Fragment, type ReactNode } from 'react' | ||
|
|
||
| const INLINE_TOKEN = | ||
| /(\*{3}[^\s*](?:[^*\n]*[^\s*])?\*{3}|\*\*[^\s*](?:[^*\n]*[^\s*])?\*\*|\*[^\s*](?:[^*\n]*[^\s*])?\*|`[^`\n]+`|\[[^\]\n]+\]\([^\s)]+\))/g | ||
|
|
||
| const LINK_TOKEN = /^\[([^\]\n]+)\]\([^\s)]+\)$/ | ||
|
|
||
| /** | ||
| * Minimal inline-markdown renderer for agent-group narration rows. Supports | ||
| * `**bold**`, `*italic*`, `***bold-italic***`, `` `code` `` spans, and | ||
| * `[label](url)` links (rendered as their label — narration is prose, not | ||
| * navigation). Emphasis contents and link labels are rendered recursively so | ||
| * nested markers resolve; code spans stay verbatim. Everything else, | ||
| * including unterminated markers, renders as-is. Full Streamdown rendering is | ||
| * intentionally avoided here — these rows re-render on every streaming frame. | ||
| * | ||
| * Splitting on a single capturing group alternates plain text (even indices) | ||
| * and matched tokens (odd indices), so index parity is the exact | ||
| * discriminator — plain text that merely resembles a marker (e.g. `* x *`, | ||
| * rejected by the tokenizer's boundary rules) is never reclassified. | ||
| */ | ||
| export function renderInlineMarkdown(text: string): ReactNode[] { | ||
| return text.split(INLINE_TOKEN).map((part, i) => (i % 2 === 1 ? renderToken(part, i) : part)) | ||
| } | ||
|
|
||
| function renderToken(part: string, key: number): ReactNode { | ||
| if (part.length > 6 && part.startsWith('***') && part.endsWith('***')) { | ||
| return ( | ||
| <strong key={key} className='font-semibold'> | ||
| <em>{renderInlineMarkdown(part.slice(3, -3))}</em> | ||
| </strong> | ||
| ) | ||
| } | ||
| if (part.length > 4 && part.startsWith('**') && part.endsWith('**')) { | ||
| return ( | ||
| <strong key={key} className='font-semibold'> | ||
| {renderInlineMarkdown(part.slice(2, -2))} | ||
| </strong> | ||
| ) | ||
| } | ||
| if (part.length > 2 && part.startsWith('`') && part.endsWith('`')) { | ||
| return ( | ||
| <span key={key} className='font-mono text-[12px]'> | ||
| {part.slice(1, -1)} | ||
| </span> | ||
| ) | ||
| } | ||
| if (part.length > 2 && part.startsWith('*') && part.endsWith('*')) { | ||
| return <em key={key}>{renderInlineMarkdown(part.slice(1, -1))}</em> | ||
| } | ||
| const link = LINK_TOKEN.exec(part) | ||
| if (link) { | ||
| return <Fragment key={key}>{renderInlineMarkdown(link[1])}</Fragment> | ||
| } | ||
| return part | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.