configToMap reduces a fully-parsed *latest.Config to the small JS-friendly shape returned by parseConfig. We deliberately omit fields that wouldn't mean anything in the browser (toolsets, hooks, sandbox).
(cfg *latest.Config)
| 107 | // shape returned by parseConfig. We deliberately omit fields that wouldn't |
| 108 | // mean anything in the browser (toolsets, hooks, sandbox). |
| 109 | func configToMap(cfg *latest.Config) map[string]any { |
| 110 | agents := make([]any, 0, len(cfg.Agents)) |
| 111 | for _, a := range cfg.Agents { |
| 112 | agents = append(agents, map[string]any{ |
| 113 | "name": a.Name, |
| 114 | "description": a.Description, |
| 115 | "model": a.Model, |
| 116 | "instruction": a.Instruction, |
| 117 | "sub_agents": stringsToAny(a.SubAgents), |
| 118 | "handoffs": stringsToAny(a.Handoffs), |
| 119 | "add_date": a.AddDate, |
| 120 | "add_env_info": a.AddEnvironmentInfo, |
| 121 | }) |
| 122 | } |
| 123 | |
| 124 | models := map[string]any{} |
| 125 | for k, m := range cfg.Models { |
| 126 | models[k] = map[string]any{ |
| 127 | "provider": m.Provider, |
| 128 | "model": m.Model, |
| 129 | "base_url": m.BaseURL, |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return map[string]any{ |
| 134 | "version": cfg.Version, |
| 135 | "agents": agents, |
| 136 | "models": models, |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // stringsToAny widens a []string to []any so syscall/js.ValueOf accepts it. |
| 141 | func stringsToAny(in []string) []any { |
no test coverage detected