Skip to content

Commit 9b41497

Browse files
authored
Merge pull request #312 from iceljc/features/refine-chat-window
refine agent templates
2 parents a9af474 + cfaa874 commit 9b41497

File tree

14 files changed

+378
-114
lines changed

14 files changed

+378
-114
lines changed

src/lib/common/InPlaceEdit.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
{:else}
6969
<!-- svelte-ignore a11y-click-events-have-key-events -->
7070
<!-- svelte-ignore a11y-no-static-element-interactions -->
71-
<div style="width: fit-content; min-width: 30%;" class="clickable" on:click={() => edit()}>
71+
<div style="width: fit-content; min-width: 30%;" class="clickable ellipsis" on:click={() => edit()}>
7272
{#if !!value?.trim()}
7373
<span>{value}</span>
7474
{:else}

src/lib/common/nav-bar/NavItem.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
on:input={handleTabInput}
119119
/>
120120
{:else}
121-
<div style="height: 100%" class="line-align-center">
121+
<div style="height: 100%;" class="line-align-center ellipsis">
122122
<div>{navBtnText}</div>
123123
</div>
124124
{/if}

src/lib/helpers/types/agentTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/**
77
* @typedef {Object} AgentTemplate
8+
* @property {string?} [uid]
89
* @property {string} name
910
* @property {string} content
1011
*/

src/lib/scss/custom/pages/_agent.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@
102102
background-color: white;
103103
padding: 20px;
104104
}
105+
106+
.agent-prompt-body {
107+
overflow-y: auto;
108+
scrollbar-width: none;
109+
margin-bottom: 0px !important;
110+
}
105111
}
106112
}
107113
}

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

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
88
import HeadTitle from '$lib/common/HeadTitle.svelte';
99
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';
1111
import AgentOverview from './agent-components/agent-overview.svelte';
1212
import AgentFunction from './agent-components/agent-function.svelte';
1313
import AgentTabs from './agent-tabs.svelte';
@@ -19,13 +19,16 @@
1919
import { goto } from '$app/navigation';
2020
import { AgentExtensions } from '$lib/helpers/utils/agent';
2121
import LocalStorageManager from '$lib/helpers/utils/storage-manager';
22+
import AgentTemplate from './agent-components/agent-template.svelte';
2223
2324
/** @type {import('$agentTypes').AgentModel} */
2425
let agent;
2526
/** @type {any} */
2627
let agentFunctionCmp = null;
2728
/** @type {any} */
28-
let agentPromptCmp = null;
29+
let agentInstructionCmp = null;
30+
/** @type {any} */
31+
let agentTemplateCmp = null;
2932
/** @type {any} */
3033
let agentTabsCmp = null;
3134
/** @type {import('$agentTypes').AgentModel} */
@@ -90,7 +93,8 @@
9093
9194
function handleAgentUpdate() {
9295
fetchJsonContent();
93-
fetchPrompts();
96+
fetchInstructions();
97+
fetchTemplates();
9498
fetchTabData();
9599
96100
agent = {
@@ -114,7 +118,8 @@
114118
isLoading = false;
115119
isComplete = true;
116120
deleteAgentDraft();
117-
refreshChannelPrompts();
121+
refreshInstructions();
122+
refreshTemplates();
118123
setTimeout(() => {
119124
isComplete = false;
120125
}, duration);
@@ -132,53 +137,73 @@
132137
functions: textContent?.functions?.length > 0 ? textContent.functions :
133138
(jsonContent?.functions?.length > 0 ? jsonContent?.functions : []),
134139
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 : [])
138141
}
139142
}
140143
144+
// Functions, responses
141145
function fetchJsonContent() {
142146
const data = formatJsonContent();
143147
agent.functions = data.functions;
144148
agent.responses = data.responses;
145-
agent.templates = data.templates;
146149
}
147150
148-
function formatOriginalPrompts() {
149-
const obj = agentPromptCmp?.fetchOriginalChannelPrompts();
151+
// Insturctions
152+
function formatOriginalInstructions() {
153+
const obj = agentInstructionCmp?.fetchOriginalInstructions();
150154
return {
151155
instruction: obj.systemPrompt,
152156
channel_instructions: obj.channelPrompts || []
153157
}
154158
}
155159
156-
function fetchPrompts() {
157-
const obj = agentPromptCmp?.fetchChannelPrompts();
160+
function fetchInstructions() {
161+
const obj = agentInstructionCmp?.fetchInstructions();
158162
agent.instruction = obj.systemPrompt;
159163
agent.channel_instructions = obj.channelPrompts || [];
160164
}
161165
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
162189
function formatOriginalTabData() {
163-
const data = agentTabsCmp?.fetchOriginalData();
190+
const data = agentTabsCmp?.fetchOriginalTabData();
164191
return data ? {
165192
utilities: data.utilities || [],
166193
knowledge_bases: data.knwoledgebases || [],
167194
rules: data.rules || []
168195
} : null;
169196
}
197+
170198
function fetchTabData() {
171-
const data = agentTabsCmp?.fetchData();
199+
const data = agentTabsCmp?.fetchTabData();
172200
if (data) {
173201
agent.utilities = data.utilities || [];
174202
agent.knowledge_bases = data.knwoledgebases || [];
175203
agent.rules = data.rules || [];
176204
}
177205
}
178206
179-
function refreshChannelPrompts() {
180-
agentPromptCmp?.refreshChannelPrompts();
181-
}
182207
183208
function deleteCurrentAgent() {
184209
Swal.fire({
@@ -207,7 +232,8 @@
207232
const data = {
208233
...agent,
209234
...formatJsonContent(),
210-
...formatOriginalPrompts(),
235+
...formatOriginalInstructions(),
236+
...formatOriginalTemplates(),
211237
...formatOriginalTabData(),
212238
};
213239
saveAgentDraft(data);
@@ -218,9 +244,10 @@
218244
agentDraft = null;
219245
deleteAgentDraft();
220246
setTimeout(() => {
221-
refreshChannelPrompts();
222-
agentFunctionCmp?.reinit();
223-
agentTabsCmp?.reinit();
247+
refreshInstructions();
248+
refreshTemplates();
249+
agentFunctionCmp?.refresh();
250+
agentTabsCmp?.refresh();
224251
});
225252
}
226253
</script>
@@ -253,8 +280,15 @@
253280
</Col>
254281
<Col class="section-min-width agent-col" style="flex: 60%;">
255282
<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}
258292
agent={agent}
259293
{handleAgentChange}
260294
/>

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
export let agent;
77
88
/** @type {() => void} */
9-
export let handleAgentChange;
9+
export let handleAgentChange = () => {};
1010
1111
export const fetchContent = () => {
1212
return content;
1313
}
1414
15-
export const reinit = () => init();
15+
export const refresh = () => init();
1616
1717
/** @type {import('svelte-jsoneditor').Content} */
1818
let content = {
@@ -27,8 +27,7 @@
2727
content = {
2828
json: {
2929
functions: agent.functions,
30-
responses: agent.responses,
31-
templates: agent.templates
30+
responses: agent.responses
3231
}
3332
};
3433
}

0 commit comments

Comments
 (0)