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

66.66% Statements 4/6
100% Branches 0/0
0% Functions 0/2
66.66% Lines 4/6

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              2x                                                                   2x                       2x                               2x  
import { capability } from './capability.ts';
 
type SearchResult = {
  source: string;
  published: string;
  snippet: string;
};
export const search = capability(
  async ({ query }: { query: string }): Promise<SearchResult[]> => [
    {
      source: 'https://www.google.com',
      published: '2025-01-01',
      snippet: `No information found for ${query}`,
    },
  ],
  {
    description: 'Search the web for information.',
    args: { query: { type: 'string', description: 'The query to search for' } },
    returns: {
      type: 'array',
      items: {
        type: 'object',
        properties: {
          source: {
            type: 'string',
            description: 'The source of the information.',
          },
          published: {
            type: 'string',
            description: 'The date the information was published.',
          },
          snippet: {
            type: 'string',
            description: 'The snippet of information.',
          },
        },
      },
    },
  },
);
 
const moonPhases = [
  'new moon',
  'waxing crescent',
  'first quarter',
  'waxing gibbous',
  'full moon',
  'waning gibbous',
  'third quarter',
  'waning crescent',
] as const;
type MoonPhase = (typeof moonPhases)[number];
 
export const getMoonPhase = capability(
  async (): Promise<MoonPhase> =>
    moonPhases[Math.floor(Math.random() * moonPhases.length)] as MoonPhase,
  {
    description: 'Get the current phase of the moon.',
    args: {},
    returns: {
      type: 'string',
      // TODO: Add enum support to the capability schema
      // @ts-expect-error - enum is not supported by the capability schema
      enum: moonPhases,
      description: 'The current phase of the moon.',
    },
  },
);
 
export const exampleCapabilities = { search, getMoonPhase };