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, Layer, Option } from 'effect'; |
| 2 | import { |
| 3 | PendingLoginError, |
| 4 | PendingLoginSession, |
| 5 | type PendingLogin, |
| 6 | } from 'src/services/pending-login-session'; |
| 7 | |
| 8 | /** |
| 9 | * An in-memory `PendingLoginSession`: `write` stamps `cachedAt`, `read` answers what was |
| 10 | * written (or `initial`) and fails as `missing` once cleared, and `current` shows the cached |
| 11 | * login, for assertions. |
| 12 | */ |
| 13 | export const PendingLoginSessionTest = (initial: Option.Option<PendingLogin> = Option.none()) => { |
| 14 | let cached = initial; |
| 15 | const service = PendingLoginSession.of({ |
| 16 | write: session => |
| 17 | Effect.sync(() => { |
| 18 | cached = Option.some({ ...session, cachedAt: '2026-01-01T00:00:00.000Z' }); |
| 19 | }), |
| 20 | read: Effect.suspend(() => |
| 21 | Option.match(cached, { |
| 22 | onSome: Effect.succeed, |
| 23 | onNone: () => |
| 24 | Effect.fail( |
| 25 | new PendingLoginError({ |
| 26 | message: 'No pending login found. Run `composio login < /dev/null` first.', |
| 27 | reason: 'missing', |
| 28 | }) |
| 29 | ), |
| 30 | }) |
| 31 | ), |
| 32 | clear: Effect.sync(() => { |
| 33 | cached = Option.none(); |
| 34 | }), |
| 35 | }); |
| 36 | return { |
| 37 | layer: Layer.succeed(PendingLoginSession, service), |
| 38 | current: () => cached, |
| 39 | }; |
| 40 | }; |