RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
feat(agent): add Search1API search and crawl tools (#20666)
wang21c970958db31
diff --git a/docs/guides/agent/agent_workflow/tool_components.md b/docs/guides/agent/agent_workflow/tool_components.mdindex 81d2125464..9aff9c961a 100644--- a/docs/guides/agent/agent_workflow/tool_components.md+++ b/docs/guides/agent/agent_workflow/tool_components.md@@ -16,7 +16,7 @@ Tool components connect external search, databases, HTTP APIs, email sending, do| Tool Category | Typical Components | Use Case || --- | --- | --- |-| Web search | Tavily, Google, DuckDuckGo, SearXNG, Keenable, Sofya | Retrieve web pages, news, public information, or content from specified sites. |+| Web search | Tavily, Google, DuckDuckGo, SearXNG, Keenable, Sofya, Search1API | Retrieve web pages, news, public information, or content from specified sites. || Academic search | Google Scholar, ArXiv, PubMed, BGPT | Retrieve papers, medical literature, and research materials. || Data and financial queries | Execute SQL, Yahoo Finance, WenCai | Query databases, market data, or financial screening results. || Content output | Email, Document Generator | Send emails or generate downloadable documents. |@@ -253,6 +253,66 @@ Sofya is a web search API for AI Agents. It returns the text of the result pagesThe output contains titles, links, and page content returned by Sofya. Results whose page could not be read fall back to the search snippet. It can be summarized by the Agent or passed to subsequent nodes.+### Search1API++Search1API searches the web or the news through one API and lets you choose the search service, such as Google, Bing, Baidu, GitHub, arXiv, Reddit, YouTube, Hacker News, or Reuters. When it is added to an Agent as a tool, the node settings are only defaults: the Agent can pick the channel and the search service for each call, for example GitHub for code questions or Reuters for news. An API key is required and can be created at [app.s1.dev](https://app.s1.dev). See the [Search1API documentation](https://s1.dev/docs) for details.++#### Parameter Description++| Field | Type | Required | Default Value | Description |+| --- | --- | --- | --- | --- |+| query | string | Yes | `{sys.query}` | Search keywords. |+| channel | string | No | general | `general` for web search or `news` for news search. The Agent can override the node value. |+| search_service | string | No | google | The search service to query. The Agent can override the node value with any service the channel supports. |+| time_range | string | No | any | Limit results by recency: `day`, `week`, `month`, `year`, or `any`. |+| api_key | string | Node configuration | Empty | Search1API API key. |+| top_n | integer | Node configuration | 10 | Maximum number of results, up to 50. |++#### Supported Parameter Values++| Channel | Supported Search Services |+| --- | --- |+| general | google, bing, bingcn, duckduckgo, yahoo, yandex, youtube, x, reddit, github, arxiv, wechat, bilibili, imdb, wikipedia, baidu, 360, quark |+| news | google, bing, duckduckgo, yahoo, hackernews, reuters |++If the Agent switches to a channel that does not offer the node's search service, the search uses Search1API's default service for that channel.++#### Configuration Example++| Configuration Item | Example Value |+| --- | --- |+| Query | RAGFlow Go release |+| API Key | `<your-search1api-api-key>` |+| Channel | general |+| Search Service | google |+| Top N | 10 |++#### Output Result++The output contains titles, links, and snippets returned by Search1API. `formalized_content` is commonly used as Agent context, while `json` preserves the raw result list.++### Search1API Crawl++Search1API Crawl reads one web page and returns its title and full content. A common workflow is to use Search1API to find links, then let the Agent read the most relevant page with this component. It uses the same API key as Search1API.++#### Parameter Description++| Field | Type | Required | Default Value | Description |+| --- | --- | --- | --- | --- |+| url | string | Yes | Empty | The absolute HTTP or HTTPS URL of the page to read. As an Agent tool, the Agent supplies the URL. |+| api_key | string | Node configuration | Empty | Search1API API key. |++#### Configuration Example++| Configuration Item | Example Value |+| --- | --- |+| URL | `https://ragflow.io/docs/dev/` |+| API Key | `<your-search1api-api-key>` |++#### Output Result++`json` contains the page title, link, content, and any metadata returned by Search1API.+### WikipediaThe Wikipedia component searches encyclopedia entries and extracts entry summaries. It is suitable for querying clear entities, concepts, and historical events. Query terms should be as close as possible to the entry title.diff --git a/internal/agent/component/tool_component.go b/internal/agent/component/tool_component.goindex d2a080a427..baaf784acc 100644--- a/internal/agent/component/tool_component.go+++ b/internal/agent/component/tool_component.go@@ -138,6 +138,8 @@ var toolComponentRegistrations = []struct {{componentName: "PubMed", toolName: "pubmed"},{componentName: "QueritContents", toolName: "querit_contents"},{componentName: "QueritSearch", toolName: "querit_search"},+ {componentName: "Search1APICrawl", toolName: "search1api_crawl"},+ {componentName: "Search1APISearch", toolName: "search1api"},{componentName: "SearXNG", toolName: "searxng"},{componentName: "SofyaSearch", toolName: "sofya"},{componentName: "TavilySearch", toolName: "tavily"},diff --git a/internal/agent/component/tool_component_test.go b/internal/agent/component/tool_component_test.goindex 94be864393..aedb17f2b4 100644--- a/internal/agent/component/tool_component_test.go+++ b/internal/agent/component/tool_component_test.go@@ -214,6 +214,20 @@ func TestToolBackedComponentRegisteredFactories(t *testing.T) {outputKey: "json",inputKey: "query",},+ {+ name: "Search1APICrawl",+ toolName: "Search1APICrawl",+ params: map[string]any{"api_key": "stored-key", "url": "{begin@url}", "outputs": map[string]any{"json": map[string]any{}}},+ outputKey: "json",+ inputKey: "url",+ },+ {+ name: "Search1APISearch",+ toolName: "Search1APISearch",+ params: map[string]any{"api_key": "stored-key", "channel": "news", "search_service": "reuters", "top_n": float64(3), "outputs": map[string]any{"formalized_content": map[string]any{}, "json": map[string]any{}}},+ outputKey: "json",+ inputKey: "query",+ },{name: "SearXNG",toolName: "SearXNG",@@ -297,7 +311,7 @@ func TestToolBackedComponentWenCaiInvoke(t *testing.T) {}func TestToolBackedComponentRegisteredBuildWorkflow(t *testing.T) {- for _, componentName := range []string{"ArXiv", "BGPT", "DuckDuckGo", "Email", "Google", "GoogleScholar", "KeenableSearch", "PubMed", "QueritContents", "QueritSearch", "SearXNG", "SofyaSearch", "WenCai", "TavilyExtract", "TavilySearch", "Wikipedia", "YahooFinance"} {+ for _, componentName := range []string{"ArXiv", "BGPT", "DuckDuckGo", "Email", "Google", "GoogleScholar", "KeenableSearch", "PubMed", "QueritContents", "QueritSearch", "Search1APICrawl", "Search1APISearch", "SearXNG", "SofyaSearch", "WenCai", "TavilyExtract", "TavilySearch", "Wikipedia", "YahooFinance"} {t.Run(componentName, func(t *testing.T) {c := &canvas.Canvas{Components: map[string]canvas.CanvasComponent{diff --git a/internal/agent/tool/registry.go b/internal/agent/tool/registry.goindex 0a2f82c325..d92f515be7 100644--- a/internal/agent/tool/registry.go+++ b/internal/agent/tool/registry.go@@ -19,6 +19,7 @@ package toolimport ("fmt""math"+ "slices""strconv""strings"@@ -60,6 +61,8 @@ var registry = map[string]Factory{"retrieval": buildRetrievalTool,"search_my_dataset": buildRetrievalTool,"search_my_dateset": buildRetrievalTool,+ "search1api": buildSearch1APITool,+ "search1api_crawl": buildSearch1APICrawlTool,"searxng": buildSearXNGTool,"sofya": buildSofyaTool,"tavily": buildTavilyTool,@@ -77,15 +80,17 @@ var registry = map[string]Factory{// names such as "CodeExec" and "GoogleScholar", while the tool registry uses// snake_case names for several tools.var canvasToolNames = map[string]string{- "codeexec": "code_exec",- "googlescholar": "google_scholar",- "keenablesearch": "keenable",- "queritcontents": "querit_contents",- "queritsearch": "querit_search",- "sofyasearch": "sofya",- "tavilyextract": "tavily_extract",- "tavilysearch": "tavily",- "yahoofinance": "yahoo_finance",+ "codeexec": "code_exec",+ "googlescholar": "google_scholar",+ "keenablesearch": "keenable",+ "queritcontents": "querit_contents",+ "queritsearch": "querit_search",+ "search1apicrawl": "search1api_crawl",+ "search1apisearch": "search1api",+ "sofyasearch": "sofya",+ "tavilyextract": "tavily_extract",+ "tavilysearch": "tavily",+ "yahoofinance": "yahoo_finance",}func noConfig(name string, fn func() einotool.BaseTool) Factory {@@ -771,6 +776,64 @@ func buildSofyaTool(params map[string]any) (einotool.BaseTool, error) {return newSofyaTool(nil, apiKey, defaults), nil}+func buildSearch1APITool(params map[string]any) (einotool.BaseTool, error) {+ defaults := search1APIDefaults{}+ apiKey := ""+ if value, ok := params["api_key"]; ok {+ var valid bool+ apiKey, valid = value.(string)+ if !valid {+ return nil, fmt.Errorf("agent tool: tool %q requires string node-level param api_key", "search1api")+ }+ }+ if value, ok := params["channel"]; ok {+ channel, valid := value.(string)+ if !valid || (channel != search1APIChannelGeneral && channel != search1APIChannelNews) {+ return nil, fmt.Errorf("agent tool: tool %q has unsupported channel %v", "search1api", value)+ }+ defaults.Channel = channel+ }+ if value, ok := params["search_service"]; ok {+ searchService, valid := value.(string)+ channel := defaults.Channel+ if channel == "" {+ channel = search1APIChannelGeneral+ }+ if !valid || (searchService != "" && !slices.Contains(search1APIChannelServices(channel), searchService)) {+ return nil, fmt.Errorf("agent tool: tool %q has unsupported search_service %v for the %s channel", "search1api", value, channel)+ }+ defaults.SearchService = searchService+ }+ if value, ok := params["top_n"]; ok {+ topN, valid := strictInt(value)+ if !valid || topN <= 0 || topN > search1APIMaxResults {+ return nil, fmt.Errorf("agent tool: tool %q requires integer node-level param top_n within [1, %d]", "search1api", search1APIMaxResults)+ }+ defaults.TopN = topN+ }+ return newSearch1APITool(nil, apiKey, defaults), nil+}++func buildSearch1APICrawlTool(params map[string]any) (einotool.BaseTool, error) {+ apiKey := ""+ if value, ok := params["api_key"]; ok {+ var valid bool+ apiKey, valid = value.(string)+ if !valid {+ return nil, fmt.Errorf("agent tool: tool %q requires string node-level param api_key", search1APICrawlToolName)+ }+ }+ defaultURL := ""+ if value, ok := params["url"]; ok {+ var valid bool+ defaultURL, valid = value.(string)+ if !valid {+ return nil, fmt.Errorf("agent tool: tool %q requires string node-level param url", search1APICrawlToolName)+ }+ }+ return newSearch1APICrawlTool(nil, apiKey, defaultURL), nil+}+func buildWikipediaTool(params map[string]any) (einotool.BaseTool, error) {topN := defaultWikipediaTopNlanguage := defaultWikipediaLanguagediff --git a/internal/agent/tool/registry_test.go b/internal/agent/tool/registry_test.goindex 2c908f72ea..01e6cf7312 100644--- a/internal/agent/tool/registry_test.go+++ b/internal/agent/tool/registry_test.go@@ -50,6 +50,8 @@ func TestBuildByName_CanvasComponentNames(t *testing.T) {{name: "KeenableSearch", wantToolName: "keenable_search"},{name: "QueritContents", wantToolName: "querit_contents"},{name: "QueritSearch", wantToolName: "querit_search"},+ {name: "Search1APICrawl", wantToolName: "search1api_crawl"},+ {name: "Search1APISearch", wantToolName: "search1api_search"},{name: "SofyaSearch", wantToolName: "sofya_search"},{name: "TavilyExtract", wantToolName: "tavily_extract"},{name: "TavilySearch", wantToolName: "tavily_search"},@@ -164,7 +166,7 @@ func TestBuildAll_AllRegisteredTools(t *testing.T) {"duckduckgo", "email", "exesql", "execute_sql", "github", "google","google_scholar", "google_scholar_search", "jin10", "keenable", "pubmed", "qweather","querit", "querit_contents", "querit_search",- "retrieval", "search_my_dataset", "search_my_dateset", "searxng", "sofya",+ "retrieval", "search_my_dataset", "search_my_dateset", "search1api", "search1api_crawl", "searxng", "sofya","tavily", "tavily_extract", "tushare", "web_crawler", "wencai", "wikipedia", "wikipedia_search","yahoo_finance",}@@ -228,7 +230,7 @@ func TestToolRegistry_SchemasAreComplete(t *testing.T) {"duckduckgo", "email", "execute_sql", "exesql", "github", "google","google_scholar", "google_scholar_search", "jin10", "keenable", "pubmed", "qweather","querit", "querit_contents", "querit_search",- "retrieval", "search_my_dataset", "search_my_dateset", "searxng", "sofya",+ "retrieval", "search_my_dataset", "search_my_dateset", "search1api", "search1api_crawl", "searxng", "sofya","tavily", "tavily_extract", "tushare", "web_crawler", "wencai", "wikipedia", "wikipedia_search","yahoo_finance",}diff --git a/internal/agent/tool/search1api.go b/internal/agent/tool/search1api.gonew file mode 100644index 0000000000..1cd9ef49b7--- /dev/null+++ b/internal/agent/tool/search1api.go@@ -0,0 +1,467 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package tool++import (+ "context"+ "crypto/sha1"+ "encoding/json"+ "fmt"+ "math/big"+ "net/http"+ "slices"+ "strconv"+ "strings"+ "unicode/utf8"++ "github.com/cloudwego/eino/components/tool"+ "github.com/cloudwego/eino/schema"++ "ragflow/internal/tokenizer"+)++const search1APIToolName = "search1api_search"++const search1APIToolDescription = `Search1API searches the web or the news through one API, using the search service you pick. When searching:+ - Use a focused query of the most important terms (and synonyms).+ - Use the news channel for current events, and the general channel otherwise.+ - Pick a search service that fits the question, e.g. "github" for code, "arxiv" for papers, "reddit" for discussions, "youtube" for videos, "baidu" for Chinese web pages, "hackernews" or "reuters" for news. Leave it out to use the service set on the node.+ - Optionally restrict results by how recently they were published.`++// search1APIMaxResults is the most results Search1API returns for one search.+const search1APIMaxResults = 50++const search1APIPromptMaxTokens = 200000++const (+ search1APIChannelGeneral = "general"+ search1APIChannelNews = "news"+)++var search1APIChannels = []string{search1APIChannelGeneral, search1APIChannelNews}++// Search services accepted by each channel's endpoint. A service outside the+// channel's list is rejected by Search1API, so it is checked before the call.+var search1APIGeneralServices = []string{+ "google", "bing", "bingcn", "duckduckgo", "yahoo", "yandex", "youtube", "x", "reddit",+ "github", "arxiv", "wechat", "bilibili", "imdb", "wikipedia", "baidu", "360", "quark",+}++var search1APINewsServices = []string{"google", "bing", "duckduckgo", "yahoo", "hackernews", "reuters"}++// search1APIServices is every service the model may pick, across both channels.+var search1APIServices = append(slices.Clone(search1APIGeneralServices), "hackernews", "reuters")++// "any" means no recency limit and is not sent.+var search1APITimeRanges = []string{"any", "day", "week", "month", "year"}++// search1APIEndpoints are the Search1API URLs per channel. Exposed as a+// package var so tests can substitute it through rewriteHostTransport.+var search1APIEndpoints = map[string]string{+ search1APIChannelGeneral: "https://api.search1api.com/search",+ search1APIChannelNews: "https://api.search1api.com/news",+}++// search1APIArgs is the JSON shape the model sends into InvokableRun.+// max_results is decoded loosely: a missing, blank or non-numeric value means+// "use the node's Top N" rather than failing the run.+type search1APIArgs struct {+ Query string `json:"query"`+ Channel string `json:"channel"`+ SearchService string `json:"search_service"`+ TimeRange string `json:"time_range"`+ MaxResults any `json:"max_results"`+}++// search1APIDefaults holds the node-level configuration. The model's+// channel and search_service, when given, override the node's.+type search1APIDefaults struct {+ Channel string+ SearchService string+ TopN int+}++type search1APIRequestBody struct {+ Query string `json:"query"`+ SearchService string `json:"search_service,omitempty"`+ MaxResults int `json:"max_results"`+ TimeRange string `json:"time_range,omitempty"`+}++// search1APIResponse preserves every upstream result field because the Canvas+// json output exposes the result list unchanged.+type search1APIResponse struct {+ Results []map[string]any `json:"results"`+}++type search1APIEnvelope struct {+ Results []map[string]any `json:"results"`+ Error string `json:"_ERROR,omitempty"`+}++// Search1APITool is the Search1API web and news search tool. It POSTs a+// search to https://api.search1api.com/search or /news and returns the+// upstream `results` array. The API key is node configuration only and never+// model-visible.+type Search1APITool struct {+ helper *HTTPHelper+ apiKey string+ defaults search1APIDefaults+}++var _ ToolComponent = (*Search1APITool)(nil)+var _ ReferenceBuilder = (*Search1APITool)(nil)++// NewSearch1APITool returns a Search1APITool with no API key and the default+// HTTPHelper.+func NewSearch1APITool() *Search1APITool {+ return newSearch1APITool(nil, "", search1APIDefaults{})+}++// NewSearch1APIToolWith returns a Search1APITool that uses the provided+// HTTPHelper and API key. Useful for tests that want to inject a custom+// transport.+func NewSearch1APIToolWith(h *HTTPHelper, apiKey string) *Search1APITool {+ return newSearch1APITool(h, apiKey, search1APIDefaults{})+}++func newSearch1APITool(h *HTTPHelper, apiKey string, defaults search1APIDefaults) *Search1APITool {+ if h == nil {+ h = NewHTTPHelper()+ }+ if defaults.Channel == "" {+ defaults.Channel = search1APIChannelGeneral+ }+ if defaults.TopN <= 0 {+ defaults.TopN = 10+ }+ return &Search1APITool{helper: h, apiKey: strings.TrimSpace(apiKey), defaults: defaults}+}++// Info returns the tool's metadata for the chat model.+func (s *Search1APITool) Info(_ context.Context) (*schema.ToolInfo, error) {+ return &schema.ToolInfo{+ Name: search1APIToolName,+ Desc: search1APIToolDescription,+ ParamsOneOf: schema.NewParamsOneOfByParams(map[string]*schema.ParameterInfo{+ "query": {+ Type: schema.String,+ Desc: "The search keywords to execute with Search1API. The most important words/terms (and synonyms) from the original request.",+ Required: true,+ },+ "channel": {+ Type: schema.String,+ Desc: `Search channel: "news" for current events, "general" for a broader web search. Leave it out to use the channel set on the node.`,+ Enum: search1APIChannels,+ Required: false,+ },+ "search_service": {+ Type: schema.String,+ Desc: fmt.Sprintf(+ "The search service to query. The general channel supports: %s. The news channel supports: %s. Leave it out to use the service set on the node.",+ strings.Join(search1APIGeneralServices, ", "),+ strings.Join(search1APINewsServices, ", "),+ ),+ Enum: search1APIServices,+ Required: false,+ },+ "time_range": {+ Type: schema.String,+ Desc: `Restrict results by recency: "day", "week", "month", "year", or "any" (default) for no limit.`,+ Enum: search1APITimeRanges,+ Required: false,+ },+ "max_results": {+ Type: schema.Integer,+ Desc: "Number of results to return, 1 to 50. Leave it out to use the Top N set on the node.",+ Required: false,+ },+ }),+ }, nil+}++// InvokableRun performs the Search1API search.+//+// Recoverable errors (bad arguments, missing API key, API or network failures)+// are returned as a JSON envelope with an _ERROR field and a nil Go error, so+// the ReAct agent feeds them back to the model instead of failing the run,+// matching SofyaTool.+func (s *Search1APITool) InvokableRun(ctx context.Context, argsJSON string, _ ...tool.Option) (string, error) {+ var args search1APIArgs+ if err := json.Unmarshal([]byte(argsJSON), &args); err != nil {+ return search1APIErrJSON(fmt.Errorf("search1api: parse arguments: %w", err)), nil+ }+ if strings.TrimSpace(args.Query) == "" {+ return search1APIJSON(search1APIEnvelope{Results: []map[string]any{}}), nil+ }+ if s.apiKey == "" {+ return search1APIErrJSON(fmt.Errorf("search1api: api_key is required")), nil+ }++ channel, err := search1APIEnumArg("channel", args.Channel, search1APIChannels, s.defaults.Channel)+ if err != nil {+ return search1APIErrJSON(err), nil+ }+ searchService, err := s.searchServiceArg(channel, args.SearchService)+ if err != nil {+ return search1APIErrJSON(err), nil+ }+ timeRange, err := search1APIEnumArg("time_range", args.TimeRange, search1APITimeRanges, "any")+ if err != nil {+ return search1APIErrJSON(err), nil+ }+ if timeRange == "any" {+ timeRange = ""+ }+ maxResults := search1APIMaxResultsArg(args.MaxResults, s.defaults.TopN)++ body, _ := json.Marshal(search1APIRequestBody{+ Query: args.Query,+ SearchService: searchService,+ MaxResults: maxResults,+ TimeRange: timeRange,+ })+ resp, err := s.helper.Do(ctx,+ http.MethodPost, search1APIEndpoints[channel], string(body), "application/json",+ map[string]string{+ "Authorization": "Bearer " + s.apiKey,+ "Accept": "application/json",+ // Identifies RAGFlow to Search1API.+ "User-Agent": "RAGFlow search1api-integration/infiniflow-ragflow",+ },+ )+ if err != nil {+ return search1APIErrJSON(err), nil+ }+ defer resp.Body.Close()++ if resp.StatusCode < 200 || resp.StatusCode >= 300 {+ return search1APIErrJSON(fmt.Errorf("search1api: upstream returned %d", resp.StatusCode)), nil+ }++ var raw search1APIResponse+ if err := json.NewDecoder(resp.Body).Decode(&raw); err != nil {+ return search1APIErrJSON(fmt.Errorf("search1api: decode response: %w", err)), nil+ }+ results := raw.Results+ if results == nil {+ results = []map[string]any{}+ }+ if len(results) > maxResults {+ results = results[:maxResults]+ }+ return search1APIJSON(search1APIEnvelope{Results: results}), nil+}++// searchServiceArg picks the search service for the channel. A service the+// model names must belong to the channel. The node's service is used when the+// model names none; if the model switched to a channel that does not offer+// it, no service is sent and Search1API uses its own default.+func (s *Search1APITool) searchServiceArg(channel, value string) (string, error) {+ allowed := search1APIChannelServices(channel)+ v := strings.ToLower(strings.TrimSpace(value))+ if v == "" {+ if slices.Contains(allowed, s.defaults.SearchService) {+ return s.defaults.SearchService, nil+ }+ return "", nil+ }+ if !slices.Contains(allowed, v) {+ return "", fmt.Errorf("search1api: search_service %q is not supported by the %s channel, it should be one of %v", value, channel, allowed)+ }+ return v, nil+}++func search1APIChannelServices(channel string) []string {+ if channel == search1APIChannelNews {+ return search1APINewsServices+ }+ return search1APIGeneralServices+}++// search1APIEnumArg normalizes a model-supplied enum value. Blank means the+// default; anything else must be a known value, because it is forwarded to+// Search1API as-is.+func search1APIEnumArg(name, value string, allowed []string, fallback string) (string, error) {+ v := strings.ToLower(strings.TrimSpace(value))+ if v == "" {+ return fallback, nil+ }+ if slices.Contains(allowed, v) {+ return v, nil+ }+ return "", fmt.Errorf("search1api: %s %q is not supported, it should be one of %v", name, value, allowed)+}++// search1APIMaxResultsArg returns the model's result count if it gave a+// usable one, else the node's Top N, clamped to [1, 50].+func search1APIMaxResultsArg(value any, topN int) int {+ n := topN+ switch v := value.(type) {+ case float64:+ n = int(v)+ case string:+ if parsed, err := strconv.Atoi(strings.TrimSpace(v)); err == nil {+ n = parsed+ }+ }+ return min(max(n, 1), search1APIMaxResults)+}++// ComponentSpec returns the Search1APISearch Canvas surface.+func (s *Search1APITool) ComponentSpec() ComponentSpec {+ return ComponentSpec{+ Inputs: map[string]string{+ "query": "The search keywords to execute with Search1API.",+ "channel": `Search channel: "general" or "news".`,+ "search_service": "The search service to query.",+ "time_range": `Recency limit: "day", "week", "month", "year" or "any".`,+ },+ Outputs: map[string]string{+ "formalized_content": "Rendered Search1API references for downstream prompts.",+ "json": "Raw Search1API result list.",+ },+ InputForm: map[string]any{+ "query": map[string]any{"name": "Query", "type": "line"},+ "channel": map[string]any{+ "name": "Channel",+ "type": "options",+ "value": search1APIChannelGeneral,+ "options": search1APIChannels,+ },+ "time_range": map[string]any{+ "name": "Time range",+ "type": "options",+ "value": "any",+ "options": search1APITimeRanges,+ },+ },+ }+}++func (s *Search1APITool) BuildReferences(_ context.Context, envelope map[string]any) ([]map[string]any, []map[string]any) {+ return buildSearch1APIReferences(envelope)+}++func (s *Search1APITool) BuildComponentOutputs(envelope map[string]any) map[string]any {+ results := envelopeSlice(envelope, "results")+ chunks, _ := buildSearch1APIReferences(envelope)+ return map[string]any{+ "formalized_content": renderSearch1APIReferences(chunks, search1APIPromptMaxTokens),+ "json": results,+ }+}++// buildSearch1APIReferences prefers a result's page content and falls back to+// its search snippet. `content` is only present when Search1API read the page.+// A result with neither is dropped rather than stored as a blank chunk.+func buildSearch1APIReferences(envelope map[string]any) ([]map[string]any, []map[string]any) {+ results := envelopeSlice(envelope, "results")+ chunks := make([]map[string]any, 0, len(results))+ docAggs := make([]map[string]any, 0, len(results))+ for _, item := range results {+ result, ok := item.(map[string]any)+ if !ok {+ continue+ }+ content := search1APIText(result["content"])+ if content == "" {+ content = search1APIText(result["snippet"])+ }+ content = truncateSearch1APIRunes(strings.Join(strings.Fields(content), " "), 10000)+ if content == "" {+ continue+ }+ documentID := strconv.FormatInt(search1APIHashInt(content, 100000000), 10)+ displayID := strconv.FormatInt(search1APIHashInt(documentID, 500), 10)+ title := search1APIText(result["title"])+ resultURL := search1APIText(result["link"])+ chunks = append(chunks, map[string]any{+ "id": displayID,+ "chunk_id": documentID,+ "content": content,+ "doc_id": documentID,+ "document_id": documentID,+ "docnm_kwd": title,+ "document_name": title,+ "similarity": 1,+ "score": 1,+ "url": resultURL,+ })+ docAggs = append(docAggs, map[string]any{+ "doc_name": title,+ "doc_id": documentID,+ "count": 1,+ "url": resultURL,+ })+ }+ return chunks, docAggs+}++func renderSearch1APIReferences(chunks []map[string]any, maxTokens int) string {+ usedTokens := 0+ blocks := make([]string, 0, len(chunks))+ for _, chunk := range chunks {+ content := search1APIText(chunk["content"])+ usedTokens += tokenizer.NumTokensFromString(content)+ blocks = append(blocks, strings.Join([]string{+ "\nID: " + search1APIText(chunk["id"]),+ "├── Title: " + strings.Join(strings.Fields(search1APIText(chunk["document_name"])), " "),+ "├── URL: " + search1APIText(chunk["url"]),+ "└── Content:\n" + content,+ }, "\n"))+ if maxTokens > 0 && float64(maxTokens)*0.97 < float64(usedTokens) {+ break+ }+ }+ return strings.Join(blocks, "\n")+}++func search1APIText(value any) string {+ if value == nil {+ return ""+ }+ if text, ok := value.(string); ok {+ return strings.TrimSpace(text)+ }+ return strings.TrimSpace(fmt.Sprint(value))+}++func search1APIHashInt(value string, modulus int64) int64 {+ digest := sha1.Sum([]byte(value))+ number := new(big.Int).SetBytes(digest[:])+ return new(big.Int).Mod(number, big.NewInt(modulus)).Int64()+}++func truncateSearch1APIRunes(value string, limit int) string {+ if utf8.RuneCountInString(value) <= limit {+ return value+ }+ return string([]rune(value)[:limit])+}++func search1APIJSON(env search1APIEnvelope) string {+ b, err := json.Marshal(env)+ if err != nil {+ return fmt.Sprintf(`{"_ERROR":"search1api: marshal result: %s"}`, err)+ }+ return string(b)+}++func search1APIErrJSON(err error) string {+ return search1APIJSON(search1APIEnvelope{Error: err.Error()})+}diff --git a/internal/agent/tool/search1api_crawl.go b/internal/agent/tool/search1api_crawl.gonew file mode 100644index 0000000000..a6eb790240--- /dev/null+++ b/internal/agent/tool/search1api_crawl.go@@ -0,0 +1,189 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package tool++import (+ "context"+ "encoding/json"+ "fmt"+ "net/http"+ "net/url"+ "strings"+ "time"++ "github.com/cloudwego/eino/components/tool"+ "github.com/cloudwego/eino/schema"+)++const search1APICrawlToolName = "search1api_crawl"++// search1APICrawlEndpoint is the Search1API crawl URL. Exposed as a package+// var so tests can substitute it through rewriteHostTransport.+var search1APICrawlEndpoint = "https://api.search1api.com/crawl"++type search1APICrawlArgs struct {+ URL string `json:"url"`+}++type search1APICrawlRequestBody struct {+ URL string `json:"url"`+}++// search1APICrawlResponse keeps the upstream page object unchanged: title,+// link, content and any metadata Search1API returns.+type search1APICrawlResponse struct {+ Results map[string]any `json:"results"`+}++type search1APICrawlEnvelope struct {+ Results map[string]any `json:"results,omitempty"`+ Error string `json:"_ERROR,omitempty"`+}++// Search1APICrawlTool reads one web page through the Search1API crawl+// endpoint and returns its content. The API key is node configuration only+// and never model-visible.+type Search1APICrawlTool struct {+ helper *HTTPHelper+ apiKey string+ defaultURL string+}++var _ ToolComponent = (*Search1APICrawlTool)(nil)++// NewSearch1APICrawlTool returns a Search1APICrawlTool with no API key and+// the default HTTPHelper.+func NewSearch1APICrawlTool() *Search1APICrawlTool {+ return newSearch1APICrawlTool(nil, "", "")+}++// NewSearch1APICrawlToolWith returns a Search1APICrawlTool that uses the+// provided HTTPHelper and API key.+func NewSearch1APICrawlToolWith(h *HTTPHelper, apiKey string) *Search1APICrawlTool {+ return newSearch1APICrawlTool(h, apiKey, "")+}++func newSearch1APICrawlTool(h *HTTPHelper, apiKey, defaultURL string) *Search1APICrawlTool {+ if h == nil {+ h = NewHTTPHelper()+ // Reading a slow page can take longer than the 30s default.+ h.client.Timeout = 60 * time.Second+ }+ return &Search1APICrawlTool{helper: h, apiKey: strings.TrimSpace(apiKey), defaultURL: defaultURL}+}++// Info returns the tool's metadata for the chat model.+func (c *Search1APICrawlTool) Info(_ context.Context) (*schema.ToolInfo, error) {+ return &schema.ToolInfo{+ Name: search1APICrawlToolName,+ Desc: "Read one web page with Search1API and return its title and full content. Use it to read a page found by a search, or a URL the user gave.",+ ParamsOneOf: schema.NewParamsOneOfByParams(map[string]*schema.ParameterInfo{+ "url": {+ Type: schema.String,+ Desc: "The absolute HTTP or HTTPS URL of the page to read.",+ Required: true,+ },+ }),+ }, nil+}++// InvokableRun crawls the page. Recoverable errors are returned as a JSON+// envelope with an _ERROR field and a nil Go error, matching+// Search1APITool.+func (c *Search1APICrawlTool) InvokableRun(ctx context.Context, argsJSON string, _ ...tool.Option) (string, error) {+ var args search1APICrawlArgs+ if err := json.Unmarshal([]byte(argsJSON), &args); err != nil {+ return search1APICrawlErrJSON(fmt.Errorf("search1api_crawl: parse arguments: %w", err)), nil+ }+ pageURL := strings.TrimSpace(args.URL)+ if pageURL == "" {+ pageURL = strings.TrimSpace(c.defaultURL)+ }+ if pageURL == "" {+ return search1APICrawlErrJSON(fmt.Errorf("search1api_crawl: url is required")), nil+ }+ parsed, err := url.ParseRequestURI(pageURL)+ if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" {+ return search1APICrawlErrJSON(fmt.Errorf("search1api_crawl: url %q must be an absolute HTTP or HTTPS URL", pageURL)), nil+ }+ if c.apiKey == "" {+ return search1APICrawlErrJSON(fmt.Errorf("search1api_crawl: api_key is required")), nil+ }++ body, _ := json.Marshal(search1APICrawlRequestBody{URL: pageURL})+ resp, err := c.helper.Do(ctx,+ http.MethodPost, search1APICrawlEndpoint, string(body), "application/json",+ map[string]string{+ "Authorization": "Bearer " + c.apiKey,+ "Accept": "application/json",+ // Identifies RAGFlow to Search1API.+ "User-Agent": "RAGFlow search1api-integration/infiniflow-ragflow",+ },+ )+ if err != nil {+ return search1APICrawlErrJSON(err), nil+ }+ defer resp.Body.Close()++ if resp.StatusCode < 200 || resp.StatusCode >= 300 {+ return search1APICrawlErrJSON(fmt.Errorf("search1api_crawl: upstream returned %d", resp.StatusCode)), nil+ }++ var raw search1APICrawlResponse+ if err := json.NewDecoder(resp.Body).Decode(&raw); err != nil {+ return search1APICrawlErrJSON(fmt.Errorf("search1api_crawl: decode response: %w", err)), nil+ }+ if raw.Results == nil {+ return search1APICrawlErrJSON(fmt.Errorf("search1api_crawl: response has no results")), nil+ }+ return search1APICrawlJSON(search1APICrawlEnvelope{Results: raw.Results}), nil+}++// ComponentSpec returns the Search1APICrawl Canvas surface.+func (c *Search1APICrawlTool) ComponentSpec() ComponentSpec {+ return ComponentSpec{+ Inputs: map[string]string{+ "url": "The absolute HTTP or HTTPS URL of the page to read.",+ },+ Outputs: map[string]string{+ "json": "The crawled page: title, link, content and metadata.",+ },+ InputForm: map[string]any{+ "url": map[string]any{"name": "URL", "type": "line"},+ },+ }+}++func (c *Search1APICrawlTool) BuildComponentOutputs(envelope map[string]any) map[string]any {+ results, _ := envelope["results"].(map[string]any)+ if results == nil {+ results = map[string]any{}+ }+ return map[string]any{"json": results}+}++func search1APICrawlJSON(env search1APICrawlEnvelope) string {+ b, err := json.Marshal(env)+ if err != nil {+ return fmt.Sprintf(`{"_ERROR":"search1api_crawl: marshal result: %s"}`, err)+ }+ return string(b)+}++func search1APICrawlErrJSON(err error) string {+ return search1APICrawlJSON(search1APICrawlEnvelope{Error: err.Error()})+}diff --git a/internal/agent/tool/search1api_crawl_test.go b/internal/agent/tool/search1api_crawl_test.gonew file mode 100644index 0000000000..b86d0f1d49--- /dev/null+++ b/internal/agent/tool/search1api_crawl_test.go@@ -0,0 +1,154 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package tool++import (+ "encoding/json"+ "net/http"+ "strings"+ "testing"+)++func decodeSearch1APICrawlEnvelope(t *testing.T, out string) search1APICrawlEnvelope {+ t.Helper()+ var env search1APICrawlEnvelope+ if err := json.Unmarshal([]byte(out), &env); err != nil {+ t.Fatalf("decode envelope %q: %v", out, err)+ }+ return env+}++func TestSearch1APICrawl_BuildRequestAndResult(t *testing.T) {+ t.Parallel()+ helper, req, body, _ := search1APITestServer(t, http.StatusOK,+ `{"crawlParameters":{"url":"https://example.com/a"},"results":{"title":"A","link":"https://example.com/a","content":"# A\n\nBody","metadata":{"lang":"en"}}}`)+ tool := NewSearch1APICrawlToolWith(helper, " key-xyz ")++ out, err := tool.InvokableRun(t.Context(), `{"url":" https://example.com/a "}`)+ if err != nil {+ t.Fatalf("InvokableRun: %v", err)+ }+ if req.Method != http.MethodPost || req.URL.Path != "/crawl" {+ t.Errorf("request = %s %s, want POST /crawl", req.Method, req.URL.Path)+ }+ if got := req.Header.Get("Authorization"); got != "Bearer key-xyz" {+ t.Errorf("Authorization = %q, want trimmed bearer key", got)+ }+ if got := req.Header.Get("User-Agent"); got != "RAGFlow search1api-integration/infiniflow-ragflow" {+ t.Errorf("User-Agent = %q", got)+ }+ if len(*body) != 1 || (*body)["url"] != "https://example.com/a" {+ t.Errorf("body = %v, want only the trimmed url", *body)+ }+ env := decodeSearch1APICrawlEnvelope(t, out)+ if env.Error != "" || env.Results["content"] != "# A\n\nBody" || env.Results["metadata"] == nil {+ t.Fatalf("envelope = %#v, want the page with its fields intact", env)+ }+}++func TestSearch1APICrawl_UsesNodeURLWhenModelGivesNone(t *testing.T) {+ t.Parallel()+ helper, _, body, _ := search1APITestServer(t, http.StatusOK, `{"results":{"title":"N"}}`)+ tool := newSearch1APICrawlTool(helper, "key", "https://example.com/node")++ if _, err := tool.InvokableRun(t.Context(), `{}`); err != nil {+ t.Fatalf("InvokableRun: %v", err)+ }+ if (*body)["url"] != "https://example.com/node" {+ t.Errorf("url = %v, want the node url", (*body)["url"])+ }+}++func TestSearch1APICrawl_ErrorsReachTheModel(t *testing.T) {+ t.Parallel()+ cases := []struct {+ name, key, args, respBody, wantErr string+ status int+ wantCalls int32+ }{+ {"no url", "key", `{"url":" "}`, `{}`, "url is required", http.StatusOK, 0},+ {"relative url", "key", `{"url":"example.com/a"}`, `{}`, "must be an absolute HTTP or HTTPS URL", http.StatusOK, 0},+ {"non-http url", "key", `{"url":"file:///etc/passwd"}`, `{}`, "must be an absolute HTTP or HTTPS URL", http.StatusOK, 0},+ {"no api key", "", `{"url":"https://example.com"}`, `{}`, "api_key is required", http.StatusOK, 0},+ {"bad arguments", "key", `{"url":`, `{}`, "parse arguments", http.StatusOK, 0},+ {"rejected key", "key", `{"url":"https://example.com"}`, `{"error":"nope"}`, "upstream returned 401", http.StatusUnauthorized, 1},+ {"no results", "key", `{"url":"https://example.com"}`, `{"crawlParameters":{}}`, "response has no results", http.StatusOK, 1},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ helper, _, _, calls := search1APITestServer(t, tc.status, tc.respBody)+ out, err := NewSearch1APICrawlToolWith(helper, tc.key).InvokableRun(t.Context(), tc.args)+ if err != nil {+ t.Fatalf("Go error %v: recoverable errors must go back to the model", err)+ }+ if env := decodeSearch1APICrawlEnvelope(t, out); !strings.Contains(env.Error, tc.wantErr) {+ t.Errorf("_ERROR = %q, want it to contain %q", env.Error, tc.wantErr)+ }+ if got := calls.Load(); got != tc.wantCalls {+ t.Errorf("upstream calls = %d, want %d", got, tc.wantCalls)+ }+ })+ }+}++func TestSearch1APICrawl_ComponentOutputs(t *testing.T) {+ t.Parallel()+ tool := NewSearch1APICrawlTool()+ page := map[string]any{"title": "A", "content": "Body"}+ outputs := tool.BuildComponentOutputs(map[string]any{"results": page})+ if got, _ := outputs["json"].(map[string]any); got["content"] != "Body" {+ t.Errorf("json output = %#v, want the crawled page", outputs["json"])+ }+ if got, _ := tool.BuildComponentOutputs(map[string]any{"_ERROR": "x"})["json"].(map[string]any); got == nil {+ t.Error("json output must be an empty object on error, not nil")+ }+ spec := tool.ComponentSpec()+ if _, ok := spec.Inputs["url"]; !ok {+ t.Errorf("Inputs = %#v, want url", spec.Inputs)+ }+}++func TestSearch1APICrawl_BuildByNameUsesNodeConfig(t *testing.T) {+ t.Parallel()+ built, err := BuildByName("Search1APICrawl", map[string]any{+ "api_key": "stored-key", "url": "https://example.com", "outputs": map[string]any{},+ })+ if err != nil {+ t.Fatalf("BuildByName: %v", err)+ }+ tool, ok := built.(*Search1APICrawlTool)+ if !ok {+ t.Fatalf("built %T, want *Search1APICrawlTool", built)+ }+ if tool.apiKey != "stored-key" || tool.defaultURL != "https://example.com" {+ t.Errorf("tool = key %q url %q", tool.apiKey, tool.defaultURL)+ }+ info, err := tool.Info(t.Context())+ if err != nil || info.Name != search1APICrawlToolName {+ t.Fatalf("Info = %+v, %v", info, err)+ }++ for name, params := range map[string]map[string]any{+ "api_key not a string": {"api_key": 42},+ "url not a string": {"url": []any{"https://example.com"}},+ } {+ if _, err := BuildByName("search1api_crawl", params); err == nil {+ t.Errorf("%s: expected a config error", name)+ }+ }+}diff --git a/internal/agent/tool/search1api_test.go b/internal/agent/tool/search1api_test.gonew file mode 100644index 0000000000..6cc0eca3e7--- /dev/null+++ b/internal/agent/tool/search1api_test.go@@ -0,0 +1,322 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package tool++import (+ "encoding/json"+ "net/http"+ "net/http/httptest"+ "strings"+ "sync/atomic"+ "testing"+)++// search1APITestServer records the last request and answers with the given+// status and body.+func search1APITestServer(t *testing.T, status int, respBody string) (*HTTPHelper, *http.Request, *map[string]any, *atomic.Int32) {+ t.Helper()+ var gotReq http.Request+ gotBody := map[string]any{}+ calls := &atomic.Int32{}+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ calls.Add(1)+ gotReq = *r.Clone(r.Context())+ gotBody = map[string]any{}+ _ = json.NewDecoder(r.Body).Decode(&gotBody)+ w.Header().Set("Content-Type", "application/json")+ w.WriteHeader(status)+ _, _ = w.Write([]byte(respBody))+ }))+ t.Cleanup(srv.Close)+ helper := NewHTTPHelper().WithClient(&http.Client{Transport: rewriteHostTransport(srv.URL)})+ return helper, &gotReq, &gotBody, calls+}++func decodeSearch1APIEnvelope(t *testing.T, out string) search1APIEnvelope {+ t.Helper()+ var env search1APIEnvelope+ if err := json.Unmarshal([]byte(out), &env); err != nil {+ t.Fatalf("decode envelope %q: %v", out, err)+ }+ return env+}++func TestSearch1API_BuildRequest(t *testing.T) {+ t.Parallel()+ helper, req, body, _ := search1APITestServer(t, http.StatusOK, `{"results":[]}`)+ tool := newSearch1APITool(helper, " key-xyz ", search1APIDefaults{TopN: 5})++ out, err := tool.InvokableRun(t.Context(), `{"query":"ragflow go","channel":"News","search_service":"HackerNews","time_range":"week"}`)+ if err != nil {+ t.Fatalf("InvokableRun: %v", err)+ }+ if env := decodeSearch1APIEnvelope(t, out); env.Error != "" {+ t.Fatalf("unexpected _ERROR %q", env.Error)+ }+ if req.Method != http.MethodPost || req.URL.Path != "/news" {+ t.Errorf("request = %s %s, want POST /news", req.Method, req.URL.Path)+ }+ if got := req.Header.Get("Authorization"); got != "Bearer key-xyz" {+ t.Errorf("Authorization = %q, want trimmed bearer key", got)+ }+ if got := req.Header.Get("User-Agent"); got != "RAGFlow search1api-integration/infiniflow-ragflow" {+ t.Errorf("User-Agent = %q", got)+ }+ want := map[string]any{+ "query": "ragflow go", "search_service": "hackernews", "max_results": float64(5), "time_range": "week",+ }+ for k, v := range want {+ if (*body)[k] != v {+ t.Errorf("body.%s = %v, want %v", k, (*body)[k], v)+ }+ }+ if len(*body) != len(want) {+ t.Errorf("body = %v, want only %v", *body, want)+ }+}++func TestSearch1API_DefaultsOmitOptionalFields(t *testing.T) {+ t.Parallel()+ helper, req, body, _ := search1APITestServer(t, http.StatusOK, `{"results":[]}`)+ tool := NewSearch1APIToolWith(helper, "key")++ if _, err := tool.InvokableRun(t.Context(), `{"query":"q","time_range":"any"}`); err != nil {+ t.Fatalf("InvokableRun: %v", err)+ }+ if req.URL.Path != "/search" {+ t.Errorf("path = %q, want /search for the general channel", req.URL.Path)+ }+ for _, key := range []string{"time_range", "search_service"} {+ if _, ok := (*body)[key]; ok {+ t.Errorf("%s sent without a value: %v", key, (*body)[key])+ }+ }+ if (*body)["max_results"] != float64(10) {+ t.Errorf("max_results = %v, want the default Top N 10", (*body)["max_results"])+ }+}++func TestSearch1API_ModelOverridesNodeDefaults(t *testing.T) {+ t.Parallel()+ cases := []struct {+ name, args, wantPath string+ wantService any+ }{+ {"node defaults", `{"query":"q"}`, "/search", "github"},+ {"model service", `{"query":"q","search_service":"arxiv"}`, "/search", "arxiv"},+ // The node's github is not a news service, so Search1API picks its default.+ {"model channel drops node service", `{"query":"q","channel":"news"}`, "/news", nil},+ {"model channel and service", `{"query":"q","channel":"news","search_service":"reuters"}`, "/news", "reuters"},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ helper, req, body, _ := search1APITestServer(t, http.StatusOK, `{"results":[]}`)+ tool := newSearch1APITool(helper, "key", search1APIDefaults{Channel: "general", SearchService: "github"})+ out, err := tool.InvokableRun(t.Context(), tc.args)+ if err != nil {+ t.Fatalf("InvokableRun: %v", err)+ }+ if env := decodeSearch1APIEnvelope(t, out); env.Error != "" {+ t.Fatalf("unexpected _ERROR %q", env.Error)+ }+ if req.URL.Path != tc.wantPath {+ t.Errorf("path = %q, want %q", req.URL.Path, tc.wantPath)+ }+ if got := (*body)["search_service"]; got != tc.wantService {+ t.Errorf("search_service = %v, want %v", got, tc.wantService)+ }+ })+ }+}++func TestSearch1API_MaxResultsArg(t *testing.T) {+ t.Parallel()+ cases := []struct {+ value any+ want int+ }{+ {nil, 7}, // not given: node Top N+ {"", 7}, // blank: node Top N+ {"lots", 7}, // unparseable: node Top N+ {float64(3), 3}, // model's value wins+ {"4", 4}, // numeric string+ {float64(0), 1}, // clamped low+ {float64(99), 50}, // clamped to Search1API's max+ {float64(-5), 1}, // negative+ {float64(50), 50}, // upper bound kept+ {float64(20.9), 20}, // fractional truncated+ }+ for _, tc := range cases {+ if got := search1APIMaxResultsArg(tc.value, 7); got != tc.want {+ t.Errorf("search1APIMaxResultsArg(%#v, 7) = %d, want %d", tc.value, got, tc.want)+ }+ }+}++func TestSearch1API_ErrorsReachTheModel(t *testing.T) {+ t.Parallel()+ cases := []struct {+ name, key, args, wantErr string+ status int+ wantCalls int32+ }{+ {"no api key", "", `{"query":"q"}`, "api_key is required", http.StatusOK, 0},+ {"unknown channel", "key", `{"query":"q","channel":"images"}`, `channel "images" is not supported`, http.StatusOK, 0},+ {"unknown service", "key", `{"query":"q","search_service":"altavista"}`, `search_service "altavista" is not supported by the general channel`, http.StatusOK, 0},+ {"service not in channel", "key", `{"query":"q","channel":"news","search_service":"github"}`, `search_service "github" is not supported by the news channel`, http.StatusOK, 0},+ {"unknown time range", "key", `{"query":"q","time_range":"decade"}`, `time_range "decade" is not supported`, http.StatusOK, 0},+ {"bad arguments", "key", `{"query":`, "parse arguments", http.StatusOK, 0},+ {"rejected key", "key", `{"query":"q"}`, "upstream returned 401", http.StatusUnauthorized, 1},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ helper, _, _, calls := search1APITestServer(t, tc.status, `{"error":"nope"}`)+ out, err := NewSearch1APIToolWith(helper, tc.key).InvokableRun(t.Context(), tc.args)+ if err != nil {+ t.Fatalf("Go error %v: recoverable errors must go back to the model", err)+ }+ if env := decodeSearch1APIEnvelope(t, out); !strings.Contains(env.Error, tc.wantErr) {+ t.Errorf("_ERROR = %q, want it to contain %q", env.Error, tc.wantErr)+ }+ if got := calls.Load(); got != tc.wantCalls {+ t.Errorf("upstream calls = %d, want %d", got, tc.wantCalls)+ }+ })+ }+}++func TestSearch1API_EmptyQueryReturnsEmptyResults(t *testing.T) {+ t.Parallel()+ helper, _, _, calls := search1APITestServer(t, http.StatusOK, `{"results":[]}`)+ out, err := NewSearch1APIToolWith(helper, "key").InvokableRun(t.Context(), `{"query":" "}`)+ if err != nil || out != `{"results":[]}` {+ t.Fatalf("out, err = %q, %v; want empty results", out, err)+ }+ if calls.Load() != 0 {+ t.Error("an empty query must not reach the API")+ }+}++func TestSearch1API_KeepsRawResultsUpToMaxResults(t *testing.T) {+ t.Parallel()+ helper, _, _, _ := search1APITestServer(t, http.StatusOK,+ `{"searchParameters":{"query":"q"},"results":[{"title":"A","link":"https://a","published_date":"2026-10-01"},{"title":"B"},{"title":"C"}]}`)+ out, err := NewSearch1APIToolWith(helper, "key").InvokableRun(t.Context(), `{"query":"q","max_results":2}`)+ if err != nil {+ t.Fatalf("InvokableRun: %v", err)+ }+ env := decodeSearch1APIEnvelope(t, out)+ if len(env.Results) != 2 || env.Results[0]["published_date"] != "2026-10-01" {+ t.Fatalf("results = %#v, want the first 2 results with fields intact", env.Results)+ }+}++func TestSearch1API_ComponentReferencesAndOutputs(t *testing.T) {+ t.Parallel()+ envelope := map[string]any{"results": []any{+ map[string]any{"title": "Page", "link": "https://p", "content": " page\n\n text ", "snippet": "snippet"},+ map[string]any{"title": "Snippet only", "link": "https://s", "snippet": "just a snippet"},+ map[string]any{"title": "Empty", "link": "https://e"},+ "not a result",+ }}+ tool := NewSearch1APITool()++ chunks, docAggs := tool.BuildReferences(t.Context(), envelope)+ if len(chunks) != 2 || len(docAggs) != 2 {+ t.Fatalf("got %d chunks / %d docs, want 2 / 2 (empty result dropped)", len(chunks), len(docAggs))+ }+ if chunks[0]["content"] != "page text" {+ t.Errorf("chunk 0 content = %q, want page content with whitespace collapsed", chunks[0]["content"])+ }+ if chunks[1]["content"] != "just a snippet" {+ t.Errorf("chunk 1 content = %q, want the snippet fallback", chunks[1]["content"])+ }+ if chunks[0]["url"] != "https://p" || docAggs[0]["doc_name"] != "Page" || docAggs[0]["url"] != "https://p" {+ t.Errorf("chunk 0 = %#v / %#v", chunks[0], docAggs[0])+ }++ outputs := tool.BuildComponentOutputs(envelope)+ rendered, _ := outputs["formalized_content"].(string)+ for _, want := range []string{"├── Title: Page", "├── URL: https://p", "└── Content:\npage text", "just a snippet"} {+ if !strings.Contains(rendered, want) {+ t.Errorf("formalized_content missing %q:\n%s", want, rendered)+ }+ }+ if raw, _ := outputs["json"].([]any); len(raw) != 4 {+ t.Errorf("json output = %#v, want the raw result list", outputs["json"])+ }+}++func TestSearch1API_InfoExposesServiceChoice(t *testing.T) {+ t.Parallel()+ info, err := NewSearch1APITool().Info(t.Context())+ if err != nil || info.Name != search1APIToolName {+ t.Fatalf("Info = %+v, %v", info, err)+ }+ params, err := info.ParamsOneOf.ToJSONSchema()+ if err != nil {+ t.Fatalf("ToJSONSchema: %v", err)+ }+ raw, _ := json.Marshal(params)+ for _, want := range []string{`"search_service"`, `"hackernews"`, `"arxiv"`, `"channel"`, `"time_range"`, `"max_results"`} {+ if !strings.Contains(string(raw), want) {+ t.Errorf("schema missing %s: %s", want, raw)+ }+ }+ if strings.Contains(string(raw), "api_key") {+ t.Errorf("api_key must not be model-visible: %s", raw)+ }+}++func TestSearch1API_BuildByNameUsesNodeConfig(t *testing.T) {+ t.Parallel()+ built, err := BuildByName("Search1APISearch", map[string]any{+ "api_key": "stored-key", "channel": "news", "search_service": "reuters", "top_n": float64(4),+ "query": "{sys.query}", "outputs": map[string]any{},+ })+ if err != nil {+ t.Fatalf("BuildByName: %v", err)+ }+ tool, ok := built.(*Search1APITool)+ if !ok {+ t.Fatalf("built %T, want *Search1APITool", built)+ }+ want := search1APIDefaults{Channel: "news", SearchService: "reuters", TopN: 4}+ if tool.apiKey != "stored-key" || tool.defaults != want {+ t.Errorf("tool = key %q defaults %+v, want %+v", tool.apiKey, tool.defaults, want)+ }+}++func TestSearch1API_BuildByNameRejectsInvalidNodeConfig(t *testing.T) {+ t.Parallel()+ for name, params := range map[string]map[string]any{+ "api_key not a string": {"api_key": 42},+ "unknown channel": {"channel": "images"},+ "unknown search_service": {"search_service": "altavista"},+ "service not in channel": {"channel": "news", "search_service": "github"},+ "news service for general": {"search_service": "reuters"},+ "zero top_n": {"top_n": float64(0)},+ "top_n over the limit": {"top_n": float64(51)},+ "fractional top_n": {"top_n": 2.5},+ } {+ if _, err := BuildByName("search1api", params); err == nil {+ t.Errorf("%s: expected a config error", name)+ }+ }+}diff --git a/web/src/components/operator-icon.tsx b/web/src/components/operator-icon.tsxindex 6052a11954..98245ae5dc 100644--- a/web/src/components/operator-icon.tsx+++ b/web/src/components/operator-icon.tsx@@ -17,6 +17,7 @@import { IconFontFill } from '@/components/icon-font';import SvgIcon from '@/components/svg-icon';import queritLogo from '@/assets/querit.png';+import search1apiLogo from '@/assets/search1api.png';import { cn } from '@/lib/utils';import {Columns3Cog,@@ -78,6 +79,8 @@ export const SVGIconMap = {[Operator.TavilySearch]: 'tavily',[Operator.QueritContents]: 'querit',[Operator.QueritSearch]: 'querit',+ [Operator.Search1APISearch]: 'search1api',+ [Operator.Search1APICrawl]: 'search1api',[Operator.Wikipedia]: 'wikipedia',[Operator.YahooFinance]: 'yahoo-finance',[Operator.WenCai]: 'wencai',@@ -137,6 +140,16 @@ const OperatorIcon = ({ name, className }: IProps) => {);}+ if (name === Operator.Search1APISearch || name === Operator.Search1APICrawl) {+ return (+ <img+ src={search1apiLogo}+ alt=""+ className={cn('size-5 object-contain', className)}+ />+ );+ }+if (name === Operator.Begin) {return (<divdiff --git a/web/src/constants/agent.tsx b/web/src/constants/agent.tsxindex 20bb8bfb73..5d0c55fe5f 100644--- a/web/src/constants/agent.tsx+++ b/web/src/constants/agent.tsx@@ -120,6 +120,8 @@ export enum Operator {KeenableSearch = 'KeenableSearch',YouComSearch = 'YouComSearch',SofyaSearch = 'SofyaSearch',+ Search1APISearch = 'Search1APISearch',+ Search1APICrawl = 'Search1APICrawl',DocGenerator = 'DocGenerator',Browser = 'Browser',Placeholder = 'Placeholder',diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex 70640d205b..0290bb249f 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -2940,6 +2940,23 @@ Best for: Documents with flowing, contextually connected content — such as boosofyaSearchDepthBasic: 'Page content',sofyaSearchDepthSnippets: 'Snippets only',sofyaApiKeyTip: 'Required. Create an API Key at sofya.co.',+ search1APISearch: 'Search1API',+ search1APISearchDescription:+ 'A web and news search component powered by Search1API. It covers search services such as Google, Bing, Baidu, GitHub, arXiv, Reddit, YouTube, Hacker News and Reuters. As an agent tool, the agent can pick the channel and search service for each call. An API Key is required.',+ search1APIChannelTip:+ 'Web searches the general web; News searches news sources. As an agent tool, the agent can switch the channel for each call.',+ search1APIChannelGeneral: 'Web',+ search1APIChannelNews: 'News',+ search1APIService: 'Search service',+ search1APIServiceTip:+ 'The default search service for the selected channel. As an agent tool, the agent can pick another service the channel supports for each call.',+ search1APIApiKeyTip: 'Required. Create an API Key at app.s1.dev.',+ search1APICrawl: 'Search1API crawl',+ search1APICrawlDescription:+ 'Read a web page with Search1API and return its title and full content. An API Key is required.',+ search1APICrawlUrl: 'URL',+ search1APICrawlUrlTip:+ 'The absolute HTTP or HTTPS URL of the page to read. As an agent tool, the agent supplies the URL.',docGenerator: 'Doc Generator',docGeneratorDescription: `Generate a file from Markdown content.`,browser: 'Browser',diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex b89efbcada..3429796dc8 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -2529,6 +2529,23 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 RsofyaSearchDepthBasic: '页面正文',sofyaSearchDepthSnippets: '仅摘要',sofyaApiKeyTip: '必填。请在 sofya.co 申请 API Key。',+ search1APISearch: 'Search1API',+ search1APISearchDescription:+ '基于 Search1API 的网页与新闻搜索组件,覆盖 Google、Bing、百度、GitHub、arXiv、Reddit、YouTube、Hacker News、Reuters 等搜索服务。作为智能体工具时,智能体可以在每次调用时自行选择频道和搜索服务。需要配置 API Key。',+ search1APIChannelTip:+ '网页频道搜索通用网页,新闻频道搜索新闻来源。作为智能体工具时,智能体可以在每次调用时切换频道。',+ search1APIChannelGeneral: '网页',+ search1APIChannelNews: '新闻',+ search1APIService: '搜索服务',+ search1APIServiceTip:+ '所选频道的默认搜索服务。作为智能体工具时,智能体可以在每次调用时改用该频道支持的其他服务。',+ search1APIApiKeyTip: '必填。请在 app.s1.dev 申请 API Key。',+ search1APICrawl: 'Search1API 网页读取',+ search1APICrawlDescription:+ '使用 Search1API 读取网页,返回页面标题和完整正文。需要配置 API Key。',+ search1APICrawlUrl: '网页地址',+ search1APICrawlUrlTip:+ '要读取页面的完整 HTTP 或 HTTPS 地址。作为智能体工具时,由智能体提供地址。',docGenerator: '文档生成器',docGeneratorDescription: `从 Markdown 内容生成文件。`,browser: 'Browser',diff --git a/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx b/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsxindex 69e0a634f4..f1f5f4c299 100644--- a/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx+++ b/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx@@ -91,6 +91,8 @@ export function AccordionOperators({Operator.KeenableSearch,Operator.YouComSearch,Operator.SofyaSearch,+ Operator.Search1APISearch,+ Operator.Search1APICrawl,Operator.DocGenerator,Operator.Browser,]);diff --git a/web/src/pages/agent/constant/index.tsx b/web/src/pages/agent/constant/index.tsxindex e22cf5fc14..42e8eaf42a 100644--- a/web/src/pages/agent/constant/index.tsx+++ b/web/src/pages/agent/constant/index.tsx@@ -248,6 +248,73 @@ export const initialSofyaValues = {},};+export enum Search1APIChannel {+ General = 'general',+ News = 'news',+}++// Search services each Search1API channel accepts. The agent may pick any of+// them at call time; the node value is only the default.+export const Search1APIServices: Record<Search1APIChannel, string[]> = {+ [Search1APIChannel.General]: [+ 'google',+ 'bing',+ 'bingcn',+ 'duckduckgo',+ 'yahoo',+ 'yandex',+ 'youtube',+ 'x',+ 'reddit',+ 'github',+ 'arxiv',+ 'wechat',+ 'bilibili',+ 'imdb',+ 'wikipedia',+ 'baidu',+ '360',+ 'quark',+ ],+ [Search1APIChannel.News]: [+ 'google',+ 'bing',+ 'duckduckgo',+ 'yahoo',+ 'hackernews',+ 'reuters',+ ],+};++export const initialSearch1APISearchValues = {+ api_key: '',+ query: AgentGlobals.SysQuery,+ channel: Search1APIChannel.General,+ search_service: 'google',+ top_n: 10,+ outputs: {+ formalized_content: {+ value: '',+ type: 'string',+ },+ json: {+ value: [],+ type: 'Array<Object>',+ },+ },+};++export const initialSearch1APICrawlValues = {+ api_key: '',+ url: '',+ outputs: {+ json: {+ value: {},+ type: 'object',+ },+ },+};+export const initialKeenableValues = {api_key: '',query: AgentGlobals.SysQuery,@@ -803,6 +870,8 @@ export const RestrictedUpstreamMap = {[Operator.KeenableSearch]: [Operator.Begin, Operator.Retrieval],[Operator.YouComSearch]: [Operator.Begin, Operator.Retrieval],[Operator.SofyaSearch]: [Operator.Begin, Operator.Retrieval],+ [Operator.Search1APISearch]: [Operator.Begin, Operator.Retrieval],+ [Operator.Search1APICrawl]: [Operator.Begin],[Operator.ExeSQL]: [Operator.Begin],[Operator.Switch]: [Operator.Begin],[Operator.WenCai]: [Operator.Begin],@@ -862,6 +931,8 @@ export const NodeMap = {[Operator.KeenableSearch]: 'ragNode',[Operator.YouComSearch]: 'ragNode',[Operator.SofyaSearch]: 'ragNode',+ [Operator.Search1APISearch]: 'ragNode',+ [Operator.Search1APICrawl]: 'ragNode',[Operator.ExeSQL]: 'ragNode',[Operator.Switch]: 'switchNode',[Operator.WenCai]: 'ragNode',diff --git a/web/src/pages/agent/form-sheet/form-config-map.tsx b/web/src/pages/agent/form-sheet/form-config-map.tsxindex 553c8ff715..b20e721436 100644--- a/web/src/pages/agent/form-sheet/form-config-map.tsx+++ b/web/src/pages/agent/form-sheet/form-config-map.tsx@@ -22,6 +22,8 @@ import IterationForm from '../form/iteration-form';import IterationStartForm from '../form/iteration-start-from';import KeenableForm from '../form/keenable-form';import SofyaForm from '../form/sofya-form';+import Search1APICrawlForm from '../form/search1api-crawl-form';+import Search1APIForm from '../form/search1api-form';import YouComForm from '../form/youcom-form';import ListOperationsForm from '../form/list-operations-form';import LoopForm from '../form/loop-form';@@ -87,6 +89,12 @@ export const FormConfigMap = {[Operator.SofyaSearch]: {component: SofyaForm,},+ [Operator.Search1APISearch]: {+ component: Search1APIForm,+ },+ [Operator.Search1APICrawl]: {+ component: Search1APICrawlForm,+ },[Operator.Wikipedia]: {component: WikipediaForm,},diff --git a/web/src/pages/agent/form/agent-form/tool-popover/tool-command.tsx b/web/src/pages/agent/form/agent-form/tool-popover/tool-command.tsxindex 3cc7f0655b..196f759616 100644--- a/web/src/pages/agent/form/agent-form/tool-popover/tool-command.tsx+++ b/web/src/pages/agent/form/agent-form/tool-popover/tool-command.tsx@@ -32,6 +32,8 @@ const Menus = [Operator.KeenableSearch,Operator.YouComSearch,Operator.SofyaSearch,+ Operator.Search1APISearch,+ Operator.Search1APICrawl,Operator.YahooFinance,Operator.PubMed,Operator.BGPT,diff --git a/web/src/pages/agent/form/search1api-crawl-form/index.tsx b/web/src/pages/agent/form/search1api-crawl-form/index.tsxnew file mode 100644index 0000000000..9a7a74cf21--- /dev/null+++ b/web/src/pages/agent/form/search1api-crawl-form/index.tsx@@ -0,0 +1,76 @@+import { FormContainer } from '@/components/form-container';+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from '@/components/ui/form';+import { useTranslate } from '@/hooks/common-hooks';+import { zodResolver } from '@hookform/resolvers/zod';+import { memo } from 'react';+import { useForm } from 'react-hook-form';+import { z } from 'zod';+import { initialSearch1APICrawlValues } from '../../constant';+import { useFormValues } from '../../hooks/use-form-values';+import { useWatchFormChange } from '../../hooks/use-watch-form-change';+import { INextOperatorForm } from '../../interface';+import { buildOutputList } from '../../utils/build-output-list';+import { ApiKeyField } from '../components/api-key-field';+import { FormWrapper } from '../components/form-wrapper';+import { Output } from '../components/output';+import { PromptEditor } from '../components/prompt-editor';++const outputList = buildOutputList(initialSearch1APICrawlValues.outputs);++const FormSchema = z.object({+ api_key: z.string(),+ url: z.string().min(1),+});++function Search1APICrawlForm({ node }: INextOperatorForm) {+ const { t } = useTranslate('flow');+ const values = useFormValues(initialSearch1APICrawlValues, node);+ const form = useForm<z.infer<typeof FormSchema>>({+ defaultValues: values,+ resolver: zodResolver(FormSchema),+ mode: 'onChange',+ });++ useWatchFormChange(node?.id, form);++ return (+ <Form {...form}>+ <FormWrapper>+ <FormContainer>+ <ApiKeyField placeholder={t('search1APIApiKeyTip')} />+ <FormField+ control={form.control}+ name="url"+ render={({ field }) => (+ <FormItem>+ <FormLabel tooltip={t('search1APICrawlUrlTip')}>+ {t('search1APICrawlUrl')}+ </FormLabel>+ <FormControl>+ <PromptEditor+ {...field}+ multiLine={false}+ showToolbar={false}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </FormContainer>+ </FormWrapper>+ <div className="p-5">+ <Output list={outputList} />+ </div>+ </Form>+ );+}++export default memo(Search1APICrawlForm);diff --git a/web/src/pages/agent/form/search1api-form/index.tsx b/web/src/pages/agent/form/search1api-form/index.tsxnew file mode 100644index 0000000000..4cb87d8636--- /dev/null+++ b/web/src/pages/agent/form/search1api-form/index.tsx@@ -0,0 +1,174 @@+import { FormContainer } from '@/components/form-container';+import { TopNFormField } from '@/components/top-n-item';+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from '@/components/ui/form';+import { SelectWithSearch } from '@/components/originui/select-with-search';+import { useTranslate } from '@/hooks/common-hooks';+import { zodResolver } from '@hookform/resolvers/zod';+import { memo, useEffect, useMemo } from 'react';+import { useForm, useFormContext, useWatch } from 'react-hook-form';+import { z } from 'zod';+import {+ Search1APIChannel,+ Search1APIServices,+ initialSearch1APISearchValues,+} from '../../constant';+import { useFormValues } from '../../hooks/use-form-values';+import { useWatchFormChange } from '../../hooks/use-watch-form-change';+import { INextOperatorForm } from '../../interface';+import { buildOutputList } from '../../utils/build-output-list';+import { ApiKeyField } from '../components/api-key-field';+import { FormWrapper } from '../components/form-wrapper';+import { Output } from '../components/output';+import { QueryVariable } from '../components/query-variable';++const Search1APIChannelLabelKeys: Record<Search1APIChannel, string> = {+ [Search1APIChannel.General]: 'search1APIChannelGeneral',+ [Search1APIChannel.News]: 'search1APIChannelNews',+};++// Service names are brands, so they are shown as-is rather than translated.+const Search1APIServiceLabels: Record<string, string> = {+ google: 'Google',+ bing: 'Bing',+ bingcn: 'Bing CN',+ duckduckgo: 'DuckDuckGo',+ yahoo: 'Yahoo',+ yandex: 'Yandex',+ youtube: 'YouTube',+ x: 'X',+ reddit: 'Reddit',+ github: 'GitHub',+ arxiv: 'arXiv',+ wechat: 'WeChat',+ bilibili: 'Bilibili',+ imdb: 'IMDb',+ wikipedia: 'Wikipedia',+ baidu: 'Baidu',+ '360': '360',+ quark: 'Quark',+ hackernews: 'Hacker News',+ reuters: 'Reuters',+};++export const Search1APIFormPartialSchema = {+ api_key: z.string().optional(),+ channel: z.string().optional(),+ search_service: z.string().optional(),+ top_n: z.coerce.number(),+};++const FormSchema = z.object({+ query: z.string(),+ ...Search1APIFormPartialSchema,+});++export function Search1APIWidgets() {+ const { t } = useTranslate('flow');+ const form = useFormContext();+ const channel: Search1APIChannel =+ useWatch({ control: form.control, name: 'channel' }) ||+ Search1APIChannel.General;+ const services = useMemo(() => Search1APIServices[channel] ?? [], [channel]);++ const channelOptions = useMemo(+ () =>+ Object.values(Search1APIChannel).map((x) => ({+ value: x,+ label: t(Search1APIChannelLabelKeys[x]),+ })),+ [t],+ );++ const serviceOptions = useMemo(+ () =>+ services.map((x) => ({+ value: x,+ label: Search1APIServiceLabels[x] ?? x,+ })),+ [services],+ );++ // Each channel offers its own services, so a service the new channel lacks+ // falls back to the channel's first one.+ useEffect(() => {+ const current = form.getValues('search_service');+ if (services.length > 0 && !services.includes(current)) {+ form.setValue('search_service', services[0], { shouldDirty: true });+ }+ }, [form, services]);++ return (+ <>+ <ApiKeyField placeholder={t('search1APIApiKeyTip')}></ApiKeyField>+ <FormField+ control={form.control}+ name={'channel'}+ render={({ field }) => (+ <FormItem>+ <FormLabel tooltip={t('search1APIChannelTip')}>+ {t('channel')}+ </FormLabel>+ <FormControl>+ <SelectWithSearch {...field} options={channelOptions} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name={'search_service'}+ render={({ field }) => (+ <FormItem>+ <FormLabel tooltip={t('search1APIServiceTip')}>+ {t('search1APIService')}+ </FormLabel>+ <FormControl>+ <SelectWithSearch {...field} options={serviceOptions} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <TopNFormField max={50}></TopNFormField>+ </>+ );+}++const Search1APIOutputList = buildOutputList(+ initialSearch1APISearchValues.outputs,+);++function Search1APIForm({ node }: INextOperatorForm) {+ const defaultValues = useFormValues(initialSearch1APISearchValues, node);++ const form = useForm<z.infer<typeof FormSchema>>({+ defaultValues,+ resolver: zodResolver(FormSchema),+ });++ useWatchFormChange(node?.id, form);++ return (+ <Form {...form}>+ <FormWrapper>+ <FormContainer>+ <QueryVariable></QueryVariable>+ <Search1APIWidgets></Search1APIWidgets>+ </FormContainer>+ </FormWrapper>+ <div className="p-5">+ <Output list={Search1APIOutputList}></Output>+ </div>+ </Form>+ );+}++export default memo(Search1APIForm);diff --git a/web/src/pages/agent/form/tool-form/constant.tsx b/web/src/pages/agent/form/tool-form/constant.tsxindex 936e14e0b9..ac407b9e7c 100644--- a/web/src/pages/agent/form/tool-form/constant.tsx+++ b/web/src/pages/agent/form/tool-form/constant.tsx@@ -10,6 +10,7 @@ import GoogleForm from './google-form';import GoogleScholarForm from './google-scholar-form';import KeenableForm from './keenable-form';import SofyaForm from './sofya-form';+import Search1APIForm from './search1api-form';import YouComForm from './youcom-form';import PubMedForm from './pubmed-form';import QueritForm from './querit-form';@@ -46,4 +47,6 @@ export const ToolFormConfigMap = {[Operator.KeenableSearch]: KeenableForm,[Operator.YouComSearch]: YouComForm,[Operator.SofyaSearch]: SofyaForm,+ [Operator.Search1APISearch]: Search1APIForm,+ [Operator.Search1APICrawl]: ApiKeyToolForm,};diff --git a/web/src/pages/agent/form/tool-form/search1api-form/index.tsx b/web/src/pages/agent/form/tool-form/search1api-form/index.tsxnew file mode 100644index 0000000000..8d00479809--- /dev/null+++ b/web/src/pages/agent/form/tool-form/search1api-form/index.tsx@@ -0,0 +1,38 @@+import { FormContainer } from '@/components/form-container';+import { Form } from '@/components/ui/form';+import { zodResolver } from '@hookform/resolvers/zod';+import { memo } from 'react';+import { useForm } from 'react-hook-form';+import { z } from 'zod';+import { FormWrapper } from '../../components/form-wrapper';+import {+ Search1APIFormPartialSchema,+ Search1APIWidgets,+} from '../../search1api-form';+import { useValues } from '../use-values';+import { useWatchFormChange } from '../use-watch-change';++function Search1APIForm() {+ const values = useValues();++ const FormSchema = z.object(Search1APIFormPartialSchema);++ const form = useForm<z.infer<typeof FormSchema>>({+ defaultValues: values,+ resolver: zodResolver(FormSchema),+ });++ useWatchFormChange(form);++ return (+ <Form {...form}>+ <FormWrapper>+ <FormContainer>+ <Search1APIWidgets></Search1APIWidgets>+ </FormContainer>+ </FormWrapper>+ </Form>+ );+}++export default memo(Search1APIForm);diff --git a/web/src/pages/agent/hooks/use-add-node.ts b/web/src/pages/agent/hooks/use-add-node.tsindex b41f8a9ad8..d0ed36bb02 100644--- a/web/src/pages/agent/hooks/use-add-node.ts+++ b/web/src/pages/agent/hooks/use-add-node.ts@@ -32,6 +32,8 @@ import {initialIterationValues,initialKeenableValues,initialSofyaValues,+ initialSearch1APICrawlValues,+ initialSearch1APISearchValues,initialYouComValues,initialListOperationsValues,initialLoopValues,@@ -177,6 +179,8 @@ export const useInitializeOperatorParams = () => {[Operator.KeenableSearch]: initialKeenableValues,[Operator.YouComSearch]: initialYouComValues,[Operator.SofyaSearch]: initialSofyaValues,+ [Operator.Search1APISearch]: initialSearch1APISearchValues,+ [Operator.Search1APICrawl]: initialSearch1APICrawlValues,[Operator.UserFillUp]: initialUserFillUpValues,[Operator.StringTransform]: initialStringTransformValues,[Operator.TavilyExtract]: initialTavilyExtractValues,diff --git a/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts b/web/src/pages/agent/hooks/use-agent-tool-initial-values.tsindex e3145aa3bc..f25d8330a1 100644--- a/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts+++ b/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts@@ -72,6 +72,16 @@ export function useAgentToolInitialValues() {return pick(initialValues, 'api_key', 'freshness', 'top_n');case Operator.SofyaSearch:return pick(initialValues, 'api_key', 'search_depth', 'top_n');+ case Operator.Search1APISearch:+ return pick(+ initialValues,+ 'api_key',+ 'channel',+ 'search_service',+ 'top_n',+ );+ case Operator.Search1APICrawl:+ return { api_key: '' };default:return initialValues;diff --git a/web/src/pages/agent/log-sheet/tool-name.test.ts b/web/src/pages/agent/log-sheet/tool-name.test.tsindex 538cff9b9e..9ca19838fc 100644--- a/web/src/pages/agent/log-sheet/tool-name.test.ts+++ b/web/src/pages/agent/log-sheet/tool-name.test.ts@@ -2,6 +2,8 @@ jest.mock('@/constants/agent', () => ({Operator: {QueritContents: 'QueritContents',QueritSearch: 'QueritSearch',+ Search1APICrawl: 'Search1APICrawl',+ Search1APISearch: 'Search1APISearch',},}));@@ -23,6 +25,20 @@ describe('getToolOperatorName', () => {},);+ it.each(['Search1APISearch', 'search1api_search'])(+ 'maps the Search1API timeline name %p to its operator',+ (toolName) => {+ expect(getToolOperatorName(toolName)).toBe(Operator.Search1APISearch);+ },+ );++ it.each(['Search1APICrawl', 'search1api_crawl'])(+ 'maps the Search1API crawl timeline name %p to its operator',+ (toolName) => {+ expect(getToolOperatorName(toolName)).toBe(Operator.Search1APICrawl);+ },+ );+it.each([undefined, null, ''])('returns an empty name for the missing value %p',(toolName) => {diff --git a/web/src/pages/agent/log-sheet/tool-name.ts b/web/src/pages/agent/log-sheet/tool-name.tsindex 3bcb718060..a29abe4c90 100644--- a/web/src/pages/agent/log-sheet/tool-name.ts+++ b/web/src/pages/agent/log-sheet/tool-name.ts@@ -12,6 +12,13 @@ export function getToolOperatorName(toolName?: string | null) {if (normalizedName === Operator.QueritContents.toLowerCase()) {return Operator.QueritContents;}+ // Search1API keeps its brand casing, which the generic split below loses.+ if (normalizedName === Operator.Search1APISearch.toLowerCase()) {+ return Operator.Search1APISearch;+ }+ if (normalizedName === Operator.Search1APICrawl.toLowerCase()) {+ return Operator.Search1APICrawl;+ }return toolName.split('_')diff --git a/web/src/pages/agent/log-sheet/tool-timeline-item.tsx b/web/src/pages/agent/log-sheet/tool-timeline-item.tsxindex ebb4a0ea55..eb121758b2 100644--- a/web/src/pages/agent/log-sheet/tool-timeline-item.tsx+++ b/web/src/pages/agent/log-sheet/tool-timeline-item.tsx@@ -34,6 +34,8 @@ type IToolIcon =| Operator.KeenableSearch| Operator.YouComSearch| Operator.SofyaSearch+ | Operator.Search1APISearch+ | Operator.Search1APICrawl| Operator.Wikipedia| Operator.YahooFinance| Operator.WenCaidiff --git a/web/src/pages/agent/utils/clear-sensitive-fields.test.ts b/web/src/pages/agent/utils/clear-sensitive-fields.test.tsindex 0ccb4ae950..35d5670220 100644--- a/web/src/pages/agent/utils/clear-sensitive-fields.test.ts+++ b/web/src/pages/agent/utils/clear-sensitive-fields.test.ts@@ -9,6 +9,8 @@ jest.mock('@/constants/agent', () => ({BGPT: 'Bing',QueritContents: 'QueritContents',QueritSearch: 'QueritSearch',+ Search1APISearch: 'Search1APISearch',+ Search1APICrawl: 'Search1APICrawl',},}));@@ -183,6 +185,54 @@ describe('clearSensitiveFields', () => {expect(dsl.tools[0].params.api_key).toBe('sofya-tool-secret');});+ it.each([+ 'Search1APISearch',+ 'Search1APICrawl',+ 'search1apisearch',+ 'search1apicrawl',+ 'search1api',+ 'search1api_crawl',+ ])(+ 'clears a %s key from a canvas node and from a tool record',+ (operator) => {+ const dsl = {+ graph: {+ nodes: [+ {+ data: {+ label: operator,+ form: {+ api_key: 'search1api-graph-secret',+ channel: 'news',+ },+ },+ },+ ],+ },+ tools: [+ {+ component_name: operator,+ params: {+ api_key: 'search1api-tool-secret',+ search_service: 'reuters',+ },+ },+ ],+ };++ const sanitized = clearSensitiveFields(dsl);++ expect(sanitized.graph.nodes[0].data.form.api_key).toBe('');+ expect(sanitized.graph.nodes[0].data.form.channel).toBe('news');+ expect(sanitized.tools[0].params.api_key).toBe('');+ expect(sanitized.tools[0].params.search_service).toBe('reuters');+ expect(dsl.graph.nodes[0].data.form.api_key).toBe(+ 'search1api-graph-secret',+ );+ expect(dsl.tools[0].params.api_key).toBe('search1api-tool-secret');+ },+ );+it('does not change standalone graph export behavior for other tools', () => {const dsl = {graph: {diff --git a/web/src/pages/agent/utils/clear-sensitive-fields.ts b/web/src/pages/agent/utils/clear-sensitive-fields.tsindex 795090d6bb..1b35fd6881 100644--- a/web/src/pages/agent/utils/clear-sensitive-fields.ts+++ b/web/src/pages/agent/utils/clear-sensitive-fields.ts@@ -31,12 +31,26 @@ function isQueritOperator(value: unknown) {);}+function isSearch1APIOperator(value: unknown) {+ if (typeof value !== 'string') {+ return false;+ }++ return ['search1api', 'search1apisearch', 'search1apicrawl'].includes(+ value.replace(/_/g, '').toLowerCase(),+ );+}+function isNodeLabelApiKeyOperator(value: unknown) {if (typeof value !== 'string') {return false;}- return isQueritOperator(value) || nodeLabelApiKeyOperators.includes(value);+ return (+ isQueritOperator(value) ||+ isSearch1APIOperator(value) ||+ nodeLabelApiKeyOperators.includes(value)+ );}export function clearSensitiveFields<T>(obj: T): T {@@ -47,7 +61,8 @@ export function clearSensitiveFields<T>(obj: T): T {if ((apiKeyOperators.includes(value.component_name) ||- isQueritOperator(value.component_name)) &&+ isQueritOperator(value.component_name) ||+ isSearch1APIOperator(value.component_name)) &&get(value, 'params.api_key')) {return { ...value, params: { ...value.params, api_key: '' } };