Skip to content

Commit b0cca21

Browse files
author
Jicheng Lu
committed
revert agent reset
1 parent b4c2408 commit b0cca21

File tree

10 files changed

+11
-193
lines changed

10 files changed

+11
-193
lines changed

src/routes/page/agent/[agentId]/+page.svelte

Lines changed: 10 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import Swal from 'sweetalert2'
1919
import { goto } from '$app/navigation';
2020
import { AgentExtensions } from '$lib/helpers/utils/agent';
21-
import LocalStorageManager from '$lib/helpers/utils/storage-manager';
2221
import AgentTemplate from './agent-components/agent-template.svelte';
2322
2423
/** @type {import('$agentTypes').AgentModel} */
@@ -31,51 +30,23 @@
3130
let agentTemplateCmp = null;
3231
/** @type {any} */
3332
let agentTabsCmp = null;
34-
/** @type {import('$agentTypes').AgentModel} */
35-
let originalAgent;
36-
/** @type {any} */
37-
let agentDraft = null;
3833
3934
/** @type {boolean} */
4035
let isLoading = false;
4136
let isComplete = false;
4237
4338
const duration = 3000;
4439
const params = $page.params;
45-
const agentStorage = new LocalStorageManager();
46-
4740
4841
onMount(() => {
4942
isLoading = true;
50-
agentDraft = getAgentDraft();
5143
getAgent(params.agentId).then(data => {
52-
originalAgent = {
53-
...data,
54-
llm_config: data.llm_config || {}
55-
};
56-
if (agentDraft) {
57-
agent = agentDraft;
58-
} else {
59-
agent = JSON.parse(JSON.stringify(originalAgent));
60-
}
44+
agent = data;
6145
}).finally(() => {
6246
isLoading = false;
6347
});
6448
});
6549
66-
function getAgentDraft() {
67-
return agentStorage.get(`agent_draft_${params.agentId}`)
68-
}
69-
70-
/** @param {any} data */
71-
function saveAgentDraft(data) {
72-
agentStorage.set(`agent_draft_${params.agentId}`, data, 24 * 60 * 60 * 1000)
73-
}
74-
75-
function deleteAgentDraft() {
76-
agentStorage.remove(`agent_draft_${params.agentId}`);
77-
}
78-
7950
function updateCurrentAgent() {
8051
Swal.fire({
8152
title: 'Are you sure?',
@@ -107,15 +78,17 @@
10778
utilities: agent.utilities || [],
10879
knowledge_bases: agent.knowledge_bases || [],
10980
rules: agent.rules || [],
110-
max_message_count: Number(agent.max_message_count) > 0 ? Number(agent.max_message_count) : null
81+
max_message_count: Number(agent.max_message_count) > 0 ? Number(agent.max_message_count) : null,
82+
llm_config: {
83+
...agent.llm_config,
84+
max_output_tokens: Number(agent.llm_config.max_output_tokens) > 0 ? Number(agent.llm_config.max_output_tokens) : null
85+
}
11186
};
11287
isLoading = true;
11388
saveAgent(agent).then(res => {
11489
isLoading = false;
11590
isComplete = true;
116-
deleteAgentDraft();
117-
refreshInstructions();
118-
refreshTemplates();
91+
refresh();
11992
setTimeout(() => {
12093
isComplete = false;
12194
}, duration);
@@ -144,53 +117,17 @@
144117
agent.responses = data.responses;
145118
}
146119
147-
// Insturctions
148-
function formatOriginalInstructions() {
149-
const obj = agentInstructionCmp?.fetchOriginalInstructions();
150-
return {
151-
instruction: obj.systemPrompt,
152-
channel_instructions: obj.channelPrompts || []
153-
}
154-
}
155-
156120
function fetchInstructions() {
157121
const obj = agentInstructionCmp?.fetchInstructions();
158122
agent.instruction = obj.systemPrompt;
159123
agent.channel_instructions = obj.channelPrompts || [];
160124
}
161125
162-
function refreshInstructions() {
163-
agentInstructionCmp?.refresh();
164-
}
165-
166-
// Templates
167-
function formatOriginalTemplates() {
168-
const templates = agentTemplateCmp?.fetchOriginalTemplates();
169-
return {
170-
templates: templates || []
171-
}
172-
}
173-
174126
function fetchTemplates() {
175127
agent.templates = agentTemplateCmp?.fetchTemplates();;
176128
}
177129
178-
function refreshTemplates() {
179-
agentTemplateCmp?.refresh();
180-
}
181-
182-
183130
// Tab data
184-
function formatOriginalTabData() {
185-
const data = agentTabsCmp?.fetchOriginalTabData();
186-
return data ? {
187-
utilities: data.utilities || [],
188-
knowledge_bases: data.knwoledgebases || [],
189-
rules: data.rules || [],
190-
mcp_tools: data.mcpTools || []
191-
} : null;
192-
}
193-
194131
function fetchTabData() {
195132
const data = agentTabsCmp?.fetchTabData();
196133
if (data) {
@@ -221,32 +158,12 @@
221158
222159
function handleAgentDelete() {
223160
deleteAgent(agent?.id).then(res => {
224-
deleteAgentDraft();
225161
goto(`page/agent`);
226162
});
227163
}
228164
229-
function handleAgentChange() {
230-
const data = {
231-
...agent,
232-
...formatJsonContent(),
233-
...formatOriginalInstructions(),
234-
...formatOriginalTemplates(),
235-
...formatOriginalTabData(),
236-
};
237-
saveAgentDraft(data);
238-
}
239-
240-
function handleAgentReset() {
241-
agent = JSON.parse(JSON.stringify(originalAgent));
242-
agentDraft = null;
243-
deleteAgentDraft();
244-
setTimeout(() => {
245-
refreshInstructions();
246-
refreshTemplates();
247-
agentFunctionCmp?.refresh();
248-
agentTabsCmp?.refresh();
249-
});
165+
function refresh() {
166+
agentInstructionCmp?.refresh();
250167
}
251168
</script>
252169
@@ -263,16 +180,12 @@
263180
agent={agent}
264181
profiles={agent.profiles || []}
265182
labels={agent.labels || []}
266-
resetable={!!agentDraft}
267-
resetAgent={() => handleAgentReset()}
268-
{handleAgentChange}
269183
/>
270184
</div>
271185
<div class="agent-detail-section">
272186
<AgentTabs
273187
bind:this={agentTabsCmp}
274188
agent={agent}
275-
{handleAgentChange}
276189
/>
277190
</div>
278191
</Col>
@@ -281,27 +194,24 @@
281194
<AgentInstruction
282195
bind:this={agentInstructionCmp}
283196
agent={agent}
284-
{handleAgentChange}
285197
/>
286198
</div>
287199
<div class="agent-detail-section">
288200
<AgentTemplate
289201
bind:this={agentTemplateCmp}
290202
agent={agent}
291-
{handleAgentChange}
292203
/>
293204
</div>
294205
<div class="agent-detail-section">
295206
<AgentFunction
296207
bind:this={agentFunctionCmp}
297208
agent={agent}
298-
{handleAgentChange}
299209
/>
300210
</div>
301211
</Col>
302212
</Row>
303213
304-
{#if !!AgentExtensions.editable(originalAgent)}
214+
{#if !!AgentExtensions.editable(agent)}
305215
<Row>
306216
<div class="hstack gap-2 my-4">
307217
<Button class="btn btn-soft-primary" on:click={() => updateCurrentAgent()}>{$_('Save Agent')}</Button>

src/routes/page/agent/[agentId]/agent-components/agent-instruction.svelte

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515
/** @type {() => void} */
1616
export let handleAgentChange = () => {};
1717
18-
export const fetchOriginalInstructions = () => {
19-
return {
20-
systemPrompt: inner_instructions?.[0]?.instruction || '',
21-
channelPrompts: inner_instructions?.slice(1)?.map(x => ({
22-
channel: x.channel,
23-
instruction: x.instruction
24-
})) || []
25-
};
26-
};
27-
2818
export const fetchInstructions = () => {
2919
const candidates = inner_instructions?.filter((x, idx) => idx > 0 && !!x.channel?.trim())?.map(x => {
3020
return { channel: x.channel.trim().toLowerCase(), instruction: x.instruction };

src/routes/page/agent/[agentId]/agent-components/agent-knowledge-base.svelte

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
return knowledgeBases;
4040
}
4141
42-
export const fetchOriginalKnowledgeBases = () => {
43-
return innerKnowledgeBases;
44-
}
45-
46-
export const refresh = () => init();
47-
4842
/** @type {any[]} */
4943
let knowledgeBaseOptions = [];
5044

src/routes/page/agent/[agentId]/agent-components/agent-llm-config.svelte

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
};
1818
}
1919
20-
export const fetchOriginalLlmConfig = () => {};
21-
22-
export const refresh = () => {
23-
config = agent.llm_config;
24-
init();
25-
};
26-
2720
const recursiveDepthLowerLimit = 1;
2821
2922
let config = agent.llm_config;

src/routes/page/agent/[agentId]/agent-components/agent-mcp-tool.svelte

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@
4848
return mcps;
4949
}
5050
51-
export const fetchOriginalMcpTools = () => {
52-
return innerMcps;
53-
}
54-
55-
export const refresh = () => init();
56-
5751
/** @type {any[]} */
5852
let mcpOptions = [];
5953

src/routes/page/agent/[agentId]/agent-components/agent-overview.svelte

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
2222
/** @type {() => void} */
2323
export let handleAgentChange = () => {};
24-
25-
/** @type {boolean} */
26-
export let resetable = false;
27-
28-
/** @type {() => void} */
29-
export let resetAgent = () => {};
3024
3125
onMount(() => {});
3226
@@ -73,19 +67,6 @@
7367
7468
<Card>
7569
<CardHeader>
76-
{#if resetable}
77-
<!-- svelte-ignore a11y-click-events-have-key-events -->
78-
<!-- svelte-ignore a11y-no-static-element-interactions -->
79-
<div
80-
class="agent-reset-container"
81-
data-bs-toggle="tooltip"
82-
data-bs-placement="bottom"
83-
title={$_('Reset')}
84-
on:click={() => resetAgent()}
85-
>
86-
<i class="mdi mdi-refresh text-primary clickable" />
87-
</div>
88-
{/if}
8970
<div class="text-center">
9071
<div class="agent-overview-header">
9172
<img

src/routes/page/agent/[agentId]/agent-components/agent-rule.svelte

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
return rules;
3636
}
3737
38-
export const fetchOriginalRules = () => {
39-
return innerRules;
40-
}
41-
42-
export const refresh = () => init();
43-
4438
/** @type {any[]} */
4539
let ruleOptions = [];
4640

src/routes/page/agent/[agentId]/agent-components/agent-template.svelte

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
/** @type {() => void} */
1515
export let handleAgentChange = () => {};
1616
17-
export const fetchOriginalTemplates = () => {
18-
const templates = inner_templates?.map(x => ({
19-
name: x.name,
20-
content: x.content
21-
})) || [];
22-
return templates;
23-
};
24-
2517
export const fetchTemplates = () => {
2618
const candidates = inner_templates?.filter((x, idx) => !!x.name?.trim())?.map(x => {
2719
return { name: x.name.trim().toLowerCase(), content: x.content };
@@ -38,8 +30,6 @@
3830
return prompts;
3931
}
4032
41-
export const refresh = () => init();
42-
4333
4434
/** @type {import('$agentTypes').AgentTemplate} */
4535
const defaultTemplate = {

src/routes/page/agent/[agentId]/agent-components/agent-utility.svelte

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@
5050
innerRefresh(candidates);
5151
return candidates;
5252
}
53-
54-
export const fetchOriginalUtilities = () => {
55-
return innerUtilities;
56-
}
57-
58-
export const refresh = () => init();
59-
53+
6054
/** @type {any} */
6155
let utilityMapper = {};
6256

src/routes/page/agent/[agentId]/agent-tabs.svelte

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,6 @@
3232
};
3333
};
3434
35-
export const fetchOriginalTabData = () => {
36-
const utilities = agentUtilityCmp?.fetchOriginalUtilities();
37-
const knwoledgebases = agentKnowledgeBaseCmp?.fetchOriginalKnowledgeBases();
38-
const rules = agentEventRuleCmp?.fetchOriginalRules();
39-
const mcpTools = agentMcpToolCmp?.fetchOriginalMcpTools();
40-
41-
return {
42-
utilities: utilities || [],
43-
knwoledgebases: knwoledgebases || [],
44-
rules: rules || [],
45-
mcpTools: mcpTools || []
46-
};
47-
}
48-
49-
export const refresh = () => {
50-
agentLlmConfigCmp?.refresh();
51-
agentUtilityCmp?.refresh();
52-
agentKnowledgeBaseCmp?.refresh();
53-
agentEventRuleCmp?.refresh();
54-
agentMcpToolCmp?.refresh();
55-
}
56-
5735
/** @type {any} */
5836
let agentLlmConfigCmp = null;
5937
/** @type {any} */

0 commit comments

Comments
 (0)