Skip to content

Commit 8703411

Browse files
committed
clean up old Zod references and some lint warnings
1 parent 0efa9f6 commit 8703411

6 files changed

Lines changed: 30 additions & 81 deletions

File tree

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ for (const tool of tools) {
4242
{
4343
title: tool.title ?? tool.name,
4444
description: tool.description,
45-
inputSchema: tool.inputSchema ?? {},
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
46+
inputSchema: (tool.inputSchema ?? {}) as any,
4647
},
47-
handler
48+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49+
handler as any
4850
);
4951
} else {
5052
console.error(`No handler found for tool: ${tool.name}`);

src/tools/composeTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function buildToolList(): ToolDef[] {
8484
const copy: ToolDef = { ...t };
8585
if (copy.inputSchema && typeof copy.inputSchema === "object") {
8686
// If top-level is a $ref only, replace it; otherwise recursively resolve nested refs
87-
copy.inputSchema = resolveRefObject(JSON.parse(JSON.stringify(copy.inputSchema)));
87+
copy.inputSchema = resolveRefObject(JSON.parse(JSON.stringify(copy.inputSchema))) as Record<string, unknown>;
8888
}
8989
return copy;
9090
});

src/tools/tests/unit/tools-resolver.test.ts

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { describe, it, expect } from "vitest";
22
import { buildToolList } from "../../composeTools.js";
33

