@hasna/logs 0.3.20 → 0.3.22
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 +191 -170
- package/README.md +15 -0
- package/bun.lock +6 -2
- package/dist/cli/index.js +1 -1
- package/dist/http-1r4r23qf.js +1236 -0
- package/dist/index-hjzbctgt.js +5868 -0
- package/dist/index-ssqkc6nh.js +1241 -0
- package/dist/index.js +156 -0
- package/dist/mcp/index.js +1199 -6957
- package/dist/server/index.js +5 -5
- package/package.json +3 -3
- package/sdk/package.json +8 -3
- package/src/cli/entrypoints.test.ts +1 -1
- package/src/index.ts +1 -0
- package/src/mcp/http.test.ts +92 -0
- package/src/mcp/http.ts +128 -0
- package/src/mcp/index.ts +36 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import"./index-re3ntm60.js";
|
|
3
|
+
|
|
4
|
+
// sdk/src/index.ts
|
|
5
|
+
var DEFAULT_URL = "http://localhost:3460";
|
|
6
|
+
|
|
7
|
+
class LogsClient {
|
|
8
|
+
url;
|
|
9
|
+
projectId;
|
|
10
|
+
headers;
|
|
11
|
+
constructor(opts = {}) {
|
|
12
|
+
this.url = (opts.url ?? DEFAULT_URL).replace(/\/$/, "");
|
|
13
|
+
this.projectId = opts.projectId;
|
|
14
|
+
this.headers = { "Content-Type": "application/json" };
|
|
15
|
+
if (opts.apiKey)
|
|
16
|
+
this.headers["Authorization"] = `Bearer ${opts.apiKey}`;
|
|
17
|
+
}
|
|
18
|
+
async push(entry) {
|
|
19
|
+
const res = await fetch(`${this.url}/api/logs`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: this.headers,
|
|
22
|
+
body: JSON.stringify({ project_id: this.projectId, ...entry })
|
|
23
|
+
});
|
|
24
|
+
return res.json();
|
|
25
|
+
}
|
|
26
|
+
async pushBatch(entries) {
|
|
27
|
+
const res = await fetch(`${this.url}/api/logs`, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: this.headers,
|
|
30
|
+
body: JSON.stringify(entries.map((e) => ({ project_id: this.projectId, ...e })))
|
|
31
|
+
});
|
|
32
|
+
return res.json();
|
|
33
|
+
}
|
|
34
|
+
async search(query = {}) {
|
|
35
|
+
const params = new URLSearchParams;
|
|
36
|
+
if (query.project_id ?? this.projectId)
|
|
37
|
+
params.set("project_id", query.project_id ?? this.projectId);
|
|
38
|
+
if (query.page_id)
|
|
39
|
+
params.set("page_id", query.page_id);
|
|
40
|
+
if (query.level)
|
|
41
|
+
params.set("level", Array.isArray(query.level) ? query.level.join(",") : query.level);
|
|
42
|
+
if (query.service)
|
|
43
|
+
params.set("service", query.service);
|
|
44
|
+
if (query.since)
|
|
45
|
+
params.set("since", query.since);
|
|
46
|
+
if (query.until)
|
|
47
|
+
params.set("until", query.until);
|
|
48
|
+
if (query.text)
|
|
49
|
+
params.set("text", query.text);
|
|
50
|
+
if (query.limit)
|
|
51
|
+
params.set("limit", String(query.limit));
|
|
52
|
+
if (query.offset)
|
|
53
|
+
params.set("offset", String(query.offset));
|
|
54
|
+
if (query.fields)
|
|
55
|
+
params.set("fields", query.fields.join(","));
|
|
56
|
+
const res = await fetch(`${this.url}/api/logs?${params}`, { headers: this.headers });
|
|
57
|
+
return res.json();
|
|
58
|
+
}
|
|
59
|
+
async tail(projectId, n = 50) {
|
|
60
|
+
const params = new URLSearchParams({ n: String(n) });
|
|
61
|
+
const pid = projectId ?? this.projectId;
|
|
62
|
+
if (pid)
|
|
63
|
+
params.set("project_id", pid);
|
|
64
|
+
const res = await fetch(`${this.url}/api/logs/tail?${params}`, { headers: this.headers });
|
|
65
|
+
return res.json();
|
|
66
|
+
}
|
|
67
|
+
async summary(projectId, since) {
|
|
68
|
+
const params = new URLSearchParams;
|
|
69
|
+
const pid = projectId ?? this.projectId;
|
|
70
|
+
if (pid)
|
|
71
|
+
params.set("project_id", pid);
|
|
72
|
+
if (since)
|
|
73
|
+
params.set("since", since);
|
|
74
|
+
const res = await fetch(`${this.url}/api/logs/summary?${params}`, { headers: this.headers });
|
|
75
|
+
return res.json();
|
|
76
|
+
}
|
|
77
|
+
async context(traceId) {
|
|
78
|
+
const res = await fetch(`${this.url}/api/logs/${traceId}/context`, { headers: this.headers });
|
|
79
|
+
return res.json();
|
|
80
|
+
}
|
|
81
|
+
async registerProject(name, githubRepo, baseUrl) {
|
|
82
|
+
const res = await fetch(`${this.url}/api/projects`, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: this.headers,
|
|
85
|
+
body: JSON.stringify({ name, github_repo: githubRepo, base_url: baseUrl })
|
|
86
|
+
});
|
|
87
|
+
return res.json();
|
|
88
|
+
}
|
|
89
|
+
async registerPage(projectId, url, path, name) {
|
|
90
|
+
const res = await fetch(`${this.url}/api/projects/${projectId}/pages`, {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: this.headers,
|
|
93
|
+
body: JSON.stringify({ url, path, name })
|
|
94
|
+
});
|
|
95
|
+
return res.json();
|
|
96
|
+
}
|
|
97
|
+
async createScanJob(projectId, schedule, pageId) {
|
|
98
|
+
const res = await fetch(`${this.url}/api/jobs`, {
|
|
99
|
+
method: "POST",
|
|
100
|
+
headers: this.headers,
|
|
101
|
+
body: JSON.stringify({ project_id: projectId, schedule, page_id: pageId })
|
|
102
|
+
});
|
|
103
|
+
return res.json();
|
|
104
|
+
}
|
|
105
|
+
async perfSnapshot(projectId, pageId) {
|
|
106
|
+
const params = new URLSearchParams({ project_id: projectId });
|
|
107
|
+
if (pageId)
|
|
108
|
+
params.set("page_id", pageId);
|
|
109
|
+
const res = await fetch(`${this.url}/api/perf?${params}`, { headers: this.headers });
|
|
110
|
+
return res.json();
|
|
111
|
+
}
|
|
112
|
+
async perfTrend(projectId, pageId, since, limit) {
|
|
113
|
+
const params = new URLSearchParams({ project_id: projectId });
|
|
114
|
+
if (pageId)
|
|
115
|
+
params.set("page_id", pageId);
|
|
116
|
+
if (since)
|
|
117
|
+
params.set("since", since);
|
|
118
|
+
if (limit)
|
|
119
|
+
params.set("limit", String(limit));
|
|
120
|
+
const res = await fetch(`${this.url}/api/perf/trend?${params}`, { headers: this.headers });
|
|
121
|
+
return res.json();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function initLogs(opts) {
|
|
125
|
+
if (typeof window === "undefined")
|
|
126
|
+
return;
|
|
127
|
+
const serverUrl = (opts.url ?? DEFAULT_URL).replace(/\/$/, "");
|
|
128
|
+
const client = new LogsClient({ url: serverUrl, projectId: opts.projectId });
|
|
129
|
+
const q = [];
|
|
130
|
+
const flush = () => {
|
|
131
|
+
if (q.length)
|
|
132
|
+
client.pushBatch(q.splice(0)).catch(() => {});
|
|
133
|
+
};
|
|
134
|
+
setInterval(flush, 2000);
|
|
135
|
+
const _ce = console.error.bind(console);
|
|
136
|
+
console.error = (...args) => {
|
|
137
|
+
_ce(...args);
|
|
138
|
+
q.push({ level: "error", message: args.map(String).join(" "), source: "script", url: location.href });
|
|
139
|
+
};
|
|
140
|
+
const _cw = console.warn.bind(console);
|
|
141
|
+
console.warn = (...args) => {
|
|
142
|
+
_cw(...args);
|
|
143
|
+
q.push({ level: "warn", message: args.map(String).join(" "), source: "script", url: location.href });
|
|
144
|
+
};
|
|
145
|
+
window.addEventListener("error", (e) => {
|
|
146
|
+
q.push({ level: "error", message: e.message, stack_trace: e.error?.stack, source: "script", url: location.href });
|
|
147
|
+
});
|
|
148
|
+
window.addEventListener("unhandledrejection", (e) => {
|
|
149
|
+
q.push({ level: "error", message: `Unhandled: ${e.reason?.message ?? e.reason}`, stack_trace: e.reason?.stack, source: "script", url: location.href });
|
|
150
|
+
});
|
|
151
|
+
window.addEventListener("beforeunload", flush);
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
initLogs,
|
|
155
|
+
LogsClient
|
|
156
|
+
};
|