Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import type { SessionConfigs, SessionConfigListParams, SessionConfigSummary } from '@composio/core'; |
| 2 | |
| 3 | export async function listAllSessionConfigs( |
| 4 | sessionConfigs: Pick<SessionConfigs, 'list'>, |
| 5 | params: Pick<SessionConfigListParams, 'archived'> = {} |
| 6 | ): Promise<SessionConfigSummary[]> { |
| 7 | const items: SessionConfigSummary[] = []; |
| 8 | const seenCursors = new Set<string>(); |
| 9 | let cursor: string | undefined; |
| 10 | do { |
| 11 | const page = await sessionConfigs.list({ ...params, limit: 100, cursor }); |
| 12 | items.push(...page.items); |
| 13 | cursor = page.nextCursor ?? undefined; |
| 14 | if (cursor !== undefined) { |
| 15 | if (seenCursors.has(cursor)) |
| 16 | throw new Error(`Session config pagination repeated cursor: ${cursor}`); |
| 17 | seenCursors.add(cursor); |
| 18 | } |
| 19 | } while (cursor !== undefined); |
| 20 | return items; |
| 21 | } |
| 22 | |
| 23 | export async function cleanupVerificationSessions( |
| 24 | sessionIds: string[], |
| 25 | deleteSession: (id: string) => Promise<{ deleted: boolean }> |
| 26 | ): Promise<void> { |
| 27 | const failures: Error[] = []; |
| 28 | for (const id of sessionIds) { |
| 29 | try { |
| 30 | const result = await deleteSession(id); |
| 31 | if (!result.deleted) throw new Error('API did not confirm deletion'); |
| 32 | } catch (cause) { |
| 33 | failures.push(new Error(`Could not delete session ${id}`, { cause })); |
| 34 | } |
| 35 | } |
| 36 | if (failures.length > 0) { |
| 37 | throw new AggregateError(failures, failures.map(error => error.message).join('; ')); |
| 38 | } |
| 39 | } |