generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema): add support for custom prompts schema
This commit introduces support for custom prompts schema in the AutoDev platform. It adds a new schema provider factory, `AutoDevPromptJsonSchemaProviderFactory`, which creates a `CustomPromptsSchemaFileProvider` for each project. The `CustomPromptsSchemaFileProvider` is responsible for providing the custom prompts schema file, which is expected to have the name `AutoDevCustomsPromptFile.json`. The commit also modifies the `LLMSettingComponent` to include a `LanguageTextField` for editing the custom prompts schema. This component is now initialized with a `SimpleDocumentCreator` that generates a document based on the provided value, language, and project, and also sets the file name to `CUSTOM_PROMPTS_FILE_NAME`. Finally, a new extension is added to the `autodev-core.xml` file, which registers the `AutoDevPromptJsonSchemaProviderFactory` as a provider factory for the `JavaScript.JsonSchema` extension. This enables the custom prompts schema support in the IDE.
- Loading branch information
Showing
6 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/cc/unitmesh/devti/custom/schema/CustomPromptsJsonSchemaProviderFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cc.unitmesh.devti.custom.schema | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider | ||
import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory | ||
|
||
class AutoDevPromptJsonSchemaProviderFactory: JsonSchemaProviderFactory { | ||
override fun getProviders(project: Project): MutableList<JsonSchemaFileProvider> { | ||
return mutableListOf(CustomPromptsSchemaFileProvider(project)) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/cc/unitmesh/devti/custom/schema/CustomPromptsSchemaFileProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cc.unitmesh.devti.custom.schema | ||
|
||
import com.intellij.openapi.application.runReadAction | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider | ||
import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory | ||
import com.jetbrains.jsonSchema.extension.SchemaType | ||
|
||
const val CUSTOM_PROMPTS_FILE_NAME = "AutoDevCustomsPromptFile.json" | ||
|
||
class CustomPromptsSchemaFileProvider(project: Project) : JsonSchemaFileProvider { | ||
override fun isAvailable(file: VirtualFile): Boolean { | ||
return runReadAction { isAutoDevCustomAgentFile(file) } | ||
} | ||
|
||
private fun isAutoDevCustomAgentFile(file: VirtualFile): Boolean { | ||
if (!file.isValid) { | ||
return false | ||
} | ||
|
||
return file.name == CUSTOM_PROMPTS_FILE_NAME | ||
} | ||
|
||
override fun getName(): String = "AutoDevCustomsPromptFile" | ||
|
||
override fun getSchemaFile(): VirtualFile? { | ||
return JsonSchemaProviderFactory.getResourceFile(this::class.java, customPromptsSchemaFile) | ||
} | ||
|
||
override fun getSchemaType(): SchemaType { | ||
return SchemaType.schema | ||
} | ||
|
||
companion object { | ||
private const val customPromptsSchemaFile = "autodev-custom-prompts.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/resources/cc/unitmesh/devti/custom/schema/autodev-custom-prompts.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"spec": { | ||
"type": "object", | ||
"properties": { | ||
"controller": { | ||
"type": "string" | ||
}, | ||
"service": { | ||
"type": "string" | ||
}, | ||
"entity": { | ||
"type": "string" | ||
}, | ||
"repository": { | ||
"type": "string" | ||
}, | ||
"ddl": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [], | ||
"additionalProperties": true | ||
}, | ||
"prompts": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"type": "string" | ||
}, | ||
"autoInvoke": { | ||
"type": "boolean" | ||
}, | ||
"matchRegex": { | ||
"type": "string" | ||
}, | ||
"priority": { | ||
"type": "integer" | ||
}, | ||
"template": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"title", | ||
"template" | ||
] | ||
} | ||
}, | ||
"documentations": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"type": "string" | ||
}, | ||
"prompt": { | ||
"type": "string" | ||
}, | ||
"start": { | ||
"type": "string" | ||
}, | ||
"end": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"type": "string" | ||
}, | ||
"example": { | ||
"type": "object", | ||
"properties": { | ||
"question": { | ||
"type": "string" | ||
}, | ||
"answer": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"question", | ||
"answer" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"title", | ||
"prompt", | ||
"example" | ||
] | ||
} | ||
} | ||
}, | ||
"required": [], | ||
"additionalProperties": true | ||
} |