@juspay/neurolink 10.6.1 → 10.6.3

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 (151) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/adapters/video/vertexVideoHandler.js +4 -1
  3. package/dist/agent/directTools.d.ts +2 -2
  4. package/dist/agent/orchestration/orchestrator.js +2 -0
  5. package/dist/auth/errors.d.ts +1 -1
  6. package/dist/auth/middleware/AuthMiddleware.d.ts +1 -1
  7. package/dist/auth/providers/BaseAuthProvider.d.ts +1 -1
  8. package/dist/auth/providers/auth0.js +1 -1
  9. package/dist/auth/providers/betterAuth.js +1 -1
  10. package/dist/auth/providers/clerk.js +1 -1
  11. package/dist/auth/providers/firebase.js +1 -1
  12. package/dist/auth/providers/jwt.js +1 -1
  13. package/dist/auth/providers/oauth2.js +1 -1
  14. package/dist/auth/providers/supabase.js +1 -1
  15. package/dist/auth/providers/workos.js +1 -1
  16. package/dist/browser/neurolink.min.js +338 -338
  17. package/dist/cli/commands/proxy.js +2 -0
  18. package/dist/cli/commands/rag.js +2 -4
  19. package/dist/cli/factories/commandFactory.js +3 -2
  20. package/dist/cli/loop/conversationSelector.js +4 -6
  21. package/dist/client/auth.js +2 -7
  22. package/dist/client/reactHooks.js +2 -2
  23. package/dist/client/reactHooks.tsx +5 -10
  24. package/dist/core/baseProvider.d.ts +1 -1
  25. package/dist/core/baseProvider.js +16 -6
  26. package/dist/core/factory.d.ts +4 -3
  27. package/dist/core/modules/GenerationHandler.d.ts +1 -1
  28. package/dist/core/modules/GenerationHandler.js +7 -5
  29. package/dist/core/modules/TelemetryHandler.js +2 -2
  30. package/dist/core/toolExecutionRecorder.d.ts +1 -1
  31. package/dist/core/toolExecutionRecorder.js +1 -2
  32. package/dist/evaluation/errors/EvaluationError.d.ts +1 -1
  33. package/dist/evaluation/scorers/rule/contentSimilarityScorer.js +2 -0
  34. package/dist/evaluation/scorers/rule/formatScorer.js +1 -1
  35. package/dist/factories/providerFactory.d.ts +4 -3
  36. package/dist/factories/providerRegistry.d.ts +9 -4
  37. package/dist/factories/providerRegistry.js +9 -4
  38. package/dist/features/ppt/slideGenerator.js +6 -5
  39. package/dist/features/ppt/utils.d.ts +2 -1
  40. package/dist/features/ppt/utils.js +1 -0
  41. package/dist/lib/adapters/video/vertexVideoHandler.js +4 -1
  42. package/dist/lib/agent/orchestration/orchestrator.js +2 -0
  43. package/dist/lib/auth/providers/auth0.js +1 -1
  44. package/dist/lib/auth/providers/betterAuth.js +1 -1
  45. package/dist/lib/auth/providers/clerk.js +1 -1
  46. package/dist/lib/auth/providers/firebase.js +1 -1
  47. package/dist/lib/auth/providers/jwt.js +1 -1
  48. package/dist/lib/auth/providers/oauth2.js +1 -1
  49. package/dist/lib/auth/providers/supabase.js +1 -1
  50. package/dist/lib/auth/providers/workos.js +1 -1
  51. package/dist/lib/client/auth.js +2 -7
  52. package/dist/lib/client/reactHooks.js +2 -2
  53. package/dist/lib/core/baseProvider.d.ts +1 -1
  54. package/dist/lib/core/baseProvider.js +16 -6
  55. package/dist/lib/core/factory.d.ts +4 -3
  56. package/dist/lib/core/modules/GenerationHandler.d.ts +1 -1
  57. package/dist/lib/core/modules/GenerationHandler.js +7 -5
  58. package/dist/lib/core/modules/TelemetryHandler.js +2 -2
  59. package/dist/lib/core/toolExecutionRecorder.d.ts +1 -1
  60. package/dist/lib/core/toolExecutionRecorder.js +1 -2
  61. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.js +2 -0
  62. package/dist/lib/evaluation/scorers/rule/formatScorer.js +1 -1
  63. package/dist/lib/factories/providerFactory.d.ts +4 -3
  64. package/dist/lib/factories/providerRegistry.d.ts +9 -4
  65. package/dist/lib/factories/providerRegistry.js +9 -4
  66. package/dist/lib/features/ppt/slideGenerator.js +6 -5
  67. package/dist/lib/features/ppt/utils.d.ts +2 -1
  68. package/dist/lib/features/ppt/utils.js +1 -0
  69. package/dist/lib/mcp/elicitationProtocol.js +1 -1
  70. package/dist/lib/mcp/mcpRegistryClient.js +1 -1
  71. package/dist/lib/middleware/utils/guardrailsUtils.js +1 -1
  72. package/dist/lib/neurolink.js +15 -7
  73. package/dist/lib/processors/document/ExcelProcessor.js +5 -1
  74. package/dist/lib/providers/amazonBedrock.js +4 -5
  75. package/dist/lib/providers/amazonSagemaker.d.ts +18 -0
  76. package/dist/lib/providers/amazonSagemaker.js +9 -3
  77. package/dist/lib/providers/anthropic.js +6 -1
  78. package/dist/lib/providers/googleAiStudio.js +5 -12
  79. package/dist/lib/providers/googleVertex.js +26 -5
  80. package/dist/lib/providers/openaiChatCompletionsBase.js +2 -0
  81. package/dist/lib/providers/sagemaker/errors.js +2 -1
  82. package/dist/lib/proxy/proxyFetch.js +6 -2
  83. package/dist/lib/rag/ChunkerFactory.js +1 -1
  84. package/dist/lib/rag/chunking/semanticChunker.js +1 -2
  85. package/dist/lib/rag/document/MDocument.js +1 -2
  86. package/dist/lib/rag/document/loaders.js +16 -3
  87. package/dist/lib/rag/pipeline/RAGPipeline.js +1 -2
  88. package/dist/lib/rag/retrieval/hybridSearch.js +1 -2
  89. package/dist/lib/rag/retrieval/vectorQueryTool.js +1 -2
  90. package/dist/lib/sdk/toolRegistration.js +6 -2
  91. package/dist/lib/server/middleware/cache.d.ts +4 -0
  92. package/dist/lib/server/middleware/cache.js +7 -3
  93. package/dist/lib/server/middleware/validation.js +2 -1
  94. package/dist/lib/server/utils/redaction.js +31 -39
  95. package/dist/lib/server/websocket/WebSocketHandler.js +3 -3
  96. package/dist/lib/services/server/ai/observability/instrumentation.js +8 -5
  97. package/dist/lib/types/classifierRouter.d.ts +2 -1
  98. package/dist/lib/types/cli.d.ts +18 -18
  99. package/dist/lib/types/providers.d.ts +24 -4
  100. package/dist/lib/utils/pdfProcessor.js +2 -0
  101. package/dist/lib/utils/safeFetch.js +20 -0
  102. package/dist/lib/utils/schemaConversion.d.ts +1 -1
  103. package/dist/lib/utils/schemaConversion.js +5 -1
  104. package/dist/lib/workflow/config.d.ts +1 -1
  105. package/dist/lib/workflow/config.js +1 -1
  106. package/dist/lib/workflow/core/workflowRegistry.js +1 -1
  107. package/dist/lib/workflow/core/workflowRunner.js +1 -1
  108. package/dist/lib/workflow/utils/workflowMetrics.d.ts +1 -1
  109. package/dist/lib/workflow/utils/workflowMetrics.js +1 -1
  110. package/dist/mcp/elicitationProtocol.js +1 -1
  111. package/dist/mcp/mcpRegistryClient.js +1 -1
  112. package/dist/middleware/utils/guardrailsUtils.js +1 -1
  113. package/dist/neurolink.js +15 -7
  114. package/dist/processors/document/ExcelProcessor.js +5 -1
  115. package/dist/providers/amazonBedrock.js +4 -5
  116. package/dist/providers/amazonSagemaker.d.ts +18 -0
  117. package/dist/providers/amazonSagemaker.js +9 -3
  118. package/dist/providers/anthropic.js +6 -1
  119. package/dist/providers/googleAiStudio.js +5 -12
  120. package/dist/providers/googleVertex.js +26 -5
  121. package/dist/providers/openaiChatCompletionsBase.js +2 -0
  122. package/dist/providers/sagemaker/errors.js +2 -1
  123. package/dist/proxy/proxyFetch.js +6 -2
  124. package/dist/rag/ChunkerFactory.js +1 -1
  125. package/dist/rag/chunking/semanticChunker.js +1 -2
  126. package/dist/rag/document/MDocument.js +1 -2
  127. package/dist/rag/document/loaders.js +16 -3
  128. package/dist/rag/pipeline/RAGPipeline.js +1 -2
  129. package/dist/rag/retrieval/hybridSearch.js +1 -2
  130. package/dist/rag/retrieval/vectorQueryTool.js +1 -2
  131. package/dist/sdk/toolRegistration.js +6 -2
  132. package/dist/server/middleware/cache.d.ts +4 -0
  133. package/dist/server/middleware/cache.js +7 -3
  134. package/dist/server/middleware/validation.js +2 -1
  135. package/dist/server/utils/redaction.js +31 -39
  136. package/dist/server/websocket/WebSocketHandler.js +3 -3
  137. package/dist/services/server/ai/observability/instrumentation.js +8 -5
  138. package/dist/types/classifierRouter.d.ts +2 -1
  139. package/dist/types/cli.d.ts +18 -18
  140. package/dist/types/providers.d.ts +24 -4
  141. package/dist/utils/pdfProcessor.js +2 -0
  142. package/dist/utils/safeFetch.js +20 -0
  143. package/dist/utils/schemaConversion.d.ts +1 -1
  144. package/dist/utils/schemaConversion.js +5 -1
  145. package/dist/workflow/config.d.ts +2 -2
  146. package/dist/workflow/config.js +1 -1
  147. package/dist/workflow/core/workflowRegistry.js +1 -1
  148. package/dist/workflow/core/workflowRunner.js +1 -1
  149. package/dist/workflow/utils/workflowMetrics.d.ts +1 -1
  150. package/dist/workflow/utils/workflowMetrics.js +1 -1
  151. package/package.json +1 -1
