@runappsai/agent 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,74 @@
1
+ // Web tools: the platform's web_search and web_fetch offered to the model
2
+ // as the agent's own tools (`webTools`). The platform runs them and bills
3
+ // them per call; the descriptions come from it (`GET /v1/tools`, cached by
4
+ // the SDK), so a better description or a new limit needs no new package.
5
+ // They run like any other tool — in the loop, beside the app's tools,
6
+ // shown in the chat as cards — and their cost is added to the agent's usage.
7
+ /** The platform tools `webTools` offers. */
8
+ export const WEB_TOOL_NAMES = ["web_search", "web_fetch"];
9
+ const svg = (body) => `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${body}</svg>`;
10
+ /** lucide "globe". */
11
+ export const GLOBE_ICON = svg('<circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/>');
12
+ const SEARCH_ICON = svg('<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>');
13
+ const GUIDELINES = [
14
+ "web_search finds pages and web_fetch reads one: use them for facts you can't know or that change (news, prices, releases, people, places, a work's details, a reference the user names), not for what the conversation or your own knowledge already answers.",
15
+ "Read the most relevant results with web_fetch before relying on them; a snippet is not the page. Say where an answer came from, with the link.",
16
+ "Each call costs the user a little: search with a precise query, and stop when you have enough.",
17
+ ];
18
+ function hostOf(url) {
19
+ if (typeof url !== "string")
20
+ return "";
21
+ try {
22
+ const u = new URL(url.includes("://") ? url : `https://${url}`);
23
+ const path = u.pathname === "/" ? "" : u.pathname;
24
+ return u.host + (path.length > 32 ? path.slice(0, 31) + "…" : path);
25
+ }
26
+ catch {
27
+ return url.slice(0, 48);
28
+ }
29
+ }
30
+ /**
31
+ * The tools as the agent holds them. `onCost` gets what each call charged
32
+ * (USD, the creator's fee included); a call that fails throws, and costs
33
+ * nothing.
34
+ */
35
+ export async function webTools(platform, opts = {}) {
36
+ const list = await platform.list(opts.signal ? { signal: opts.signal } : undefined);
37
+ const out = [];
38
+ for (const name of WEB_TOOL_NAMES) {
39
+ const info = list.find((t) => t.name === name);
40
+ if (!info)
41
+ continue;
42
+ const isSearch = name === "web_search";
43
+ out.push({
44
+ name,
45
+ description: info.description,
46
+ parameters: (info.parameters ?? { type: "object", properties: {} }),
47
+ readOnly: true,
48
+ // A page may be long; web_fetch cuts it at its own max_chars (40 000 by default).
49
+ maxResultChars: isSearch ? 16_000 : 42_000,
50
+ ...(isSearch ? { guidelines: GUIDELINES } : {}),
51
+ display: {
52
+ icon: isSearch ? SEARCH_ICON : GLOBE_ICON,
53
+ outcome: ({ details }) => {
54
+ if (isSearch) {
55
+ const n = details?.results?.length;
56
+ return typeof n === "number" ? String(n) : undefined;
57
+ }
58
+ const title = details?.title;
59
+ return title ? title.slice(0, 40) : undefined;
60
+ },
61
+ },
62
+ async execute(args, ctx) {
63
+ if (!isSearch && typeof args.url === "string")
64
+ ctx.update(hostOf(args.url));
65
+ const r = await platform.call(name, args, { signal: ctx.signal });
66
+ const cost = r.usage?.total_cost;
67
+ if (typeof cost === "number" && cost > 0)
68
+ opts.onCost?.(cost);
69
+ return { content: r.content, details: r.data };
70
+ },
71
+ });
72
+ }
73
+ return out;
74
+ }
package/docs/agent.md CHANGED
@@ -244,6 +244,7 @@ Both live in the workspace's directory: shared by every conversation that uses t
244
244
  | `persist` | `true` with a workspace | Save after every turn. |
245
245
  | `restore` | | A `SessionData` to continue. |
246
246
  | `prompt` | | RunApps private prompt reference (`{ id, vars }`), sent with every request. |
247
- | `serverTools` | | RunApps only: `["web_search", "web_fetch"]` run by the gateway, for an agent with no tools of its own. |
247
+ | `webTools` | `false` | RunApps (SDK 0.19+): the platform's `web_search` and `web_fetch` beside your tools, billed per call (see [Tools](tools.md#web-search-and-reading-pages)). A function is read every turn. |
248
+ | `serverTools` | | Deprecated, use `webTools`: the gateway runs the tools inside the chat call, for an agent with no tools of its own. |
248
249
 
