Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit ab8bc88

Browse files
committed
Merge from main
2 parents cb107de + f753618 commit ab8bc88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1483
-1130
lines changed

.discourse-compatibility

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
< 3.5.0.beta2-dev: de8624416a15b3d8e7ad350b083cc1420451ccec
12
< 3.5.0.beta1-dev: bdef136080074a993e7c4f5ca562edc31a8ba756
23
< 3.4.0.beta4-dev: a53719ab8eb071459f215227421b3ea4987e5f87
34
< 3.4.0.beta4-dev: 20612fde52d3f740cad64823ef8aadb0748b567f
Lines changed: 51 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { tracked } from "@glimmer/tracking";
21
import { ajax } from "discourse/lib/ajax";
32
import RestModel from "discourse/models/rest";
43

@@ -63,40 +62,7 @@ const SYSTEM_ATTRIBUTES = [
6362
"allow_chat_direct_messages",
6463
];
6564

66-
class ToolOption {
67-
@tracked value = null;
68-
}
69-
7065
export default class AiPersona extends RestModel {
71-
// this code is here to convert the wire schema to easier to work with object
72-
// on the wire we pass in/out tools as an Array.
73-
// [[ToolName, {option1: value, option2: value}, force], ToolName2, ToolName3]
74-
// So we rework this into a "tools" property and nested toolOptions
75-
init(properties) {
76-
this.forcedTools = [];
77-
if (properties.tools) {
78-
properties.tools = properties.tools.map((tool) => {
79-
if (typeof tool === "string") {
80-
return tool;
81-
} else {
82-
let [toolId, options, force] = tool;
83-
for (let optionId in options) {
84-
if (!options.hasOwnProperty(optionId)) {
85-
continue;
86-
}
87-
this.getToolOption(toolId, optionId).value = options[optionId];
88-
}
89-
if (force) {
90-
this.forcedTools.push(toolId);
91-
}
92-
return toolId;
93-
}
94-
});
95-
}
96-
super.init(properties);
97-
this.tools = properties.tools;
98-
}
99-
10066
async createUser() {
10167
const result = await ajax(
10268
`/admin/plugins/discourse-ai/ai-personas/${this.id}/create-user.json`,
@@ -109,63 +75,79 @@ export default class AiPersona extends RestModel {
10975
return this.user;
11076
}
11177

112-
getToolOption(toolId, optionId) {
113-
this.toolOptions ||= {};
114-
this.toolOptions[toolId] ||= {};
115-
return (this.toolOptions[toolId][optionId] ||= new ToolOption());
78+
flattenedToolStructure(data) {
79+
return data.tools.map((tName) => {
80+
return [tName, data.toolOptions[tName], data.forcedTools.includes(tName)];
81+
});
11682
}
11783

118-
populateToolOptions(attrs) {
119-
if (!attrs.tools) {
120-
return;
121-
}
122-
let toolsWithOptions = [];
123-
attrs.tools.forEach((toolId) => {
124-
if (typeof toolId !== "string") {
125-
toolId = toolId[0];
126-
}
84+
// this code is here to convert the wire schema to easier to work with object
85+
// on the wire we pass in/out tools as an Array.
86+
// [[ToolName, {option1: value, option2: value}, force], ToolName2, ToolName3]
87+
// We split it into tools, options and a list of forced ones.
88+
populateTools(attrs) {
89+
const forcedTools = [];
90+
const toolOptions = {};
91+
92+
const flatTools = attrs.tools?.map((tool) => {
93+
if (typeof tool === "string") {
94+
return tool;
95+
} else {
96+
let [toolId, options, force] = tool;
97+
const mappedOptions = {};
12798

128-
let force = this.forcedTools.includes(toolId);
129-
if (this.toolOptions && this.toolOptions[toolId]) {
130-
let options = this.toolOptions[toolId];
131-
let optionsWithValues = {};
132-
for (let optionId in options) {
99+
for (const optionId in options) {
133100
if (!options.hasOwnProperty(optionId)) {
134101
continue;
135102
}
136-
let option = options[optionId];
137-
optionsWithValues[optionId] = option.value;
103+
104+
mappedOptions[optionId] = options[optionId];
138105
}
139-
toolsWithOptions.push([toolId, optionsWithValues, force]);
140-
} else {
141-
toolsWithOptions.push([toolId, {}, force]);
106+
107+
if (Object.keys(mappedOptions).length > 0) {
108+
toolOptions[toolId] = mappedOptions;
109+
}
110+
111+
if (force) {
112+
forcedTools.push(toolId);
113+
}
114+
115+
return toolId;
142116
}
143117
});
144-
attrs.tools = toolsWithOptions;
118+
119+
attrs.tools = flatTools;
120+
attrs.forcedTools = forcedTools;
121+
attrs.toolOptions = toolOptions;
145122
}
146123

147124
updateProperties() {
148-
let attrs = this.system
125+
const attrs = this.system
149126
? this.getProperties(SYSTEM_ATTRIBUTES)
150127
: this.getProperties(CREATE_ATTRIBUTES);
151128
attrs.id = this.id;
152-
this.populateToolOptions(attrs);
129+
153130
return attrs;
154131
}
155132

156133
createProperties() {
157-
let attrs = this.getProperties(CREATE_ATTRIBUTES);
158-
this.populateToolOptions(attrs);
159-
return attrs;
134+
return this.getProperties(CREATE_ATTRIBUTES);
160135
}
161136

162-
workingCopy() {
163-
let attrs = this.getProperties(CREATE_ATTRIBUTES);
164-
this.populateToolOptions(attrs);
137+
fromPOJO(data) {
138+
const dataClone = JSON.parse(JSON.stringify(data));
139+
140+
const persona = AiPersona.create(dataClone);
141+
persona.tools = this.flattenedToolStructure(dataClone);
165142

166-
const persona = AiPersona.create(attrs);
167-
persona.forcedTools = (this.forcedTools || []).slice();
168-
persona.forced_tool_count = this.forced_tool_count || -1;
169143
return persona;
170144
}
145+
146+
toPOJO() {
147+
const attrs = this.getProperties(CREATE_ATTRIBUTES);
148+
this.populateTools(attrs);
149+
attrs.forced_tool_count = this.forced_tool_count || -1;
150+
151+
return attrs;
152+
}
171153
}

assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,15 @@ export default class AdminReportSentimentAnalysis extends Component {
216216
}
217217

218218
const currentQueryParams = this.router.currentRoute.queryParams;
219+
220+
const currentFilters = currentQueryParams?.filters
221+
? JSON.parse(currentQueryParams.filters)
222+
: {};
223+
219224
this.router.transitionTo(this.router.currentRoute.name, {
220225
queryParams: {
221226
...currentQueryParams,
222-
filters: JSON.parse(currentQueryParams.filters), // avoids a double escaping
227+
filters: currentFilters, // avoids a double escaping
223228
selectedChart: data.title,
224229
},
225230
});
@@ -265,10 +270,13 @@ export default class AdminReportSentimentAnalysis extends Component {
265270
this.posts = [];
266271

267272
const currentQueryParams = this.router.currentRoute.queryParams;
273+
const currentFilters = currentQueryParams?.filters
274+
? JSON.parse(currentQueryParams.filters)
275+
: {};
268276
this.router.transitionTo(this.router.currentRoute.name, {
269277
queryParams: {
270278
...currentQueryParams,
271-
filters: JSON.parse(currentQueryParams.filters), // avoids a double escaping
279+
filters: currentFilters, // avoids a double escaping
272280
selectedChart: null,
273281
},
274282
});

assets/javascripts/discourse/components/ai-embedding-editor.gjs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ export default class AiEmbeddingEditor extends Component {
288288
});
289289
}
290290

291+
@action
292+
providerKeys(providerParams) {
293+
return Object.keys(providerParams);
294+
}
295+
291296
<template>
292297
{{#if this.showPresets}}
293298
<BackButton
@@ -493,8 +498,8 @@ export default class AiEmbeddingEditor extends Component {
493498

494499
{{! provider-specific content }}
495500
{{#if this.currentProvider}}
496-
{{#if data.provider_params}}
497-
<form.Object @name="provider_params" as |object name|>
501+
<form.Object @name="provider_params" as |object providerData|>
502+
{{#each (this.providerKeys providerData) as |name|}}
498503
{{#let (get this.providerParams name) as |params|}}
499504
{{#if params}}
500505
<object.Field
@@ -523,8 +528,8 @@ export default class AiEmbeddingEditor extends Component {
523528
</object.Field>
524529
{{/if}}
525530
{{/let}}
526-
</form.Object>
527-
{{/if}}
531+
{{/each}}
532+
</form.Object>
528533
{{/if}}
529534

530535
<form.Actions class="ai-embedding-editor__action_panel">
@@ -550,33 +555,24 @@ export default class AiEmbeddingEditor extends Component {
550555
</form.Actions>
551556

552557
{{#if this.displayTestResult}}
553-
<form.Field
554-
@showTitle={{false}}
555-
@name="test_results"
556-
@title="test_results"
557-
@format="full"
558-
class="ai-embedding-editor-tests"
559-
as |field|
560-
>
561-
<field.Custom>
562-
<ConditionalLoadingSpinner
563-
@size="small"
564-
@condition={{this.testRunning}}
565-
>
566-
{{#if this.testResult}}
567-
<div class="ai-embedding-editor-tests__success">
568-
{{icon "check"}}
569-
{{i18n "discourse_ai.embeddings.tests.success"}}
570-
</div>
571-
{{else}}
572-
<div class="ai-embedding-editor-tests__failure">
573-
{{icon "xmark"}}
574-
{{this.testErrorMessage}}
575-
</div>
576-
{{/if}}
577-
</ConditionalLoadingSpinner>
578-
</field.Custom>
579-
</form.Field>
558+
<form.Container @format="full" class="ai-embedding-editor-tests">
559+
<ConditionalLoadingSpinner
560+
@size="small"
561+
@condition={{this.testRunning}}
562+
>
563+
{{#if this.testResult}}
564+
<div class="ai-embedding-editor-tests__success">
565+
{{icon "check"}}
566+
{{i18n "discourse_ai.embeddings.tests.success"}}
567+
</div>
568+
{{else}}
569+
<div class="ai-embedding-editor-tests__failure">
570+
{{icon "xmark"}}
571+
{{this.testErrorMessage}}
572+
</div>
573+
{{/if}}
574+
</ConditionalLoadingSpinner>
575+
</form.Container>
580576
{{/if}}
581577
</Form>
582578
{{/if}}

assets/javascripts/discourse/components/ai-forced-tool-strategy-selector.gjs

Lines changed: 0 additions & 29 deletions
This file was deleted.

assets/javascripts/discourse/components/ai-full-page-search.gjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ export default class AiFullPageSearch extends Component {
172172
this.AiResults = [];
173173
this.showingAiResults = false;
174174
this.args.addSearchResults([], "topic_id");
175-
this.appEvents.trigger(AI_RESULTS_TOGGLED, {
176-
enabled: false,
177-
});
178175
}
179176

180177
performHyDESearch() {

0 commit comments

Comments
 (0)