Commit Graph
9 Commits
Author SHA1 Message Date
chenchen 66947cd543 Merge remote-tracking branch 'origin/feat/swarm-model-key-injection-60' into deploy/test-pr69-73 2026-06-11 19:19:34 +08:00
chenchenandClaude Opus 4.8 c494e9576e feat(swarm): #60 模型 key 注入(方案A)+ pool_terminated 吊销握手
对接 agent_swarm PR#43 定死的参数,实现 HM 侧的 per-user 模型 key 注入:

- A.1 粒度/命名:为认证用户 mint 一把 per-user sk-(getOrMintSwarmModelToken),
  跨该用户所有 swarm run 复用;KV 密文名 swarm-model-key-<user_id>。
- A.2 KV value:JSON {"openai_api_key":"sk-..."},对齐 Swarm
  orchestrator/agent_launcher._extract_model_key 解析字段。
- A.4 OPENAI_API_BASE 为 Swarm 部署常量,HM 不经 billing_context 下发。
- A.5 吊销:事件驱动。注册 swarm.pool_terminated(swarm_lifecycle 类),
  回调 handleSwarmPoolTerminated 删 KV 密文 + 软删 token;user_id 优先取
  payload,缺失回退 deployment 上下文。

createAgentDeploymentFromPlan 在 swarm 模式且 billing_context 未自带 secret_ref
时调 provisionSwarmModelKey,把 azkv:// 引用写进 billing_context.secret_ref 下发。
Key Vault 未配置/不可达时降级:记日志、secret_ref 留空,不阻断 create(联调前可用)。
明文 sk- 仅经 secret_ref 服务端解析,绝不入代码/日志/事件/argv。

测试:swarm_model_key_test.go 覆盖 per-user 复用、吊销重 mint、pool_terminated
回调(payload/上下文两路 user_id)、非目标事件不误吊销、事件已注册。

