molecule-core/platform/internal/handlers/bundle.go
Hongming Wang 24fec62d7f initial commit — Molecule AI platform
Forked clean from public hackathon repo (Starfire-AgentTeam, BSL 1.1)
with full rebrand to Molecule AI under github.com/Molecule-AI/molecule-monorepo.

Brand: Starfire → Molecule AI.
Slug: starfire / agent-molecule → molecule.
Env vars: STARFIRE_* → MOLECULE_*.
Go module: github.com/agent-molecule/platform → github.com/Molecule-AI/molecule-monorepo/platform.
Python packages: starfire_plugin → molecule_plugin, starfire_agent → molecule_agent.
DB: agentmolecule → molecule.

History truncated; see public repo for prior commits and contributor
attribution. Verified green: go test -race ./... (platform), pytest
(workspace-template 1129 + sdk 132), vitest (canvas 352), build (mcp).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 11:55:37 -07:00

58 lines
1.5 KiB
Go

package handlers
import (
"net/http"
"github.com/Molecule-AI/molecule-monorepo/platform/internal/bundle"
"github.com/Molecule-AI/molecule-monorepo/platform/internal/events"
"github.com/Molecule-AI/molecule-monorepo/platform/internal/provisioner"
"github.com/docker/docker/client"
"github.com/gin-gonic/gin"
)
type BundleHandler struct {
broadcaster *events.Broadcaster
provisioner *provisioner.Provisioner
platformURL string
configsDir string
docker *client.Client
}
func NewBundleHandler(b *events.Broadcaster, p *provisioner.Provisioner, platformURL, configsDir string, dockerCli *client.Client) *BundleHandler {
return &BundleHandler{
broadcaster: b,
provisioner: p,
platformURL: platformURL,
configsDir: configsDir,
docker: dockerCli,
}
}
// Export handles GET /bundles/export/:id
func (h *BundleHandler) Export(c *gin.Context) {
workspaceID := c.Param("id")
ctx := c.Request.Context()
b, err := bundle.Export(ctx, workspaceID, h.configsDir, h.docker)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, b)
}
// Import handles POST /bundles/import
func (h *BundleHandler) Import(c *gin.Context) {
var b bundle.Bundle
if err := c.ShouldBindJSON(&b); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
ctx := c.Request.Context()
result := bundle.Import(ctx, &b, nil, h.broadcaster, h.provisioner, h.platformURL)
c.JSON(http.StatusCreated, result)
}