@dudko.dev/agent 0.0.55 → 0.0.57

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.
package/README.md CHANGED
@@ -140,7 +140,7 @@ Pass an event handler as the second argument to `createAgent`, or per run via `o
140
140
  | `user.question-asked` / `user.question-answered` | The model asked the person a question ([`askUser`](#asking-the-user-a-question-with-choices)) and `onQuestion` is being called (`id`, `question`, `options: { label, description? }[]`, `multiple`, `allowOther`, `step?`, `subagent?` - the model's text, cleaned) / how it ended (`id`, `action: 'choice' \| 'other' \| 'declined' \| 'timeout' \| 'stopped'`, `automatic`, `choice?` - the labels picked -, `reason?: 'handler-error' \| 'invalid-answer' \| 'cannot-park'`). Never the person's own words. With the journal the id is the id of the item a [park](#parking-a-run-a-persons-answer-or-a-result-from-outside) on it would have; a question the run parks on is answered in the attempt that resumes it. |
141
141
  | `mcp.elicitation-requested` / `mcp.elicitation-answered` | An MCP server asked the user for input during a tool call and `onElicitation` is being called (`id`, `server`, `tool`, `mode`, `message`, `requestedSchema?`, `url?`, `step?`, `subagent?` - the server's text, cleaned and capped) / the question was settled (`action`, `automatic`, `reason?`, `fields?` - field names, never a value). See [MCP elicitation](#mcp-elicitation-a-server-asks-the-user). |
142
142
  | `egress.request` | A `web_fetch` request (or `web_search`'s call to its [search API](#search-finding-the-page-to-fetch)), allowed or refused by the [egress policy](#egress-what-the-model-may-fetch) (`url` is origin and path only, `allowed`, `status?`, `reason?`). |
143
- | `media.generated` | A [media tool](#media-images-speech-and-transcription) wrote a file: `kind: 'image' \| 'speech'`, `path` (absolute), `mediaType`, `bytes`, `model`, `step?`. The bytes are in the file, never in an event. |
143
+ | `media.generated` | A [media tool](#media-images-speech-and-transcription) wrote a file: `kind: 'image' \| 'speech'`, `path` (absolute), `mediaType`, `bytes`, `model`, `references?` (`{ used, count, paths }`: the reference pictures of a `generate_image` call, and whether they were sent), `step?`. The bytes are in the file, never in an event. |
144
144
  | `media.transcribed` | An audio file became text: `source: 'attachment' \| 'tool'`, `name`, `text` (what the model reads), `language?`, `durationInSeconds?`, `model`. |
145
145
  | `skill.learned` / `skill.forgotten` | The agent wrote, rewrote (`update`) or removed a lesson — see [Learning](#learning-lessons-that-outlive-the-task) (`name`, and for a lesson `description`, `chars`, `sources`). |
146
146
 
@@ -1306,7 +1306,7 @@ const agent = await createAgent({
1306
1306
 
1307
1307
  | `search` field | |
1308
1308
  |---|---|
1309
- | `engine` | Your own `(query, { maxResults, freshness, signal }) => Promise<{ title, url, snippet, date? }[]>` - any search API, or an index of yours. Its requests are yours, like a tool you pass; its results get the same cleaning, caps and filter. Exactly one of `engine` / `provider`. |
1309
+ | `engine` | Your own `(query, { maxResults, freshness, signal }) => Promise<{ title, url, snippet, date? }[]>` - any search API, or an index of yours. Its requests are yours, like a tool you pass; its results get the same cleaning, caps and filter. A search that runs a model (a provider's server-side search tool) may answer `{ results, usage?, summary?, note? }` instead: `usage` (`{ inputTokens, outputTokens, reasoningTokens? }`, whole counts) is a `usage` event of phase `'search'` - in `result.usage`, `agent.usage` and against `limits`, like the google provider's -, `summary` (the model's answer) reaches the model when no result has a snippet, and `note` (one line on what the results are, 300 characters at most) goes with every result list. Exactly one of `engine` / `provider`. |
1310
1310
  | `provider` | `'google'`: the built-in provider, see below. The only value. |
1311
1311
  | `apiKey` | `provider` only: a Gemini (Google AI Studio) API key. Sent in the `x-goog-api-key` header to that API only. |
1312
1312
  | `model` | `provider` only: the Gemini model that makes the grounding call. Default `'gemini-2.5-flash-lite'`. |
@@ -1409,7 +1409,7 @@ The engine's host does not go into `egress.allow`: the function's requests are y
1409
1409
 
1410
1410
  **Approval.** `web_fetch` is read-only only when the policy names the hosts, because an open GET can carry data anywhere. A search reaches exactly one host and you named it, so by the same rule it is **read-only** (`ask-writes` and `read-only` let it run). That host still *sees the query*: a model that was talked into it could put private data into one. If queries must not leave unreviewed, set `search: { ..., readOnly: false }` (it then asks like a write) or a rule: `toolApproval: { rules: { web_search: 'ask' } }`. It is an ordinary tool otherwise: `maxToolCalls`, the tool-output cap, `excludedTools` and tool search all apply, and a tool of your own named `web_search` wins.
1411
1411
 
1412
- **Events.** The provider's request emits the same `egress.request` as `web_fetch` (`url` is the API's origin and path - never the query string; `allowed`, `status` / `reason`), and its tokens a `usage` event of phase `'search'`. The query itself is in the ordinary `tool.call` event. A function `engine` makes its own requests and emits neither.
1412
+ **Events.** The provider's request emits the same `egress.request` as `web_fetch` (`url` is the API's origin and path - never the query string; `allowed`, `status` / `reason`), and its tokens a `usage` event of phase `'search'`. The query itself is in the ordinary `tool.call` event. A function `engine` makes its own requests: no `egress.request`, and a `usage` event of phase `'search'` only when it answered `usage`.
1413
1413
 
1414
1414
  What it is not: the providers' server-side search tools (Anthropic, OpenAI, Google). Those run inside the provider's API call, outside this policy; they are not wired here.
1415
1415
 
@@ -1444,7 +1444,8 @@ const { mediaCalls, imagesGenerated, transcriptionSeconds } = result.usage // 2,
1444
1444
 
1445
1445
  | `media` field | |
1446
1446
  | --- | --- |
1447
- | `imageModel` | Mounts `generate_image({ prompt, size?, aspectRatio? })`: one image per call. |
1447
+ | `imageModel` | Mounts `generate_image({ prompt, size?, aspectRatio?, images? })`: one image per call; `images` are reference pictures (below). |
1448
+ | `imageInputs` | Whether the image model takes reference pictures. Default: what the model object declares (`supportsFileInputs`; unknown counts as no). |
1448
1449
  | `speechModel` | Mounts `generate_speech({ text, voice?, language? })`. |
1449
1450
  | `transcriptionModel` | Mounts `transcribe_audio({ path })` and lets a run take audio in `run({ files })`. |
1450
1451
  | `maxCalls` | Media calls **one run** may make, attachments included. Default `8` (`MEDIA_DEFAULT_MAX_CALLS`); `0` = no cap. |
@@ -1460,6 +1461,12 @@ const { mediaCalls, imagesGenerated, transcriptionSeconds } = result.usage // 2,
1460
1461
  - **The tool names the file**: `image-<random>.png`, `speech-<random>.mp3`. The model has no argument that is a path or a name, an existing file is never replaced, and the final path is checked to be a direct child of the folder.
1461
1462
  - **`transcribe_audio` reads only inside the run's directory** (and `media.dir`): the path a tool returned for an audio file - an MCP tool's spilled audio, or a file `generate_speech` wrote. Both sides are resolved through symlinks before they are compared, so `../`, an absolute path elsewhere and a link that points out are all refused before a byte is read. The Node agent has no workspace of the user's files, which is why the tool reaches no further; the browser sibling's reads its virtual file system.
1462
1463
 
1464
+ **Reference pictures.** `generate_image({ prompt, images: ['me.jpg'] })` sends up to 4 pictures with the prompt - "a picture of me riding a dinosaur", "like this" - through the AI SDK's image prompt with images (`generateImage({ prompt: { text, images } })`: Gemini's image models get them in the request, OpenAI's GPT Image models through the edits endpoint, OpenRouter's as `input_references`). The result says what became of them: `references: { used: true, count: 1, paths: ['/…/me.jpg'] }`.
1465
+
1466
+ - **Which models take them**: `media.imageInputs`, else the model object's `supportsFileInputs` (the AI SDK's own field; `@ai-sdk/openai` says true for GPT Image, false for DALL·E 3; `@ai-sdk/google` true only for the Gemini ids it knows). Unknown counts as no. A model that takes none is **not refused**: the picture is made from the text alone, nothing is read, and the result says so plainly (`used: false` and a note: the picture was NOT sent, do not say it was made from the user's picture) - so the agent never claims otherwise. The tool's description says the same, and when to pass the person's picture.
1467
+ - **Where they are read: the same rule as `transcribe_audio`** - a file of the run's directory or of `media.dir`, resolved through symlinks on both sides; anything else is refused before a byte is read. Each must BE a PNG, JPEG or WebP by its bytes (not GIF, never SVG); at most 4 a call, 8 MiB each (by its size, before it is read) and 12 MiB together, the longer side at most 4096 px (read from the header; a file whose size cannot be read is refused). Nothing is downscaled here (no canvas in Node): the host makes a picture smaller. Everything is checked before the call is paid for.
1468
+ - The bytes are in no prompt, result or event (paths and a count). A call with pictures is one media call and one image, under the same `media.maxCalls`. The pictures go to the image model's provider with the prompt.
1469
+
1463
1470
  **Audio attachments.** `run({ input, files: [{ data, name?, mediaType? }] })` takes audio as bytes, base64 or a data URL. Each file is transcribed **once**, before planning, and its text is put under the input in a fenced block that says what it is:
1464
1471
 
1465
1472
  ```
@@ -1477,9 +1484,9 @@ The transcript is user-supplied **data**: it travels in the user message (system
1477
1484
 
1478
1485
  **Gates.** They are ordinary tools otherwise: `maxToolCalls`, `excludedTools`, tool search and the output cap apply, and a tool of your own with the same name wins. For [tool approval](#tool-approval-and-autopilot) all three are **writes** - they spend money and two of them write files - so `ask-writes` asks before each call and `read-only` refuses them. The run's abort signal ends a call in flight at once (also when the provider ignores it), and nothing is written.
1479
1486
 
1480
- **What leaves.** The image prompt, the text to speak and the audio are sent to the provider of that model; the tool descriptions tell the model so, and not to put secrets or private data into them. Do not enable a modality where that text may carry data that must stay inside.
1487
+ **What leaves.** The image prompt and its reference pictures, the text to speak and the audio are sent to the provider of that model; the tool descriptions tell the model so, and not to put secrets or private data into them. Do not enable a modality where that text may carry data that must stay inside.
1481
1488
 
1482
- Not verified against a real provider in this repository's tests: they run on mock models that implement the SDK's interfaces. Image *editing* (an image as input), streaming speech and live transcription are not wired.
1489
+ Not verified against a real provider in this repository's tests: they run on mock models that implement the SDK's interfaces. Masks (inpainting), streaming speech and live transcription are not wired.
1483
1490
 
1484
1491
  ## Learning: lessons that outlive the task
1485
1492
 
@@ -1855,7 +1862,7 @@ Consent is the host's job ([tool approval](#tool-approval-and-autopilot)) — th
1855
1862
  | `outputSanitizer` | Optional `(toolName, output) => unknown` hook to redact tool results before they reach the LLM. |
1856
1863
  | `inputSanitizer` | Optional `(toolName, input) => unknown` hook to redact LLM-generated tool args before they hit the MCP server **and** before they appear in `step.tool-call` events. **Must be idempotent** — applied at both the event boundary and the dispatch boundary. |
1857
1864
  | `outputSanitizer` ordering | The sanitizer runs on the **raw MCP `result.content`** (image/audio base64 still inline), **before** the agent spills binary parts to the sandbox. This favors privacy: a sanitizer that drops a sensitive image keeps the bytes out of the disk entirely. If you want post-spill sanitization (e.g. redact a path), do it in your tool wrapper instead. A result with `structuredContent` calls the sanitizer a second time with that object, so it cannot bypass redaction. |
1858
- | `media` | Off by default. `{ imageModel, speechModel, transcriptionModel, maxCalls, timeoutMs, dir, voice, speechFormat }`: each model mounts its tool (`generate_image`, `generate_speech`, `transcribe_audio` + audio attachments). Files on disk, never bytes in the context; calls counted in `usage.mediaCalls` (and the other media fields) and capped per run. See [Media](#media-images-speech-and-transcription). |
1865
+ | `media` | Off by default. `{ imageModel, imageInputs, speechModel, transcriptionModel, maxCalls, timeoutMs, dir, voice, speechFormat }`: each model mounts its tool (`generate_image` - with reference pictures for a model that takes them -, `generate_speech`, `transcribe_audio` + audio attachments). Files on disk, never bytes in the context; calls counted in `usage.mediaCalls` (and the other media fields) and capped per run. See [Media](#media-images-speech-and-transcription). |
1859
1866
  | `sandboxRoot` | Per-run sandbox subdirs are created at `<sandboxRoot>/<runId>/` for tools that spill binary content (images, audio, blob resources). Defaults to `<os.tmpdir()>/agent-sandbox`. |
1860
1867
  | `keepSandbox` | When `true`, the per-run directory is not removed after the run completes. Default `false`. |
1861
1868
  | `systemPrompt` | Appended to the planner, executor, replanner, and synthesizer system prompts so the same domain context (persona, language, tone) reaches every stage. |