troxy-cli 1.0.1 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api.js CHANGED
@@ -49,7 +49,7 @@ export const api = {
49
49
  evaluate: (body, apiKey) => request('POST', '/evaluate', { apiKey, body }),
50
50
 
51
51
  // MCP heartbeat (agent API key)
52
- mcpHeartbeat: (apiKey) => request('POST', '/mcp/heartbeat', { apiKey }),
52
+ mcpHeartbeat: (apiKey, agentName) => request('POST', '/mcp/heartbeat', { apiKey, body: agentName ? { agent_name: agentName } : undefined }),
53
53
  };
54
54
 
55
55
  // Named export for backwards compat with init.js + mcp-server.js
package/src/init.js CHANGED
@@ -1,9 +1,15 @@
1
- import fs from 'fs';
2
- import os from 'os';
3
- import path from 'path';
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import readline from 'readline';
4
5
  import { saveConfig } from './config.js';
5
6
  import { evaluatePayment } from './api.js';
6
7
 
8
+ function prompt(question) {
9
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
10
+ return new Promise(resolve => rl.question(question, ans => { rl.close(); resolve(ans.trim()); }));
11
+ }
12
+
7
13
  // MCP config locations per client and platform
8
14
  const MCP_CLIENTS = [
9
15
  {
@@ -66,8 +72,15 @@ export async function runInit({ key } = {}) {
66
72
  console.log('✓');
67
73
  }
68
74
 
75
+ // Ask for agent name
76
+ const agentName = await prompt(' What would you like to name this agent? (e.g. "Shopping Bot"): ');
77
+ if (!agentName) {
78
+ console.error('\n Error: agent name is required.\n');
79
+ process.exit(1);
80
+ }
81
+
69
82
  // Save config
70
- saveConfig({ apiKey: key });
83
+ saveConfig({ apiKey: key, agentName });
71
84
  console.log(' Config saved (~/.troxy/config.json) ✓');
72
85
 
73
86
  // Detect and patch MCP clients
package/src/mcp-server.js CHANGED
@@ -8,8 +8,9 @@ import { loadConfig } from './config.js';
8
8
  import { evaluatePayment, api } from './api.js';
9
9
 
10
10
  export async function runMcp() {
11
- const config = loadConfig();
12
- const apiKey = process.env.TROXY_API_KEY || config?.apiKey;
11
+ const config = loadConfig();
12
+ const apiKey = process.env.TROXY_API_KEY || config?.apiKey;
13
+ const agentName = process.env.TROXY_AGENT_NAME || config?.agentName;
13
14
 
14
15
  if (!apiKey) {
15
16
  process.stderr.write(
@@ -70,6 +71,7 @@ export async function runMcp() {
70
71
  }
71
72
 
72
73
  const args = request.params.arguments ?? {};
74
+ if (agentName && !args.agent) args.agent = agentName;
73
75
  const result = await evaluatePayment(args, apiKey);
74
76
 
75
77
  if (result.error) {
@@ -109,7 +111,7 @@ export async function runMcp() {
109
111
  // Must be set up before server.connect() since stdio transport keeps the
110
112
  // event loop running but connect() may not return in all environments.
111
113
  const sendHeartbeat = () =>
112
- api.mcpHeartbeat(apiKey)
114
+ api.mcpHeartbeat(apiKey, agentName)
113
115
  .then(() => process.stderr.write('[troxy] heartbeat ok\n'))
114
116
  .catch(err => process.stderr.write(`[troxy] heartbeat failed: ${err.message}\n`));
115
117
  sendHeartbeat();