44
// Helper to recursively check if a schema contains any $ref entries (except within oneOf/anyOf/allOf arrays)
5-
function hasUnresolvedRefs(obj: any, path = ""): { found: boolean; paths: string[] } {
5+
function hasUnresolvedRefs(obj: unknown, path = ""): { found: boolean; paths: string[] } {
66
const paths: string[] = [];
77

8-
function traverse(val: any, p: string) {
8+
function traverse(val: unknown, p: string) {
99
if (!val || typeof val !== "object") return;
1010

1111
if (Array.isArray(val)) {
@@ -39,32 +39,21 @@ describe("unit: tool list resolver", () => {
3939
// specific checks for presentations tools
4040
const createTemplate = tools.find((t) => t.name === "create_proof_template");
4141
expect(createTemplate).toBeDefined();
42-
const s1 = createTemplate!.inputSchema as any;
43-
const isZod = (x: any) => x && typeof x.safeParse === 'function';
44-
if (isZod(s1)) {
45-
expect(isZod(s1)).toBe(true);
46-
} else {
47-
expect(s1.$ref).toBeUndefined();
48-
expect(s1.type).toBe("object");
49-
}
42+
const s1 = createTemplate!.inputSchema as Record<string, unknown>;
43+
expect(s1.$ref).toBeUndefined();
44+
expect(s1.type).toBe("object");
5045

5146
const createRequest = tools.find((t) => t.name === "create_proof_request");
5247
expect(createRequest).toBeDefined();
53-
const s2 = createRequest!.inputSchema as any;
54-
if (isZod(s2)) {
55-
expect(isZod(s2)).toBe(true);
56-
} else {
57-
expect(s2.$ref).toBeUndefined();
58-
expect(s2.properties).toBeDefined();
59-
}
48+
const s2 = createRequest!.inputSchema as Record<string, unknown>;
49+
expect(s2.$ref).toBeUndefined();
50+
expect(s2.properties).toBeDefined();
6051

6152
// generic assertion: no tool should expose a top-level $ref-only inputSchema
6253
for (const t of tools) {
63-
const s = t.inputSchema as any;
64-
const isZod = (x: any) => x && typeof x.safeParse === 'function';
54+
const s = t.inputSchema;
6555
if (s && typeof s === 'object') {
66-
if (isZod(s)) continue;
67-
expect(s.$ref).toBeUndefined();
56+
expect((s as Record<string, unknown>).$ref).toBeUndefined();
6857
}
6958
}
7059
});
@@ -77,42 +66,37 @@ describe("unit: tool list resolver", () => {
7766
const createIssuer = tools.find((t) => t.name === "create_issuer");
7867
expect(createIssuer).toBeDefined();
7968

80-
const schema = createIssuer!.inputSchema as any;
81-
const isZod = (x: any) => x && typeof x.safeParse === 'function';
82-
if (isZod(schema)) {
83-
expect(isZod(schema)).toBe(true);
84-
return;
85-
}
69+
const schema = createIssuer!.inputSchema as Record<string, unknown>;
8670

8771
// Should have resolved credentialOptions from a $ref to an actual object
8872
expect(schema.properties).toBeDefined();
89-
expect(schema.properties.credentialOptions).toBeDefined();
90-
expect((schema.properties.credentialOptions as any).$ref).toBeUndefined();
73+
expect((schema.properties as Record<string, unknown>).credentialOptions).toBeDefined();
74+
expect(((schema.properties as Record<string, unknown>).credentialOptions as Record<string, unknown>).$ref).toBeUndefined();
9175

9276
// credentialOptions should have credential property (from CredentialIssueRequest)
93-
const credentialOptions = schema.properties.credentialOptions as any;
77+
const credentialOptions = (schema.properties as Record<string, unknown>).credentialOptions as Record<string, unknown>;
9478
expect(credentialOptions.properties).toBeDefined();
95-
expect(credentialOptions.properties.credential).toBeDefined();
79+
expect((credentialOptions.properties as Record<string, unknown>).credential).toBeDefined();
9680

9781
// credential property should also be resolved (from Credential schema)
98-
const credentialProp = credentialOptions.properties.credential as any;
82+
const credentialProp = (credentialOptions.properties as Record<string, unknown>).credential as Record<string, unknown>;
9983
expect(credentialProp.$ref).toBeUndefined();
10084
expect(credentialProp.type).toBe("object");
10185
expect(credentialProp.properties).toBeDefined();
10286

10387
// The credential should have subject property (not credentialSubject)
104-
expect(credentialProp.properties.subject).toBeDefined();
105-
expect(credentialProp.properties.credentialSubject).toBeUndefined();
88+
expect((credentialProp.properties as Record<string, unknown>).subject).toBeDefined();
89+
expect((credentialProp.properties as Record<string, unknown>).credentialSubject).toBeUndefined();
10690
});
10791

10892
it("ensures no tool has bare $ref-only top-level inputSchema", () => {
10993
const tools = buildToolList();
11094

11195
for (const tool of tools) {
112-
const schema = tool.inputSchema as any;
96+
const schema = tool.inputSchema;
11397
if (schema && typeof schema === "object") {
11498
// Top-level should never be a bare $ref
115-
expect(schema.$ref).toBeUndefined();
99+
expect((schema as Record<string, unknown>).$ref).toBeUndefined();
116100
}
117101
}
118102
});
@@ -121,10 +105,8 @@ describe("unit: tool list resolver", () => {
121105
const tools = buildToolList();
122106

123107
for (const tool of tools) {
124-
const schema = tool.inputSchema as any;
108+
const schema = tool.inputSchema;
125109
if (!schema) continue;
126-
const isZod = (x: any) => x && typeof x.safeParse === 'function';
127-
if (isZod(schema)) continue; // Zod schemas don't use $ref
128110

129111
if (schema && typeof schema === "object") {
130112
const { found, paths } = hasUnresolvedRefs(schema, tool.name);

src/tools/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export type ToolDef = {
22
name: string;
33
description: string;
4-
inputSchema?: any; // JSON Schema is inherently dynamic
5-
outputSchema?: any; // JSON Schema is inherently dynamic
4+
inputSchema?: Record<string, unknown>; // JSON Schema is inherently dynamic
5+
outputSchema?: Record<string, unknown>; // JSON Schema is inherently dynamic
66
title?: string;
77
};
88

src/transport/http/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function startHTTPTransport({
2222
const transports: { [key: string]: StreamableHTTPServerTransport } = {};
2323

2424
function isInitializeRequest(body: unknown): boolean {
25-
return !!body && typeof body === "object" && (body as any).method === "initialize";
25+
return !!body && typeof body === "object" && "method" in body && (body as Record<string, unknown>).method === "initialize";
2626
}
2727

2828
const httpServer = http.createServer(async (req, res) => {

tests/integration/tools-integration.test.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,8 @@ import { TruveraClient } from '../../src/clients/index.js';
44

55
function constructArgsFromSchema(schema: any) {
66
const args: any = {};
7-
if (!schema) return args;
8-
9-
const isZod = (s: any) => s && typeof s.safeParse === 'function';
10-
if (isZod(schema)) {
11-
const shape = (schema as any)._def?.shape || (schema as any).shape || {};
12-
for (const [key, val] of Object.entries(shape)) {
13-
// determine if optional
14-
const inner = (val as any)._def?.innerType || (val as any);
15-
const isOptional = (val as any)?._def?.type === 'optional' || (val as any).isOptional;
16-
if (isOptional) continue;
17-
const t = inner?._def?.type || inner?._def?.typeName || typeof inner;
18-
switch (t) {
19-
case 'number':
20-
case 'ZodNumber':
21-
args[key] = 1;
22-
break;
23-
case 'ZodBoolean':
24-
case 'boolean':
25-
args[key] = true;
26-
break;
27-
case 'ZodObject':
28-
case 'object':
29-
args[key] = {};
30-
break;
31-
case 'ZodArray':
32-
case 'array':
33-
args[key] = [];
34-
break;
35-
default:
36-
args[key] = 'test';
37-
}
38-
}
39-
return args;
40-
}
41-
42-
// Fallback: JSON Schema style
437
if (!schema || !schema.required) return args;
8+
449
for (const key of schema.required) {
4510
const prop = schema.properties && schema.properties[key];
4611
if (!prop) {

0 commit comments

Comments
 (0)