249
- Change settings on a live agent with `agent.configure({ model, maxTurns, maxTokens, permissions, reasoningEffort })`; `agent.settings` reads them back.
250
+ Change settings on a live agent with `agent.configure({ model, maxTurns, maxTokens, permissions, reasoningEffort, webTools })`; `agent.settings` reads them back, `agent.webTools` says whether the web tools are on and `agent.webToolsAvailable` whether the provider has them.
package/docs/chat-ui.md CHANGED
@@ -90,6 +90,7 @@ Typing `/` lists the built-in commands, then the directory's prompt templates an
90
90
  | `skillsMenu` | on with a workspace | The *Skills* button. |
91
91
  | `settings` | on | The settings gear. |
92
92
  | `attachments` | on | Paperclip, drop and paste. |
93
+ | `webSearch` | shown when the provider has web tools | The globe beside the paperclip: turns the platform's web search and page reading on and off (`webTools`), kept per app. Hidden when `webTools` is a function of yours; `false` hides it. |
93
94
  | `uploadsDir` | `/uploads` | Where attachments are saved (with a workspace and file tools; with `fileTools: false` a text file goes into the message itself, so the model can read it). |
94
95
  | `showUsage` | on | The context ring in the header and its panel (context use, spending, *Compact now*). |
95
96
  | `locale` | the document's | `"en"` or `"zh"`. |
package/docs/reference.md CHANGED
@@ -63,6 +63,7 @@ Options: see [the options table](agent.md#options). Events: see [Events](agent.m
63
63
  | `connectMCP(url, { token?, headers?, prefix?, confirm?, images?, timeoutMs?, maxTools?, maxResultChars?, fetch?, signal? })` → `MCPConnection` | An MCP server's tools (`tools`, `serverTools`, `server`, `instructions`, `refresh()`, `close()`). `MCPError` for its failures. |
64
64
  | `sandboxTool(options)`, `runInSandbox(code, input, options)` | The `run_js` sandbox. `runInSandbox`'s `bridge` gives the code `tools`. |
65
65
  | `askUserTool()` | The `ask_user` tool. |
66
+ | `webTools(platform, { onCost?, signal? })`, `WEB_TOOL_NAMES` | The platform's `web_search` and `web_fetch` as tools (what `webTools: true` adds). `platform` is a provider's `platformTools` (`PlatformTools`: `list`, `call`). |
66
67
  | `normalizeResult(value)` | How a tool's return value becomes the model's result. |
67
68
  | `validateSchema(schema, value)` → `string[]` | The JSON Schema check used on arguments (the errors, empty when valid). |
68
69
  | types | `Tool`, `ToolDefinition`, `ToolContext`, `ToolConfirm`, `ToolResultValue`, `ToolStatus`, `JSONSchema`, `FileToolsOptions`, `FileGuard`, `MCPConnection`, `MCPOptions`, `MCPToolInfo` |
package/docs/tools.md CHANGED
@@ -226,6 +226,18 @@ What it handles: the session id the server gives, answers that come as JSON or a
226
226
 
227
227
  In a browser the server must allow your page's origin (CORS) and expose the `Mcp-Session-Id` header. OAuth sign-in and local (stdio) servers are not supported: get the token yourself and pass it.
228
228
 
229
+ ## Web search and reading pages
230
+
231
+ `webTools: true` gives the model the platform's `web_search` (results with title, URL, age and snippet) and `web_fetch` (a page's title and main content as text, links kept). They come from the provider: the RunApps client (SDK 0.19+) has them, other providers do not (`agent.webToolsAvailable`). The platform runs them and charges the user per call ($0.005 a search, $0.0005 a page; a failed call is free), and their descriptions come from it, cached by the SDK. They are offered beside your own tools, so a turn can search, read, and then call yours; their cost is added to `agent.usage.total_cost`. The system prompt gets a few lines on when to use them and to cite the links.
232
+
233
+ ```ts
234
+ const agent = createAgent(client, { tools: myTools, webTools: true });
235
+ agent.configure({ webTools: false }); // off from the next turn
236
+ createAgent(client, { webTools: () => settings.web }); // read every turn
237
+ ```
238
+
239
+ In `renderChat` the globe in the composer's toolbar switches them for the user (kept per app); `webSearch: false` hides it. The calls show as "Searching the web …" / "Reading …" lines. `webTools(platform, { onCost })` returns the two tools on their own, for an agent of your own.
240
+
229
241
  ## Built-in tools
230
242
 
231
243
  | Tool | | Option |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runappsai/agent",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "Agent harness: the model ↔ tool loop with a workspace, skills, sessions, compaction, a sandbox and a chat UI. Bring any OpenAI-compatible model provider (RunApps included); no runtime dependencies.",
6
6
  "license": "MIT",