Skip to content
pi-c Artifact [aff603d35f]
Login

Artifact [aff603d35f]

Artifact aff603d35f4a08bd25727816c87ee5b01c8146d9ad473cedb8cc312f25578d1b:


/* The provider's own web search (websearch_native.c): when the model's provider runs searches
 * itself, a request declares that server tool where the session's web_search function would be,
 * and the search happens on the provider's side, billed per search to the user's account there.
 * The model sees one tool name, web_search, either way; pic's function (Brave, websearch.c) is
 * what it gets when the provider has none or this conversation may not use it. */
#ifndef PIC_WEBSEARCH_NATIVE_H
#define PIC_WEBSEARCH_NATIVE_H

#include <stddef.h>
#include <stdint.h>

#include "pic.h"
#include "sqlite3.h"

/* For a request of model M in SUBMISSION's conversation, with TOOLS the session's tools (a JSON
 * array of {name,description,input_schema}): when the provider's own search applies, TOOLS
 * without the web_search function (malloc'd) and *NATIVE the server tool's declaration in the
 * wire shape (malloc'd); else NULL and *NATIVE NULL, and the request goes as it was.
 *
 * It applies when TOOLS holds web_search (so --exclude-tools turns it off), the setting webSearch
 * is auto, offline is off, the conversation's permission mode is allow or ask-edits (pic cannot
 * ask before a call the provider makes, so the modes that ask or refuse changes get the function,
 * which pic gates), and the provider has a search that M and its sign-in can use: Anthropic,
 * OpenAI with an API key, xAI and OpenRouter. (Gemini is not among them: its search shares a request
 * with function tools only from Gemini 3, with server-side tool parts that must be passed back,
 * which the Gemini decoder does not keep; it gets the function.) */
char *pic_websearch_native(pic_store *s, int64_t submission, const pic_model *m, const char *tools, char **native);

/* TOOLS with NATIVE put first in the array (malloc'd): for a wire whose tools are the neutral shape. */
char *pic_websearch_prepend(const char *tools, const char *native);

/* JSON (the messages of an Anthropic request, or the input items of a Responses one) with the
 * search of earlier replies turned into what a request that declares no provider search may carry
 * (malloc'd); NULL when it holds none. */
char *pic_websearch_demote(sqlite3 *db, int anthropic, const char *json);

/* Whether the model the next request goes to (pic_toolset_model) can search through its provider,
 * which has a credential here: web_search is offered then even with no Brave key. */
int pic_websearch_native_possible(void);

#endif