| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "slices" |
| 5 | |
| 6 | "reasonix/internal/config" |
| 7 | "reasonix/internal/event" |
| 8 | "reasonix/internal/i18n" |
| 9 | "reasonix/internal/netclient" |
| 10 | "reasonix/internal/provider" |
| 11 | "reasonix/internal/tool" |
| 12 | "reasonix/internal/websearch" |
| 13 | ) |
| 14 | |
| 15 | func addWebSearch(reg *tool.Registry, cfg *config.Config, current *config.ProviderEntry, proxy netclient.ProxySpec, sink event.Sink) { |
| 16 | if cfg.Environment.Offline || (len(cfg.Tools.Enabled) > 0 && !slices.Contains(cfg.Tools.Enabled, "web_search")) { |
| 17 | return |
| 18 | } |
| 19 | selection := cfg.ResolveWebSearch(current) |
| 20 | if selection.Status == "invalid" && sink != nil { |
| 21 | sink.Emit(event.Event{Kind: event.Notice, Level: event.LevelInfo, Code: "web_search_model_unavailable", Text: i18n.M.SearchModelUnavailable + " " + selection.Reason}) |
| 22 | } |
| 23 | entry := selection.Entry |
| 24 | if entry == nil { |
| 25 | return |
| 26 | } |
| 27 | reg.Add(&websearch.Tool{ |
| 28 | ReportSourcesStatus: func(status string) { |
| 29 | if sink != nil && status == provider.SourcesNotProvided { |
| 30 | sink.Emit(event.Event{Kind: event.Notice, Level: event.LevelInfo, Code: "search_sources_not_provided", Text: i18n.M.SearchSourcesNotProvided}) |
| 31 | } |
| 32 | }, |
| 33 | Factory: func() (provider.Provider, error) { |
| 34 | return newProviderWithSearchMode(entry, proxy, nil, false) |
| 35 | }, |
| 36 | ReportUsage: func(usage *provider.Usage) { |
| 37 | if sink != nil { |
| 38 | sink.Emit(event.Event{Kind: event.Usage, ModelRef: modelRefFromEntry(entry), Usage: usage, Pricing: entry.Price, UsageSource: "web-search"}) |
| 39 | } |
| 40 | }, |
| 41 | }) |
| 42 | } |
| 43 |