|
7 | 7 | import Breadcrumb from '$lib/common/Breadcrumb.svelte'; |
8 | 8 | import HeadTitle from '$lib/common/HeadTitle.svelte'; |
9 | 9 | import LoadingToComplete from '$lib/common/LoadingToComplete.svelte'; |
10 | | - import AgentPrompt from './agent-components/agent-prompt.svelte'; |
| 10 | + import AgentInstruction from './agent-components/agent-instruction.svelte'; |
11 | 11 | import AgentOverview from './agent-components/agent-overview.svelte'; |
12 | 12 | import AgentFunction from './agent-components/agent-function.svelte'; |
13 | 13 | import AgentTabs from './agent-tabs.svelte'; |
|
19 | 19 | import { goto } from '$app/navigation'; |
20 | 20 | import { AgentExtensions } from '$lib/helpers/utils/agent'; |
21 | 21 | import LocalStorageManager from '$lib/helpers/utils/storage-manager'; |
| 22 | + import AgentTemplate from './agent-components/agent-template.svelte'; |
22 | 23 |
|
23 | 24 | /** @type {import('$agentTypes').AgentModel} */ |
24 | 25 | let agent; |
25 | 26 | /** @type {any} */ |
26 | 27 | let agentFunctionCmp = null; |
27 | 28 | /** @type {any} */ |
28 | | - let agentPromptCmp = null; |
| 29 | + let agentInstructionCmp = null; |
| 30 | + /** @type {any} */ |
| 31 | + let agentTemplateCmp = null; |
29 | 32 | /** @type {any} */ |
30 | 33 | let agentTabsCmp = null; |
31 | 34 | /** @type {import('$agentTypes').AgentModel} */ |
|
90 | 93 |
|
91 | 94 | function handleAgentUpdate() { |
92 | 95 | fetchJsonContent(); |
93 | | - fetchPrompts(); |
| 96 | + fetchInstructions(); |
| 97 | + fetchTemplates(); |
94 | 98 | fetchTabData(); |
95 | 99 |
|
96 | 100 | agent = { |
|
114 | 118 | isLoading = false; |
115 | 119 | isComplete = true; |
116 | 120 | deleteAgentDraft(); |
117 | | - refreshChannelPrompts(); |
| 121 | + refreshInstructions(); |
| 122 | + refreshTemplates(); |
118 | 123 | setTimeout(() => { |
119 | 124 | isComplete = false; |
120 | 125 | }, duration); |
|
132 | 137 | functions: textContent?.functions?.length > 0 ? textContent.functions : |
133 | 138 | (jsonContent?.functions?.length > 0 ? jsonContent?.functions : []), |
134 | 139 | responses: textContent?.responses?.length > 0 ? textContent.responses : |
135 | | - (jsonContent?.responses?.length > 0 ? jsonContent?.responses : []), |
136 | | - templates: textContent?.templates?.length > 0 ? textContent.templates : |
137 | | - (jsonContent?.templates?.length > 0 ? jsonContent?.templates : []), |
| 140 | + (jsonContent?.responses?.length > 0 ? jsonContent?.responses : []) |
138 | 141 | } |
139 | 142 | } |
140 | 143 |
|
| 144 | + // Functions, responses |
141 | 145 | function fetchJsonContent() { |
142 | 146 | const data = formatJsonContent(); |
143 | 147 | agent.functions = data.functions; |
144 | 148 | agent.responses = data.responses; |
145 | | - agent.templates = data.templates; |
146 | 149 | } |
147 | 150 |
|
148 | | - function formatOriginalPrompts() { |
149 | | - const obj = agentPromptCmp?.fetchOriginalChannelPrompts(); |
| 151 | + // Insturctions |
| 152 | + function formatOriginalInstructions() { |
| 153 | + const obj = agentInstructionCmp?.fetchOriginalInstructions(); |
150 | 154 | return { |
151 | 155 | instruction: obj.systemPrompt, |
152 | 156 | channel_instructions: obj.channelPrompts || [] |
153 | 157 | } |
154 | 158 | } |
155 | 159 |
|
156 | | - function fetchPrompts() { |
157 | | - const obj = agentPromptCmp?.fetchChannelPrompts(); |
| 160 | + function fetchInstructions() { |
| 161 | + const obj = agentInstructionCmp?.fetchInstructions(); |
158 | 162 | agent.instruction = obj.systemPrompt; |
159 | 163 | agent.channel_instructions = obj.channelPrompts || []; |
160 | 164 | } |
161 | 165 |
|
| 166 | + function refreshInstructions() { |
| 167 | + agentInstructionCmp?.refresh(); |
| 168 | + } |
| 169 | +
|
| 170 | + // Templates |
| 171 | + function formatOriginalTemplates() { |
| 172 | + const obj = agentTemplateCmp?.fetchOriginalTemplates(); |
| 173 | + return { |
| 174 | + templates: obj.templates || [] |
| 175 | + } |
| 176 | + } |
| 177 | +
|
| 178 | + function fetchTemplates() { |
| 179 | + const obj = agentTemplateCmp?.fetchTemplates(); |
| 180 | + agent.templates = obj.templates || []; |
| 181 | + } |
| 182 | +
|
| 183 | + function refreshTemplates() { |
| 184 | + agentTemplateCmp?.refresh(); |
| 185 | + } |
| 186 | +
|
| 187 | +
|
| 188 | + // Tab data |
162 | 189 | function formatOriginalTabData() { |
163 | | - const data = agentTabsCmp?.fetchOriginalData(); |
| 190 | + const data = agentTabsCmp?.fetchOriginalTabData(); |
164 | 191 | return data ? { |
165 | 192 | utilities: data.utilities || [], |
166 | 193 | knowledge_bases: data.knwoledgebases || [], |
167 | 194 | rules: data.rules || [] |
168 | 195 | } : null; |
169 | 196 | } |
| 197 | +
|
170 | 198 | function fetchTabData() { |
171 | | - const data = agentTabsCmp?.fetchData(); |
| 199 | + const data = agentTabsCmp?.fetchTabData(); |
172 | 200 | if (data) { |
173 | 201 | agent.utilities = data.utilities || []; |
174 | 202 | agent.knowledge_bases = data.knwoledgebases || []; |
175 | 203 | agent.rules = data.rules || []; |
176 | 204 | } |
177 | 205 | } |
178 | 206 |
|
179 | | - function refreshChannelPrompts() { |
180 | | - agentPromptCmp?.refreshChannelPrompts(); |
181 | | - } |
182 | 207 |
|
183 | 208 | function deleteCurrentAgent() { |
184 | 209 | Swal.fire({ |
|
207 | 232 | const data = { |
208 | 233 | ...agent, |
209 | 234 | ...formatJsonContent(), |
210 | | - ...formatOriginalPrompts(), |
| 235 | + ...formatOriginalInstructions(), |
| 236 | + ...formatOriginalTemplates(), |
211 | 237 | ...formatOriginalTabData(), |
212 | 238 | }; |
213 | 239 | saveAgentDraft(data); |
|
218 | 244 | agentDraft = null; |
219 | 245 | deleteAgentDraft(); |
220 | 246 | setTimeout(() => { |
221 | | - refreshChannelPrompts(); |
222 | | - agentFunctionCmp?.reinit(); |
223 | | - agentTabsCmp?.reinit(); |
| 247 | + refreshInstructions(); |
| 248 | + refreshTemplates(); |
| 249 | + agentFunctionCmp?.refresh(); |
| 250 | + agentTabsCmp?.refresh(); |
224 | 251 | }); |
225 | 252 | } |
226 | 253 | </script> |
|
253 | 280 | </Col> |
254 | 281 | <Col class="section-min-width agent-col" style="flex: 60%;"> |
255 | 282 | <div class="agent-detail-section"> |
256 | | - <AgentPrompt |
257 | | - bind:this={agentPromptCmp} |
| 283 | + <AgentInstruction |
| 284 | + bind:this={agentInstructionCmp} |
| 285 | + agent={agent} |
| 286 | + {handleAgentChange} |
| 287 | + /> |
| 288 | + </div> |
| 289 | + <div class="agent-detail-section"> |
| 290 | + <AgentTemplate |
| 291 | + bind:this={agentTemplateCmp} |
258 | 292 | agent={agent} |
259 | 293 | {handleAgentChange} |
260 | 294 | /> |
|
0 commit comments