adaptive-memory-multi-model-router 2.14.45 → 2.14.47

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 (605) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.js +8 -2
  3. package/dist/memory/hybridMemory.d.ts +71 -0
  4. package/dist/memory/hybridMemory.js +124 -0
  5. package/dist/memory/reasoningBank.d.ts +88 -0
  6. package/dist/memory/reasoningBank.js +303 -0
  7. package/{docs/llms.txt → llms.txt.bak} +6 -6
  8. package/package.json +13 -84
  9. package/src/index.ts +8 -0
  10. package/src/memory/hybridMemory.ts +155 -0
  11. package/src/memory/reasoningBank.ts +335 -0
  12. package/src/routing/advancedRouter.ts.bak +650 -0
  13. package/test.js.bak +376 -0
  14. package/.dockerignore +0 -82
  15. package/.env.example +0 -303
  16. package/.github/DISCUSSIONS_WELCOME.md +0 -27
  17. package/.github/DISCUSSION_TEMPLATE.yml +0 -5
  18. package/.github/FUNDING.yml +0 -2
  19. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -94
  20. package/.github/ISSUE_TEMPLATE/config.yml +0 -17
  21. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -71
  22. package/.github/PULL_REQUEST_TEMPLATE.md +0 -71
  23. package/.github/dependabot.yml +0 -9
  24. package/.github/workflows/auto-publish.yml +0 -51
  25. package/.github/workflows/ci.yml +0 -263
  26. package/.github/workflows/codeql.yml +0 -38
  27. package/.github/workflows/npm-publish.yml +0 -20
  28. package/.github/workflows/pages.yml +0 -37
  29. package/.github/workflows/stale.yml +0 -54
  30. package/.publish-tick +0 -1
  31. package/.well-known/ai-plugin.json +0 -16
  32. package/AGENT_COUNCIL_FINDINGS.md +0 -142
  33. package/ARCHITECTURE.md +0 -346
  34. package/AUDIT_REPORT.md +0 -28
  35. package/CODE_OF_CONDUCT.md +0 -128
  36. package/CONTRIBUTING.md +0 -50
  37. package/CONTRIBUTORS.md +0 -20
  38. package/Dockerfile +0 -53
  39. package/Dockerfile.proxy +0 -33
  40. package/HEALTH_REPORT.md +0 -118
  41. package/IMPROVEMENT_PLAN.md +0 -107
  42. package/LANDING.md +0 -43
  43. package/LAUNCH-PAIN-DRIVEN.md +0 -339
  44. package/LAUNCH.md +0 -337
  45. package/LAUNCH_CHECKLIST.md +0 -141
  46. package/LAUNCH_SNAPSHOT.md +0 -260
  47. package/MANIFESTO.md +0 -41
  48. package/POPULARITY_BOOSTERS.md +0 -285
  49. package/PR_STATUS_REPORT.md +0 -148
  50. package/REDESIGN.md +0 -95
  51. package/RUNKIT.md +0 -83
  52. package/SECURITY.md +0 -29
  53. package/SUBMISSIONS.md +0 -43
  54. package/_schema.html +0 -53
  55. package/ai-plugin.json +0 -16
  56. package/articles/AI_AGENT_LLM_ROUTING.md +0 -150
  57. package/articles/CHINESE_DIRECTORIES.md +0 -100
  58. package/articles/CHINESE_SUBMISSIONS_READY.md +0 -322
  59. package/articles/COMPETITOR_ALERTS.md +0 -31
  60. package/articles/COMPLETE_POSTING_DIRECTORY.md +0 -147
  61. package/articles/CONTENT_STRUCTURE.md +0 -292
  62. package/articles/DEVTO_COST_GUIDE.md +0 -473
  63. package/articles/DEVTO_FINAL.md +0 -416
  64. package/articles/DEVTO_MULTI_PROVIDER.md +0 -542
  65. package/articles/DEVTO_READY.md +0 -255
  66. package/articles/DEVTO_V2_ANNOUNCEMENT.md +0 -160
  67. package/articles/DEVTO_VIRAL_GROWTH.md +0 -280
  68. package/articles/FRESH_devto.md +0 -460
  69. package/articles/FRESH_devto_2026_05.md +0 -73
  70. package/articles/FRESH_hackernews.md +0 -14
  71. package/articles/FRESH_reddit_ml.md +0 -90
  72. package/articles/FRESH_reddit_node.md +0 -198
  73. package/articles/FRESH_reddit_sideproject.md +0 -72
  74. package/articles/FRESH_reddit_webdev.md +0 -130
  75. package/articles/FROM_ZERO_TO_10K.md +0 -107
  76. package/articles/HN_10X_BETTER.md +0 -430
  77. package/articles/HN_ACCOUNT_GUIDE.md +0 -21
  78. package/articles/HN_CHINESE_STYLE.md +0 -308
  79. package/articles/HN_FINAL.md +0 -148
  80. package/articles/HN_POSTED_VERSION.md +0 -56
  81. package/articles/HN_POST_READY.md +0 -137
  82. package/articles/HN_RESEARCH.md +0 -364
  83. package/articles/HN_SHOW_routerarena.md +0 -17
  84. package/articles/HN_TIMING_GUIDE.md +0 -52
  85. package/articles/INDIEHACKERS_POST.md +0 -52
  86. package/articles/INDIEHACKERS_READY.md +0 -120
  87. package/articles/LLM_BENCHMARK_DEEP_DIVE.md +0 -153
  88. package/articles/MASTER_POSTING_DIRECTORY.md +0 -189
  89. package/articles/NEWSLETTER_SEND_NOW.md +0 -259
  90. package/articles/NEWSLETTER_SUBMISSIONS.md +0 -112
  91. package/articles/PAIN-DRIVEN-devto-v2.md +0 -308
  92. package/articles/PAIN-DRIVEN-devto-v3.md +0 -268
  93. package/articles/PAIN-DRIVEN-devto.md +0 -242
  94. package/articles/PAIN-DRIVEN-hackernews-v2.md +0 -138
  95. package/articles/PAIN-DRIVEN-hackernews-v3.md +0 -151
  96. package/articles/PAIN-DRIVEN-hackernews.md +0 -131
  97. package/articles/PAIN-DRIVEN-reddit-v2.md +0 -301
  98. package/articles/PAIN-DRIVEN-reddit-v3.md +0 -236
  99. package/articles/PAIN-DRIVEN-reddit.md +0 -218
  100. package/articles/PAIN-DRIVEN-twitter-v2.md +0 -110
  101. package/articles/PAIN-DRIVEN-twitter-v3.md +0 -121
  102. package/articles/PAIN-DRIVEN-twitter.md +0 -120
  103. package/articles/PORTKEY_VS_A3M.md +0 -147
  104. package/articles/POSTING_KIT_2026_05.md +0 -67
  105. package/articles/PRESS_KIT_routerarena.md +0 -77
  106. package/articles/PRODUCTHUNT_LISTING.md +0 -48
  107. package/articles/PRODUCTHUNT_READY.md +0 -106
  108. package/articles/PR_PLAN_vault.md +0 -125
  109. package/articles/REDDIT_FINAL.md +0 -232
  110. package/articles/REDDIT_POST.md +0 -67
  111. package/articles/REDDIT_SUBMISSION_READY.md +0 -348
  112. package/articles/ROUTERARENA_LEADER.md +0 -45
  113. package/articles/SHOW_HN_FINAL.md +0 -29
  114. package/articles/TWEETS_10K_DOWNLOADS.md +0 -47
  115. package/articles/TWEETS_BENCHMARK_FIRST.md +0 -46
  116. package/articles/TWEETS_MCP_PLAY.md +0 -51
  117. package/articles/TWEETS_SEQUENTIAL_BROKEN.md +0 -49
  118. package/articles/TWEETS_WHY_BUILD.md +0 -54
  119. package/articles/TWEETS_routerarena_leader.md +0 -53
  120. package/articles/TWEET_STORM_READY.md +0 -165
  121. package/articles/TWITTER_FINAL.md +0 -167
  122. package/articles/WHY_10X_BETTER.md +0 -261
  123. package/articles/WHY_CHINESE_STYLE_BETTER.md +0 -323
  124. package/articles/ai-discoverability-llm-routing.md +0 -210
  125. package/articles/devto-llm-routing.md +0 -138
  126. package/articles/hackernews-show-hn.md +0 -54
  127. package/articles/hashnode-llm-cost-optimization.md +0 -125
  128. package/articles/hn_show_2026_05.md +0 -11
  129. package/articles/medium-building-llm-router.md +0 -205
  130. package/articles/reddit-ml.md +0 -76
  131. package/articles/twitter-thread-cost-savings.md +0 -50
  132. package/articles/youtube-tutorial-script.md +0 -262
  133. package/assets/a3m_3blue1brown.mp4 +0 -0
  134. package/assets/banner.svg +0 -109
  135. package/assets/chart-cost-v2.svg +0 -91
  136. package/assets/chart-cost-v3.svg +0 -143
  137. package/assets/chart-features-v2.svg +0 -132
  138. package/assets/chart-features-v3.svg +0 -211
  139. package/assets/chart-growth-v2.svg +0 -122
  140. package/assets/chart-growth-v3.svg +0 -189
  141. package/assets/cost-comparison.svg +0 -134
  142. package/assets/cost-simple.svg +0 -64
  143. package/assets/demo-hn.gif +0 -0
  144. package/assets/feature-matrix.svg +0 -136
  145. package/assets/growth-chart-animated.svg +0 -76
  146. package/assets/growth-chart.svg +0 -82
  147. package/assets/growth-simple.svg +0 -69
  148. package/assets/hero-diagram.svg +0 -81
  149. package/assets/logo-new.svg +0 -21
  150. package/assets/logo.svg +0 -68
  151. package/assets/provider-comparison.svg +0 -121
  152. package/assets/social-preview-new.svg +0 -100
  153. package/assets/social-preview.svg +0 -194
  154. package/assets/social-v2.svg +0 -130
  155. package/assets/social-v3.svg +0 -212
  156. package/benchmark-provider-results.json +0 -245
  157. package/benchmark-results.json +0 -54
  158. package/council-votes/architecture-vote.md +0 -121
  159. package/council-votes/coverage-vote.md +0 -93
  160. package/data/adaptive-benchmark.json +0 -92
  161. package/data/benchmark-results.json +0 -47
  162. package/data/labeled-benchmark.json +0 -88
  163. package/demo/3blue1brown_video.py +0 -285
  164. package/demo/3blue1brown_video_v2.py +0 -310
  165. package/demo/IMPROVED_PROMPTS.md +0 -229
  166. package/demo/VEO3_PROMPTS.md +0 -269
  167. package/demo/VIDEO_PRODUCTION_GUIDE.md +0 -333
  168. package/demo/a3m_3blue1brown.mp4 +0 -0
  169. package/demo/asciinema-demo.sh +0 -195
  170. package/demo/demo-hn.tape +0 -74
  171. package/demo/demo-script.md +0 -53
  172. package/demo/demo-script.sh +0 -62
  173. package/demo/demo.svg +0 -75
  174. package/demo/frame1_ai_data_center.png +0 -0
  175. package/demo/frame1_sunset_video.mp4 +0 -0
  176. package/demo/frame2_cost_comparison.png +0 -0
  177. package/demo/frame2_cost_comparison_fallback.png +0 -0
  178. package/demo/frame3_parallel_execution.png +0 -0
  179. package/demo/frame3_parallel_execution_fallback.png +0 -0
  180. package/demo/frame4_providers.png +0 -0
  181. package/demo/frame4_providers_fallback.png +0 -0
  182. package/demo/frame5_endcard.png +0 -0
  183. package/demo/frame5_endcard_fallback.png +0 -0
  184. package/demo/new_frame1_hook.png +0 -0
  185. package/demo/new_frame2_proof.png +0 -0
  186. package/demo/new_frame3_wow.png +0 -0
  187. package/demo/new_frame4_social.png +0 -0
  188. package/demo/new_frame5_cta.png +0 -0
  189. package/demo/package.json +0 -13
  190. package/demo/product-video-final.mp4 +0 -0
  191. package/demo/product-video-hype-v1.mp4 +0 -0
  192. package/demo/product-video-v1.mp4 +0 -0
  193. package/demo/public/index.html +0 -762
  194. package/demo/recording.cast +0 -55
  195. package/demo/server.js +0 -405
  196. package/demo-new.tape +0 -71
  197. package/demo-real.sh +0 -198
  198. package/demo-simple.tape +0 -205
  199. package/demo.html +0 -520
  200. package/demo.sh +0 -85
  201. package/demo.tape +0 -259
  202. package/dist/analytics/costAnalytics.d.ts.map +0 -1
  203. package/dist/analytics/costAnalytics.js.map +0 -1
  204. package/dist/benchmark/comprehensive.js.map +0 -1
  205. package/dist/benchmark/reproducible.d.ts.map +0 -1
  206. package/dist/benchmark/reproducible.js.map +0 -1
  207. package/dist/cache/prefixCache.d.ts.map +0 -1
  208. package/dist/cache/prefixCache.js.map +0 -1
  209. package/dist/cache/responseCache.d.ts.map +0 -1
  210. package/dist/cache/responseCache.js.map +0 -1
  211. package/dist/cache/semanticCache.d.ts.map +0 -1
  212. package/dist/cache/semanticCache.js.map +0 -1
  213. package/dist/cli/setupWizard.d.ts.map +0 -1
  214. package/dist/cli/setupWizard.js.map +0 -1
  215. package/dist/cost/budgetEnforcer.d.ts.map +0 -1
  216. package/dist/cost/budgetEnforcer.js.map +0 -1
  217. package/dist/cost/costTracker.d.ts.map +0 -1
  218. package/dist/cost/costTracker.js.map +0 -1
  219. package/dist/ensemble/multiRoundDialog.js.map +0 -1
  220. package/dist/ensemble/shapleyValue.js.map +0 -1
  221. package/dist/integrations/langchainAdapter.d.ts.map +0 -1
  222. package/dist/integrations/langchainAdapter.js.map +0 -1
  223. package/dist/integrations/oauth.d.ts.map +0 -1
  224. package/dist/integrations/oauth.js.map +0 -1
  225. package/dist/integrations/scienceAdapter.js.map +0 -1
  226. package/dist/memory/autoFetch.d.ts.map +0 -1
  227. package/dist/memory/autoFetch.js.map +0 -1
  228. package/dist/memory/episodicMemory.d.ts.map +0 -1
  229. package/dist/memory/episodicMemory.js.map +0 -1
  230. package/dist/memory/memoryTree.d.ts.map +0 -1
  231. package/dist/memory/memoryTree.js.map +0 -1
  232. package/dist/memory/obsidianVault.d.ts.map +0 -1
  233. package/dist/memory/obsidianVault.js.map +0 -1
  234. package/dist/observability/changeWatch.d.ts.map +0 -1
  235. package/dist/observability/changeWatch.js.map +0 -1
  236. package/dist/observability/fatigueDetector.d.ts.map +0 -1
  237. package/dist/observability/fatigueDetector.js.map +0 -1
  238. package/dist/observability/index.d.ts.map +0 -1
  239. package/dist/observability/index.js.map +0 -1
  240. package/dist/observability/metrics.d.ts.map +0 -1
  241. package/dist/observability/metrics.js.map +0 -1
  242. package/dist/observability/middleware.d.ts.map +0 -1
  243. package/dist/observability/middleware.js.map +0 -1
  244. package/dist/observability/tracer.d.ts.map +0 -1
  245. package/dist/observability/tracer.js.map +0 -1
  246. package/dist/observability/types.d.ts.map +0 -1
  247. package/dist/observability/types.js.map +0 -1
  248. package/dist/orchestration/haloOrchestrator.d.ts.map +0 -1
  249. package/dist/orchestration/haloOrchestrator.js.map +0 -1
  250. package/dist/orchestration/mctsWorkflow.d.ts.map +0 -1
  251. package/dist/orchestration/mctsWorkflow.js.map +0 -1
  252. package/dist/providers/localProvider.d.ts.map +0 -1
  253. package/dist/providers/localProvider.js.map +0 -1
  254. package/dist/providers/providerConfig.d.ts.map +0 -1
  255. package/dist/providers/providerConfig.js.map +0 -1
  256. package/dist/providers/registry.d.ts.map +0 -1
  257. package/dist/providers/registry.js.map +0 -1
  258. package/dist/routing/advancedRouter.d.ts.map +0 -1
  259. package/dist/routing/advancedRouter.js.map +0 -1
  260. package/dist/routing/crossModelValidation.d.ts.map +0 -1
  261. package/dist/routing/crossModelValidation.js.map +0 -1
  262. package/dist/routing/providerHealth.d.ts.map +0 -1
  263. package/dist/routing/providerHealth.js.map +0 -1
  264. package/dist/routing/providerRetry.d.ts.map +0 -1
  265. package/dist/routing/providerRetry.js.map +0 -1
  266. package/dist/scripts/banner.js +0 -29
  267. package/dist/security/guardrails.d.ts.map +0 -1
  268. package/dist/security/guardrails.js.map +0 -1
  269. package/dist/server/dashboard.d.ts.map +0 -1
  270. package/dist/server/dashboard.js.map +0 -1
  271. package/dist/server/modelMapper.d.ts.map +0 -1
  272. package/dist/server/modelMapper.js.map +0 -1
  273. package/dist/server/proxyServer.d.ts.map +0 -1
  274. package/dist/server/proxyServer.js.map +0 -1
  275. package/dist/skills/__tests__/skill_manager.test.d.ts +0 -2
  276. package/dist/skills/__tests__/skill_manager.test.d.ts.map +0 -1
  277. package/dist/skills/__tests__/skill_manager.test.js +0 -268
  278. package/dist/skills/__tests__/skill_manager.test.js.map +0 -1
  279. package/dist/tools/tmlpdTools.d.ts.map +0 -1
  280. package/dist/tools/tmlpdTools.js.map +0 -1
  281. package/dist/tui/dashboard.d.ts.map +0 -1
  282. package/dist/tui/dashboard.js.map +0 -1
  283. package/dist/tui/index.d.ts.map +0 -1
  284. package/dist/tui/index.js.map +0 -1
  285. package/dist/utils/batchProcessor.d.ts.map +0 -1
  286. package/dist/utils/batchProcessor.js.map +0 -1
  287. package/dist/utils/compression.d.ts.map +0 -1
  288. package/dist/utils/compression.js.map +0 -1
  289. package/dist/utils/costUtils.d.ts.map +0 -1
  290. package/dist/utils/costUtils.js.map +0 -1
  291. package/dist/utils/reliability.d.ts.map +0 -1
  292. package/dist/utils/reliability.js.map +0 -1
  293. package/dist/utils/sorting.d.ts.map +0 -1
  294. package/dist/utils/sorting.js.map +0 -1
  295. package/dist/utils/speculativeDecoding.d.ts.map +0 -1
  296. package/dist/utils/speculativeDecoding.js.map +0 -1
  297. package/dist/utils/tokenUtils.d.ts.map +0 -1
  298. package/dist/utils/tokenUtils.js.map +0 -1
  299. package/docs/.nojekyll +0 -0
  300. package/docs/ANALYSIS_PRINCIPLES.md +0 -162
  301. package/docs/API.md +0 -855
  302. package/docs/ARCHITECTURAL-IMPROVEMENTS-2025.md +0 -1391
  303. package/docs/ARCHITECTURAL-IMPROVEMENTS-REVISED-2025.md +0 -1051
  304. package/docs/BENCHMARK.md +0 -170
  305. package/docs/CHINESE_PROVIDER_RELIABILITY.md +0 -37
  306. package/docs/CITATIONS.md +0 -74
  307. package/docs/CLAIMS_AND_EVIDENCE.md +0 -58
  308. package/docs/CONFIGURATION.md +0 -476
  309. package/docs/COUNCIL_DECISION.json +0 -816
  310. package/docs/COUNCIL_SUMMARY.md +0 -319
  311. package/docs/COUNCIL_V2.2_DECISION.md +0 -416
  312. package/docs/ENGINEERING_SPEC.md +0 -55
  313. package/docs/FACTORY_RESET.md +0 -34
  314. package/docs/GEO.md +0 -66
  315. package/docs/GEO_OPTIMIZATION.md +0 -30
  316. package/docs/GEO_ROOT_CAUSE.md +0 -136
  317. package/docs/GEO_STATUS.md +0 -85
  318. package/docs/GEO_TEST_RESULTS.md +0 -176
  319. package/docs/HN_CHECKLIST.md +0 -38
  320. package/docs/HN_FOUNDER_COMMENT.md +0 -17
  321. package/docs/HN_SUBMISSION_FINAL.md +0 -180
  322. package/docs/HN_SUBMISSION_V3.md +0 -56
  323. package/docs/IMPROVEMENT_ROADMAP.md +0 -515
  324. package/docs/INTEGRATIONS.md +0 -420
  325. package/docs/LANGCHAIN_INTEGRATION.md +0 -147
  326. package/docs/LLM_COUNCIL_DECISION.md +0 -508
  327. package/docs/MIDDLEWARE_CHAIN.md +0 -35
  328. package/docs/PROMO_CHECKLIST.md +0 -200
  329. package/docs/QUICKSTART.md +0 -271
  330. package/docs/QUICK_START.md +0 -43
  331. package/docs/QUICK_START_VISIBILITY.md +0 -782
  332. package/docs/REDDIT_GAP_ANALYSIS.md +0 -299
  333. package/docs/RELEASE_CHECKLIST.md +0 -32
  334. package/docs/REPRODUCIBILITY.md +0 -63
  335. package/docs/RESEARCH_BACKED_IMPROVEMENTS.md +0 -1180
  336. package/docs/ROUTING_RUBRIC.md +0 -197
  337. package/docs/SEO_AUDIT.md +0 -186
  338. package/docs/SOCIAL_LISTENING.md +0 -219
  339. package/docs/TMLPD_QNA.md +0 -751
  340. package/docs/TMLPD_V2.1_COMPLETE.md +0 -763
  341. package/docs/TMLPD_V2.2_RESEARCH_ROADMAP.md +0 -754
  342. package/docs/UPDATE_TOPICS.md +0 -15
  343. package/docs/USE_CASES.md +0 -59
  344. package/docs/V2.2_IMPLEMENTATION_COMPLETE.md +0 -446
  345. package/docs/V2_IMPLEMENTATION_GUIDE.md +0 -388
  346. package/docs/VERCEL_AI_SDK.md +0 -209
  347. package/docs/VISIBILITY_ADOPTION_PLAN.md +0 -1005
  348. package/docs/_config.yml +0 -49
  349. package/docs/ai-plugin.json +0 -16
  350. package/docs/api.html +0 -513
  351. package/docs/architecture-diagram.md +0 -40
  352. package/docs/benchmark-chart.png +0 -0
  353. package/docs/benchmark.html +0 -387
  354. package/docs/blog/routerarena-number-one.html +0 -73
  355. package/docs/cli-cheatsheet.md +0 -339
  356. package/docs/compare.md +0 -109
  357. package/docs/comparison-litellm.md +0 -88
  358. package/docs/comparison.md +0 -108
  359. package/docs/cost-chart-ascii.md +0 -42
  360. package/docs/cost-comparison-chart.svg +0 -88
  361. package/docs/curl-examples.md +0 -247
  362. package/docs/demo-auto.html +0 -264
  363. package/docs/demo.html +0 -416
  364. package/docs/geo/GENERATIVE_ENGINE_OPTIMIZATION.md +0 -232
  365. package/docs/index.html +0 -507
  366. package/docs/launch-content/LAUNCH_EXECUTION_CHECKLIST.md +0 -421
  367. package/docs/launch-content/README.md +0 -457
  368. package/docs/launch-content/assets/cost_comparison_100_tasks.png +0 -0
  369. package/docs/launch-content/assets/cumulative_savings.png +0 -0
  370. package/docs/launch-content/assets/parallel_speedup.png +0 -0
  371. package/docs/launch-content/assets/provider_pricing_comparison.png +0 -0
  372. package/docs/launch-content/assets/task_breakdown_comparison.png +0 -0
  373. package/docs/launch-content/generate_charts.py +0 -313
  374. package/docs/launch-content/hn_show_post.md +0 -139
  375. package/docs/launch-content/partner_outreach_templates.md +0 -745
  376. package/docs/launch-content/reddit_posts.md +0 -467
  377. package/docs/launch-content/twitter_thread.txt +0 -460
  378. package/docs/npm-downloads-chart.svg +0 -43
  379. package/docs/openapi.json +0 -139
  380. package/docs/openapi.yaml +0 -1318
  381. package/docs/quick-start.html +0 -366
  382. package/docs/robots.txt +0 -52
  383. package/docs/sitemap.xml +0 -57
  384. package/docs/styles.css +0 -682
  385. package/docs/well-known/ai-plugin.json +0 -16
  386. package/docs/wellknown/ai-plugin.json +0 -16
  387. package/docs-site/assets/og-banner.svg +0 -194
  388. package/docs-site/index.html +0 -632
  389. package/eval/README.md +0 -46
  390. package/eval/baselines/main.json +0 -12
  391. package/eval/benchmark_dataset.jsonl +0 -16
  392. package/eval/check_golden_routes.js +0 -64
  393. package/eval/datasets/catalog.json +0 -33
  394. package/eval/datasets/slices/cn_provider_reliability_v1.jsonl +0 -3
  395. package/eval/datasets/slices/cost_pressure_v1.jsonl +0 -3
  396. package/eval/datasets/slices/safety_guardrails_v1.jsonl +0 -3
  397. package/eval/evals.json +0 -199
  398. package/eval/fault_injection_thresholds.json +0 -3
  399. package/eval/generate_report.js +0 -128
  400. package/eval/golden_routes.json +0 -114
  401. package/eval/lib/experiment_registry.js +0 -24
  402. package/eval/run_eval.js +0 -197
  403. package/eval/run_fault_injection.js +0 -201
  404. package/eval/run_shadow_eval.js +0 -85
  405. package/eval/thresholds.json +0 -9
  406. package/examples/QUICKSTART.md +0 -183
  407. package/examples/README.md +0 -61
  408. package/examples/a3m-sdk.js +0 -124
  409. package/examples/basic-route.js +0 -54
  410. package/examples/chat-loop.js +0 -202
  411. package/examples/classify-then-route.js +0 -102
  412. package/examples/cost-compare.js +0 -120
  413. package/examples/ensemble.js +0 -160
  414. package/examples/whatsapp-telegram-bridge-demo.js +0 -302
  415. package/examples/whatsapp-telegram-bridge.js +0 -269
  416. package/hf-space/README.md +0 -23
  417. package/hf-space/app.py +0 -240
  418. package/hf-space/requirements.txt +0 -1
  419. package/huggingface_space/README.md +0 -35
  420. package/huggingface_space/app.py +0 -126
  421. package/huggingface_space/create_space.py +0 -208
  422. package/huggingface_space/requirements.txt +0 -1
  423. package/mcp-server/README.md +0 -188
  424. package/mcp-server/package.json +0 -29
  425. package/mcp-server/src/index.ts +0 -744
  426. package/mcp-server/tsconfig.json +0 -19
  427. package/openclaw-alexa-bridge/ALL_REMAINING_FIXES_PLAN.md +0 -313
  428. package/openclaw-alexa-bridge/REMAINING_FIXES_SUMMARY.md +0 -277
  429. package/openclaw-alexa-bridge/src/alexa_handler_no_tmlpd.js +0 -1234
  430. package/openclaw-alexa-bridge/test_fixes.js +0 -77
  431. package/playground/README.md +0 -51
  432. package/playground/codesandbox.json +0 -12
  433. package/playground/index.js +0 -39
  434. package/proxy/README.md +0 -227
  435. package/proxy/package-lock.json +0 -831
  436. package/proxy/package.json +0 -17
  437. package/proxy/rate-limit.js +0 -145
  438. package/proxy/rate-limit.test.js +0 -311
  439. package/proxy/server.js +0 -970
  440. package/python/README.md +0 -102
  441. package/python/a3m/__init__.py +0 -6
  442. package/python/a3m/client.py +0 -190
  443. package/python/a3m/models.py +0 -40
  444. package/python/a3m/sync_client.py +0 -61
  445. package/python/examples.py +0 -53
  446. package/python/integrations.py +0 -330
  447. package/python/pyproject.toml +0 -23
  448. package/python/setup.py +0 -28
  449. package/python/tmlpd.py +0 -369
  450. package/qna/REDDIT_GAP_ANALYSIS.md +0 -299
  451. package/qna/TMLPD_QNA.md +0 -751
  452. package/research/FINDING_001_safety.md +0 -28
  453. package/research/FINDING_002_error_diversity.md +0 -32
  454. package/research/FINDING_003_confidence_weighted_voting.md +0 -32
  455. package/research/FINDING_004_cross_model_semantic_detection.md +0 -37
  456. package/research/FINDING_005_knowledge_gap_orthogonality.md +0 -34
  457. package/research/HALLUCINATION_RESEARCH.md +0 -27
  458. package/research/ensemble-voting.md +0 -324
  459. package/research/loss-functions.md +0 -545
  460. package/research-log.md +0 -49
  461. package/scripts/banner.js +0 -29
  462. package/scripts/benchmark-local-routerarena.ts +0 -176
  463. package/scripts/benchmark.js +0 -145
  464. package/scripts/benchmark.sh +0 -61
  465. package/scripts/compare-providers.sh +0 -230
  466. package/scripts/content-planner.js +0 -25
  467. package/scripts/create-labeled-benchmark.ts +0 -105
  468. package/scripts/cross_post.py +0 -443
  469. package/scripts/local-router-benchmark.ts +0 -154
  470. package/scripts/post-all.sh +0 -41
  471. package/scripts/publish_fcc.py +0 -106
  472. package/scripts/push-to-gitee.sh +0 -25
  473. package/scripts/routerarena_ensemble.js +0 -144
  474. package/scripts/routing-benchmark-v2.js +0 -373
  475. package/scripts/routing-benchmark-v3.js +0 -118
  476. package/scripts/routing-benchmark.js +0 -462
  477. package/scripts/run-labeled-benchmark.mjs +0 -104
  478. package/scripts/run-mmlu-benchmark.js +0 -176
  479. package/scripts/run-provider-benchmark.js +0 -244
  480. package/scripts/update-npm-badges.js +0 -158
  481. package/skill/SKILL.md +0 -238
  482. package/src/__tests__/integration/tmpld_integration.test.py +0 -540
  483. package/src/skills/__tests__/skill_manager.test.ts +0 -328
  484. package/submissions/benchmarks/ALL_PLATFORMS_SUBMISSION.md +0 -94
  485. package/submissions/benchmarks/LLMROUTERBENCH_SUBMISSION.md +0 -121
  486. package/submissions/benchmarks/MMRBENCH_SUBMISSION.md +0 -94
  487. package/submissions/benchmarks/ROUTERARENA_UPDATE.md +0 -83
  488. package/submissions/benchmarks/ROUTERBENCH_SUBMISSION.md +0 -225
  489. package/test-council/1-structure-tests.test.js +0 -353
  490. package/test-council/1-structure-tests.test.ts +0 -353
  491. package/test-council/2-edge-case-tests.test.ts +0 -361
  492. package/test-council/3-performance-tests.test.ts +0 -669
  493. package/test-council/4-integration-tests.test.ts +0 -391
  494. package/test-council/5-agent-council-eval.test.ts +0 -413
  495. package/test-council/AGENT_COUNCIL_ARCHITECTURE.md +0 -349
  496. package/test-council/TEST_COUNCIL_REPORT.md +0 -201
  497. package/test-council/agents/edge-case-agent.ts +0 -363
  498. package/test-council/agents/performance-agent.ts +0 -426
  499. package/test-council/agents/structure-agent.ts +0 -227
  500. package/test-council/council.md +0 -183
  501. package/tests/__mocks__/tokenUtils.ts +0 -8
  502. package/tests/memory/episodicMemory.test.ts +0 -227
  503. package/tests/package-lock.json +0 -1628
  504. package/tests/package.json +0 -18
  505. package/tests/routing/ensembleVoting.test.ts +0 -236
  506. package/tests/routing/providerRetry.test.ts +0 -360
  507. package/tests/routing/queryTypePresets.test.ts +0 -208
  508. package/tests/security/guardrailEngine.test.ts +0 -700
  509. package/tests/tsconfig.json +0 -21
  510. package/tests/vitest.config.ts +0 -18
  511. package/tmlpd-pi-extension/README.md +0 -66
  512. package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts +0 -114
  513. package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts.map +0 -1
  514. package/tmlpd-pi-extension/dist/cache/prefixCache.js +0 -285
  515. package/tmlpd-pi-extension/dist/cache/prefixCache.js.map +0 -1
  516. package/tmlpd-pi-extension/dist/cache/responseCache.d.ts +0 -58
  517. package/tmlpd-pi-extension/dist/cache/responseCache.d.ts.map +0 -1
  518. package/tmlpd-pi-extension/dist/cache/responseCache.js +0 -153
  519. package/tmlpd-pi-extension/dist/cache/responseCache.js.map +0 -1
  520. package/tmlpd-pi-extension/dist/cli.js +0 -59
  521. package/tmlpd-pi-extension/dist/cost/costTracker.d.ts +0 -95
  522. package/tmlpd-pi-extension/dist/cost/costTracker.d.ts.map +0 -1
  523. package/tmlpd-pi-extension/dist/cost/costTracker.js +0 -240
  524. package/tmlpd-pi-extension/dist/cost/costTracker.js.map +0 -1
  525. package/tmlpd-pi-extension/dist/index.d.ts +0 -723
  526. package/tmlpd-pi-extension/dist/index.d.ts.map +0 -1
  527. package/tmlpd-pi-extension/dist/index.js +0 -239
  528. package/tmlpd-pi-extension/dist/index.js.map +0 -1
  529. package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts +0 -82
  530. package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts.map +0 -1
  531. package/tmlpd-pi-extension/dist/memory/episodicMemory.js +0 -145
  532. package/tmlpd-pi-extension/dist/memory/episodicMemory.js.map +0 -1
  533. package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts +0 -102
  534. package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts.map +0 -1
  535. package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js +0 -207
  536. package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js.map +0 -1
  537. package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts +0 -85
  538. package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts.map +0 -1
  539. package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js +0 -210
  540. package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js.map +0 -1
  541. package/tmlpd-pi-extension/dist/providers/localProvider.d.ts +0 -102
  542. package/tmlpd-pi-extension/dist/providers/localProvider.d.ts.map +0 -1
  543. package/tmlpd-pi-extension/dist/providers/localProvider.js +0 -338
  544. package/tmlpd-pi-extension/dist/providers/localProvider.js.map +0 -1
  545. package/tmlpd-pi-extension/dist/providers/registry.d.ts +0 -55
  546. package/tmlpd-pi-extension/dist/providers/registry.d.ts.map +0 -1
  547. package/tmlpd-pi-extension/dist/providers/registry.js +0 -138
  548. package/tmlpd-pi-extension/dist/providers/registry.js.map +0 -1
  549. package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts +0 -68
  550. package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts.map +0 -1
  551. package/tmlpd-pi-extension/dist/routing/advancedRouter.js +0 -332
  552. package/tmlpd-pi-extension/dist/routing/advancedRouter.js.map +0 -1
  553. package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts +0 -101
  554. package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts.map +0 -1
  555. package/tmlpd-pi-extension/dist/tools/tmlpdTools.js +0 -368
  556. package/tmlpd-pi-extension/dist/tools/tmlpdTools.js.map +0 -1
  557. package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts +0 -96
  558. package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts.map +0 -1
  559. package/tmlpd-pi-extension/dist/utils/batchProcessor.js +0 -170
  560. package/tmlpd-pi-extension/dist/utils/batchProcessor.js.map +0 -1
  561. package/tmlpd-pi-extension/dist/utils/compression.d.ts +0 -61
  562. package/tmlpd-pi-extension/dist/utils/compression.d.ts.map +0 -1
  563. package/tmlpd-pi-extension/dist/utils/compression.js +0 -281
  564. package/tmlpd-pi-extension/dist/utils/compression.js.map +0 -1
  565. package/tmlpd-pi-extension/dist/utils/reliability.d.ts +0 -74
  566. package/tmlpd-pi-extension/dist/utils/reliability.d.ts.map +0 -1
  567. package/tmlpd-pi-extension/dist/utils/reliability.js +0 -177
  568. package/tmlpd-pi-extension/dist/utils/reliability.js.map +0 -1
  569. package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts +0 -117
  570. package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts.map +0 -1
  571. package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js +0 -246
  572. package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js.map +0 -1
  573. package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts +0 -50
  574. package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts.map +0 -1
  575. package/tmlpd-pi-extension/dist/utils/tokenUtils.js +0 -124
  576. package/tmlpd-pi-extension/dist/utils/tokenUtils.js.map +0 -1
  577. package/tmlpd-pi-extension/examples/QUICKSTART.md +0 -183
  578. package/tmlpd-pi-extension/package-lock.json +0 -79
  579. package/tmlpd-pi-extension/package.json +0 -172
  580. package/tmlpd-pi-extension/python/examples.py +0 -53
  581. package/tmlpd-pi-extension/python/integrations.py +0 -330
  582. package/tmlpd-pi-extension/python/setup.py +0 -28
  583. package/tmlpd-pi-extension/python/tmlpd.py +0 -369
  584. package/tmlpd-pi-extension/qna/REDDIT_GAP_ANALYSIS.md +0 -299
  585. package/tmlpd-pi-extension/qna/TMLPD_QNA.md +0 -751
  586. package/tmlpd-pi-extension/skill/SKILL.md +0 -238
  587. package/tmlpd-pi-extension/src/cache/responseCache.ts +0 -147
  588. package/tmlpd-pi-extension/src/cost/costTracker.ts +0 -302
  589. package/tmlpd-pi-extension/src/index.ts +0 -232
  590. package/tmlpd-pi-extension/src/memory/episodicMemory.ts +0 -257
  591. package/tmlpd-pi-extension/src/orchestration/haloOrchestrator.ts +0 -266
  592. package/tmlpd-pi-extension/src/orchestration/mctsWorkflow.ts +0 -262
  593. package/tmlpd-pi-extension/src/providers/localProvider.ts +0 -406
  594. package/tmlpd-pi-extension/src/providers/registry.ts +0 -164
  595. package/tmlpd-pi-extension/src/routing/ensembleVoting.ts +0 -159
  596. package/tmlpd-pi-extension/src/routing/queryTypePresets.ts +0 -136
  597. package/tmlpd-pi-extension/src/tools/tmlpdTools.ts +0 -433
  598. package/tmlpd-pi-extension/src/utils/batchProcessor.ts +0 -232
  599. package/tmlpd-pi-extension/src/utils/compression.ts +0 -325
  600. package/tmlpd-pi-extension/src/utils/reliability.ts +0 -221
  601. package/tmlpd-pi-extension/src/utils/tokenUtils.ts +0 -145
  602. package/tmlpd-pi-extension/tsconfig.json +0 -18
  603. package/tsconfig.build.json +0 -29
  604. package/tsconfig.json +0 -18
  605. /package/{docs/llms-full.txt → llms-full.txt.bak} +0 -0
