Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/bryantaolong_coder.json
T
OpenCode 68a9071cf1 feat: reconcile local master with origin (exa/hot-platform hunters, leaks ledger, latest results)
Local branch had diverged from origin/master (sibling commits on the same base). Rewrote local history linearly on top of origin/master, folding in all local content: exa/hot-platform discovery hunters, leaks ledger, nightly sweep orchestrator, updated .gitignore and skill docs, plus the latest hunt output and vault state. Remote-only files (vault keys, channel scripts) were restored rather than dropped, so the resulting tree is a full union of both sides.
2026-08-07 12:53:47 +08:00

1 line
4.6 KiB
JSON

{"repo": "bryantaolong/coder", "files": {"internal/model/registry.go": {"ecd809355f0403ef21c6444adb1649cc1fb9c6fe": {"t": 1786068298.4319434, "n": 4105, "h": "aae6fa6630f00c08", "c": "package model\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"sync\"\n)\n\n// ModelRegistry manages multiple providers.\ntype ModelRegistry struct {\n\tmu sync.RWMutex\n\tproviders map[ProviderId]ModelProvider\n}\n\n// NewModelRegistry creates a new empty registry.\nfunc NewModelRegistry() *ModelRegistry {\n\treturn &ModelRegistry{\n\t\tproviders: make(map[ProviderId]ModelProvider),\n\t}\n}\n\n// Register adds a provider to the registry.\nfunc (r *ModelRegistry) Register(p ModelProvider) {\n\tr.mu.Lock()\n\tdefer r.mu.Unlock()\n\tr.providers[p.ID()] = p\n}\n\n// GetProvider returns a provider by ID.\nfunc (r *ModelRegistry) GetProvider(id ProviderId) (ModelProvider, bool) {\n\tr.mu.RLock()\n\tdefer r.mu.RUnlock()\n\tp, ok := r.providers[id]\n\treturn p, ok\n}\n\n// MustGetProvider returns a provider or panics.\nfunc (r *ModelRegistry) MustGetProvider(id ProviderId) ModelProvider {\n\tp, ok := r.GetProvider(id)\n\tif !ok {\n\t\tpanic(fmt.Sprintf(\"未注册的模型供应商: %s\", id))\n\t}\n\treturn p\n}\n\n// ListModels returns models for a specific provider.\nfunc (r *ModelRegistry) ListModels(ctx context.Context, providerId ProviderId) (ModelListResult, error) {\n\tp, ok := r.GetProvider(providerId)\n\tif !ok {\n\t\treturn ModelListResult{}, fmt.Errorf(\"未注册的模型供应商: %s\", providerId)\n\t}\n\treturn p.ListModels(ctx)\n}\n\n// ListAllModels returns models for all providers concurrently.\nfunc (r *ModelRegistry) ListAllModels(ctx context.Context) ([]ModelListResult, error) {\n\tr.mu.RLock()\n\tproviders := make([]ModelProvider, 0, len(r.providers))\n\tfor _, p := range r.providers {\n\t\tproviders = append(providers, p)\n\t}\n\tr.mu.RUnlock()\n\n\ttype result struct {\n\t\tprovider ProviderId\n\t\tresult ModelListResult\n\t\terr error\n\t}\n\tresults := make(chan result, len(providers))\n\tvar wg sync.WaitGroup\n\twg.Add(len(providers))\n\tfor _, p := range providers {\n\t\tgo func(p ModelProvider) {\n\t\t\tdefer wg.Done()\n\t\t\tres, err := p.ListModels(ctx)\n\t\t\tresults <- result{provider: p.ID(), result: res, err: err}\n\t\t}(p)\n\t}\n\tgo func() {\n\t\twg.Wait()\n\t\tclose(results)\n\t}()\n\n\tvar out []ModelListResult\n\tfor res := range results {\n\t\tif res.err != nil {\n\t\t\treturn nil, fmt.Errorf(\"list models for %s: %w\", res.provider, res.err)\n\t\t}\n\t\tout = append(out, res.result)\n\t}\n\treturn out, nil\n}\n\n// ListAllModelsFlat returns all models flattened with source metadata.\nfunc (r *ModelRegistry) ListAllModelsFlat(ctx context.Context) ([]ModelInfo, error) {\n\tresults, err := r.ListAllModels(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar out []ModelInfo\n\tfor _, res := range results {\n\t\tfor _, m := range res.Models {\n\t\t\tif m.Metadata == nil {\n\t\t\t\tm.Metadata = make(map[string]interface{})\n\t\t\t}\n\t\t\tm.Metadata[\"listSource\"] = string(res.Source)\n\t\t\tout = append(out, m)\n\t\t}\n\t}\n\treturn out, nil\n}\n\n// Chat sends a non-streaming request to a provider.\nfunc (r *ModelRegistry) Chat(ctx context.Context, providerId ProviderId, req ChatRequest) (ChatResponse, error) {\n\treturn r.MustGetProvider(providerId).Chat(ctx, req)\n}\n\n// ChatStream sends a streaming request to a provider.\nfunc (r *ModelRegistry) ChatStream(ctx context.Context, providerId ProviderId, req ChatRequest) (<-chan ChatStreamChunk, error) {\n\treturn r.MustGetProvider(providerId).ChatStream(ctx, req)\n}\n\n// CreateDefaultRegistry creates a registry with all default providers.\nfunc CreateDefaultRegistry(configs ProviderConfigs) *ModelRegistry {\n\tregistry := NewModelRegistry()\n\n\tfactories := []struct {\n\t\tid ProviderId\n\t\tfactory ProviderFactory\n\t\tenvKey string\n\t}{\n\t\t{ProviderDeepSeek, NewDeepSeekProvider, \"DEEPSEEK_API_KEY\"},\n\t\t{ProviderMiniMax, NewMiniMaxProvider, \"MINIMAX_API_KEY\"},\n\t\t{ProviderMoonshot, NewMoonshotProvider, \"MOONSHOT_API_KEY\"},\n\t\t{ProviderMimo, NewMimoProvider, \"MIMO_API_KEY\"},\n\t\t{ProviderZhipu, NewZhipuProvider, \"ZHIPU_API_KEY\"},\n\t}\n\n\tfor _, f := range factories {\n\t\toverride := configs[f.id]\n\t\tapiKey := override.APIKey\n\t\tif apiKey == \"\" {\n\t\t\tapiKey = os.Getenv(f.envKey)\n\t\t}\n\t\tcfg := ProviderConfig{\n\t\t\tAPIKey: apiKey,\n\t\t\tBaseURL: override.BaseURL,\n\t\t\tTimeoutMs: override.TimeoutMs,\n\t\t}\n\t\tregistry.Register(f.factory(cfg))\n\t}\n\n\treturn registry\n}\n\nvar ErrProviderNotFound = errors.New(\"provider not found\")\n"}}}}