@juspay/neurolink 9.36.1 → 9.38.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 (211) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/auth/errors.d.ts +1 -1
  3. package/dist/auth/middleware/AuthMiddleware.d.ts +1 -1
  4. package/dist/auth/providers/BaseAuthProvider.d.ts +1 -1
  5. package/dist/browser/neurolink.min.js +1105 -556
  6. package/dist/cli/commands/evaluate.d.ts +48 -0
  7. package/dist/cli/commands/evaluate.js +955 -0
  8. package/dist/cli/parser.js +4 -1
  9. package/dist/evaluation/BatchEvaluator.d.ts +163 -0
  10. package/dist/evaluation/BatchEvaluator.js +267 -0
  11. package/dist/evaluation/EvaluationAggregator.d.ts +272 -0
  12. package/dist/evaluation/EvaluationAggregator.js +377 -0
  13. package/dist/evaluation/EvaluatorFactory.d.ts +113 -0
  14. package/dist/evaluation/EvaluatorFactory.js +280 -0
  15. package/dist/evaluation/EvaluatorRegistry.d.ts +160 -0
  16. package/dist/evaluation/EvaluatorRegistry.js +184 -0
  17. package/dist/evaluation/errors/EvaluationError.d.ts +189 -0
  18. package/dist/evaluation/errors/EvaluationError.js +206 -0
  19. package/dist/evaluation/errors/index.d.ts +4 -0
  20. package/dist/evaluation/errors/index.js +4 -0
  21. package/dist/evaluation/hooks/index.d.ts +6 -0
  22. package/dist/evaluation/hooks/index.js +6 -0
  23. package/dist/evaluation/hooks/langfuseAdapter.d.ts +99 -0
  24. package/dist/evaluation/hooks/langfuseAdapter.js +172 -0
  25. package/dist/evaluation/hooks/observabilityHooks.d.ts +129 -0
  26. package/dist/evaluation/hooks/observabilityHooks.js +181 -0
  27. package/dist/evaluation/index.d.ts +11 -2
  28. package/dist/evaluation/index.js +15 -0
  29. package/dist/evaluation/pipeline/evaluationPipeline.d.ts +114 -0
  30. package/dist/evaluation/pipeline/evaluationPipeline.js +381 -0
  31. package/dist/evaluation/pipeline/index.d.ts +8 -0
  32. package/dist/evaluation/pipeline/index.js +8 -0
  33. package/dist/evaluation/pipeline/pipelineBuilder.d.ts +126 -0
  34. package/dist/evaluation/pipeline/pipelineBuilder.js +260 -0
  35. package/dist/evaluation/pipeline/presets.d.ts +66 -0
  36. package/dist/evaluation/pipeline/presets.js +224 -0
  37. package/dist/evaluation/pipeline/strategies/batchStrategy.d.ts +99 -0
  38. package/dist/evaluation/pipeline/strategies/batchStrategy.js +238 -0
  39. package/dist/evaluation/pipeline/strategies/index.d.ts +6 -0
  40. package/dist/evaluation/pipeline/strategies/index.js +6 -0
  41. package/dist/evaluation/pipeline/strategies/samplingStrategy.d.ts +76 -0
  42. package/dist/evaluation/pipeline/strategies/samplingStrategy.js +238 -0
  43. package/dist/evaluation/reporting/index.d.ts +6 -0
  44. package/dist/evaluation/reporting/index.js +6 -0
  45. package/dist/evaluation/reporting/metricsCollector.d.ts +147 -0
  46. package/dist/evaluation/reporting/metricsCollector.js +285 -0
  47. package/dist/evaluation/reporting/reportGenerator.d.ts +90 -0
  48. package/dist/evaluation/reporting/reportGenerator.js +374 -0
  49. package/dist/evaluation/scorers/baseScorer.d.ts +83 -0
  50. package/dist/evaluation/scorers/baseScorer.js +232 -0
  51. package/dist/evaluation/scorers/customScorerUtils.d.ts +95 -0
  52. package/dist/evaluation/scorers/customScorerUtils.js +381 -0
  53. package/dist/evaluation/scorers/index.d.ts +10 -0
  54. package/dist/evaluation/scorers/index.js +16 -0
  55. package/dist/evaluation/scorers/llm/answerRelevancyScorer.d.ts +12 -0
  56. package/dist/evaluation/scorers/llm/answerRelevancyScorer.js +99 -0
  57. package/dist/evaluation/scorers/llm/baseLLMScorer.d.ts +71 -0
  58. package/dist/evaluation/scorers/llm/baseLLMScorer.js +281 -0
  59. package/dist/evaluation/scorers/llm/biasDetectionScorer.d.ts +12 -0
  60. package/dist/evaluation/scorers/llm/biasDetectionScorer.js +127 -0
  61. package/dist/evaluation/scorers/llm/contextPrecisionScorer.d.ts +12 -0
  62. package/dist/evaluation/scorers/llm/contextPrecisionScorer.js +92 -0
  63. package/dist/evaluation/scorers/llm/contextRelevancyScorer.d.ts +12 -0
  64. package/dist/evaluation/scorers/llm/contextRelevancyScorer.js +107 -0
  65. package/dist/evaluation/scorers/llm/faithfulnessScorer.d.ts +12 -0
  66. package/dist/evaluation/scorers/llm/faithfulnessScorer.js +121 -0
  67. package/dist/evaluation/scorers/llm/hallucinationScorer.d.ts +12 -0
  68. package/dist/evaluation/scorers/llm/hallucinationScorer.js +140 -0
  69. package/dist/evaluation/scorers/llm/index.d.ts +15 -0
  70. package/dist/evaluation/scorers/llm/index.js +16 -0
  71. package/dist/evaluation/scorers/llm/promptAlignmentScorer.d.ts +12 -0
  72. package/dist/evaluation/scorers/llm/promptAlignmentScorer.js +106 -0
  73. package/dist/evaluation/scorers/llm/summarizationScorer.d.ts +12 -0
  74. package/dist/evaluation/scorers/llm/summarizationScorer.js +114 -0
  75. package/dist/evaluation/scorers/llm/toneConsistencyScorer.d.ts +12 -0
  76. package/dist/evaluation/scorers/llm/toneConsistencyScorer.js +106 -0
  77. package/dist/evaluation/scorers/llm/toxicityScorer.d.ts +12 -0
  78. package/dist/evaluation/scorers/llm/toxicityScorer.js +121 -0
  79. package/dist/evaluation/scorers/rule/baseRuleScorer.d.ts +77 -0
  80. package/dist/evaluation/scorers/rule/baseRuleScorer.js +233 -0
  81. package/dist/evaluation/scorers/rule/contentSimilarityScorer.d.ts +108 -0
  82. package/dist/evaluation/scorers/rule/contentSimilarityScorer.js +350 -0
  83. package/dist/evaluation/scorers/rule/formatScorer.d.ts +147 -0
  84. package/dist/evaluation/scorers/rule/formatScorer.js +470 -0
  85. package/dist/evaluation/scorers/rule/index.d.ts +9 -0
  86. package/dist/evaluation/scorers/rule/index.js +10 -0
  87. package/dist/evaluation/scorers/rule/keywordCoverageScorer.d.ts +83 -0
  88. package/dist/evaluation/scorers/rule/keywordCoverageScorer.js +347 -0
  89. package/dist/evaluation/scorers/rule/lengthScorer.d.ts +105 -0
  90. package/dist/evaluation/scorers/rule/lengthScorer.js +351 -0
  91. package/dist/evaluation/scorers/scorerBuilder.d.ts +161 -0
  92. package/dist/evaluation/scorers/scorerBuilder.js +420 -0
  93. package/dist/evaluation/scorers/scorerRegistry.d.ts +62 -0
  94. package/dist/evaluation/scorers/scorerRegistry.js +467 -0
  95. package/dist/index.d.ts +37 -25
  96. package/dist/index.js +65 -26
  97. package/dist/lib/auth/providers/BaseAuthProvider.d.ts +1 -1
  98. package/dist/lib/evaluation/BatchEvaluator.d.ts +163 -0
  99. package/dist/lib/evaluation/BatchEvaluator.js +268 -0
  100. package/dist/lib/evaluation/EvaluationAggregator.d.ts +272 -0
  101. package/dist/lib/evaluation/EvaluationAggregator.js +378 -0
  102. package/dist/lib/evaluation/EvaluatorFactory.d.ts +113 -0
  103. package/dist/lib/evaluation/EvaluatorFactory.js +281 -0
  104. package/dist/lib/evaluation/EvaluatorRegistry.d.ts +160 -0
  105. package/dist/lib/evaluation/EvaluatorRegistry.js +185 -0
  106. package/dist/lib/evaluation/errors/EvaluationError.d.ts +189 -0
  107. package/dist/lib/evaluation/errors/EvaluationError.js +207 -0
  108. package/dist/lib/evaluation/errors/index.d.ts +4 -0
  109. package/dist/lib/evaluation/errors/index.js +5 -0
  110. package/dist/lib/evaluation/hooks/index.d.ts +6 -0
  111. package/dist/lib/evaluation/hooks/index.js +7 -0
  112. package/dist/lib/evaluation/hooks/langfuseAdapter.d.ts +99 -0
  113. package/dist/lib/evaluation/hooks/langfuseAdapter.js +173 -0
  114. package/dist/lib/evaluation/hooks/observabilityHooks.d.ts +129 -0
  115. package/dist/lib/evaluation/hooks/observabilityHooks.js +182 -0
  116. package/dist/lib/evaluation/index.d.ts +11 -2
  117. package/dist/lib/evaluation/index.js +15 -0
  118. package/dist/lib/evaluation/pipeline/evaluationPipeline.d.ts +114 -0
  119. package/dist/lib/evaluation/pipeline/evaluationPipeline.js +382 -0
  120. package/dist/lib/evaluation/pipeline/index.d.ts +8 -0
  121. package/dist/lib/evaluation/pipeline/index.js +9 -0
  122. package/dist/lib/evaluation/pipeline/pipelineBuilder.d.ts +126 -0
  123. package/dist/lib/evaluation/pipeline/pipelineBuilder.js +261 -0
  124. package/dist/lib/evaluation/pipeline/presets.d.ts +66 -0
  125. package/dist/lib/evaluation/pipeline/presets.js +225 -0
  126. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.d.ts +99 -0
  127. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +239 -0
  128. package/dist/lib/evaluation/pipeline/strategies/index.d.ts +6 -0
  129. package/dist/lib/evaluation/pipeline/strategies/index.js +7 -0
  130. package/dist/lib/evaluation/pipeline/strategies/samplingStrategy.d.ts +76 -0
  131. package/dist/lib/evaluation/pipeline/strategies/samplingStrategy.js +239 -0
  132. package/dist/lib/evaluation/reporting/index.d.ts +6 -0
  133. package/dist/lib/evaluation/reporting/index.js +7 -0
  134. package/dist/lib/evaluation/reporting/metricsCollector.d.ts +147 -0
  135. package/dist/lib/evaluation/reporting/metricsCollector.js +286 -0
  136. package/dist/lib/evaluation/reporting/reportGenerator.d.ts +90 -0
  137. package/dist/lib/evaluation/reporting/reportGenerator.js +375 -0
  138. package/dist/lib/evaluation/scorers/baseScorer.d.ts +83 -0
  139. package/dist/lib/evaluation/scorers/baseScorer.js +233 -0
  140. package/dist/lib/evaluation/scorers/customScorerUtils.d.ts +95 -0
  141. package/dist/lib/evaluation/scorers/customScorerUtils.js +382 -0
  142. package/dist/lib/evaluation/scorers/index.d.ts +10 -0
  143. package/dist/lib/evaluation/scorers/index.js +17 -0
  144. package/dist/lib/evaluation/scorers/llm/answerRelevancyScorer.d.ts +12 -0
  145. package/dist/lib/evaluation/scorers/llm/answerRelevancyScorer.js +100 -0
  146. package/dist/lib/evaluation/scorers/llm/baseLLMScorer.d.ts +71 -0
  147. package/dist/lib/evaluation/scorers/llm/baseLLMScorer.js +282 -0
  148. package/dist/lib/evaluation/scorers/llm/biasDetectionScorer.d.ts +12 -0
  149. package/dist/lib/evaluation/scorers/llm/biasDetectionScorer.js +128 -0
  150. package/dist/lib/evaluation/scorers/llm/contextPrecisionScorer.d.ts +12 -0
  151. package/dist/lib/evaluation/scorers/llm/contextPrecisionScorer.js +93 -0
  152. package/dist/lib/evaluation/scorers/llm/contextRelevancyScorer.d.ts +12 -0
  153. package/dist/lib/evaluation/scorers/llm/contextRelevancyScorer.js +108 -0
  154. package/dist/lib/evaluation/scorers/llm/faithfulnessScorer.d.ts +12 -0
  155. package/dist/lib/evaluation/scorers/llm/faithfulnessScorer.js +122 -0
  156. package/dist/lib/evaluation/scorers/llm/hallucinationScorer.d.ts +12 -0
  157. package/dist/lib/evaluation/scorers/llm/hallucinationScorer.js +141 -0
  158. package/dist/lib/evaluation/scorers/llm/index.d.ts +15 -0
  159. package/dist/lib/evaluation/scorers/llm/index.js +17 -0
  160. package/dist/lib/evaluation/scorers/llm/promptAlignmentScorer.d.ts +12 -0
  161. package/dist/lib/evaluation/scorers/llm/promptAlignmentScorer.js +107 -0
  162. package/dist/lib/evaluation/scorers/llm/summarizationScorer.d.ts +12 -0
  163. package/dist/lib/evaluation/scorers/llm/summarizationScorer.js +115 -0
  164. package/dist/lib/evaluation/scorers/llm/toneConsistencyScorer.d.ts +12 -0
  165. package/dist/lib/evaluation/scorers/llm/toneConsistencyScorer.js +107 -0
  166. package/dist/lib/evaluation/scorers/llm/toxicityScorer.d.ts +12 -0
  167. package/dist/lib/evaluation/scorers/llm/toxicityScorer.js +122 -0
  168. package/dist/lib/evaluation/scorers/rule/baseRuleScorer.d.ts +77 -0
  169. package/dist/lib/evaluation/scorers/rule/baseRuleScorer.js +234 -0
  170. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.d.ts +108 -0
  171. package/dist/lib/evaluation/scorers/rule/contentSimilarityScorer.js +351 -0
  172. package/dist/lib/evaluation/scorers/rule/formatScorer.d.ts +147 -0
  173. package/dist/lib/evaluation/scorers/rule/formatScorer.js +471 -0
  174. package/dist/lib/evaluation/scorers/rule/index.d.ts +9 -0
  175. package/dist/lib/evaluation/scorers/rule/index.js +11 -0
  176. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.d.ts +83 -0
  177. package/dist/lib/evaluation/scorers/rule/keywordCoverageScorer.js +348 -0
  178. package/dist/lib/evaluation/scorers/rule/lengthScorer.d.ts +105 -0
  179. package/dist/lib/evaluation/scorers/rule/lengthScorer.js +352 -0
  180. package/dist/lib/evaluation/scorers/scorerBuilder.d.ts +161 -0
  181. package/dist/lib/evaluation/scorers/scorerBuilder.js +421 -0
  182. package/dist/lib/evaluation/scorers/scorerRegistry.d.ts +62 -0
  183. package/dist/lib/evaluation/scorers/scorerRegistry.js +468 -0
  184. package/dist/lib/index.d.ts +37 -25
  185. package/dist/lib/index.js +65 -26
  186. package/dist/lib/neurolink.d.ts +204 -0
  187. package/dist/lib/neurolink.js +296 -0
  188. package/dist/lib/processors/media/VideoProcessor.d.ts +8 -2
  189. package/dist/lib/processors/media/VideoProcessor.js +90 -41
  190. package/dist/lib/telemetry/telemetryService.d.ts +1 -1
  191. package/dist/lib/telemetry/telemetryService.js +27 -13
  192. package/dist/lib/types/index.d.ts +3 -1
  193. package/dist/lib/types/index.js +3 -2
  194. package/dist/lib/types/scorerTypes.d.ts +423 -0
  195. package/dist/lib/types/scorerTypes.js +6 -0
  196. package/dist/lib/utils/errorHandling.d.ts +20 -0
  197. package/dist/lib/utils/errorHandling.js +60 -0
  198. package/dist/neurolink.d.ts +204 -0
  199. package/dist/neurolink.js +296 -0
  200. package/dist/processors/media/VideoProcessor.d.ts +8 -2
  201. package/dist/processors/media/VideoProcessor.js +90 -41
  202. package/dist/telemetry/telemetryService.d.ts +1 -1
  203. package/dist/telemetry/telemetryService.js +27 -13
  204. package/dist/types/index.d.ts +3 -1
  205. package/dist/types/index.js +3 -2
  206. package/dist/types/scorerTypes.d.ts +423 -0
  207. package/dist/types/scorerTypes.js +5 -0
  208. package/dist/utils/errorHandling.d.ts +20 -0
  209. package/dist/utils/errorHandling.js +60 -0
  210. package/package.json +7 -7
  211. package/dist/processors/media/ffprobe-static.d.ts +0 -4
