trenchfeed-cli 0.1.0 → 0.2.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/src/api.ts DELETED
@@ -1,147 +0,0 @@
1
- /**
2
- * CLI API Client — REST client for TrenchFeed backend
3
- */
4
-
5
- import { loadConfig } from './config';
6
-
7
- async function request<T>(path: string, opts: { method?: string; body?: unknown; token?: string } = {}): Promise<T> {
8
- const config = loadConfig();
9
- const url = `${config.apiUrl}${path}`;
10
- const token = opts.token ?? config.apiKey;
11
-
12
- const headers: Record<string, string> = {
13
- 'Content-Type': 'application/json',
14
- };
15
- if (token) {
16
- headers['Authorization'] = `Bearer ${token}`;
17
- }
18
-
19
- const res = await fetch(url, {
20
- method: opts.method ?? 'GET',
21
- headers,
22
- body: opts.body ? JSON.stringify(opts.body) : undefined,
23
- });
24
-
25
- if (!res.ok) {
26
- const err = await res.json().catch(() => ({ error: res.statusText }));
27
- throw new Error((err as { error?: string }).error ?? `API error ${res.status}`);
28
- }
29
-
30
- return res.json() as Promise<T>;
31
- }
32
-
33
- // ─── Types ────────────────────────────────────────────────────────────────────
34
-
35
- export interface PlatformConfig {
36
- burnRequired: boolean;
37
- burnMint: string | null;
38
- burnAmount: number;
39
- burnTokenSymbol: string;
40
- }
41
-
42
- export interface AgentSummary {
43
- id: string;
44
- userId: string;
45
- status: string;
46
- strategy: string;
47
- name: string;
48
- dryRun?: boolean;
49
- positions: number;
50
- openPnlSol: number;
51
- closedPnlSol: number;
52
- totalTrades: number;
53
- wallet: { publicKey: string };
54
- createdAt: number;
55
- startedAt: number | null;
56
- }
57
-
58
- export interface AgentDetail {
59
- id: string;
60
- userId: string;
61
- status: string;
62
- config: Record<string, unknown>;
63
- openPnlSol: number;
64
- closedPnlSol: number;
65
- totalTrades: number;
66
- wallet: { publicKey: string };
67
- positions: Array<{
68
- mint: string;
69
- symbol?: string;
70
- amountSol: number;
71
- entryPrice: number;
72
- currentPrice?: number;
73
- unrealizedPnl?: number;
74
- unrealizedPnlPct?: number;
75
- }>;
76
- createdAt: number;
77
- startedAt: number | null;
78
- stoppedAt: number | null;
79
- }
80
-
81
- export interface TradeRecord {
82
- id: number;
83
- action: string;
84
- mint: string;
85
- symbol: string | null;
86
- amountSol: number | null;
87
- price: number | null;
88
- pnlSol: number | null;
89
- pnlPct: number | null;
90
- reason: string | null;
91
- createdAt: number;
92
- }
93
-
94
- export interface WalletInfo {
95
- publicKey: string;
96
- balance: number;
97
- lamports: number;
98
- }
99
-
100
- // ─── API Methods ──────────────────────────────────────────────────────────────
101
-
102
- export const api = {
103
- // Health
104
- health: () => request<{ status: string; agents: number; running: number }>('/health'),
105
-
106
- // Platform config (burn gate info)
107
- getCliConfig: () => request<PlatformConfig>('/api/cli/config'),
108
-
109
- // CLI auth
110
- register: (walletToken: string, body: { config?: Record<string, unknown>; burnTxSignature?: string }) =>
111
- request<{ apiKey: string; agentId: string; wallet: string; status: string; message: string }>(
112
- '/api/cli/register', { method: 'POST', body, token: walletToken }
113
- ),
114
-
115
- // Agent
116
- getMyAgent: () => request<AgentSummary[]>('/api/agents/me'),
117
-
118
- getAgent: (id: string) => request<AgentDetail>(`/api/agents/${id}`),
119
-
120
- startAgent: (id: string) =>
121
- request<{ status: string }>(`/api/agents/${id}/start`, { method: 'POST' }),
122
-
123
- stopAgent: (id: string) =>
124
- request<{ status: string }>(`/api/agents/${id}/stop`, { method: 'POST' }),
125
-
126
- pauseAgent: (id: string) =>
127
- request<{ status: string }>(`/api/agents/${id}/pause`, { method: 'POST' }),
128
-
129
- resumeAgent: (id: string) =>
130
- request<{ status: string }>(`/api/agents/${id}/resume`, { method: 'POST' }),
131
-
132
- emergencyStop: (id: string) =>
133
- request<{ status: string }>(`/api/agents/${id}/emergency`, { method: 'POST' }),
134
-
135
- updateConfig: (id: string, config: Record<string, unknown>) =>
136
- request<{ config: Record<string, unknown> }>(`/api/agents/${id}/config`, { method: 'PATCH', body: config }),
137
-
138
- getWallet: (id: string) => request<WalletInfo>(`/api/agents/${id}/wallet`),
139
-
140
- getTrades: (id: string, limit = 20) =>
141
- request<TradeRecord[]>(`/api/agents/${id}/trades?limit=${limit}`),
142
-
143
- withdraw: (id: string, toAddress: string, amountSol: number) =>
144
- request<{ signature: string }>(`/api/agents/${id}/wallet/withdraw`, {
145
- method: 'POST', body: { toAddress, amountSol },
146
- }),
147
- };
package/src/config.ts DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * CLI Config — Stores API key and settings in ~/.trenchfeed/cli.json
3
- */
4
-
5
- import { join } from 'path';
6
- import { homedir } from 'os';
7
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
8
-
9
- const CONFIG_DIR = join(homedir(), '.trenchfeed');
10
- const CONFIG_FILE = join(CONFIG_DIR, 'cli.json');
11
-
12
- export interface CliConfig {
13
- apiUrl: string;
14
- apiKey: string | null;
15
- agentId: string | null;
16
- wallet: string | null;
17
- }
18
-
19
- const DEFAULTS: CliConfig = {
20
- apiUrl: 'https://trenchfeed-production.up.railway.app',
21
- apiKey: null,
22
- agentId: null,
23
- wallet: null,
24
- };
25
-
26
- export function loadConfig(): CliConfig {
27
- if (!existsSync(CONFIG_FILE)) return { ...DEFAULTS };
28
- try {
29
- const raw = readFileSync(CONFIG_FILE, 'utf-8');
30
- return { ...DEFAULTS, ...JSON.parse(raw) };
31
- } catch {
32
- return { ...DEFAULTS };
33
- }
34
- }
35
-
36
- export function saveConfig(config: Partial<CliConfig>): void {
37
- if (!existsSync(CONFIG_DIR)) {
38
- mkdirSync(CONFIG_DIR, { recursive: true });
39
- }
40
- const current = loadConfig();
41
- const merged = { ...current, ...config };
42
- writeFileSync(CONFIG_FILE, JSON.stringify(merged, null, 2), 'utf-8');
43
- }
44
-
45
- export function clearConfig(): void {
46
- if (existsSync(CONFIG_FILE)) {
47
- writeFileSync(CONFIG_FILE, JSON.stringify(DEFAULTS, null, 2), 'utf-8');
48
- }
49
- }
50
-
51
- export function getConfigPath(): string {
52
- return CONFIG_FILE;
53
- }