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

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

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    2x 1x                         2x   4x               2x   4x                           2x    
import { capability } from './capability.ts';
 
export const count = capability(
  async ({ word }: { word: string }) => word.length,
  {
    description: 'Count the number of characters in an arbitrary string',
    args: {
      word: { type: 'string', description: 'The string to get the length of.' },
    },
    returns: {
      type: 'number',
      description: 'The number of characters in the string.',
    },
  },
);
 
export const add = capability(
  async ({ summands }: { summands: number[] }) =>
    summands.reduce((acc, summand) => acc + summand, 0),
  {
    description: 'Add a list of numbers.',
    args: { summands: { type: 'array', items: { type: 'number' } } },
    returns: { type: 'number', description: 'The sum of the numbers.' },
  },
);
 
export const multiply = capability(
  async ({ factors }: { factors: number[] }) =>
    factors.reduce((acc, factor) => acc * factor, 1),
  {
    description: 'Multiply a list of numbers.',
    args: {
      factors: {
        type: 'array',
        description: 'The list of numbers to multiply.',
        items: { type: 'number' },
      },
    },
    returns: { type: 'number', description: 'The product of the factors.' },
  },
);
 
const capabilities = { count, add, multiply };
export default capabilities;