Skip to content

Commit 69c6766

Browse files
author
Jicheng Lu
committed
temp save
1 parent e31a819 commit 69c6766

File tree

6 files changed

+98
-37
lines changed

6 files changed

+98
-37
lines changed

src/lib/helpers/types/agentTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@
204204
* @property {string} criteria
205205
* @property {string?} [displayName]
206206
* @property {boolean} disabled
207+
* @property {any?} [output_args]
208+
* @property {string?} [json_args]
207209
*/
208210

209211

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@
268268
.markdown-div {
269269
max-height: 500px;
270270
font-size: 15px;
271+
272+
pre {
273+
white-space: pre !important;
274+
margin-top: 1em;
275+
margin-bottom: 1em;
276+
}
271277
}
272278

273279
&.show {

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
<script>
2-
import {
3-
Col,
4-
Row,
5-
Button
6-
} from '@sveltestrap/sveltestrap';
2+
import { onDestroy, onMount } from 'svelte';
3+
import { page } from '$app/stores';
4+
import { goto } from '$app/navigation';
5+
import { _ } from 'svelte-i18n';
6+
import Swal from 'sweetalert2';
7+
import { Col, Row, Button } from '@sveltestrap/sveltestrap';
78
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
89
import HeadTitle from '$lib/common/HeadTitle.svelte';
910
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
10-
import AgentInstruction from './agent-components/agent-instruction.svelte';
11-
import AgentOverview from './agent-components/agent-overview.svelte';
12-
import AgentFunction from './agent-components/agent-function.svelte';
13-
import AgentTabs from './agent-tabs.svelte';
14-
import { page } from '$app/stores';
1511
import { deleteAgent, getAgent, saveAgent } from '$lib/services/agent-service.js';
16-
import { onDestroy, onMount } from 'svelte';
17-
import { _ } from 'svelte-i18n'
18-
import Swal from 'sweetalert2'
19-
import { goto } from '$app/navigation';
2012
import { AgentExtensions } from '$lib/helpers/utils/agent';
21-
import AgentTemplate from './agent-components/agent-template.svelte';
2213
import { globalEventStore } from '$lib/helpers/store';
2314
import { GlobalEvent } from '$lib/helpers/enums';
15+
import { myInfo } from '$lib/services/auth-service';
16+
import AgentInstruction from './agent-components/agent-instruction.svelte';
17+
import AgentOverview from './agent-components/agent-overview.svelte';
18+
import AgentFunction from './agent-components/agent-function.svelte';
19+
import AgentTabs from './agent-tabs.svelte';
20+
import AgentTemplate from './agent-components/agent-template.svelte';
2421
2522
/** @type {import('$agentTypes').AgentModel} */
2623
let agent;
@@ -34,6 +31,8 @@
3431
let agentTabsCmp = null;
3532
/** @type {any} */
3633
let unsubscriber;
34+
/** @type {import('$userTypes').UserModel} */
35+
let user;
3736
3837
/** @type {boolean} */
3938
let isLoading = false;
@@ -42,13 +41,11 @@
4241
const duration = 3000;
4342
const params = $page.params;
4443
45-
onMount(() => {
44+
onMount(async () => {
4645
isLoading = true;
47-
getAgent(params.agentId).then(data => {
48-
agent = data;
49-
}).finally(() => {
50-
isLoading = false;
51-
});
46+
user = await myInfo();
47+
agent = await getAgent(params.agentId);
48+
isLoading = false;
5249
5350
unsubscriber = globalEventStore.subscribe((/** @type {import('$commonTypes').GlobalEvent} */ event) => {
5451
if (event.name !== GlobalEvent.Search) return;
@@ -203,6 +200,7 @@
203200
<AgentTabs
204201
bind:this={agentTabsCmp}
205202
agent={agent}
203+
user={user}
206204
/>
207205
</div>
208206
</Col>

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

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
import { onMount } from 'svelte';
33
import { Card, CardBody, Input, Button } from '@sveltestrap/sveltestrap';
44
import { getAgentRuleOptions } from '$lib/services/agent-service';
5+
import Markdown from '$lib/common/markdown/Markdown.svelte';
6+
import BotsharpTooltip from '$lib/common/tooltip/BotsharpTooltip.svelte';
7+
import { ADMIN_ROLES } from '$lib/helpers/constants';
58
69
const limit = 100;
7-
const textLimit = 200;
10+
const textLimit = 1024;
811
912
/** @type {import('$agentTypes').AgentModel} */
1013
export let agent;
1114
15+
/** @type {import('$userTypes').UserModel} */
16+
export let user;
17+
1218
/** @type {() => void} */
1319
export let handleAgentChange = () => {};
1420
@@ -49,22 +55,23 @@
4955
const list = data?.map(x => {
5056
return {
5157
name: x.trigger_name,
52-
displayName: ""
58+
displayName: "",
59+
json_args: x.json_args
5360
};
5461
}) || [];
5562
ruleOptions = [{
5663
name: "",
5764
displayName: ""
5865
}, ...list];
66+
init();
5967
});
60-
init();
6168
});
6269
6370
function init() {
6471
const list = agent.rules?.map(x => {
6572
return {
6673
...x,
67-
displayName: "",
74+
displayName: ""
6875
};
6976
}) || [];
7077
innerRefresh(list);
@@ -138,11 +145,14 @@
138145
/** @param {import('$agentTypes').AgentRule[]} list */
139146
function innerRefresh(list) {
140147
innerRules = list?.map(x => {
148+
const found = ruleOptions.find(y => y.name === x.trigger_name);
141149
return {
142-
trigger_name: x.trigger_name,
143-
criteria: x.criteria,
144-
displayName: x.displayName,
145-
disabled: x.disabled
150+
...x,
151+
// json_args: found?.json_args
152+
json_args: `\`\`\`json\n${JSON.stringify({
153+
test: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the mo',
154+
name: 'The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Mal'
155+
}, null, 2)}\n\`\`\``
146156
}
147157
}) || [];
148158
}
@@ -220,19 +230,61 @@
220230
<div class="utility-content">
221231
<div class="utility-list-item">
222232
<div class="utility-label line-align-center">
223-
{'Criteria'}
233+
<div class="d-flex gap-1">
234+
<div class="line-align-center">
235+
{'Criteria'}
236+
</div>
237+
{#if ADMIN_ROLES.includes(user?.role || '') && !!rule.trigger_name}
238+
<div
239+
class="line-align-center clickable text-primary fs-4"
240+
data-bs-toggle="tooltip"
241+
data-bs-placement="top"
242+
title="Compile"
243+
>
244+
<i class="mdi mdi-file-code" />
245+
</div>
246+
{/if}
247+
</div>
224248
</div>
225249
<div class="utility-value">
226250
<div class="utility-input line-align-center">
227251
<Input
228-
type="text"
252+
type="textarea"
253+
style="resize: none;"
254+
rows={5}
229255
disabled={rule.disabled}
230256
maxlength={textLimit}
231257
value={rule.criteria}
232258
on:input={e => changeContent(e, uid, 'criteria')}
233259
/>
234260
</div>
235-
<div class="utility-delete line-align-center"></div>
261+
<div class="utility-delete line-align-center">
262+
{#if rule.json_args}
263+
<div class="line-align-center">
264+
<i
265+
class="bx bx-info-circle"
266+
style="font-size: 15px;"
267+
id={`rule-${uid}`}
268+
/>
269+
<BotsharpTooltip
270+
isOpen
271+
containerClasses="agent-utility-desc"
272+
style={`min-width: 100px;`}
273+
target={`rule-${uid}`}
274+
placement="right"
275+
persist={false}
276+
>
277+
<Markdown
278+
rawText
279+
scrollable
280+
containerClasses={'markdown-div'}
281+
containerStyles={`max-width: 500px; max-height: 100px;`}
282+
text={rule.json_args}
283+
/>
284+
</BotsharpTooltip>
285+
</div>
286+
{/if}
287+
</div>
236288
</div>
237289
</div>
238290
</div>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { getAgentUtilityOptions } from '$lib/services/agent-service';
55
import { truncateByPrefix } from '$lib/helpers/utils/common';
66
import Markdown from '$lib/common/markdown/Markdown.svelte';
7-
import BotSharpTooltip from '$lib/common/tooltip/BotSharpTooltip.svelte';
7+
import BotsharpTooltip from '$lib/common/tooltip/BotsharpTooltip.svelte';
88
99
const limit = 100;
1010
const prefix = "util-";
@@ -446,7 +446,7 @@
446446
style="font-size: 15px;"
447447
id={`utility-${uid}-${fid}`}
448448
/>
449-
<BotSharpTooltip
449+
<BotsharpTooltip
450450
containerClasses="agent-utility-desc"
451451
style={`min-width: ${Math.floor(windowWidth*0.3)}px;`}
452452
target={`utility-${uid}-${fid}`}
@@ -460,7 +460,7 @@
460460
containerStyles={`max-width: ${Math.floor(windowWidth*0.55)}px;`}
461461
text={description}
462462
/>
463-
</BotSharpTooltip>
463+
</BotsharpTooltip>
464464
</div>
465465
{/if}
466466
</div>

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
/** @type {import('$agentTypes').AgentModel} */
1414
export let agent;
1515
16+
/** @type {import('$userTypes').UserModel} */
17+
export let user;
18+
1619
/** @type {() => void} */
1720
export let handleAgentChange = () => {};
1821
@@ -57,7 +60,7 @@
5760
];
5861
5962
onMount(() => {
60-
selectedTab = tabs[0]?.name;
63+
selectedTab = tabs[4]?.name;
6164
});
6265
6366
/** @param {string} selected */
@@ -99,7 +102,7 @@
99102
<AgentKnowledgeBase agent={agent} bind:this={agentKnowledgeBaseCmp} {handleAgentChange} />
100103
</div>
101104
<div class:hide={selectedTab !== 'agent-event-rule'}>
102-
<AgentEventRule agent={agent} bind:this={agentEventRuleCmp} {handleAgentChange} />
105+
<AgentEventRule agent={agent} user={user} bind:this={agentEventRuleCmp} {handleAgentChange} />
103106
</div>
104107
<div class:hide={selectedTab !== 'agent-mcp-tool'}>
105108
<AgentMcpTool agent={agent} bind:this={agentMcpToolCmp} {handleAgentChange} />

0 commit comments

Comments
 (0)