|
2 | 2 | import { onMount } from 'svelte'; |
3 | 3 | import { Card, CardBody, Input, Button } from '@sveltestrap/sveltestrap'; |
4 | 4 | import { getAgentUtilityOptions } from '$lib/services/agent-service'; |
| 5 | + import { truncateByPrefix } from '$lib/helpers/utils/common'; |
5 | 6 |
|
6 | 7 | const limit = 5; |
7 | | - const maxLength = 30; |
| 8 | + const prefix = "util-"; |
8 | 9 |
|
9 | 10 | /** @type {import('$agentTypes').AgentModel} */ |
10 | 11 | export let agent; |
|
60 | 61 | getAgentUtilityOptions().then(data => { |
61 | 62 | const list = data || []; |
62 | 63 | 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 | + }); |
65 | 76 |
|
66 | 77 | if (!utilityMapper[item.name]) { |
67 | 78 | 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] |
70 | 87 | }; |
71 | 88 | } else { |
72 | 89 | const prevFns = utilityMapper[item.name].functions; |
|
82 | 99 | }); |
83 | 100 |
|
84 | 101 | 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); |
86 | 116 | } |
87 | 117 |
|
88 | 118 | /** |
|
97 | 127 | found.name = name; |
98 | 128 | found.functions = [ |
99 | 129 | // @ts-ignore |
100 | | - ...utilityMapper[name].functions?.filter(x => !!x)?.map(x => ({ name: x })) || [] |
| 130 | + ...utilityMapper[name].functions?.filter(x => !!x.name) || [] |
101 | 131 | ]; |
102 | 132 | found.templates = [ |
103 | 133 | // @ts-ignore |
104 | | - ...utilityMapper[name].templates?.filter(x => !!x)?.map(x => ({ name: x })) || [] |
| 134 | + ...utilityMapper[name].templates?.filter(x => !!x.name) || [] |
105 | 135 | ]; |
106 | 136 | refresh(innerUtilities); |
107 | 137 | } |
|
132 | 162 | if (!found || found.disabled) return; |
133 | 163 |
|
134 | 164 | if (type === 'function') { |
135 | | - found.functions.push({ name: '' }); |
| 165 | + found.functions.push({ name: '', displayName: '' }); |
136 | 166 | } else if (type === 'template') { |
137 | | - found.templates.push({ name: '' }); |
| 167 | + found.templates.push({ name: '', displayName: '' }); |
138 | 168 | } |
139 | 169 |
|
140 | 170 | refresh(innerUtilities); |
|
171 | 201 | const found = innerUtilities.find((_, index) => index === uid); |
172 | 202 | if (!found) return; |
173 | 203 |
|
| 204 | + const vals = e.target.value.split("#"); |
174 | 205 | if (type === 'function') { |
175 | 206 | const fn = found.functions?.find((_, index) => index === idx); |
176 | 207 | if (fn) { |
177 | | - fn.name = e.target.value; |
| 208 | + fn.name = vals[0]; |
| 209 | + fn.displayName = vals[1]; |
178 | 210 | } |
179 | 211 | } else if (type === 'template') { |
180 | 212 | const tp = found.templates?.find((_, index) => index === idx); |
181 | 213 | if (tp) { |
182 | | - tp.name = e.target.value; |
| 214 | + tp.name = vals[0]; |
| 215 | + tp.displayName = vals[1]; |
183 | 216 | } |
184 | 217 | } |
185 | 218 | refresh(innerUtilities); |
|
305 | 338 | <div class="utility-input line-align-center"> |
306 | 339 | <Input |
307 | 340 | type="select" |
308 | | - value={fn.name} |
309 | 341 | disabled={utility.disabled} |
310 | 342 | on:change={e => selectContent(e, uid, fid, 'function')} |
311 | 343 | > |
312 | 344 | {#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> |
314 | 346 | {/each} |
315 | 347 | </Input> |
316 | 348 | </div> |
|
355 | 387 | <div class="utility-input line-align-center"> |
356 | 388 | <Input |
357 | 389 | type="select" |
358 | | - value={tp.name} |
359 | 390 | disabled={utility.disabled} |
360 | 391 | on:change={e => selectContent(e, uid, tid, 'template')} |
361 | 392 | > |
362 | 393 | {#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> |
364 | 395 | {/each} |
365 | 396 | </Input> |
366 | 397 | </div> |
|
0 commit comments