影响面:agent_swarm(契约消费侧)、密钥(per-user sk- mint+吊销)、计费
(走 User.Quota)、审计(回调入库+审计事件)。不影响 Client/CodeGW/发布链路。
未决依赖:A.3(Swarm 读 heicode-kv 的 RBAC,运维授权 pending)是端到端联调前置,
不阻塞本 PR。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 18:30:32 +08:00
chenchenandClaude Opus 4.8 a0616eaebf feat(swarm): 按订阅套餐控制蜂群使用权(管理员可配)
需求:管理员在 HM 控制台按订阅套餐控制谁能用蜂群。照搬现有 MaxAgents(#8)模式
(per-plan、管理员设、不硬编码 tier)。

后端:
- model SubscriptionPlan 加 SwarmEnabled bool(default false;AutoMigrate 加列,跨三库)。
- model GetUserSwarmEnabled(userId):用户任一活跃套餐 SwarmEnabled=true 即放行(镜像
  GetUserMaxAgents);无套餐/DB 不可用 => false(opt-in)。
- controller AgentCreateUserSwarm gate:普通用户须有开通套餐,管理员(role>=admin)绕过(测试/运维)。
- controller 套餐 admin upsert 字段映射加 swarm_enabled(create 整结构已自动带)。

前端(web/default 套餐编辑):
- plan-form schema/defaults/映射 + types 加 swarm_enabled。
- 套餐编辑抽屉加「蜂群使用权」Switch(镜像 enabled)。
- zh.json 加 "Swarm Access" → 蜂群使用权(en 用 key 兜底)。

默认关闭(opt-in)、管理员逐套餐勾选;gate 在 swarm 创建入口,与 swarm 运行时是否启用无关。
测试 TestGetUserSwarmEnabled(无套餐/开通/未开通/过期/多套餐/非法 user)。build+vet+model 测试全绿。

影响面:HM 订阅模型(加字段)+ swarm 创建鉴权 + admin UI;不涉计费扣费/密钥/swarm 契约。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 17:55:55 +08:00
zsbgnw12andGitHub 9444cdb498 fix agent deploy caps
approved
2026-06-08 17:49:35 +08:00
chenchenandClaude Opus 4.8 65ce549fb2 fix(heicode): sub-mode workflow/list gaps from desktop client (A/B/D/F)
Address the desktop client sub-mode gap report:
- B: /tasks list items now carry Manager-judged display_status (were raw
  status, so completed could really be needs_codegen).
- D: list + detail expose top-level mode (sub_agile|swarm) derived from the
  runtime mode, so a task recovered from /list after restart routes to the
  right mode instead of defaulting to sub-agile.
- F: unify mode naming on sub_agile everywhere (capabilities/list/detail/
  workflow); workflow keeps sub_mode for the agile/waterfall cadence.
- A: /workflow gains phases[], per-agent tokens/tools/elapsed_seconds/
  artifact_ids, and top-level metrics + aggregates, filled from runtime
  status diagnostics. Per-agent tokens/tools, artifact source role and phase
  breakdown surface as 0/[] until agent_management reports them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 16:20:38 +08:00
chenchenandClaude Opus 4.8 0f1d3d2009 feat(agent): three-layer status on workflow, error retryable, V2/envelope doc alignment
按桌面客户端 spec 重审后补齐:
- workflow 端点补三层状态(cloud_deployment_status/runtime_execution_status/display_status/
  conversation_id/last_synced_at,§10.2),作为客户端右侧面板状态源。
- agentError 补 error.retryable(§14)。
- 文档:明确 V2 body 加密与模型调用一致(directive)、真实响应 envelope、轮询刷新(无 SSE,
  按 §17.3 兜底)、需求包创建 + messages/execute/delete。

V2 加密链核验:新 /api/heicode/* 全走 UserOrV2DeviceAuth(同模型调用),
heicode-aead-v1/ChaCha20/Ed25519 常量未被改名误伤,中间件测试通过——加密未丢失。

go build ./... + go test 全绿。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 03:37:05 +08:00
chenchenandClaude Opus 4.8 7f3806c510 feat(agent): client requirement-package create + messages/execute/delete (spec §5.1/§8)
补齐桌面客户端对接缺口:之前 POST /tasks 只收 orchestration_plan、且缺 messages/execute/delete,
客户端无法照 spec §8 需求包直接对接。本次:

- POST /api/heicode/{sub-agile,swarm}/tasks 改收需求包 {mode,conversation_id,requirement,model_selection,roles},
  Manager 翻译成 orchestration_plan(per_role/default/primary 模型),仍兼容直传 orchestration_plan。
- POST .../tasks/{id}/messages:持续对话,记录用户消息 + 回当前 display_status。
- POST .../tasks/{id}/execute:确保派发 Runtime + reconcile。
- DELETE .../tasks/{id}:停止任务。
- 重构 createAgentDeploymentFromPlan,供原始 plan 与需求包两条路径复用。
- 更新 docs/integration/heicode-desktop-unified-api.md(创建改需求包 + 新路由)。

go build ./... + go test(controller/router)全绿。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 03:26:57 +08:00
chenchenandClaude Opus 4.8 443f552917 fix(agent): reconcile deployment from runtime status on read
真实生产模拟暴露:runtime 完成极快时,artifact.created/status callback 会与
runtime_swarm_id 映射的异步持久化竞态——callback 先到、按 swarm_id 匹配不到
deployment 而成孤儿,导致 deployment 永远停在 accepted、/artifacts 为空,
尽管 runtime 已 completed 且可直查到。

修复:detail / timeline / workflow / artifacts 读取时,对非终态且有 runtime
映射的 deployment 调 reconcileDeploymentFromRuntime——复用 diagnostics 的
runtime 状态直查,把终态 + 真实 artifact 反写落库,不再单依赖会丢/会竞态的 callback。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 00:05:43 +08:00
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