@stackone/ai
Version:
Tools for agents to perform actions on your SaaS
104 lines (101 loc) • 3.53 kB
TypeScript
import { ValueOf } from "./node_modules/type-fest/source/value-of.js";
import "./node_modules/type-fest/index.js";
import { JSONSchema7, JSONSchema7Definition } from "json-schema";
//#region src/types.d.ts
/**
* Generic dictionary type for JSON-compatible objects
*/
type JsonDict = Record<string, unknown>;
/**
* HTTP headers type
*/
/**
* JSON Schema properties type
*/
type JsonSchemaProperties = Record<string, JSONSchema7Definition>;
/**
* JSON Schema type
*/
type JsonSchemaType = JSONSchema7['type'];
/**
* EXPERIMENTAL: Function to override the tool schema at creation time
* Takes the original tool parameters and returns a new schema
* @param originalSchema - The original tool parameters schema from OpenAPI
* @returns New schema definition for the tool
*/
type Experimental_SchemaOverride = (originalSchema: ToolParameters) => ToolParameters;
/**
* EXPERIMENTAL: Function to preprocess parameters before tool execution
* Transforms parameters from override schema format back to original API format
* @param params - The input parameters in override schema format
* @returns Parameters in original API format
*/
type Experimental_PreExecuteFunction = (params: JsonDict) => Promise<JsonDict> | JsonDict;
/**
* Valid locations for parameters in requests
*/
declare const ParameterLocation: {
readonly HEADER: "header";
readonly QUERY: "query";
readonly PATH: "path";
readonly BODY: "body";
};
type ParameterLocation = ValueOf<typeof ParameterLocation>;
/**
* Configuration for executing a tool against an API endpoint
*/
interface ExecuteConfig {
method: string;
url: string;
bodyType: 'json' | 'multipart-form' | 'form';
params: {
name: string;
location: ParameterLocation;
type: JsonSchemaType;
derivedFrom?: string; // this is the name of the param that this one is derived from.
}[]; // this params are the full list of params used to execute. This should come straight from the OpenAPI spec.
}
/**
* EXPERIMENTAL: Options for creating tools with schema overrides and preExecute functions
*/
interface Experimental_ToolCreationOptions {
/**
* EXPERIMENTAL: Function to override the tool schema at creation time
* Takes the original schema and returns a new schema for the tool
*/
experimental_schemaOverride?: Experimental_SchemaOverride;
/**
* EXPERIMENTAL: Function to preprocess parameters before execution
* Transforms parameters from override schema format back to original API format
*/
experimental_preExecute?: Experimental_PreExecuteFunction;
}
/**
* Options for executing a tool
*/
interface ExecuteOptions {
/**
* If true, returns the request details instead of making the actual API call
* Useful for debugging and testing transformed parameters
*/
dryRun?: boolean;
}
/**
* Schema definition for tool parameters
*/
interface ToolParameters {
type: string;
properties: JsonSchemaProperties; // these are the params we will expose to the user/agent in the tool. These might be higher level params.
required?: string[]; // list of required parameter names
}
/**
* Complete definition of a tool including its schema and execution config
*/
interface ToolDefinition {
description: string;
parameters: ToolParameters;
execute: ExecuteConfig;
}
//#endregion
export { ExecuteConfig, ExecuteOptions, Experimental_PreExecuteFunction, Experimental_SchemaOverride, Experimental_ToolCreationOptions, JsonDict, ParameterLocation, ToolDefinition, ToolParameters };
//# sourceMappingURL=types.d.ts.map