Files
heicode-mananger/heicode/model/agent_approval.go
T
chenchenandClaude Opus 4.8 0fe1d20d67 feat(agent): unify agnet→agent and implement client/runtime unification spec v0.1 core
按桌面客户端统一方案 v0.1 + agent_management Sub Mode Runtime 对接,强制全量统一,不留兼容。

命名统一(强制,无兼容):
- 全仓 agnet/Agnet/AGNET → agent/Agent/AGENT:后端 Go(路由 /api/agent/*、env AGENT_*、
  结构体/函数、19 个文件改名)、前端(agent-console/agent-hub、/api/agent 调用、i18n)、
  DB(表 agent_*、列 agent_id)、compose/.env、文档、脚本。
- DB 加幂等迁移 renameAgnetTablesToAgent():启动时 rename 老 agnet_* 表/列,保住生产数据。

统一方案核心(10 项):
- callback 统一 /api/agent/callbacks/runtime-events(路由/广播URL/函数名)。
- artifact 兜底判定改用 Runtime 权威信号 metadata.synthesized(§7.2)+ 结构化 artifact_type。
- Manager→Runtime 路径对齐 /api/agent/sub-agile/deployments(§2.2),{deployment_id} 回退 swarm_id。
- 状态裁决 display_status:Manager 唯一裁判,completed 无有效产物→needs_codegen/
  completed_without_deliverable(§10.6),接入 detail/timeline/workflow。
- GET /api/heicode/capabilities 能力发现(§6)。
- 模型策略 per_role(role_models)+ 收集 allowed_model_ids(§9)。
- resource_binding_id→secret_ref 服务端解析,客户端不再 inline secret_ref(§17.6)。
- 客户端统一路由层 /api/heicode/sub-agile|swarm/*(task≡deployment,复用控制面)+ workflow 投影。
- 日志分层 user_logs/debug_logs(§13)。

验证:go build ./... + go test(controller/router/model/middleware)全绿;前端 tsc -b + rsbuild build 通过。
待部署:VM .env 的 AGNET_*→AGENT_*;启动迁移自动 rename 表;其他三仓库需同步切到 /api/agent。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-01 23:45:10 +08:00

65 lines
3.8 KiB
Go

package model
// AgentApprovalRequest records a user-visible approval gate for a
// high-risk Agent operation. It intentionally stores only a Secret
// Store reference for credential-backed operations; plaintext secrets
// must never be written to this table.
type AgentApprovalRequest struct {
Id int `json:"id" gorm:"primaryKey"`
ApprovalID string `json:"approval_id" gorm:"type:varchar(64);uniqueIndex;not null"`
UserId int `json:"user_id" gorm:"index;not null"`
DeploymentID string `json:"deployment_id" gorm:"type:varchar(64);index"`
BindingScope string `json:"binding_scope" gorm:"type:varchar(512);index"`
Operation string `json:"operation" gorm:"type:varchar(128);index;not null"`
ResourceID string `json:"resource_id" gorm:"type:varchar(128);index"`
ResourceType string `json:"resource_type" gorm:"type:varchar(32);index"`
ResourceScope string `json:"resource_scope" gorm:"type:varchar(512)"`
TargetRole string `json:"target_role" gorm:"type:varchar(128);index"`
RiskLevel string `json:"risk_level" gorm:"type:varchar(32);index;not null"`
RequiresCredential bool `json:"requires_credential" gorm:"default:false"`
SecretRef string `json:"secret_ref" gorm:"type:varchar(512)"`
CredentialLeaseID string `json:"credential_lease_id" gorm:"type:varchar(64);index"`
Status string `json:"status" gorm:"type:varchar(32);index;not null"`
RequestedBy string `json:"requested_by" gorm:"type:varchar(64)"`
DecidedBy string `json:"decided_by" gorm:"type:varchar(64)"`
RequestReason string `json:"request_reason" gorm:"type:text"`
DecisionReason string `json:"decision_reason" gorm:"type:text"`
TTLSeconds int `json:"ttl_seconds" gorm:"default:0"`
ExpiresAt int64 `json:"expires_at" gorm:"bigint;index"`
DecidedAt int64 `json:"decided_at" gorm:"bigint;default:0"`
CreatedAt int64 `json:"created_at" gorm:"autoCreateTime;column:created_at"`
UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime;column:updated_at"`
}
func (AgentApprovalRequest) TableName() string {
return "agent_approval_requests"
}
// AgentCredentialLease is the Manager-side short-lived credential
// handle produced after an approval succeeds. CredentialRef is the
// external handle; SecretRef is internal and points at Azure Key Vault.
type AgentCredentialLease struct {
Id int `json:"id" gorm:"primaryKey"`
LeaseID string `json:"lease_id" gorm:"type:varchar(64);uniqueIndex;not null"`
CredentialRef string `json:"credential_ref" gorm:"type:varchar(128);uniqueIndex;not null"`
ApprovalID string `json:"approval_id" gorm:"type:varchar(64);index;not null"`
UserId int `json:"user_id" gorm:"index;not null"`
DeploymentID string `json:"deployment_id" gorm:"type:varchar(64);index"`
BindingScope string `json:"binding_scope" gorm:"type:varchar(512);index"`
ResourceID string `json:"resource_id" gorm:"type:varchar(128);index"`
ResourceType string `json:"resource_type" gorm:"type:varchar(32);index"`
ResourceScope string `json:"resource_scope" gorm:"type:varchar(512)"`
TargetRole string `json:"target_role" gorm:"type:varchar(128);index"`
SecretRef string `json:"secret_ref" gorm:"type:varchar(512);not null"`
Status string `json:"status" gorm:"type:varchar(32);index;not null"`
TTLSeconds int `json:"ttl_seconds" gorm:"default:0"`
ExpiresAt int64 `json:"expires_at" gorm:"bigint;index"`
RevokedAt int64 `json:"revoked_at" gorm:"bigint;default:0"`
CreatedAt int64 `json:"created_at" gorm:"autoCreateTime;column:created_at"`
UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime;column:updated_at"`
}
func (AgentCredentialLease) TableName() string {
return "agent_credential_leases"
}