MCPcopy Create free account
hub / github.com/CopilotKit/OpenGenerativeUI / save_template

Function save_template

apps/agent/src/templates.py:99–137  ·  view source on GitHub ↗

Save a generated UI as a reusable template. Call this when the user wants to save a widget/visualization they liked for reuse later. Args: name: Short name for the template (e.g. "Invoice", "Dashboard") description: What the template displays or does html: The r

(
    name: str,
    description: str,
    html: str,
    data_description: str,
    runtime: ToolRuntime,
)

Source from the content-addressed store, hash-verified

97
98@tool
99def save_template(
100 name: str,
101 description: str,
102 html: str,
103 data_description: str,
104 runtime: ToolRuntime,
105) -> Command:
106 """
107 Save a generated UI as a reusable template.
108 Call this when the user wants to save a widget/visualization they liked for reuse later.
109
110 Args:
111 name: Short name for the template (e.g. "Invoice", "Dashboard")
112 description: What the template displays or does
113 html: The raw HTML string of the widget to save as a template
114 data_description: Description of the data shape this template expects
115 """
116 templates = list(runtime.state.get("templates", []))
117
118 template: UITemplate = {
119 "id": str(uuid.uuid4()),
120 "name": name,
121 "description": description,
122 "html": html,
123 "data_description": data_description,
124 "created_at": datetime.now().isoformat(),
125 "version": 1,
126 }
127 templates.append(template)
128
129 return Command(update={
130 "templates": templates,
131 "messages": [
132 ToolMessage(
133 content=f"Template '{name}' saved successfully (id: {template['id']})",
134 tool_call_id=runtime.tool_call_id,
135 )
136 ],
137 })
138
139
140@tool

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected