@mastra/libsql 1.11.1-alpha.0 → 1.12.0-alpha.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 1.12.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added the `tool_provider_connections` storage domain. Stored agents can now persist per-agent ToolProvider config that round-trips on read/write/create. Runtime connection resolution (per-author, shared, caller-supplied) ships in a follow-up PR. ([#17247](https://github.com/mastra-ai/mastra/pull/17247))
8
+
9
+ **What you can do**
10
+ - Pin a connection on a stored agent's config and have it round-trip on read/write/create.
11
+ - Persist multiple connections per toolkit so a follow-up runtime PR can fan-out to the right one at execution time.
12
+
13
+ **Example**
14
+
15
+ ```ts
16
+ import { LibSQLStore } from '@mastra/libsql';
17
+
18
+ const storage = new LibSQLStore({ url: process.env.DATABASE_URL });
19
+
20
+ // Persist an OAuth connection that an agent can pin later
21
+ await storage.toolProviders.upsertConnection({
22
+ authorId: 'user-123',
23
+ providerId: 'composio',
24
+ connectionId: 'auth_abc',
25
+ toolkit: 'gmail',
26
+ label: 'Work inbox',
27
+ scope: 'per-author',
28
+ });
29
+
30
+ // List a user's own connections (admin can omit authorId to list across users)
31
+ const { items } = await storage.toolProviders.listConnectionsByAuthor({
32
+ authorId: 'user-123',
33
+ providerId: 'composio',
34
+ });
35
+ ```
36
+
37
+ Additive — existing stored agents continue to work unchanged. The runtime that consumes this domain ships in a follow-up PR.
38
+
39
+ PR 1 of 3 split from #17224.
40
+
41
+ ### Patch Changes
42
+
43
+ - Added a public `close()` method to `LibSQLStore` that releases SQLite file handles and cleans up the WAL/shm sidecar files. Previously these handles stayed open until the process exited, which on Windows caused `EBUSY` errors when removing the storage directory after shutdown. `Mastra.shutdown()` now calls `close()` automatically, so you no longer need to reach into private fields. ([#17306](https://github.com/mastra-ai/mastra/pull/17306))
44
+
45
+ ```typescript
46
+ const storage = new LibSQLStore({ id: 'my-store', url: 'file:./dev.db' });
47
+
48
+ // Release all file handles, including WAL/shm sidecar files
49
+ await storage.close();
50
+
51
+ // Now safe to remove the storage directory on all platforms, including Windows
52
+ await fs.rm('./dev.db', { recursive: true, force: true });
53
+ ```
54
+
55
+ - Updated dependencies [[`8ace89d`](https://github.com/mastra-ai/mastra/commit/8ace89df77f762e622d3b9f7f65ad7524350d050), [`fa63872`](https://github.com/mastra-ai/mastra/commit/fa6387280954e6b667bec5714b55ba082bc627ff), [`f07b646`](https://github.com/mastra-ai/mastra/commit/f07b64604ab7d25391179790b7fd4823df9e2dff), [`d8838ae`](https://github.com/mastra-ai/mastra/commit/d8838ae80b69780361693d27098f7f6684af12fe), [`40f9297`](https://github.com/mastra-ai/mastra/commit/40f9297003b921c62373d3e8d3a4bda76c9f6de3), [`0f0d1ba`](https://github.com/mastra-ai/mastra/commit/0f0d1ba67bfcb2204e571401662f1eceefc03357), [`8c31bcd`](https://github.com/mastra-ai/mastra/commit/8c31bcdb00e597880d5939b1b7d7566fbe5dacae), [`95b14cd`](https://github.com/mastra-ai/mastra/commit/95b14cdd820e86d97ac05fe568424c513a252e31), [`aa36be2`](https://github.com/mastra-ai/mastra/commit/aa36be23aa513b7dc53cb8ca16b7fab8f20e43ad), [`212c635`](https://github.com/mastra-ai/mastra/commit/212c635203e61d036ab41db8ff86c3893dc795b3), [`d8838ae`](https://github.com/mastra-ai/mastra/commit/d8838ae80b69780361693d27098f7f6684af12fe), [`9aa5a73`](https://github.com/mastra-ai/mastra/commit/9aa5a73e7e110f6e9365eec69364a33d5f03bb56), [`f73c789`](https://github.com/mastra-ai/mastra/commit/f73c789e8ef21561580395d2c410119cab5848c8), [`8bd16da`](https://github.com/mastra-ai/mastra/commit/8bd16da73a4cb874d739373643dbd6a6e7f88684), [`c8630f8`](https://github.com/mastra-ai/mastra/commit/c8630f80d4f40cb5d22e60ab162b618b1907167a), [`47f71dc`](https://github.com/mastra-ai/mastra/commit/47f71dc6fbcbd12d71e21a979e676e20a02bd77d), [`50ceae2`](https://github.com/mastra-ai/mastra/commit/50ceae270878e2f8fb2b2c6c2faab09df0007c8a), [`8cdde58`](https://github.com/mastra-ai/mastra/commit/8cdde5875bbba6702d9df226f2b20232b8d75d6c), [`847ff1e`](https://github.com/mastra-ai/mastra/commit/847ff1e0d94368d94b2e173e4e0908e115568ef3), [`259d409`](https://github.com/mastra-ai/mastra/commit/259d409a514174299dbde1ff5e1121209b3ba850), [`9e16c68`](https://github.com/mastra-ai/mastra/commit/9e16c6818b6485ccb43df28aba6f3a2219d28662), [`cefca33`](https://github.com/mastra-ai/mastra/commit/cefca33ae666e69810c935fedf95a929c173d1d7), [`d00e8c5`](https://github.com/mastra-ai/mastra/commit/d00e8c50daebe5bce5bf2f48bde39c86fc3d2fe4), [`36fa7e2`](https://github.com/mastra-ai/mastra/commit/36fa7e24d14e58a1eb46147097b32f583e5b8775), [`87e9774`](https://github.com/mastra-ai/mastra/commit/87e97741c1e493cd6d62f478eb810b49bda4d57c), [`65a72e7`](https://github.com/mastra-ai/mastra/commit/65a72e70c25eedea8ff985a6624b96be2850236b), [`0f77241`](https://github.com/mastra-ai/mastra/commit/0f7724108806703799a8ba80ad0f09414afd5066), [`92ff509`](https://github.com/mastra-ai/mastra/commit/92ff5098ef8a990438ca038077021a5f7541ec1d), [`3fce5e7`](https://github.com/mastra-ai/mastra/commit/3fce5e70d011d289043e75003ef3336ed4aa43c3), [`a763592`](https://github.com/mastra-ai/mastra/commit/a763592c3db46963ef1011cfe16fe372816e775e), [`80c7737`](https://github.com/mastra-ai/mastra/commit/80c7737e32d7917b5f356957d67c169d01744fd3), [`3f1cf47`](https://github.com/mastra-ai/mastra/commit/3f1cf476f74c1e4cc2df908837e05853a5347e31)]:
56
+ - @mastra/core@1.38.0-alpha.3
57
+
58
+ ## 1.11.1
59
+
60
+ ### Patch Changes
61
+
62
+ - Fixed scheduler performance and correctness issues that could cause excessive Postgres CPU and noisy failed runs. ([#16805](https://github.com/mastra-ai/mastra/pull/16805))
63
+ - Added missing indexes on the schedules tables that the tick loop polls every 10 seconds: `(status, next_fire_at)` on `mastra_schedules` and `(schedule_id, actual_fire_at)` on `mastra_schedule_triggers`. Without these the scheduler performed a full sequential scan on every tick.
64
+ - The scheduler tick loop is now only started when at least one workflow declares a schedule (or `scheduler.enabled` is set explicitly), so deployments without scheduled workflows no longer poll the database at all.
65
+ - The scheduler now validates that a schedule's target workflow is still registered before firing it. Schedules whose target workflow has been removed from the Mastra config are skipped for a short grace window and then deleted, so stale rows stop producing failed workflow runs forever.
66
+ - The scheduler is now lazily initialized inside `startWorkers()`. Accessing `mastra.scheduler` before `startWorkers()` runs throws a descriptive error instead of returning a half-initialized instance.
67
+
68
+ - Updated dependencies [[`452036a`](https://github.com/mastra-ai/mastra/commit/452036a0d965b4f4c1efd93606e4f03b50b807a5), [`c272d50`](https://github.com/mastra-ai/mastra/commit/c272d50610a54496b6b6d92ccd4d37b333a2613a), [`27fd1b7`](https://github.com/mastra-ai/mastra/commit/27fd1b79ac62eb7694f92587eb7d1be05b59be01), [`5ba7253`](https://github.com/mastra-ai/mastra/commit/5ba7253745c85e8df8012a76d954c640ffa336f7), [`5556cc1`](https://github.com/mastra-ai/mastra/commit/5556cc1befec71518d84f826b3bfe3a079a9daf7), [`f73980d`](https://github.com/mastra-ai/mastra/commit/f73980d651eb5f7f1ab20582de4615a1b6f10fce), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`a702009`](https://github.com/mastra-ai/mastra/commit/a702009d3cfaa745120f501e21c783ed4d6a3072), [`9aee493`](https://github.com/mastra-ai/mastra/commit/9aee493ed6089b5133472623dcce49934bf2d509), [`d8692af`](https://github.com/mastra-ai/mastra/commit/d8692afa253028e39cdce2aafa0ac414071a762e), [`1a9cc60`](https://github.com/mastra-ai/mastra/commit/1a9cc6069f9910fc3d59e4953ac8cd95d89ad6f5), [`8cdb86c`](https://github.com/mastra-ai/mastra/commit/8cdb86ceed1137bc2768e147dce85a0692b9fb26), [`8534d79`](https://github.com/mastra-ai/mastra/commit/8534d791fa1cb70fe1c19e2604c4b63cc10dd051), [`eda90c5`](https://github.com/mastra-ai/mastra/commit/eda90c5bfd7de11805ecc9f4552716c895fbaf78), [`a935b0a`](https://github.com/mastra-ai/mastra/commit/a935b0a0977ae3f196b33ec7621f528069c82db0), [`9c88701`](https://github.com/mastra-ai/mastra/commit/9c8870195b41a38dc40b6ba2aa55eda04df8fa69), [`c78f8cd`](https://github.com/mastra-ai/mastra/commit/c78f8cd6222a86e6c60ae5210b6929ad5221b6fb), [`e146aad`](https://github.com/mastra-ai/mastra/commit/e146aadbba66c410ba0e74bac4c50135495cb8dd), [`ac79462`](https://github.com/mastra-ai/mastra/commit/ac79462b98f1062394c45093aa515b0766f27ee2), [`1a0ec78`](https://github.com/mastra-ai/mastra/commit/1a0ec789a26cae443744e9abbd62ed6ee676af39), [`e47bca7`](https://github.com/mastra-ai/mastra/commit/e47bca7b72866d3abd173b9f530ac4318113a8ff), [`afc004f`](https://github.com/mastra-ai/mastra/commit/afc004f5cc7e30697809e7021820b9f5881e6719), [`0031d0f`](https://github.com/mastra-ai/mastra/commit/0031d0f13831d7843ac5d498734a7d92862e2ce3), [`841a222`](https://github.com/mastra-ai/mastra/commit/841a222560d8c19238f8213713f30535cdd82284), [`64c1e0b`](https://github.com/mastra-ai/mastra/commit/64c1e0b35165c96b659818bd0177aa18794ef11f), [`40d83a9`](https://github.com/mastra-ai/mastra/commit/40d83a90d9be31a1b83e04649edb703eb7753e33), [`4e88dc6`](https://github.com/mastra-ai/mastra/commit/4e88dc6b89f154c0eae37221c8126be0c23c569f), [`19018f0`](https://github.com/mastra-ai/mastra/commit/19018f05722af74a5978781a7731a654b26f7f2a), [`19281c7`](https://github.com/mastra-ai/mastra/commit/19281c70424f757219782de16c2699743c5e04d0), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`d52b6fe`](https://github.com/mastra-ai/mastra/commit/d52b6fe1c56853eb38864baae0bbfa75cc739ccb), [`408be73`](https://github.com/mastra-ai/mastra/commit/408be73449dfab92b51eab8c6623b6c443debc25), [`359439b`](https://github.com/mastra-ai/mastra/commit/359439bb8c635e048176306828195f8297f50021), [`71a820b`](https://github.com/mastra-ai/mastra/commit/71a820b2353fa1406772c50760a3732058a8b337), [`1698f5e`](https://github.com/mastra-ai/mastra/commit/1698f5ec141d34f22a873efdb145ce3cdf848a5e)]:
69
+ - @mastra/core@1.36.0
70
+
3
71
  ## 1.11.1-alpha.0
4
72
 
5
73
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-libsql
3
3
  description: Documentation for @mastra/libsql. Use when working with @mastra/libsql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/libsql"
6
- version: "1.11.1-alpha.0"
6
+ version: "1.12.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -16,6 +16,8 @@ Read the individual reference documents for detailed explanations and code examp
16
16
 
17
17
  ### Docs
18
18
 
19
+ - [Deploying](references/docs-agent-builder-deploying.md) - Swap local Agent Builder primitives for cloud-backed storage, filesystems, sandboxes, an EE license, auth, and a public channel URL for production.
20
+ - [Agent Builder overview](references/docs-agent-builder-overview.md) - Let teammates create, configure, and operate Mastra agents from a browser, with admin-pinned defaults, RBAC, and channel integrations.
19
21
  - [Agent approval](references/docs-agents-agent-approval.md) - Learn how to require approvals, suspend tool execution, and automatically resume suspended tools while keeping humans in control of agent workflows.
20
22
  - [Agent networks](references/docs-agents-networks.md) - Coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
21
23
  - [Memory processors](references/docs-memory-memory-processors.md) - Learn how to use memory processors in Mastra to filter, trim, and transform messages before they're sent to the language model to manage context window limits.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.1-alpha.0",
2
+ "version": "1.12.0-alpha.0",
3
3
  "package": "@mastra/libsql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -0,0 +1,121 @@
1
+ # Deploying
2
+
3
+ > **Note:** The Agent Builder is part of the Mastra Enterprise Edition. Production deployments require a valid EE license. [Contact sales](https://mastra.ai/contact) for more information.
4
+
5
+ Production deployments swap the local primitives in the Quickstart for cloud-backed equivalents. The shape of the `Mastra` and `MastraEditor` config doesn't change — only the providers behind it.
6
+
7
+ ## What a production deployment needs
8
+
9
+ 1. **EE license** — a valid `MASTRA_EE_LICENSE` so the server will start with the Builder enabled.
10
+ 2. **Hosted storage** — a shared store for agents, skills, runs, and memory.
11
+ 3. **Shared workspace filesystem** — survives across instances; `local` is single-node only.
12
+ 4. **Cloud sandbox** — runs agent commands safely; `local` is unsafe in shared environments.
13
+ 5. **Auth and RBAC** — gates the Builder UI and `/agent-builder/*` routes.
14
+ 6. **Public base URL for channels** — Slack and other channel providers need a reachable URL.
15
+
16
+ ## EE license
17
+
18
+ Set `MASTRA_EE_LICENSE` in the deployment environment. The server refuses to start when `builder.enabled` is truthy without a valid license. Treat the license key as a secret.
19
+
20
+ ## Storage
21
+
22
+ Replace the file-backed LibSQL store with a hosted backend. LibSQL Cloud, PostgreSQL, and any other Mastra storage adapter all work.
23
+
24
+ ```typescript
25
+ import { Mastra } from '@mastra/core/mastra'
26
+ import { LibSQLStore } from '@mastra/libsql'
27
+
28
+ new Mastra({
29
+ storage: new LibSQLStore({
30
+ url: process.env.DATABASE_URL!,
31
+ authToken: process.env.DATABASE_AUTH_TOKEN,
32
+ }),
33
+ })
34
+ ```
35
+
36
+ ## Workspace filesystem and sandbox
37
+
38
+ `local` filesystem works only on the node that owns the directory. For multi-instance deployments, register cloud filesystem and sandbox providers on `MastraEditor` and reference them by id in the inline workspace config.
39
+
40
+ **npm**:
41
+
42
+ ```bash
43
+ npm install @mastra/s3 @mastra/e2b
44
+ ```
45
+
46
+ **pnpm**:
47
+
48
+ ```bash
49
+ pnpm add @mastra/s3 @mastra/e2b
50
+ ```
51
+
52
+ **Yarn**:
53
+
54
+ ```bash
55
+ yarn add @mastra/s3 @mastra/e2b
56
+ ```
57
+
58
+ **Bun**:
59
+
60
+ ```bash
61
+ bun add @mastra/s3 @mastra/e2b
62
+ ```
63
+
64
+ ```typescript
65
+ import { Mastra } from '@mastra/core/mastra'
66
+ import { MastraEditor } from '@mastra/editor'
67
+ import { s3FilesystemProvider } from '@mastra/s3'
68
+ import { e2bSandboxProvider } from '@mastra/e2b'
69
+
70
+ new Mastra({
71
+ editor: new MastraEditor({
72
+ filesystems: { [s3FilesystemProvider.id]: s3FilesystemProvider },
73
+ sandboxes: { [e2bSandboxProvider.id]: e2bSandboxProvider },
74
+ builder: {
75
+ enabled: true,
76
+ configuration: {
77
+ agent: {
78
+ workspace: {
79
+ type: 'inline',
80
+ config: {
81
+ name: 'builder-workspace',
82
+ filesystem: {
83
+ provider: s3FilesystemProvider.id,
84
+ config: {
85
+ bucket: process.env.S3_BUCKET!,
86
+ region: process.env.S3_REGION!,
87
+ },
88
+ },
89
+ sandbox: {
90
+ provider: e2bSandboxProvider.id,
91
+ config: { apiKey: process.env.E2B_API_KEY! },
92
+ },
93
+ },
94
+ },
95
+ },
96
+ },
97
+ },
98
+ }),
99
+ })
100
+ ```
101
+
102
+ `S3Filesystem` uses the default AWS credential chain (environment variables, `~/.aws` config, IAM roles, EC2 instance profile). For long-running deployments, use a credential provider function so credentials refresh automatically.
103
+
104
+ `DockerSandbox` and `VercelSandbox` are alternative cloud sandbox providers — pick whichever matches your runtime.
105
+
106
+ > **Warning:** A local sandbox can't run commands safely in a shared environment. Always register a cloud sandbox provider and reference it in the workspace config before deploying.
107
+
108
+ ## Auth and RBAC
109
+
110
+ A production deployment without authentication exposes the Builder to the public internet. Register a `Mastra.server.auth` provider (for example, WorkOS or your own provider) and a `Mastra.server.rbac` provider to gate access.
111
+
112
+ See [Access control](https://mastra.ai/docs/agent-builder/access-control) for the required role permissions and a WorkOS quickstart.
113
+
114
+ ## Public URL for channels
115
+
116
+ Slack needs to reach your server through a public URL. Pass `baseUrl` to `SlackProvider` with the deployed URL (no trailing slash). See [Channels](https://mastra.ai/docs/agent-builder/channels) for the full setup.
117
+
118
+ ## Related
119
+
120
+ - [Access control](https://mastra.ai/docs/agent-builder/access-control) — auth and RBAC setup.
121
+ - [Channels](https://mastra.ai/docs/agent-builder/channels) — Slack `baseUrl` and channel-specific setup.
@@ -0,0 +1,97 @@
1
+ # Agent Builder overview
2
+
3
+ > **Note:** The Agent Builder is part of the Mastra Enterprise Edition. Production deployments require a valid EE license. [Contact sales](https://mastra.ai/contact) for more information.
4
+
5
+ The Agent Builder lets you build, configure, and operate Mastra agents all within the UI. It runs inside your Mastra server, persists everything to `Mastra.storage`, and supports multi-tenant agent workflows with RBAC and channel integrations.
6
+
7
+ - [**Configuration**](https://mastra.ai/docs/agent-builder/configuration): Toggle UI sections and pin admin-controlled defaults for every new agent.
8
+ - [**Model policy**](https://mastra.ai/docs/agent-builder/model-policy): Restrict which providers and models the Builder exposes, and pin a default.
9
+ - [**Memory**](https://mastra.ai/docs/agent-builder/memory): Configure the default memory shape for every Builder-created agent.
10
+ - [**Access control**](https://mastra.ai/docs/agent-builder/access-control): Gate the Builder behind Mastra RBAC roles and permissions.
11
+ - [**Channels**](https://mastra.ai/docs/agent-builder/channels): Connect Builder-created agents to Slack and other channels.
12
+ - [**Skill registries**](https://mastra.ai/docs/agent-builder/skill-registries): Browse and install community skills from opt-in registries.
13
+ - [**Deploying**](https://mastra.ai/docs/agent-builder/deploying): Swap local primitives for cloud-backed storage, filesystems, and sandboxes.
14
+
15
+ For building agents entirely in code, see the [Agents overview](https://mastra.ai/docs/agents/overview). For editing code-defined agents through Studio, see the [Editor overview](https://mastra.ai/docs/editor/overview).
16
+
17
+ ## Get started
18
+
19
+ Install `@mastra/editor` alongside a storage adapter:
20
+
21
+ **npm**:
22
+
23
+ ```bash
24
+ npm install @mastra/editor @mastra/libsql
25
+ ```
26
+
27
+ **pnpm**:
28
+
29
+ ```bash
30
+ pnpm add @mastra/editor @mastra/libsql
31
+ ```
32
+
33
+ **Yarn**:
34
+
35
+ ```bash
36
+ yarn add @mastra/editor @mastra/libsql
37
+ ```
38
+
39
+ **Bun**:
40
+
41
+ ```bash
42
+ bun add @mastra/editor @mastra/libsql
43
+ ```
44
+
45
+ Wire the Agent Builder onto a `Mastra` instance:
46
+
47
+ ```typescript
48
+ import { Mastra } from '@mastra/core/mastra'
49
+ import { MastraEditor } from '@mastra/editor'
50
+ import { createBuilderAgent } from '@mastra/editor/ee'
51
+ import { LibSQLStore } from '@mastra/libsql'
52
+
53
+ export const mastra = new Mastra({
54
+ storage: new LibSQLStore({ url: 'file:./mastra.db' }),
55
+ agents: { builderAgent: createBuilderAgent() },
56
+ editor: new MastraEditor({
57
+ builder: {
58
+ enabled: true,
59
+ configuration: {
60
+ agent: {
61
+ memory: { observationalMemory: true },
62
+ },
63
+ },
64
+ },
65
+ }),
66
+ })
67
+ ```
68
+
69
+ Start the dev server:
70
+
71
+ ```bash
72
+ npx mastra dev
73
+ ```
74
+
75
+ The Agent Builder is mounted at `http://localhost:4111/agent-builder`.
76
+
77
+ ## Prerequisites
78
+
79
+ The Agent Builder requires:
80
+
81
+ - **Storage**: An `@mastra/core` storage adapter on the `Mastra` instance. Agents, memory, and workspace state all persist through `Mastra.storage`.
82
+ - **The Builder agent**: Register a Builder agent created with the `createBuilderAgent()` factory from `@mastra/editor/ee` on `Mastra.agents`. The chat-based editor invokes it through the same `Mastra.getAgent(id)` lookup as any other agent. Without this registration, the chat-based editor returns 404.
83
+ - **`OPENAI_API_KEY`**: The Builder agent created by `createBuilderAgent()` runs on an OpenAI model, so an `OPENAI_API_KEY` environment variable is required.
84
+
85
+ ## Disabling the Builder
86
+
87
+ Set `enabled: false` to keep the config in place but turn the surface off:
88
+
89
+ ```typescript
90
+ new MastraEditor({
91
+ builder: {
92
+ enabled: false,
93
+ },
94
+ })
95
+ ```
96
+
97
+ Omitting the `builder` field has the same effect.
@@ -86,6 +86,20 @@ for await (const chunk of stream.fullStream) {
86
86
  }
87
87
  ```
88
88
 
89
+ #### Conditional approval with a function
90
+
91
+ Instead of a boolean, `requireToolApproval` accepts a function that decides per tool call. It receives the `toolName`, the `args` the model passed, the `requestContext`, and the `workspace`. Return `true` to require approval for that call, or `false` to allow it. This lets you gate approval dynamically — for example, only for tools whose name matches a pattern:
92
+
93
+ ```typescript
94
+ const stream = await agent.stream('Clean up old records', {
95
+ requireToolApproval: ({ toolName }) => /^delete_/.test(toolName),
96
+ })
97
+ ```
98
+
99
+ A tool's own `requireApproval` setting still takes precedence: if a tool defines its own approval rule, that rule decides for that tool and the function above does not override it. If the function throws, the call requires approval (fail-safe).
100
+
101
+ > **Note:** Function-based `requireToolApproval` is only available on regular `stream()` / `generate()` calls. Durable agents and stored agents persist their options, and a function can't be serialized, so they accept only a boolean. If you pass a function in those contexts it falls back to requiring approval for every tool call.
102
+
89
103
  ### Runtime suspension with `suspend()`
90
104
 
91
105
  A tool can also pause _during_ its `execute` function by calling `suspend()`. This is useful when the tool starts running and then discovers it needs additional user input or confirmation before it can finish.
@@ -65,7 +65,7 @@ const memory = new Memory({
65
65
  export const collabAgent = new Agent({
66
66
  id: 'collab',
67
67
  name: 'CollabAgent',
68
- model: 'openai/gpt-5.4-mini',
68
+ model: '__OPENAI_MODEL_MINI__',
69
69
  memory,
70
70
  instructions: `
71
71
  You are a collaborative document assistant. Multiple users talk to you in the SAME thread.
@@ -247,7 +247,7 @@ const agent = new Agent({
247
247
  })
248
248
  ```
249
249
 
250
- The model router automatically handles API key detection from environment variables (`OPENAI_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`, `OPENROUTER_API_KEY`).
250
+ The model router automatically handles API key detection from environment variables (`OPENAI_API_KEY`, `GOOGLE_API_KEY`, `OPENROUTER_API_KEY`). Google models also fall back to `GOOGLE_GENERATIVE_AI_API_KEY`.
251
251
 
252
252
  ### Using AI SDK Packages
253
253
 
@@ -179,7 +179,7 @@ export const agent = new Agent({
179
179
  memory: new Memory({
180
180
  options: {
181
181
  generateTitle: {
182
- model: 'openai/gpt-5-mini',
182
+ model: '__OPENAI_MODEL_MINI__',
183
183
  instructions: 'Generate a 1 word title',
184
184
  },
185
185
  },
@@ -472,7 +472,10 @@ const initialResults = await pgVector.query({
472
472
  })
473
473
 
474
474
  // Create a relevance scorer
475
- const relevanceProvider = new MastraAgentRelevanceScorer('relevance-scorer', 'openai/gpt-5.4')
475
+ const relevanceProvider = new MastraAgentRelevanceScorer(
476
+ 'relevance-scorer',
477
+ 'openai/gpt-5.4',
478
+ )
476
479
 
477
480
  // Re-rank the results
478
481
  const rerankedResults = await rerank({