@juspay/neurolink 9.14.0 → 9.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +15 -15
  3. package/dist/adapters/video/videoAnalyzer.d.ts +1 -1
  4. package/dist/adapters/video/videoAnalyzer.js +10 -8
  5. package/dist/auth/anthropicOAuth.d.ts +377 -0
  6. package/dist/auth/anthropicOAuth.js +914 -0
  7. package/dist/auth/index.d.ts +20 -0
  8. package/dist/auth/index.js +29 -0
  9. package/dist/auth/tokenStore.d.ts +225 -0
  10. package/dist/auth/tokenStore.js +521 -0
  11. package/dist/cli/commands/auth.d.ts +50 -0
  12. package/dist/cli/commands/auth.js +1115 -0
  13. package/dist/cli/commands/setup-anthropic.js +1 -14
  14. package/dist/cli/commands/setup-azure.js +1 -12
  15. package/dist/cli/commands/setup-bedrock.js +1 -9
  16. package/dist/cli/commands/setup-google-ai.js +1 -12
  17. package/dist/cli/commands/setup-openai.js +1 -14
  18. package/dist/cli/commands/workflow.d.ts +27 -0
  19. package/dist/cli/commands/workflow.js +216 -0
  20. package/dist/cli/factories/authCommandFactory.d.ts +52 -0
  21. package/dist/cli/factories/authCommandFactory.js +146 -0
  22. package/dist/cli/factories/commandFactory.d.ts +6 -0
  23. package/dist/cli/factories/commandFactory.js +171 -22
  24. package/dist/cli/index.js +0 -1
  25. package/dist/cli/parser.js +14 -2
  26. package/dist/cli/utils/maskCredential.d.ts +11 -0
  27. package/dist/cli/utils/maskCredential.js +23 -0
  28. package/dist/constants/contextWindows.js +107 -16
  29. package/dist/constants/enums.d.ts +119 -15
  30. package/dist/constants/enums.js +182 -22
  31. package/dist/constants/index.d.ts +3 -1
  32. package/dist/constants/index.js +11 -1
  33. package/dist/context/budgetChecker.js +1 -1
  34. package/dist/context/contextCompactor.js +31 -4
  35. package/dist/context/emergencyTruncation.d.ts +21 -0
  36. package/dist/context/emergencyTruncation.js +88 -0
  37. package/dist/context/errorDetection.d.ts +16 -0
  38. package/dist/context/errorDetection.js +48 -1
  39. package/dist/context/errors.d.ts +19 -0
  40. package/dist/context/errors.js +21 -0
  41. package/dist/context/stages/slidingWindowTruncator.d.ts +6 -0
  42. package/dist/context/stages/slidingWindowTruncator.js +159 -24
  43. package/dist/core/baseProvider.js +306 -200
  44. package/dist/core/conversationMemoryManager.js +104 -61
  45. package/dist/core/evaluationProviders.js +16 -33
  46. package/dist/core/factory.js +237 -164
  47. package/dist/core/modules/GenerationHandler.js +175 -116
  48. package/dist/core/modules/MessageBuilder.js +222 -170
  49. package/dist/core/modules/StreamHandler.d.ts +1 -0
  50. package/dist/core/modules/StreamHandler.js +95 -27
  51. package/dist/core/modules/TelemetryHandler.d.ts +10 -1
  52. package/dist/core/modules/TelemetryHandler.js +25 -7
  53. package/dist/core/modules/ToolsManager.js +115 -191
  54. package/dist/core/redisConversationMemoryManager.js +418 -282
  55. package/dist/factories/providerRegistry.d.ts +5 -0
  56. package/dist/factories/providerRegistry.js +20 -2
  57. package/dist/index.d.ts +3 -3
  58. package/dist/index.js +4 -2
  59. package/dist/lib/adapters/video/videoAnalyzer.d.ts +1 -1
  60. package/dist/lib/adapters/video/videoAnalyzer.js +10 -8
  61. package/dist/lib/auth/anthropicOAuth.d.ts +377 -0
  62. package/dist/lib/auth/anthropicOAuth.js +915 -0
  63. package/dist/lib/auth/index.d.ts +20 -0
  64. package/dist/lib/auth/index.js +30 -0
  65. package/dist/lib/auth/tokenStore.d.ts +225 -0
  66. package/dist/lib/auth/tokenStore.js +522 -0
  67. package/dist/lib/constants/contextWindows.js +107 -16
  68. package/dist/lib/constants/enums.d.ts +119 -15
  69. package/dist/lib/constants/enums.js +182 -22
  70. package/dist/lib/constants/index.d.ts +3 -1
  71. package/dist/lib/constants/index.js +11 -1
  72. package/dist/lib/context/budgetChecker.js +1 -1
  73. package/dist/lib/context/contextCompactor.js +31 -4
  74. package/dist/lib/context/emergencyTruncation.d.ts +21 -0
  75. package/dist/lib/context/emergencyTruncation.js +89 -0
  76. package/dist/lib/context/errorDetection.d.ts +16 -0
  77. package/dist/lib/context/errorDetection.js +48 -1
  78. package/dist/lib/context/errors.d.ts +19 -0
  79. package/dist/lib/context/errors.js +22 -0
  80. package/dist/lib/context/stages/slidingWindowTruncator.d.ts +6 -0
  81. package/dist/lib/context/stages/slidingWindowTruncator.js +159 -24
  82. package/dist/lib/core/baseProvider.js +306 -200
  83. package/dist/lib/core/conversationMemoryManager.js +104 -61
  84. package/dist/lib/core/evaluationProviders.js +16 -33
  85. package/dist/lib/core/factory.js +237 -164
  86. package/dist/lib/core/modules/GenerationHandler.js +175 -116
  87. package/dist/lib/core/modules/MessageBuilder.js +222 -170
  88. package/dist/lib/core/modules/StreamHandler.d.ts +1 -0
  89. package/dist/lib/core/modules/StreamHandler.js +95 -27
  90. package/dist/lib/core/modules/TelemetryHandler.d.ts +10 -1
  91. package/dist/lib/core/modules/TelemetryHandler.js +25 -7
  92. package/dist/lib/core/modules/ToolsManager.js +115 -191
  93. package/dist/lib/core/redisConversationMemoryManager.js +418 -282
  94. package/dist/lib/factories/providerRegistry.d.ts +5 -0
  95. package/dist/lib/factories/providerRegistry.js +20 -2
  96. package/dist/lib/index.d.ts +3 -3
  97. package/dist/lib/index.js +4 -2
  98. package/dist/lib/mcp/externalServerManager.js +66 -0
  99. package/dist/lib/mcp/mcpCircuitBreaker.js +24 -0
  100. package/dist/lib/mcp/mcpClientFactory.js +16 -0
  101. package/dist/lib/mcp/toolDiscoveryService.js +32 -6
  102. package/dist/lib/mcp/toolRegistry.js +193 -123
  103. package/dist/lib/models/anthropicModels.d.ts +267 -0
  104. package/dist/lib/models/anthropicModels.js +528 -0
  105. package/dist/lib/neurolink.d.ts +6 -0
  106. package/dist/lib/neurolink.js +1162 -646
  107. package/dist/lib/providers/amazonBedrock.d.ts +1 -1
  108. package/dist/lib/providers/amazonBedrock.js +521 -319
  109. package/dist/lib/providers/anthropic.d.ts +123 -2
  110. package/dist/lib/providers/anthropic.js +873 -27
  111. package/dist/lib/providers/anthropicBaseProvider.js +77 -17
  112. package/dist/lib/providers/googleAiStudio.d.ts +1 -1
  113. package/dist/lib/providers/googleAiStudio.js +292 -227
  114. package/dist/lib/providers/googleVertex.d.ts +36 -1
  115. package/dist/lib/providers/googleVertex.js +553 -260
  116. package/dist/lib/providers/ollama.js +329 -278
  117. package/dist/lib/providers/openAI.js +77 -19
  118. package/dist/lib/providers/sagemaker/parsers.js +3 -3
  119. package/dist/lib/providers/sagemaker/streaming.js +3 -3
  120. package/dist/lib/proxy/proxyFetch.js +81 -48
  121. package/dist/lib/rag/ChunkerFactory.js +1 -1
  122. package/dist/lib/rag/chunkers/MarkdownChunker.d.ts +22 -0
  123. package/dist/lib/rag/chunkers/MarkdownChunker.js +213 -9
  124. package/dist/lib/rag/chunking/markdownChunker.d.ts +16 -0
  125. package/dist/lib/rag/chunking/markdownChunker.js +174 -2
  126. package/dist/lib/rag/pipeline/contextAssembly.js +2 -1
  127. package/dist/lib/rag/ragIntegration.d.ts +18 -1
  128. package/dist/lib/rag/ragIntegration.js +94 -14
  129. package/dist/lib/rag/retrieval/vectorQueryTool.js +21 -4
  130. package/dist/lib/server/abstract/baseServerAdapter.js +4 -1
  131. package/dist/lib/server/adapters/fastifyAdapter.js +35 -30
  132. package/dist/lib/services/server/ai/observability/instrumentation.d.ts +32 -0
  133. package/dist/lib/services/server/ai/observability/instrumentation.js +39 -0
  134. package/dist/lib/telemetry/attributes.d.ts +52 -0
  135. package/dist/lib/telemetry/attributes.js +61 -0
  136. package/dist/lib/telemetry/index.d.ts +3 -0
  137. package/dist/lib/telemetry/index.js +3 -0
  138. package/dist/lib/telemetry/telemetryService.d.ts +6 -0
  139. package/dist/lib/telemetry/telemetryService.js +6 -0
  140. package/dist/lib/telemetry/tracers.d.ts +15 -0
  141. package/dist/lib/telemetry/tracers.js +17 -0
  142. package/dist/lib/telemetry/withSpan.d.ts +9 -0
  143. package/dist/lib/telemetry/withSpan.js +35 -0
  144. package/dist/lib/types/contextTypes.d.ts +10 -0
  145. package/dist/lib/types/errors.d.ts +62 -0
  146. package/dist/lib/types/errors.js +107 -0
  147. package/dist/lib/types/index.d.ts +2 -1
  148. package/dist/lib/types/index.js +2 -0
  149. package/dist/lib/types/providers.d.ts +107 -0
  150. package/dist/lib/types/providers.js +69 -0
  151. package/dist/lib/types/streamTypes.d.ts +14 -0
  152. package/dist/lib/types/subscriptionTypes.d.ts +893 -0
  153. package/dist/lib/types/subscriptionTypes.js +8 -0
  154. package/dist/lib/utils/conversationMemory.js +121 -82
  155. package/dist/lib/utils/logger.d.ts +5 -0
  156. package/dist/lib/utils/logger.js +50 -2
  157. package/dist/lib/utils/messageBuilder.js +22 -42
  158. package/dist/lib/utils/modelDetection.js +3 -3
  159. package/dist/lib/utils/providerConfig.d.ts +167 -0
  160. package/dist/lib/utils/providerConfig.js +619 -9
  161. package/dist/lib/utils/providerRetry.d.ts +41 -0
  162. package/dist/lib/utils/providerRetry.js +114 -0
  163. package/dist/lib/utils/retryability.d.ts +14 -0
  164. package/dist/lib/utils/retryability.js +23 -0
  165. package/dist/lib/utils/sanitizers/svg.js +4 -5
  166. package/dist/lib/utils/tokenEstimation.d.ts +11 -1
  167. package/dist/lib/utils/tokenEstimation.js +19 -4
  168. package/dist/lib/utils/videoAnalysisProcessor.js +7 -3
  169. package/dist/mcp/externalServerManager.js +66 -0
  170. package/dist/mcp/mcpCircuitBreaker.js +24 -0
  171. package/dist/mcp/mcpClientFactory.js +16 -0
  172. package/dist/mcp/toolDiscoveryService.js +32 -6
  173. package/dist/mcp/toolRegistry.js +193 -123
  174. package/dist/models/anthropicModels.d.ts +267 -0
  175. package/dist/models/anthropicModels.js +527 -0
  176. package/dist/neurolink.d.ts +6 -0
  177. package/dist/neurolink.js +1162 -646
  178. package/dist/providers/amazonBedrock.d.ts +1 -1
  179. package/dist/providers/amazonBedrock.js +521 -319
  180. package/dist/providers/anthropic.d.ts +123 -2
  181. package/dist/providers/anthropic.js +873 -27
  182. package/dist/providers/anthropicBaseProvider.js +77 -17
  183. package/dist/providers/googleAiStudio.d.ts +1 -1
  184. package/dist/providers/googleAiStudio.js +292 -227
  185. package/dist/providers/googleVertex.d.ts +36 -1
  186. package/dist/providers/googleVertex.js +553 -260
  187. package/dist/providers/ollama.js +329 -278
  188. package/dist/providers/openAI.js +77 -19
  189. package/dist/providers/sagemaker/parsers.js +3 -3
  190. package/dist/providers/sagemaker/streaming.js +3 -3
  191. package/dist/proxy/proxyFetch.js +81 -48
  192. package/dist/rag/ChunkerFactory.js +1 -1
  193. package/dist/rag/chunkers/MarkdownChunker.d.ts +22 -0
  194. package/dist/rag/chunkers/MarkdownChunker.js +213 -9
  195. package/dist/rag/chunking/markdownChunker.d.ts +16 -0
  196. package/dist/rag/chunking/markdownChunker.js +174 -2
  197. package/dist/rag/pipeline/contextAssembly.js +2 -1
  198. package/dist/rag/ragIntegration.d.ts +18 -1
  199. package/dist/rag/ragIntegration.js +94 -14
  200. package/dist/rag/retrieval/vectorQueryTool.js +21 -4
  201. package/dist/server/abstract/baseServerAdapter.js +4 -1
  202. package/dist/server/adapters/fastifyAdapter.js +35 -30
  203. package/dist/services/server/ai/observability/instrumentation.d.ts +32 -0
  204. package/dist/services/server/ai/observability/instrumentation.js +39 -0
  205. package/dist/telemetry/attributes.d.ts +52 -0
  206. package/dist/telemetry/attributes.js +60 -0
  207. package/dist/telemetry/index.d.ts +3 -0
  208. package/dist/telemetry/index.js +3 -0
  209. package/dist/telemetry/telemetryService.d.ts +6 -0
  210. package/dist/telemetry/telemetryService.js +6 -0
  211. package/dist/telemetry/tracers.d.ts +15 -0
  212. package/dist/telemetry/tracers.js +16 -0
  213. package/dist/telemetry/withSpan.d.ts +9 -0
  214. package/dist/telemetry/withSpan.js +34 -0
  215. package/dist/types/contextTypes.d.ts +10 -0
  216. package/dist/types/errors.d.ts +62 -0
  217. package/dist/types/errors.js +107 -0
  218. package/dist/types/index.d.ts +2 -1
  219. package/dist/types/index.js +2 -0
  220. package/dist/types/providers.d.ts +107 -0
  221. package/dist/types/providers.js +69 -0
  222. package/dist/types/streamTypes.d.ts +14 -0
  223. package/dist/types/subscriptionTypes.d.ts +893 -0
  224. package/dist/types/subscriptionTypes.js +7 -0
  225. package/dist/utils/conversationMemory.js +121 -82
  226. package/dist/utils/logger.d.ts +5 -0
  227. package/dist/utils/logger.js +50 -2
  228. package/dist/utils/messageBuilder.js +22 -42
  229. package/dist/utils/modelDetection.js +3 -3
  230. package/dist/utils/providerConfig.d.ts +167 -0
  231. package/dist/utils/providerConfig.js +619 -9
  232. package/dist/utils/providerRetry.d.ts +41 -0
  233. package/dist/utils/providerRetry.js +113 -0
  234. package/dist/utils/retryability.d.ts +14 -0
  235. package/dist/utils/retryability.js +22 -0
  236. package/dist/utils/sanitizers/svg.js +4 -5
  237. package/dist/utils/tokenEstimation.d.ts +11 -1
  238. package/dist/utils/tokenEstimation.js +19 -4
  239. package/dist/utils/videoAnalysisProcessor.js +7 -3
  240. package/dist/workflow/config.d.ts +26 -26
  241. package/package.json +2 -1
