@agentvalet/register 0.2.1 → 0.2.2
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/dist/index.js
CHANGED
|
@@ -603,7 +603,7 @@ program.command("refresh").description("Refresh approved permissions and update
|
|
|
603
603
|
}
|
|
604
604
|
});
|
|
605
605
|
program.command("mcp-server").description("Start the AgentValet MCP server (stdio transport)").action(async () => {
|
|
606
|
-
await import("./mcp-server-
|
|
606
|
+
await import("./mcp-server-DMQWPHYT.js");
|
|
607
607
|
});
|
|
608
608
|
program.parseAsync().catch((err) => {
|
|
609
609
|
console.error(err);
|
|
@@ -7,8 +7,8 @@ import { SignJWT, importPKCS8 } from "jose";
|
|
|
7
7
|
if (!process.env.AGENT_PRIVATE_KEY && process.env.AGENT_PRIVATE_KEY_PATH) {
|
|
8
8
|
try {
|
|
9
9
|
process.env.AGENT_PRIVATE_KEY = readFileSync(process.env.AGENT_PRIVATE_KEY_PATH, "utf-8").trim();
|
|
10
|
-
} catch (
|
|
11
|
-
process.stderr.write(`[agent-authority] Cannot read AGENT_PRIVATE_KEY_PATH: ${
|
|
10
|
+
} catch (err) {
|
|
11
|
+
process.stderr.write(`[agent-authority] Cannot read AGENT_PRIVATE_KEY_PATH: ${err instanceof Error ? err.message : err}
|
|
12
12
|
`);
|
|
13
13
|
process.exit(1);
|
|
14
14
|
}
|
|
@@ -25,23 +25,28 @@ var AGENT_PRIVATE_KEY_RAW = process.env.AGENT_PRIVATE_KEY;
|
|
|
25
25
|
var AGENT_ID = process.env.AGENT_ID;
|
|
26
26
|
var OWNER_ID = process.env.OWNER_ID;
|
|
27
27
|
var PROXY_URL = process.env.PROXY_URL.replace(/\/$/, "");
|
|
28
|
-
var
|
|
29
|
-
|
|
28
|
+
var _privateKey = null;
|
|
29
|
+
var _keyError = null;
|
|
30
|
+
async function getPrivateKey() {
|
|
31
|
+
if (_keyError) throw new Error(_keyError);
|
|
32
|
+
if (_privateKey) return _privateKey;
|
|
33
|
+
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL") return null;
|
|
30
34
|
const raw = AGENT_PRIVATE_KEY_RAW.trim();
|
|
31
35
|
const pem = raw.startsWith("-----") ? raw.replace(/\\n/g, "\n") : `-----BEGIN PRIVATE KEY-----
|
|
32
36
|
${raw}
|
|
33
37
|
-----END PRIVATE KEY-----`;
|
|
34
38
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`
|
|
39
|
-
|
|
39
|
+
_privateKey = await importPKCS8(pem, "RS256");
|
|
40
|
+
return _privateKey;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
_keyError = `Invalid private key: ${err instanceof Error ? err.message : err}`;
|
|
43
|
+
throw new Error(_keyError);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
async function signJWT() {
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
const key = await getPrivateKey();
|
|
48
|
+
if (!key) throw new Error("Private key not loaded");
|
|
49
|
+
return new SignJWT({ agent_id: AGENT_ID, owner_id: OWNER_ID }).setProtectedHeader({ alg: "RS256" }).setIssuedAt().setExpirationTime("60s").sign(key);
|
|
45
50
|
}
|
|
46
51
|
function fetchWithTimeout(url, init, ms = 15e3) {
|
|
47
52
|
const ac = new AbortController();
|
|
@@ -55,12 +60,9 @@ async function bearerFetch(url, init) {
|
|
|
55
60
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", ...init.headers }
|
|
56
61
|
});
|
|
57
62
|
}
|
|
58
|
-
function
|
|
63
|
+
function errResult(msg) {
|
|
59
64
|
return { content: [{ type: "text", text: msg }], isError: true };
|
|
60
65
|
}
|
|
61
|
-
function pendingResponse() {
|
|
62
|
-
return err("Agent not yet activated \u2014 owner confirmation pending. Retry in 60 seconds.");
|
|
63
|
-
}
|
|
64
66
|
var ALLOWED_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
65
67
|
var server = new Server(
|
|
66
68
|
{ name: "agent-authority", version: "1.0.0" },
|
|
@@ -93,22 +95,26 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
93
95
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
94
96
|
const { name, arguments: args } = request.params;
|
|
95
97
|
if (name === "list_platforms") {
|
|
96
|
-
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL")
|
|
98
|
+
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL") {
|
|
99
|
+
return errResult("Agent not yet activated \u2014 owner confirmation pending. Retry in 60 seconds.");
|
|
100
|
+
}
|
|
97
101
|
try {
|
|
98
102
|
const res = await bearerFetch(`${PROXY_URL}/v1/agent/permissions`, { method: "GET", headers: {} });
|
|
99
103
|
const body = await res.text();
|
|
100
|
-
if (!res.ok) return
|
|
104
|
+
if (!res.ok) return errResult(`Proxy error ${res.status}: ${body}`);
|
|
101
105
|
return { content: [{ type: "text", text: body }] };
|
|
102
106
|
} catch (e) {
|
|
103
|
-
return
|
|
107
|
+
return errResult(`Error: ${e instanceof Error ? e.message : e}`);
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
if (name === "use_platform") {
|
|
107
|
-
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL")
|
|
111
|
+
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL") {
|
|
112
|
+
return errResult("Agent not yet activated \u2014 owner confirmation pending. Retry in 60 seconds.");
|
|
113
|
+
}
|
|
108
114
|
if (!args || typeof args.platform !== "string" || typeof args.endpoint !== "string" || typeof args.method !== "string" || typeof args.scope !== "string") {
|
|
109
|
-
return
|
|
115
|
+
return errResult("Missing required args: platform, endpoint, method, scope");
|
|
110
116
|
}
|
|
111
|
-
if (!ALLOWED_METHODS.includes(args.method)) return
|
|
117
|
+
if (!ALLOWED_METHODS.includes(args.method)) return errResult(`Invalid method: ${args.method}`);
|
|
112
118
|
try {
|
|
113
119
|
const res = await bearerFetch(`${PROXY_URL}/v1/actions`, {
|
|
114
120
|
method: "POST",
|
|
@@ -121,13 +127,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
121
127
|
})
|
|
122
128
|
});
|
|
123
129
|
const body = await res.text();
|
|
124
|
-
if (!res.ok) return
|
|
130
|
+
if (!res.ok) return errResult(`Proxy error ${res.status}: ${body}`);
|
|
125
131
|
return { content: [{ type: "text", text: body }] };
|
|
126
132
|
} catch (e) {
|
|
127
|
-
return
|
|
133
|
+
return errResult(`Error: ${e instanceof Error ? e.message : e}`);
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
|
-
return
|
|
136
|
+
return errResult(`Unknown tool: ${name}`);
|
|
131
137
|
});
|
|
132
138
|
var transport = new StdioServerTransport();
|
|
133
139
|
await server.connect(transport);
|