-
Notifications
You must be signed in to change notification settings - Fork 248
feat: new conversation ai component #6170
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
Open
TarunAdobe
wants to merge
23
commits into
main
Choose a base branch
from
ttomar/conversation-ai
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
464a674
feat: add new conversational-ai pattern
TarunAdobe 1627a02
chore: add all conversation-ai components
TarunAdobe aa9de43
chore: update conversation ui component
TarunAdobe 7aece43
chore: update conversation-turn component
TarunAdobe e220a48
feat(css): updating css for css and lint fixes
aramos-adobe a2bc379
Merge branch 'conversation-ai-pattern' of github.com:adobe/spectrum-w…
aramos-adobe 8cff96c
feat(sources): add proper styling to links
aramos-adobe 06cb9f1
chore: update api for conversation ai
TarunAdobe 631c11b
chore: fix artifact media type
TarunAdobe d57b02c
chore: trigger preview deploy
TarunAdobe 4ad12d1
chore: update demo
TarunAdobe 4a301e4
chore: update conversation ai
TarunAdobe 0774ea8
chore: trigger preview-docs workflow
TarunAdobe 6b56487
chore: dummy commit
rubencarvalho b7b7747
feat(convoai): aligning with design annotations
aramos-adobe 1f4e54c
Merge branch 'main' into ttomar/conversation-ai
TarunAdobe 38ba0ce
chore: update conversation ai component
TarunAdobe 73530b0
fix(css): adjusting user message corners and some focus states
aramos-adobe d5d3926
fix(css): suggestion item focus
aramos-adobe b6e4a62
chore: add mode to prompt field
TarunAdobe 61b87b5
chore: fix upload artifact
TarunAdobe 6bf33c3
fix(sources): adjust inline size
aramos-adobe f07bd52
fix(convoAi): running through tests via playwright and vite
aramos-adobe 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
28 changes: 28 additions & 0 deletions
28
2nd-gen/packages/swc/.storybook/blocks/DocsAfterApiMarkdown.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,28 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { Markdown, useOf } from '@storybook/addon-docs/blocks'; | ||
| import React from 'react'; | ||
|
|
||
| /** | ||
| * Renders `parameters.docs.afterApi` (markdown) immediately after the API / Controls table. | ||
| */ | ||
| export const DocsAfterApiMarkdown = () => { | ||
| const resolvedOf = useOf('meta', ['meta']); | ||
| const md = resolvedOf.preparedMeta?.parameters?.docs?.afterApi; | ||
|
|
||
| if (!md || typeof md !== 'string') { | ||
| return null; | ||
| } | ||
|
|
||
| return <Markdown>{md}</Markdown>; | ||
| }; |
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
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
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
74 changes: 74 additions & 0 deletions
74
2nd-gen/packages/swc/.storybook/utils/docs-source-transform.ts
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,74 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| import type { StoryContext } from '@storybook/web-components'; | ||
|
|
||
| const PATTERN_TITLE_PREFIX = 'Patterns/Conversational AI/'; | ||
|
|
||
| /** | ||
| * Format source snippets for Storybook code panel. | ||
| * For conversational AI pattern stories, this removes CSF wrapper noise and | ||
| * keeps only the `html\`...\`` content when possible. | ||
| */ | ||
| export async function transformDocsSource( | ||
| source: string, | ||
| storyContext?: StoryContext | ||
| ): Promise<string> { | ||
| const normalizedSource = shouldNormalizePatternSource(storyContext) | ||
| ? extractHtmlTemplate(source) | ||
| : source; | ||
|
|
||
| return formatHtml(normalizedSource); | ||
| } | ||
|
|
||
| function shouldNormalizePatternSource(storyContext?: StoryContext): boolean { | ||
| return storyContext?.title?.startsWith(PATTERN_TITLE_PREFIX) ?? false; | ||
| } | ||
|
|
||
| function extractHtmlTemplate(source: string): string { | ||
| const primaryMatch = source.match( | ||
| /\brender\s*:\s*\([^)]*\)\s*=>\s*html`([\s\S]*?)`\s*[},]/m | ||
| ); | ||
| if (primaryMatch?.[1]) { | ||
| return primaryMatch[1].trim(); | ||
| } | ||
|
|
||
| const fallbackMatch = source.match(/\bhtml`([\s\S]*?)`/m); | ||
| if (fallbackMatch?.[1]) { | ||
| return fallbackMatch[1].trim(); | ||
| } | ||
|
|
||
| return source; | ||
| } | ||
|
|
||
| async function formatHtml(source: string): Promise<string> { | ||
| try { | ||
| const prettier = await import('prettier/standalone'); | ||
| const prettierPluginHtml = await import('prettier/plugins/html'); | ||
| const prettierPluginBabel = await import('prettier/plugins/babel'); | ||
| const prettierPluginEstree = await import('prettier/plugins/estree'); | ||
|
|
||
| return prettier.format(source, { | ||
| parser: 'html', | ||
| plugins: [ | ||
| prettierPluginHtml.default, | ||
| prettierPluginBabel.default, | ||
| prettierPluginEstree.default, | ||
| ], | ||
| tabWidth: 2, | ||
| useTabs: false, | ||
| singleQuote: true, | ||
| printWidth: 80, | ||
| }); | ||
| } catch { | ||
| return source; | ||
| } | ||
| } |
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
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,25 @@ | ||
| [11:45:52.845] [INFO] storybook v10.2.8 | ||
| [11:45:54.394] [DEBUG] Getting package.json info for /Users/ttomar/Documents/work/ai-component/spectrum-web-components/2nd-gen/packages/swc/package.json... | ||
| [11:45:54.535] [DEBUG] Serving static files from [36m2nd-gen/packages/swc/public[39m at [36m/[39m | ||
| [11:45:54.536] [INFO] Starting... | ||
| [11:45:55.838] [ERROR] [38;2;241;97;97mSB_CORE-SERVER_0004 (NoMatchingExportError): There was an exports mismatch error when trying to build Storybook. | ||
| Please check whether the versions of your Storybook packages match whenever possible, as this might be the cause. | ||
|
|
||
| Problematic example: | ||
| { "@storybook/react": "7.5.3", "@storybook/react-vite": "7.4.5", "storybook": "7.3.0" } | ||
|
|
||
| Correct example: | ||
| { "@storybook/react": "7.5.3", "@storybook/react-vite": "7.5.3", "storybook": "7.5.3" } | ||
|
|
||
| Please run `npx storybook doctor` for guidance on how to fix this issue. | ||
|
|
||
| More info: | ||
| [39m | ||
| at buildOrThrow (file:///Users/ttomar/Documents/work/ai-component/spectrum-web-components/2nd-gen/node_modules/storybook/dist/core-server/index.js:4509:9) | ||
| at process.processTicksAndRejections (node:internal/process/task_queues:103:5) | ||
| at async buildDevStandalone (file:///Users/ttomar/Documents/work/ai-component/spectrum-web-components/2nd-gen/node_modules/storybook/dist/core-server/index.js:7577:66) | ||
| at async withTelemetry (file:///Users/ttomar/Documents/work/ai-component/spectrum-web-components/2nd-gen/node_modules/storybook/dist/_node-chunks/chunk-KIOKJLL5.js:218:12) | ||
| at async dev (file:///Users/ttomar/Documents/work/ai-component/spectrum-web-components/2nd-gen/node_modules/storybook/dist/bin/core.js:2734:3) | ||
| at async _Command.<anonymous> (file:///Users/ttomar/Documents/work/ai-component/spectrum-web-components/2nd-gen/node_modules/storybook/dist/bin/core.js:2803:92) | ||
| [11:45:55.841] [WARN] Broken build, fix the error above. | ||
| You may need to refresh the browser. |
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
60 changes: 60 additions & 0 deletions
60
2nd-gen/packages/swc/patterns/conversational-ai/README.mdx
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,60 @@ | ||
| import { Meta, Canvas } from '@storybook/addon-docs/blocks'; | ||
| import * as ConversationTurnStories from './conversation-turn/stories/conversation-turn.stories'; | ||
|
|
||
| <Meta title="Conversational AI/README" /> | ||
|
|
||
| # Conversational AI | ||
|
|
||
| A complete set of building blocks for composing AI chat interfaces in 2nd-gen Spectrum Web Components. The pattern covers the full response lifecycle — from user input through AI generation, output, feedback, source attribution, and follow-up suggestions. | ||
|
|
||
| --- | ||
|
|
||
| ## Full example | ||
|
|
||
| <Canvas of={ConversationTurnStories.FullPattern} sourceState="none" /> | ||
|
|
||
| --- | ||
|
|
||
| ## Components | ||
|
|
||
| | Element | Description | | ||
| | ----------------------- | -------------------------------------------------------------------------------------------------------------- | | ||
| | `swc-prompt-field` | Text input surface for entering or refining a prompt | | ||
| | `swc-upload-artifact` | Shared upload artifact primitive with `card` and `media` types, used in prompt-field and user-message surfaces | | ||
| | `swc-conversation-turn` | Column alignment for one participant turn; stack consecutive messages in one turn for grouped spacing | | ||
| | `swc-user-message` | User message bubble with slot-inferred copy/card/media layout | | ||
| | `swc-system-message` | System reply stack; **default slot** guidance is after the API table on the System message docs page | | ||
| | `swc-response-status` | Loading / generation-complete status indicator | | ||
| | `swc-message-feedback` | Positive / negative feedback control | | ||
| | `swc-message-sources` | Collapsible numbered list of response sources | | ||
| | `swc-suggestion` | Follow-up suggestion group with optional title and slotted suggestion items | | ||
| | `swc-suggestion-item` | Interactive chip action used inside `swc-suggestion`; emits bubbled selection event | | ||
|
|
||
| --- | ||
|
|
||
| ## Pattern structure | ||
|
|
||
| ```text | ||
| patterns/ | ||
| conversational-ai/ | ||
| README.mdx | ||
| system-prose-demo.css | ||
| upload-artifact/ | ||
| prompt-field/ | ||
| user-message/ | ||
| response-status/ | ||
| message-feedback/ | ||
| message-sources/ | ||
| suggestion/ | ||
| suggestion-item/ | ||
| conversation-turn/ | ||
| system-message/ | ||
| utils/ | ||
| icons/ | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Tokens | ||
|
|
||
| All components resolve styles through `token()` calls that map to `var(--swc-*)` custom properties. No hard-coded colours or sizes — set the standard Spectrum token layer to theme the pattern globally. |
49 changes: 49 additions & 0 deletions
49
2nd-gen/packages/swc/patterns/conversational-ai/conversation-turn/ConversationTurn.ts
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,49 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { CSSResultArray, html, TemplateResult } from 'lit'; | ||
| import { property } from 'lit/decorators.js'; | ||
|
|
||
| import { SpectrumElement } from '@spectrum-web-components/core/element/index.js'; | ||
|
|
||
| import styles from './conversation-turn.css'; | ||
|
|
||
| /** | ||
| * Aligns one turn in a chat column: user content toward the end (right in LTR) | ||
| * and system content toward the start at full width. | ||
| * | ||
| * Slot **`swc-user-message`**, **`swc-system-message`**, or custom markup inside each turn | ||
| * Multiple slotted messages are stacked automatically with | ||
| * `--swc-conversation-turn-group-gap` spacing. | ||
| * User-message widths are applied by layout context (full screen, split rail, | ||
| * panel) while system content remains full width. | ||
| * | ||
| * @element swc-conversation-turn | ||
| * @slot - Turn body (message stack or bubble) | ||
| */ | ||
| export class ConversationTurn extends SpectrumElement { | ||
| /** `user` — end-aligned; `system` — start-aligned, full width of the column. */ | ||
| @property({ type: String, reflect: true }) | ||
| public type: 'system' | 'user' = 'user'; | ||
|
|
||
| public static override get styles(): CSSResultArray { | ||
| return [styles]; | ||
| } | ||
|
|
||
| protected override render(): TemplateResult { | ||
| return html` | ||
| <div class="swc-ConversationTurn"> | ||
| <slot></slot> | ||
| </div> | ||
| `; | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sighted users can tell which turn is from the user and which one is from the AI. We need a way to communicate this to screenreaders as well.