0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/examples/agent-builder/tsconfig.node.json
Marvin Frachet 271d8917e4
feat(client-js,playground): port magnificent-marquess frontend stack (#17105)
## What

Ports the scoped frontend stack from `yj/magnificent-marquess` onto
`rain-purpose` as one reviewable PR, while preserving the newer
client-tools-on-signals (#16540) and Agent Builder view/edit pages
(#17104) work that already landed on `rain-purpose`. Also brings over
`examples/agent-builder/` for end-to-end smoke testing.

## Scope

**`@mastra/client-js`**
- New `ToolProvider` resource + unit tests
- `getModelPolicy` accessor on the root client
- Regenerated route types

**`@internal/playground`**
- **Auth**: `route-permissions` module, `RoutePermissionGuard`, login
layout, `ImpersonationBanner`, `RoleImpersonationProvider`, expanded
user-menu
- **Agent Builder routing**: agents / skills / infrastructure / favorite
/ library + create/edit/view all wired in `App.tsx`,
`AgentBuilderRootLayout`, `RoutePermissionGuard` around the app outlet,
`RoleImpersonationProvider` wrapping `PostHogProvider`,
`StudioIndexRedirect` replacing the `/agents` home redirect
- **Agents**: composer/model-switcher updates, browser-thumbnail/panel
`hideSidebar` plumbing, channels/CMS sidebar tweaks, new
`useUpdateSkill` MSW test
- **LLM**: models/providers/provider-logo updates
- **Misc**: `useRestoreFocus` hook, `studio-index-redirect`, nav-items
entries, tsconfig path tweak, e2e auth login-flow + kitchen-sink fixture
updates

**`examples/agent-builder`**
- New example app for smoke testing the Agent Builder routes locally

## Preserved from rain-purpose (explicitly NOT overwritten)

- `client-sdks/client-js/src/resources/agent.{ts,test.ts}`
- `client-sdks/react/src/agent/hooks.ts`, `package.json`,
`vitest.config.ts`, `hooks.test.ts`
- `packages/playground/src/services/mastra-runtime-provider.tsx`
-
`packages/playground/src/pages/agent-builder/agents/__tests__/{view,edit}.test.tsx`
- `packages/playground/src/domains/builder.ts` (yj #17072 deletion
skipped)

## Test plan

- `pnpm --filter ./client-sdks/client-js test`: **491/491 passing**
- New playground MSW + login-page tests: **13/13 passing**
- `pnpm --filter ./packages/playground exec tsc -p tsconfig.app.json
--noEmit`: same 46 pre-existing errors as `rain-purpose` HEAD; **zero
new errors introduced**
- Smoke test locally with `examples/agent-builder` to validate the new
routes, route-permission guard, and role-impersonation banner


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5

This PR brings a sophisticated frontend system from another branch into
the main codebase, adding support for role-based access controls,
authentication, and an improved Agent Builder interface. It's like
moving a fully furnished house into a new location while keeping all the
original furniture that was already there.

---

## Overview

Ports the `yj/magnificent-marquess` frontend stack onto `rain-purpose`,
integrating route-based permission controls, role impersonation,
enhanced authentication flows, and Agent Builder routing while
preserving existing `client-tools-on-signals` and Agent Builder
view/edit functionality. Includes a new `examples/agent-builder` app for
local smoke testing.

## `@mastra/client-js`

- **ToolProvider resource**: New resource type with unit tests
- **getModelPolicy accessor**: Added to root client for admin model
policy access
- **Route types**: Regenerated for new endpoints

## `@internal/playground`

### Authentication & Permissions
- **route-permissions module**: Centralized registry mapping Studio
routes to required permissions with utilities for permission resolution
and access determination
- **RoutePermissionGuard**: New component gating route access based on
user permissions, with deterministic redirects to `/agents` for viewers
without `tools:read`
- **Role impersonation**: `RoleImpersonationProvider`,
`useRoleImpersonation` hook, and `ImpersonationBanner` component
enabling admins to preview the app as different roles
- **LoginLayout component**: Shared visual shell for auth pages
- **Login flow tests**: E2E tests for unauthenticated redirects with
credential submission and auth-disabled routes; parity tests for
login/signup UI across auth capability modes

### Agent Builder Routing
- **Route wiring**: Integrated
agents/skills/infrastructure/favorite/library routes with
create/edit/view flows in `App.tsx` and `AgentBuilderRootLayout`
- **Layout guards**: Wrapped app outlet with `RoutePermissionGuard` and
`PostHogProvider` with `RoleImpersonationProvider`
- **Home redirect**: Replaced `/agents` redirect with
`StudioIndexRedirect` for permission-aware home routing

### Agent Builder & Agents UI
- **Model policy integration**: Composer and model-switcher components
now respect admin model policies, showing "locked by admin" chips and
stale-model warnings
- **Browser sidebar control**: Added `hideSidebar` prop plumbing through
`AgentChatPanelChat` → `BrowserThumbnailSlot` → `BrowserThumbnail`
- **Skill editing**: `SkillEditDialog` refactored to support
view/edit/create modes with optional chat-driven field population,
file-tree editing for admins, and update mutations
- **CMS sidebar feature-gating**: Sections now filtered by builder
feature toggles
- **Browser view refactoring**: `BrowserViewPanel` simplified to use
`useRestoreFocus` hook and modal-only behavior
- **Workspace selector**: Now conditionally rendered only when workspace
options are available

### LLM & Providers
- **Model/provider filtering**: Updated to incorporate builder admin
policies via `useBuilderFilteredModels`/`useBuilderFilteredProviders`
- **Provider logo styling**: Added optional `style` prop for custom CSS
properties

### Hooks & Utilities
- **useRestoreFocus**: New hook capturing and restoring focus when modal
opens/closes
- **useCanCreateAgent**: Moved to `agent-builder` domain for Agent
Builder context
- **useUpdateSkill**: MSW tests added for sparse PATCH request
validation
- **useStoredAgents**: Added model-policy error handling and cache
invalidation for builder-settings

### Navigation & Layout
- **Nav items refactoring**: Removed per-item permission fields;
permission checks now centralized via `route-permissions`
- **User menu expansion**: Added role-preview section with
role-switching controls and visual active states
- **ImpersonationBanner**: Displayed in both AppSidebar and
AgentBuilderSidebar when impersonation is active
- **useDefaultVisibility hook**: New utility for visibility state
management
- **Auth capabilities**: Added `availableRoles` field to
`AuthenticatedCapabilities` for admin role-switching

### Configuration & Dev
- **Dev script update**: `dev` script now runs Vite with
`MASTRA_AUTO_DETECT_URL=true`
- **Playwright auth tests**: Updated viewer-role E2E test to wait for
deterministic redirects
- **TypeScript**: Added kitchen-sink `MastraEditor` builder
configuration with tools and avatar-upload features
- **CSS**: Added `@keyframes shimmer-text` animation for text shimmer
effects

## examples/agent-builder

New example app for local Agent Builder smoke testing with:
- **Mastra setup**: Configured with LibSQL storage, WorkOS
authentication, RBAC provider with role-to-permissions mapping, Slack
provider, and Stagehand browser support
- **Agents**: `weatherAgent` with OpenAI `gpt-4o-mini` model
- **Tools**: `weatherInfo`, `weatherTool`, `diceRoll`, `coinFlip`,
`randomQuote` with Zod schemas
- **Workflows**: `greetWorkflow` demonstrating step composition and Zod
validation
- **Workspace**: E2B sandbox with Git environment variable support
- **Configuration**: Role-based builder with feature toggles, browser
workspace via Stagehand, Composio tool provider, Swagger API docs, and
observability with cloud exporters
- **Dev setup**: pnpm-based with local workspace links to `@mastra/*`
packages, MSW mocking, and `mastra:dev`/`mastra:build` commands

## Testing

- **client-js tests**: 491/491 passing
- **Playground tests**: 13/13 passing (new MSW + login-page tests)
- **TypeScript**: 46 pre-existing errors, zero new errors
- **Manual testing**: Examples/agent-builder smoke tests for routes,
guards, and impersonation banner

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/mastra-ai/mastra/pull/17105?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Mastra Code (anthropic/claude-opus-4-7) <noreply@mastra.ai>
2026-05-27 02:24:04 +02:00

12 lines
279 B