* FEATURE: Tool name validation - Add unique index to the name column of the ai_tools table - correct our tests for AiToolController - tool_name field which will be used to represent to LLM - Add tool_name to Tools's presets - Add duplicate tools validation for AiPersona - Add unique constraint to the name column of the ai_tools table * DEV: Validate duplicate tool_name between builin tools and custom tools * lint * chore: fix linting * fix conlict mistakes * chore: correct icon class * chore: fix failed specs * Add max_length to tool_name * chore: correct the option name * lintings * fix lintings
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
import { TrackedArray, TrackedObject } from "@ember-compat/tracked-built-ins";
|
|
import RestModel from "discourse/models/rest";
|
|
|
|
const CREATE_ATTRIBUTES = [
|
|
"id",
|
|
"name",
|
|
"tool_name",
|
|
"description",
|
|
"parameters",
|
|
"script",
|
|
"summary",
|
|
"rag_uploads",
|
|
"rag_chunk_tokens",
|
|
"rag_chunk_overlap_tokens",
|
|
"enabled",
|
|
];
|
|
|
|
export default class AiTool extends RestModel {
|
|
createProperties() {
|
|
return this.getProperties(CREATE_ATTRIBUTES);
|
|
}
|
|
|
|
updateProperties() {
|
|
return this.getProperties(CREATE_ATTRIBUTES);
|
|
}
|
|
|
|
trackParameters(parameters) {
|
|
return new TrackedArray(
|
|
parameters?.map((p) => {
|
|
const parameter = new TrackedObject(p);
|
|
|
|
if (parameter.enum && parameter.enum.length) {
|
|
parameter.enum = new TrackedArray(parameter.enum);
|
|
} else {
|
|
parameter.enum = null;
|
|
}
|
|
|
|
return parameter;
|
|
})
|
|
);
|
|
}
|
|
|
|
workingCopy() {
|
|
const attrs = this.getProperties(CREATE_ATTRIBUTES);
|
|
attrs.parameters = this.trackParameters(attrs.parameters);
|
|
return this.store.createRecord("ai-tool", attrs);
|
|
}
|
|
}
|