Files
heicode-mananger/heicode/model/agent_deployment.go
T
chenchenandClaude Opus 4.8 436b079c16 feat(agent): inject OPENAI_API_KEY (minted sk-) so the agent can call HM /v1
Deploy now also passes OPENAI_API_KEY (the 3rd of OPENAI_BASE_URL/MODEL_NAME/
OPENAI_API_KEY AM expects). HM mints a hidden, unlimited-quota sk- token for the
user per agent ("sk-"+key, billed to the user), injects it as OPENAI_API_KEY, and
stores the token id on the deployment. The token is revoked on delete and rolled
back if AM start / persist fails (no leaked keys). gateway accepts Bearer
sk-<key> (middleware strips sk-).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 16:44:17 +08:00

53 lines
3.1 KiB
Go

package model
// AgentDeployment stores the Manager-side deployment placeholder.
// It is intentionally a control-plane snapshot: the real Agent platform
// execution state can attach later, but Manager must not lose the accepted
// plan, manifest, status, or audit context across container restarts.
type AgentDeployment struct {
Id int `gorm:"primaryKey" json:"id"`
DeploymentID string `gorm:"type:varchar(64);uniqueIndex" json:"deployment_id"`
UserID string `gorm:"type:varchar(64);index" json:"user_id"`
ChannelID string `gorm:"type:varchar(64)" json:"channel_id"`
BindingScope string `gorm:"type:varchar(512);index" json:"binding_scope"`
CorrelationID string `gorm:"type:varchar(64);index" json:"correlation_id"`
SubMode string `gorm:"type:varchar(32);index" json:"sub_mode"`
Status string `gorm:"type:varchar(32);index" json:"status"`
Phase string `gorm:"type:varchar(32);index" json:"phase"`
RuntimeState string `gorm:"type:varchar(32)" json:"runtime_state"`
RuntimeDeploymentID string `gorm:"type:varchar(128);index" json:"runtime_deployment_id"`
RuntimeSwarmID string `gorm:"type:varchar(128);index" json:"runtime_swarm_id"`
RuntimeLastSyncAtText string `gorm:"type:varchar(32)" json:"runtime_last_sync_at"`
FailureReason string `gorm:"type:varchar(512)" json:"failure_reason"`
CreatedAtText string `gorm:"type:varchar(32)" json:"created_at"`
UpdatedAtText string `gorm:"type:varchar(32)" json:"updated_at"`
CreatedAtMs int64 `gorm:"bigint;index" json:"created_at_ms"`
UpdatedAtMs int64 `gorm:"bigint;index" json:"updated_at_ms"`
PlanJSON string `gorm:"type:text" json:"plan_json"`
AgentInstancesJSON string `gorm:"type:text" json:"agent_instances_json"`
PermissionManifestJSON string `gorm:"type:text" json:"permission_manifest_json"`
PayloadJSON string `gorm:"type:text" json:"payload_json"`
// --- Template-agent model (new) ---
// A deployed template agent: started by AM with the selected bound resources
// injected into its .env; reachable by the desktop client directly over SSE.
TemplateID string `gorm:"type:varchar(128);index" json:"template_id"`
Subdomain string `gorm:"type:varchar(255)" json:"subdomain"` // AM-assigned public address
AccessToken string `gorm:"type:varchar(512)" json:"access_token"` // client presents this to the agent; HM stores a copy
BindingIDsJSON string `gorm:"type:text" json:"binding_ids_json"` // JSON array of resource_binding ids attached to this agent
ModelTokenID int `gorm:"index" json:"model_token_id"` // sk- token minted for this agent's model calls (OPENAI_API_KEY); revoked on delete
}
func (AgentDeployment) TableName() string {
return "agent_deployments"
}
// DeleteAgentDeployment hard-removes a deployment row (client DELETE task).
func DeleteAgentDeployment(deploymentID string) error {
if DB == nil {
return nil
}
return DB.Where("deployment_id = ?", deploymentID).
Delete(&AgentDeployment{}).Error
}