@spfunctions/cli 1.7.19 → 1.7.22

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.
Files changed (180) hide show
  1. package/dist/101.index.js +1 -0
  2. package/dist/12.index.js +1 -0
  3. package/dist/160.index.js +1 -0
  4. package/dist/174.index.js +1 -0
  5. package/dist/278.index.js +6 -0
  6. package/dist/582.index.js +1 -0
  7. package/dist/641.index.js +324 -0
  8. package/dist/669.index.js +1 -0
  9. package/dist/722.index.js +1 -0
  10. package/dist/788.index.js +1 -0
  11. package/dist/816.index.js +12 -0
  12. package/dist/830.index.js +1 -0
  13. package/dist/921.index.js +1 -0
  14. package/dist/index.js +1 -833
  15. package/package.json +5 -2
  16. package/dist/cache.d.ts +0 -6
  17. package/dist/cache.js +0 -31
  18. package/dist/cache.test.d.ts +0 -1
  19. package/dist/cache.test.js +0 -73
  20. package/dist/client.d.ts +0 -56
  21. package/dist/client.js +0 -205
  22. package/dist/client.test.d.ts +0 -1
  23. package/dist/client.test.js +0 -89
  24. package/dist/commands/agent.d.ts +0 -20
  25. package/dist/commands/agent.js +0 -4119
  26. package/dist/commands/announcements.d.ts +0 -3
  27. package/dist/commands/announcements.js +0 -28
  28. package/dist/commands/augment.d.ts +0 -12
  29. package/dist/commands/augment.js +0 -56
  30. package/dist/commands/balance.d.ts +0 -3
  31. package/dist/commands/balance.js +0 -17
  32. package/dist/commands/book.d.ts +0 -17
  33. package/dist/commands/book.js +0 -220
  34. package/dist/commands/cancel.d.ts +0 -5
  35. package/dist/commands/cancel.js +0 -41
  36. package/dist/commands/context.d.ts +0 -6
  37. package/dist/commands/context.js +0 -208
  38. package/dist/commands/create.d.ts +0 -7
  39. package/dist/commands/create.js +0 -42
  40. package/dist/commands/dashboard.d.ts +0 -14
  41. package/dist/commands/dashboard.js +0 -215
  42. package/dist/commands/delta.d.ts +0 -16
  43. package/dist/commands/delta.js +0 -115
  44. package/dist/commands/edges.d.ts +0 -26
  45. package/dist/commands/edges.js +0 -246
  46. package/dist/commands/evaluate.d.ts +0 -4
  47. package/dist/commands/evaluate.js +0 -30
  48. package/dist/commands/explore.d.ts +0 -14
  49. package/dist/commands/explore.js +0 -116
  50. package/dist/commands/feed.d.ts +0 -13
  51. package/dist/commands/feed.js +0 -73
  52. package/dist/commands/fills.d.ts +0 -4
  53. package/dist/commands/fills.js +0 -29
  54. package/dist/commands/forecast.d.ts +0 -4
  55. package/dist/commands/forecast.js +0 -53
  56. package/dist/commands/get.d.ts +0 -5
  57. package/dist/commands/get.js +0 -98
  58. package/dist/commands/heartbeat.d.ts +0 -20
  59. package/dist/commands/heartbeat.js +0 -73
  60. package/dist/commands/history.d.ts +0 -3
  61. package/dist/commands/history.js +0 -38
  62. package/dist/commands/liquidity.d.ts +0 -14
  63. package/dist/commands/liquidity.js +0 -378
  64. package/dist/commands/list.d.ts +0 -5
  65. package/dist/commands/list.js +0 -38
  66. package/dist/commands/login.d.ts +0 -10
  67. package/dist/commands/login.js +0 -98
  68. package/dist/commands/markets.d.ts +0 -10
  69. package/dist/commands/markets.js +0 -39
  70. package/dist/commands/milestones.d.ts +0 -8
  71. package/dist/commands/milestones.js +0 -56
  72. package/dist/commands/orders.d.ts +0 -4
  73. package/dist/commands/orders.js +0 -28
  74. package/dist/commands/performance.d.ts +0 -11
  75. package/dist/commands/performance.js +0 -250
  76. package/dist/commands/positions.d.ts +0 -19
  77. package/dist/commands/positions.js +0 -294
  78. package/dist/commands/prompt.d.ts +0 -13
  79. package/dist/commands/prompt.js +0 -35
  80. package/dist/commands/publish.d.ts +0 -15
  81. package/dist/commands/publish.js +0 -39
  82. package/dist/commands/query.d.ts +0 -15
  83. package/dist/commands/query.js +0 -132
  84. package/dist/commands/rfq.d.ts +0 -5
  85. package/dist/commands/rfq.js +0 -35
  86. package/dist/commands/scan.d.ts +0 -11
  87. package/dist/commands/scan.js +0 -230
  88. package/dist/commands/schedule.d.ts +0 -3
  89. package/dist/commands/schedule.js +0 -38
  90. package/dist/commands/settlements.d.ts +0 -6
  91. package/dist/commands/settlements.js +0 -50
  92. package/dist/commands/setup.d.ts +0 -24
  93. package/dist/commands/setup.js +0 -700
  94. package/dist/commands/signal.d.ts +0 -6
  95. package/dist/commands/signal.js +0 -32
  96. package/dist/commands/strategies.d.ts +0 -11
  97. package/dist/commands/strategies.js +0 -130
  98. package/dist/commands/telegram.d.ts +0 -15
  99. package/dist/commands/telegram.js +0 -125
  100. package/dist/commands/trade.d.ts +0 -12
  101. package/dist/commands/trade.js +0 -112
  102. package/dist/commands/watch.d.ts +0 -19
  103. package/dist/commands/watch.js +0 -157
  104. package/dist/commands/whatif.d.ts +0 -17
  105. package/dist/commands/whatif.js +0 -209
  106. package/dist/commands/x.d.ts +0 -28
  107. package/dist/commands/x.js +0 -167
  108. package/dist/config.d.ts +0 -55
  109. package/dist/config.js +0 -139
  110. package/dist/config.test.d.ts +0 -1
  111. package/dist/config.test.js +0 -138
  112. package/dist/index.d.ts +0 -20
  113. package/dist/kalshi.d.ts +0 -144
  114. package/dist/kalshi.js +0 -498
  115. package/dist/polymarket.d.ts +0 -237
  116. package/dist/polymarket.js +0 -353
  117. package/dist/polymarket.test.d.ts +0 -1
  118. package/dist/polymarket.test.js +0 -424
  119. package/dist/share.d.ts +0 -4
  120. package/dist/share.js +0 -27
  121. package/dist/skills/loader.d.ts +0 -19
  122. package/dist/skills/loader.js +0 -86
  123. package/dist/telegram/agent-bridge.d.ts +0 -15
  124. package/dist/telegram/agent-bridge.js +0 -573
  125. package/dist/telegram/bot.d.ts +0 -10
  126. package/dist/telegram/bot.js +0 -297
  127. package/dist/telegram/commands.d.ts +0 -11
  128. package/dist/telegram/commands.js +0 -120
  129. package/dist/telegram/format.d.ts +0 -11
  130. package/dist/telegram/format.js +0 -51
  131. package/dist/telegram/format.test.d.ts +0 -1
  132. package/dist/telegram/format.test.js +0 -73
  133. package/dist/telegram/poller.d.ts +0 -6
  134. package/dist/telegram/poller.js +0 -32
  135. package/dist/topics.d.ts +0 -17
  136. package/dist/topics.js +0 -102
  137. package/dist/topics.test.d.ts +0 -1
  138. package/dist/topics.test.js +0 -131
  139. package/dist/tui/border.d.ts +0 -33
  140. package/dist/tui/border.js +0 -87
  141. package/dist/tui/chart.d.ts +0 -19
  142. package/dist/tui/chart.js +0 -117
  143. package/dist/tui/dashboard.d.ts +0 -9
  144. package/dist/tui/dashboard.js +0 -814
  145. package/dist/tui/layout.d.ts +0 -16
  146. package/dist/tui/layout.js +0 -41
  147. package/dist/tui/screen.d.ts +0 -33
  148. package/dist/tui/screen.js +0 -102
  149. package/dist/tui/state.d.ts +0 -40
  150. package/dist/tui/state.js +0 -36
  151. package/dist/tui/widgets/commandbar.d.ts +0 -8
  152. package/dist/tui/widgets/commandbar.js +0 -82
  153. package/dist/tui/widgets/detail.d.ts +0 -9
  154. package/dist/tui/widgets/detail.js +0 -151
  155. package/dist/tui/widgets/edges.d.ts +0 -4
  156. package/dist/tui/widgets/edges.js +0 -34
  157. package/dist/tui/widgets/liquidity.d.ts +0 -9
  158. package/dist/tui/widgets/liquidity.js +0 -142
  159. package/dist/tui/widgets/orders.d.ts +0 -4
  160. package/dist/tui/widgets/orders.js +0 -37
  161. package/dist/tui/widgets/portfolio.d.ts +0 -4
  162. package/dist/tui/widgets/portfolio.js +0 -59
  163. package/dist/tui/widgets/signals.d.ts +0 -4
  164. package/dist/tui/widgets/signals.js +0 -31
  165. package/dist/tui/widgets/statusbar.d.ts +0 -8
  166. package/dist/tui/widgets/statusbar.js +0 -72
  167. package/dist/tui/widgets/thesis.d.ts +0 -4
  168. package/dist/tui/widgets/thesis.js +0 -66
  169. package/dist/tui/widgets/trade.d.ts +0 -9
  170. package/dist/tui/widgets/trade.js +0 -117
  171. package/dist/tui/widgets/upcoming.d.ts +0 -4
  172. package/dist/tui/widgets/upcoming.js +0 -41
  173. package/dist/tui/widgets/whatif.d.ts +0 -7
  174. package/dist/tui/widgets/whatif.js +0 -113
  175. package/dist/types/output.d.ts +0 -412
  176. package/dist/types/output.js +0 -9
  177. package/dist/utils.d.ts +0 -52
  178. package/dist/utils.js +0 -146
  179. package/dist/utils.test.d.ts +0 -1
  180. package/dist/utils.test.js +0 -111
