vista README

项目的 README,来自 github.com/Mantitup-Org/vista。合并为一个 markdown 文件:README.md。

Vista.js

Vista.js is a React 19 framework for building apps the way you already think about Next.js: file-based routes under app/, React Server Components by default, and one CLI for dev / build / start.

Official site: https://vistajs.pages.dev · Repo: https://github.com/Mantitup-Org/vista

Which guide do you need?

I want to… Read this
Build a normal React site (pages, layouts, client UI) 1. React app
Add APIs, typed procedures, auth, middleware 2. Fullstack app
Chat with an LLM / tools / streaming UI 3. AI agents
Ground answers in my own docs (RAG) 4. RAG

Docs site mirrors these paths:


Quick start

npx create-vista-app@latest my-app
cd my-app
npm run dev

Open http://localhost:3003. Same scripts on every engine:

npm run dev      # develop
npm run build    # production build → .vista/
npm run start    # serve production

Optional flags:

npx create-vista-app@latest my-app --engine flashpack   # Rust-backed engine
npx create-vista-app@latest my-app --typed-api          # scaffold typed API files

Package name in apps: vista/.... In this monorepo the published name is @vistagenic/vista.


1. Build a normal React app

Vista apps are React apps. Folders under app/ are routes. Components are Server Components by default (less JS in the browser). Mark interactive pieces with 'use client'.

my-app/
├── app/
│   ├── root.tsx          # <html>, <body>, fonts, shared layout
│   ├── index.tsx         # home page → /
│   ├── about/page.tsx    # → /about
│   └── globals.css
├── components/           # shared UI
├── public/
└── vista.config.ts

Page (Server Component):

// app/about/page.tsx
export default function AboutPage() {
  return <h1>About</h1>;
}

Interactive UI (Client Component):

// components/counter.tsx
'use client';

import { useState } from 'react';

export function Counter() {
  const [n, setN] = useState(0);
  return <button onClick={() => setN(n + 1)}>{n}</button>;
}

Theme / fonts / links (same mental model as Next):

import { ThemeProvider, ThemeScript } from 'vista/theme';
import Link from 'vista/link';

That is enough for marketing sites, dashboards UI shells, and content apps. No API required.


2. Build a fullstack app

Add a backend in the same repo. Three layers you can mix:

A. File-based API routes (route.ts)

Any app/**/route.ts is an HTTP endpoint:

// app/api/users/route.ts
export async function GET() {
  return Response.json({ users: [] });
}

export async function POST(request: Request) {
  const body = await request.json();
  return Response.json({ ok: true, body }, { status: 201 });
}

Dynamic params work like pages: app/api/users/[id]/route.ts → /api/users/42.

B. Typed API (vista/stack) — end-to-end types

vista g api-init
// app/api/typed.ts
import { vstack } from 'vista/stack';
import { createRootRouter } from './routers';

const v = vstack.init();
export const router = createRootRouter(v);

Call from a Server Component without HTTP:

import { vstack } from 'vista/stack';
import { router } from '@/app/api/typed';

const v = vstack.init();
const caller = v.createCaller(router, { ctx: {}, env: {} });
const health = await caller.health();

Or from the browser with createVistaClient from vista/stack/client.

C. Auth + middleware

vista g auth

That writes auth.ts, /signin, /account, fail-closed middleware.ts, and a SessionProvider wrapper. Credentials signIn POSTs; OAuth keeps callbackUrl.

import VistaAuth, { GitHub, Credentials } from 'vista/auth';

export const { handlers, auth, authMiddleware } = VistaAuth({
  pages: { signIn: '/signin' },
  providers: [GitHub({}), Credentials({ authorize: async () => null })],
});
// middleware.ts (generated)
import { authMiddleware } from './auth';

export default authMiddleware(({ auth, request }) => {
  const pathname = new URL(request.url).pathname;
  if (pathname.startsWith('/account') && !auth) return false;
  return true;
});

Set AUTH_SECRET in the environment before using credentials/OAuth.


3. Use AI agents

Agents live next to your UI. Generate one:

vista g agent support

Creates:

Define the agent:

import { agent, tool } from 'vista/ai';

export const supportAgent = agent({
  name: 'support',
  model: process.env.VISTA_AI_MODEL || 'openai:gpt-4o',
  systemPrompt: 'You are a helpful support agent.',
  tools: [
    tool({
      name: 'ping',
      description: 'Health check',
      execute: async () => ({ ok: true }),
    }),
  ],
  memory: true,
});

Stream from a route:

import { supportAgent } from '../../agents/support/agent';

export async function POST(req: Request) {
  const { prompt, messages, sessionId } = await req.json();
  return supportAgent.stream({ prompt, messages, sessionId }).toDataStreamResponse();
}

Consume in React:

