MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / runListModelsCmd

Function runListModelsCmd

internal/providers/models.go:311–336  ·  view source on GitHub ↗
(ep Endpoint, epName string, getenv func(string) string)

Source from the content-addressed store, hash-verified

309}
310
311func runListModelsCmd(ep Endpoint, epName string, getenv func(string) string) ([]string, error) {
312 ctx, cancel := context.WithTimeout(context.Background(), modelDiscoveryTimeout)
313 defer cancel()
314
315 name, args := discoveryShell(ep.ListModelsCmd)
316 cmd := exec.CommandContext(ctx, name, args...)
317 cmd.Env = buildDiscoveryEnv(ep, getenv)
318
319 out, err := cmd.Output()
320 if ctx.Err() == context.DeadlineExceeded {
321 return nil, fmt.Errorf("providers: list_models_cmd for %s timed out after %s", epName, modelDiscoveryTimeout)
322 }
323 if err != nil {
324 if exit, ok := err.(*exec.ExitError); ok {
325 return nil, fmt.Errorf("providers: list_models_cmd for %s exited %d: %s",
326 epName, exit.ExitCode(), strings.TrimSpace(string(exit.Stderr)))
327 }
328 return nil, fmt.Errorf("providers: list_models_cmd for %s: %w", epName, err)
329 }
330
331 models := parseModelsOutput(string(out))
332 if len(models) == 0 {
333 return nil, ErrEmptyModelList
334 }
335 return models, nil
336}
337
338// parseModelsOutput splits stdout on \n and drops empty/whitespace lines.
339// Each surviving line is trimmed.

Callers 1

ResolveModelsFunction · 0.85

Calls 3

discoveryShellFunction · 0.85
buildDiscoveryEnvFunction · 0.85
parseModelsOutputFunction · 0.85

Tested by

no test coverage detected