@hashbrownai/core
Version:
Runtime helpers for Hashbrown AI
51 lines • 1.89 kB
TypeScript
import { s } from '../schema';
import type { QuickJSAsyncContext, QuickJSHandle } from 'quickjs-emscripten-core';
import { RuntimeTransport } from './transport';
/**
* A reference to a function in the runtime.
*
* @param Args - The args of the function.
* @param Result - The result of the function.
* @returns The function reference.
*/
export type RuntimeFunctionRef<Args, Result> = {
name: string;
description: string;
args?: s.HashbrownType;
result?: s.HashbrownType;
handler: (args: Args, abortSignal: AbortSignal) => Result | Promise<Result>;
};
/**
* Creates a function with an input schema.
*
* @param cfg - The configuration for the function.
* @param cfg.name - The name of the function.
* @param cfg.description - The description of the function.
* @param cfg.args - The args schema of the function.
* @param cfg.result - The result schema of the function.
* @param cfg.handler - The handler of the function.
* @returns The function reference.
*/
export declare function createRuntimeFunctionImpl(cfg: {
name: string;
description: string;
args: s.HashbrownType;
result: s.HashbrownType;
handler: (args: unknown, abort?: AbortSignal) => unknown;
} | {
name: string;
description: string;
result: s.HashbrownType;
handler: (abort?: AbortSignal) => unknown;
} | {
name: string;
description: string;
args: s.HashbrownType;
handler: (args: unknown, abort?: AbortSignal) => unknown;
} | {
name: string;
description: string;
handler: (abortSignal?: AbortSignal) => unknown;
}): RuntimeFunctionRef<any, any>;
export declare function attachFunctionToContext(context: QuickJSAsyncContext, transport: RuntimeTransport, definition: RuntimeFunctionRef<any, Promise<any>>, attachTo: QuickJSHandle, abortSignal: AbortSignal): QuickJSHandle;
//# sourceMappingURL=create-runtime-function-impl.d.ts.map