@nordsym/apiclaw 1.7.3 → 1.7.5

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 (219) hide show
  1. package/convex/_generated/api.d.ts +115 -0
  2. package/convex/_generated/api.js +23 -0
  3. package/convex/_generated/dataModel.d.ts +60 -0
  4. package/convex/_generated/server.d.ts +143 -0
  5. package/convex/_generated/server.js +93 -0
  6. package/convex/adminActivate.d.ts +3 -0
  7. package/convex/adminActivate.d.ts.map +1 -0
  8. package/convex/adminActivate.js +47 -0
  9. package/convex/adminActivate.js.map +1 -0
  10. package/convex/adminActivate.ts +54 -0
  11. package/convex/adminStats.d.ts +3 -0
  12. package/convex/adminStats.d.ts.map +1 -0
  13. package/convex/adminStats.js +42 -0
  14. package/convex/adminStats.js.map +1 -0
  15. package/convex/adminStats.ts +44 -0
  16. package/convex/agents.d.ts +76 -0
  17. package/convex/agents.d.ts.map +1 -0
  18. package/convex/agents.js +699 -0
  19. package/convex/agents.js.map +1 -0
  20. package/convex/agents.ts +814 -0
  21. package/convex/analytics.d.ts +5 -0
  22. package/convex/analytics.d.ts.map +1 -0
  23. package/convex/analytics.js +166 -0
  24. package/convex/analytics.js.map +1 -0
  25. package/convex/analytics.ts +186 -0
  26. package/convex/billing.d.ts +88 -0
  27. package/convex/billing.d.ts.map +1 -0
  28. package/convex/billing.js +655 -0
  29. package/convex/billing.js.map +1 -0
  30. package/convex/billing.ts +791 -0
  31. package/convex/capabilities.d.ts +9 -0
  32. package/convex/capabilities.d.ts.map +1 -0
  33. package/convex/capabilities.js +145 -0
  34. package/convex/capabilities.js.map +1 -0
  35. package/convex/capabilities.ts +157 -0
  36. package/convex/chains.d.ts +68 -0
  37. package/convex/chains.d.ts.map +1 -0
  38. package/convex/chains.js +1105 -0
  39. package/convex/chains.js.map +1 -0
  40. package/convex/chains.ts +1318 -0
  41. package/convex/credits.d.ts +25 -0
  42. package/convex/credits.d.ts.map +1 -0
  43. package/convex/credits.js +186 -0
  44. package/convex/credits.js.map +1 -0
  45. package/convex/credits.ts +211 -0
  46. package/convex/crons.d.ts +3 -0
  47. package/convex/crons.d.ts.map +1 -0
  48. package/convex/crons.js +17 -0
  49. package/convex/crons.js.map +1 -0
  50. package/convex/crons.ts +28 -0
  51. package/convex/directCall.d.ts +72 -0
  52. package/convex/directCall.d.ts.map +1 -0
  53. package/convex/directCall.js +627 -0
  54. package/convex/directCall.js.map +1 -0
  55. package/convex/directCall.ts +678 -0
  56. package/convex/earnProgress.d.ts +58 -0
  57. package/convex/earnProgress.d.ts.map +1 -0
  58. package/convex/earnProgress.js +649 -0
  59. package/convex/earnProgress.js.map +1 -0
  60. package/convex/earnProgress.ts +753 -0
  61. package/convex/email.d.ts +14 -0
  62. package/convex/email.d.ts.map +1 -0
  63. package/convex/email.js +300 -0
  64. package/convex/email.js.map +1 -0
  65. package/convex/email.ts +329 -0
  66. package/convex/feedback.d.ts +7 -0
  67. package/convex/feedback.d.ts.map +1 -0
  68. package/convex/feedback.js +227 -0
  69. package/convex/feedback.js.map +1 -0
  70. package/convex/feedback.ts +265 -0
  71. package/convex/http.d.ts +3 -0
  72. package/convex/http.d.ts.map +1 -0
  73. package/convex/http.js +1405 -0
  74. package/convex/http.js.map +1 -0
  75. package/convex/http.ts +1577 -0
  76. package/convex/inbound.d.ts +2 -0
  77. package/convex/inbound.d.ts.map +1 -0
  78. package/convex/inbound.js +32 -0
  79. package/convex/inbound.js.map +1 -0
  80. package/convex/inbound.ts +32 -0
  81. package/convex/logs.d.ts +48 -0
  82. package/convex/logs.d.ts.map +1 -0
  83. package/convex/logs.js +592 -0
  84. package/convex/logs.js.map +1 -0
  85. package/convex/logs.ts +662 -0
  86. package/convex/mou.d.ts +6 -0
  87. package/convex/mou.d.ts.map +1 -0
  88. package/convex/mou.js +82 -0
  89. package/convex/mou.js.map +1 -0
  90. package/convex/mou.ts +91 -0
  91. package/convex/providerKeys.d.ts +31 -0
  92. package/convex/providerKeys.d.ts.map +1 -0
  93. package/convex/providerKeys.js +257 -0
  94. package/convex/providerKeys.js.map +1 -0
  95. package/convex/providerKeys.ts +289 -0
  96. package/convex/providers.d.ts +32 -0
  97. package/convex/providers.d.ts.map +1 -0
  98. package/convex/providers.js +814 -0
  99. package/convex/providers.js.map +1 -0
  100. package/convex/providers.ts +909 -0
  101. package/convex/purchases.d.ts +7 -0
  102. package/convex/purchases.d.ts.map +1 -0
  103. package/convex/purchases.js +157 -0
  104. package/convex/purchases.js.map +1 -0
  105. package/convex/purchases.ts +183 -0
  106. package/convex/ratelimit.d.ts +4 -0
  107. package/convex/ratelimit.d.ts.map +1 -0
  108. package/convex/ratelimit.js +91 -0
  109. package/convex/ratelimit.js.map +1 -0
  110. package/convex/ratelimit.ts +104 -0
  111. package/convex/schema.ts +805 -0
  112. package/convex/searchLogs.d.ts +4 -0
  113. package/convex/searchLogs.d.ts.map +1 -0
  114. package/convex/searchLogs.js +129 -0
  115. package/convex/searchLogs.js.map +1 -0
  116. package/convex/searchLogs.ts +146 -0
  117. package/convex/seedAPILayerAPIs.d.ts +7 -0
  118. package/convex/seedAPILayerAPIs.d.ts.map +1 -0
  119. package/convex/seedAPILayerAPIs.js +177 -0
  120. package/convex/seedAPILayerAPIs.js.map +1 -0
  121. package/convex/seedAPILayerAPIs.ts +191 -0
  122. package/convex/seedDirectCallConfigs.d.ts +2 -0
  123. package/convex/seedDirectCallConfigs.d.ts.map +1 -0
  124. package/convex/seedDirectCallConfigs.js +324 -0
  125. package/convex/seedDirectCallConfigs.js.map +1 -0
  126. package/convex/seedDirectCallConfigs.ts +336 -0
  127. package/convex/seedPratham.d.ts +6 -0
  128. package/convex/seedPratham.d.ts.map +1 -0
  129. package/convex/seedPratham.js +150 -0
  130. package/convex/seedPratham.js.map +1 -0
  131. package/convex/seedPratham.ts +161 -0
  132. package/convex/spendAlerts.d.ts +36 -0
  133. package/convex/spendAlerts.d.ts.map +1 -0
  134. package/convex/spendAlerts.js +380 -0
  135. package/convex/spendAlerts.js.map +1 -0
  136. package/convex/spendAlerts.ts +442 -0
  137. package/convex/stripeActions.d.ts +19 -0
  138. package/convex/stripeActions.d.ts.map +1 -0
  139. package/convex/stripeActions.js +411 -0
  140. package/convex/stripeActions.js.map +1 -0
  141. package/convex/stripeActions.ts +512 -0
  142. package/convex/teams.d.ts +21 -0
  143. package/convex/teams.d.ts.map +1 -0
  144. package/convex/teams.js +215 -0
  145. package/convex/teams.js.map +1 -0
  146. package/convex/teams.ts +243 -0
  147. package/convex/telemetry.d.ts +4 -0
  148. package/convex/telemetry.d.ts.map +1 -0
  149. package/convex/telemetry.js +74 -0
  150. package/convex/telemetry.js.map +1 -0
  151. package/convex/telemetry.ts +81 -0
  152. package/convex/tsconfig.json +25 -0
  153. package/convex/updateAPIStatus.d.ts +6 -0
  154. package/convex/updateAPIStatus.d.ts.map +1 -0
  155. package/convex/updateAPIStatus.js +40 -0
  156. package/convex/updateAPIStatus.js.map +1 -0
  157. package/convex/updateAPIStatus.ts +45 -0
  158. package/convex/usage.d.ts +27 -0
  159. package/convex/usage.d.ts.map +1 -0
  160. package/convex/usage.js +229 -0
  161. package/convex/usage.js.map +1 -0
  162. package/convex/usage.ts +260 -0
  163. package/convex/waitlist.d.ts +4 -0
  164. package/convex/waitlist.d.ts.map +1 -0
  165. package/convex/waitlist.js +49 -0
  166. package/convex/waitlist.js.map +1 -0
  167. package/convex/waitlist.ts +55 -0
  168. package/convex/webhooks.d.ts +12 -0
  169. package/convex/webhooks.d.ts.map +1 -0
  170. package/convex/webhooks.js +410 -0
  171. package/convex/webhooks.js.map +1 -0
  172. package/convex/webhooks.ts +494 -0
  173. package/convex/workspaces.d.ts +31 -0
  174. package/convex/workspaces.d.ts.map +1 -0
  175. package/convex/workspaces.js +975 -0
  176. package/convex/workspaces.js.map +1 -0
  177. package/convex/workspaces.ts +1130 -0
  178. package/dist/bin.js +0 -0
  179. package/dist/index.js +9 -0
  180. package/dist/index.js.map +1 -1
  181. package/package.json +1 -1
  182. package/src/index.ts +10 -0
  183. package/dist/chain-types.d.ts +0 -187
  184. package/dist/chain-types.d.ts.map +0 -1
  185. package/dist/chain-types.js +0 -33
  186. package/dist/chain-types.js.map +0 -1
  187. package/dist/registry/apis.json.bak +0 -248811
  188. package/dist/src/bin.js +0 -17
  189. package/dist/src/capability-router.js +0 -240
  190. package/dist/src/chainExecutor.js +0 -451
  191. package/dist/src/chainResolver.js +0 -518
  192. package/dist/src/cli/commands/doctor.js +0 -324
  193. package/dist/src/cli/commands/mcp-install.js +0 -255
  194. package/dist/src/cli/commands/restore.js +0 -259
  195. package/dist/src/cli/commands/setup.js +0 -205
  196. package/dist/src/cli/commands/uninstall.js +0 -188
  197. package/dist/src/cli/index.js +0 -111
  198. package/dist/src/cli.js +0 -302
  199. package/dist/src/confirmation.js +0 -240
  200. package/dist/src/credentials.js +0 -357
  201. package/dist/src/credits.js +0 -260
  202. package/dist/src/crypto.js +0 -66
  203. package/dist/src/discovery.js +0 -504
  204. package/dist/src/enterprise/env.js +0 -123
  205. package/dist/src/enterprise/script-generator.js +0 -460
  206. package/dist/src/execute-dynamic.js +0 -473
  207. package/dist/src/execute.js +0 -1727
  208. package/dist/src/index.js +0 -2062
  209. package/dist/src/metered.js +0 -80
  210. package/dist/src/open-apis.js +0 -276
  211. package/dist/src/proxy.js +0 -28
  212. package/dist/src/session.js +0 -86
  213. package/dist/src/stripe.js +0 -407
  214. package/dist/src/telemetry.js +0 -49
  215. package/dist/src/types.js +0 -2
  216. package/dist/src/utils/backup.js +0 -181
  217. package/dist/src/utils/config.js +0 -220
  218. package/dist/src/utils/os.js +0 -105
  219. package/dist/src/utils/paths.js +0 -159
