Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import { FileSystem } from 'effect/FileSystem'; |
| 2 | import type { PlatformError } from 'effect/PlatformError'; |
| 3 | import { Effect } from 'effect'; |
| 4 | |
| 5 | import type { ErrorLocation } from './get-error-location-from-file-path'; |
| 6 | |
| 7 | export interface SourceCode { |
| 8 | line: number; |
| 9 | code: string; |
| 10 | column: number | undefined; |
| 11 | } |
| 12 | |
| 13 | const numberOflinesToExtract = 7; |
| 14 | |
| 15 | export const getSourceCode = ( |
| 16 | { filePath, line, column }: ErrorLocation, |
| 17 | isFromJs = false |
| 18 | ): Effect.Effect<SourceCode[], PlatformError, FileSystem> => |
| 19 | Effect.gen(function* () { |
| 20 | const fs = yield* FileSystem; |
| 21 | const sourceCode = yield* fs.readFileString(filePath, 'utf8'); |
| 22 | |
| 23 | const start = line >= 4 ? line - 4 : 0; |
| 24 | |
| 25 | return sourceCode |
| 26 | .split('\n') |
| 27 | .splice(start, numberOflinesToExtract) |
| 28 | .map((currentLine, index) => { |
| 29 | const currentLineNumber = index + start + 1; |
| 30 | |
| 31 | const actualColumn = isFromJs ? column + 1 : column; |
| 32 | |
| 33 | return { |
| 34 | line: currentLineNumber, |
| 35 | code: currentLine, |
| 36 | column: currentLineNumber === line ? actualColumn : undefined, |
| 37 | }; |
| 38 | }); |
| 39 | }); |