feat: Migrate Task Master to generateObject for structured AI responses (#1262)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Ben Vargas <ben@example.com>
This commit is contained in:
Ralph Khreish
2025-10-02 16:23:34 +02:00
committed by GitHub
parent c7418c4594
commit 738ec51c04
34 changed files with 862 additions and 1034 deletions

View File

@@ -21,6 +21,13 @@ export class BaseAIProvider {
// Each provider must set their name
this.name = this.constructor.name;
/**
* Whether this provider needs explicit schema in JSON mode
* Can be overridden by subclasses
* @type {boolean}
*/
this.needsExplicitJsonSchema = false;
}
/**
@@ -272,12 +279,15 @@ export class BaseAIProvider {
);
const client = await this.getClient(params);
const result = await generateObject({
model: client(params.modelId),
messages: params.messages,
schema: zodSchema(params.schema),
mode: params.mode || 'auto',
...this.prepareTokenParam(params.modelId, params.maxTokens),
schema: params.schema,
mode: this.needsExplicitJsonSchema ? 'json' : 'auto',
schemaName: params.objectName,
schemaDescription: `Generate a valid JSON object for ${params.objectName}`,
maxTokens: params.maxTokens,
temperature: params.temperature
});
@@ -298,7 +308,7 @@ export class BaseAIProvider {
// Check if this is a JSON parsing error that we can potentially fix
if (
NoObjectGeneratedError.isInstance(error) &&
JSONParseError.isInstance(error.cause) &&
error.cause instanceof JSONParseError &&
error.cause.text
) {
log(

View File

@@ -32,6 +32,8 @@ export class ClaudeCodeProvider extends BaseAIProvider {
super();
this.name = 'Claude Code';
this.supportedModels = ['sonnet', 'opus'];
// Claude Code requires explicit JSON schema mode
this.needsExplicitJsonSchema = true;
}
/**

View File

@@ -15,6 +15,8 @@ export class GeminiCliProvider extends BaseAIProvider {
constructor() {
super();
this.name = 'Gemini CLI';
// Gemini CLI requires explicit JSON schema mode
this.needsExplicitJsonSchema = true;
}
/**
@@ -587,7 +589,7 @@ Generate ${subtaskCount} subtasks based on the original task context. Return ONL
system: systemPrompt,
messages: messages,
schema: params.schema,
mode: 'json', // Use json mode instead of auto for Gemini
mode: this.needsExplicitJsonSchema ? 'json' : 'auto',
maxOutputTokens: params.maxTokens,
temperature: params.temperature
});

View File

@@ -11,6 +11,8 @@ export class GrokCliProvider extends BaseAIProvider {
constructor() {
super();
this.name = 'Grok CLI';
// Grok CLI requires explicit JSON schema mode
this.needsExplicitJsonSchema = true;
}
/**