pnpfucius 2.0.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.
@@ -0,0 +1,120 @@
1
+ // Tool registry and executor for PNPFUCIUS - The PNP Exchange CLI
2
+
3
+ import { marketToolDefinitions, executeMarketTool } from './market-tools.js';
4
+ import { analyticsToolDefinitions, executeAnalyticsTool } from './analytics-tools.js';
5
+
6
+ // Combine all tool definitions
7
+ export const tools = [
8
+ ...marketToolDefinitions,
9
+ ...analyticsToolDefinitions
10
+ ];
11
+
12
+ // Tool name to executor mapping
13
+ const toolExecutors = {
14
+ // Market tools
15
+ create_market: executeMarketTool,
16
+ list_markets: executeMarketTool,
17
+ get_market_info: executeMarketTool,
18
+ // Trading tools
19
+ buy_tokens: executeMarketTool,
20
+ sell_tokens: executeMarketTool,
21
+ get_market_prices: executeMarketTool,
22
+ get_balances: executeMarketTool,
23
+ // Redemption tools
24
+ redeem_position: executeMarketTool,
25
+ claim_refund: executeMarketTool,
26
+ // URL-aware market creation
27
+ create_market_from_source: executeMarketTool,
28
+ // PNP Oracle/Settlement tools
29
+ get_settlement_criteria: executeMarketTool,
30
+ get_settlement_data: executeMarketTool,
31
+ wait_for_settlement: executeMarketTool,
32
+ settle_market: executeMarketTool,
33
+ // Market Discovery tools
34
+ discover_all_markets: executeMarketTool,
35
+ get_market_metadata: executeMarketTool,
36
+ get_v2_market_info: executeMarketTool,
37
+ get_p2p_market_info: executeMarketTool,
38
+ // P2P Market tools with custom odds
39
+ create_p2p_market_simple: executeMarketTool,
40
+ create_p2p_market_with_odds: executeMarketTool,
41
+ create_amm_market_with_odds: executeMarketTool,
42
+ // Custom Oracle tools
43
+ create_market_with_oracle: executeMarketTool,
44
+ // V3/P2P Redemption tools
45
+ redeem_v3_position: executeMarketTool,
46
+ redeem_p2p_position: executeMarketTool,
47
+ claim_p2p_refund: executeMarketTool,
48
+ // V3 Trading tools
49
+ buy_v3_tokens: executeMarketTool,
50
+ // Global config
51
+ get_pnp_config: executeMarketTool,
52
+ // Analytics tools
53
+ get_stats: executeAnalyticsTool,
54
+ get_categories: executeAnalyticsTool
55
+ };
56
+
57
+ /**
58
+ * Execute a tool by name with given input
59
+ * @param {string} name - Tool name
60
+ * @param {object} input - Tool input parameters
61
+ * @returns {Promise<object>} Tool result
62
+ */
63
+ export async function executeTool(name, input) {
64
+ const executor = toolExecutors[name];
65
+
66
+ if (!executor) {
67
+ return {
68
+ error: `Unknown tool: ${name}`,
69
+ available_tools: Object.keys(toolExecutors)
70
+ };
71
+ }
72
+
73
+ try {
74
+ const startTime = Date.now();
75
+ const result = await executor(name, input);
76
+ const duration = Date.now() - startTime;
77
+
78
+ return {
79
+ ...result,
80
+ _meta: {
81
+ tool: name,
82
+ duration_ms: duration
83
+ }
84
+ };
85
+ } catch (error) {
86
+ return {
87
+ error: error.message,
88
+ stack: process.env.DEBUG ? error.stack : undefined,
89
+ tool: name
90
+ };
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Get tool definition by name
96
+ * @param {string} name - Tool name
97
+ * @returns {object|null} Tool definition
98
+ */
99
+ export function getToolDefinition(name) {
100
+ return tools.find(t => t.name === name) || null;
101
+ }
102
+
103
+ /**
104
+ * List all available tools
105
+ * @returns {string[]} Tool names
106
+ */
107
+ export function listTools() {
108
+ return tools.map(t => t.name);
109
+ }
110
+
111
+ /**
112
+ * Get tools grouped by category
113
+ * @returns {object} Tools by category
114
+ */
115
+ export function getToolsByCategory() {
116
+ return {
117
+ market: marketToolDefinitions.map(t => t.name),
118
+ analytics: analyticsToolDefinitions.map(t => t.name)
119
+ };
120
+ }