Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 32 lines 1.2 KB
Raw
1 import type { FileSystem } from 'effect/FileSystem';
2 import type { Path } from 'effect/Path';
3 import { Effect } from 'effect';
4
5 import { stackAtRegex } from 'effect-errors/logic/stack';
6
7 import { getErrorRelatedSources } from './get-error-related-sources';
8 import { MappedSources, type MaybeMappedSources } from './mapped-sources';
9
10 export const maybeMapSourcemaps = (
11 name: string,
12 stacktrace: string[]
13 ): Effect.Effect<MaybeMappedSources[], never, FileSystem | Path> =>
14 Effect.forEach(stacktrace, stackLine =>
15 Effect.gen(function* () {
16 const chunks = stackLine.trimStart().split(' ');
17 const mapFileReportedPath =
18 chunks.length === 2 ? chunks[1] : chunks[chunks.length - 1].slice(1, -1);
19
20 const details = yield* getErrorRelatedSources(name, mapFileReportedPath);
21 if (details === undefined) {
22 return MappedSources['stack-entry']({
23 runPath: stackLine.replaceAll(stackAtRegex, 'at '),
24 });
25 }
26
27 // `node_modules` frames are already dropped by `getSourcesFromMapFile`,
28 // which compares resolved paths through the `Path` service instead of
29 // interpolating the working directory into an unescaped `RegExp`.
30 return details;
31 })
32 );