@datalayer/agent-runtimes 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/lib/{examples/components → components}/AgentConfiguration.d.ts +27 -12
- package/lib/{examples/components → components}/AgentConfiguration.js +170 -22
- package/lib/{examples/components → components}/FooterMetrics.d.ts +1 -2
- package/lib/{examples/components → components}/Header.d.ts +1 -6
- package/lib/{examples/components → components}/Header.js +5 -39
- package/lib/{examples/components → components}/HeaderControls.d.ts +1 -2
- package/lib/{examples/components → components}/HeaderControls.js +1 -1
- package/lib/{examples/components → components}/LexicalEditor.d.ts +2 -3
- package/lib/{examples/components → components}/LexicalEditor.js +2 -2
- package/lib/components/MainContent.d.ts +34 -0
- package/lib/{examples/components → components}/MainContent.js +18 -9
- package/lib/components/McpServerManager.d.ts +30 -0
- package/lib/components/McpServerManager.js +331 -0
- package/lib/{examples/components → components}/MockFileBrowser.d.ts +1 -2
- package/lib/{examples/components → components}/SessionTabs.d.ts +2 -3
- package/lib/{examples/components → components}/TimeTravel.d.ts +1 -2
- package/lib/components/chat/components/AgentDetails.d.ts +3 -1
- package/lib/components/chat/components/AgentDetails.js +323 -31
- package/lib/components/chat/components/Chat.d.ts +37 -3
- package/lib/components/chat/components/Chat.js +29 -10
- package/lib/components/chat/components/ChatFloating.d.ts +27 -2
- package/lib/components/chat/components/ChatFloating.js +17 -10
- package/lib/components/chat/components/ChatPopupStandalone.js +1 -1
- package/lib/components/chat/components/ChatSidebar.d.ts +1 -1
- package/lib/components/chat/components/ChatStandalone.d.ts +1 -1
- package/lib/components/chat/components/ChatStandalone.js +1 -1
- package/lib/components/chat/components/ContextDistribution.d.ts +70 -6
- package/lib/components/chat/components/ContextDistribution.js +11 -4
- package/lib/components/chat/components/ContextInspector.d.ts +81 -0
- package/lib/components/chat/components/ContextInspector.js +261 -0
- package/lib/components/chat/components/ContextPanel.d.ts +112 -0
- package/lib/components/chat/components/ContextPanel.js +373 -0
- package/lib/components/chat/components/base/ChatBase.d.ts +74 -19
- package/lib/components/chat/components/base/ChatBase.js +296 -37
- package/lib/components/chat/components/index.d.ts +3 -1
- package/lib/components/chat/components/index.js +2 -0
- package/lib/components/chat/extensions/ExtensionRegistry.d.ts +1 -1
- package/lib/components/chat/extensions/index.d.ts +1 -0
- package/lib/components/chat/index.d.ts +3 -3
- package/lib/components/chat/protocols/AGUIAdapter.js +24 -4
- package/lib/components/chat/protocols/VercelAIAdapter.js +35 -1
- package/lib/components/chat/store/chatStore.d.ts +2 -3
- package/lib/components/chat/store/conversationStore.d.ts +83 -0
- package/lib/components/chat/store/conversationStore.js +174 -0
- package/lib/components/chat/store/index.d.ts +2 -1
- package/lib/components/chat/store/index.js +1 -0
- package/lib/components/chat/types/inference.d.ts +17 -0
- package/lib/components/chat/types/protocol.d.ts +10 -0
- package/lib/components/index.d.ts +23 -0
- package/lib/components/index.js +11 -0
- package/lib/config/agents.d.ts +33 -0
- package/lib/config/agents.js +424 -0
- package/lib/config/index.d.ts +4 -0
- package/lib/config/index.js +8 -0
- package/lib/config/mcpServers.d.ts +18 -0
- package/lib/config/mcpServers.js +129 -0
- package/lib/config/skills.d.ts +25 -0
- package/lib/config/skills.js +54 -0
- package/lib/{lib → config}/utils.d.ts +1 -1
- package/lib/{lib → config}/utils.js +2 -2
- package/lib/examples/AgentRuntimeLexical2Example.d.ts +1 -0
- package/lib/examples/AgentRuntimeLexical2Example.js +3 -2
- package/lib/examples/AgentRuntimeLexicalExample.d.ts +1 -0
- package/lib/examples/AgentRuntimeLexicalExample.js +5 -3
- package/lib/examples/AgentRuntimeLexicalSidebarExample.d.ts +1 -0
- package/lib/examples/AgentRuntimeLexicalSidebarExample.js +3 -3
- package/lib/examples/AgentRuntimeNotebookExample.js +1 -1
- package/lib/examples/AgentSpaceFormExample.d.ts +2 -2
- package/lib/examples/AgentSpaceFormExample.js +167 -29
- package/lib/examples/CopilotKitLexicalExample.d.ts +1 -0
- package/lib/examples/CopilotKitLexicalExample.js +3 -2
- package/lib/examples/index.d.ts +1 -0
- package/lib/examples/stores/notebooks/NotebookExample2.ipynb.json +43 -43
- package/lib/hooks/useAGUI.d.ts +1 -1
- package/lib/hooks/useAGUI.js +1 -1
- package/lib/identity/types.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/lib/runtime/index.d.ts +3 -0
- package/lib/runtime/runtimeStore.d.ts +3 -4
- package/lib/runtime/useAgentConnection.d.ts +2 -3
- package/lib/runtime/useAgentRuntime.d.ts +2 -3
- package/lib/stories/Cell.stories.js +1 -1
- package/lib/tools/adapters/agent-runtimes/notebookHooks.js +1 -0
- package/lib/tools/adapters/copilotkit/notebookHooks.js +1 -0
- package/lib/types.d.ts +150 -0
- package/package.json +4 -5
- package/scripts/apply-patches.sh +32 -0
- package/scripts/codegen/generate_agents.py +452 -0
- package/scripts/codegen/generate_mcp_servers.py +424 -0
- package/scripts/codegen/generate_skills.py +321 -0
- package/scripts/download-ai-elements.py +35 -20
- package/scripts/sync-jupyter.sh +6 -0
- package/lib/components/ui/accordion.d.ts +0 -7
- package/lib/components/ui/accordion.js +0 -22
- package/lib/components/ui/alert-dialog.d.ts +0 -14
- package/lib/components/ui/alert-dialog.js +0 -43
- package/lib/components/ui/alert.d.ts +0 -9
- package/lib/components/ui/alert.js +0 -24
- package/lib/components/ui/aspect-ratio.d.ts +0 -3
- package/lib/components/ui/aspect-ratio.js +0 -11
- package/lib/components/ui/avatar.d.ts +0 -6
- package/lib/components/ui/avatar.js +0 -18
- package/lib/components/ui/badge.d.ts +0 -9
- package/lib/components/ui/badge.js +0 -22
- package/lib/components/ui/breadcrumb.d.ts +0 -11
- package/lib/components/ui/breadcrumb.js +0 -27
- package/lib/components/ui/button-group.d.ts +0 -11
- package/lib/components/ui/button-group.js +0 -31
- package/lib/components/ui/button.d.ts +0 -13
- package/lib/components/ui/button.js +0 -39
- package/lib/components/ui/calendar.d.ts +0 -8
- package/lib/components/ui/calendar.js +0 -80
- package/lib/components/ui/card.d.ts +0 -9
- package/lib/components/ui/card.js +0 -24
- package/lib/components/ui/carousel.d.ts +0 -19
- package/lib/components/ui/carousel.js +0 -95
- package/lib/components/ui/chart.d.ts +0 -53
- package/lib/components/ui/chart.js +0 -136
- package/lib/components/ui/checkbox.d.ts +0 -4
- package/lib/components/ui/checkbox.js +0 -13
- package/lib/components/ui/collapsible.d.ts +0 -5
- package/lib/components/ui/collapsible.js +0 -17
- package/lib/components/ui/command.d.ts +0 -18
- package/lib/components/ui/command.js +0 -38
- package/lib/components/ui/context-menu.d.ts +0 -25
- package/lib/components/ui/context-menu.js +0 -55
- package/lib/components/ui/dialog.d.ts +0 -15
- package/lib/components/ui/dialog.js +0 -40
- package/lib/components/ui/drawer.d.ts +0 -13
- package/lib/components/ui/drawer.js +0 -39
- package/lib/components/ui/dropdown-menu.d.ts +0 -25
- package/lib/components/ui/dropdown-menu.js +0 -55
- package/lib/components/ui/empty.d.ts +0 -11
- package/lib/components/ui/empty.js +0 -37
- package/lib/components/ui/field.d.ts +0 -24
- package/lib/components/ui/field.js +0 -80
- package/lib/components/ui/form.d.ts +0 -24
- package/lib/components/ui/form.js +0 -63
- package/lib/components/ui/hover-card.d.ts +0 -6
- package/lib/components/ui/hover-card.js +0 -18
- package/lib/components/ui/input-group.d.ts +0 -19
- package/lib/components/ui/input-group.js +0 -69
- package/lib/components/ui/input-otp.d.ts +0 -11
- package/lib/components/ui/input-otp.js +0 -25
- package/lib/components/ui/input.d.ts +0 -3
- package/lib/components/ui/input.js +0 -6
- package/lib/components/ui/item.d.ts +0 -23
- package/lib/components/ui/item.js +0 -66
- package/lib/components/ui/kbd.d.ts +0 -3
- package/lib/components/ui/kbd.js +0 -13
- package/lib/components/ui/label.d.ts +0 -4
- package/lib/components/ui/label.js +0 -12
- package/lib/components/ui/menubar.d.ts +0 -26
- package/lib/components/ui/menubar.js +0 -58
- package/lib/components/ui/navigation-menu.d.ts +0 -14
- package/lib/components/ui/navigation-menu.js +0 -31
- package/lib/components/ui/pagination.d.ts +0 -13
- package/lib/components/ui/pagination.js +0 -29
- package/lib/components/ui/popover.d.ts +0 -7
- package/lib/components/ui/popover.js +0 -21
- package/lib/components/ui/progress.d.ts +0 -4
- package/lib/components/ui/progress.js +0 -12
- package/lib/components/ui/radio-group.d.ts +0 -5
- package/lib/components/ui/radio-group.js +0 -16
- package/lib/components/ui/resizable.d.ts +0 -8
- package/lib/components/ui/resizable.js +0 -19
- package/lib/components/ui/scroll-area.d.ts +0 -5
- package/lib/components/ui/scroll-area.js +0 -17
- package/lib/components/ui/select.d.ts +0 -15
- package/lib/components/ui/select.js +0 -42
- package/lib/components/ui/separator.d.ts +0 -4
- package/lib/components/ui/separator.js +0 -12
- package/lib/components/ui/sheet.d.ts +0 -13
- package/lib/components/ui/sheet.js +0 -44
- package/lib/components/ui/sidebar.d.ts +0 -69
- package/lib/components/ui/sidebar.js +0 -216
- package/lib/components/ui/skeleton.d.ts +0 -2
- package/lib/components/ui/skeleton.js +0 -10
- package/lib/components/ui/slider.d.ts +0 -4
- package/lib/components/ui/slider.js +0 -18
- package/lib/components/ui/sonner.d.ts +0 -3
- package/lib/components/ui/sonner.js +0 -25
- package/lib/components/ui/spinner.d.ts +0 -2
- package/lib/components/ui/spinner.js +0 -11
- package/lib/components/ui/switch.d.ts +0 -4
- package/lib/components/ui/switch.js +0 -12
- package/lib/components/ui/table.d.ts +0 -10
- package/lib/components/ui/table.js +0 -32
- package/lib/components/ui/tabs.d.ts +0 -7
- package/lib/components/ui/tabs.js +0 -21
- package/lib/components/ui/textarea.d.ts +0 -3
- package/lib/components/ui/textarea.js +0 -6
- package/lib/components/ui/toast.d.ts +0 -15
- package/lib/components/ui/toast.js +0 -38
- package/lib/components/ui/toaster.d.ts +0 -1
- package/lib/components/ui/toaster.js +0 -14
- package/lib/components/ui/toggle-group.d.ts +0 -9
- package/lib/components/ui/toggle-group.js +0 -26
- package/lib/components/ui/toggle.d.ts +0 -9
- package/lib/components/ui/toggle.js +0 -30
- package/lib/components/ui/tooltip.d.ts +0 -7
- package/lib/components/ui/tooltip.js +0 -21
- package/lib/components/vercel-ai-elements/artifact.d.ts +0 -23
- package/lib/components/vercel-ai-elements/artifact.js +0 -24
- package/lib/components/vercel-ai-elements/code-block.d.ts +0 -17
- package/lib/components/vercel-ai-elements/code-block.js +0 -94
- package/lib/components/vercel-ai-elements/conversation.d.ts +0 -15
- package/lib/components/vercel-ai-elements/conversation.js +0 -21
- package/lib/components/vercel-ai-elements/loader.d.ts +0 -5
- package/lib/components/vercel-ai-elements/loader.js +0 -8
- package/lib/components/vercel-ai-elements/message.d.ts +0 -46
- package/lib/components/vercel-ai-elements/message.js +0 -109
- package/lib/components/vercel-ai-elements/model-selector.d.ts +0 -35
- package/lib/components/vercel-ai-elements/model-selector.js +0 -22
- package/lib/components/vercel-ai-elements/prompt-input.d.ts +0 -195
- package/lib/components/vercel-ai-elements/prompt-input.js +0 -589
- package/lib/components/vercel-ai-elements/reasoning.d.ts +0 -26
- package/lib/components/vercel-ai-elements/reasoning.js +0 -80
- package/lib/components/vercel-ai-elements/shimmer.d.ts +0 -9
- package/lib/components/vercel-ai-elements/shimmer.js +0 -22
- package/lib/components/vercel-ai-elements/sources.d.ts +0 -12
- package/lib/components/vercel-ai-elements/sources.js +0 -13
- package/lib/components/vercel-ai-elements/suggestion.d.ts +0 -10
- package/lib/components/vercel-ai-elements/suggestion.js +0 -16
- package/lib/components/vercel-ai-elements/tool.d.ts +0 -23
- package/lib/components/vercel-ai-elements/tool.js +0 -52
- package/lib/examples/components/MainContent.d.ts +0 -19
- package/lib/examples/components/index.d.ts +0 -10
- package/lib/examples/components/index.js +0 -13
- package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.d.ts +0 -12
- package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.js +0 -69
- package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.js +0 -85
- package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.js +0 -62
- package/lib/examples/vercel-ai-elements/components/ConversationShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ConversationShowcase.js +0 -51
- package/lib/examples/vercel-ai-elements/components/LoaderShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/LoaderShowcase.js +0 -9
- package/lib/examples/vercel-ai-elements/components/MessageShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/MessageShowcase.js +0 -56
- package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.js +0 -50
- package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.js +0 -16
- package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.js +0 -72
- package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.js +0 -9
- package/lib/examples/vercel-ai-elements/components/SourcesShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/SourcesShowcase.js +0 -43
- package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.js +0 -31
- package/lib/examples/vercel-ai-elements/components/ToolShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ToolShowcase.js +0 -54
- package/lib/examples/vercel-ai-elements/index.d.ts +0 -13
- package/lib/examples/vercel-ai-elements/index.js +0 -17
- package/lib/examples/vercel-ai-elements/main.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/main.js +0 -9
- package/lib/examples/vercel-ai-elements/showcase.css +0 -128
- package/lib/hooks/useToast.d.ts +0 -44
- package/lib/hooks/useToast.js +0 -128
- package/patches/@datalayer+jupyter-lexical+1.0.8.patch +0 -11628
- package/patches/@datalayer+jupyter-react+2.0.2.patch +0 -5338
- package/style/showcase-vercel-ai.css +0 -137
- /package/lib/{examples/components → components}/FooterMetrics.js +0 -0
- /package/lib/{examples/components → components}/MockFileBrowser.js +0 -0
- /package/lib/{examples/components → components}/SessionTabs.js +0 -0
- /package/lib/{examples/components → components}/TimeTravel.js +0 -0
- /package/lib/{models → types}/AIAgent.d.ts +0 -0
- /package/lib/{models → types}/AIAgent.js +0 -0
- /package/lib/{models → types}/index.d.ts +0 -0
- /package/lib/{models → types}/index.js +0 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
# Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Agent Specification Code Generator.
|
|
7
|
+
|
|
8
|
+
Generates Python and TypeScript code from YAML agent specifications.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any, Dict, List
|
|
15
|
+
|
|
16
|
+
import yaml
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _fmt_list(items: list[str]) -> str:
|
|
20
|
+
"""Format a list of strings with double quotes for ruff compliance."""
|
|
21
|
+
if not items:
|
|
22
|
+
return "[]"
|
|
23
|
+
return "[" + ", ".join(f'"{item}"' for item in items) + "]"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def load_yaml_specs(specs_dir: Path) -> List[Dict[str, Any]]:
|
|
27
|
+
"""Load all YAML agent specifications from directory."""
|
|
28
|
+
specs = []
|
|
29
|
+
for yaml_file in sorted(specs_dir.glob("*.yaml")):
|
|
30
|
+
with open(yaml_file, "r") as f:
|
|
31
|
+
spec = yaml.safe_load(f)
|
|
32
|
+
if spec: # Skip empty files
|
|
33
|
+
specs.append(spec)
|
|
34
|
+
return specs
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def generate_python_code(specs: List[Dict[str, Any]]) -> str:
|
|
38
|
+
"""Generate Python code from agent specifications."""
|
|
39
|
+
# Header
|
|
40
|
+
code = '''# Copyright (c) 2025-2026 Datalayer, Inc.
|
|
41
|
+
# Distributed under the terms of the Modified BSD License.
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
Agent Library.
|
|
45
|
+
|
|
46
|
+
Predefined agent specifications that can be instantiated as AgentSpaces.
|
|
47
|
+
THIS FILE IS AUTO-GENERATED. DO NOT EDIT MANUALLY.
|
|
48
|
+
Generated from YAML specifications in specs/agents/
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
from typing import Dict
|
|
52
|
+
|
|
53
|
+
from agent_runtimes.mcp.catalog_mcp_servers import MCP_SERVER_CATALOG
|
|
54
|
+
from agent_runtimes.types import AgentSpec
|
|
55
|
+
|
|
56
|
+
# ============================================================================
|
|
57
|
+
# Agent Specs
|
|
58
|
+
# ============================================================================
|
|
59
|
+
|
|
60
|
+
'''
|
|
61
|
+
|
|
62
|
+
# Generate agent spec constants
|
|
63
|
+
agent_ids = []
|
|
64
|
+
for spec in specs:
|
|
65
|
+
agent_id = spec["id"]
|
|
66
|
+
# Create constant name: e.g., "data-acquisition" -> "DATA_ACQUISITION_AGENT_SPEC"
|
|
67
|
+
# But if id already ends with "-agent", don't duplicate: "github-agent" -> "GITHUB_AGENT_SPEC"
|
|
68
|
+
if agent_id.endswith("-agent"):
|
|
69
|
+
const_name = agent_id.upper().replace("-", "_") + "_SPEC"
|
|
70
|
+
else:
|
|
71
|
+
const_name = agent_id.upper().replace("-", "_") + "_AGENT_SPEC"
|
|
72
|
+
agent_ids.append((agent_id, const_name))
|
|
73
|
+
|
|
74
|
+
# Get MCP servers
|
|
75
|
+
mcp_server_ids = spec.get("mcp_servers", [])
|
|
76
|
+
mcp_servers_str = ", ".join(
|
|
77
|
+
f'MCP_SERVER_CATALOG["{sid}"]' for sid in mcp_server_ids
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Format optional fields
|
|
81
|
+
icon = f'"{spec.get("icon")}"' if spec.get("icon") else "None"
|
|
82
|
+
color = f'"{spec.get("color")}"' if spec.get("color") else "None"
|
|
83
|
+
suggestions = spec.get("suggestions", [])
|
|
84
|
+
suggestions_str = (
|
|
85
|
+
"[\n "
|
|
86
|
+
+ ",\n ".join(f'"{s}"' for s in suggestions)
|
|
87
|
+
+ ",\n ]"
|
|
88
|
+
if suggestions
|
|
89
|
+
else "[]"
|
|
90
|
+
)
|
|
91
|
+
# Escape multi-line strings properly
|
|
92
|
+
welcome = spec.get("welcome_message", "").replace('"', '\\"').replace("\n", " ")
|
|
93
|
+
welcome_notebook = spec.get("welcome_notebook")
|
|
94
|
+
welcome_document = spec.get("welcome_document")
|
|
95
|
+
system_prompt = spec.get("system_prompt", "")
|
|
96
|
+
system_prompt_codemode = spec.get("system_prompt_codemode", "")
|
|
97
|
+
|
|
98
|
+
# Escape triple quotes in system prompts for Python triple-quoted strings
|
|
99
|
+
if system_prompt:
|
|
100
|
+
system_prompt = system_prompt.replace('"""', r"\"\"\"")
|
|
101
|
+
if system_prompt_codemode:
|
|
102
|
+
system_prompt_codemode = system_prompt_codemode.replace('"""', r"\"\"\"")
|
|
103
|
+
|
|
104
|
+
# Clean description for Python (single line)
|
|
105
|
+
description = spec["description"].replace("\n", " ").replace(" ", " ").strip()
|
|
106
|
+
|
|
107
|
+
# Use triple quotes for multiline system prompts
|
|
108
|
+
system_prompt_str = f'"""{system_prompt}"""' if system_prompt else "None"
|
|
109
|
+
system_prompt_codemode_str = (
|
|
110
|
+
f'"""{system_prompt_codemode}"""' if system_prompt_codemode else "None"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
code += f'''{const_name} = AgentSpec(
|
|
114
|
+
id="{spec["id"]}",
|
|
115
|
+
name="{spec["name"]}",
|
|
116
|
+
description="{description}",
|
|
117
|
+
tags={_fmt_list(spec.get("tags", []))},
|
|
118
|
+
enabled={spec.get("enabled", True)},
|
|
119
|
+
mcp_servers=[{mcp_servers_str}],
|
|
120
|
+
skills={_fmt_list(spec.get("skills", []))},
|
|
121
|
+
environment_name="{spec.get("environment_name", "ai-agents-env")}",
|
|
122
|
+
icon={icon},
|
|
123
|
+
color={color},
|
|
124
|
+
suggestions={suggestions_str},
|
|
125
|
+
welcome_message="{welcome}",
|
|
126
|
+
welcome_notebook={f'"{welcome_notebook}"' if welcome_notebook else "None"},
|
|
127
|
+
welcome_document={f'"{welcome_document}"' if welcome_document else "None"},
|
|
128
|
+
system_prompt={system_prompt_str},
|
|
129
|
+
system_prompt_codemode={system_prompt_codemode_str},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
'''
|
|
133
|
+
|
|
134
|
+
# Generate registry
|
|
135
|
+
code += """
|
|
136
|
+
# ============================================================================
|
|
137
|
+
# Agent Specs Registry
|
|
138
|
+
# ============================================================================
|
|
139
|
+
|
|
140
|
+
AGENT_SPECS: Dict[str, AgentSpec] = {
|
|
141
|
+
"""
|
|
142
|
+
for agent_id, const_name in agent_ids:
|
|
143
|
+
code += f' "{agent_id}": {const_name},\n'
|
|
144
|
+
|
|
145
|
+
code += """}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def get_agent_spec(agent_id: str) -> AgentSpec | None:
|
|
149
|
+
\"\"\"
|
|
150
|
+
Get an agent specification by ID.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
agent_id: The unique identifier of the agent.
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
The AgentSpec configuration, or None if not found.
|
|
157
|
+
\"\"\"
|
|
158
|
+
return AGENT_SPECS.get(agent_id)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def list_agent_specs() -> list[AgentSpec]:
|
|
162
|
+
\"\"\"
|
|
163
|
+
List all available agent specifications.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
List of all AgentSpec configurations.
|
|
167
|
+
\"\"\"
|
|
168
|
+
return list(AGENT_SPECS.values())
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
return code
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def generate_typescript_code(
|
|
175
|
+
specs: List[Dict[str, Any]], mcp_specs_dir: str, skills_specs_dir: str
|
|
176
|
+
) -> str:
|
|
177
|
+
"""Generate TypeScript code from agent specifications."""
|
|
178
|
+
# Load available MCP servers from specs
|
|
179
|
+
import glob
|
|
180
|
+
import os
|
|
181
|
+
|
|
182
|
+
mcp_server_files = glob.glob(os.path.join(mcp_specs_dir, "*.yaml"))
|
|
183
|
+
mcp_server_ids = [
|
|
184
|
+
os.path.basename(f).replace(".yaml", "") for f in mcp_server_files
|
|
185
|
+
]
|
|
186
|
+
mcp_server_ids.sort()
|
|
187
|
+
|
|
188
|
+
# Load available skills from specs
|
|
189
|
+
skill_files = glob.glob(os.path.join(skills_specs_dir, "*.yaml"))
|
|
190
|
+
skill_ids = [os.path.basename(f).replace(".yaml", "") for f in skill_files]
|
|
191
|
+
skill_ids.sort()
|
|
192
|
+
|
|
193
|
+
# Generate import names and map entries dynamically
|
|
194
|
+
mcp_imports = []
|
|
195
|
+
mcp_map_entries = []
|
|
196
|
+
for server_id in mcp_server_ids:
|
|
197
|
+
const_name = server_id.upper().replace("-", "_") + "_MCP_SERVER"
|
|
198
|
+
mcp_imports.append(const_name)
|
|
199
|
+
mcp_map_entries.append(f" '{server_id}': {const_name},")
|
|
200
|
+
|
|
201
|
+
# Generate skill import names and map entries
|
|
202
|
+
skill_imports = []
|
|
203
|
+
skill_map_entries = []
|
|
204
|
+
for sid in skill_ids:
|
|
205
|
+
const_name = sid.upper().replace("-", "_") + "_SKILL_SPEC"
|
|
206
|
+
skill_imports.append(const_name)
|
|
207
|
+
skill_map_entries.append(f" '{sid}': {const_name},")
|
|
208
|
+
|
|
209
|
+
# Header
|
|
210
|
+
code = """/*
|
|
211
|
+
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
212
|
+
* Distributed under the terms of the Modified BSD License.
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Agent Library.
|
|
217
|
+
*
|
|
218
|
+
* Predefined agent specifications that can be instantiated as AgentSpaces.
|
|
219
|
+
* THIS FILE IS AUTO-GENERATED. DO NOT EDIT MANUALLY.
|
|
220
|
+
* Generated from YAML specifications in specs/agents/
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
import type { AgentSpec } from '../types';
|
|
224
|
+
import {
|
|
225
|
+
"""
|
|
226
|
+
code += " " + ",\n ".join(mcp_imports) + ",\n"
|
|
227
|
+
code += """} from './mcpServers';
|
|
228
|
+
import {
|
|
229
|
+
"""
|
|
230
|
+
code += " " + ",\n ".join(skill_imports) + ",\n"
|
|
231
|
+
code += """} from './skills';
|
|
232
|
+
import type { SkillSpec } from './skills';
|
|
233
|
+
|
|
234
|
+
// ============================================================================
|
|
235
|
+
// MCP Server Lookup
|
|
236
|
+
// ============================================================================
|
|
237
|
+
|
|
238
|
+
const MCP_SERVER_MAP: Record<string, any> = {
|
|
239
|
+
"""
|
|
240
|
+
code += "\n".join(mcp_map_entries) + "\n"
|
|
241
|
+
code += """};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Map skill IDs to SkillSpec objects, converting to AgentSkillSpec shape.
|
|
245
|
+
*/
|
|
246
|
+
const SKILL_MAP: Record<string, any> = {
|
|
247
|
+
"""
|
|
248
|
+
code += "\n".join(skill_map_entries) + "\n"
|
|
249
|
+
code += """};
|
|
250
|
+
|
|
251
|
+
function toAgentSkillSpec(skill: SkillSpec) {
|
|
252
|
+
return {
|
|
253
|
+
id: skill.id,
|
|
254
|
+
name: skill.name,
|
|
255
|
+
description: skill.description,
|
|
256
|
+
version: '1.0.0',
|
|
257
|
+
tags: skill.tags,
|
|
258
|
+
enabled: skill.enabled,
|
|
259
|
+
requiredEnvVars: skill.requiredEnvVars,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ============================================================================
|
|
264
|
+
// Agent Specs
|
|
265
|
+
// ============================================================================
|
|
266
|
+
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
# Generate agent spec constants
|
|
270
|
+
agent_ids = []
|
|
271
|
+
for spec in specs:
|
|
272
|
+
agent_id = spec["id"]
|
|
273
|
+
# Create constant name: e.g., "data-acquisition" -> "DATA_ACQUISITION_AGENT_SPEC"
|
|
274
|
+
# But if id already ends with "-agent", don't duplicate: "github-agent" -> "GITHUB_AGENT_SPEC"
|
|
275
|
+
if agent_id.endswith("-agent"):
|
|
276
|
+
const_name = agent_id.upper().replace("-", "_") + "_SPEC"
|
|
277
|
+
else:
|
|
278
|
+
const_name = agent_id.upper().replace("-", "_") + "_AGENT_SPEC"
|
|
279
|
+
agent_ids.append((agent_id, const_name))
|
|
280
|
+
|
|
281
|
+
# Get MCP servers
|
|
282
|
+
mcp_server_ids = spec.get("mcp_servers", [])
|
|
283
|
+
mcp_servers_str = ", ".join(
|
|
284
|
+
f"MCP_SERVER_MAP['{sid}']" for sid in mcp_server_ids
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
# Get skills - resolve to AgentSkillSpec via toAgentSkillSpec
|
|
288
|
+
skill_ids_list = spec.get("skills", [])
|
|
289
|
+
if skill_ids_list:
|
|
290
|
+
skills_str = ", ".join(
|
|
291
|
+
f"toAgentSkillSpec(SKILL_MAP['{sid}'])" for sid in skill_ids_list
|
|
292
|
+
)
|
|
293
|
+
else:
|
|
294
|
+
skills_str = ""
|
|
295
|
+
|
|
296
|
+
# Format tags and suggestions as arrays
|
|
297
|
+
tags = spec.get("tags", [])
|
|
298
|
+
tags_str = "[" + ", ".join(f"'{t}'" for t in tags) + "]"
|
|
299
|
+
|
|
300
|
+
suggestions = spec.get("suggestions", [])
|
|
301
|
+
# Escape single quotes in suggestions for TypeScript
|
|
302
|
+
escaped_suggestions = [s.replace("'", "\\'") for s in suggestions]
|
|
303
|
+
suggestions_str = (
|
|
304
|
+
"[\n " + ",\n ".join(f"'{s}'" for s in escaped_suggestions) + ",\n ]"
|
|
305
|
+
if suggestions
|
|
306
|
+
else "[]"
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
# Format optional fields
|
|
310
|
+
icon = f"'{spec.get('icon')}'" if spec.get("icon") else "undefined"
|
|
311
|
+
color = f"'{spec.get('color')}'" if spec.get("color") else "undefined"
|
|
312
|
+
system_prompt = spec.get("system_prompt")
|
|
313
|
+
system_prompt_codemode = spec.get("system_prompt_codemode")
|
|
314
|
+
|
|
315
|
+
# Escape backticks for TypeScript template literals
|
|
316
|
+
if system_prompt:
|
|
317
|
+
system_prompt = system_prompt.replace("`", "\\`")
|
|
318
|
+
if system_prompt_codemode:
|
|
319
|
+
system_prompt_codemode = system_prompt_codemode.replace("`", "\\`")
|
|
320
|
+
|
|
321
|
+
# Clean description for TypeScript (multi-line template literal)
|
|
322
|
+
description = spec["description"].replace("\n", " ").replace(" ", " ").strip()
|
|
323
|
+
|
|
324
|
+
code += f"""export const {const_name}: AgentSpec = {{
|
|
325
|
+
id: '{spec["id"]}',
|
|
326
|
+
name: '{spec["name"]}',
|
|
327
|
+
description: `{description}`,
|
|
328
|
+
tags: {tags_str},
|
|
329
|
+
enabled: {str(spec.get("enabled", True)).lower()},
|
|
330
|
+
mcpServers: [{mcp_servers_str}],
|
|
331
|
+
skills: [{skills_str}],
|
|
332
|
+
environmentName: '{spec.get("environment_name", "ai-agents-env")}',
|
|
333
|
+
icon: {icon},
|
|
334
|
+
color: {color},
|
|
335
|
+
suggestions: {suggestions_str},
|
|
336
|
+
systemPrompt: {f"`{system_prompt}`" if system_prompt else "undefined"},
|
|
337
|
+
systemPromptCodemode: {f"`{system_prompt_codemode}`" if system_prompt_codemode else "undefined"},
|
|
338
|
+
}};
|
|
339
|
+
|
|
340
|
+
"""
|
|
341
|
+
|
|
342
|
+
# Generate registry
|
|
343
|
+
code += """// ============================================================================
|
|
344
|
+
// Agent Specs Registry
|
|
345
|
+
// ============================================================================
|
|
346
|
+
|
|
347
|
+
export const AGENT_SPECS: Record<string, AgentSpec> = {
|
|
348
|
+
"""
|
|
349
|
+
for agent_id, const_name in agent_ids:
|
|
350
|
+
code += f" '{agent_id}': {const_name},\n"
|
|
351
|
+
|
|
352
|
+
code += """};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Get an agent specification by ID.
|
|
356
|
+
*/
|
|
357
|
+
export function getAgentSpecs(agentId: string): AgentSpec | undefined {
|
|
358
|
+
return AGENT_SPECS[agentId];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* List all available agent specifications.
|
|
363
|
+
*/
|
|
364
|
+
export function listAgentSpecs(): AgentSpec[] {
|
|
365
|
+
return Object.values(AGENT_SPECS);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Collect all required environment variables for an agent spec.
|
|
370
|
+
*
|
|
371
|
+
* Iterates over the spec's MCP servers and skills and returns the
|
|
372
|
+
* deduplicated union of their `requiredEnvVars` arrays.
|
|
373
|
+
*/
|
|
374
|
+
export function getAgentSpecRequiredEnvVars(spec: AgentSpec): string[] {
|
|
375
|
+
const vars = new Set<string>();
|
|
376
|
+
for (const server of spec.mcpServers) {
|
|
377
|
+
for (const v of server.requiredEnvVars ?? []) {
|
|
378
|
+
vars.add(v);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
for (const skill of spec.skills) {
|
|
382
|
+
for (const v of skill.requiredEnvVars ?? []) {
|
|
383
|
+
vars.add(v);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return Array.from(vars);
|
|
387
|
+
}
|
|
388
|
+
"""
|
|
389
|
+
|
|
390
|
+
return code
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def main():
|
|
394
|
+
"""Main entry point."""
|
|
395
|
+
parser = argparse.ArgumentParser(
|
|
396
|
+
description="Generate Python and TypeScript code from YAML agent specifications"
|
|
397
|
+
)
|
|
398
|
+
parser.add_argument(
|
|
399
|
+
"--specs-dir",
|
|
400
|
+
type=Path,
|
|
401
|
+
default=Path("specs/agents"),
|
|
402
|
+
help="Directory containing YAML agent specifications",
|
|
403
|
+
)
|
|
404
|
+
parser.add_argument(
|
|
405
|
+
"--python-output",
|
|
406
|
+
type=Path,
|
|
407
|
+
default=Path("agent_runtimes/config/agents.py"),
|
|
408
|
+
help="Output path for generated Python code",
|
|
409
|
+
)
|
|
410
|
+
parser.add_argument(
|
|
411
|
+
"--typescript-output",
|
|
412
|
+
type=Path,
|
|
413
|
+
default=Path("src/config/agents.ts"),
|
|
414
|
+
help="Output path for generated TypeScript code",
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
args = parser.parse_args()
|
|
418
|
+
|
|
419
|
+
# Check specs directory exists
|
|
420
|
+
if not args.specs_dir.exists():
|
|
421
|
+
print(f"Error: Specs directory not found: {args.specs_dir}", file=sys.stderr)
|
|
422
|
+
sys.exit(1)
|
|
423
|
+
|
|
424
|
+
# Load YAML specifications
|
|
425
|
+
print(f"Loading agent specifications from {args.specs_dir}...")
|
|
426
|
+
specs = load_yaml_specs(args.specs_dir)
|
|
427
|
+
print(f"Loaded {len(specs)} agent specification(s)")
|
|
428
|
+
|
|
429
|
+
# Generate Python code
|
|
430
|
+
print(f"Generating Python code to {args.python_output}...")
|
|
431
|
+
python_code = generate_python_code(specs)
|
|
432
|
+
args.python_output.parent.mkdir(parents=True, exist_ok=True)
|
|
433
|
+
with open(args.python_output, "w") as f:
|
|
434
|
+
f.write(python_code)
|
|
435
|
+
|
|
436
|
+
# Generate TypeScript code
|
|
437
|
+
print(f"Generating TypeScript code to {args.typescript_output}...")
|
|
438
|
+
# Get MCP and skills specs directories (siblings to agents directory)
|
|
439
|
+
mcp_specs_dir = args.specs_dir.parent / "mcp-servers"
|
|
440
|
+
skills_specs_dir = args.specs_dir.parent / "skills"
|
|
441
|
+
typescript_code = generate_typescript_code(
|
|
442
|
+
specs, str(mcp_specs_dir), str(skills_specs_dir)
|
|
443
|
+
)
|
|
444
|
+
args.typescript_output.parent.mkdir(parents=True, exist_ok=True)
|
|
445
|
+
with open(args.typescript_output, "w") as f:
|
|
446
|
+
f.write(typescript_code)
|
|
447
|
+
|
|
448
|
+
print("✅ Code generation complete!")
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
if __name__ == "__main__":
|
|
452
|
+
main()
|