Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions hax/artifacts/showcase/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2025 Cisco Systems, Inc. and its affiliates
*
* Licensed 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 CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

import { useCopilotAction } from "@copilotkit/react-core";
import { z } from "zod";
import {
ShowcaseArtifact,
ShowcaseItemZod,
ShowcaseCategoryZod,
ShowcaseVariantZod,
} from "./types";
import { SHOWCASE_DESCRIPTION } from "./description";

interface UseShowcaseActionProps {
addOrUpdateArtifact: (artifact: ShowcaseArtifact) => void;
}

export const useShowcaseAction = ({
addOrUpdateArtifact,
}: UseShowcaseActionProps) => {
useCopilotAction({
name: "create_showcase",
description: SHOWCASE_DESCRIPTION,
parameters: [
{
name: "variant",
type: "string",
description:
"Layout variant: grid, list, dense-grid, table, categorized, featured",
required: false,
},
{
name: "itemsJson",
type: "string",
description:
"JSON string of items array: [{id, title, description, badge?, imageUrl?, author?, category?}]",
required: false,
},
{
name: "categoriesJson",
type: "string",
description:
'JSON string of categories array (for categorized variant): [{title, icon?, items: [...]}]',
required: false,
},
],
handler: async (args: {
variant?: string;
itemsJson?: string;
categoriesJson?: string;
}) => {
try {
const variant = args.variant
? ShowcaseVariantZod.parse(args.variant)
: "grid";

let items: z.infer<typeof ShowcaseItemZod>[] | undefined;
if (args.itemsJson) {
const parsed = JSON.parse(args.itemsJson);
items = z.array(ShowcaseItemZod).parse(parsed);
}

let categories: z.infer<typeof ShowcaseCategoryZod>[] | undefined;
if (args.categoriesJson) {
const parsed = JSON.parse(args.categoriesJson);
categories = z.array(ShowcaseCategoryZod).parse(parsed);
}

const artifact: ShowcaseArtifact = {
id: `showcase-${Date.now()}`,
type: "showcase",
data: {
variant,
...(items && { items }),
...(categories && { categories }),
},
};

addOrUpdateArtifact(artifact);
return `Created showcase (${variant}) with ${items?.length ?? 0} items`;
} catch (error) {
return `Error creating showcase: ${String(error)}`;
}
},
});
};
41 changes: 41 additions & 0 deletions hax/artifacts/showcase/description.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2025 Cisco Systems, Inc. and its affiliates
*
* Licensed 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 CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

export const SHOWCASE_DESCRIPTION =
`Use the showcase artifact to present a browsable collection of items for the user to explore, preview, and act on. Best for displaying templates, search results, recommendations, generated options, or curated content.

Supports 6 layout variants:
- "grid": 3x2 vertical card grid with image, badge, heading, description. Best for visual-heavy content.
- "list": 2-column horizontal cards with image left, content right, Preview button + favorite. Best for items with rich metadata.
- "dense-grid": 4x3 compact grid with smaller cards. Best for large collections.
- "table": Row-based table with Preview thumbnail, Title, Author, Category badge, action icons. Best for data-dense scanning.
- "categorized": Sections with icon headers (Trending/Star/Clock), 3 overlay cards per section. Best for grouped/curated content.
- "featured": Full-width hero card + 3-column masonry grid below. Best for highlighting a primary item with supporting items.

Each item requires: id (unique), title, description.
Optional per item: badge (category label), imageUrl (preview), author, category.

For "categorized" variant, provide categories array instead of items. Each category has: title, icon (trending/star/clock), items array.

Choose the variant that best matches the user's intent:
- Browsing/exploring → grid or dense-grid
- Comparing with details → list or table
- Curated sections → categorized
- Highlighting one item → featured

Ensure each item has a unique id. Include badges for categorization. Keep descriptions concise (1-2 sentences).` as const;
34 changes: 34 additions & 0 deletions hax/artifacts/showcase/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025 Cisco Systems, Inc. and its affiliates
*
* Licensed 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 CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

export { HAXShowcase } from "./showcase";
export type { HAXShowcaseProps } from "./showcase";
export { useShowcaseAction } from "./action";
export { SHOWCASE_DESCRIPTION } from "./description";
export {
ShowcaseArtifactZod,
ShowcaseItemZod,
ShowcaseCategoryZod,
ShowcaseVariantZod,
} from "./types";
export type {
ShowcaseArtifact,
ShowcaseItemData,
ShowcaseCategoryData,
ShowcaseVariant,
} from "./types";
Loading