@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
ts 37 lines 1.18 KB
Raw
1 import { Data, Effect, type Cause } from 'effect';
2
3 type RequestErrorFields = {
4 readonly message: string;
5 readonly cause: unknown;
6 };
7
8 /**
9 * Base class for a command's failure around a client request: the command's
10 * own message, with the client's error kept in `cause`, which the top-level
11 * printer renders as `Caused by:`.
12 *
13 * @example
14 * ```ts
15 * class ToolLogsRequestError extends requestError('commands/ToolLogsRequestError') {}
16 * ```
17 */
18 export const requestError = <Tag extends string>(
19 tag: Tag
20 ): new (
21 fields: RequestErrorFields
22 ) => Cause.YieldableError & { readonly _tag: Tag } & RequestErrorFields =>
23 Data.TaggedError(tag)<RequestErrorFields>;
24
25 /**
26 * Replaces any failure of an effect with `RequestError` carrying `message`,
27 * keeping the original failure as its cause.
28 *
29 * @example
30 * ```ts
31 * client.logs.createToolExecution(body, idempotent).pipe(failedWith(ToolLogsRequestError, 'Failed to fetch tool logs.'))
32 * ```
33 */
34 export const failedWith =
35 <E>(RequestError: new (fields: RequestErrorFields) => E, message: string) =>
36 <A, R>(self: Effect.Effect<A, unknown, R>): Effect.Effect<A, E, R> =>
37 Effect.mapError(self, cause => new RequestError({ message, cause }));