chore: import upstream snapshot with attribution
OpenSSF Scorecard / scorecard (push) Failing after 0s
DCO / dco (push) Failing after 0s
CodeQL SAST / analyze (push) Failing after 1s
Deploy Pages / deploy (push) Failing after 1s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:28:05 +08:00
commit 41cb1c0170
1830 changed files with 38276124 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
/* JSON-RPC client — speaks the same protocol as MCP clients via POST /rpc */
let _nextId = 1;
export class RpcError extends Error {
constructor(
public code: number,
message: string,
) {
super(message);
this.name = "RpcError";
}
}
export async function callTool<T = unknown>(
name: string,
args: Record<string, unknown> = {},
): Promise<T> {
const res = await fetch("/rpc", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
jsonrpc: "2.0",
id: _nextId++,
method: "tools/call",
params: { name, arguments: args },
}),
});
if (!res.ok) {
throw new RpcError(-1, `HTTP ${res.status}: ${res.statusText}`);
}
const json = await res.json();
if (json.error) {
throw new RpcError(json.error.code ?? -1, json.error.message ?? "unknown");
}
/* MCP tool results are wrapped: { result: { content: [{ text: "..." }] } } */
const text = json?.result?.content?.[0]?.text;
if (text === undefined) {
return json.result as T;
}
return JSON.parse(text) as T;
}