@@ -16,6 +16,7 @@ import ora from "ora";
16
16
  import { logger } from "../../lib/utils/logger.js";
17
17
  import { getTopModelChoices } from "../../lib/utils/modelChoices.js";
18
18
  import { AIProviderName } from "../../lib/types/index.js";
19
+ import { maskCredential } from "../utils/maskCredential.js";
19
20
  export async function handleAnthropicSetup(argv) {
20
21
  try {
21
22
  const options = {
@@ -365,20 +366,6 @@ async function updateEnvFile(config) {
365
366
  throw error;
366
367
  }
367
368
  }
368
- /**
369
- * Mask API key for display
370
- */
371
- function maskCredential(credential) {
372
- if (!credential || credential.length < 8) {
373
- return "****";
374
- }
375
- const knownPrefixes = ["sk-ant-"];
376
- const prefix = knownPrefixes.find((p) => credential.startsWith(p)) ??
377
- credential.slice(0, 3);
378
- const end = credential.slice(-4);
379
- const stars = "*".repeat(Math.max(4, credential.length - prefix.length - 4));
380
- return `${prefix}${stars}${end}`;
381
- }
382
369
  /**
383
370
  * Show usage example
384
371
  */
@@ -16,6 +16,7 @@ import { logger } from "../../lib/utils/logger.js";
16
16
  import { updateEnvFile as updateEnvFileShared, displayEnvUpdateSummary, } from "../utils/envManager.js";
17
17
  import { getTopModelChoices } from "../../lib/utils/modelChoices.js";
18
18
  import { AIProviderName } from "../../lib/types/index.js";
19
+ import { maskCredential } from "../utils/maskCredential.js";
19
20
  export async function handleAzureSetup(argv) {
20
21
  try {
21
22
  const options = {
@@ -372,18 +373,6 @@ async function updateEnvFileWithConfig(config) {
372
373
  throw error;
373
374
  }
374
375
  }
375
- /**
376
- * Mask API key for display
377
- */
378
- function maskCredential(credential) {
379
- if (!credential || credential.length < 8) {
380
- return "****";
381
- }
382
- const start = credential.slice(0, 4);
383
- const end = credential.slice(-4);
384
- const middle = "*".repeat(Math.max(4, credential.length - 8));
385
- return `${start}${middle}${end}`;
386
- }
387
376
  /**
388
377
  * Show usage example
389
378
  */
@@ -15,6 +15,7 @@ import { logger } from "../../lib/utils/logger.js";
15
15
  import { updateEnvFile as envUpdate } from "../utils/envManager.js";
16
16
  import { getTopModelChoices } from "../../lib/utils/modelChoices.js";
17
17
  import { AIProviderName } from "../../lib/types/index.js";
18
+ import { maskCredential } from "../utils/maskCredential.js";
18
19
  export async function handleBedrockSetup(argv) {
19
20
  try {
20
21
  const options = {
@@ -453,13 +454,4 @@ function displayUsageExample() {
453
454
  logger.always(chalk.green("🚀 You can now use AWS Bedrock with the NeuroLink CLI:"));
454
455
  logger.always(chalk.cyan(" pnpm cli generate 'Hello from Bedrock!' --provider bedrock"));
455
456
  }
456
- function maskCredential(credential) {
457
- if (!credential || credential.length < 8) {
458
- return "****";
459
- }
460
- const start = credential.slice(0, 4);
461
- const end = credential.slice(-4);
462
- const middle = "*".repeat(Math.max(4, credential.length - 8));
463
- return `${start}${middle}${end}`;
464
- }
465
457
  //# sourceMappingURL=setup-bedrock.js.map
@@ -17,6 +17,7 @@ import { GoogleAIModels } from "../../lib/constants/enums.js";
17
17
  import { updateEnvFile as updateEnvFileManager, displayEnvUpdateSummary, } from "../utils/envManager.js";
18
18
  import { getTopModelChoices } from "../../lib/utils/modelChoices.js";
19
19
  import { AIProviderName } from "../../lib/types/index.js";
20
+ import { maskCredential } from "../utils/maskCredential.js";
20
21
  /**
21
22
  * Get the runtime default model that matches the provider implementation
22
23
  */
@@ -326,18 +327,6 @@ async function updateEnvFile(config) {
326
327
  throw error;
327
328
  }
328
329
  }
329
- /**
330
- * Mask API key for display
331
- */
332
- function maskCredential(credential) {
333
- if (!credential || credential.length < 8) {
334
- return "****";
335
- }
336
- const start = credential.slice(0, 7); // Show 'AIza' plus a few chars
337
- const end = credential.slice(-4);
338
- const middle = "*".repeat(Math.max(4, credential.length - 11));
339
- return `${start}${middle}${end}`;
340
- }
341
330
  /**
342
331
  * Show usage example
343
332
  */
@@ -16,6 +16,7 @@ import ora from "ora";
16
16
  import { logger } from "../../lib/utils/logger.js";
17
17
  import { getTopModelChoices } from "../../lib/utils/modelChoices.js";
18
18
  import { AIProviderName } from "../../lib/types/index.js";
19
+ import { maskCredential } from "../utils/maskCredential.js";
19
20
  export async function handleOpenAISetup(argv) {
20
21
  try {
21
22
  const options = {
@@ -358,20 +359,6 @@ async function updateEnvFile(config) {
358
359
  throw error;
359
360
  }
360
361
  }
361
- /**
362
- * Mask API key for display
363
- */
364
- function maskCredential(credential) {
365
- if (!credential || credential.length < 8) {
366
- return "****";
367
- }
368
- const knownPrefixes = ["sk-"];
369
- const prefix = knownPrefixes.find((p) => credential.startsWith(p)) ??
370
- credential.slice(0, 3);
371
- const end = credential.slice(-4);
372
- const stars = "*".repeat(Math.max(4, credential.length - prefix.length - 4));
373
- return `${prefix}${stars}${end}`;
374
- }
375
362
  /**
376
363
  * Show usage example
377
364
  */
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Workflow CLI Commands for NeuroLink
3
+ *
4
+ * Implements commands for workflow management and execution:
5
+ * - neurolink workflow list - List available predefined workflows
6
+ * - neurolink workflow info <name> - Show details of a workflow
7
+ * - neurolink workflow execute <name> <prompt> - Execute a workflow
8
+ */
9
+ import type { CommandModule } from "yargs";
10
+ /**
11
+ * Workflow CLI command factory
12
+ */
13
+ export declare class WorkflowCommandFactory {
14
+ static createWorkflowCommands(): CommandModule;
15
+ /**
16
+ * List all predefined workflows
17
+ */
18
+ private static executeList;
19
+ /**
20
+ * Show details of a specific workflow
21
+ */
22
+ private static executeInfo;
23
+ /**
24
+ * Execute a workflow
25
+ */
26
+ private static executeWorkflow;
27
+ }
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Workflow CLI Commands for NeuroLink
3
+ *
4
+ * Implements commands for workflow management and execution:
5
+ * - neurolink workflow list - List available predefined workflows
6
+ * - neurolink workflow info <name> - Show details of a workflow
7
+ * - neurolink workflow execute <name> <prompt> - Execute a workflow
8
+ */
9
+ import chalk from "chalk";
10
+ import ora from "ora";
11
+ /**
12
+ * All predefined workflow configs keyed by their id.
13
+ * Loaded lazily via dynamic import to avoid circular deps.
14
+ */
15
+ async function loadPredefinedWorkflows() {
16
+ const [consensus, fallback, adaptive, multiJudge] = await Promise.all([
17
+ import("../../lib/workflow/workflows/consensusWorkflow.js"),
18
+ import("../../lib/workflow/workflows/fallbackWorkflow.js"),
19
+ import("../../lib/workflow/workflows/adaptiveWorkflow.js"),
20
+ import("../../lib/workflow/workflows/multiJudgeWorkflow.js"),
21
+ ]);
22
+ const configs = [
23
+ consensus.CONSENSUS_3_WORKFLOW,
24
+ consensus.CONSENSUS_3_FAST_WORKFLOW,
25
+ fallback.FAST_FALLBACK_WORKFLOW,
26
+ fallback.AGGRESSIVE_FALLBACK_WORKFLOW,
27
+ adaptive.QUALITY_MAX_WORKFLOW,
28
+ adaptive.SPEED_FIRST_WORKFLOW,
29
+ adaptive.BALANCED_ADAPTIVE_WORKFLOW,
30
+ multiJudge.MULTI_JUDGE_5_WORKFLOW,
31
+ multiJudge.MULTI_JUDGE_3_WORKFLOW,
32
+ ];
33
+ const map = {};
34
+ for (const cfg of configs) {
35
+ map[cfg.id] = cfg;
36
+ }
37
+ return map;
38
+ }
39
+ /**
40
+ * Workflow CLI command factory
41
+ */
42
+ export class WorkflowCommandFactory {
43
+ static createWorkflowCommands() {
44
+ return {
45
+ command: "workflow <subcommand>",
46
+ describe: "Manage and execute AI workflows",
47
+ builder: (yargs) => {
48
+ return yargs
49
+ .command("list", "List available predefined workflows", (y) => y, async () => {
50
+ await WorkflowCommandFactory.executeList();
51
+ })
52
+ .command("info <name>", "Show details of a workflow", (y) => y.positional("name", {
53
+ type: "string",
54
+ description: "Workflow name/id",
55
+ demandOption: true,
56
+ }), async (argv) => {
57
+ await WorkflowCommandFactory.executeInfo(argv);
58
+ })
59
+ .command("execute <name> <prompt>", "Execute a workflow with a prompt", (y) => y
60
+ .positional("name", {
61
+ type: "string",
62
+ description: "Workflow name/id",
63
+ demandOption: true,
64
+ })
65
+ .positional("prompt", {
66
+ type: "string",
67
+ description: "Prompt to send to the workflow",
68
+ demandOption: true,
69
+ })
70
+ .option("provider", {
71
+ type: "string",
72
+ description: "Override AI provider",
73
+ })
74
+ .option("model", {
75
+ type: "string",
76
+ description: "Override model name",
77
+ })
78
+ .option("timeout", {
79
+ type: "number",
80
+ description: "Execution timeout in milliseconds",
81
+ })
82
+ .option("verbose", {
83
+ type: "boolean",
84
+ description: "Enable verbose output",
85
+ default: false,
86
+ }), async (argv) => {
87
+ await WorkflowCommandFactory.executeWorkflow(argv);
88
+ })
89
+ .demandCommand(1, "Please specify a workflow subcommand");
90
+ },
91
+ handler: () => { },
92
+ };
93
+ }
94
+ /**
95
+ * List all predefined workflows
96
+ */
97
+ static async executeList() {
98
+ const workflows = await loadPredefinedWorkflows();
99
+ const configs = Object.values(workflows);
100
+ console.info(chalk.bold("\nAvailable Workflows:\n"));
101
+ for (const cfg of configs) {
102
+ const tags = cfg.tags?.join(", ") || "";
103
+ console.info(` ${chalk.cyan(cfg.id.padEnd(24))} ${chalk.white(cfg.name)}`);
104
+ console.info(` ${"".padEnd(24)} ${chalk.gray(cfg.description || "")}`);
105
+ if (tags) {
106
+ console.info(` ${"".padEnd(24)} ${chalk.gray(`Tags: ${tags}`)}`);
107
+ }
108
+ console.info();
109
+ }
110
+ console.info(chalk.gray(`Total: ${configs.length} workflows`));
111
+ }
112
+ /**
113
+ * Show details of a specific workflow
114
+ */
115
+ static async executeInfo(argv) {
116
+ const workflows = await loadPredefinedWorkflows();
117
+ const cfg = workflows[argv.name];
118
+ if (!cfg) {
119
+ console.error(chalk.red(`Workflow "${argv.name}" not found.`));
120
+ console.info(chalk.gray(`Available: ${Object.keys(workflows).join(", ")}`));
121
+ process.exitCode = 1;
122
+ return;
123
+ }
124
+ console.info(chalk.bold(`\nWorkflow: ${cfg.name}\n`));
125
+ console.info(` ID: ${cfg.id}`);
126
+ console.info(` Type: ${cfg.type}`);
127
+ console.info(` Version: ${cfg.version || "n/a"}`);
128
+ console.info(` Description: ${cfg.description || "n/a"}`);
129
+ if (cfg.models && cfg.models.length > 0) {
130
+ console.info(`\n Models:`);
131
+ for (const m of cfg.models) {
132
+ console.info(` - ${chalk.cyan(m.label || m.model)} (${m.provider})`);
133
+ }
134
+ }
135
+ if (cfg.modelGroups && cfg.modelGroups.length > 0) {
136
+ console.info(`\n Model Groups:`);
137
+ for (const group of cfg.modelGroups) {
138
+ console.info(` ${chalk.cyan(group.id)}:`);
139
+ for (const m of group.models) {
140
+ console.info(` - ${m.label || m.model} (${m.provider})`);
141
+ }
142
+ }
143
+ }
144
+ if (cfg.judge) {
145
+ console.info(`\n Judge: ${cfg.judge.model} (${cfg.judge.provider})`);
146
+ if (cfg.judge.criteria) {
147
+ console.info(` Criteria: ${cfg.judge.criteria.join(", ")}`);
148
+ }
149
+ }
150
+ if (cfg.execution) {
151
+ console.info(`\n Execution:`);
152
+ if (cfg.execution.timeout) {
153
+ console.info(` Timeout: ${cfg.execution.timeout}ms`);
154
+ }
155
+ if (cfg.execution.parallelism) {
156
+ console.info(` Parallelism: ${cfg.execution.parallelism}`);
157
+ }
158
+ if (cfg.execution.minResponses) {
159
+ console.info(` Min Responses: ${cfg.execution.minResponses}`);
160
+ }
161
+ }
162
+ if (cfg.tags && cfg.tags.length > 0) {
163
+ console.info(`\n Tags: ${cfg.tags.join(", ")}`);
164
+ }
165
+ }
166
+ /**
167
+ * Execute a workflow
168
+ */
169
+ static async executeWorkflow(argv) {
170
+ const workflows = await loadPredefinedWorkflows();
171
+ let cfg = workflows[argv.name];
172
+ if (!cfg) {
173
+ console.error(chalk.red(`Workflow "${argv.name}" not found.`));
174
+ console.info(chalk.gray(`Available: ${Object.keys(workflows).join(", ")}`));
175
+ process.exitCode = 1;
176
+ return;
177
+ }
178
+ // Apply provider/model overrides if specified
179
+ if (argv.provider || argv.model) {
180
+ cfg = {
181
+ ...cfg,
182
+ models: cfg.models?.map((m) => ({
183
+ ...m,
184
+ provider: argv.provider || m.provider,
185
+ model: argv.model || m.model,
186
+ })),
187
+ };
188
+ }
189
+ const spinner = ora("Executing workflow...").start();
190
+ try {
191
+ const { runWorkflow } = await import("../../lib/workflow/core/workflowRunner.js");
192
+ const result = await runWorkflow(cfg, {
193
+ prompt: argv.prompt,
194
+ timeout: argv.timeout,
195
+ verbose: argv.verbose,
196
+ });
197
+ spinner.stop();
198
+ if (result.content) {
199
+ console.info(result.content);
200
+ }
201
+ else {
202
+ console.info(chalk.yellow("Workflow completed but produced no content."));
203
+ if (result.reasoning) {
204
+ console.info(chalk.gray(`Reasoning: ${result.reasoning}`));
205
+ }
206
+ }
207
+ }
208
+ catch (error) {
209
+ spinner.stop();
210
+ const msg = error instanceof Error ? error.message : String(error);
211
+ console.error(chalk.red(`Workflow execution failed: ${msg}`));
212
+ process.exitCode = 1;
213
+ }
214
+ }
215
+ }
216
+ //# sourceMappingURL=workflow.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Auth Command Factory for NeuroLink
3
+ *
4
+ * Creates the unified authentication command with subcommands for AI providers.
5
+ * Follows the MCP command pattern with subcommands: login, logout, status, refresh.
6
+ *
7
+ * Supported providers:
8
+ * - Anthropic (API key + OAuth for Claude subscription plans)
9
+ */
10
+ import type { CommandModule } from "yargs";
11
+ /**
12
+ * Auth command arguments interface
13
+ */
14
+ export interface AuthCommandArgs {
15
+ provider?: string;
16
+ method?: "api-key" | "oauth" | "create-api-key";
17
+ format?: "text" | "json";
18
+ quiet?: boolean;
19
+ debug?: boolean;
20
+ nonInteractive?: boolean;
21
+ }
22
+ /**
23
+ * Auth Command Factory
24
+ *
25
+ * Creates the main auth command with subcommands:
26
+ * - login: Authenticate with a provider
27
+ * - logout: Clear stored credentials
28
+ * - status: Show authentication status
29
+ * - refresh: Manually refresh OAuth tokens
30
+ */
31
+ export declare class AuthCommandFactory {
32
+ /**
33
+ * Create the main auth command with subcommands
34
+ */
35
+ static createAuthCommands(): CommandModule;
36
+ /**
37
+ * Build options for login subcommand
38
+ */
39
+ private static buildLoginOptions;
40
+ /**
41
+ * Build options for logout subcommand
42
+ */
43
+ private static buildLogoutOptions;
44
+ /**
45
+ * Build options for status subcommand
46
+ */
47
+ private static buildStatusOptions;
48
+ /**
49
+ * Build options for refresh subcommand
50
+ */
51
+ private static buildRefreshOptions;
52
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Auth Command Factory for NeuroLink
3
+ *
4
+ * Creates the unified authentication command with subcommands for AI providers.
5
+ * Follows the MCP command pattern with subcommands: login, logout, status, refresh.
6
+ *
7
+ * Supported providers:
8
+ * - Anthropic (API key + OAuth for Claude subscription plans)
9
+ */
10
+ /**
11
+ * Supported providers for authentication
12
+ */
13
+ const SUPPORTED_PROVIDERS = ["anthropic"];
14
+ /**
15
+ * Auth Command Factory
16
+ *
17
+ * Creates the main auth command with subcommands:
18
+ * - login: Authenticate with a provider
19
+ * - logout: Clear stored credentials
20
+ * - status: Show authentication status
21
+ * - refresh: Manually refresh OAuth tokens
22
+ */
23
+ export class AuthCommandFactory {
24
+ /**
25
+ * Create the main auth command with subcommands
26
+ */
27
+ static createAuthCommands() {
28
+ return {
29
+ command: "auth <subcommand>",
30
+ describe: "Manage authentication with AI providers (API key or OAuth)",
31
+ builder: (yargs) => {
32
+ return yargs
33
+ .command("login <provider>", "Authenticate with an AI provider", (yargs) => this.buildLoginOptions(yargs), async (argv) => {
34
+ const { handleLogin } = await import("../commands/auth.js");
35
+ await handleLogin(argv);
36
+ })
37
+ .command("logout <provider>", "Clear stored credentials for a provider", (yargs) => this.buildLogoutOptions(yargs), async (argv) => {
38
+ const { handleLogout } = await import("../commands/auth.js");
39
+ await handleLogout(argv);
40
+ })
41
+ .command("status [provider]", "Show authentication status for provider(s)", (yargs) => this.buildStatusOptions(yargs), async (argv) => {
42
+ const { handleStatus } = await import("../commands/auth.js");
43
+ await handleStatus(argv);
44
+ })
45
+ .command("refresh <provider>", "Manually refresh OAuth tokens for a provider", (yargs) => this.buildRefreshOptions(yargs), async (argv) => {
46
+ const { handleRefresh } = await import("../commands/auth.js");
47
+ await handleRefresh(argv);
48
+ })
49
+ .option("format", {
50
+ choices: ["text", "json"],
51
+ default: "text",
52
+ description: "Output format",
53
+ })
54
+ .option("quiet", {
55
+ type: "boolean",
56
+ alias: "q",
57
+ default: false,
58
+ description: "Suppress non-essential output",
59
+ })
60
+ .option("debug", {
61
+ type: "boolean",
62
+ default: false,
63
+ description: "Enable debug output",
64
+ })
65
+ .demandCommand(1, "Please specify an auth subcommand")
66
+ .example("$0 auth login anthropic", "Authenticate with Anthropic")
67
+ .example("$0 auth login anthropic --method create-api-key", "Create API key via OAuth (Claude Pro/Max - Recommended)")
68
+ .example("$0 auth status", "Show authentication status for all providers")
69
+ .example("$0 auth logout anthropic", "Clear Anthropic stored credentials")
70
+ .example("$0 auth refresh anthropic", "Refresh Anthropic OAuth tokens")
71
+ .help();
72
+ },
73
+ handler: () => {
74
+ // No-op handler as subcommands handle everything
75
+ },
76
+ };
77
+ }
78
+ /**
79
+ * Build options for login subcommand
80
+ */
81
+ static buildLoginOptions(yargs) {
82
+ return yargs
83
+ .positional("provider", {
84
+ type: "string",
85
+ description: "AI provider to authenticate with",
86
+ choices: SUPPORTED_PROVIDERS,
87
+ demandOption: true,
88
+ })
89
+ .option("method", {
90
+ type: "string",
91
+ alias: "m",
92
+ description: "Authentication method",
93
+ choices: ["api-key", "oauth", "create-api-key"],
94
+ })
95
+ .option("non-interactive", {
96
+ type: "boolean",
97
+ description: "Skip interactive prompts (requires environment variables)",
98
+ default: false,
99
+ })
100
+ .example("$0 auth login anthropic", "Interactive authentication (choose method)")
101
+ .example("$0 auth login anthropic --method api-key", "API key authentication")
102
+ .example("$0 auth login anthropic --method create-api-key", "Create API key via OAuth (Claude Pro/Max)")
103
+ .example("$0 auth login anthropic --method oauth", "Direct OAuth (experimental)");
104
+ }
105
+ /**
106
+ * Build options for logout subcommand
107
+ */
108
+ static buildLogoutOptions(yargs) {
109
+ return yargs
110
+ .positional("provider", {
111
+ type: "string",
112
+ description: "AI provider to log out from",
113
+ choices: SUPPORTED_PROVIDERS,
114
+ demandOption: true,
115
+ })
116
+ .example("$0 auth logout anthropic", "Clear all Anthropic credentials");
117
+ }
118
+ /**
119
+ * Build options for status subcommand
120
+ */
121
+ static buildStatusOptions(yargs) {
122
+ return yargs
123
+ .positional("provider", {
124
+ type: "string",
125
+ description: "AI provider to check (optional, shows all if not specified)",
126
+ choices: SUPPORTED_PROVIDERS,
127
+ })
128
+ .example("$0 auth status", "Show status for all configured providers")
129
+ .example("$0 auth status anthropic", "Show Anthropic authentication status")
130
+ .example("$0 auth status --format json", "Show status in JSON format");
131
+ }
132
+ /**
133
+ * Build options for refresh subcommand
134
+ */
135
+ static buildRefreshOptions(yargs) {
136
+ return yargs
137
+ .positional("provider", {
138
+ type: "string",
139
+ description: "AI provider to refresh tokens for",
140
+ choices: SUPPORTED_PROVIDERS,
141
+ demandOption: true,
142
+ })
143
+ .example("$0 auth refresh anthropic", "Refresh Anthropic OAuth tokens");
144
+ }
145
+ }
146
+ //# sourceMappingURL=authCommandFactory.js.map
@@ -11,6 +11,12 @@ export declare class CLICommandFactory {
11
11
  private static processCliFiles;
12
12
  private static processCliVideoFiles;
13
13
  private static processOptions;
14
+ /**
15
+ * Validate Anthropic subscription options
16
+ * Ensures subscription tier is provided when using anthropic-subscription provider
17
+ * or when oauth auth method is selected
18
+ */
19
+ private static validateAnthropicSubscriptionOptions;
14
20
  private static handleOutput;
15
21
  /**
16
22
  * Helper method to handle TTS audio file output