Skip to content

Commit a5840c9

Browse files
authored
fix the schema extractor and bump version (#33)
fix the schema extractor and bump version (#33)
1 parent 73208b8 commit a5840c9

File tree

2 files changed

+9
-35
lines changed

2 files changed

+9
-35
lines changed

front_end/panels/ai_chat/core/Version.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// found in the LICENSE file.
44

55
export const VERSION_INFO = {
6-
version: '0.2.2',
7-
buildDate: '2025-08-06',
6+
version: '0.3.0',
7+
buildDate: '2025-08-07',
88
channel: 'stable'
99
} as const;
1010

front_end/panels/ai_chat/tools/SchemaBasedExtractorTool.ts

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Schema Examples:
7777
async execute(args: SchemaExtractionArgs): Promise<SchemaExtractionResult> {
7878
logger.debug('Executing with args', args);
7979

80-
const { instruction, reasoning } = args;
80+
const { schema, instruction, reasoning } = args;
8181
const agentService = AgentService.getInstance();
8282
const apiKey = agentService.getApiKey();
8383

@@ -89,30 +89,8 @@ Schema Examples:
8989
};
9090
}
9191

92-
// Handle both old format (schema as string) and new format (schema as object)
93-
let actualSchema: SchemaDefinition;
94-
95-
if (typeof args.schema === 'string') {
96-
// Old format: reconstruct the schema from separate fields
97-
if (!args.properties) {
98-
return {
99-
success: false,
100-
data: null,
101-
error: 'Schema is required. When using string format, properties field is required. Please provide a JSON Schema definition. Example: {"type": "object", "properties": {"title": {"type": "string"}}}'
102-
};
103-
}
104-
105-
actualSchema = {
106-
type: args.schema,
107-
properties: args.properties,
108-
...(args.required && { required: args.required })
109-
};
110-
111-
logger.debug('Converted old format schema to new format:', actualSchema);
112-
} else if (typeof args.schema === 'object' && args.schema !== null) {
113-
// New format: use schema as-is
114-
actualSchema = args.schema;
115-
} else {
92+
// Enhanced schema validation with helpful error messages
93+
if (!schema) {
11694
return {
11795
success: false,
11896
data: null,
@@ -149,7 +127,7 @@ Schema Examples:
149127
const rootNodeId: Protocol.DOM.NodeId | undefined = undefined;
150128

151129
// 2. Transform schema to replace URL fields with numeric AX Node IDs (strings)
152-
const [transformedSchema, urlPaths] = this.transformUrlFieldsToIds(actualSchema);
130+
const [transformedSchema, urlPaths] = this.transformUrlFieldsToIds(schema);
153131
logger.debug('Transformed Schema:', JSON.stringify(transformedSchema, null, 2));
154132
logger.debug('URL Paths:', urlPaths);
155133

@@ -227,7 +205,7 @@ Schema Examples:
227205
const finalData = await this.resolveUrlsWithLLM({
228206
data: refinedData,
229207
apiKey,
230-
schema: actualSchema, // Original schema to understand what fields are URLs
208+
schema, // Original schema to understand what fields are URLs
231209
});
232210

233211
logger.debug('Data after URL resolution:',
@@ -247,7 +225,7 @@ Schema Examples:
247225
instruction: instruction || 'Assess extraction completion',
248226
extractedData: finalData, // Use the final data with URLs for assessment
249227
domContent: treeText, // Pass the DOM content for context
250-
schema: actualSchema, // Pass the schema to understand what was requested
228+
schema, // Pass the schema to understand what was requested
251229
apiKey,
252230
});
253231

@@ -878,13 +856,9 @@ Return ONLY a valid JSON object conforming to the required metadata schema.`;
878856
* Arguments for schema extraction
879857
*/
880858
export interface SchemaExtractionArgs {
881-
schema: SchemaDefinition | string; // Support both object and string formats
859+
schema: SchemaDefinition;
882860
instruction?: string;
883861
reasoning?: string;
884-
// Support old format fields
885-
properties?: Record<string, SchemaProperty>;
886-
required?: string[];
887-
type?: string;
888862
}
889863

890864
/**

0 commit comments

Comments
 (0)