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 { Effect } from 'effect'; |
| 2 | import { type Cause, hasInterruptsOnly } from 'effect/Cause'; |
| 3 | import type { FileSystem } from 'effect/FileSystem'; |
| 4 | import type { Path } from 'effect/Path'; |
| 5 | |
| 6 | import { captureErrorsFrom } from 'effect-errors/logic/errors'; |
| 7 | import { |
| 8 | type ErrorLocation, |
| 9 | type ErrorRelatedSources, |
| 10 | transformRawError, |
| 11 | } from 'effect-errors/sourcemaps'; |
| 12 | import type { ErrorSpan } from 'effect-errors/types'; |
| 13 | |
| 14 | export interface ErrorData { |
| 15 | errorType: unknown; |
| 16 | message: unknown; |
| 17 | stack: string[] | undefined; |
| 18 | sources: Omit<ErrorRelatedSources, '_tag'>[] | undefined; |
| 19 | location: Omit<ErrorLocation, '_tag'>[] | undefined; |
| 20 | spans: ReadonlyArray<ErrorSpan> | undefined; |
| 21 | isPlainString: boolean; |
| 22 | } |
| 23 | |
| 24 | export interface CapturedErrors { |
| 25 | interrupted: boolean; |
| 26 | errors: ErrorData[]; |
| 27 | } |
| 28 | |
| 29 | export interface CaptureErrorsOptions { |
| 30 | stripCwd?: boolean; |
| 31 | } |
| 32 | |
| 33 | export const captureErrors = <E>( |
| 34 | cause: Cause<E>, |
| 35 | options: CaptureErrorsOptions = { |
| 36 | stripCwd: true, |
| 37 | } |
| 38 | ): Effect.Effect<CapturedErrors, never, FileSystem | Path> => |
| 39 | Effect.gen(function* () { |
| 40 | if (hasInterruptsOnly(cause)) { |
| 41 | return { |
| 42 | interrupted: true, |
| 43 | errors: [], |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | const rawErrors = captureErrorsFrom<E>(cause); |
| 48 | const errors = yield* Effect.forEach(rawErrors, transformRawError(options)); |
| 49 | |
| 50 | return { |
| 51 | interrupted: false, |
| 52 | errors, |
| 53 | }; |
| 54 | }); |