@mastra/core
Version:
36 lines • 1.62 kB
TypeScript
/**
* Code Mode — Type stub generation
*
* Converts Mastra tools into TypeScript `declare function external_<id>(...)`
* stubs and assembles the instructions the model sees. The pipeline is:
*
* tool.inputSchema (StandardSchemaWithJSON)
* -> standardSchemaToJSONSchema() (already in core, zod v3 + v4 + arktype)
* -> jsonSchemaToTsString() (this file, synchronous, dependency-free)
* -> stub string
*
* Only the subset of JSON Schema that tool schemas actually produce is handled;
* anything else degrades to `unknown`.
*/
import type { JSONSchema7Definition } from 'json-schema';
import type { ToolsInput } from '../../agent/types.js';
import type { CodeModeConfig } from './types.js';
/**
* Convert a JSON Schema (draft-07) node into a TypeScript type string.
* Unsupported constructs return `unknown`.
*/
export declare function jsonSchemaToTsString(schema: JSONSchema7Definition | undefined): string;
/** A single tool's TS declaration plus the original/sanitized id mapping. */
export interface CodeModeStub {
/** Original tool id (key used by the RPC dispatcher). */
toolId: string;
/** Sanitized identifier used in `external_<name>`. */
externalName: string;
/** The full `declare function ...` line(s). */
declaration: string;
}
/** Generate stubs for every tool in the config. */
export declare function generateStubs(tools: ToolsInput): CodeModeStub[];
/** Build the full instructions string (usage contract + stubs). */
export declare function createCodeModeInstructions(config: CodeModeConfig): string;
//# sourceMappingURL=stub-generator.d.ts.map