Skip to content

Commit 7d28962

Browse files
committed
clean up
1 parent e614046 commit 7d28962

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

src/client/index.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from '.
4545
import { ZodLiteral, ZodObject, z } from 'zod';
4646
import type { RequestHandlerExtra } from '../shared/protocol.js';
4747

48+
/**
49+
* Elicitation default application helper. Applies defaults to the data based on the schema.
50+
*
51+
* @param schema - The schema to apply defaults to.
52+
* @param data - The data to apply defaults to.
53+
*/
4854
function applyElicitationDefaults(schema: JsonSchemaType | undefined, data: unknown): void {
4955
if (!schema || data === null || typeof data !== 'object') return;
5056

@@ -65,20 +71,6 @@ function applyElicitationDefaults(schema: JsonSchemaType | undefined, data: unkn
6571
}
6672
}
6773

68-
// Handle arrays
69-
if (schema.type === 'array' && Array.isArray(data) && schema.items) {
70-
const itemsSchema = schema.items as JsonSchemaType | JsonSchemaType[];
71-
if (Array.isArray(itemsSchema)) {
72-
for (let i = 0; i < data.length && i < itemsSchema.length; i++) {
73-
applyElicitationDefaults(itemsSchema[i], data[i]);
74-
}
75-
} else {
76-
for (const item of data) {
77-
applyElicitationDefaults(itemsSchema, item);
78-
}
79-
}
80-
}
81-
8274
// Combine schemas
8375
if (Array.isArray(schema.allOf)) {
8476
for (const sub of schema.allOf) {

src/server/elicitation.test.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,7 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo
364364
}
365365
);
366366

367-
const client = new Client(
368-
{ name: 'test-client', version: '1.0.0' },
369-
{ capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider }
370-
);
367+
const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } });
371368

372369
client.setRequestHandler(ElicitRequestSchema, _request => ({
373370
action: 'accept',
@@ -401,10 +398,7 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo
401398
}
402399
);
403400

404-
const client = new Client(
405-
{ name: 'test-client', version: '1.0.0' },
406-
{ capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider }
407-
);
401+
const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } });
408402

409403
client.setRequestHandler(ElicitRequestSchema, _request => ({
410404
action: 'decline'
@@ -438,10 +432,7 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo
438432
}
439433
);
440434

441-
const client = new Client(
442-
{ name: 'test-client', version: '1.0.0' },
443-
{ capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider }
444-
);
435+
const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } });
445436

446437
client.setRequestHandler(ElicitRequestSchema, _request => ({
447438
action: 'cancel'

0 commit comments

Comments
 (0)