'use client';
import { useAgent } from 'vista/ai/react';

export function Chat() {
  const { messages, input, setInput, handleSubmit, isLoading } = useAgent({
    api: '/api/agents/support',
  });
  // render messages + form…
}

Model strings (provider:model)

Provider Example Env
OpenAI openai:gpt-4o OPENAI_API_KEY
Anthropic anthropic:claude-3-5-sonnet ANTHROPIC_API_KEY
Gemini gemini:gemini-1.5-flash GEMINI_API_KEY
Ollama ollama:llama3 local Ollama
Groq groq:llama-3.1-8b-instant GROQ_API_KEY
NVIDIA NIM nvidia:meta/llama-3.1-8b-instruct NVIDIA_API_KEY or NIM_API_KEY
Tests mock:echo none

Override the default with VISTA_AI_MODEL=groq:llama-3.1-8b-instant.


4. Use RAG (retrieval-augmented generation)

RAG = store your docs as vectors (or keywords) → retrieve the best chunks → give them to the agent as a tool.

import {
  agent,
  InMemoryVectorStore,
  createRetrieverTool,
  embedText,
} from 'vista/ai';

const store = new InMemoryVectorStore();

// Index once (startup or build script)
store.addDocument({
  id: 'intro',
  text: 'Vista is a React framework with App Router and RSC.',
  vector: await embedText('Vista is a React framework with App Router and RSC.', {
    model: 'openai:text-embedding-3-small',
  }),
});

const search = createRetrieverTool({
  store,
  embed: (query) =>
    embedText(query, { model: 'openai:text-embedding-3-small' }),
  topK: 3,
});

export const docsAgent = agent({
  name: 'docs',
  model: 'groq:llama-3.1-8b-instant',
  systemPrompt: 'Answer only from search_knowledge_base results.',
  tools: [search],
  memory: true,
});

No embedding API yet? Omit embed — the retriever falls back to keyword search (what apps/vista-rag-demo does out of the box, no API key required).

Run the demo:

pnpm --filter vista-rag-demo dev
# or: cd apps/vista-rag-demo && npm run dev

Packages

Package Purpose
@vistagenic/vista Framework runtime, CLI, RSC/SSR, auth, AI, stack
create-vista-app Scaffold new apps
vista-native Internal Rust/NAPI bridge

Engines

Pick at scaffold time or set engine.variant in vista.config.ts. Commands stay the same.

Local monorepo development

pnpm install
npm --prefix packages/vista run build
pnpm test:integrity

After editing packages/vista/src, rebuild packages/vista/dist (committed).

Learn more

vista (Mantitup-Org/vista)

正在搜索数据库…

这是什么?Vista.js 是一个 React 19 Web 框架,采用 App Router 风格的文件约定、React Server Components 和流式 SSR,理念上与 Next.js 类似,但采用双引擎构建系统。
默认引擎和 Flashpack 引擎有什么不同吗?有区别。默认引擎是基于 webpack 的主 RSC/SSR 流水线,而 Flashpack 是备用的基于 Rust 的引擎,会把图和运行时状态持久化到 .flash 目录中。
怎么创建一个新的 Vista 应用?用 create-vista-app 包搭建项目,它会提示你选择默认引擎或 Flashpack 引擎以及一个包管理器;之后两种引擎使用相同的构建/开发命令。
运行 Vista 之前需要安装什么?需要 Node.js 20 或更高版本,monorepo 用 pnpm 管理,并且 Flashpack 引擎依赖一个编译好的 Rust/NAPI 原生绑定(vista-native)。
Vista 的所有功能都能用于生产环境吗?通过 vista/stack 暴露的类型化 API 明确标注为实验性,而且 Flashpack 引擎的原生 Rust 绑定在其源码变更时需要单独重新编译。
默认引擎和 Flashpack 有什么区别?默认引擎使用基于 webpack 的 RSC/SSR 流水线,而 Flashpack 是基于 Rust 的引擎,会把图和运行时状态持久化到 .flash 目录中,用于 dev、build 和 start。
独立的 .vista 输出包含什么?它打包了清单、文件追踪数据、PPR shell 产物和运行时元数据,使构建可以作为独立输出运行。
Vista 提供哪些缓存 API?它内置了 Next.js 风格的缓存原语,包括 unstable_cache、revalidateTag、revalidatePath、cacheTag 和 cacheLife。
为什么这个仓库包含一个 Rust crate?vista-native 是一个内部 Rust/NAPI 桥接,用于支撑 Flashpack 引擎的原生绑定,从 crates/vista-napi 构建。
有哪些类似的项目?fresh, vue, ice, qiankun, react-router, nuxt, nx, taro
大小
10.6 MB
星标
2.3K
时长
2个月
提交 · 90 天