@@ -10,8 +10,9 @@
10
10
  * The extracted content is formatted as text + images that can be sent to any
11
11
  * AI provider for analysis.
12
12
  *
13
- * Uses fluent-ffmpeg for video processing and sharp for frame resizing.
14
- * Requires ffmpeg/ffprobe to be available (via ffmpeg-static or system PATH).
13
+ * Uses mediabunny (pure TypeScript) for metadata extraction, with fluent-ffmpeg
14
+ * as a fallback for unsupported formats. Requires ffmpeg for keyframe/subtitle
15
+ * extraction (via ffmpeg-static or system PATH).
15
16
  *
16
17
  * Key features:
17
18
  * - Adaptive keyframe extraction intervals based on video duration
@@ -42,10 +43,10 @@
42
43
  * }
43
44
  * ```
44
45
  */
45
- /// <reference path="./ffprobe-static.d.ts" />
46
46
  import { randomUUID } from "crypto";
47
47
  import ffmpegCommand from "fluent-ffmpeg";
48
48
  import { createWriteStream, existsSync, promises as fs } from "fs";
49
+ import { Input, FilePathSource, ALL_FORMATS } from "mediabunny";
49
50
  import { tmpdir } from "os";
50
51
  import { join } from "path";
51
52
  import { Readable } from "stream";
@@ -64,8 +65,12 @@ import { logger } from "../../utils/logger.js";
64
65
  */
65
66
  let ffmpegPathInitialized = false;
66
67
  /**
67
- * Initialize ffmpeg and ffprobe binary paths.
68
- * Tries ffmpeg-static/ffprobe-static first, falls back to system binaries in PATH.
68
+ * Initialize ffmpeg binary paths.
69
+ * Tries ffmpeg-static first, falls back to system binary in PATH.
70
+ *
71
+ * Note: ffprobe-static has been removed. Metadata probing now uses mediabunny
72
+ * (pure TypeScript) as the primary method, with ffprobe as a fallback only when
73
+ * mediabunny cannot handle the format (e.g., AVI, FLV).
69
74
  *
70
75
  * This is called lazily on the first processFile() invocation so that the module
71
76
  * can be imported without side effects.
@@ -91,27 +96,6 @@ async function initFfmpegPaths() {
91
96
  catch {
92
97
  // Use system ffmpeg (already in PATH)
93
98
  }
94
- // Try ffprobe-static first, fall back to system ffprobe
95
- try {
96
- const ffprobeStatic = (await import("ffprobe-static"));
97
- // Direct path property (CommonJS default)
98
- if (typeof ffprobeStatic["path"] === "string" &&
99
- existsSync(ffprobeStatic["path"])) {
100
- ffmpegCommand.setFfprobePath(ffprobeStatic["path"]);
101
- }
102
- else if (ffprobeStatic["default"] &&
103
- typeof ffprobeStatic["default"] === "object" &&
104
- typeof ffprobeStatic["default"]["path"] ===
105
- "string") {
106
- const probePath = ffprobeStatic["default"]["path"];
107
- if (existsSync(probePath)) {
108
- ffmpegCommand.setFfprobePath(probePath);
109
- }
110
- }
111
- }
112
- catch {
113
- // Use system ffprobe (already in PATH)
114
- }
115
99
  }
116
100
  // =============================================================================
117
101
  // CONSTANTS
@@ -372,23 +356,33 @@ export class VideoProcessor extends BaseFileProcessor {
372
356
  const extension = this.getExtensionFromFileInfo(fileInfo);
373
357
  const tempVideoPath = join(tempDir, `input${extension}`);
374
358
  await this.writeBufferToFile(buffer, tempVideoPath);
375
- // Step 4: Extract metadata via ffprobe
376
- const probeResult = await this.probeVideo(tempVideoPath);
377
- if (!probeResult.success) {
378
- const errMsg = probeResult.error || "ffprobe failed";
379
- span.setAttribute(ATTR.FILE_SUCCESS, false);
380
- span.setAttribute(ATTR.FILE_ERROR, errMsg);
381
- logger.warn(`[NEUROLINK] Video skipped/failed: ${filename} — reason: ${errMsg}`);
382
- return {
383
- success: false,
384
- error: this.createError(FileErrorCode.PROCESSING_FAILED, {
385
- fileType: "video",
386
- reason: probeResult.error,
387
- }),
359
+ // Step 4: Extract metadata try mediabunny first (pure TS, no binary),
360
+ // fall back to ffprobe for formats mediabunny doesn't support (AVI, FLV, WMV).
361
+ let metadata;
362
+ const mediabunnyResult = await this.probeVideoWithMediabunny(tempVideoPath);
363
+ if (mediabunnyResult.success && mediabunnyResult.data) {
364
+ metadata = { ...mediabunnyResult.data, fileSize: buffer.length };
365
+ }
366
+ else {
367
+ // Fall back to ffprobe (requires system ffprobe to be available)
368
+ const probeResult = await this.probeVideo(tempVideoPath);
369
+ if (probeResult.success && probeResult.data) {
370
+ metadata = this.buildMetadata(probeResult.data, buffer.length);
371
+ }
372
+ }
373
+ if (!metadata) {
374
+ metadata = {
375
+ duration: 0,
376
+ durationFormatted: "unknown",
377
+ width: 0,
378
+ height: 0,
379
+ codec: "unknown",
380
+ fps: 0,
381
+ bitrate: 0,
382
+ subtitleTracks: 0,
383
+ fileSize: buffer.length,
388
384
  };
389
385
  }
390
- const probeData = probeResult.data;
391
- const metadata = this.buildMetadata(probeData, buffer.length);
392
386
  // Record video-specific metadata on span
393
387
  span.setAttribute(ATTR.VIDEO_DURATION_SEC, metadata.duration);
394
388
  span.setAttribute(ATTR.VIDEO_WIDTH, metadata.width);
@@ -494,6 +488,61 @@ export class VideoProcessor extends BaseFileProcessor {
494
488
  });
495
489
  });
496
490
  }
491
+ /**
492
+ * Probe a video file using mediabunny (pure TypeScript, no native binary).
493
+ * Falls back to ffprobe if mediabunny fails or doesn't support the format.
494
+ */
495
+ async probeVideoWithMediabunny(filePath) {
496
+ let input;
497
+ try {
498
+ input = new Input({
499
+ source: new FilePathSource(filePath),
500
+ formats: [...ALL_FORMATS],
501
+ });
502
+ const duration = await input.computeDuration();
503
+ const videoTrack = await input.getPrimaryVideoTrack();
504
+ const audioTrack = await input.getPrimaryAudioTrack();
505
+ const allTracks = await input.getTracks();
506
+ const subtitleTracks = allTracks.filter((t) => !t.isVideoTrack() && !t.isAudioTrack());
507
+ // Get FPS from video track packet stats (sample a small number of packets)
508
+ let fps = 0;
509
+ if (videoTrack) {
510
+ try {
511
+ const stats = await videoTrack.computePacketStats(120);
512
+ fps = Math.round(stats.averagePacketRate * 100) / 100;
513
+ }
514
+ catch {
515
+ // FPS unavailable — non-fatal
516
+ }
517
+ }
518
+ return {
519
+ success: true,
520
+ data: {
521
+ duration: duration ?? 0,
522
+ durationFormatted: this.formatDuration(duration ?? 0),
523
+ width: videoTrack?.displayWidth ?? 0,
524
+ height: videoTrack?.displayHeight ?? 0,
525
+ codec: videoTrack?.codec ?? "unknown",
526
+ fps,
527
+ bitrate: 0,
528
+ audioCodec: audioTrack?.codec ?? undefined,
529
+ audioChannels: audioTrack?.numberOfChannels,
530
+ audioSampleRate: audioTrack?.sampleRate,
531
+ subtitleTracks: subtitleTracks.length,
532
+ fileSize: 0,
533
+ },
534
+ };
535
+ }
536
+ catch (error) {
537
+ return {
538
+ success: false,
539
+ error: `mediabunny failed: ${error instanceof Error ? error.message : String(error)}`,
540
+ };
541
+ }
542
+ finally {
543
+ input?.dispose();
544
+ }
545
+ }
497
546
  /**
498
547
  * Build a structured metadata object from ffprobe data.
499
548
  *
@@ -8,7 +8,7 @@ export type HealthMetrics = {
8
8
  };
9
9
  export declare class TelemetryService {
10
10
  private static instance;
11
- private sdk?;
11
+ private tracerProvider?;
12
12
  private enabled;
13
13
  private initialized;
14
14
  private meter?;
@@ -1,12 +1,12 @@
1
- import { NodeSDK } from "@opentelemetry/sdk-node";
2
- import { metrics, trace, } from "@opentelemetry/api";
3
- import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
1
+ import { context, metrics, trace, } from "@opentelemetry/api";
2
+ import { BasicTracerProvider, BatchSpanProcessor, } from "@opentelemetry/sdk-trace-base";
3
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
4
4
  import { resourceFromAttributes } from "@opentelemetry/resources";
5
5
  import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from "@opentelemetry/semantic-conventions";
6
6
  import { logger } from "../utils/logger.js";
7
7
  export class TelemetryService {
8
8
  static instance;
9
- sdk;
9
+ tracerProvider;
10
10
  enabled = false;
11
11
  initialized = false;
12
12
  meter;
@@ -52,11 +52,16 @@ export class TelemetryService {
52
52
  [ATTR_SERVICE_NAME]: process.env.OTEL_SERVICE_NAME || "neurolink-ai",
53
53
  [ATTR_SERVICE_VERSION]: process.env.OTEL_SERVICE_VERSION || "3.0.1",
54
54
  });
55
- this.sdk = new NodeSDK({
55
+ const exporter = new OTLPTraceExporter({
56
+ url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT
57
+ ? `${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`
58
+ : undefined,
59
+ });
60
+ this.tracerProvider = new BasicTracerProvider({
56
61
  resource,
57
- // Note: Metric reader configured separately
58
- instrumentations: [getNodeAutoInstrumentations()],
62
+ spanProcessors: [new BatchSpanProcessor(exporter)],
59
63
  });
64
+ trace.setGlobalTracerProvider(this.tracerProvider);
60
65
  this.meter = metrics.getMeter("neurolink-ai");
61
66
  this.tracer = trace.getTracer("neurolink-ai");
62
67
  this.initializeMetrics();
@@ -101,12 +106,21 @@ export class TelemetryService {
101
106
  return;
102
107
  }
103
108
  try {
104
- await this.sdk?.start();
109
+ // Register AsyncLocalStorage context manager for proper parent-child
110
+ // span relationships across async boundaries (required for startActiveSpan)
111
+ try {
112
+ const { AsyncLocalStorageContextManager } = await import("@opentelemetry/context-async-hooks");
113
+ context.setGlobalContextManager(new AsyncLocalStorageContextManager().enable());
114
+ }
115
+ catch {
116
+ // context-async-hooks not installed — context propagation
117
+ // will use the default (noop) manager
118
+ }
105
119
  this.initialized = true;
106
- logger.debug("[Telemetry] SDK started successfully");
120
+ logger.debug("[Telemetry] Tracer provider started successfully");
107
121
  }
108
122
  catch (error) {
109
- logger.error("[Telemetry] Failed to start SDK:", error);
123
+ logger.error("[Telemetry] Failed to start:", error);
110
124
  this.enabled = false;
111
125
  this.initialized = false;
112
126
  }
@@ -294,11 +308,11 @@ export class TelemetryService {
294
308
  }
295
309
  // Cleanup
296
310
  async shutdown() {
297
- if (this.enabled && this.sdk) {
311
+ if (this.enabled && this.tracerProvider) {
298
312
  try {
299
- await this.sdk.shutdown();
313
+ await this.tracerProvider.shutdown();
300
314
  this.initialized = false;
301
- logger.debug("[Telemetry] SDK shutdown completed");
315
+ logger.debug("[Telemetry] Tracer provider shutdown completed");
302
316
  }
303
317
  catch (error) {
304
318
  logger.error("[Telemetry] Error during shutdown:", error);
@@ -27,13 +27,15 @@ TextGenerationOptions, TextGenerationResult, UnifiedGenerationOptions, } from ".
27
27
  export * from "./hitlTypes.js";
28
28
  export * from "./middlewareTypes.js";
29
29
  export * from "./modelTypes.js";
30
+ export * from "./scorerTypes.js";
30
31
  export * from "./sdkTypes.js";
31
32
  export * from "./serviceTypes.js";
32
33
  export type { EnhancedStreamProvider, ProgressCallback, StreamingMetadata, StreamingOptions, StreamingProgressData, StreamOptions, StreamResult, ToolCall as StreamToolCall, // Renamed to avoid conflict with tools.js ToolCall
33
34
  ToolCallResults, ToolCalls, ToolResult as StreamToolResult, } from "./streamTypes.js";
34
35
  export * from "./ttsTypes.js";
35
36
  export * from "./utilities.js";
36
- export * from "./workflowTypes.js";
37
+ export type { AggregatedUsage, ConditioningConfig, ConditionOptions, ConditionResult, EnsembleExecutionResult, EnsembleResponse, ExecuteEnsembleOptions, ExecuteLayerOptions, ExecuteModelOptions, ExecutionConfig, ExecutionStrategy, JudgeConfig, JudgeOutputFormat, JudgeScores, LayerExecutionResult, ListOptions, ModelGroup, MultiJudgeScores, ParsedJudgeResponse, RegisterOptions, RegisterResult, RegistryEntry, RegistryStats, ScoreOptions, ScoreResult as WorkflowScoreResult, SummaryStats, ToneAdjustment, ValidationIssues, WorkflowAnalytics, WorkflowComparison, WorkflowConfig, WorkflowErrorDetails, WorkflowEvaluationData, WorkflowExecutionMetrics, WorkflowGenerateOptions, WorkflowInput, WorkflowMetadata, WorkflowModelConfig, WorkflowResult, WorkflowType, WorkflowValidationError, WorkflowValidationResult, WorkflowValidationWarning, } from "./workflowTypes.js";
38
+ export { WorkflowError } from "./workflowTypes.js";
37
39
  export * from "./contextTypes.js";
38
40
  export * from "./fileReferenceTypes.js";
39
41
  export * from "./ragTypes.js";
@@ -28,6 +28,8 @@ export * from "./hitlTypes.js";
28
28
  export * from "./middlewareTypes.js";
29
29
  // Model types - NEW
30
30
  export * from "./modelTypes.js";
31
+ // Scorer types for evaluation system
32
+ export * from "./scorerTypes.js";
31
33
  // SDK Types - Core types for external developers
32
34
  // Note: sdkTypes.ts uses selective re-exports internally, so we use wildcard here
33
35
  // The conflicts were from generateTypes and analytics which are now handled above
@@ -38,8 +40,7 @@ export * from "./serviceTypes.js";
38
40
  export * from "./ttsTypes.js";
39
41
  // Utilities Types - Utility module types (selective export to avoid conflicts)
40
42
  export * from "./utilities.js";
41
- // Workflow types
42
- export * from "./workflowTypes.js";
43
+ export { WorkflowError } from "./workflowTypes.js";
43
44
  // Context compaction types
44
45
  export * from "./contextTypes.js";
45
46
  // File reference types