ai-utils.js
Version:
Build AI applications, chatbots, and agents with JavaScript and TypeScript.
30 lines (29 loc) • 1.25 kB
TypeScript
import { z } from "zod";
import { ApiCallError } from "./ApiCallError.js";
export type ResponseHandler<T> = (options: {
url: string;
requestBodyValues: unknown;
response: Response;
}) => PromiseLike<T>;
export declare const createJsonResponseHandler: <T>(responseSchema: z.ZodType<T, z.ZodTypeDef, T>) => ResponseHandler<T>;
export declare const createTextResponseHandler: () => ResponseHandler<string>;
export declare const postJsonToApi: <T>({ url, apiKey, body, failedResponseHandler, successfulResponseHandler, abortSignal, }: {
url: string;
apiKey?: string | undefined;
body: unknown;
failedResponseHandler: ResponseHandler<ApiCallError>;
successfulResponseHandler: ResponseHandler<T>;
abortSignal?: AbortSignal | undefined;
}) => Promise<T>;
export declare const postToApi: <T>({ url, apiKey, contentType, body, successfulResponseHandler, failedResponseHandler, abortSignal, }: {
url: string;
apiKey?: string | undefined;
contentType: string | null;
body: {
content: string | FormData;
values: unknown;
};
failedResponseHandler: ResponseHandler<Error>;
successfulResponseHandler: ResponseHandler<T>;
abortSignal?: AbortSignal | undefined;
}) => Promise<T>;