@@ -1,1234 +0,0 @@
1
- /**
2
- * Alexa Request Handler - TMLPD-Free Version
3
- *
4
- * This version removes TMLPD dependency completely and uses direct AI API calls.
5
- * Simplifies architecture and improves reliability by eliminating single point of failure.
6
- *
7
- * Responsibilities:
8
- * - Parse Alexa request format
9
- * - Detect language using Google Translate API
10
- * - Translate if needed using Sarvam API
11
- * - Call AI APIs directly (OpenAI, Anthropic, etc.)
12
- * - Format responses for Alexa
13
- */
14
-
15
- const SarvamClient = require('./sarvam_client');
16
- const GoogleTranslateClient = require('./google_translate_client');
17
- const { hashValue } = require('./logger');
18
-
19
- class AlexaRequestHandlerNoTMLPD {
20
- constructor(options = {}) {
21
- this.sarvamClient = new SarvamClient(options.sarvamApiKey);
22
- this.googleTranslateClient = new GoogleTranslateClient(options.googleTranslate || {});
23
- this.voiceConfig = options.voice || null;
24
- this.logVerbose = Boolean(options.logVerbose);
25
- this.userLanguagePrefs = new Map(); // userId -> language preference
26
-
27
- // Language detection method tracking
28
- this.detectionMethodStats = {
29
- google: 0,
30
- enhanced: 0,
31
- fallback: 0,
32
- total: 0
33
- };
34
-
35
- // AI API configuration
36
- this.aiConfig = options.ai || {};
37
- this.primaryAIProvider = options.ai?.primary || 'openai';
38
- this.fallbackAIProviders = options.ai?.fallbacks || ['groq', 'anthropic', 'google', 'cerebras'];
39
- }
40
-
41
- /**
42
- * Initialize AI API connections
43
- */
44
- async initialize() {
45
- console.log('[Alexa] Initializing TMLPD-free Alexa handler...');
46
-
47
- // Check Sarvam API
48
- const sarvamStatus = await this.sarvamClient.healthCheck();
49
- console.log('[Alexa] Sarvam API Status:', sarvamStatus.status);
50
-
51
- // Check Google Translate API
52
- const googleHealth = await this.googleTranslateClient.healthCheck();
53
- console.log('[Alexa] Google Translate API Status:', googleHealth ? 'Healthy' : 'Unhealthy');
54
-
55
- // Configure AI API clients
56
- await this.initializeAIClients();
57
- }
58
-
59
- /**
60
- * Initialize direct AI API clients
61
- */
62
- async initializeAIClients() {
63
- const providers = ['openai', 'anthropic', 'google', 'groq', 'cerebras', 'claude', 'openrouter'];
64
-
65
- for (const provider of providers) {
66
- try {
67
- const client = await this.createAIClient(provider);
68
- if (client) {
69
- console.log(`[Alexa] ${provider} AI client initialized`);
70
- }
71
- } catch (error) {
72
- console.warn(`[Alexa] Failed to initialize ${provider} client:`, error.message);
73
- }
74
- }
75
- }
76
-
77
- /**
78
- * Call Hugging Face Inference API (Free alternative)
79
- */
80
- async callHuggingFaceAI(prompt, options = {}) {
81
- const apiKey = process.env.HUGGINGFACE_API_KEY || this.aiConfig.huggingface?.apiKey;
82
- if (!apiKey) {
83
- throw new Error('Hugging Face API key not configured');
84
- }
85
-
86
- const model = options.model || this.aiConfig.huggingface?.model || 'meta-llama/Llama-3.2-3B-Instruct';
87
-
88
- console.log(`[Alexa] Calling Hugging Face API with model: ${model}`);
89
-
90
- const response = await fetch(`https://api-inference.huggingface.co/models/${model}/v1/chat/completions`, {
91
- method: 'POST',
92
- headers: {
93
- 'Content-Type': 'application/json',
94
- 'Authorization': `Bearer ${apiKey}`
95
- },
96
- body: JSON.stringify({
97
- model: model,
98
- messages: [{ role: 'user', content: prompt }],
99
- max_tokens: options.maxTokens || 500,
100
- temperature: options.temperature || 0.7
101
- })
102
- });
103
-
104
- if (!response.ok) {
105
- const errorText = await response.text();
106
- console.log(`[Alexa] Hugging Face API error ${response.status}: ${errorText.substring(0, 200)}`);
107
- throw new Error(`Hugging Face API error: ${response.status}`);
108
- }
109
-
110
- const data = await response.json();
111
- console.log(`[Alexa] Hugging Face response structure:`, Object.keys(data));
112
-
113
- return data.choices[0]?.message?.content || data[0]?.generated_text || 'I apologize, but I could not generate a response.';
114
- }
115
-
116
- /**
117
- * Create AI client for specific provider
118
- */
119
- async createAIClient(provider) {
120
- switch (provider) {
121
- case 'openai':
122
- return {
123
- provider: 'openai',
124
- execute: async (prompt, options = {}) => {
125
- return await this.callOpenAI(prompt, options);
126
- }
127
- };
128
- case 'anthropic':
129
- return {
130
- provider: 'anthropic',
131
- execute: async (prompt, options = {}) => {
132
- return await this.callAnthropic(prompt, options);
133
- }
134
- };
135
- case 'google':
136
- return {
137
- provider: 'google',
138
- execute: async (prompt, options = {}) => {
139
- return await this.callGoogleAI(prompt, options);
140
- }
141
- };
142
- case 'huggingface':
143
- return {
144
- provider: 'huggingface',
145
- execute: async (prompt, options = {}) => {
146
- return await this.callHuggingFaceAI(prompt, options);
147
- }
148
- };
149
- case 'openrouter':
150
- return {
151
- provider: 'openrouter',
152
- execute: async (prompt, options = {}) => {
153
- return await this.callOpenRouter(prompt, options);
154
- }
155
- };
156
- case 'cerebras':
157
- return {
158
- provider: 'cerebras',
159
- execute: async (prompt, options = {}) => {
160
- return await this.callCerebras(prompt, options);
161
- }
162
- };
163
- case 'groq':
164
- return {
165
- provider: 'groq',
166
- execute: async (prompt, options = {}) => {
167
- return await this.callGroq(prompt, options);
168
- }
169
- };
170
- default:
171
- return null;
172
- }
173
- }
174
-
175
- /**
176
- * Call OpenAI API directly
177
- */
178
- async callOpenAI(prompt, options = {}) {
179
- const apiKey = process.env.OPENAI_API_KEY || this.aiConfig.openai?.apiKey;
180
- if (!apiKey) {
181
- throw new Error('OpenAI API key not configured');
182
- }
183
-
184
- console.log(`[Alexa] Calling OpenAI API with key starting with: ${apiKey.substring(0, 10)}...`);
185
-
186
- // Use standard OpenAI API endpoint with fallback model
187
- const response = await fetch('https://api.openai.com/v1/chat/completions', {
188
- method: 'POST',
189
- headers: {
190
- 'Content-Type': 'application/json',
191
- 'Authorization': `Bearer ${apiKey}`
192
- },
193
- body: JSON.stringify({
194
- model: options.model || 'gpt-3.5-turbo',
195
- messages: [{ role: 'user', content: prompt }],
196
- max_tokens: options.maxTokens || 500,
197
- temperature: options.temperature || 0.7
198
- })
199
- });
200
-
201
- if (!response.ok) {
202
- const errorText = await response.text();
203
- console.log(`[Alexa] OpenAI API error ${response.status}: ${errorText.substring(0, 200)}`);
204
- throw new Error(`OpenAI API error: ${response.status}`);
205
- }
206
-
207
- const data = await response.json();
208
- console.log(`[Alexa] OpenAI response structure:`, Object.keys(data));
209
- return data.choices[0]?.message?.content || 'I apologize, but I could not generate a response.';
210
- }
211
-
212
- /**
213
- * Call z.ai GLM models (Pro subscription)
214
- */
215
- async callAnthropic(prompt, options = {}) {
216
- const apiKey = process.env.ANTHROPIC_AUTH_TOKEN || process.env.ANTHROPIC_API_KEY || this.aiConfig.anthropic?.apiKey;
217
- if (!apiKey) {
218
- throw new Error('z.ai API key not configured');
219
- }
220
-
221
- console.log(`[Alexa] Calling z.ai GLM API...`);
222
-
223
- // Try different z.ai API endpoints for GLM models
224
- const endpoints = [
225
- 'https://api.z.ai/v1/chat/completions',
226
- 'https://api.z.ai/v1/glm/chat/completions',
227
- 'https://api.z.ai/api/v1/chat/completions'
228
- ];
229
-
230
- for (const endpoint of endpoints) {
231
- try {
232
- console.log(`[Alexa] Trying z.ai endpoint: ${endpoint}`);
233
-
234
- const response = await fetch(endpoint, {
235
- method: 'POST',
236
- headers: {
237
- 'Content-Type': 'application/json',
238
- 'Authorization': `Bearer ${apiKey}`
239
- },
240
- body: JSON.stringify({
241
- model: options.model || 'glm-4-plus',
242
- messages: [{ role: 'user', content: prompt }],
243
- max_tokens: options.maxTokens || 500,
244
- temperature: options.temperature || 0.7
245
- })
246
- });
247
-
248
- if (response.ok) {
249
- const data = await response.json();
250
- console.log(`[Alexa] z.ai response structure:`, Object.keys(data));
251
-
252
- // Handle different response formats
253
- if (data.choices && Array.isArray(data.choices) && data.choices[0]) {
254
- return data.choices[0].message?.content || data.choices[0].text || 'I apologize, but I could not generate a response.';
255
- } else if (data.content && Array.isArray(data.content) && data.content[0]) {
256
- return data.content[0].text || 'I apologize, but I could not generate a response.';
257
- } else if (data.message) {
258
- return data.message.content || data.message;
259
- } else if (data.text) {
260
- return data.text;
261
- } else if (typeof data === 'string') {
262
- return data;
263
- } else {
264
- console.log('[Alexa] z.ai full response:', JSON.stringify(data).substring(0, 500));
265
- return 'I apologize, but I could not generate a response.';
266
- }
267
- }
268
- } catch (error) {
269
- console.log(`[Alexa] z.ai endpoint ${endpoint} failed:`, error.message);
270
- continue;
271
- }
272
- }
273
-
274
- throw new Error('All z.ai API endpoints failed');
275
- }
276
-
277
- /**
278
- * Call Google AI API directly using Gemini
279
- */
280
- async callGoogleAI(prompt, options = {}) {
281
- const apiKey = process.env.GOOGLE_AI_API_KEY || this.aiConfig.google?.apiKey;
282
- const model = options.model || this.aiConfig.google?.model || 'gemini-2.0-flash';
283
-
284
- if (!apiKey) {
285
- throw new Error('Google AI API key not configured');
286
- }
287
-
288
- console.log(`[Alexa] Calling Google AI API with Gemini model: ${model}`);
289
-
290
- const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`, {
291
- method: 'POST',
292
- headers: {
293
- 'Content-Type': 'application/json'
294
- },
295
- body: JSON.stringify({
296
- contents: [{
297
- parts: [{ text: prompt }],
298
- role: 'user'
299
- }],
300
- generationConfig: {
301
- temperature: options.temperature || 0.7,
302
- maxOutputTokens: options.maxTokens || 500
303
- }
304
- })
305
- });
306
-
307
- if (!response.ok) {
308
- const errorText = await response.text();
309
- console.log(`[Alexa] Google AI API error ${response.status}: ${errorText.substring(0, 200)}`);
310
- throw new Error(`Google AI API error: ${response.status}`);
311
- }
312
-
313
- const data = await response.json();
314
- console.log(`[Alexa] Google AI response structure:`, Object.keys(data));
315
-
316
- return data.candidates[0]?.content?.parts[0]?.text || 'I apologize, but I could not generate a response.';
317
- }
318
-
319
- /**
320
- * Call Groq API for fast inference
321
- */
322
- async callGroq(prompt, options = {}) {
323
- const apiKey = process.env.GROQ_API_KEY || this.aiConfig.groq?.apiKey;
324
-
325
- // Use fast Groq models optimized for speed
326
- const model = options.model || this.aiConfig.groq?.model || 'llama-3.3-70b-versatile';
327
-
328
- if (!apiKey) {
329
- throw new Error('Groq API key not configured');
330
- }
331
-
332
- console.log(`[Alexa] Calling Groq API with fast model: ${model}`);
333
-
334
- const response = await fetch('https://api.groq.com/openai/v1/chat/completions', {
335
- method: 'POST',
336
- headers: {
337
- 'Content-Type': 'application/json',
338
- 'Authorization': `Bearer ${apiKey}`
339
- },
340
- body: JSON.stringify({
341
- model: model,
342
- messages: [{ role: 'user', content: prompt }],
343
- max_tokens: options.maxTokens || 500,
344
- temperature: options.temperature || 0.7
345
- })
346
- });
347
-
348
- if (!response.ok) {
349
- const errorText = await response.text();
350
- console.log(`[Alexa] Groq API error ${response.status}: ${errorText.substring(0, 200)}`);
351
-
352
- // Handle specific Groq API errors
353
- if (response.status === 401) {
354
- throw new Error('Groq API authentication failed. Please check your API key.');
355
- } else if (response.status === 429) {
356
- throw new Error('Groq API rate limit exceeded. Please try again later.');
357
- } else if (response.status === 500) {
358
- throw new Error('Groq API server error. Please try again later.');
359
- }
360
-
361
- throw new Error(`Groq API error: ${response.status}`);
362
- }
363
-
364
- const data = await response.json();
365
- console.log(`[Alexa] Groq response structure:`, Object.keys(data));
366
-
367
- return data.choices[0]?.message?.content || 'I apologize, but I could not generate a response.';
368
- }
369
-
370
- /**
371
- * Call OpenRouter API for unified access to multiple LLM models
372
- */
373
- async callOpenRouter(prompt, options = {}) {
374
- const apiKey = process.env.OPENROUTER_API_KEY || this.aiConfig.openrouter?.apiKey;
375
- if (!apiKey) {
376
- throw new Error('OpenRouter API key not configured');
377
- }
378
-
379
- // Support multiple models through OpenRouter's unified interface
380
- const model = options.model || this.aiConfig.openrouter?.model || 'openai/gpt-3.5-turbo';
381
-
382
- console.log(`[Alexa] Calling OpenRouter API with model: ${model}`);
383
- console.log(`[Alexa] API key starting with: ${apiKey.substring(0, 10)}...`);
384
-
385
- const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
386
- method: 'POST',
387
- headers: {
388
- 'Content-Type': 'application/json',
389
- 'Authorization': `Bearer ${apiKey}`,
390
- 'HTTP-Referer': 'https://github.com/Subho/openclaw-alexa-bridge',
391
- 'X-Title': 'OpenClaw Alexa Bridge'
392
- },
393
- body: JSON.stringify({
394
- model: model,
395
- messages: [{ role: 'user', content: prompt }],
396
- max_tokens: options.maxTokens || 500,
397
- temperature: options.temperature || 0.7
398
- })
399
- });
400
-
401
- if (!response.ok) {
402
- const errorText = await response.text();
403
- console.log(`[Alexa] OpenRouter API error ${response.status}: ${errorText.substring(0, 200)}`);
404
-
405
- // Handle specific OpenRouter error scenarios
406
- if (response.status === 401) {
407
- throw new Error('OpenRouter authentication failed. Check your API key.');
408
- } else if (response.status === 402) {
409
- throw new Error('OpenRouter insufficient credits. Please check your account balance.');
410
- } else if (response.status === 429) {
411
- throw new Error('OpenRouter rate limit exceeded. Please try again later.');
412
- } else if (response.status === 400) {
413
- throw new Error('OpenRouter invalid request. Check the model name and parameters.');
414
- }
415
-
416
- throw new Error(`OpenRouter API error: ${response.status}`);
417
- }
418
-
419
- const data = await response.json();
420
- console.log(`[Alexa] OpenRouter response structure:`, Object.keys(data));
421
-
422
- // Handle OpenRouter response format (similar to OpenAI)
423
- return data.choices[0]?.message?.content || 'I apologize, but I could not generate a response.';
424
- }
425
-
426
- /**
427
- * Call Cerebras API directly for ultra-fast inference
428
- */
429
- async callCerebras(prompt, options = {}) {
430
- const apiKey = process.env.CEREBRAS_API_KEY || this.aiConfig.cerebras?.apiKey;
431
- if (!apiKey) {
432
- throw new Error('Cerebras API key not configured');
433
- }
434
-
435
- // Use fast Llama models on Cerebras
436
- const model = options.model || this.aiConfig.cerebras?.model || 'llama-3.3-70b-8192';
437
-
438
- console.log(`[Alexa] Calling Cerebras API with fast model: ${model}`);
439
- console.log(`[Alexa] API key starting with: ${apiKey.substring(0, 10)}...`);
440
-
441
- const response = await fetch('https://api.cerebras.ai/v1/chat/completions', {
442
- method: 'POST',
443
- headers: {
444
- 'Content-Type': 'application/json',
445
- 'Authorization': `Bearer ${apiKey}`
446
- },
447
- body: JSON.stringify({
448
- model: model,
449
- messages: [{ role: 'user', content: prompt }],
450
- max_tokens: options.maxTokens || 500,
451
- temperature: options.temperature || 0.7
452
- })
453
- });
454
-
455
- if (!response.ok) {
456
- const errorText = await response.text();
457
- console.log(`[Alexa] Cerebras API error ${response.status}: ${errorText.substring(0, 200)}`);
458
-
459
- // Handle specific Cerebras error scenarios
460
- if (response.status === 401) {
461
- throw new Error('Cerebras authentication failed. Check your API key.');
462
- } else if (response.status === 403) {
463
- throw new Error('Cerebras access forbidden. Check your API permissions.');
464
- } else if (response.status === 429) {
465
- throw new Error('Cerebras rate limit exceeded. Please try again later.');
466
- } else if (response.status === 400) {
467
- throw new Error('Cerebras invalid request. Check the model name and parameters.');
468
- }
469
-
470
- throw new Error(`Cerebras API error: ${response.status}`);
471
- }
472
-
473
- const data = await response.json();
474
- console.log(`[Alexa] Cerebras response structure:`, Object.keys(data));
475
-
476
- // Handle Cerebras response format (similar to OpenAI)
477
- return data.choices[0]?.message?.content || 'I apologize, but I could not generate a response.';
478
- }
479
-
480
- /**
481
- * Handle incoming Alexa request
482
- */
483
- async handleRequest(request) {
484
- try {
485
- // 1. Parse Alexa request
486
- const intent = this.parseIntent(request);
487
- const userId = this.getUserId(request);
488
- const query = this.extractQuery(request, intent);
489
-
490
- const userHash = hashValue(userId);
491
- console.log(`[Alexa] Request: intent=${intent.name}, user=${userHash || 'unknown'}`);
492
- if (this.logVerbose) {
493
- console.log(`[Alexa] Query: ${query}`);
494
- }
495
-
496
- // 2. Detect language using Google Translate API with fallback
497
- const detectionResult = await this.detectLanguageWithFallback(query);
498
- const detectedLang = detectionResult.language;
499
- const detectionMethod = detectionResult.method;
500
- const detectionConfidence = detectionResult.confidence;
501
-
502
- // Track detection method statistics
503
- this.trackDetectionMethod(detectionMethod);
504
-
505
- const userLangPref = this.userLanguagePrefs.get(userId);
506
- const targetLang = userLangPref || detectedLang;
507
-
508
- let translatedQuery = query;
509
- let originalLanguage = detectedLang;
510
- const isMixedLanguage = detectionResult.isTransliterated || detectionResult.enhancedDetails?.isMixedLanguage;
511
-
512
- // 3. Translate if needed
513
- if (isMixedLanguage) {
514
- console.log(`[Alexa] Mixed language detected (${detectedLang}-EN) using ${detectionMethod}`);
515
- console.log(`[Alexa] Detection confidence: ${(detectionConfidence * 100).toFixed(1)}%`);
516
-
517
- if (detectedLang !== 'en') {
518
- translatedQuery = await this.translateWithSarvamOrFallback(query, detectedLang);
519
- }
520
- } else if (detectedLang !== 'en') {
521
- console.log(`[Alexa] Language detected: ${detectedLang} using ${detectionMethod} (confidence: ${(detectionConfidence * 100).toFixed(1)}%)`);
522
- translatedQuery = await this.translateWithSarvamOrFallback(query, detectedLang);
523
- }
524
-
525
- if (this.logVerbose) {
526
- console.log(`[Alexa] Original query: ${query}`);
527
- console.log(`[Alexa] Translated query: ${translatedQuery}`);
528
- }
529
-
530
- // 4. Execute via direct AI API (simplified flow)
531
- const aiResponse = await this.executeViaDirectAI(translatedQuery, detectedLang);
532
-
533
- // 5. Translate response back to original language if needed
534
- let finalResponse = aiResponse;
535
- if (originalLanguage !== 'en' && aiResponse) {
536
- console.log(`[Alexa] Translating response back to ${originalLanguage}...`);
537
- const translatedBack = await this.sarvamClient.translateFromEnglish(
538
- aiResponse,
539
- originalLanguage
540
- );
541
- finalResponse = {
542
- originalEnglish: aiResponse,
543
- content: translatedBack,
544
- language: originalLanguage
545
- };
546
- if (this.logVerbose) {
547
- console.log(`[Alexa] Translated response: ${translatedBack.substring(0, 100)}...`);
548
- }
549
- } else {
550
- finalResponse = {
551
- content: aiResponse,
552
- language: 'en'
553
- };
554
- }
555
-
556
- // 6. Format for Alexa
557
- return this.formatAlexaResponse(finalResponse);
558
-
559
- } catch (error) {
560
- console.error('[Alexa] Request failed:', error);
561
- return this.handleError(error);
562
- }
563
- }
564
-
565
- /**
566
- * Execute query via direct AI API calls
567
- */
568
- async executeViaDirectAI(query, language, options = {}) {
569
- console.log(`[Alexa] Executing via direct AI API (language: ${language})`);
570
-
571
- // Build prompt for AI with context
572
- const prompt = this.buildAIPrompt(query, language, options);
573
-
574
- // Try primary AI provider first
575
- try {
576
- const primaryClient = await this.createAIClient(this.primaryAIProvider);
577
- if (primaryClient) {
578
- console.log(`[Alexa] Using primary AI provider: ${this.primaryAIProvider}`);
579
- return await primaryClient.execute(prompt, options);
580
- }
581
- } catch (primaryError) {
582
- console.warn(`[Alexa] Primary AI provider failed: ${primaryError.message}`);
583
-
584
- // Try fallback providers
585
- for (const fallbackProvider of this.fallbackAIProviders) {
586
- try {
587
- const fallbackClient = await this.createAIClient(fallbackProvider);
588
- if (fallbackClient) {
589
- console.log(`[Alexa] Using fallback AI provider: ${fallbackProvider}`);
590
- return await fallbackClient.execute(prompt, options);
591
- }
592
- } catch (fallbackError) {
593
- console.warn(`[Alexa] Fallback provider ${fallbackProvider} failed: ${fallbackError.message}`);
594
- continue;
595
- }
596
- }
597
-
598
- // All AI providers failed - return helpful fallback response
599
- throw new Error('All AI providers unavailable');
600
- }
601
- }
602
-
603
- /**
604
- * Build prompt for AI API
605
- */
606
- buildAIPrompt(query, language, options = {}) {
607
- let prompt = query;
608
-
609
- // Add language context
610
- if (language !== 'en') {
611
- prompt += `\n\n[Language Context: Query is in ${language === 'hi' ? 'Hindi' : language === 'bn' ? 'Bengali' : language}]`;
612
- }
613
-
614
- // Add platform context
615
- prompt += '\n\n[Platform: Alexa Voice Assistant]';
616
-
617
- // Add system prompt for better responses
618
- prompt += '\n\nYou are a helpful Alexa voice assistant. Provide clear, concise responses that work well with voice output. Avoid markdown, code blocks, or complex formatting.';
619
-
620
- return prompt;
621
- }
622
-
623
- /**
624
- * Parse intent from Alexa request
625
- */
626
- parseIntent(request) {
627
- const intent = request.request.intent;
628
- return {
629
- name: intent ? intent.name : 'GeneralQueryIntent',
630
- slots: intent ? intent.slots : {},
631
- confirmationStatus: intent ? intent.confirmationStatus : 'NONE'
632
- };
633
- }
634
-
635
- /**
636
- * Extract user ID from Alexa request
637
- */
638
- getUserId(request) {
639
- return request.session.user.userId;
640
- }
641
-
642
- /**
643
- * Extract query from Alexa request
644
- */
645
- extractQuery(request, intent) {
646
- // Try to get from intent slot (handle both uppercase and lowercase slot names)
647
- if (intent.slots) {
648
- // Check for lowercase 'query' slot (Alexa standard)
649
- if (intent.slots.query && intent.slots.query.value) {
650
- return intent.slots.query.value;
651
- }
652
- // Check for uppercase 'Query' slot (fallback)
653
- if (intent.slots.Query && intent.slots.Query.value) {
654
- return intent.slots.Query.value;
655
- }
656
- // Check for WhatsApp 'fullRequest' slot
657
- if (intent.slots.fullRequest && intent.slots.fullRequest.value) {
658
- return intent.slots.fullRequest.value;
659
- }
660
- }
661
-
662
- // Fallback to request body
663
- return request.request.intent?.name || 'General query';
664
- }
665
-
666
- /**
667
- * Detect language using Google Translate API with intelligent fallback
668
- */
669
- async detectLanguageWithFallback(text) {
670
- try {
671
- // Try Google Translate API first
672
- console.log(`[Alexa] Attempting Google Translate API detection...`);
673
- const googleResult = await this.googleTranslateClient.detectLanguage(text);
674
-
675
- console.log(`[Alexa] Google Translate detection successful: ${googleResult.language} (confidence: ${(googleResult.confidence * 100).toFixed(1)}%)`);
676
-
677
- // Return enhanced result with metadata
678
- return {
679
- language: googleResult.language,
680
- confidence: googleResult.confidence,
681
- method: 'google',
682
- processingTime: googleResult.processingTime || 0,
683
- isTransliterated: googleResult.isTransliterated || false,
684
- googleLanguage: googleResult.googleLanguage || googleResult.language,
685
- enhancedDetails: null
686
- };
687
-
688
- } catch (error) {
689
- console.log(`[Alexa] Google Translate API failed: ${error.message}`);
690
- console.log(`[Alexa] Falling back to enhanced language detector...`);
691
-
692
- // Fallback to enhanced detector
693
- try {
694
- const enhancedResult = await this.sarvamClient.enhancedDetector.detectLanguage(text);
695
-
696
- return {
697
- language: enhancedResult.language,
698
- confidence: enhancedResult.confidence,
699
- method: 'enhanced_fallback',
700
- processingTime: enhancedResult.details?.processingTime || 'unknown',
701
- isTransliterated: enhancedResult.isMixedLanguage || false,
702
- googleLanguage: null,
703
- enhancedDetails: enhancedResult
704
- };
705
- } catch (fallbackError) {
706
- console.error(`[Alexa] Both detection methods failed: ${fallbackError.message}`);
707
-
708
- // Ultimate fallback to basic detection
709
- return {
710
- language: 'en',
711
- confidence: 0.5,
712
- method: 'ultimate_fallback',
713
- processingTime: 0,
714
- isTransliterated: false,
715
- googleLanguage: null,
716
- enhancedDetails: null,
717
- error: fallbackError.message
718
- };
719
- }
720
- }
721
- }
722
-
723
- /**
724
- * Translate using Sarvam API with fallback to alternative services
725
- */
726
- async translateWithSarvamOrFallback(text, sourceLang) {
727
- try {
728
- // Primary: Use Sarvam API for translation
729
- console.log(`[Alexa] Attempting Sarvam API translation from ${sourceLang} to English...`);
730
-
731
- const translated = await this.sarvamClient.translateToEnglish(text, sourceLang);
732
- console.log(`[Alexa] Sarvam API translation successful`);
733
-
734
- return translated;
735
-
736
- } catch (sarvamError) {
737
- console.warn(`[Alexa] Sarvam API translation failed: ${sarvamError.message}`);
738
- console.log(`[Alexa] Falling back to alternative translation services...`);
739
-
740
- // Secondary: Try LibreTranslate
741
- try {
742
- const libreTranslated = await this.translateWithLibreTranslate(text, sourceLang, 'en');
743
- console.log(`[Alexa] LibreTranslate fallback successful`);
744
- return libreTranslated;
745
- } catch (libreError) {
746
- console.warn(`[Alexa] LibreTranslate failed: ${libreError.message}`);
747
-
748
- // Tertiary: Try MyMemory
749
- try {
750
- const memoryTranslated = await this.translateWithMyMemory(text, sourceLang, 'en');
751
- console.log(`[Alexa] MyMemory fallback successful`);
752
- return memoryTranslated;
753
- } catch (memoryError) {
754
- console.error(`[Alexa] All translation services failed: ${memoryError.message}`);
755
- // Ultimate fallback: Return original text
756
- return text;
757
- }
758
- }
759
- }
760
- }
761
-
762
- /**
763
- * Translate using LibreTranslate
764
- */
765
- async translateWithLibreTranslate(text, source, target) {
766
- const response = await fetch('https://libretranslate.de/translate', {
767
- method: 'POST',
768
- headers: {
769
- 'Content-Type': 'application/json',
770
- },
771
- body: JSON.stringify({
772
- q: text,
773
- source: source === 'hi' ? 'hi' : source === 'bn' ? 'bn' : 'en',
774
- target: target === 'en' ? 'en' : 'en',
775
- format: 'text'
776
- })
777
- });
778
-
779
- if (!response.ok) {
780
- throw new Error(`LibreTranslate error: ${response.status}`);
781
- }
782
-
783
- const data = await response.json();
784
- return data.translatedText || text;
785
- }
786
-
787
- /**
788
- * Translate using MyMemory
789
- */
790
- async translateWithMyMemory(text, source, target) {
791
- const response = await fetch('https://api.mymemory.translated.net/objs', {
792
- method: 'POST',
793
- headers: {
794
- 'Content-Type': 'application/json',
795
- },
796
- body: JSON.stringify({
797
- source: source === 'hi' ? 'hi' : source === 'bn' ? 'bn' : 'en',
798
- target: target === 'en' ? 'en' : 'en',
799
- input: text,
800
- format: 'text'
801
- })
802
- });
803
-
804
- if (!response.ok) {
805
- throw new Error(`MyMemory error: ${response.status}`);
806
- }
807
-
808
- const data = await response.json();
809
- return data.responseData.translatedText || text;
810
- }
811
-
812
- /**
813
- * Format AI response for Alexa
814
- */
815
- formatAlexaResponse(aiResponse) {
816
- let text;
817
-
818
- // Handle different response formats
819
- if (typeof aiResponse === 'string') {
820
- text = aiResponse;
821
- } else if (aiResponse.content) {
822
- text = aiResponse.content;
823
- } else if (aiResponse.responses && aiResponse.responses.length > 0) {
824
- // Use best response from parallel execution
825
- const bestResponse = aiResponse.responses[0];
826
- text = bestResponse.content || bestResponse;
827
- } else {
828
- text = "I apologize, but I couldn't process that request.";
829
- }
830
-
831
- // Clean up text for voice output
832
- text = this.cleanTextForAlexa(text);
833
-
834
- // Build Alexa response
835
- const response = {
836
- version: "1.0",
837
- response: {
838
- outputSpeech: this.buildSpeech(text),
839
- shouldEndSession: true
840
- }
841
- };
842
-
843
- return response;
844
- }
845
-
846
- /**
847
- * Build speech output (with or without voice)
848
- */
849
- buildSpeech(text) {
850
- const escapedText = this.escapeXml(text);
851
-
852
- if (this.voiceConfig && this.voiceConfig.voice) {
853
- return {
854
- type: 'SSML',
855
- ssml: `<speak><voice name="${this.voiceConfig.voice}">${escapedText}</voice></speak>`
856
- };
857
- }
858
-
859
- return {
860
- type: 'PlainText',
861
- text: text
862
- };
863
- }
864
-
865
- /**
866
- * Clean text for Alexa speech
867
- */
868
- cleanTextForAlexa(text) {
869
- return text
870
- .replace(/```[\s\S]*?```/g, 'See code for details.') // Remove code blocks
871
- .replace(/\*\*([^*]+)\*\*/g, '$1') // Remove bold markdown
872
- .replace(/\*([^*]+)\*/g, '$1') // Remove italic markdown
873
- .replace(/#{1,6}\s/g, '') // Remove headers
874
- .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // Remove links
875
- .replace(/\n{3,}/g, '\n\n') // Reduce excessive newlines
876
- .trim();
877
- }
878
-
879
- /**
880
- * Escape XML for SSML
881
- */
882
- escapeXml(text) {
883
- return text
884
- .replace(/&/g, '&amp;')
885
- .replace(/</g, '&lt;')
886
- .replace(/>/g, '&gt;')
887
- .replace(/"/g, '&quot;')
888
- .replace(/'/g, '&apos;');
889
- }
890
-
891
- /**
892
- * Handle errors with enhanced recovery logic
893
- */
894
- handleError(error) {
895
- console.error('[Alexa] Error:', error);
896
-
897
- // Determine error type and recovery strategy
898
- let recoveryStrategy = this.determineRecoveryStrategy(error);
899
-
900
- switch (recoveryStrategy) {
901
- case 'translation_error':
902
- return this.handleTranslationError(error);
903
-
904
- case 'ai_error':
905
- return this.handleAIError(error);
906
-
907
- case 'network_error':
908
- return this.handleNetworkError(error);
909
-
910
- case 'user_input_error':
911
- return this.handleUserInputError(error);
912
-
913
- case 'system_error':
914
- return this.handleSystemError(error);
915
-
916
- default:
917
- return this.handleGenericError(error);
918
- }
919
- }
920
-
921
- /**
922
- * Determine recovery strategy based on error type
923
- */
924
- determineRecoveryStrategy(error) {
925
- const errorMessage = error.message?.toLowerCase() || error.toString().toLowerCase();
926
-
927
- // AI API errors (check these first to avoid catching "api" in translation errors)
928
- if (errorMessage.includes('ai') ||
929
- errorMessage.includes('openai') ||
930
- errorMessage.includes('anthropic') ||
931
- errorMessage.includes('claude') ||
932
- errorMessage.includes('google') ||
933
- errorMessage.includes('openrouter') ||
934
- errorMessage.includes('cerebras') ||
935
- errorMessage.includes('groq') ||
936
- errorMessage.includes('model')) {
937
- return 'ai_error';
938
- }
939
-
940
- // Translation errors
941
- if (errorMessage.includes('translation') ||
942
- errorMessage.includes('sarvam') ||
943
- errorMessage.includes('translate')) {
944
- return 'translation_error';
945
- }
946
-
947
- // Generic API errors (only if not already classified)
948
- if (errorMessage.includes('api')) {
949
- return 'system_error';
950
- }
951
-
952
- // Network errors
953
- if (errorMessage.includes('network') ||
954
- errorMessage.includes('connection') ||
955
- errorMessage.includes('timeout') ||
956
- errorMessage.includes('fetch') ||
957
- errorMessage.includes('econnrefused')) {
958
- return 'network_error';
959
- }
960
-
961
- // User input errors
962
- if (errorMessage.includes('invalid') ||
963
- errorMessage.includes('undefined') ||
964
- errorMessage.includes('null') ||
965
- errorMessage.includes('format')) {
966
- return 'user_input_error';
967
- }
968
-
969
- // System errors
970
- return 'system_error';
971
- }
972
-
973
- /**
974
- * Handle translation errors with user-friendly messages
975
- */
976
- handleTranslationError(error) {
977
- console.log('[Alexa] Translation error detected, activating recovery...');
978
-
979
- const errorMessages = [
980
- "I'm having trouble translating that right now. Let me try a different approach.",
981
- "Translation service is temporarily unavailable. I'll use my fallback system.",
982
- "I can process your request, but I'm having translation issues.",
983
- "Let me help you with that using English instead."
984
- ];
985
-
986
- const userMessage = errorMessages[Math.floor(Math.random() * errorMessages.length)];
987
-
988
- return {
989
- version: "1.0",
990
- response: {
991
- outputSpeech: {
992
- type: 'PlainText',
993
- text: userMessage
994
- },
995
- shouldEndSession: false,
996
- card: {
997
- type: 'Simple',
998
- title: 'Translation Service Issue',
999
- content: userMessage + " I'm working to improve this experience."
1000
- }
1001
- }
1002
- };
1003
- }
1004
-
1005
- /**
1006
- * Handle AI API errors with fallback
1007
- */
1008
- handleAIError(error) {
1009
- console.log('[Alexa] AI API error detected, activating fallback...');
1010
-
1011
- const fallbackResponses = [
1012
- "I'm having some technical difficulties right now. Let me try to help you differently.",
1013
- "Let me provide you with some general information instead.",
1014
- "I'm working on improving my responses for you.",
1015
- "Thank you for your patience while I resolve this issue."
1016
- ];
1017
-
1018
- const fallbackMessage = fallbackResponses[Math.floor(Math.random() * fallbackResponses.length)];
1019
-
1020
- return {
1021
- version: "1.0",
1022
- response: {
1023
- outputSpeech: {
1024
- type: 'PlainText',
1025
- text: fallbackMessage
1026
- },
1027
- shouldEndSession: false,
1028
- card: {
1029
- type: 'Simple',
1030
- title: 'Technical Issue',
1031
- content: fallbackMessage + " I'm experiencing some technical challenges."
1032
- }
1033
- }
1034
- };
1035
- }
1036
-
1037
- /**
1038
- * Handle network errors with retry logic
1039
- */
1040
- handleNetworkError(error) {
1041
- console.log('[Alexa] Network error detected, implementing retry logic...');
1042
-
1043
- const retryMessages = [
1044
- "I'm having trouble connecting right now. Let me try again.",
1045
- "Network connection seems unstable. Please try again in a moment.",
1046
- "I'm experiencing some connectivity issues. Let me help you with what I can do."
1047
- ];
1048
-
1049
- const retryMessage = retryMessages[Math.floor(Math.random() * retryMessages.length)];
1050
-
1051
- return {
1052
- version: "1.0",
1053
- response: {
1054
- outputSpeech: {
1055
- type: 'PlainText',
1056
- text: retryMessage
1057
- },
1058
- shouldEndSession: false,
1059
- card: {
1060
- type: 'Simple',
1061
- title: 'Connection Issue',
1062
- content: retryMessage + " I'll keep trying to provide the best service possible."
1063
- }
1064
- }
1065
- };
1066
- }
1067
-
1068
- /**
1069
- * Handle user input errors with helpful guidance
1070
- */
1071
- handleUserInputError(error) {
1072
- console.log('[Alexa] User input error, providing guidance...');
1073
-
1074
- const guidanceMessages = [
1075
- "I didn't quite catch that. Could you please say it differently?",
1076
- "I'm having some trouble understanding. Could you rephrase that?",
1077
- "Let's try a different approach. What would you like to know about?",
1078
- "I want to make sure I'm giving you the best help possible."
1079
- ];
1080
-
1081
- const guidanceMessage = guidanceMessages[Math.floor(Math.random() * guidanceMessages.length)];
1082
-
1083
- return {
1084
- version: "1.0",
1085
- response: {
1086
- outputSpeech: {
1087
- type: 'PlainText',
1088
- text: guidanceMessage
1089
- },
1090
- shouldEndSession: false,
1091
- card: {
1092
- type: 'Simple',
1093
- title: 'Understanding Issue',
1094
- content: guidanceMessage + " I'm here to help you in the best way I can."
1095
- }
1096
- }
1097
- };
1098
- }
1099
-
1100
- /**
1101
- * Handle system errors gracefully
1102
- */
1103
- handleSystemError(error) {
1104
- console.log('[Alexa] System error, using graceful degradation...');
1105
-
1106
- const gracefulMessages = [
1107
- "I'm experiencing some technical difficulties. Thank you for your patience.",
1108
- "My systems are working hard to serve you better.",
1109
- "I apologize for the inconvenience. I'm improving my services.",
1110
- "Thank you for your understanding as I work through this technical challenge."
1111
- ];
1112
-
1113
- const gracefulMessage = gracefulMessages[Math.floor(Math.random() * gracefulMessages.length)];
1114
-
1115
- return {
1116
- version: "1.0",
1117
- response: {
1118
- outputSpeech: {
1119
- type: 'PlainText',
1120
- text: gracefulMessage
1121
- },
1122
- shouldEndSession: false,
1123
- card: {
1124
- type: 'Simple',
1125
- title: 'Service Improvement',
1126
- content: gracefulMessage + " I'm continuously working to enhance your experience."
1127
- }
1128
- }
1129
- };
1130
- }
1131
-
1132
- /**
1133
- * Handle generic errors with fallback
1134
- */
1135
- handleGenericError(error) {
1136
- console.error('[Alexa] Unhandled error:', error);
1137
-
1138
- return {
1139
- version: "1.0",
1140
- response: {
1141
- outputSpeech: {
1142
- type: 'PlainText',
1143
- text: "I'm sorry, but I encountered an unexpected issue. Please try again."
1144
- },
1145
- shouldEndSession: true
1146
- }
1147
- };
1148
- }
1149
-
1150
- /**
1151
- * Track detection method usage statistics
1152
- */
1153
- trackDetectionMethod(method) {
1154
- this.detectionMethodStats.total++;
1155
-
1156
- if (method === 'google') {
1157
- this.detectionMethodStats.google++;
1158
- } else if (method === 'enhanced_fallback') {
1159
- this.detectionMethodStats.enhanced++;
1160
- } else {
1161
- this.detectionMethodStats.fallback++;
1162
- }
1163
-
1164
- // Log statistics periodically
1165
- if (this.detectionMethodStats.total % 10 === 0) {
1166
- console.log('[Alexa] Detection method statistics:', this.getDetectionMethodStats());
1167
- }
1168
- }
1169
-
1170
- /**
1171
- * Get detection method statistics
1172
- */
1173
- getDetectionMethodStats() {
1174
- const stats = { ...this.detectionMethodStats };
1175
- const total = stats.total || 1; // Avoid division by zero
1176
-
1177
- stats.googlePercentage = ((stats.google / total) * 100).toFixed(1) + '%';
1178
- stats.enhancedPercentage = ((stats.enhanced / total) * 100).toFixed(1) + '%';
1179
- stats.fallbackPercentage = ((stats.fallback / total) * 100).toFixed(1) + '%';
1180
-
1181
- return stats;
1182
- }
1183
-
1184
- /**
1185
- * Get comprehensive language detection performance metrics
1186
- */
1187
- getLanguageDetectionMetrics() {
1188
- return {
1189
- googleTranslate: this.googleTranslateClient.getPerformanceMetrics(),
1190
- enhancedDetector: this.sarvamClient.enhancedDetector.getPerformanceMetrics(),
1191
- methodStatistics: this.getDetectionMethodStats(),
1192
- overallSuccessRate: this.calculateOverallSuccessRate()
1193
- };
1194
- }
1195
-
1196
- /**
1197
- * Calculate overall success rate across detection methods
1198
- */
1199
- calculateOverallSuccessRate() {
1200
- const googleMetrics = this.googleTranslateClient.getMetrics();
1201
- const totalDetections = googleMetrics.totalDetections;
1202
- const totalSuccesses = googleMetrics.totalSuccesses;
1203
-
1204
- if (totalDetections > 0) {
1205
- return ((totalSuccesses / totalDetections) * 100).toFixed(1) + '%';
1206
- }
1207
- return '0%';
1208
- }
1209
-
1210
- /**
1211
- * Reset detection statistics
1212
- */
1213
- resetDetectionStats() {
1214
- this.detectionMethodStats = {
1215
- google: 0,
1216
- enhanced: 0,
1217
- fallback: 0,
1218
- total: 0
1219
- };
1220
- this.googleTranslateClient.resetMetrics();
1221
- this.sarvamClient.enhancedDetector.resetMetrics();
1222
- console.log('[Alexa] Detection statistics reset');
1223
- }
1224
-
1225
- /**
1226
- * Close connection
1227
- */
1228
- close() {
1229
- console.log('[Alexa] Shutting down TMLPD-free Alexa handler...');
1230
- this.resetDetectionStats();
1231
- }
1232
- }
1233
-
1234
- module.exports = AlexaRequestHandlerNoTMLPD;