@@ -27,6 +27,18 @@ import { TelemetryHandler } from "./modules/TelemetryHandler.js";
27
27
  import { ToolsManager } from "./modules/ToolsManager.js";
28
28
  import { Utilities } from "./modules/Utilities.js";
29
29
  import { generateText } from "../utils/generation.js";
30
+ /**
31
+ * Read the consumer-facing lifecycle callbacks buried inside a request's
32
+ * middleware blob. The parameter is `unknown` on purpose: request options
33
+ * arrive as several structurally-unrelated shapes (StreamOptions,
34
+ * TextGenerationOptions), and the lifecycle branch is an optional add-on
35
+ * none of them declare — a single structural view keeps the read cast-free
36
+ * at every call site.
37
+ */
38
+ function getLifecycleMiddlewareConfig(options) {
39
+ return options?.middleware
40
+ ?.middlewareConfig?.lifecycle?.config;
41
+ }
30
42
  /**
31
43
  * Abstract base class for all AI providers
32
44
  * Tools are integrated as first-class citizens - always available by default
@@ -39,7 +51,7 @@ export class BaseProvider {
39
51
  modelName;
40
52
  providerName;
41
53
  defaultTimeout = 30000; // 30 seconds
42
- middlewareOptions; // TODO: Implement global level middlewares that can be used
54
+ middlewareOptions; // TODO(#1179): Implement global level middlewares that can be used
43
55
  // Tools are conditionally included based on centralized configuration
44
56
  directTools = shouldDisableBuiltinTools()
45
57
  ? {}
@@ -279,8 +291,7 @@ export class BaseProvider {
279
291
  * underlying transport.
280
292
  */
