modality-kit 0.12.6 → 0.12.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  export { setupAITools, ModalityFastMCP } from "./util_mcp_tools_converter";
2
- export type { AITools, AITool } from "./schemas/schemas_tool_config";
2
+ export type { AITools, AITool, FastMCPTool, } from "./schemas/schemas_tool_config";
3
3
  export { formatErrorResponse, formatSuccessResponse } from "./util_response";
4
4
  export { getLoggerInstance, type ModalityLogger } from "./util_logger";
5
5
  export { withErrorHandling, ErrorCode } from "./util_error";
@@ -1,22 +1,66 @@
1
1
  /**
2
- * TypeScript interfaces for tool configuration objects
2
+ * Copy of StandardSchemaV1 interface for compatibility
3
3
  */
4
- import { z } from "zod";
4
+ export interface ToolParameters<Input = unknown, Output = Input> {
5
+ readonly "~standard": ToolParameters.Props<Input, Output>;
6
+ }
7
+ export declare namespace ToolParameters {
8
+ interface Props<Input = unknown, Output = Input> {
9
+ readonly version: 1;
10
+ readonly vendor: string;
11
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
12
+ readonly types?: Types<Input, Output> | undefined;
13
+ }
14
+ type Result<Output> = SuccessResult<Output> | FailureResult;
15
+ interface SuccessResult<Output> {
16
+ readonly value: Output;
17
+ readonly issues?: undefined;
18
+ }
19
+ interface FailureResult {
20
+ readonly issues: ReadonlyArray<Issue>;
21
+ }
22
+ interface Issue {
23
+ readonly message: string;
24
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
25
+ }
26
+ interface PathSegment {
27
+ readonly key: PropertyKey;
28
+ }
29
+ interface Types<Input = unknown, Output = Input> {
30
+ readonly input: Input;
31
+ readonly output: Output;
32
+ }
33
+ type InferInput<Schema extends ToolParameters> = NonNullable<Schema["~standard"]["types"]>["input"];
34
+ type InferOutput<Schema extends ToolParameters> = NonNullable<Schema["~standard"]["types"]>["output"];
35
+ }
5
36
  /**
6
37
  * Tool interface for AI SDK compatibility
7
38
  */
