File size: 1,793 Bytes
6e38ce1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { ModelConfig } from "../tabs/agentSettings/modelSelector/modelConfigForms/types";
import { DEFAULT_OPENAI } from "../tabs/agentSettings/modelSelector/modelConfigForms/OpenAIModelConfigForm";
import { PROVIDER_FORM_MAP } from "../tabs/agentSettings/modelSelector/ModelSelector";

export const MODEL_CLIENT_CONFIGS = {
  orchestrator: {
    value: "orchestrator",
    label: "Orchestrator",
    defaultValue: DEFAULT_OPENAI,
  },
  web_surfer: {
    value: "web_surfer",
    label: "Web Surfer",
    defaultValue: DEFAULT_OPENAI,
  },
  coder: { value: "coder", label: "Coder", defaultValue: DEFAULT_OPENAI },
  file_surfer: {
    value: "file_surfer",
    label: "File Surfer",
    defaultValue: DEFAULT_OPENAI,
  },
  action_guard: {
    value: "action_guard",
    label: "Action Guard",
    defaultValue:
      PROVIDER_FORM_MAP[DEFAULT_OPENAI.provider].presets[
      "gpt-4.1-nano-2025-04-14"
      ],
  },
};

export interface ConfigWithModels {
  default_model?: ModelConfig;
  model_client_configs?: Record<string, ModelConfig>;
}

export const initializeDefaultModel = (config: ConfigWithModels): ModelConfig | undefined => {
  // If we have a stored default_model, use it
  if (config.default_model) {
    return config.default_model;
  }

  // Otherwise, try to detect if all agents use the same model
  const configs = config.model_client_configs;
  if (configs) {
    const firstConfig = configs[Object.keys(MODEL_CLIENT_CONFIGS)[0]];
    const allSame = Object.values(MODEL_CLIENT_CONFIGS).every(({ value }) => {
      const agentConfig = configs[value];
      return (
        agentConfig &&
        JSON.stringify(agentConfig) === JSON.stringify(firstConfig)
      );
    });

    if (allSame && firstConfig) {
      return firstConfig;
    }
  }

  return undefined;
};