Follow up to b863ddc94b
Ruby:
* Validate `summary` (the column is `not null`)
* Fix `name` validation (the column has `max_length` 100)
* Fix table annotations
* Accept missing `parameter` attributes (`required, `enum`, `enum_values`)
JS:
* Use native classes
* Don't use ember's array extensions
* Add explicit service injections
* Correct class names
* Use `||=` operator
* Use `store` service to create records
* Remove unused service injections
* Extract consts
* Group actions together
* Use `async`/`await`
* Use `withEventValue`
* Sort html attributes
* Use DButtons `@label` arg
* Use `input` elements instead of Ember's `Input` component (same w/ textarea)
* Remove `btn-default` class (automatically applied by DButton)
* Don't mix `I18n.t` and `i18n` in the same template
* Don't track props that aren't used in a template
* Correct invalid `target.value` code
* Remove unused/invalid `this.parameter`/`onChange` code
* Whitespace
* Use the new service import `inject as service` -> `service`
* Use `Object.entries()`
* Add missing i18n strings
* Fix an error in `addEnumValue` (calling `pushObject` on `undefined`)
* Use `TrackedArray`/`TrackedObject`
* Transform tool `parameters` keys (`enumValues` -> `enum_values`)
42 lines
920 B
JavaScript
42 lines
920 B
JavaScript
import { TrackedArray, TrackedObject } from "@ember-compat/tracked-built-ins";
|
|
import RestModel from "discourse/models/rest";
|
|
|
|
const CREATE_ATTRIBUTES = [
|
|
"id",
|
|
"name",
|
|
"description",
|
|
"parameters",
|
|
"script",
|
|
"summary",
|
|
"enabled",
|
|
];
|
|
|
|
export default class AiTool extends RestModel {
|
|
createProperties() {
|
|
return this.getProperties(CREATE_ATTRIBUTES);
|
|
}
|
|
|
|
updateProperties() {
|
|
return this.getProperties(CREATE_ATTRIBUTES);
|
|
}
|
|
|
|
workingCopy() {
|
|
const attrs = this.getProperties(CREATE_ATTRIBUTES);
|
|
|
|
attrs.parameters = new TrackedArray(
|
|
attrs.parameters?.map((p) => {
|
|
const parameter = new TrackedObject(p);
|
|
|
|
if (parameter.enum_values) {
|
|
parameter.enumValues = new TrackedArray(parameter.enum_values);
|
|
delete parameter.enum_values;
|
|
}
|
|
|
|
return parameter;
|
|
})
|
|
);
|
|
|
|
return this.store.createRecord("ai-tool", attrs);
|
|
}
|
|
}
|