281
293
  wrapStreamWithLifecycleCallbacks(result, options) {
282
- const lifecycle = options
283
- ?.middleware?.middlewareConfig?.lifecycle?.config;
294
+ const lifecycle = getLifecycleMiddlewareConfig(options);
284
295
  if (!lifecycle?.onChunk && !lifecycle?.onFinish && !lifecycle?.onError) {
285
296
  return result;
286
297
  }
@@ -376,8 +387,7 @@ export class BaseProvider {
376
387
  if (hasLifecycleErrorFired(err)) {
377
388
  return;
378
389
  }
379
- const lifecycle = options
380
- ?.middleware?.middlewareConfig?.lifecycle?.config;
390
+ const lifecycle = getLifecycleMiddlewareConfig(options);
381
391
  const onError = lifecycle?.onError;
382
392
  if (!onError) {
383
393
  return;
@@ -1295,7 +1305,7 @@ export class BaseProvider {
1295
1305
  /**
1296
1306
  * Get AI SDK model with middleware applied
1297
1307
  * This method wraps the base model with any configured middleware
1298
- * TODO: Implement global level middlewares that can be used
1308
+ * TODO(#1179): Implement global level middlewares that can be used
1299
1309
  */
1300
1310
  async getAISDKModelWithMiddleware(options = {}) {
1301
1311
  // Get the base model
@@ -1,4 +1,5 @@
1
- import type { AIProvider, SupportedModelName, NeurolinkCredentials, UnknownRecord, ProviderPairResult } from "../types/index.js";
1
+ import type { NeuroLink } from "../neurolink.js";
2
+ import type { AIProvider, SupportedModelName, NeurolinkCredentials, ProviderPairResult } from "../types/index.js";
2
3
  import { AIProviderName } from "../constants/enums.js";
3
4
  /**
4
5
  * Factory for creating AI provider instances with centralized configuration
@@ -25,7 +26,7 @@ export declare class AIProviderFactory {
25
26
  * @param region - Optional region override for cloud providers
26
27
  * @returns AIProvider instance
27
28
  */
28
- static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean, sdk?: UnknownRecord, region?: string, credentials?: NeurolinkCredentials): Promise<AIProvider>;
29
+ static createProvider(providerName: string, modelName?: string | null, enableMCP?: boolean, sdk?: NeuroLink, region?: string, credentials?: NeurolinkCredentials): Promise<AIProvider>;
29
30
  /**
30
31
  * Create a provider instance with specific provider enum and model
31
32
  * @param provider - Provider enum value
@@ -40,7 +41,7 @@ export declare class AIProviderFactory {
40
41
  * @param enableMCP - Optional flag to enable MCP integration (default: true)
41
42
  * @returns AIProvider instance
42
43
  */
43
- static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean, sdk?: UnknownRecord): Promise<AIProvider>;
44
+ static createBestProvider(requestedProvider?: string, modelName?: string | null, enableMCP?: boolean, sdk?: NeuroLink): Promise<AIProvider>;
44
45
  /**
45
46
  * Create primary and fallback provider instances
46
47
  * @param primaryProvider - Primary provider name
@@ -91,5 +91,5 @@ export declare class GenerationHandler {
91
91
  /**
92
92
  * Analyze AI response structure and log detailed debugging information
93
93
  */
94
- analyzeAIResponse(result: Record<string, unknown>): void;
94
+ analyzeAIResponse(rawResult: unknown): void;
95
95
  }
@@ -693,11 +693,9 @@ export class GenerationHandler {
693
693
  }));
694
694
  }
695
695
  // Extract from steps