8
- export interface AITool<T extends z.ZodSchema = z.ZodSchema> {
9
- name?: string;
10
- annotations?: any;
11
- description: string;
12
- inputSchema: T;
13
- execute: (args: z.infer<T>) => Promise<string>;
39
+ export interface AITool<T extends Record<string, unknown> | undefined = any, TParams extends ToolParameters = ToolParameters> {
40
+ annotations?: {
41
+ streamingHint?: boolean;
42
+ } & {
43
+ destructiveHint?: boolean;
44
+ idempotentHint?: boolean;
45
+ openWorldHint?: boolean;
46
+ readOnlyHint?: boolean;
47
+ title?: string;
48
+ };
49
+ canAccess?: (auth: T) => boolean;
50
+ description?: string;
51
+ execute: (args: ToolParameters.InferOutput<TParams>, context?: any) => Promise<any>;
52
+ name: string;
53
+ inputSchema?: TParams;
54
+ timeoutMs?: number;
55
+ }
56
+ export interface FastMCPTool<T extends Record<string, unknown> | undefined = any, TParams extends ToolParameters = ToolParameters> extends AITool<T, TParams> {
57
+ parameters?: TParams;
14
58
  }
15
59
  /**
16
60
  * Type for a collection of AI tools with preserved schema types
17
61
  * @template T - Record mapping tool names to their inputSchema types
18
62
  * @example AITools<{getUserById: z.object({id: z.string()}), createUser: z.object({name: z.string()})}>
19
63
  */
20
- export type AITools<T extends Record<string, z.ZodSchema> = Record<string, z.ZodSchema>> = {
21
- [K in keyof T]: AITool<T[K]>;
64
+ export type AITools<T extends Record<string, ToolParameters> = Record<string, ToolParameters>> = {
65
+ [K in keyof T]: AITool<any, T[K]>;
22
66
  };
@@ -1,66 +1,10 @@
1
- import type { AITools } from "./schemas/schemas_tool_config.ts";
2
- import type { z } from "zod";
3
- /**
4
- * Copy of StandardSchemaV1 interface for compatibility
5
- */
6
- export interface ToolParameters<Input = unknown, Output = Input> {
7
- readonly "~standard": ToolParameters.Props<Input, Output>;
8
- }
9
- export declare namespace ToolParameters {
10
- interface Props<Input = unknown, Output = Input> {
11
- readonly version: 1;
12
- readonly vendor: string;
13
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
14
- readonly types?: Types<Input, Output> | undefined;
15
- }
16
- type Result<Output> = SuccessResult<Output> | FailureResult;
17
- interface SuccessResult<Output> {
18
- readonly value: Output;
19
- readonly issues?: undefined;
20
- }
21
- interface FailureResult {
22
- readonly issues: ReadonlyArray<Issue>;
23
- }
24
- interface Issue {
25
- readonly message: string;
26
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
27
- }
28
- interface PathSegment {
29
- readonly key: PropertyKey;
30
- }
31
- interface Types<Input = unknown, Output = Input> {
32
- readonly input: Input;
33
- readonly output: Output;
34
- }
35
- type InferInput<Schema extends ToolParameters> = NonNullable<Schema["~standard"]["types"]>["input"];
36
- type InferOutput<Schema extends ToolParameters> = NonNullable<Schema["~standard"]["types"]>["output"];
37
- }
38
- /**
39
- * Copy of FastMCP's Tool type for compatibility
40
- */
41
- export type Tool<T extends Record<string, unknown> | undefined = any, Params extends ToolParameters = ToolParameters> = {
42
- annotations?: {
43
- streamingHint?: boolean;
44
- } & {
45
- destructiveHint?: boolean;
46
- idempotentHint?: boolean;
47
- openWorldHint?: boolean;
48
- readOnlyHint?: boolean;
49
- title?: string;
50
- };
51
- canAccess?: (auth: T) => boolean;
52
- description?: string;
53
- execute: (args: ToolParameters.InferOutput<Params>, context: any) => Promise<any>;
54
- name: string;
55
- parameters?: Params;
56
- timeoutMs?: number;
57
- };
1
+ import type { AITools, FastMCPTool, ToolParameters } from "./schemas/schemas_tool_config";
58
2
  /**
59
3
  * FastMCP-compatible interface for MCP server functionality
60
4
  * Provides exact API compatibility with FastMCP.addTool method
61
5
  */
62
6
  export interface FastMCPCompatible {
63
- addTool<Params extends ToolParameters>(tool: Tool<any, Params>): void;
7
+ addTool<Params extends ToolParameters>(tool: FastMCPTool<any, Params>): void;
64
8
  }
65
9
  /**
66
10
  * ModalityFastMCP - A FastMCP-compatible implementation
@@ -71,17 +15,14 @@ export declare class ModalityFastMCP implements FastMCPCompatible {
71
15
  /**
72
16
  * Add a tool to the server
73
17
  */
74
- addTool<Params extends ToolParameters>(tool: Tool<any, Params>): void;
18
+ addTool<Params extends ToolParameters>(tool: FastMCPTool<any, Params>): void;
75
19
  /**
76
20
  * Get all registered tools
77
21
  */
78
- getTools(): Tool<any, any>[];
22
+ getTools(): FastMCPTool<any, any>[];
79
23
  }
80
24
  /**
81
25
  * Setup function that optionally registers AITools with MCP server
82
26
  * Automatically infers and preserves schema types from the input
83
- * @param aiTools - The AITools object with schema mapping
84
- * @param mcpServer - Optional MCP server to register tools with
85
- * @returns The same AITools object with preserved types
86
27
  */
87
- export declare const setupAITools: <T extends Record<string, z.ZodSchema>>(aiTools: AITools<T>, mcpServer?: FastMCPCompatible) => AITools<T>;
28
+ export declare const setupAITools: <T extends Record<string, ToolParameters>>(aiTools: AITools<T>, mcpServer?: FastMCPCompatible) => AITools<T>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.12.6",
2
+ "version": "0.12.8",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",