feat(routing): 引入多执行池智能调度

将 Worker 发现、路由画像、容量与执行传输抽象为平台无关接口,新增 Kubernetes 和静态容量适配器,并以 shadow 模式接入生产配置。

实现网络与容量评分、路由防抖、池队列、同步 Worker 租约、一次性执行令牌,以及提交状态不明时禁止重复分配的安全语义。

新增 0105 兼容迁移、管理接口、指标、OpenAPI 和回归测试。已执行全量 Go 测试、go vet、OpenAPI、迁移安全、Compose 与 Kustomize 验证。
This commit is contained in:
2026-08-05 22:25:37 +08:00
parent 03c0873649
commit 7786692d32
58 changed files with 4510 additions and 348 deletions
@@ -0,0 +1,68 @@
package store
import (
"context"
)
type RouteProbeTarget struct {
Candidate RuntimeModelCandidate
Hot bool
}
func (s *Store) ListRouteProbeTargets(ctx context.Context) ([]RouteProbeTarget, error) {
rows, err := s.pool.Query(ctx, `
SELECT platform.id::text,
platform.provider,
COALESCE(NULLIF(platform.config->>'specType', ''), NULLIF(catalog.provider_type, ''), NULLIF(platform.config->>'sourceSpecType', ''), platform.provider),
COALESCE(
NULLIF(platform.base_url, ''),
NULLIF(platform.config->>'endpoint', ''),
NULLIF(platform.config->>'baseURL', ''),
NULLIF(platform.config->>'base_url', ''),
NULLIF(catalog.default_base_url, ''),
''
),
platform.config,
model.id::text,
COALESCE(model.model_type->>0, ''),
EXISTS (
SELECT 1
FROM gateway_task_attempts attempt
WHERE attempt.platform_model_id = model.id
AND attempt.started_at > now() - interval '10 minutes'
)
FROM integration_platforms platform
JOIN platform_models model ON model.platform_id = platform.id
LEFT JOIN model_catalog_providers catalog
ON catalog.provider_key = platform.provider OR catalog.provider_code = platform.provider
WHERE platform.status = 'enabled'
AND platform.deleted_at IS NULL
AND model.enabled = true
AND COALESCE(
NULLIF(platform.base_url, ''),
NULLIF(platform.config->>'endpoint', ''),
NULLIF(platform.config->>'baseURL', ''),
NULLIF(platform.config->>'base_url', ''),
NULLIF(catalog.default_base_url, '')
) IS NOT NULL
ORDER BY platform.id, model.id`)
if err != nil {
return nil, err
}
defer rows.Close()
items := make([]RouteProbeTarget, 0)
for rows.Next() {
var item RouteProbeTarget
var config []byte
if err := rows.Scan(
&item.Candidate.PlatformID, &item.Candidate.Provider, &item.Candidate.SpecType,
&item.Candidate.BaseURL, &config, &item.Candidate.PlatformModelID,
&item.Candidate.ModelType, &item.Hot,
); err != nil {
return nil, err
}
item.Candidate.PlatformConfig = decodeObject(config)
items = append(items, item)
}
return items, rows.Err()
}