Skip to content

Commit 977935c

Browse files
fix: add outputSchema to the offline tool registration
1 parent 5976bd0 commit 977935c

File tree

2 files changed

+4
-62
lines changed
  • packages/mobile-web
    • src/tools/mobile-offline/offline-analysis
    • tests/tools/mobile-offline/offline-analysis

2 files changed

+4
-62
lines changed

packages/mobile-web/src/tools/mobile-offline/offline-analysis/tool.ts

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class OfflineAnalysisTool implements Tool {
5454
{
5555
description: this.description,
5656
inputSchema: this.inputSchema.shape,
57+
outputSchema: this.outputSchema.shape,
5758
annotations: annotations,
5859
},
5960
async (code: LwcCodeType) => {
@@ -64,9 +65,10 @@ export class OfflineAnalysisTool implements Tool {
6465
content: [
6566
{
6667
type: 'text',
67-
text: this.createAnalysisMarkdown(code.name, analysisResults),
68+
text: JSON.stringify(analysisResults),
6869
},
6970
],
71+
structuredContent: analysisResults,
7072
};
7173
} catch (error) {
7274
return {
@@ -106,70 +108,10 @@ export class OfflineAnalysisTool implements Tool {
106108
orchestrationInstructions: this.getOrchestrationInstructions(),
107109
};
108110
}
109-
110111
private getOrchestrationInstructions(): string {
111112
return "If you have not already executed the 'sfmobile-web-offline-guidance' tool in this conversation thread: (1) Immediately call the 'sfmobile-web-offline-guidance' tool, (2) Execute all review instructions from the guidance tool's output against the user's LWC component code in the specified format, (3) Combine the review results from step 2 with this tool's analysis results, then refactor the component based on all combined review recommendations.";
112113
}
113114

114-
private createAnalysisMarkdown(
115-
componentName: string,
116-
analysisResults: ExpertsCodeAnalysisIssuesType
117-
): string {
118-
const markdowns: string[] = [];
119-
markdowns.push(
120-
`Analysis results for the LWC component ${componentName} are presented below. Please review them and provide a detailed refactoring plan for the component. `
121-
);
122-
123-
for (const analysis of analysisResults.analysisResults) {
124-
markdowns.push(this.formatAnalysisSection(analysis));
125-
}
126-
127-
if (analysisResults.orchestrationInstructions) {
128-
markdowns.push(
129-
`# orchestration instructions:\n\n ${analysisResults.orchestrationInstructions}`
130-
);
131-
}
132-
133-
return markdowns.join('\n\n');
134-
}
135-
136-
private formatAnalysisSection(analysis: ExpertCodeAnalysisIssuesType): string {
137-
const sections: string[] = [];
138-
sections.push(`# ${analysis.expertReviewerName}`);
139-
140-
if (analysis.issues.length === 0) {
141-
sections.push('No issues found.');
142-
return sections.join('\n\n');
143-
}
144-
145-
for (const issue of analysis.issues) {
146-
sections.push(this.formatIssue(issue));
147-
}
148-
149-
return sections.join('\n\n');
150-
}
151-
152-
private formatIssue(issue: CodeAnalysisIssueType): string {
153-
const issueText: string[] = [];
154-
issueText.push(`## ${issue.type}`);
155-
issueText.push(`**Description:** ${issue.description}`);
156-
issueText.push(`**Intent Analysis:** ${issue.intentAnalysis}`);
157-
issueText.push(`**Suggested Action:** ${issue.suggestedAction}`);
158-
159-
if (issue.location) {
160-
issueText.push(
161-
`**Location:** Line ${issue.location.startLine}:${issue.location.startColumn} - Line ${issue.location.endLine}:${issue.location.endColumn}`
162-
);
163-
}
164-
165-
if (issue.code) {
166-
issueText.push(`**Code:**\n\`\`\`javascript\n${issue.code}\n\`\`\``);
167-
}
168-
169-
issueText.push('---');
170-
return issueText.join('\n\n');
171-
}
172-
173115
private analyzeIssues(
174116
code: string,
175117
messages: Linter.LintMessage[]

packages/mobile-web/tests/tools/mobile-offline/offline-analysis/tool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe('OfflineAnalysisTool', () => {
243243
url: '/api/v1/offline-analysis',
244244
},
245245
}).then((result: any) => {
246-
expect(result.content[0].text).toContain('orchestration instructions');
246+
expect(result.content[0].text).toContain('orchestrationInstructions');
247247
expect(result.content[0].text).toContain('sfmobile-web-offline-guidance');
248248
});
249249
});

0 commit comments

Comments
 (0)