# All files / src/trpc/routers account.ts

6.25% Statements 1/16
100% Branches 0/0
12.5% Functions 1/8
6.25% Lines 1/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77

    11x

     /**
     * Account Router — list, add, remove, refresh, update auth, mark exhausted, providers
     */

    import { z } from 'zod';
    import type { ProcedureBuilder } from '../trpc.js';
    import { requireAccountRepository } from './_helpers.js';
    import { listProviders as listProviderNames } from '../../agent/providers/registry.js';

    export function accountProcedures(publicProcedure: ProcedureBuilder) {
      return {
        listAccounts: publicProcedure
          .query(async ({ ctx }) => {
            const repo = requireAccountRepository(ctx);
            return repo.findAll();
          }),

        addAccount: publicProcedure
          .input(z.object({
            email: z.string().min(1),
            provider: z.string().default('claude'),
            configJson: z.string().optional(),
            credentials: z.string().optional(),
          }))
          .mutation(async ({ ctx, input }) => {
            const repo = requireAccountRepository(ctx);
            return repo.create({
              email: input.email,
              provider: input.provider,
              configJson: input.configJson,
              credentials: input.credentials,
            });
          }),

        removeAccount: publicProcedure
          .input(z.object({ id: z.string().min(1) }))
          .mutation(async ({ ctx, input }) => {
            const repo = requireAccountRepository(ctx);
            await repo.delete(input.id);
            return { success: true };
          }),

        refreshAccounts: publicProcedure
          .mutation(async ({ ctx }) => {
            const repo = requireAccountRepository(ctx);
            const cleared = await repo.clearExpiredExhaustion();
            return { cleared };
          }),

        updateAccountAuth: publicProcedure
          .input(z.object({
            id: z.string().min(1),
            configJson: z.string(),
            credentials: z.string(),
          }))
          .mutation(async ({ ctx, input }) => {
            const repo = requireAccountRepository(ctx);
            return repo.updateAccountAuth(input.id, input.configJson, input.credentials);
          }),

        markAccountExhausted: publicProcedure
          .input(z.object({
            id: z.string().min(1),
            until: z.string().datetime(),
          }))
          .mutation(async ({ ctx, input }) => {
            const repo = requireAccountRepository(ctx);
            return repo.markExhausted(input.id, new Date(input.until));
          }),

        listProviderNames: publicProcedure
          .query(() => {
            return listProviderNames();
          }),
      };
    }