@@ -1,504 +0,0 @@
1
- // Discovery engine for APIvault
2
- // MVP: Keyword matching. Future: Embeddings + semantic search
3
- import { readFileSync } from 'fs';
4
- import { fileURLToPath } from 'url';
5
- import { dirname, join } from 'path';
6
- import { openAPIs, isOpenAPI } from './open-apis.js';
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
- const apisData = JSON.parse(readFileSync(join(__dirname, 'registry', 'apis.json'), 'utf-8'));
10
- const apis = apisData.apis;
11
- // Direct Call provider specs (hardcoded handlers with params)
12
- // Ordered: AI-first (models, LLM routing, audio), then infrastructure (code, web, search, email, SMS)
13
- const DIRECT_CALL_SPECS = {
14
- openrouter: {
15
- description: 'LLM routing (100+ models)',
16
- auth: 'bearer',
17
- docs: 'https://openrouter.ai/docs',
18
- actions: {
19
- chat: {
20
- desc: 'Chat completion',
21
- params: [
22
- { name: 'messages', required: true, desc: 'Array of {role, content}' },
23
- { name: 'model', required: false, desc: 'Model ID (default: claude-3-haiku)' },
24
- { name: 'max_tokens', required: false, desc: 'Max response tokens (default: 1000)' },
25
- ],
26
- },
27
- },
28
- },
29
- replicate: {
30
- description: 'Run any AI model (images, video, audio)',
31
- auth: 'bearer',
32
- docs: 'https://replicate.com/docs',
33
- actions: {
34
- run: {
35
- desc: 'Run a model',
36
- params: [
37
- { name: 'model', required: true, desc: 'Model ID (e.g., stability-ai/sdxl:...)' },
38
- { name: 'input', required: true, desc: 'Model input parameters' },
39
- ],
40
- },
41
- list_models: {
42
- desc: 'List available models',
43
- params: [],
44
- },
45
- },
46
- },
47
- elevenlabs: {
48
- description: 'Text-to-speech',
49
- auth: 'api_key',
50
- docs: 'https://elevenlabs.io/docs',
51
- actions: {
52
- text_to_speech: {
53
- desc: 'Generate audio from text',
54
- params: [
55
- { name: 'text', required: true, desc: 'Text to speak' },
56
- { name: 'voice_id', required: false, desc: 'Voice ID (default: Rachel)' },
57
- { name: 'model_id', required: false, desc: 'Model ID' },
58
- ],
59
- },
60
- },
61
- },
62
- e2b: {
63
- description: 'Code sandbox for AI agents',
64
- auth: 'api_key',
65
- docs: 'https://e2b.dev/docs',
66
- actions: {
67
- run_code: {
68
- desc: 'Execute code in sandbox',
69
- params: [
70
- { name: 'code', required: true, desc: 'Code to run' },
71
- { name: 'language', required: false, desc: 'Language (default: python)' },
72
- ],
73
- },
74
- run_shell: {
75
- desc: 'Execute shell command',
76
- params: [
77
- { name: 'command', required: true, desc: 'Shell command' },
78
- ],
79
- },
80
- },
81
- },
82
- firecrawl: {
83
- description: 'Web scraping and crawling',
84
- auth: 'bearer',
85
- docs: 'https://firecrawl.dev/docs',
86
- actions: {
87
- scrape: {
88
- desc: 'Scrape a URL',
89
- params: [
90
- { name: 'url', required: true, desc: 'URL to scrape' },
91
- { name: 'formats', required: false, desc: 'Output formats (default: ["markdown"])' },
92
- ],
93
- },
94
- crawl: {
95
- desc: 'Start a crawl job',
96
- params: [
97
- { name: 'url', required: true, desc: 'Starting URL' },
98
- { name: 'limit', required: false, desc: 'Max pages (default: 10)' },
99
- ],
100
- },
101
- map: {
102
- desc: 'Map site structure',
103
- params: [
104
- { name: 'url', required: true, desc: 'URL to map' },
105
- ],
106
- },
107
- },
108
- },
109
- github: {
110
- description: 'Code repos and developer data',
111
- auth: 'bearer',
112
- docs: 'https://docs.github.com/rest',
113
- actions: {
114
- search_repos: {
115
- desc: 'Search repositories',
116
- params: [
117
- { name: 'query', required: true, desc: 'Search query' },
118
- { name: 'sort', required: false, desc: 'Sort by (default: stars)' },
119
- { name: 'limit', required: false, desc: 'Max results (default: 10)' },
120
- ],
121
- },
122
- get_repo: {
123
- desc: 'Get repo details',
124
- params: [
125
- { name: 'owner', required: true, desc: 'Repo owner' },
126
- { name: 'repo', required: true, desc: 'Repo name' },
127
- ],
128
- },
129
- list_issues: {
130
- desc: 'List issues',
131
- params: [
132
- { name: 'owner', required: true, desc: 'Repo owner' },
133
- { name: 'repo', required: true, desc: 'Repo name' },
134
- { name: 'state', required: false, desc: 'State filter (default: open)' },
135
- ],
136
- },
137
- create_issue: {
138
- desc: 'Create issue',
139
- params: [
140
- { name: 'owner', required: true, desc: 'Repo owner' },
141
- { name: 'repo', required: true, desc: 'Repo name' },
142
- { name: 'title', required: true, desc: 'Issue title' },
143
- { name: 'body', required: false, desc: 'Issue body' },
144
- ],
145
- },
146
- get_file: {
147
- desc: 'Get file contents',
148
- params: [
149
- { name: 'owner', required: true, desc: 'Repo owner' },
150
- { name: 'repo', required: true, desc: 'Repo name' },
151
- { name: 'path', required: true, desc: 'File path' },
152
- ],
153
- },
154
- },
155
- },
156
- brave_search: {
157
- description: 'Web search API',
158
- auth: 'api_key',
159
- docs: 'https://api.search.brave.com/docs',
160
- actions: {
161
- search: {
162
- desc: 'Search the web',
163
- params: [
164
- { name: 'query', required: true, desc: 'Search query' },
165
- { name: 'count', required: false, desc: 'Number of results (default: 5)' },
166
- ],
167
- },
168
- },
169
- },
170
- resend: {
171
- description: 'Email API',
172
- auth: 'bearer',
173
- docs: 'https://resend.com/docs',
174
- actions: {
175
- send_email: {
176
- desc: 'Send email',
177
- params: [
178
- { name: 'to', required: true, desc: 'Recipient email' },
179
- { name: 'subject', required: true, desc: 'Email subject' },
180
- { name: 'html', required: false, desc: 'HTML body' },
181
- { name: 'text', required: false, desc: 'Plain text body' },
182
- { name: 'from', required: false, desc: 'Sender (default: noreply@apiclaw.nordsym.com)' },
183
- ],
184
- },
185
- },
186
- },
187
- '46elks': {
188
- description: 'Swedish SMS and voice API',
189
- auth: 'basic',
190
- docs: 'https://46elks.com/docs',
191
- actions: {
192
- send_sms: {
193
- desc: 'Send SMS message',
194
- params: [
195
- { name: 'to', required: true, desc: 'Phone number (+46...)' },
196
- { name: 'message', required: true, desc: 'SMS text (max 160 chars for 1 segment)' },
197
- { name: 'from', required: false, desc: 'Sender ID (default: APIClaw)' },
198
- ],
199
- },
200
- },
201
- },
202
- twilio: {
203
- description: 'Global SMS and voice API',
204
- auth: 'basic',
205
- docs: 'https://www.twilio.com/docs',
206
- actions: {
207
- send_sms: {
208
- desc: 'Send SMS message',
209
- params: [
210
- { name: 'to', required: true, desc: 'Phone number (E.164 format)' },
211
- { name: 'message', required: true, desc: 'SMS text' },
212
- { name: 'from', required: false, desc: 'Sender phone number' },
213
- ],
214
- },
215
- },
216
- },
217
- apilayer: {
218
- description: 'APILayer marketplace — currency, news, scraping, PDFs, verification & more',
219
- auth: 'api_key',
220
- docs: 'https://apilayer.com',
221
- actions: {
222
- exchange_rates: {
223
- desc: 'Get live or historical currency exchange rates',
224
- params: [
225
- { name: 'base', required: false, desc: 'Base currency (default: USD)' },
226
- { name: 'symbols', required: false, desc: 'Comma-separated target currencies' },
227
- { name: 'date', required: false, desc: 'Historical date YYYY-MM-DD (omit for live)' },
228
- ],
229
- },
230
- market_data: {
231
- desc: 'End-of-day stock market data',
232
- params: [
233
- { name: 'symbols', required: true, desc: 'Stock ticker(s), comma-separated e.g. AAPL,MSFT' },
234
- { name: 'date_from', required: false, desc: 'Start date YYYY-MM-DD' },
235
- { name: 'date_to', required: false, desc: 'End date YYYY-MM-DD' },
236
- ],
237
- },
238
- aviation: {
239
- desc: 'Real-time flight data and tracking',
240
- params: [
241
- { name: 'flight_iata', required: false, desc: 'IATA flight number e.g. AA100' },
242
- { name: 'dep_iata', required: false, desc: 'Departure airport IATA code' },
243
- { name: 'arr_iata', required: false, desc: 'Arrival airport IATA code' },
244
- ],
245
- },
246
- pdf_generate: {
247
- desc: 'Generate PDF from URL or HTML',
248
- params: [
249
- { name: 'document_url', required: false, desc: 'URL to convert to PDF' },
250
- { name: 'document_html', required: false, desc: 'HTML string to convert (alternative to URL)' },
251
- { name: 'page_size', required: false, desc: 'Page size: A4, Letter, etc (default: A4)' },
252
- ],
253
- },
254
- screenshot: {
255
- desc: 'Capture full-page screenshot of any URL',
256
- params: [
257
- { name: 'url', required: true, desc: 'URL to screenshot' },
258
- { name: 'viewport', required: false, desc: 'Viewport size e.g. 1440x900 (default)' },
259
- { name: 'fullpage', required: false, desc: '1 for full page, 0 for viewport only (default: 0)' },
260
- ],
261
- },
262
- verify_email: {
263
- desc: 'Validate email address format and deliverability',
264
- params: [
265
- { name: 'email', required: true, desc: 'Email address to verify' },
266
- ],
267
- },
268
- verify_number: {
269
- desc: 'Validate and lookup phone number details',
270
- params: [
271
- { name: 'number', required: true, desc: 'Phone number in E.164 format e.g. +46701234567' },
272
- ],
273
- },
274
- vat_check: {
275
- desc: 'Validate EU VAT number',
276
- params: [
277
- { name: 'vat_number', required: true, desc: 'EU VAT number e.g. SE556012345601' },
278
- ],
279
- },
280
- world_news: {
281
- desc: 'Extract and analyze news articles from a URL',
282
- params: [
283
- { name: 'url', required: true, desc: 'URL of the news article to analyze' },
284
- { name: 'analyze', required: false, desc: 'Whether to analyze the news (default: true)' },
285
- ],
286
- },
287
- finance_news: {
288
- desc: 'Latest financial and stock market news',
289
- params: [
290
- { name: 'tickers', required: false, desc: 'Stock tickers comma-separated e.g. AAPL,TSLA' },
291
- { name: 'text', required: false, desc: 'Keyword filter' },
292
- { name: 'number', required: false, desc: 'Number of results (default: 5)' },
293
- ],
294
- },
295
- scrape: {
296
- desc: 'Advanced web scraper — returns clean page content',
297
- params: [
298
- { name: 'url', required: true, desc: 'URL to scrape' },
299
- ],
300
- },
301
- image_crop: {
302
- desc: 'Smart crop an image to specified dimensions',
303
- params: [
304
- { name: 'url', required: true, desc: 'Image URL to crop' },
305
- { name: 'width', required: false, desc: 'Target width in pixels' },
306
- { name: 'height', required: false, desc: 'Target height in pixels' },
307
- ],
308
- },
309
- skills: {
310
- desc: 'Search 7000+ professional skills database',
311
- params: [
312
- { name: 'q', required: true, desc: 'Skill search query e.g. "machine learning"' },
313
- { name: 'count', required: false, desc: 'Number of results (default: 10)' },
314
- ],
315
- },
316
- form_submit: {
317
- desc: 'Submit form data to a FormAPI endpoint',
318
- params: [
319
- { name: 'endpoint', required: true, desc: 'FormAPI endpoint path' },
320
- { name: 'data', required: false, desc: 'Form data object to submit' },
321
- ],
322
- },
323
- },
324
- },
325
- };
326
- /**
327
- * Discover APIs based on a natural language query
328
- * MVP uses keyword matching; production would use embeddings
329
- */
330
- export function discoverAPIs(query, options = {}) {
331
- const { category, maxResults = 5, maxPrice, region } = options;
332
- const queryLower = query.toLowerCase();
333
- const queryWords = queryLower.split(/\s+/).filter(w => w.length > 2);
334
- const results = [];
335
- for (const api of apis) {
336
- // Category filter
337
- if (category && api.category !== category)
338
- continue;
339
- // Region filter
340
- if (region && api.regions && !api.regions.includes(region) && !api.regions.includes('global'))
341
- continue;
342
- // Calculate relevance score
343
- let score = 0;
344
- const matchReasons = [];
345
- // Check keywords
346
- for (const word of queryWords) {
347
- // Direct keyword match
348
- if (api.keywords?.some(k => k.includes(word))) {
349
- score += 10;
350
- matchReasons.push(`keyword: ${word}`);
351
- }
352
- // Capability match
353
- if (api.capabilities?.some(c => c.includes(word))) {
354
- score += 15;
355
- matchReasons.push(`capability: ${word}`);
356
- }
357
- // Name match
358
- if (api.name.toLowerCase().includes(word)) {
359
- score += 20;
360
- matchReasons.push(`name: ${word}`);
361
- }
362
- // Description match
363
- if (api.description.toLowerCase().includes(word)) {
364
- score += 5;
365
- matchReasons.push(`description: ${word}`);
366
- }
367
- // Feature match
368
- if (api.features?.some(f => f.toLowerCase().includes(word))) {
369
- score += 8;
370
- matchReasons.push(`feature: ${word}`);
371
- }
372
- }
373
- // Boost for high success rate (default to 0.8 if not set)
374
- score += (api.agent_success_rate ?? 0.8) * 10;
375
- // Boost for low latency (default to 500ms if not set)
376
- score += Math.max(0, (1000 - (api.avg_latency_ms ?? 500)) / 100);
377
- // Boost for free tier
378
- if (api.pricing?.free_tier) {
379
- score += 5;
380
- matchReasons.push('has free tier');
381
- }
382
- if (score > 0) {
383
- results.push({
384
- provider: api,
385
- relevance_score: Math.round(score * 100) / 100,
386
- match_reasons: [...new Set(matchReasons)]
387
- });
388
- }
389
- }
390
- // Sort by relevance
391
- results.sort((a, b) => b.relevance_score - a.relevance_score);
392
- return results.slice(0, maxResults);
393
- }
394
- /**
395
- * Get detailed information about a specific API
396
- * @param apiId - The API provider ID
397
- * @param options.compact - If true, returns minified spec (saves ~60% tokens)
398
- */
399
- export function getAPIDetails(apiId, options = {}) {
400
- const { compact = false } = options;
401
- // Check if it's a Direct Call provider (hardcoded handlers)
402
- const directSpec = DIRECT_CALL_SPECS[apiId];
403
- if (directSpec) {
404
- if (compact) {
405
- // Minified format: ~60% smaller
406
- return {
407
- id: apiId,
408
- type: 'direct_call',
409
- desc: directSpec.description,
410
- auth: directSpec.auth,
411
- actions: Object.fromEntries(Object.entries(directSpec.actions).map(([action, info]) => [
412
- action,
413
- {
414
- params: info.params.map(p => p.required ? p.name : `${p.name}?`),
415
- },
416
- ])),
417
- };
418
- }
419
- return {
420
- id: apiId,
421
- type: 'direct_call',
422
- name: apiId,
423
- description: directSpec.description,
424
- auth_type: directSpec.auth,
425
- docs_url: directSpec.docs,
426
- direct_call: true,
427
- actions: Object.fromEntries(Object.entries(directSpec.actions).map(([action, info]) => [
428
- action,
429
- {
430
- description: info.desc,
431
- params: info.params,
432
- },
433
- ])),
434
- };
435
- }
436
- // Check if it's an Open API (free, no auth)
437
- if (isOpenAPI(apiId)) {
438
- const openApi = openAPIs[apiId];
439
- const actions = Object.keys(openApi.actions);
440
- if (compact) {
441
- return {
442
- id: apiId,
443
- type: 'open',
444
- desc: openApi.description,
445
- auth: 'none',
446
- actions: Object.fromEntries(actions.map(a => [a, { params: [] }])),
447
- };
448
- }
449
- return {
450
- id: apiId,
451
- type: 'open',
452
- name: openApi.name,
453
- description: openApi.description,
454
- auth_type: 'none',
455
- free: true,
456
- actions: Object.fromEntries(actions.map(a => [a, { description: `Execute ${a}`, params: [] }])),
457
- };
458
- }
459
- // Fall back to registry (19,000+ APIs - basic info only)
460
- const registryApi = apis.find(api => api.id === apiId ||
461
- api.name?.toLowerCase() === apiId.toLowerCase());
462
- if (!registryApi) {
463
- return null;
464
- }
465
- if (compact) {
466
- return {
467
- id: registryApi.id || registryApi.name,
468
- type: 'registry',
469
- desc: registryApi.description?.slice(0, 80),
470
- auth: registryApi.auth_type || registryApi.auth || 'unknown',
471
- url: registryApi.base_url || registryApi.baseUrl,
472
- };
473
- }
474
- return {
475
- id: registryApi.id || registryApi.name,
476
- type: 'registry',
477
- name: registryApi.name,
478
- description: registryApi.description,
479
- category: registryApi.category,
480
- auth_type: registryApi.auth_type || registryApi.auth,
481
- base_url: registryApi.base_url || registryApi.baseUrl,
482
- docs_url: registryApi.docs_url || registryApi.docsUrl,
483
- pricing: registryApi.pricing || registryApi.pricing,
484
- note: 'Registry API - use call_api with customer_key or check docs for integration',
485
- };
486
- }
487
- /**
488
- * List all APIs in a category
489
- */
490
- export function listByCategory(category) {
491
- return apis.filter(api => api.category === category);
492
- }
493
- /**
494
- * Get all available categories
495
- */
496
- export function getCategories() {
497
- return [...new Set(apis.map(api => api.category))];
498
- }
499
- /**
500
- * Get all APIs
501
- */
502
- export function getAllAPIs() {
503
- return apis;
504
- }
@@ -1,123 +0,0 @@
1
- /**
2
- * Environment Variable Handler
3
- * Manages APIClaw environment variables for configuration
4
- */
5
- export const ENV_VARS = {
6
- WORKSPACE: 'APICLAW_WORKSPACE',
7
- API_URL: 'APICLAW_API_URL',
8
- DISABLE_TELEMETRY: 'APICLAW_DISABLE_TELEMETRY',
9
- };
10
- export const DEFAULT_API_URL = 'https://api.apiclaw.com';
11
- /**
12
- * Read APIClaw config from environment variables
13
- */
14
- export function readEnvConfig() {
15
- return {
16
- workspace: process.env[ENV_VARS.WORKSPACE] || undefined,
17
- apiUrl: process.env[ENV_VARS.API_URL] || undefined,
18
- disableTelemetry: process.env[ENV_VARS.DISABLE_TELEMETRY] === 'true' ||
19
- process.env[ENV_VARS.DISABLE_TELEMETRY] === '1',
20
- };
21
- }
22
- /**
23
- * Get API URL with fallback to default
24
- */
25
- export function getApiUrl() {
26
- return process.env[ENV_VARS.API_URL] || DEFAULT_API_URL;
27
- }
28
- /**
29
- * Check if telemetry is disabled
30
- */
31
- export function isTelemetryDisabled() {
32
- const val = process.env[ENV_VARS.DISABLE_TELEMETRY];
33
- return val === 'true' || val === '1';
34
- }
35
- /**
36
- * Get pre-configured workspace ID
37
- */
38
- export function getWorkspaceFromEnv() {
39
- return process.env[ENV_VARS.WORKSPACE];
40
- }
41
- /**
42
- * Generate env block for MCP server config
43
- */
44
- export function generateEnvBlock(config) {
45
- const env = {};
46
- if (config.workspace) {
47
- env[ENV_VARS.WORKSPACE] = config.workspace;
48
- }
49
- if (config.apiUrl && config.apiUrl !== DEFAULT_API_URL) {
50
- env[ENV_VARS.API_URL] = config.apiUrl;
51
- }
52
- if (config.disableTelemetry) {
53
- env[ENV_VARS.DISABLE_TELEMETRY] = 'true';
54
- }
55
- return env;
56
- }
57
- /**
58
- * Format env config for display
59
- */
60
- export function formatEnvConfig(config) {
61
- const lines = [];
62
- if (config.workspace) {
63
- lines.push(` Workspace: ${config.workspace}`);
64
- }
65
- if (config.apiUrl) {
66
- lines.push(` API URL: ${config.apiUrl}`);
67
- }
68
- if (config.disableTelemetry) {
69
- lines.push(` Telemetry: Disabled`);
70
- }
71
- return lines;
72
- }
73
- /**
74
- * Validate workspace ID format
75
- */
76
- export function isValidWorkspaceId(id) {
77
- // Workspace IDs should be alphanumeric with dashes/underscores
78
- return /^[a-zA-Z0-9_-]{3,64}$/.test(id);
79
- }
80
- /**
81
- * Validate API URL format
82
- */
83
- export function isValidApiUrl(url) {
84
- try {
85
- const parsed = new URL(url);
86
- return parsed.protocol === 'http:' || parsed.protocol === 'https:';
87
- }
88
- catch {
89
- return false;
90
- }
91
- }
92
- /**
93
- * Generate shell export statements
94
- */
95
- export function generateShellExports(config) {
96
- const lines = [];
97
- if (config.workspace) {
98
- lines.push(`export ${ENV_VARS.WORKSPACE}="${config.workspace}"`);
99
- }
100
- if (config.apiUrl) {
101
- lines.push(`export ${ENV_VARS.API_URL}="${config.apiUrl}"`);
102
- }
103
- if (config.disableTelemetry) {
104
- lines.push(`export ${ENV_VARS.DISABLE_TELEMETRY}="true"`);
105
- }
106
- return lines.join('\n');
107
- }
108
- /**
109
- * Generate PowerShell $env statements
110
- */
111
- export function generatePowerShellEnv(config) {
112
- const lines = [];
113
- if (config.workspace) {
114
- lines.push(`$env:${ENV_VARS.WORKSPACE} = "${config.workspace}"`);
115
- }
116
- if (config.apiUrl) {
117
- lines.push(`$env:${ENV_VARS.API_URL} = "${config.apiUrl}"`);
118
- }
119
- if (config.disableTelemetry) {
120
- lines.push(`$env:${ENV_VARS.DISABLE_TELEMETRY} = "true"`);
121
- }
122
- return lines.join('\n');
123
- }