All files / shared/src/types/middleware hooks.ts

100% Statements 37/37
100% Branches 3/3
100% Functions 0/0
100% Lines 37/37

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 561x 1x 1x 1x 1x 1x   1x 1x 1x     1x 1x 1x 1x       1x 1x 1x 1x 1x       1x 1x     1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x      
import { SuperAgentsRequestBody } from '@shared/types/api/request';
import { SuperAgentsResponseBody } from '@shared/types/api/response';
import { AIProvider } from '@shared/types/constants';
import { HttpMethod } from '@shared/types/http';
import { CacheMode } from '@shared/types/middleware/cache';
import { z } from 'zod';
 
export enum HookType {
  INPUT_HOOK = 'input',
  OUTPUT_HOOK = 'output',
}
 
export const HookHttpProviderConfig = z.object({
  method: z.enum(HttpMethod),
  url: z.string(),
});
 
export type HookHttpProviderConfig = z.infer<typeof HookHttpProviderConfig>;
 
export const HookLLMProviderConfig = z.object({
  model: z.string(),
  provider: z.enum(AIProvider),
  body: z.record(z.string(), z.unknown()).optional(),
});
 
export type HookLLMProviderConfig = z.infer<typeof HookLLMProviderConfig>;
 
export enum HookProviderSource {
  DEFAULT = 'default',
}
 
export enum HookProvider {
  HTTP = 'http',
  LLM = 'llm',
}
 
export const Hook = z.object({
  id: z.string(),
  type: z.enum(HookType),
  hook_provider: z.enum(HookProvider),
  config: z.union([HookHttpProviderConfig, HookLLMProviderConfig]),
  await: z.boolean().optional().default(true),
  cache_mode: z.enum(CacheMode).default(CacheMode.DISABLED),
});
 
export type Hook = z.infer<typeof Hook>;
 
export const HookResult = z.object({
  deny_request: z.boolean(),
  request_body_override: SuperAgentsRequestBody.optional(),
  response_body_override: SuperAgentsResponseBody.optional(),
  skipped: z.boolean(),
});
 
export type HookResult = z.infer<typeof HookResult>;