99
1010class CardContent (BaseModel ):
1111 content_type : Literal ["text/markdown" , "text/plain" ] = "text/markdown"
12+ """
13+ The content type of the card. This can be either "text/markdown" or "text/plain". This affects how the content is rendered.
14+ """
1215 content : str
16+ """
17+ The content of the card. This can be either plain text or markdown.
18+ """
1319
1420
1521class TemplateConfig (BaseModel ):
22+ """
23+ Configuration for a dashboard card for an assistant service.
24+ This is used to define the content and appearance of the card that will be shown in the dashboard.
25+ """
26+
1627 template_id : str
28+ """
29+ The template ID.
30+ """
1731 enabled : bool
32+ """
33+ Whether the template is enabled. If False, the template will not be shown as a card in the dashboard.
34+ """
1835 icon : str
36+ """
37+ The icon as a data URL. The icon is expected to be in PNG, JPEG, or SVG format. SVG is recommended for scalability.
38+ fluent v9 icons from https://react.fluentui.dev/?path=/docs/icons-catalog--docs, specifically the "20Regular" icons, is a good source.
39+ """
1940 background_color : str
41+ """
42+ The background color of the card. This should be a valid CSS color string.
43+ fluent v9 colors from https://react.fluentui.dev/?path=/docs/theme-colors--docs are a good source.
44+ """
2045 card_content : CardContent
46+ """
47+ The content of the card.
48+ """
2149
2250
2351def image_to_url (
@@ -26,6 +54,13 @@ def image_to_url(
2654) -> str :
2755 """
2856 Reads the icon file from the given path, returning it as a data URL.
57+
58+ Args:
59+ path (os.PathLike): The path to the icon file.
60+ content_type (Literal["image/png", "image/jpeg", "image/svg+xml"]): The content type of the icon file.
61+
62+ Returns:
63+ str: The icon as a data URL.
2964 """
3065
3166 match content_type :
@@ -43,6 +78,34 @@ def image_to_url(
4378
4479
4580def metadata (* templates : TemplateConfig ) -> dict [str , Any ]:
81+ """
82+ Generates metadata for the dashboard card. The resulting metadata dictionary is intended to be merged
83+ with the assistant service metadata.
84+
85+ Args:
86+ *templates (TemplateConfig): The dashboard configurations, one per template ID.
87+
88+ Returns:
89+ dict: The metadata for the dashboard card.
90+
91+ Example:
92+ ```
93+ assistant_service_metadata={
94+ **dashboard_card.metadata(
95+ TemplateConfig(
96+ enabled=True,
97+ template_id="default",
98+ background_color="rgb(238, 172, 178)",
99+ icon=image_to_url(pathlib.Path(__file__).parent / "assets" / "icon.svg", "image/svg+xml"),
100+ card_content=CardContent(
101+ content_type="text/markdown",
102+ content=(pathlib.Path(__file__).parent / "assets" / "card_content.md").read_text("utf-8"),
103+ ),
104+ )
105+ )
106+ }
107+ ```
108+ """
46109 template_dict = {}
47110 for template in templates :
48111 template_dict [template .template_id ] = template
0 commit comments