696
- if (generateResult.steps &&
697
- Array.isArray(generateResult.steps)) {
696
+ if (generateResult.steps && Array.isArray(generateResult.steps)) {
698
697
  const toolCallArgsMap = new Map();
699
- for (const step of generateResult
700
- .steps || []) {
698
+ for (const step of generateResult.steps || []) {
701
699
  // Collect tool calls and their arguments
702
700
  if (step?.toolCalls && Array.isArray(step.toolCalls)) {
703
701
  for (const toolCall of step.toolCalls) {
@@ -947,7 +945,11 @@ export class GenerationHandler {
947
945
  /**
948
946
  * Analyze AI response structure and log detailed debugging information
949
947
  */
950
- analyzeAIResponse(result) {
948
+ analyzeAIResponse(rawResult) {
949
+ if (rawResult === null || typeof rawResult !== "object") {
950
+ return;
951
+ }
952
+ const result = rawResult;
951
953
  logger.debug("NeuroLink Raw AI Response Analysis", {
952
954
  provider: this.providerName,
953
955
  model: this.modelName,
@@ -189,10 +189,10 @@ export class TelemetryHandler {
189
189
  return;
190
190
  }
191
191
  const sessionId = options.context?.sessionId ||
192
- options.sessionId ||
192
+ ("sessionId" in options ? options.sessionId : undefined) ||
193
193
  `session-${nanoid()}`;
194
194
  const userId = options.context?.userId ||
195
- options.userId;
195
+ ("userId" in options ? options.userId : undefined);
196
196
  try {
197
197
  await this.neurolink.storeToolExecutions(sessionId, userId, toolCalls, toolResults, currentTime);
198
198
  }
@@ -56,7 +56,7 @@ export declare class ToolExecutionRecorder {
56
56
  * enumerable on purpose: downstream stages spread options (`{...options}`)
57
57
  * and the recorder must survive into the provider loops.
58
58
  */
59
- attachTo(options: Record<string, unknown>): void;
59
+ attachTo(options: object): void;
60
60
  /** Retrieve the recorder a request is carrying, if any. */
61
61
  static from(options: unknown): ToolExecutionRecorder | undefined;
62
62
  }
@@ -147,8 +147,7 @@ export class ToolExecutionRecorder {
147
147
  const wrapped = Object.create(null);
148
148
  for (const [name, tool] of Object.entries(tools)) {
149
149
  const execute = tool.execute;
150
- if (typeof execute !== "function" ||
151
- execute[RECORDER_WRAPPED]) {
150
+ if (typeof execute !== "function" || execute[RECORDER_WRAPPED]) {
152
151
  wrapped[name] = tool;
153
152
  continue;
154
153
  }
@@ -270,6 +270,8 @@ export class ContentSimilarityScorer extends BaseScorer {
270
270
  const metrics = this._similarityConfig.metrics ?? [
271
271
  this._similarityConfig.metric ?? "jaccard",
272
272
  ];
273
+ // Intersected with JsonObject so the rows are JSON-typed at the source
274
+ // and flow into result metadata without a cast.
273
275
  const details = [];
274
276
  for (const metric of metrics) {
275
277
  const score = this._calculateSimilarity(input.response, reference, metric);
@@ -396,7 +396,7 @@ export class FormatScorer extends BaseRuleScorer {
396
396
  // First check if it's valid JSON
397
397
  try {
398
398
  JSON.parse(text);
399
- // TODO: Implement full JSON Schema validation
399
+ // TODO(#1179): Implement full JSON Schema validation
400
400
  // For now, just check it's valid JSON
401
401
  return { passed: true, score: 1.0 };
402
402
  }
@@ -1,5 +1,6 @@
1
+ import type { NeuroLink } from "../neurolink.js";
1
2
  import type { AIProviderName } from "../constants/enums.js";
2
- import type { AIProvider, NeurolinkCredentials, ProviderConstructor, ProviderRegistration, UnknownRecord } from "../types/index.js";
3
+ import type { AIProvider, NeurolinkCredentials, ProviderConstructor, ProviderRegistration } from "../types/index.js";
3
4
  /**
4
5
  * True Factory Pattern implementation for AI Providers
5
6
  * Uses registration-based approach to eliminate switch statements
@@ -18,7 +19,7 @@ export declare class ProviderFactory {
18
19
  * @param providerName - Provider name (optional, uses NEUROLINK_PROVIDER env var or 'vertex' as default)
19
20
  * @param modelName - Model name (optional, uses provider-specific env var or registry default)
20
21
  */
21
- static createProvider(providerName?: AIProviderName | string, modelName?: string, sdk?: UnknownRecord, region?: string, credentials?: NeurolinkCredentials): Promise<AIProvider>;
22
+ static createProvider(providerName?: AIProviderName | string, modelName?: string, sdk?: NeuroLink, region?: string, credentials?: NeurolinkCredentials): Promise<AIProvider>;
22
23
  /**
23
24
  * Check if a provider is registered
24
25
  */
@@ -52,7 +53,7 @@ export declare class ProviderFactory {
52
53
  * Create the best available provider for the given name
53
54
  * Used by NeuroLink SDK for streaming and generation
54
55
  */
55
- static createBestProvider(providerName: AIProviderName | string, modelName?: string, enableMCP?: boolean, sdk?: UnknownRecord, credentials?: NeurolinkCredentials): Promise<AIProvider>;
56
+ static createBestProvider(providerName: AIProviderName | string, modelName?: string, enableMCP?: boolean, sdk?: NeuroLink, credentials?: NeurolinkCredentials): Promise<AIProvider>;
56
57
  }
57
58
  /**
58
59
  * Helper function to create providers with backward compatibility
@@ -28,10 +28,15 @@ export declare class ProviderRegistry {
28
28
  /**
29
29
  * Internal registration implementation
30
30
  *
31
- * This method is a flat list of 13 provider registrations. Each registration
32
- * is self-contained and extracting helpers would add indirection without
33
- * reducing complexity the function is long because there are many providers,
34
- * not because any single registration is complex.
31
+ * Flat list of ProviderFactory.registerProvider() calls. Providers load via
32
+ * dynamic import() of ../providers/<module>.js only - never static imports
33
+ * (avoids circular dependencies; see CLAUDE.md).
34
+ *
35
+ * Not registered (by design): index.ts, providerTypeUtils.ts,
36
+ * anthropicBaseProvider.ts (legacy; anthropic.ts is live),
37
+ * googleNativeGemini3.ts (shared helpers). Filename != provider ID
38
+ * (e.g. amazonBedrock -> "bedrock"); static scanners that miss dynamic
39
+ * imports may false-positive (Pattern Analysis #1178).
35
40
  */
36
41
  private static _doRegister;
37
42
  /**
@@ -47,10 +47,15 @@ export class ProviderRegistry {
47
47
  /**
48
48
  * Internal registration implementation
49
49
  *
50
- * This method is a flat list of 13 provider registrations. Each registration
51
- * is self-contained and extracting helpers would add indirection without
52
- * reducing complexity the function is long because there are many providers,
53
- * not because any single registration is complex.
50
+ * Flat list of ProviderFactory.registerProvider() calls. Providers load via
51
+ * dynamic import() of ../providers/<module>.js only - never static imports
52
+ * (avoids circular dependencies; see CLAUDE.md).
53
+ *
54
+ * Not registered (by design): index.ts, providerTypeUtils.ts,
55
+ * anthropicBaseProvider.ts (legacy; anthropic.ts is live),
56
+ * googleNativeGemini3.ts (shared helpers). Filename != provider ID
57
+ * (e.g. amazonBedrock -> "bedrock"); static scanners that miss dynamic
58
+ * imports may false-positive (Pattern Analysis #1178).
54
59
  */
55
60
  // eslint-disable-next-line max-lines-per-function
56
61
  static async _doRegister() {
@@ -23,11 +23,12 @@ export async function loadPptxGenJS() {
23
23
  }
24
24
  try {
25
25
  const mod = await import(/* @vite-ignore */ "pptxgenjs");
26
- // ESM/CJS interop: pptxgenjs v4 may double-wrap the default export
27
- const Ctor = typeof mod.default === "function"
28
- ? mod.default
29
- : mod.default
30
- .default;
26
+ // ESM/CJS interop: pptxgenjs v4 may double-wrap the default export.
27
+ // The runtime shape is genuinely dynamic, so probe it as `unknown`.
28
+ const rawDefault = mod.default;
29
+ const Ctor = typeof rawDefault === "function"
30
+ ? rawDefault
31
+ : rawDefault.default;
31
32
  _pptxGenJS = Ctor;
32
33
  return _pptxGenJS;
33
34
  }
@@ -5,6 +5,7 @@
5
5
  *
6
6
  * @module ppt/utils
7
7
  */
8
+ import type { NeuroLink } from "../../neurolink.js";
8
9
  import type { PPTGenerationContext, AspectRatioOption, EffectivePPTProviderResult, ImageValidationResult, TextSegment, LogoConfig, GenerateOptions } from "../../types/index.js";
9
10
  /**
10
11
  * Extract PPT generation context from GenerateOptions
@@ -18,7 +19,7 @@ export declare const PPT_VALID_PROVIDERS: readonly string[];
18
19
  /**
19
20
  * Get an effective PPT provider - handles all orchestration logic
20
21
  */
21
- export declare function getEffectivePPTProvider(currentProvider: unknown, currentProviderName: string, currentModelName: string, neurolink?: unknown): Promise<EffectivePPTProviderResult>;
22
+ export declare function getEffectivePPTProvider(currentProvider: unknown, currentProviderName: string, currentModelName: string, neurolink?: NeuroLink): Promise<EffectivePPTProviderResult>;
22
23
  /**
23
24
  * Generate output file path for PPT
24
25
  */
@@ -100,6 +100,7 @@ export async function getEffectivePPTProvider(currentProvider, currentProviderNa
100
100
  const { ErrorFactory } = await import("../../utils/errorHandling.js");
101
101
  const normalizedProvider = currentProviderName.toLowerCase();
102
102
  if (PPT_VALID_PROVIDERS.includes(normalizedProvider)) {
103
+ // Single assertion from `unknown` — the shape is probed defensively below.
103
104
  const providerInstance = currentProvider;
104
105
  const actualModelName = currentModelName ||
105
106
  providerInstance?.modelName ||
@@ -355,7 +355,7 @@ export function createSelectRequest(message, selectOptions, options) {
355
355
  */
356
356
  export function createFormRequest(message, fields, options) {
357
357
  const requestOptions = {
358
- fields: fields,
358
+ fields,
359
359
  };
360
360
  if (options.submitLabel !== undefined) {
361
361
  requestOptions.submitLabel = options.submitLabel;
@@ -272,7 +272,7 @@ export class MCPRegistryClient extends EventEmitter {
272
272
  if (wellKnown) {
273
273
  return wellKnown;
274
274
  }
275
- // TODO: Fetch from remote registry
275
+ // TODO(#1179): Fetch from remote registry
276
276
  return undefined;
277
277
  }
278
278
  /**
@@ -318,7 +318,7 @@ export function applyContentFiltering(text, badWordsConfig, context = "unknown")
318
318
  logger.debug(`[ContentFiltering:${context}] Applying regex pattern filtering with ${badWordsConfig.regexPatterns.length} patterns using replacement: "${replacementText}".`);
319
319
  for (const pattern of badWordsConfig.regexPatterns) {
320
320
  try {
321
- // TODO: Add blocking for overly complex or long patterns
321
+ // TODO(#1179): Add blocking for overly complex or long patterns
322
322
  if (pattern.length > 1000) {
323
323
  logger.warn(`[ContentFiltering:${context}] Regex pattern exceeds max length (1000 chars): "${pattern.substring(0, 50)}..."`);
324
324
  }
@@ -327,13 +327,23 @@ export function isNeuroLink(value) {
327
327
  value !== null &&
328
328
  value[NEUROLINK_BRAND] === true);
329
329
  }
330
+ /**
331
+ * Create a Node {@link EventEmitter} exposed through the typed-emitter
332
+ * surface. The runtime object is a plain EventEmitter — the typed view only
333
+ * narrows the event-name/payload relationship for callers, so the widening
334
+ * hop through `unknown` is contained here once.
335
+ */
336
+ function createTypedEmitter() {
337
+ const emitter = new EventEmitter();
338
+ return emitter;
339
+ }
330
340
  export class NeuroLink {
331
341
  /** @internal Brand for cross-module identification — see {@link isNeuroLink}. */
332
342
  [NEUROLINK_BRAND] = true;
333
343
  mcpInitialized = false;
334
344
  mcpSkipped = false;
335
345
  mcpInitPromise = null;
336
- emitter = new EventEmitter();
346
+ emitter = createTypedEmitter();
337
347
  // TaskManager — lazy-initialized on first access via `this.tasks`
338
348
  _taskManager;
339
349
  _taskManagerConfig;
@@ -1306,8 +1316,7 @@ export class NeuroLink {
1306
1316
  description: retrieveContextDef.description ?? "Retrieve context or artifacts",
1307
1317
  // Pass the Zod schema so ToolsManager gives the LLM full parameter types.
1308
1318
  // registerTool() detects isZodSchema on inputSchema and preserves it.
1309
- inputSchema: retrieveContextDef
1310
- .inputSchema,
1319
+ inputSchema: retrieveContextDef.inputSchema,
1311
1320
  execute: async (params) => {
1312
1321
  // Lazy: conversationMemory is initialized on the first generate() call.
1313
1322
  // When only an artifact store is present (no Redis), memoryManager is
@@ -1362,8 +1371,7 @@ export class NeuroLink {
1362
1371
  description: toolDef.description ?? toolName,
1363
1372
  // Zod schema — registerTool() detects isZodSchema and preserves it
1364
1373
  // so ToolsManager gives the LLM full parameter types.
1365
- inputSchema: toolDef
1366
- .inputSchema,
1374
+ inputSchema: toolDef.inputSchema,
1367
1375
  execute: async (params) => withTimeout(toolDef.execute(params, { toolCallId: "skill-tool", messages: [] }), TOOL_TIMEOUTS.EXECUTION_DEFAULT_MS, ErrorFactory.toolTimeout(toolName, TOOL_TIMEOUTS.EXECUTION_DEFAULT_MS)),
1368
1376
  });
1369
1377
  }
@@ -8915,7 +8923,7 @@ Current user's request: ${currentInput}`;
8915
8923
  // ========================================
8916
8924
  // ENHANCED: Tool Event Emission API
8917
8925
  // ========================================
8918
- // TODO: Add ToolExecutionEvent utility methods in future version
8926
+ // TODO(#1179): Add ToolExecutionEvent utility methods in future version
8919
8927
  // Will provide structured event format for consistent tool event processing
8920
8928
  /**
8921
8929
  * Emit tool start event with execution tracking
@@ -9038,7 +9046,7 @@ Current user's request: ${currentInput}`;
9038
9046
  clearCurrentStreamExecutions() {
9039
9047
  this.currentStreamToolExecutions = [];
9040
9048
  }
9041
- // TODO: Add getToolExecutionEvents() method in future version
9049
+ // TODO(#1179): Add getToolExecutionEvents() method in future version
9042
9050
  // Will return properly formatted ToolExecutionEvent objects for structured event processing
9043
9051
  // ========================================
9044
9052
  // Tool Registration API
@@ -271,7 +271,11 @@ export class ExcelProcessor extends BaseFileProcessor {
271
271
  */
272
272
  async parseWorkbook(buffer) {
273
273
  const ExcelJS = await loadExcelJS();
274
- const workbook = new ExcelJS.Workbook();
274
+ // The exceljs constructor comes from a normalised CJS/ESM interop
275
+ // namespace (see loadExcelJS); probe the instance as `unknown` and
276
+ // narrow to the structural subset this processor uses.
277
+ const workbookInstance = new ExcelJS.Workbook();
278
+ const workbook = workbookInstance;
275
279
  // ExcelJS load() types expect Buffer but Node 22+ Buffer<ArrayBufferLike>
276
280
  // is not directly assignable. Extract a clean ArrayBuffer for the exact
277
281
  // byte range via slice, then cast for type compatibility.
@@ -155,7 +155,8 @@ export class AmazonBedrockProvider extends BaseProvider {
155
155
  // Clear conversation history for new generation
156
156
  this.conversationHistory = [];
157
157
  // Check for multimodal input (images, PDFs, CSVs, files)
158
- // Cast to any to access multimodal properties (runtime check is safe)
158
+ // Narrow to the StreamOptions input shape to access multimodal
159
+ // properties (runtime check is safe)
159
160
  const input = options.input;
160
161
  const hasMultimodalInput = !!(input?.images?.length ||
161
162
  input?.content?.length ||
@@ -917,10 +918,8 @@ export class AmazonBedrockProvider extends BaseProvider {
917
918
  logger.debug("[TRACE] executeStream CATCH - error caught from streamingConversationLoop");
918
919
  const errorObj = error;
919
920
  // Check if error is related to streaming permissions
920
- const isPermissionError = errorObj?.name ===
921
- "AccessDeniedException" ||
922
- errorObj?.name ===
923
- "UnauthorizedOperation" ||
921
+ const isPermissionError = errorObj?.name === "AccessDeniedException" ||
922
+ errorObj?.name === "UnauthorizedOperation" ||
924
923
  errorObj?.message?.includes("bedrock:InvokeModelWithResponseStream") ||
925
924
  errorObj?.message?.includes("streaming") ||
926
925
  errorObj?.message?.includes("ConverseStream");
@@ -54,6 +54,24 @@ export declare class AmazonSageMakerProvider extends BaseProvider {
54
54
  * Get model capabilities and information
55
55
  */
56
56
  getModelCapabilities(): {
57
+ capabilities: {
58
+ streaming: boolean;
59
+ toolCalling: boolean;
60
+ structuredOutput: boolean;
61
+ batchInference: boolean;
62
+ supportedResponseFormats: string[];
63
+ supportedToolTypes: string[];
64
+ maxBatchSize: number;
65
+ adaptiveConcurrency: boolean;
66
+ errorRecovery: boolean;
67
+ };
68
+ modelId: string;
69
+ provider: string;
70
+ specificationVersion: "v2";
71
+ endpointName: string;
72
+ modelType: "huggingface" | "mistral" | "custom" | "claude" | "llama" | "jumpstart" | undefined;
73
+ region: string;
74
+ } | {
57
75
  capabilities: {
58
76
  streaming: boolean;
59
77
  toolCalling: boolean;
@@ -10,6 +10,9 @@ import { SageMakerLanguageModel } from "./sagemaker/language-model.js";
10
10
  * Amazon SageMaker Provider extending BaseProvider
11
11
  */
12
12
  export class AmazonSageMakerProvider extends BaseProvider {
13
+ // Kept as the concrete class so SageMaker-specific members
14
+ // (testConnectivity, getModelCapabilities) stay typed; getAISDKModel()
15
+ // narrows to the AI SDK handle shape at its boundary.
13
16
  sagemakerModel;
14
17
  sagemakerConfig;
15
18
  modelConfig;
@@ -41,8 +44,7 @@ export class AmazonSageMakerProvider extends BaseProvider {
41
44
  // SageMakerLanguageModel implements SageMakerAsLanguageModel which is
42
45
  // structurally compatible with LanguageModelV2 (specificationVersion "v2",
43
46
  // modelId, provider, supportedUrls, doGenerate, doStream).
44
- const smModel = new SageMakerLanguageModel(this.modelName, this.sagemakerConfig, this.modelConfig);
45
- this.sagemakerModel = smModel;
47
+ this.sagemakerModel = new SageMakerLanguageModel(this.modelName, this.sagemakerConfig, this.modelConfig);
46
48
  logger.debug("Amazon SageMaker Provider initialized", {
47
49
  modelName: this.modelName,
48
50
  endpointName: this.modelConfig.endpointName,
@@ -66,7 +68,11 @@ export class AmazonSageMakerProvider extends BaseProvider {
66
68
  return getSageMakerModel();
67
69
  }
68
70
  getAISDKModel() {
69
- return this.sagemakerModel;
71
+ // Same sanctioned two-step as construction previously used: the class
72
+ // satisfies the structural SageMakerAsLanguageModel shape, which is
73
+ // single-assertable to the AI SDK LanguageModel handle.
74
+ const smModel = this.sagemakerModel;
75
+ return smModel;
70
76
  }
71
77
  async executeStream(_options, _analysisSchema) {
72
78
  return withSpan({
@@ -1072,7 +1072,11 @@ export class AnthropicProvider extends BaseProvider {
1072
1072
  const modelId = this.modelName || getDefaultAnthropicModel();
1073
1073
  const getTimeoutForOptions = (opts) => this.getTimeout((opts ?? {}));
1074
1074
  const refreshAuth = () => this.refreshAuthIfNeeded();
1075
- return {
1075
+ // Structural AI-SDK model shape (`SageMakerAsLanguageModel`, the
1076
+ // sanctioned intermediate from src/lib/types/providers.ts): assigning the
1077
+ // literal to it keeps the compiler's member checks, and the intermediate
1078
+ // is single-assertable to the ai-package `LanguageModel` handle.
1079
+ const delegatingModel = {
1076
1080
  specificationVersion: "v3",
1077
1081
  provider: providerName,
1078
1082
  modelId,
@@ -1259,6 +1263,7 @@ export class AnthropicProvider extends BaseProvider {
1259
1263
  throw new Error(`${providerName}: doStream is not implemented on the delegating model — the streaming path uses executeStream directly.`);
1260
1264
  },
1261
1265
  };
1266
+ return delegatingModel;
1262
1267
  }
1263
1268
  formatProviderError(error) {
1264
1269
  if (error instanceof TimeoutError) {
@@ -1282,10 +1282,9 @@ export class GoogleAIStudioProvider extends BaseProvider {
1282
1282
  if (queue.length > 0) {
1283
1283
  const item = queue.shift();
1284
1284
  if (!item) {
1285
- return {
1286
- value: undefined,
1287
- done: true,
1288
- };
1285
+ // `done: true` selects the IteratorReturnResult arm, whose
1286
+ // value type accepts undefined.
1287
+ return { value: undefined, done: true };
1289
1288
  }
1290
1289
  if (item.type === "audio") {
1291
1290
  return {
@@ -1295,10 +1294,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
1295
1294
  }
1296
1295
  if (item.type === "end") {
1297
1296
  done = true;
1298
- return {
1299
- value: undefined,
1300
- done: true,
1301
- };
1297
+ return { value: undefined, done: true };
1302
1298
  }
1303
1299
  if (item.type === "error") {
1304
1300
  done = true;
@@ -1308,10 +1304,7 @@ export class GoogleAIStudioProvider extends BaseProvider {
1308
1304
  }
1309
1305
  }
1310
1306
  if (done) {
1311
- return {
1312
- value: undefined,
1313
- done: true,
1314
- };
1307
+ return { value: undefined, done: true };
1315
1308
  }
1316
1309
  return await new Promise((resolve) => {
1317
1310
  resolveNext = resolve;
@@ -1443,6 +1443,9 @@ export class GoogleVertexProvider extends BaseProvider {
1443
1443
  const maxSteps = Number.isFinite(rawMaxSteps) && rawMaxSteps > 0
1444
1444
  ? Math.min(Math.floor(rawMaxSteps), 100) // Cap at 100 for safety
1445
1445
  : Math.min(DEFAULT_MAX_STEPS, 100);
1446
+ // Widened per-turn copy: the agentic loop appends functionCall /
1447
+ // functionResponse parts on top of the plain text/inlineData parts the
1448
+ // initial contents carry.
1446
1449
  const currentContents = [...contents];
1447
1450
  let finalText = "";
1448
1451
  // Last SDK finish reason seen across steps (Bug 2: previously never read,
@@ -1671,7 +1674,8 @@ export class GoogleVertexProvider extends BaseProvider {
1671
1674
  functionCall: fc,
1672
1675
  })),
1673
1676
  });
1674
- // Execute each function and collect responses
1677
+ // Execute each function and collect responses (plus an optional
1678
+ // trailing wrap-up nudge text part).
1675
1679
  const functionResponses = [];
1676
1680
  // Per-step bookkeeping for conversation-memory storage.
1677
1681
  const stepStorageCalls = [];
@@ -2080,6 +2084,10 @@ export class GoogleVertexProvider extends BaseProvider {
2080
2084
  // (assistant text empty but tools ran) and downstream consumers see
2081
2085
  // the same shape AI-SDK-driven providers expose.
2082
2086
  toolsUsed: externalToolCalls.map((tc) => tc.toolName),
2087
+ // transformToolExecutions' record shape (name/input/output/duration) is
2088
+ // what downstream consumers read at runtime; it shares no required
2089
+ // members with the declared ToolExecutionSummary element type, so the
2090
+ // assertion carries both shapes instead of erasing the real one.
2083
2091
  toolExecutions: transformToolExecutions(externalToolExecutions),
2084
2092
  metadata: {
2085
2093
  streamId: `native-vertex-${Date.now()}`,
@@ -2378,6 +2386,9 @@ export class GoogleVertexProvider extends BaseProvider {
2378
2386
  const maxSteps = Number.isFinite(rawMaxSteps) && rawMaxSteps > 0
2379
2387
  ? Math.min(Math.floor(rawMaxSteps), 100) // Cap at 100 for safety
2380
2388
  : Math.min(DEFAULT_MAX_STEPS, 100);
2389
+ // Widened per-turn copy: the agentic loop appends functionCall /
2390
+ // functionResponse parts on top of the plain text/inlineData parts the
2391
+ // initial contents carry.
2381
2392
  const currentContents = [...contents];
2382
2393
  let finalText = "";
2383
2394
  // Cross-step text accumulation + last SDK finish reason, so the
@@ -2595,7 +2606,8 @@ export class GoogleVertexProvider extends BaseProvider {
2595
2606
  functionCall: fc,
2596
2607
  })),
2597
2608
  });
2598
- // Execute each function and collect responses
2609
+ // Execute each function and collect responses (plus an optional
2610
+ // trailing wrap-up nudge text part).
2599
2611
  const functionResponses = [];
2600
2612
  const toolCallsBefore = allToolCalls.length;
2601
2613
  const toolExecsBefore = toolExecutions.length;
@@ -3094,9 +3106,18 @@ export class GoogleVertexProvider extends BaseProvider {
3094
3106
  // `prepareOptions()` is a separate continuation and still surfaces auth
3095
3107
  // errors to callers. `void` flags the returned promise as deliberately
3096
3108
  // ignored (codebase convention for fire-and-forget).
3097
- void client._authClientPromise?.catch(() => {
3098
- // Intentionally ignored see above.
3099
- });
3109
+ //
3110
+ // `_authClientPromise` is a private SDK internal, so it is reached via
3111
+ // runtime narrowing (`in` + `instanceof`) rather than a type assertion.
3112
+ const clientInternals = client;
3113
+ if ("_authClientPromise" in clientInternals) {
3114
+ const authClientPromise = clientInternals._authClientPromise;
3115
+ if (authClientPromise instanceof Promise) {
3116
+ void authClientPromise.catch(() => {
3117
+ // Intentionally ignored — see above.
3118
+ });
3119
+ }
3120
+ }
3100
3121
  return client;
3101
3122
  }
3102
3123
  /**
@@ -291,6 +291,8 @@ export class OpenAIChatCompletionsProvider extends BaseProvider {
291
291
  */
292
292
  async getAISDKModel() {
293
293
  const modelId = await this.resolveModelName();
294
+ // buildDelegatingModel returns `unknown`, so this is a single
295
+ // unknown-to-target assertion.
294
296
  return this.buildDelegatingModel(modelId);
295
297
  }
296
298
  async resolveModelName() {
@@ -192,7 +192,8 @@ export function handleSageMakerError(error, endpoint) {
192
192
  /**
193
193
  * Extract request ID from AWS SDK error for debugging
194
194
  *
195
- * @param error - Error object that might contain request ID
195
+ * @param error - Error object that might contain request ID (AWS SDK errors
196
+ * carry it as an untyped extra field, so the value is treated as opaque)
196
197
  * @returns Request ID if found, undefined otherwise
197
198
  */
198
199
  function extractRequestId(error) {