@mocklane/core 0.1.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/LICENSE +21 -0
- package/README.md +386 -0
- package/build/client/assets/entry.client-Cw45cONA.js +37 -0
- package/build/client/assets/home-CHNZ1EXV.js +178 -0
- package/build/client/assets/index-D9gteTdx.js +91 -0
- package/build/client/assets/jsx-runtime-BZbza59V.js +51 -0
- package/build/client/assets/manifest-f8a16862.js +1 -0
- package/build/client/assets/ort-wasm-simd-threaded.asyncify-DMmc6YqF.wasm +0 -0
- package/build/client/assets/root--WDECO_x.css +1 -0
- package/build/client/assets/root-CCK9sNPJ.js +1 -0
- package/build/client/assets/transformers.web-CjIQtwg9.js +41 -0
- package/build/client/index.html +13 -0
- package/dist/cli.js +318 -0
- package/dist/cli.js.map +7 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asis Paudel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
# Mocklane
|
|
2
|
+
|
|
3
|
+
Generate, edit, and serve mock HTTP responses with browser-local AI.
|
|
4
|
+
|
|
5
|
+
Mocklane turns a pasted data model and a plain-language request into a structured JSON HTTP response. Its CLI opens the browser workspace, serves generated mocks from a local API, and can proxy every unmatched request to an existing backend.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Generates complete HTTP response objects from models and prompts
|
|
10
|
+
- Runs generation locally with Transformers.js, WebLLM, or native browser AI
|
|
11
|
+
- Accepts TypeScript, Python/Pydantic, Go, Java, Prisma, SQL, OpenAPI/JSON schemas, and example JSON
|
|
12
|
+
- Validates edited output before saving it
|
|
13
|
+
- Copies and downloads generated JSON
|
|
14
|
+
- Serves mocks from `localhost:4000`
|
|
15
|
+
- Proxies unmatched requests to an optional upstream API
|
|
16
|
+
- Handles mock CORS headers and preflight requests
|
|
17
|
+
- Stores models in the browser cache after the first download
|
|
18
|
+
- Keeps mock data in memory and binds its servers to the local machine
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- Node.js 20 or newer
|
|
23
|
+
- A modern browser with WebGPU for Transformers.js and WebLLM
|
|
24
|
+
- Enough browser storage and memory for the selected local model
|
|
25
|
+
|
|
26
|
+
Native Browser AI is shown only when the browser exposes the `LanguageModel` API. The first Transformers.js or WebLLM load downloads model assets; later loads can reuse the browser cache.
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
Run Mocklane without installing it globally:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx mocklane
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For a global installation:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install --global mocklane
|
|
40
|
+
mocklane
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Mocklane starts two local servers and opens the browser workspace automatically:
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
Mocklane UI: http://localhost:4001
|
|
47
|
+
Mock API proxy: http://localhost:4000
|
|
48
|
+
Upstream server: none (standalone mode)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
In the browser:
|
|
52
|
+
|
|
53
|
+
1. Select an AI provider and model.
|
|
54
|
+
2. Load the model when the provider requires it.
|
|
55
|
+
3. Paste or edit the data structure under **Model / Structure**.
|
|
56
|
+
4. Describe the endpoint and response under **Prompt**.
|
|
57
|
+
5. Select **Generate**.
|
|
58
|
+
6. Review or edit the generated HTTP JSON.
|
|
59
|
+
7. Enter the endpoint path and select **Mock API**.
|
|
60
|
+
|
|
61
|
+
Call the active mock from any local client:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
curl http://localhost:4000/api/products
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Select **Unmock API** to remove it, or press `Ctrl+C` in the terminal to stop Mocklane.
|
|
68
|
+
|
|
69
|
+
## Generated Response Format
|
|
70
|
+
|
|
71
|
+
Mocklane generates a JSON object containing the complete HTTP response definition:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"method": "GET",
|
|
76
|
+
"path": "/api/products",
|
|
77
|
+
"status": 200,
|
|
78
|
+
"headers": {
|
|
79
|
+
"content-type": "application/json"
|
|
80
|
+
},
|
|
81
|
+
"body": [
|
|
82
|
+
{
|
|
83
|
+
"id": "1",
|
|
84
|
+
"name": "Example product"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The local mock server returns the value of `body` with the configured status and headers. Before registering the mock, the endpoint path can be changed in the field below the JSON output.
|
|
91
|
+
|
|
92
|
+
## AI Providers
|
|
93
|
+
|
|
94
|
+
### Transformers.js
|
|
95
|
+
|
|
96
|
+
The default provider uses WebGPU through Transformers.js. Available models are:
|
|
97
|
+
|
|
98
|
+
- `onnx-community/Qwen3-0.6B-ONNX` using `q4f16`
|
|
99
|
+
- `onnx-community/gemma-3-1b-it-ONNX-GQA` using `q4`
|
|
100
|
+
|
|
101
|
+
Mocklane displays model download progress and identifies whether the model is loading for the first time or from the browser cache.
|
|
102
|
+
|
|
103
|
+
### WebLLM
|
|
104
|
+
|
|
105
|
+
WebLLM uses:
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
Qwen2.5-0.5B-Instruct-q4f16_1-MLC
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The model runs through WebGPU and must be loaded before generation.
|
|
112
|
+
|
|
113
|
+
### Native Browser AI
|
|
114
|
+
|
|
115
|
+
When the browser provides `window.LanguageModel` or the legacy `window.ai.languageModel`, Mocklane can generate with the browser's native Gemini Nano runtime. Availability and model download behavior are controlled by the browser.
|
|
116
|
+
|
|
117
|
+
Mocklane does not send prompts to a hosted inference API. Model files may be downloaded from their model providers during initial setup, but response generation happens in the browser.
|
|
118
|
+
|
|
119
|
+
## Editing Output
|
|
120
|
+
|
|
121
|
+
The output toolbar supports:
|
|
122
|
+
|
|
123
|
+
- **Edit**: opens the generated response in the JSON editor
|
|
124
|
+
- **Save**: parses and formats the edited JSON
|
|
125
|
+
- **Cancel**: discards the current edits
|
|
126
|
+
- **Copy**: copies the response to the clipboard
|
|
127
|
+
- **Download**: saves the response as a `.json` file
|
|
128
|
+
|
|
129
|
+
Invalid JSON cannot be saved. Mocklane displays the parser error in the editor so the response can be corrected without losing the draft.
|
|
130
|
+
|
|
131
|
+
## Standalone Mock Server
|
|
132
|
+
|
|
133
|
+
Standalone mode is the default:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npx mocklane
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Registered routes return their configured mock responses. Unmatched routes return `404`:
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"error": "No Mocklane mock matches this route.",
|
|
144
|
+
"method": "GET",
|
|
145
|
+
"path": "/api/unknown"
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Mocks are matched by HTTP method and exact pathname. Query strings do not affect matching. Mock state is kept in memory and is cleared when the CLI exits.
|
|
150
|
+
|
|
151
|
+
## Proxy Mode
|
|
152
|
+
|
|
153
|
+
Use proxy mode when an application already has a backend and only selected routes should be mocked:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npx mocklane --target http://localhost:8000
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Point the application at `http://localhost:4000` instead of the upstream server:
|
|
160
|
+
|
|
161
|
+
```text
|
|
162
|
+
Application -> localhost:4000 -> Mocklane -> localhost:8000
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
- A matching method and pathname returns the registered mock.
|
|
166
|
+
- An unmatched request is forwarded to the upstream server.
|
|
167
|
+
- Request methods, headers, bodies, and query strings are forwarded.
|
|
168
|
+
- Upstream status codes, headers, and response bodies are passed back to the client.
|
|
169
|
+
|
|
170
|
+
For example, with only `GET /api/products` mocked:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
curl http://localhost:4000/api/products
|
|
174
|
+
curl http://localhost:4000/api/users
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The first request uses the mock. The second request is forwarded to `http://localhost:8000/api/users`.
|
|
178
|
+
|
|
179
|
+
## CLI Reference
|
|
180
|
+
|
|
181
|
+
```text
|
|
182
|
+
Usage:
|
|
183
|
+
mocklane [options]
|
|
184
|
+
|
|
185
|
+
Options:
|
|
186
|
+
--target <url> Optional upstream API URL for unmatched routes
|
|
187
|
+
--proxy-port <port> Mock/proxy port (default: 4000)
|
|
188
|
+
--ui-port <port> Mocklane UI port (default: 4001)
|
|
189
|
+
-h, --help Show CLI help
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Custom ports
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
npx mocklane --proxy-port 5000 --ui-port 5001
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Proxy with custom ports
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
npx mocklane \
|
|
202
|
+
--target http://localhost:8000 \
|
|
203
|
+
--proxy-port 5000 \
|
|
204
|
+
--ui-port 5001
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The proxy and UI ports must be different. Both servers bind to `127.0.0.1` and are not exposed to the local network.
|
|
208
|
+
|
|
209
|
+
## Local Control API
|
|
210
|
+
|
|
211
|
+
The browser workspace registers mocks through a control API on the UI port.
|
|
212
|
+
|
|
213
|
+
### Health
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
curl http://localhost:4001/__mocklane/health
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"ready": true,
|
|
222
|
+
"proxyPort": 4000,
|
|
223
|
+
"mocks": 0
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### List mocks
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
curl http://localhost:4001/__mocklane/mocks
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Register a mock
|
|
234
|
+
|
|
235
|
+
Save a response definition as `response.json`, then run:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
curl --request PUT \
|
|
239
|
+
--header "content-type: application/json" \
|
|
240
|
+
--data @response.json \
|
|
241
|
+
http://localhost:4001/__mocklane/mocks
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Remove a mock
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
curl --request DELETE \
|
|
248
|
+
--header "content-type: application/json" \
|
|
249
|
+
--data @response.json \
|
|
250
|
+
http://localhost:4001/__mocklane/mocks
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Control API request bodies are limited to 10 MB. A response definition must contain a method, a path beginning with `/`, an HTTP status from `100` to `599`, and a headers object.
|
|
254
|
+
|
|
255
|
+
## CORS Behavior
|
|
256
|
+
|
|
257
|
+
Mock responses include `access-control-allow-origin: *` unless the response already defines that header. An `OPTIONS` request containing `access-control-request-method` receives a `204` preflight response when Mocklane has a matching mock for that method and pathname.
|
|
258
|
+
|
|
259
|
+
## Development
|
|
260
|
+
|
|
261
|
+
Clone the repository and install dependencies:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
git clone https://github.com/aasispaudel/Mocklane.git
|
|
265
|
+
cd Mocklane
|
|
266
|
+
pnpm install
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Start the React Router development server:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
pnpm dev
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The development UI runs at `http://localhost:3010`. Development-only model test benches are available at:
|
|
276
|
+
|
|
277
|
+
```text
|
|
278
|
+
http://localhost:3010/test
|
|
279
|
+
http://localhost:3010/test-t
|
|
280
|
+
http://localhost:3010/test-n
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
The main application uses Transformers.js by default. The test routes isolate WebLLM, Transformers.js, and Native Browser AI behavior.
|
|
284
|
+
|
|
285
|
+
### Run the source CLI
|
|
286
|
+
|
|
287
|
+
Build the browser UI before starting the TypeScript CLI:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
pnpm build
|
|
291
|
+
pnpm mocklane
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Run the compiled CLI and rebuild everything first:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
pnpm mocklane:build
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Validation
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
pnpm typecheck
|
|
304
|
+
pnpm test:cli
|
|
305
|
+
pnpm build:package
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
- `typecheck` generates React Router types and runs TypeScript validation.
|
|
309
|
+
- `test:cli` verifies UI serving, mock registration, standalone `404` responses, CORS preflight handling, and upstream proxying.
|
|
310
|
+
- `build:package` creates the production browser bundle and compiled CLI.
|
|
311
|
+
|
|
312
|
+
## Packaging
|
|
313
|
+
|
|
314
|
+
Create the npm tarball locally:
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
npm pack
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
The `prepack` script automatically runs the production UI and CLI builds. The package contains:
|
|
321
|
+
|
|
322
|
+
```text
|
|
323
|
+
build/client/ Production browser application
|
|
324
|
+
dist/cli.js Compiled Node.js executable
|
|
325
|
+
README.md Package documentation
|
|
326
|
+
LICENSE MIT license
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Inspect the package without publishing:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
npm publish --dry-run
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Architecture
|
|
336
|
+
|
|
337
|
+
```text
|
|
338
|
+
app/
|
|
339
|
+
components/ Shared interface components
|
|
340
|
+
routes/home.tsx Main generator workspace
|
|
341
|
+
routes/test*.tsx Development model test benches
|
|
342
|
+
test-benches/ Provider-specific test interfaces
|
|
343
|
+
styles/app.css Application styles
|
|
344
|
+
cli/
|
|
345
|
+
index.ts CLI entry point and argument parsing
|
|
346
|
+
server.ts UI server, mock server, and upstream proxy
|
|
347
|
+
mockRegistry.ts In-memory method/path registry
|
|
348
|
+
server.test.ts CLI integration tests
|
|
349
|
+
src/
|
|
350
|
+
ai/localModel.ts WebLLM provider
|
|
351
|
+
ai/transformersModel.ts Transformers.js provider
|
|
352
|
+
ai/nativeBrowserModel.ts Native LanguageModel provider
|
|
353
|
+
core/browserApiMock.ts Browser-to-CLI mock registration
|
|
354
|
+
core/generateMockResponse.ts Provider orchestration
|
|
355
|
+
core/intent.ts Input structure detection
|
|
356
|
+
core/jsonUtils.ts JSON extraction and formatting
|
|
357
|
+
types/mockApi.ts HTTP response types
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
The CLI serves the built SPA on the UI port and the mock/proxy server on the proxy port. The browser performs AI generation, then sends validated response definitions to the CLI control API. No Node.js AI runtime is required.
|
|
361
|
+
|
|
362
|
+
## Operational Notes
|
|
363
|
+
|
|
364
|
+
- Local models can produce imperfect data. Review generated responses before using them in tests or demonstrations.
|
|
365
|
+
- Very large responses depend on model context limits, available GPU memory, and browser stability.
|
|
366
|
+
- Transformers.js and WebLLM are unavailable when WebGPU is unavailable.
|
|
367
|
+
- Native Browser AI depends on an experimental browser API and may not be present.
|
|
368
|
+
- Mocks are not persisted between CLI sessions.
|
|
369
|
+
- Mock matching is exact and does not interpret path parameters or wildcard routes.
|
|
370
|
+
- The proxy forwards credentials and authorization headers supplied by the client; use trusted upstream targets.
|
|
371
|
+
|
|
372
|
+
## Contributing
|
|
373
|
+
|
|
374
|
+
Issues and pull requests are welcome at [github.com/aasispaudel/Mocklane](https://github.com/aasispaudel/Mocklane).
|
|
375
|
+
|
|
376
|
+
Before opening a pull request, run:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
pnpm typecheck
|
|
380
|
+
pnpm test:cli
|
|
381
|
+
pnpm build:package
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## License
|
|
385
|
+
|
|
386
|
+
Mocklane is released under the [MIT License](LICENSE).
|