Files
discourse-ai/assets/javascripts/discourse/admin/models/ai-tool.js
T
Sam 41054c4fb8 FEATURE: improve site setting search (#780)
This improves the site setting search so it performs a somewhat
fuzzy match.

Previously it did not handle seperators such as "space" and a
term such as "min_post_length" would not find "min_first_post_length"

A more liberal search algorithm makes it easier to the AI to
navigate settings.

* Minor fix, {{and parameter.enum parameter.enum.length}} is non
obviously broken.


If parameter.enum is a tracked array it will return the object
cause embers and helper implementation.

This corrects an issue where enum keeps on selecting itself by
mistake.
2024-08-29 16:05:38 +10:00

45 lines
1015 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);
}
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);
}
}