Skip to content

Commit fb3af89

Browse files
authored
Merge pull request #281 from iceljc/features/refine-chat-window
refine utility name
2 parents 2c472dd + 22f588c commit fb3af89

File tree

4 files changed

+67
-18
lines changed

4 files changed

+67
-18
lines changed

src/lib/helpers/types/agentTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
/**
129129
* @typedef {Object} UtilityBase
130130
* @property {string} name
131+
* @property {string?} [displayName]
131132
*/
132133

133134
export default {};

src/lib/helpers/utils/common.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,21 @@ export function formatObject(object) {
5050
} catch {
5151
return object;
5252
}
53+
}
54+
55+
56+
/**
57+
* @param {string?} str
58+
* @param {string?} prefix
59+
*/
60+
export function truncateByPrefix(str, prefix) {
61+
if (!str || !prefix) {
62+
return str;
63+
}
64+
65+
if (!str.startsWith(prefix)) {
66+
return str;
67+
}
68+
69+
return str.replace(prefix, '');
5370
}

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@
17591759
{#if !!lastBotMsg && !isSendingMsg && !isThinking}
17601760
<RichContent
17611761
message={lastBotMsg}
1762-
disabled={isSendingMsg || isThinking}
1762+
disabled={isSendingMsg || isThinking || disableAction}
17631763
onConfirm={(title, payload) => confirmSelectedOption(title, payload)}
17641764
/>
17651765
{/if}
@@ -1843,7 +1843,7 @@
18431843
<div class="chat-util-links">
18441844
{#if !isLite}
18451845
<ChatBigMessage
1846-
disabled={disableAction}
1846+
disabled={isSendingMsg || isThinking || disableAction}
18471847
on:click={() => toggleBigMessageModal()}
18481848
/>
18491849
{/if}

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

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { onMount } from 'svelte';
33
import { Card, CardBody, Input, Button } from '@sveltestrap/sveltestrap';
44
import { getAgentUtilityOptions } from '$lib/services/agent-service';
5+
import { truncateByPrefix } from '$lib/helpers/utils/common';
56
67
const limit = 5;
7-
const maxLength = 30;
8+
const prefix = "util-";
89
910
/** @type {import('$agentTypes').AgentModel} */
1011
export let agent;
@@ -60,13 +61,29 @@
6061
getAgentUtilityOptions().then(data => {
6162
const list = data || [];
6263
list.forEach(item => {
63-
const fns = item.functions.map(f => f.name);
64-
const tps = item.templates.map(t => t.name);
64+
const fns = item.functions.map(f => {
65+
return {
66+
name: f.name,
67+
displayName: truncateByPrefix(f.name, prefix)
68+
};
69+
});
70+
const tps = item.templates.map(t => {
71+
return {
72+
name: t.name,
73+
displayName: truncateByPrefix(t.name, prefix)
74+
};
75+
});
6576
6677
if (!utilityMapper[item.name]) {
6778
utilityMapper[item.name] = {
68-
functions: ["", ...fns],
69-
templates: ["", ...tps]
79+
functions: [{
80+
name: "",
81+
displayName: ""
82+
}, ...fns],
83+
templates: [{
84+
name: "",
85+
displayName: ""
86+
}, ...tps]
7087
};
7188
} else {
7289
const prevFns = utilityMapper[item.name].functions;
@@ -82,7 +99,20 @@
8299
});
83100
84101
function init() {
85-
refresh(agent.utilities);
102+
const list = agent.utilities?.map(x => {
103+
return {
104+
...x,
105+
functions: x.functions?.map(f => ({
106+
...f,
107+
displayName: truncateByPrefix(f.name, prefix)
108+
})) || [],
109+
templates: x.templates?.map(t => ({
110+
...t,
111+
displayName: truncateByPrefix(t.name, prefix)
112+
})) || []
113+
};
114+
}) || [];
115+
refresh(list);
86116
}
87117
88118
/**
@@ -97,11 +127,11 @@
97127
found.name = name;
98128
found.functions = [
99129
// @ts-ignore
100-
...utilityMapper[name].functions?.filter(x => !!x)?.map(x => ({ name: x })) || []
130+
...utilityMapper[name].functions?.filter(x => !!x.name) || []
101131
];
102132
found.templates = [
103133
// @ts-ignore
104-
...utilityMapper[name].templates?.filter(x => !!x)?.map(x => ({ name: x })) || []
134+
...utilityMapper[name].templates?.filter(x => !!x.name) || []
105135
];
106136
refresh(innerUtilities);
107137
}
@@ -132,9 +162,9 @@
132162
if (!found || found.disabled) return;
133163
134164
if (type === 'function') {
135-
found.functions.push({ name: '' });
165+
found.functions.push({ name: '', displayName: '' });
136166
} else if (type === 'template') {
137-
found.templates.push({ name: '' });
167+
found.templates.push({ name: '', displayName: '' });
138168
}
139169
140170
refresh(innerUtilities);
@@ -171,15 +201,18 @@
171201
const found = innerUtilities.find((_, index) => index === uid);
172202
if (!found) return;
173203
204+
const vals = e.target.value.split("#");
174205
if (type === 'function') {
175206
const fn = found.functions?.find((_, index) => index === idx);
176207
if (fn) {
177-
fn.name = e.target.value;
208+
fn.name = vals[0];
209+
fn.displayName = vals[1];
178210
}
179211
} else if (type === 'template') {
180212
const tp = found.templates?.find((_, index) => index === idx);
181213
if (tp) {
182-
tp.name = e.target.value;
214+
tp.name = vals[0];
215+
tp.displayName = vals[1];
183216
}
184217
}
185218
refresh(innerUtilities);
@@ -305,12 +338,11 @@
305338
<div class="utility-input line-align-center">
306339
<Input
307340
type="select"
308-
value={fn.name}
309341
disabled={utility.disabled}
310342
on:change={e => selectContent(e, uid, fid, 'function')}
311343
>
312344
{#each (utilityMapper[utility.name]?.functions || []) as option}
313-
<option value={option} selected={option == fn.name}>{option}</option>
345+
<option value={`${option.name}#${option.dsiplayName}`} selected={option.name == fn.name}>{option.displayName}</option>
314346
{/each}
315347
</Input>
316348
</div>
@@ -355,12 +387,11 @@
355387
<div class="utility-input line-align-center">
356388
<Input
357389
type="select"
358-
value={tp.name}
359390
disabled={utility.disabled}
360391
on:change={e => selectContent(e, uid, tid, 'template')}
361392
>
362393
{#each (utilityMapper[utility.name]?.templates || []) as option}
363-
<option value={option} selected={option == tp.name}>{option}</option>
394+
<option value={`${option.name}#${option.dsiplayName}`} selected={option.name == tp.name}>{option.displayName}</option>
364395
{/each}
365396
</Input>
366397
</div>

0 commit comments

Comments
 (0)