@@ -1,424 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vitest_1 = require("vitest");
4
- const polymarket_js_1 = require("./polymarket.js");
5
- const mockFetch = vitest_1.vi.fn();
6
- vitest_1.vi.stubGlobal('fetch', mockFetch);
7
- (0, vitest_1.beforeEach)(() => {
8
- mockFetch.mockReset();
9
- });
10
- // ============================================================================
11
- // PURE FUNCTIONS (no network)
12
- // ============================================================================
13
- (0, vitest_1.describe)('computeOrderbookDepth', () => {
14
- (0, vitest_1.it)('computes best bid/ask and spread in cents', () => {
15
- const raw = {
16
- market: 'cond1', asset_id: 'tok1', timestamp: '123', hash: 'h',
17
- bids: [
18
- { price: '0.45', size: '200' },
19
- { price: '0.44', size: '150' },
20
- { price: '0.43', size: '100' },
21
- ],
22
- asks: [
23
- { price: '0.48', size: '300' },
24
- { price: '0.49', size: '250' },
25
- { price: '0.50', size: '100' },
26
- ],
27
- };
28
- const depth = (0, polymarket_js_1.computeOrderbookDepth)(raw);
29
- (0, vitest_1.expect)(depth.bestBid).toBe(45);
30
- (0, vitest_1.expect)(depth.bestAsk).toBe(48);
31
- (0, vitest_1.expect)(depth.spread).toBe(3);
32
- });
33
- (0, vitest_1.it)('computes top-3 depth', () => {
34
- const raw = {
35
- market: 'c', asset_id: 't', timestamp: '0', hash: '',
36
- bids: [
37
- { price: '0.50', size: '100' },
38
- { price: '0.49', size: '200' },
39
- { price: '0.48', size: '300' },
40
- { price: '0.47', size: '400' }, // 4th level, not counted
41
- ],
42
- asks: [
43
- { price: '0.52', size: '50' },
44
- { price: '0.53', size: '60' },
45
- { price: '0.54', size: '70' },
46
- ],
47
- };
48
- const depth = (0, polymarket_js_1.computeOrderbookDepth)(raw);
49
- (0, vitest_1.expect)(depth.bidDepthTop3).toBe(600); // 100+200+300
50
- (0, vitest_1.expect)(depth.askDepthTop3).toBe(180); // 50+60+70
51
- (0, vitest_1.expect)(depth.totalBidDepth).toBe(1000); // includes 4th level
52
- (0, vitest_1.expect)(depth.totalAskDepth).toBe(180);
53
- });
54
- (0, vitest_1.it)('sorts bids descending and asks ascending', () => {
55
- const raw = {
56
- market: 'c', asset_id: 't', timestamp: '0', hash: '',
57
- bids: [
58
- { price: '0.40', size: '100' },
59
- { price: '0.50', size: '200' }, // best bid (highest)
60
- ],
61
- asks: [
62
- { price: '0.60', size: '100' },
63
- { price: '0.55', size: '200' }, // best ask (lowest)
64
- ],
65
- };
66
- const depth = (0, polymarket_js_1.computeOrderbookDepth)(raw);
67
- (0, vitest_1.expect)(depth.bestBid).toBe(50);
68
- (0, vitest_1.expect)(depth.bestAsk).toBe(55);
69
- (0, vitest_1.expect)(depth.spread).toBe(5);
70
- });
71
- (0, vitest_1.it)('handles empty orderbook', () => {
72
- const raw = {
73
- market: 'c', asset_id: 't', timestamp: '0', hash: '',
74
- bids: [], asks: [],
75
- };
76
- const depth = (0, polymarket_js_1.computeOrderbookDepth)(raw);
77
- (0, vitest_1.expect)(depth.bestBid).toBe(0);
78
- (0, vitest_1.expect)(depth.bestAsk).toBe(100);
79
- (0, vitest_1.expect)(depth.spread).toBe(100);
80
- (0, vitest_1.expect)(depth.bidDepthTop3).toBe(0);
81
- (0, vitest_1.expect)(depth.askDepthTop3).toBe(0);
82
- (0, vitest_1.expect)(depth.liquidityScore).toBe('low');
83
- });
84
- (0, vitest_1.it)('assigns correct liquidity scores', () => {
85
- // high: spread ≤ 2¢, depth ≥ 500
86
- const high = {
87
- market: 'c', asset_id: 't', timestamp: '0', hash: '',
88
- bids: [{ price: '0.49', size: '300' }],
89
- asks: [{ price: '0.51', size: '300' }],
90
- };
91
- (0, vitest_1.expect)((0, polymarket_js_1.computeOrderbookDepth)(high).liquidityScore).toBe('high');
92
- // medium: spread ≤ 5¢, depth ≥ 100
93
- const medium = {
94
- market: 'c', asset_id: 't', timestamp: '0', hash: '',
95
- bids: [{ price: '0.47', size: '60' }],
96
- asks: [{ price: '0.52', size: '60' }],
97
- };
98
- (0, vitest_1.expect)((0, polymarket_js_1.computeOrderbookDepth)(medium).liquidityScore).toBe('medium');
99
- // low: wide spread
100
- const low = {
101
- market: 'c', asset_id: 't', timestamp: '0', hash: '',
102
- bids: [{ price: '0.30', size: '10' }],
103
- asks: [{ price: '0.70', size: '10' }],
104
- };
105
- (0, vitest_1.expect)((0, polymarket_js_1.computeOrderbookDepth)(low).liquidityScore).toBe('low');
106
- });
107
- });
108
- (0, vitest_1.describe)('scoreLiquidity', () => {
109
- (0, vitest_1.it)('returns high for tight spread + deep book', () => {
110
- (0, vitest_1.expect)((0, polymarket_js_1.scoreLiquidity)(1, 600)).toBe('high');
111
- (0, vitest_1.expect)((0, polymarket_js_1.scoreLiquidity)(2, 500)).toBe('high');
112
- });
113
- (0, vitest_1.it)('returns medium for moderate spread + depth', () => {
114
- (0, vitest_1.expect)((0, polymarket_js_1.scoreLiquidity)(3, 200)).toBe('medium');
115
- (0, vitest_1.expect)((0, polymarket_js_1.scoreLiquidity)(5, 100)).toBe('medium');
116
- });
117
- (0, vitest_1.it)('returns low for wide spread or thin book', () => {
118
- (0, vitest_1.expect)((0, polymarket_js_1.scoreLiquidity)(6, 1000)).toBe('low');
119
- (0, vitest_1.expect)((0, polymarket_js_1.scoreLiquidity)(1, 50)).toBe('low');
120
- (0, vitest_1.expect)((0, polymarket_js_1.scoreLiquidity)(10, 10)).toBe('low');
121
- });
122
- });
123
- (0, vitest_1.describe)('parseClobTokenIds', () => {
124
- (0, vitest_1.it)('parses valid JSON array', () => {
125
- const result = (0, polymarket_js_1.parseClobTokenIds)('["tok_yes_123","tok_no_456"]');
126
- (0, vitest_1.expect)(result).toEqual(['tok_yes_123', 'tok_no_456']);
127
- });
128
- (0, vitest_1.it)('returns null for invalid JSON', () => {
129
- (0, vitest_1.expect)((0, polymarket_js_1.parseClobTokenIds)('not json')).toBeNull();
130
- });
131
- (0, vitest_1.it)('returns null for array with < 2 elements', () => {
132
- (0, vitest_1.expect)((0, polymarket_js_1.parseClobTokenIds)('["only_one"]')).toBeNull();
133
- });
134
- (0, vitest_1.it)('returns null for empty string', () => {
135
- (0, vitest_1.expect)((0, polymarket_js_1.parseClobTokenIds)('')).toBeNull();
136
- });
137
- });
138
- (0, vitest_1.describe)('parseOutcomes', () => {
139
- (0, vitest_1.it)('parses yes/no outcomes', () => {
140
- (0, vitest_1.expect)((0, polymarket_js_1.parseOutcomes)('["Yes","No"]')).toEqual(['Yes', 'No']);
141
- });
142
- (0, vitest_1.it)('parses multi-outcome', () => {
143
- (0, vitest_1.expect)((0, polymarket_js_1.parseOutcomes)('["Trump","Biden","Other"]')).toEqual(['Trump', 'Biden', 'Other']);
144
- });
145
- (0, vitest_1.it)('returns empty for invalid', () => {
146
- (0, vitest_1.expect)((0, polymarket_js_1.parseOutcomes)('bad')).toEqual([]);
147
- });
148
- });
149
- (0, vitest_1.describe)('parseOutcomePrices', () => {
150
- (0, vitest_1.it)('parses price array', () => {
151
- (0, vitest_1.expect)((0, polymarket_js_1.parseOutcomePrices)('[0.65, 0.35]')).toEqual([0.65, 0.35]);
152
- });
153
- (0, vitest_1.it)('returns empty for invalid', () => {
154
- (0, vitest_1.expect)((0, polymarket_js_1.parseOutcomePrices)('')).toEqual([]);
155
- });
156
- });
157
- (0, vitest_1.describe)('toCents', () => {
158
- (0, vitest_1.it)('converts dollars to cents', () => {
159
- (0, vitest_1.expect)((0, polymarket_js_1.toCents)(0.55)).toBe(55);
160
- (0, vitest_1.expect)((0, polymarket_js_1.toCents)(1.0)).toBe(100);
161
- (0, vitest_1.expect)((0, polymarket_js_1.toCents)(0)).toBe(0);
162
- (0, vitest_1.expect)((0, polymarket_js_1.toCents)(0.123)).toBe(12); // rounds
163
- });
164
- });
165
- (0, vitest_1.describe)('polymarketUrl', () => {
166
- (0, vitest_1.it)('builds correct URL', () => {
167
- (0, vitest_1.expect)((0, polymarket_js_1.polymarketUrl)('fed-decision')).toBe('https://polymarket.com/event/fed-decision');
168
- });
169
- });
170
- // ============================================================================
171
- // API FUNCTIONS (mocked fetch)
172
- // ============================================================================
173
- (0, vitest_1.describe)('polymarketSearch', () => {
174
- (0, vitest_1.it)('calls Gamma API with query params', async () => {
175
- mockFetch.mockResolvedValue({
176
- ok: true,
177
- json: () => Promise.resolve({ events: [{ id: '1', title: 'Test' }] }),
178
- });
179
- const events = await (0, polymarket_js_1.polymarketSearch)('recession', 5);
180
- (0, vitest_1.expect)(events).toHaveLength(1);
181
- (0, vitest_1.expect)(events[0].title).toBe('Test');
182
- const url = mockFetch.mock.calls[0][0];
183
- (0, vitest_1.expect)(url).toContain('gamma-api.polymarket.com/public-search');
184
- (0, vitest_1.expect)(url).toContain('q=recession');
185
- (0, vitest_1.expect)(url).toContain('limit_per_type=5');
186
- });
187
- (0, vitest_1.it)('throws on error response', async () => {
188
- mockFetch.mockResolvedValue({ ok: false, status: 500 });
189
- await (0, vitest_1.expect)((0, polymarket_js_1.polymarketSearch)('test')).rejects.toThrow('500');
190
- });
191
- });
192
- (0, vitest_1.describe)('polymarketListEvents', () => {
193
- (0, vitest_1.it)('fetches active events with pagination', async () => {
194
- mockFetch.mockResolvedValue({
195
- ok: true,
196
- json: () => Promise.resolve([{ id: '1' }, { id: '2' }]),
197
- });
198
- const events = await (0, polymarket_js_1.polymarketListEvents)({ limit: 10, offset: 20, order: 'volume_24hr' });
199
- const url = mockFetch.mock.calls[0][0];
200
- (0, vitest_1.expect)(url).toContain('active=true');
201
- (0, vitest_1.expect)(url).toContain('limit=10');
202
- (0, vitest_1.expect)(url).toContain('offset=20');
203
- (0, vitest_1.expect)(url).toContain('order=volume_24hr');
204
- (0, vitest_1.expect)(events).toHaveLength(2);
205
- });
206
- });
207
- (0, vitest_1.describe)('polymarketGetEvent', () => {
208
- (0, vitest_1.it)('fetches single event by ID', async () => {
209
- mockFetch.mockResolvedValue({
210
- ok: true,
211
- json: () => Promise.resolve({ id: '42', title: 'Fed Decision' }),
212
- });
213
- const event = await (0, polymarket_js_1.polymarketGetEvent)('42');
214
- (0, vitest_1.expect)(event.id).toBe('42');
215
- (0, vitest_1.expect)(mockFetch.mock.calls[0][0]).toContain('/events/42');
216
- });
217
- });
218
- (0, vitest_1.describe)('polymarketGetMarket', () => {
219
- (0, vitest_1.it)('fetches single market', async () => {
220
- mockFetch.mockResolvedValue({
221
- ok: true,
222
- json: () => Promise.resolve({ id: 'm1', question: 'Will X happen?' }),
223
- });
224
- const market = await (0, polymarket_js_1.polymarketGetMarket)('m1');
225
- (0, vitest_1.expect)(market.question).toBe('Will X happen?');
226
- });
227
- });
228
- (0, vitest_1.describe)('polymarketListTags', () => {
229
- (0, vitest_1.it)('returns tags array', async () => {
230
- mockFetch.mockResolvedValue({
231
- ok: true,
232
- json: () => Promise.resolve([
233
- { id: '1', label: 'Politics', slug: 'politics' },
234
- { id: '2', label: 'Crypto', slug: 'crypto' },
235
- ]),
236
- });
237
- const tags = await (0, polymarket_js_1.polymarketListTags)();
238
- (0, vitest_1.expect)(tags).toHaveLength(2);
239
- (0, vitest_1.expect)(tags[0].label).toBe('Politics');
240
- });
241
- });
242
- (0, vitest_1.describe)('polymarketGetOrderbook', () => {
243
- (0, vitest_1.it)('fetches raw orderbook', async () => {
244
- mockFetch.mockResolvedValue({
245
- ok: true,
246
- json: () => Promise.resolve({
247
- market: 'cond1', asset_id: 'tok1', timestamp: '123', hash: 'h',
248
- bids: [{ price: '0.45', size: '100' }],
249
- asks: [{ price: '0.55', size: '100' }],
250
- }),
251
- });
252
- const ob = await (0, polymarket_js_1.polymarketGetOrderbook)('tok1');
253
- (0, vitest_1.expect)(ob).not.toBeNull();
254
- (0, vitest_1.expect)(ob.bids).toHaveLength(1);
255
- (0, vitest_1.expect)(mockFetch.mock.calls[0][0]).toContain('clob.polymarket.com/book?token_id=tok1');
256
- });
257
- (0, vitest_1.it)('returns null on error', async () => {
258
- mockFetch.mockResolvedValue({ ok: false, status: 404 });
259
- const ob = await (0, polymarket_js_1.polymarketGetOrderbook)('bad');
260
- (0, vitest_1.expect)(ob).toBeNull();
261
- });
262
- (0, vitest_1.it)('returns null on API error response', async () => {
263
- mockFetch.mockResolvedValue({
264
- ok: true,
265
- json: () => Promise.resolve({ error: 'No orderbook exists' }),
266
- });
267
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetOrderbook)('bad')).toBeNull();
268
- });
269
- (0, vitest_1.it)('returns null on network error', async () => {
270
- mockFetch.mockRejectedValue(new Error('network'));
271
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetOrderbook)('bad')).toBeNull();
272
- });
273
- });
274
- (0, vitest_1.describe)('polymarketGetOrderbookWithDepth', () => {
275
- (0, vitest_1.it)('fetches and computes depth in one call', async () => {
276
- mockFetch.mockResolvedValue({
277
- ok: true,
278
- json: () => Promise.resolve({
279
- market: 'c', asset_id: 't', timestamp: '0', hash: '',
280
- bids: [{ price: '0.49', size: '300' }],
281
- asks: [{ price: '0.51', size: '400' }],
282
- }),
283
- });
284
- const depth = await (0, polymarket_js_1.polymarketGetOrderbookWithDepth)('tok1');
285
- (0, vitest_1.expect)(depth).not.toBeNull();
286
- (0, vitest_1.expect)(depth.bestBid).toBe(49);
287
- (0, vitest_1.expect)(depth.bestAsk).toBe(51);
288
- (0, vitest_1.expect)(depth.spread).toBe(2);
289
- (0, vitest_1.expect)(depth.liquidityScore).toBe('high');
290
- });
291
- (0, vitest_1.it)('returns null when orderbook unavailable', async () => {
292
- mockFetch.mockResolvedValue({ ok: false });
293
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetOrderbookWithDepth)('bad')).toBeNull();
294
- });
295
- });
296
- (0, vitest_1.describe)('polymarketGetMidpoint', () => {
297
- (0, vitest_1.it)('returns midpoint as number', async () => {
298
- mockFetch.mockResolvedValue({
299
- ok: true,
300
- json: () => Promise.resolve({ mid: '0.52' }),
301
- });
302
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetMidpoint)('tok1')).toBe(0.52);
303
- });
304
- (0, vitest_1.it)('returns null on error', async () => {
305
- mockFetch.mockResolvedValue({ ok: false });
306
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetMidpoint)('bad')).toBeNull();
307
- });
308
- });
309
- (0, vitest_1.describe)('polymarketGetSpread', () => {
310
- (0, vitest_1.it)('returns spread as number', async () => {
311
- mockFetch.mockResolvedValue({
312
- ok: true,
313
- json: () => Promise.resolve({ spread: '0.03' }),
314
- });
315
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetSpread)('tok1')).toBe(0.03);
316
- });
317
- });
318
- (0, vitest_1.describe)('polymarketGetMidpoints', () => {
319
- (0, vitest_1.it)('posts batch of token IDs', async () => {
320
- mockFetch.mockResolvedValue({
321
- ok: true,
322
- json: () => Promise.resolve({ tok1: 0.5, tok2: 0.7 }),
323
- });
324
- const result = await (0, polymarket_js_1.polymarketGetMidpoints)(['tok1', 'tok2']);
325
- (0, vitest_1.expect)(result.tok1).toBe(0.5);
326
- (0, vitest_1.expect)(result.tok2).toBe(0.7);
327
- (0, vitest_1.expect)(mockFetch.mock.calls[0][1].method).toBe('POST');
328
- });
329
- (0, vitest_1.it)('returns empty for empty input', async () => {
330
- const result = await (0, polymarket_js_1.polymarketGetMidpoints)([]);
331
- (0, vitest_1.expect)(result).toEqual({});
332
- (0, vitest_1.expect)(mockFetch).not.toHaveBeenCalled();
333
- });
334
- });
335
- (0, vitest_1.describe)('polymarketGetOHLC', () => {
336
- (0, vitest_1.it)('fetches candlestick data', async () => {
337
- const candles = [
338
- { t: 1000, o: 0.5, h: 0.55, l: 0.48, c: 0.52, v: 100 },
339
- ];
340
- mockFetch.mockResolvedValue({
341
- ok: true,
342
- json: () => Promise.resolve(candles),
343
- });
344
- const result = await (0, polymarket_js_1.polymarketGetOHLC)({
345
- tokenId: 'tok1',
346
- startTs: 1000,
347
- fidelity: '1h',
348
- });
349
- (0, vitest_1.expect)(result).toHaveLength(1);
350
- (0, vitest_1.expect)(result[0].c).toBe(0.52);
351
- const url = mockFetch.mock.calls[0][0];
352
- (0, vitest_1.expect)(url).toContain('clob.polymarket.com/ohlc');
353
- (0, vitest_1.expect)(url).toContain('asset_id=tok1');
354
- (0, vitest_1.expect)(url).toContain('fidelity=1h');
355
- });
356
- (0, vitest_1.it)('returns empty array on error', async () => {
357
- mockFetch.mockResolvedValue({ ok: false, status: 400 });
358
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetOHLC)({ tokenId: 'bad', startTs: 0 })).toEqual([]);
359
- });
360
- });
361
- (0, vitest_1.describe)('polymarketGetPriceHistory', () => {
362
- (0, vitest_1.it)('fetches price history with interval', async () => {
363
- mockFetch.mockResolvedValue({
364
- ok: true,
365
- json: () => Promise.resolve({
366
- history: [{ t: 1000, p: 0.5 }, { t: 2000, p: 0.55 }],
367
- }),
368
- });
369
- const result = await (0, polymarket_js_1.polymarketGetPriceHistory)({
370
- tokenId: 'tok1',
371
- interval: '1d',
372
- });
373
- (0, vitest_1.expect)(result).toHaveLength(2);
374
- const url = mockFetch.mock.calls[0][0];
375
- (0, vitest_1.expect)(url).toContain('prices-history');
376
- (0, vitest_1.expect)(url).toContain('interval=1d');
377
- });
378
- (0, vitest_1.it)('fetches with absolute timestamps', async () => {
379
- mockFetch.mockResolvedValue({
380
- ok: true,
381
- json: () => Promise.resolve({ history: [] }),
382
- });
383
- await (0, polymarket_js_1.polymarketGetPriceHistory)({
384
- tokenId: 'tok1',
385
- startTs: 1000,
386
- endTs: 2000,
387
- fidelity: 60,
388
- });
389
- const url = mockFetch.mock.calls[0][0];
390
- (0, vitest_1.expect)(url).toContain('startTs=1000');
391
- (0, vitest_1.expect)(url).toContain('endTs=2000');
392
- (0, vitest_1.expect)(url).toContain('fidelity=60');
393
- (0, vitest_1.expect)(url).not.toContain('interval=');
394
- });
395
- });
396
- (0, vitest_1.describe)('polymarketGetPositions', () => {
397
- (0, vitest_1.it)('fetches positions for wallet address', async () => {
398
- mockFetch.mockResolvedValue({
399
- ok: true,
400
- json: () => Promise.resolve([
401
- { asset: 'tok1', size: 100, outcome: 'Yes' },
402
- ]),
403
- });
404
- const positions = await (0, polymarket_js_1.polymarketGetPositions)('0xabc123');
405
- (0, vitest_1.expect)(positions).toHaveLength(1);
406
- (0, vitest_1.expect)(positions[0].outcome).toBe('Yes');
407
- (0, vitest_1.expect)(mockFetch.mock.calls[0][0]).toContain('data-api.polymarket.com/positions?user=0xabc123');
408
- });
409
- (0, vitest_1.it)('returns empty on error', async () => {
410
- mockFetch.mockResolvedValue({ ok: false });
411
- (0, vitest_1.expect)(await (0, polymarket_js_1.polymarketGetPositions)('bad')).toEqual([]);
412
- });
413
- });
414
- (0, vitest_1.describe)('polymarketGetClosedPositions', () => {
415
- (0, vitest_1.it)('fetches closed positions', async () => {
416
- mockFetch.mockResolvedValue({
417
- ok: true,
418
- json: () => Promise.resolve([{ asset: 'tok1', outcome: 'No' }]),
419
- });
420
- const positions = await (0, polymarket_js_1.polymarketGetClosedPositions)('0xabc');
421
- (0, vitest_1.expect)(positions).toHaveLength(1);
422
- (0, vitest_1.expect)(mockFetch.mock.calls[0][0]).toContain('closed-positions');
423
- });
424
- });
package/dist/share.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * --share helper: POST CLI output to /api/share and print the URL.
3
- */
4
- export declare function shareOutput(command: string, args: string, data: unknown): Promise<void>;
package/dist/share.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- /**
3
- * --share helper: POST CLI output to /api/share and print the URL.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.shareOutput = shareOutput;
7
- const SF_API_URL = process.env.SF_API_URL || 'https://simplefunctions.dev';
8
- async function shareOutput(command, args, data) {
9
- try {
10
- const res = await fetch(`${SF_API_URL}/api/share`, {
11
- method: 'POST',
12
- headers: { 'Content-Type': 'application/json' },
13
- body: JSON.stringify({ command, args, data }),
14
- });
15
- if (!res.ok) {
16
- console.error(`Share failed: ${res.status}`);
17
- return;
18
- }
19
- const { url } = await res.json();
20
- console.log();
21
- console.log(` \x1b[36m${url}\x1b[39m`);
22
- console.log();
23
- }
24
- catch (err) {
25
- console.error(`Share failed: ${err.message}`);
26
- }
27
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Skill loader — reads .md files from the skills directory,
3
- * parses frontmatter, and makes them available as slash commands.
4
- */
5
- export interface Skill {
6
- name: string;
7
- trigger: string;
8
- description: string;
9
- author: string;
10
- version: string;
11
- category: string;
12
- tags: string[];
13
- toolsUsed: string[];
14
- estimatedTime: string;
15
- auto?: string;
16
- prompt: string;
17
- raw: string;
18
- }
19
- export declare function loadSkills(): Skill[];
@@ -1,86 +0,0 @@
1
- "use strict";
2
- /**
3
- * Skill loader — reads .md files from the skills directory,
4
- * parses frontmatter, and makes them available as slash commands.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.loadSkills = loadSkills;
8
- const fs_1 = require("fs");
9
- const path_1 = require("path");
10
- function loadSkills() {
11
- const skills = [];
12
- // Built-in skills from cli/src/skills/
13
- // __dirname works in CJS; resolve to src/skills regardless of whether running from dist/ or src/
14
- const thisDir = __dirname;
15
- const skillsDir = thisDir.includes('dist')
16
- ? (0, path_1.join)(thisDir, '../../src/skills') // running from dist/skills/
17
- : thisDir; // running from src/skills/
18
- let files = [];
19
- try {
20
- files = (0, fs_1.readdirSync)(skillsDir).filter(f => f.endsWith('.md'));
21
- }
22
- catch {
23
- return skills;
24
- }
25
- for (const file of files) {
26
- try {
27
- const raw = (0, fs_1.readFileSync)((0, path_1.join)(skillsDir, file), 'utf-8');
28
- const skill = parseSkillFile(raw);
29
- if (skill)
30
- skills.push(skill);
31
- }
32
- catch { }
33
- }
34
- // User skills from ~/.sf/skills/ (future extensibility)
35
- try {
36
- const home = process.env.HOME || process.env.USERPROFILE || '';
37
- const userDir = (0, path_1.join)(home, '.sf', 'skills');
38
- const userFiles = (0, fs_1.readdirSync)(userDir).filter(f => f.endsWith('.md'));
39
- for (const file of userFiles) {
40
- try {
41
- const raw = (0, fs_1.readFileSync)((0, path_1.join)(userDir, file), 'utf-8');
42
- const skill = parseSkillFile(raw);
43
- if (skill)
44
- skills.push(skill);
45
- }
46
- catch { }
47
- }
48
- }
49
- catch { }
50
- return skills;
51
- }
52
- function parseSkillFile(raw) {
53
- // Parse YAML frontmatter between --- delimiters
54
- const match = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
55
- if (!match)
56
- return null;
57
- const frontmatter = match[1];
58
- const body = match[2].trim();
59
- const meta = {};
60
- for (const line of frontmatter.split('\n')) {
61
- const m = line.match(/^(\w[\w_]*)\s*:\s*(.+)$/);
62
- if (m)
63
- meta[m[1]] = m[2].trim();
64
- }
65
- if (!meta.name || !meta.trigger)
66
- return null;
67
- // Extract the "Instructions" section as the prompt (everything after ## Instructions)
68
- const instructionsMatch = body.match(/## Instructions\n([\s\S]*)$/i);
69
- const prompt = instructionsMatch ? instructionsMatch[1].trim() : body;
70
- // Parse array fields: [a, b, c]
71
- const parseArray = (s) => (s || '').replace(/[\[\]]/g, '').split(',').map(x => x.trim()).filter(Boolean);
72
- return {
73
- name: meta.name,
74
- trigger: meta.trigger,
75
- description: meta.description || '',
76
- author: meta.author || 'unknown',
77
- version: meta.version || '1.0.0',
78
- category: meta.category || 'general',
79
- tags: parseArray(meta.tags),
80
- toolsUsed: parseArray(meta.tools_used),
81
- estimatedTime: meta.estimated_time || '',
82
- auto: meta.auto,
83
- prompt,
84
- raw,
85
- };
86
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Agent bridge — connects Telegram to pi-agent-core
3
- *
4
- * Uses the SAME tools as sf agent --plain. Multi-turn tool calling
5
- * is handled by pi-agent-core's Agent class (not manual OpenRouter calls).
6
- */
7
- import { SFClient } from '../client.js';
8
- interface SessionState {
9
- thesisId: string | null;
10
- agentMessages: any[];
11
- agent?: any;
12
- }
13
- export declare function getOrCreateAgent(sfClient: SFClient, session: SessionState): Promise<any>;
14
- export declare function runAgentMessage(client: SFClient, session: SessionState, userMessage: string): Promise<string>;
15
- export {};