All files / kernel-agents/src/capabilities math.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 5/5
100% Lines 5/5

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        2x       1x     4x     4x                                                     2x    
import { S } from '@metamask/kernel-utils';
 
import { makeInternalCapabilities } from './discover.ts';
 
const capabilities = makeInternalCapabilities(
  'Math',
  {
    async count(word: string) {
      return word.length;
    },
    async add(summands: number[]) {
      return summands.reduce((acc, summand) => acc + summand, 0);
    },
    async multiply(factors: number[]) {
      return factors.reduce((acc, factor) => acc * factor, 1);
    },
  },
  S.interface('Math', {
    count: S.method(
      'Count the number of characters in an arbitrary string',
      [S.arg('word', S.string('The string to get the length of.'))],
      S.number('The number of characters in the string.'),
    ),
    add: S.method(
      'Add a list of numbers.',
      [S.arg('summands', S.arrayOf(S.number()))],
      S.number('The sum of the numbers.'),
    ),
    multiply: S.method(
      'Multiply a list of numbers.',
      [
        S.arg(
          'factors',
          S.arrayOf(S.number(), 'The list of numbers to multiply.'),
        ),
      ],
      S.number('The product of the factors.'),
    ),
  }),
);
 
export const { count, add, multiply } = capabilities;
export default capabilities;