agent-zero/plugins/_browser_agent/webui/browser-agent-store.js
Alessandro d30a565549 browser-agent: selectable _model_config preset for browser runs
This PR keeps the Browser Agent runtime behavior as-is and only adds in the model-preset option for browser runs (highly requested by our users).

The Browser Agent can now use either:
- the effective Main Model from `_model_config`, or
- one saved `_model_config` preset dedicated to browser tasks

- this PR brings back LLM customization for Browser Agent plugin, but without over engineering. Model presets-only, not custom provider + LLM, like we have in Email Integration.
- created a separate `browser-agent-store.js` page store to remove JS from within x-data in the HTML markup of main.html
2026-04-12 03:38:41 +02:00

56 lines
1.4 KiB
JavaScript

import { createStore } from "/js/AlpineStore.js";
import { callJsonApi } from "/js/api.js";
const STATUS_API = "/plugins/_browser_agent/status";
const MODEL_PRESET_API = "/plugins/_browser_agent/model_preset";
const model = {
loading: true,
savingPreset: false,
error: "",
status: null,
async openModelSettings() {
await import("/components/plugins/plugin-settings-store.js");
await $store.pluginSettingsPrototype.openConfig("_model_config");
},
async refreshStatus() {
this.status = await callJsonApi(STATUS_API, {});
},
async savePreset(presetName) {
this.savingPreset = true;
try {
await callJsonApi(MODEL_PRESET_API, {
action: presetName ? "set" : "clear",
preset_name: presetName || "",
});
this.error = "";
await this.refreshStatus();
} catch (error) {
this.error = error instanceof Error ? error.message : String(error);
await this.refreshStatus();
} finally {
this.savingPreset = false;
}
},
async onOpen() {
this.loading = true;
this.error = "";
try {
await this.refreshStatus();
} catch (error) {
this.status = null;
this.error = error instanceof Error ? error.message : String(error);
} finally {
this.loading = false;
}
},
cleanup() {},
};
export const store = createStore("browserAgentPage", model);