Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* StackOne AI Node.js SDK
*/

export { DEFAULT_BASE_URL, DEFAULT_HYBRID_ALPHA } from './consts';
export { BaseTool, StackOneTool, Tools } from './tool';
export { createFeedbackTool } from './feedback';
export { StackOneAPIError, StackOneError } from './utils/errors';
Expand All @@ -22,9 +21,6 @@ export type {
AISDKToolResult,
ExecuteConfig,
ExecuteOptions,
Experimental_PreExecuteFunction,
Experimental_SchemaOverride,
Experimental_ToolCreationOptions,
JsonDict,
ParameterLocation,
ToolDefinition,
Expand Down
58 changes: 4 additions & 54 deletions src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import type {
AISDKToolResult,
ExecuteConfig,
ExecuteOptions,
Experimental_PreExecuteFunction,
Experimental_ToolCreationOptions,
HttpExecuteConfig,
JsonDict,
LocalExecuteConfig,
Expand All @@ -31,7 +29,6 @@ export class BaseTool {
parameters: ToolParameters;
executeConfig: ExecuteConfig;
protected requestBuilder?: RequestBuilder;
protected experimental_preExecute?: Experimental_PreExecuteFunction;
#exposeExecutionMetadata = true;
#headers: Record<string, string>;

Expand Down Expand Up @@ -77,7 +74,6 @@ export class BaseTool {
parameters: ToolParameters,
executeConfig: ExecuteConfig,
headers?: Record<string, string>,
experimental_preExecute?: Experimental_PreExecuteFunction,
) {
this.name = name;
this.description = description;
Expand All @@ -87,7 +83,6 @@ export class BaseTool {
if (executeConfig.kind === 'http') {
this.requestBuilder = new RequestBuilder(executeConfig, this.#headers);
}
this.experimental_preExecute = experimental_preExecute;
}

/**
Expand Down Expand Up @@ -146,15 +141,8 @@ export class BaseTool {
// Convert string params to object
const params = typeof inputParams === 'string' ? JSON.parse(inputParams) : inputParams || {};

// Apply experimental preExecute function (either from tool creation or execution options)
let processedParams = params;

if (this.experimental_preExecute) {
processedParams = await this.experimental_preExecute(params);
}

// Execute the request directly with processed parameters
return await this.requestBuilder.execute(processedParams, options);
// Execute the request directly with parameters
return await this.requestBuilder.execute(params, options);
} catch (error) {
if (error instanceof StackOneError) {
throw error;
Expand Down Expand Up @@ -322,46 +310,8 @@ export class Tools implements Iterable<BaseTool> {
/**
* Get a tool by name
*/
getTool(name: string, options?: Experimental_ToolCreationOptions): BaseTool | undefined {
const originalTool = this.tools.find((tool) => tool.name === name);
if (!originalTool) {
return undefined;
}

// If no experimental options provided, return original tool
if (!options?.experimental_schemaOverride && !options?.experimental_preExecute) {
return originalTool;
}

// Create a new tool with experimental schema override and preExecute
let parameters = originalTool.parameters;

// Apply schema override if provided
if (options.experimental_schemaOverride) {
parameters = options.experimental_schemaOverride(originalTool.parameters);
}

// Create new tool instance with modified schema and preExecute function
if (originalTool instanceof StackOneTool) {
const newTool = new StackOneTool(
originalTool.name,
originalTool.description,
parameters,
originalTool.executeConfig,
originalTool.getHeaders(),
options.experimental_preExecute,
);
return newTool;
}
const newTool = new BaseTool(
originalTool.name,
originalTool.description,
parameters,
originalTool.executeConfig,
originalTool.getHeaders(),
options.experimental_preExecute,
);
return newTool;
getTool(name: string): BaseTool | undefined {
return this.tools.find((tool) => tool.name === name);
}

/**
Expand Down
33 changes: 0 additions & 33 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ export type JsonSchemaProperties = Record<string, JSONSchema7Definition>;
*/
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
*/
export 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
*/
export type Experimental_PreExecuteFunction = (params: JsonDict) => Promise<JsonDict> | JsonDict;

/**
* Valid locations for parameters in requests
*/
Expand Down Expand Up @@ -99,23 +83,6 @@ export interface LocalExecuteConfig {
*/
export type ExecuteConfig = HttpExecuteConfig | RpcExecuteConfig | LocalExecuteConfig;

/**
* EXPERIMENTAL: Options for creating tools with schema overrides and preExecute functions
*/
export 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
*/
Expand Down
Loading