tidewave 0.3.0 → 0.5.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/README.md CHANGED
@@ -1,129 +1,222 @@
1
1
  # Tidewave
2
2
 
3
+ > Tidewave Web for Next.js and React+Vite is currently in alpha testing!
4
+
3
5
  Tidewave is the coding agent for full-stack web app development.
4
6
  [See our website](https://tidewave.ai) for more information.
5
7
 
6
- Our current release connects your editor's assistant to your web framework
7
- runtime via [MCP](https://modelcontextprotocol.io/). Support for Tidewave Web
8
- will come in future releases.
8
+ If you are using Next.js or you have a React + Vite frontend, talking either to
9
+ a backend as a service (such as Supabase) or a third-party framework, you are in
10
+ the right place!
9
11
 
10
- ## Usage
12
+ If you are using React with Django, FastAPI, Flask, Phoenix, or Rails,
13
+ [follow the steps here instead](http://hexdocs.pm/tidewave/react.html).
11
14
 
12
- ### Standalone MCP
15
+ This project can also be used through the CLI or as a standalone Model Context
16
+ Protocol (MCP) server for your editors.
13
17
 
14
- Tidewave's MCP server gives your editor and coding agents access to the
15
- documentation, type annotations, and source file locations of the packages being
16
- currently used by your project, without relying on external systems.
18
+ ## Installation
17
19
 
18
- Simply configure your editor to run `tidewave` in the same directory as your
19
- `package.json` as a STDIO MCP Server:
20
+ ### Next.js
20
21
 
21
- ```bash
22
- npx tidewave mcp
23
- # or with Bun
24
- bunx tidewave mcp
25
- # or with Deno
26
- deno run npm:tidewave mcp
27
- ```
22
+ If you are using Next.js, install Tidewave with:
28
23
 
29
- Available MCP options:
30
-
31
- - `--prefix path` - Specify the directory to find the `package.json` file
32
-
33
- ### HTTP MCP via Vite Plugin
24
+ ```sh
25
+ $ npm install -D tidewave
26
+ # or
27
+ $ yarn add -D tidewave
28
+ # or
29
+ $ pnpm add --save-dev tidewave
30
+ # or
31
+ $ bun add --dev tidewave
32
+ ```
34
33
 
35
- Tidewave also provides HTTP-based MCP access through a Vite plugin for
36
- development environments. Add the plugin to your `vite.config.js`:
34
+ Then create `pages/api/tidewave.ts` with:
37
35
 
38
- ```javascript
39
- import { defineConfig } from 'vite';
40
- import tidewave from 'tidewave/vite-plugin';
36
+ ```typescript
37
+ import type { NextApiRequest, NextApiResponse } from 'next';
38
+
39
+ export default async function handler(
40
+ req: NextApiRequest,
41
+ res: NextApiResponse,
42
+ ) {
43
+ if (process.env.NODE_ENV === 'development') {
44
+ const { tidewaveHandler } = await import('tidewave/next-js/handler');
45
+ const handler = await tidewaveHandler();
46
+ return handler(req, res);
47
+ } else {
48
+ res.status(404).end();
49
+ }
50
+ }
41
51
 
42
- export default defineConfig({
43
- plugins: [tidewave()],
44
- });
52
+ export const config = {
53
+ runtime: 'nodejs',
54
+ api: {
55
+ bodyParser: false, // Tidewave already parses the body internally
56
+ },
57
+ };
45
58
  ```
46
59
 
47
- This exposes MCP endpoints at `/tidewave/mcp` and `/tidewave/shell` during
48
- development.
60
+ _Note: this uses the **Pages Router**, however it works regardless of the router
61
+ type you use in your application._
49
62
 
50
- Configuration options:
63
+ If you are using Next.js 16+, then create (or modify) `proxy.ts` with:
51
64
 
52
- ```javascript
53
- tidewave({
54
- allowRemoteAccess: false, // Allow access from remote IPs
55
- allowedOrigins: ['localhost'], // Allowed origins: defaults to the Vite's host+port
56
- });
57
- ```
58
-
59
- ### HTTP MCP via Next.js Integration
65
+ ```typescript
66
+ import { NextRequest, NextResponse } from 'next/server';
60
67
 
61
- Tidewave provides seamless integration with Next.js through a handler function.
62
- Add the handler to your API routes **and** `middleware.ts`:
68
+ export function proxy(req: NextRequest): NextResponse {
69
+ if (req.nextUrl.pathname.startsWith('/tidewave')) {
70
+ return NextResponse.rewrite(new URL('/api/tidewave', req.url));
71
+ }
63
72
 
64
- > [!WARNING] Note that the below helper functions will only work on development
65
- > mode `NODE_ENV === 'development'` if the validation fails, an Error will be
66
- > thrown
73
+ // Here you could add your own logic or different middlewares.
74
+ return NextResponse.next();
75
+ }
76
+ ```
67
77
 
68
- **Pages Router** - Create `pages/api/tidewave/[...all].ts`:
78
+ For Next.js 15+ and earlier, create (or modify) `middleware.ts` with:
69
79
 
70
80
  ```typescript
71
- import { tidewaveHandler } from 'tidewave/next-js';
81
+ import { NextRequest, NextResponse } from 'next/server';
72
82
 
73
- export default await tidewaveHandler();
83
+ export function middleware(req: NextRequest): NextResponse {
84
+ if (req.nextUrl.pathname.startsWith('/tidewave')) {
85
+ return NextResponse.rewrite(new URL('/api/tidewave', req.url));
86
+ }
87
+
88
+ // Here you could add your own logic or different middlewares.
89
+ return NextResponse.next();
90
+ }
74
91
 
75
- // Next.js specific config
76
92
  export const config = {
77
- runtime: 'nodejs',
78
- api: {
79
- bodyParser: false, // tidewave already parses the body internally
80
- },
93
+ matcher: ['/tidewave/:path*'],
81
94
  };
82
95
  ```
83
96
 
84
- This exposes MCP endpoints at `/api/tidewave/mcp` and `/api/tidewave/shell`.
97
+ Finally, we expose your application's spans, events, and logs to Tidewave MCP.
98
+ First install the NodeSDK:
85
99
 
86
- Then create `middleware.ts` with:
100
+ ```sh
101
+ npm install @opentelemetry/sdk-node
102
+ ```
103
+
104
+ And then create (or modify) a custom `instrumentation.ts` file in the root
105
+ directory of the project (or inside `src` folder if using one):
87
106
 
88
107
  ```typescript
89
- import { tidewaveMiddleware } from 'tidewave/next-js';
108
+ // instrumentation.ts
109
+ import { NodeSDK } from '@opentelemetry/sdk-node';
110
+ import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
111
+ import type { LogRecordProcessor } from '@opentelemetry/sdk-logs';
112
+
113
+ export async function register() {
114
+ const runtime = process.env.NEXT_RUNTIME;
115
+ const env = process.env.NODE_ENV;
116
+
117
+ // Add your app own processes here existing configuration
118
+ const sdkConfig: {
119
+ spanProcessors: SpanProcessor[];
120
+ logRecordProcessors: LogRecordProcessor[];
121
+ } = {
122
+ spanProcessors: [],
123
+ logRecordProcessors: [],
124
+ };
125
+
126
+ // Conditionally add Tidewave processors in development
127
+ if (runtime === 'nodejs' && env === 'development') {
128
+ const { TidewaveSpanProcessor, TidewaveLogRecordProcessor } = await import(
129
+ 'tidewave/next-js/instrumentation'
130
+ );
131
+
132
+ sdkConfig.spanProcessors.push(new TidewaveSpanProcessor());
133
+ sdkConfig.logRecordProcessors.push(new TidewaveLogRecordProcessor());
134
+ }
135
+
136
+ const sdk = new NodeSDK(sdkConfig);
137
+ sdk.start();
138
+ }
139
+ ```
90
140
 
91
- export const middleware = tidewaveMiddleware();
141
+ Now make sure
142
+ [Tidewave is installed](https://hexdocs.pm/tidewave/installation.html) and you
143
+ are ready to connect Tidewave to your app.
92
144
 
93
- export const config = {
94
- matcher: '/tidewave/(.*)',
95
- };
145
+ ### React + Vite
146
+
147
+ If you are building a front-end application, using a backend as a service, such
148
+ as Supabase, or a non-officially supported web framework, we recommend using our
149
+ React + Vite integration.
150
+
151
+ Install it with:
152
+
153
+ ```sh
154
+ $ npm install -D tidewave
155
+ # or
156
+ $ yarn add -D tidewave
157
+ # or
158
+ $ pnpm add --save-dev tidewave
159
+ # or
160
+ $ bun add --dev tidewave
96
161
  ```
97
162
 
98
- In case you already have an existing `middleware.ts`:
163
+ Then configure your `vite.config.js` (also works for `.ts` and `.mjs`):
99
164
 
100
- ```typescript
101
- import { tidewaveMiddleware } from 'tidewave/next-js';
102
-
103
- const withTidewave = tidewaveMiddleware();
104
-
105
- export function middleware(req: NextRequest): Promise<NextResponse> {
106
- // This will return a unchanged NextResponse.next()
107
- // if path doesn't match with `/tidewave`
108
- // if does match it will rewrite to `/api/tidewave` instead
109
- withTidewave(req, (req: NextRequest) => {
110
- // your own logic
111
- return NextResponse.json({ message: 'hello, world!' });
112
- });
113
- }
165
+ ```javascript
166
+ import { defineConfig } from 'vite';
167
+ import tidewave from 'tidewave/vite-plugin';
114
168
 
115
- export const config = {
116
- matcher: [
117
- '/tidewave/(.*)', // tidewave specific matcher
118
- '/your/route/', // your specific matcher
119
- ],
120
- };
169
+ export default defineConfig({
170
+ plugins: [tidewave()],
171
+ });
172
+ ```
173
+
174
+ Now make sure
175
+ [Tidewave is installed](https://hexdocs.pm/tidewave/installation.html) and you
176
+ are ready to connect Tidewave to your app.
177
+
178
+ If you are using Supabase or similar, you can prompt Tidewave to use the
179
+ `supabase` CLI so it has complete access to your database. For non-officially
180
+ supported web frameworks, our React + Vite integration allows Tidewave Web to
181
+ perform changes on the front-end, and the agent will be able to modify your
182
+ backend code as usual, but some functionality (such as accessing logs, doing
183
+ database calls, etc) won't be available.
184
+
185
+ ### Configuration
186
+
187
+ Next.js' `tidewaveHandler` and Vite's `tidewave` accept the configuration
188
+ options below:
189
+
190
+ - `allow_remote_access:` allow remote connections when true (default false)
191
+ - `allowed_origins:` defaults to the current host/port
192
+ - `team`: enable Tidewave Web for teams
193
+
194
+ ## CLI
195
+
196
+ Tidewave.js also comes with a CLI for developers who want to use it as a
197
+ standalone MCP or query its functionality directly. Note this functionality is
198
+ separate from Tidewave Web.
199
+
200
+ ### STDIO MCP
201
+
202
+ Configure your editor to run `tidewave` in the same directory as your
203
+ `package.json` as a STDIO MCP Server:
204
+
205
+ ```bash
206
+ npx tidewave mcp
207
+ # or with Bun
208
+ bunx tidewave mcp
209
+ # or with Deno
210
+ deno run npm:tidewave mcp
121
211
  ```
122
212
 
123
- ### CLI Usage
213
+ Available options:
214
+
215
+ - `--prefix path` - Specify the directory to find the `package.json` file
216
+
217
+ ### Get docs / get source
124
218
 
125
- Tidewave also provides the MCP features over a CLI tool. Use it directly via
126
- npx/bunx/deno:
219
+ Fetch docs or retrieve the source location for classes, types, methods, etc:
127
220
 
128
221
  ```bash
129
222
  # Extract documentation for a symbol
@@ -149,14 +242,6 @@ npx tidewave source ./src/utils:formatDate
149
242
  npx tidewave source typescript:createProgram
150
243
  ```
151
244
 
152
- ### Runtime Support
153
-
154
- Tidewave JavaScript supports multiple JavaScript runtimes:
155
-
156
- - **Node.js** - Full support with npm/npx
157
- - **Bun** - Native support with bunx
158
- - **Deno** - Support via npm: protocol
159
-
160
245
  ## Contributing
161
246
 
162
247
  ```bash