tidewave 0.3.0 → 0.4.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 +131 -94
- package/dist/cli/index.js +12024 -11669
- package/dist/core.d.ts +5 -0
- package/dist/evaluation/eval_worker.js +1 -30
- package/dist/index.d.ts +2 -2
- package/dist/logger/circular-buffer.d.ts +54 -0
- package/dist/logger/instrumentation.d.ts +2 -0
- package/dist/logger/tidewave-log-record-processor.d.ts +17 -0
- package/dist/logger/tidewave-span-processor.d.ts +26 -0
- package/dist/{next-js.d.ts → next-js/handler.d.ts} +2 -6
- package/dist/{http/index.js → next-js/handler.js} +33003 -32394
- package/dist/next-js/instrumentation.d.ts +7 -0
- package/dist/next-js/instrumentation.js +255 -0
- package/dist/tools.d.ts +18 -0
- package/dist/vite-plugin.d.ts +1 -0
- package/dist/vite-plugin.js +32255 -31741
- package/package.json +22 -7
- package/dist/core.js +0 -64
- package/dist/evaluation/code_executor.js +0 -104
- package/dist/http/security.js +0 -132
- package/dist/index.js +0 -906
- package/dist/mcp.js +0 -14174
- package/dist/next-js.js +0 -40304
- package/dist/resolution/formatters.js +0 -155
- package/dist/resolution/index.js +0 -829
- package/dist/resolution/module-resolver.js +0 -166
- package/dist/resolution/symbol-finder.js +0 -429
- package/dist/resolution/utils.js +0 -112
- package/dist/tools.js +0 -4099
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tidewave",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Tidewave JavaScript CLI for documentation extraction and MCP server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -34,11 +34,17 @@
|
|
|
34
34
|
"import": "./dist/vite-plugin.js",
|
|
35
35
|
"require": "./dist/vite-plugin.js"
|
|
36
36
|
},
|
|
37
|
-
"./next-js": {
|
|
38
|
-
"types": "./dist/next-js.d.ts",
|
|
39
|
-
"import": "./dist/next-js.js",
|
|
40
|
-
"require": "./dist/next-js.js"
|
|
41
|
-
}
|
|
37
|
+
"./next-js/handler": {
|
|
38
|
+
"types": "./dist/next-js/handler.d.ts",
|
|
39
|
+
"import": "./dist/next-js/handler.js",
|
|
40
|
+
"require": "./dist/next-js/handler.js"
|
|
41
|
+
},
|
|
42
|
+
"./next-js/instrumentation": {
|
|
43
|
+
"types": "./dist/next-js/instrumentation.d.ts",
|
|
44
|
+
"import": "./dist/next-js/instrumentation.js",
|
|
45
|
+
"require": "./dist/next-js/instrumentation.js"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
42
48
|
},
|
|
43
49
|
"files": [
|
|
44
50
|
"dist/",
|
|
@@ -48,7 +54,7 @@
|
|
|
48
54
|
],
|
|
49
55
|
"scripts": {
|
|
50
56
|
"dist": "bun run clean && bun run build:js && bun run build:types",
|
|
51
|
-
"build:js": "bun build --outdir dist --root src --external commander --external chalk --external typescript src
|
|
57
|
+
"build:js": "bun build --outdir dist --root src --external commander --external chalk --external typescript --external child_process --external module --external @opentelemetry/api --external @opentelemetry/api-logs --external @opentelemetry/core --external @opentelemetry/resources --external @opentelemetry/sdk-logs --external @opentelemetry/sdk-trace-base --external @opentelemetry/sdk-trace-node --external @opentelemetry/semantic-conventions src/next-js/handler.ts src/next-js/instrumentation.ts src/vite-plugin.ts src/evaluation/eval_worker.ts src/cli/index.ts --target node",
|
|
52
58
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
53
59
|
"dev": "bun run src/cli/index.ts",
|
|
54
60
|
"test": "bun test",
|
|
@@ -61,6 +67,14 @@
|
|
|
61
67
|
},
|
|
62
68
|
"dependencies": {
|
|
63
69
|
"@modelcontextprotocol/sdk": "^1.17.4",
|
|
70
|
+
"@opentelemetry/api": "^1.9.0",
|
|
71
|
+
"@opentelemetry/api-logs": "^0.206.0",
|
|
72
|
+
"@opentelemetry/core": "^2.1.0",
|
|
73
|
+
"@opentelemetry/resources": "^2.1.0",
|
|
74
|
+
"@opentelemetry/sdk-logs": "^0.206.0",
|
|
75
|
+
"@opentelemetry/sdk-trace-base": "^2.1.0",
|
|
76
|
+
"@opentelemetry/sdk-trace-node": "^2.1.0",
|
|
77
|
+
"@opentelemetry/semantic-conventions": "^1.37.0",
|
|
64
78
|
"body-parser": "^2.2.0",
|
|
65
79
|
"chalk": "^5.3.0",
|
|
66
80
|
"commander": "^12.1.0",
|
|
@@ -76,6 +90,7 @@
|
|
|
76
90
|
"@types/node": "^22.10.1",
|
|
77
91
|
"@typescript-eslint/eslint-plugin": "^8.18.0",
|
|
78
92
|
"@typescript-eslint/parser": "^8.18.0",
|
|
93
|
+
"@vercel/otel": "^2.0.1",
|
|
79
94
|
"@vitest/ui": "^3.2.4",
|
|
80
95
|
"bun-types": "latest",
|
|
81
96
|
"eslint": "^9.16.0",
|
package/dist/core.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
|
-
|
|
30
|
-
// src/core.ts
|
|
31
|
-
function isError(result) {
|
|
32
|
-
return result != null && "success" in result && result.success === false;
|
|
33
|
-
}
|
|
34
|
-
function isResolveError(result) {
|
|
35
|
-
return result != null && "success" in result && result.success === false;
|
|
36
|
-
}
|
|
37
|
-
function isExtractError(result) {
|
|
38
|
-
return result != null && "error" in result;
|
|
39
|
-
}
|
|
40
|
-
function resolveError(specifier, source) {
|
|
41
|
-
return {
|
|
42
|
-
success: false,
|
|
43
|
-
error: {
|
|
44
|
-
code: "MODULE_NOT_FOUND",
|
|
45
|
-
message: `Cannot resolve module '${specifier}' from '${source}'`
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function createExtractError(code, message, details) {
|
|
50
|
-
return {
|
|
51
|
-
error: {
|
|
52
|
-
code,
|
|
53
|
-
message,
|
|
54
|
-
details
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
resolveError,
|
|
60
|
-
isResolveError,
|
|
61
|
-
isExtractError,
|
|
62
|
-
isError,
|
|
63
|
-
createExtractError
|
|
64
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
|
-
|
|
30
|
-
// src/evaluation/eval_worker.ts
|
|
31
|
-
process.on("message", async ({ code, args }) => {
|
|
32
|
-
if (!process.send) {
|
|
33
|
-
console.error("[Tidewave] Unable to establish communication channel with code-executor.");
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
|
|
38
|
-
const fn = new AsyncFunction(code);
|
|
39
|
-
const result = await fn(...args);
|
|
40
|
-
process.send({
|
|
41
|
-
type: "result",
|
|
42
|
-
success: true,
|
|
43
|
-
data: (result || null) && result
|
|
44
|
-
});
|
|
45
|
-
} catch (error) {
|
|
46
|
-
process.send({
|
|
47
|
-
type: "result",
|
|
48
|
-
success: false,
|
|
49
|
-
data: new String(error)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
process.exit(0);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// src/evaluation/code_executor.ts
|
|
56
|
-
import { fork } from "child_process";
|
|
57
|
-
async function executeIsolated(request) {
|
|
58
|
-
return new Promise((resolve) => {
|
|
59
|
-
const workerPath = __require.resolve("./eval_worker");
|
|
60
|
-
const child = fork(workerPath, { silent: true });
|
|
61
|
-
const evaluation = {
|
|
62
|
-
success: false,
|
|
63
|
-
result: null,
|
|
64
|
-
stdout: "",
|
|
65
|
-
stderr: ""
|
|
66
|
-
};
|
|
67
|
-
child.stdout?.on("data", (data) => {
|
|
68
|
-
evaluation.stdout += data.toString();
|
|
69
|
-
});
|
|
70
|
-
child.stderr?.on("data", (data) => {
|
|
71
|
-
evaluation.stderr += data.toString();
|
|
72
|
-
});
|
|
73
|
-
child.on("message", (msg) => {
|
|
74
|
-
if (msg.type === "result") {
|
|
75
|
-
const { data, success } = msg;
|
|
76
|
-
evaluation.result = data;
|
|
77
|
-
evaluation.success = success;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
child.on("exit", (code) => {
|
|
81
|
-
resolve({
|
|
82
|
-
success: evaluation.success && code === 0,
|
|
83
|
-
result: evaluation.result,
|
|
84
|
-
stdout: evaluation.stdout.trim(),
|
|
85
|
-
stderr: evaluation.stderr.trim()
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
const { timeout } = request;
|
|
89
|
-
const timeoutId = setTimeout(() => {
|
|
90
|
-
child.kill("SIGKILL");
|
|
91
|
-
resolve({
|
|
92
|
-
success: false,
|
|
93
|
-
result: `Evaluation timed out after ${timeout} milliseconds`,
|
|
94
|
-
stdout: evaluation.stdout,
|
|
95
|
-
stderr: evaluation.stderr
|
|
96
|
-
});
|
|
97
|
-
}, timeout);
|
|
98
|
-
child.on("exit", () => clearTimeout(timeoutId));
|
|
99
|
-
child.send(request);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
export {
|
|
103
|
-
executeIsolated
|
|
104
|
-
};
|
package/dist/http/security.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
|
-
|
|
30
|
-
// src/http/security.ts
|
|
31
|
-
function fetchRemoteIp(req) {
|
|
32
|
-
const remote = req.socket.remoteAddress;
|
|
33
|
-
if (remote)
|
|
34
|
-
return remote;
|
|
35
|
-
const ip = req.headers["x-real-ip"] && req.headers["x-forwarded-for"] || null;
|
|
36
|
-
if (Array.isArray(ip)) {
|
|
37
|
-
return ip.join();
|
|
38
|
-
}
|
|
39
|
-
return ip;
|
|
40
|
-
}
|
|
41
|
-
function checkRemoteIp(req, res, config) {
|
|
42
|
-
const ip = fetchRemoteIp(req);
|
|
43
|
-
if (!ip)
|
|
44
|
-
return false;
|
|
45
|
-
if (isLocalIp(ip))
|
|
46
|
-
return true;
|
|
47
|
-
if (config.allowRemoteAccess)
|
|
48
|
-
return true;
|
|
49
|
-
const message = "For security reasons, Tidewave does not accept remote connections by default.\n\nIf you really want to allow remote connections, configure the Tidewave with the `allowRemoteAccess: true` option.";
|
|
50
|
-
console.warn(message);
|
|
51
|
-
res.statusCode = 403;
|
|
52
|
-
res.end(message);
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
function isLocalIp(ip) {
|
|
56
|
-
if (!ip)
|
|
57
|
-
return false;
|
|
58
|
-
if (ip.startsWith("127.0.0."))
|
|
59
|
-
return true;
|
|
60
|
-
if (ip === "::1")
|
|
61
|
-
return true;
|
|
62
|
-
if (ip === "::ffff:127.0.0.1")
|
|
63
|
-
return true;
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
function checkOrigin(req, res, config) {
|
|
67
|
-
const { origin } = req.headers;
|
|
68
|
-
if (!origin)
|
|
69
|
-
return true;
|
|
70
|
-
const allowedOrigins = config.allowedOrigins || getDefaultAllowedOrigins(config);
|
|
71
|
-
const originUrl = parseUrl(origin);
|
|
72
|
-
if (!originUrl) {
|
|
73
|
-
const message = `For security reasons, Tidewave only accepts requests from allowed origins.
|
|
74
|
-
|
|
75
|
-
Invalid origin: ${origin}`;
|
|
76
|
-
console.warn(message);
|
|
77
|
-
res.statusCode = 403;
|
|
78
|
-
res.end(message);
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const isAllowed = allowedOrigins.some((allowed) => isOriginAllowed(originUrl, parseUrl(allowed)));
|
|
82
|
-
if (!isAllowed) {
|
|
83
|
-
const message = `For security reasons, Tidewave only accepts requests from the same origin your web app is running on.
|
|
84
|
-
|
|
85
|
-
If you really want to allow remote connections, configure the Tidewave with the \`allowedOrigins: [${JSON.stringify(origin)}]\` option.`;
|
|
86
|
-
console.warn(message);
|
|
87
|
-
res.statusCode = 403;
|
|
88
|
-
res.end(message);
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
function getDefaultAllowedOrigins(config) {
|
|
94
|
-
const { host, port } = config;
|
|
95
|
-
if (!(host || port))
|
|
96
|
-
return [];
|
|
97
|
-
return [`http://${host}:${port}`, `https://${host}:${port}`];
|
|
98
|
-
}
|
|
99
|
-
function parseUrl(url) {
|
|
100
|
-
try {
|
|
101
|
-
const isProtocolRelative = url.startsWith("//");
|
|
102
|
-
const parsed = new URL(isProtocolRelative ? "http:" + url : url);
|
|
103
|
-
return {
|
|
104
|
-
scheme: isProtocolRelative ? undefined : parsed.protocol?.slice(0, -1),
|
|
105
|
-
host: parsed.hostname,
|
|
106
|
-
port: parsed.port ? parseInt(parsed.port) : undefined
|
|
107
|
-
};
|
|
108
|
-
} catch {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function isOriginAllowed(origin, allowed) {
|
|
113
|
-
if (!origin || !allowed)
|
|
114
|
-
return false;
|
|
115
|
-
if (allowed.scheme && origin.scheme !== allowed.scheme)
|
|
116
|
-
return false;
|
|
117
|
-
if (allowed.port && origin.port !== allowed.port)
|
|
118
|
-
return false;
|
|
119
|
-
if (allowed.host.startsWith("*.")) {
|
|
120
|
-
const allowedDomain = allowed.host.slice(2);
|
|
121
|
-
return origin.host === allowedDomain || origin.host.endsWith("." + allowedDomain);
|
|
122
|
-
}
|
|
123
|
-
return origin.host === allowed.host;
|
|
124
|
-
}
|
|
125
|
-
export {
|
|
126
|
-
parseUrl,
|
|
127
|
-
isOriginAllowed,
|
|
128
|
-
isLocalIp,
|
|
129
|
-
getDefaultAllowedOrigins,
|
|
130
|
-
checkRemoteIp,
|
|
131
|
-
checkOrigin
|
|
132
|
-
};
|