mirror of
https://github.com/stackblitz/bolt.new
synced 2025-02-06 04:48:04 +00:00
Merge pull request #504 from thecodacus/bundle-artifact
feat(UI): added artifact bundling for custom long artifacts like uploading folder
This commit is contained in:
commit
05a5f85e68
@ -28,6 +28,7 @@ interface ArtifactProps {
|
|||||||
export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
||||||
const userToggledActions = useRef(false);
|
const userToggledActions = useRef(false);
|
||||||
const [showActions, setShowActions] = useState(false);
|
const [showActions, setShowActions] = useState(false);
|
||||||
|
const [allActionFinished, setAllActionFinished] = useState(false);
|
||||||
|
|
||||||
const artifacts = useStore(workbenchStore.artifacts);
|
const artifacts = useStore(workbenchStore.artifacts);
|
||||||
const artifact = artifacts[messageId];
|
const artifact = artifacts[messageId];
|
||||||
@ -47,6 +48,11 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|||||||
if (actions.length && !showActions && !userToggledActions.current) {
|
if (actions.length && !showActions && !userToggledActions.current) {
|
||||||
setShowActions(true);
|
setShowActions(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actions.length !== 0) {
|
||||||
|
const finished = !actions.find((action) => action.status !== 'complete');
|
||||||
|
setAllActionFinished(finished);
|
||||||
|
}
|
||||||
}, [actions]);
|
}, [actions]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -59,6 +65,18 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|||||||
workbenchStore.showWorkbench.set(!showWorkbench);
|
workbenchStore.showWorkbench.set(!showWorkbench);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{artifact.type == 'bundled' && (
|
||||||
|
<>
|
||||||
|
<div className="p-4">
|
||||||
|
{allActionFinished ? (
|
||||||
|
<div className={'i-ph:files-light'} style={{ fontSize: '2rem' }}></div>
|
||||||
|
) : (
|
||||||
|
<div className={'i-svg-spinners:90-ring-with-bg'} style={{ fontSize: '2rem' }}></div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="bg-bolt-elements-artifacts-borderColor w-[1px]" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<div className="px-5 p-3.5 w-full text-left">
|
<div className="px-5 p-3.5 w-full text-left">
|
||||||
<div className="w-full text-bolt-elements-textPrimary font-medium leading-5 text-sm">{artifact?.title}</div>
|
<div className="w-full text-bolt-elements-textPrimary font-medium leading-5 text-sm">{artifact?.title}</div>
|
||||||
<div className="w-full w-full text-bolt-elements-textSecondary text-xs mt-0.5">Click to open Workbench</div>
|
<div className="w-full w-full text-bolt-elements-textSecondary text-xs mt-0.5">Click to open Workbench</div>
|
||||||
@ -66,7 +84,7 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|||||||
</button>
|
</button>
|
||||||
<div className="bg-bolt-elements-artifacts-borderColor w-[1px]" />
|
<div className="bg-bolt-elements-artifacts-borderColor w-[1px]" />
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{actions.length && (
|
{actions.length && artifact.type !== 'bundled' && (
|
||||||
<motion.button
|
<motion.button
|
||||||
initial={{ width: 0 }}
|
initial={{ width: 0 }}
|
||||||
animate={{ width: 'auto' }}
|
animate={{ width: 'auto' }}
|
||||||
@ -83,7 +101,7 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</div>
|
</div>
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{showActions && actions.length > 0 && (
|
{artifact.type !== 'bundled' && showActions && actions.length > 0 && (
|
||||||
<motion.div
|
<motion.div
|
||||||
className="actions"
|
className="actions"
|
||||||
initial={{ height: 0 }}
|
initial={{ height: 0 }}
|
||||||
@ -92,6 +110,7 @@ export const Artifact = memo(({ messageId }: ArtifactProps) => {
|
|||||||
transition={{ duration: 0.15 }}
|
transition={{ duration: 0.15 }}
|
||||||
>
|
>
|
||||||
<div className="bg-bolt-elements-artifacts-borderColor h-[1px]" />
|
<div className="bg-bolt-elements-artifacts-borderColor h-[1px]" />
|
||||||
|
|
||||||
<div className="p-5 text-left bg-bolt-elements-actions-background">
|
<div className="p-5 text-left bg-bolt-elements-actions-background">
|
||||||
<ActionList actions={actions} />
|
<ActionList actions={actions} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -79,7 +79,7 @@ ${content}
|
|||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: `I'll help you set up these files.${binaryFilesMessage}
|
content: `I'll help you set up these files.${binaryFilesMessage}
|
||||||
|
|
||||||
<boltArtifact id="imported-files" title="Imported Files">
|
<boltArtifact id="imported-files" title="Imported Files" type="bundled">
|
||||||
${fileArtifacts.join('\n\n')}
|
${fileArtifacts.join('\n\n')}
|
||||||
</boltArtifact>`,
|
</boltArtifact>`,
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
|
@ -29,6 +29,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -96,6 +98,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -104,6 +107,7 @@ exports[`StreamingMessageParser > valid artifacts with actions > should correctl
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -112,6 +116,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -120,6 +125,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -128,6 +134,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": "bundled",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -136,6 +143,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": "bundled",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -144,6 +152,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -152,6 +161,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -160,6 +170,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -168,6 +179,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -176,6 +188,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -184,6 +197,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -192,6 +206,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -200,6 +215,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -208,6 +224,7 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -216,5 +233,6 @@ exports[`StreamingMessageParser > valid artifacts without actions > should corre
|
|||||||
"id": "artifact_1",
|
"id": "artifact_1",
|
||||||
"messageId": "message_1",
|
"messageId": "message_1",
|
||||||
"title": "Some title",
|
"title": "Some title",
|
||||||
|
"type": undefined,
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@ -59,7 +59,11 @@ describe('StreamingMessageParser', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['Some text before <boltArti', 'fact', ' title="Some title" id="artifact_1">foo</boltArtifact> Some more text'],
|
[
|
||||||
|
'Some text before <boltArti',
|
||||||
|
'fact',
|
||||||
|
' title="Some title" id="artifact_1" type="bundled" >foo</boltArtifact> Some more text',
|
||||||
|
],
|
||||||
{
|
{
|
||||||
output: 'Some text before Some more text',
|
output: 'Some text before Some more text',
|
||||||
callbacks: { onArtifactOpen: 1, onArtifactClose: 1, onActionOpen: 0, onActionClose: 0 },
|
callbacks: { onArtifactOpen: 1, onArtifactClose: 1, onActionOpen: 0, onActionClose: 0 },
|
||||||
|
@ -192,6 +192,7 @@ export class StreamingMessageParser {
|
|||||||
const artifactTag = input.slice(i, openTagEnd + 1);
|
const artifactTag = input.slice(i, openTagEnd + 1);
|
||||||
|
|
||||||
const artifactTitle = this.#extractAttribute(artifactTag, 'title') as string;
|
const artifactTitle = this.#extractAttribute(artifactTag, 'title') as string;
|
||||||
|
const type = this.#extractAttribute(artifactTag, 'type') as string;
|
||||||
const artifactId = this.#extractAttribute(artifactTag, 'id') as string;
|
const artifactId = this.#extractAttribute(artifactTag, 'id') as string;
|
||||||
|
|
||||||
if (!artifactTitle) {
|
if (!artifactTitle) {
|
||||||
@ -207,6 +208,7 @@ export class StreamingMessageParser {
|
|||||||
const currentArtifact = {
|
const currentArtifact = {
|
||||||
id: artifactId,
|
id: artifactId,
|
||||||
title: artifactTitle,
|
title: artifactTitle,
|
||||||
|
type,
|
||||||
} satisfies BoltArtifactData;
|
} satisfies BoltArtifactData;
|
||||||
|
|
||||||
state.currentArtifact = currentArtifact;
|
state.currentArtifact = currentArtifact;
|
||||||
|
@ -19,6 +19,7 @@ import { description } from '~/lib/persistence';
|
|||||||
export interface ArtifactState {
|
export interface ArtifactState {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
type?: string;
|
||||||
closed: boolean;
|
closed: boolean;
|
||||||
runner: ActionRunner;
|
runner: ActionRunner;
|
||||||
}
|
}
|
||||||
@ -230,7 +231,7 @@ export class WorkbenchStore {
|
|||||||
// TODO: what do we wanna do and how do we wanna recover from this?
|
// TODO: what do we wanna do and how do we wanna recover from this?
|
||||||
}
|
}
|
||||||
|
|
||||||
addArtifact({ messageId, title, id }: ArtifactCallbackData) {
|
addArtifact({ messageId, title, id, type }: ArtifactCallbackData) {
|
||||||
const artifact = this.#getArtifact(messageId);
|
const artifact = this.#getArtifact(messageId);
|
||||||
|
|
||||||
if (artifact) {
|
if (artifact) {
|
||||||
@ -245,6 +246,7 @@ export class WorkbenchStore {
|
|||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
closed: false,
|
closed: false,
|
||||||
|
type,
|
||||||
runner: new ActionRunner(webcontainer, () => this.boltTerminal),
|
runner: new ActionRunner(webcontainer, () => this.boltTerminal),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export interface BoltArtifactData {
|
export interface BoltArtifactData {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
type?: string | undefined;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user