Skip to content

Commit 67a7b4c

Browse files
author
Jicheng Lu
committed
refine rich content files
1 parent 8d730fb commit 67a7b4c

7 files changed

Lines changed: 126 additions & 116 deletions

File tree

src/routes/chat/[agentId]/[conversationId]/+page.svelte

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
<script>
2-
import Chat from './chat-box.svelte';
3-
import { page } from '$app/stores';
4-
import { onMount } from 'svelte';
2+
import { page } from '$app/state';
53
import { myInfo } from '$lib/services/auth-service.js';
64
import { getAgent } from '$lib/services/agent-service.js';
7-
8-
const params = $page.params;
5+
import Chat from './chat-box.svelte';
96
107
/** @type {import('$agentTypes').AgentModel} */
11-
let agent;
8+
let agent = $state(/** @type {any} */ (undefined));
129
1310
/** @type {import('$userTypes').UserModel} */
14-
let currentUser;
11+
let currentUser = $state(/** @type {any} */ (undefined));
1512
16-
onMount(async () => {
17-
currentUser = await myInfo();
13+
let agentId = $derived(page.params.agentId);
14+
15+
$effect(() => {
16+
if (agentId) {
17+
loadData(agentId);
18+
}
19+
});
1820
19-
// get agent profile
20-
let agentId = params.agentId;
21-
agent = await getAgent(agentId);
22-
});
21+
async function loadData(/** @type {string} */ id) {
22+
currentUser = await myInfo();
23+
agent = await getAgent(id);
24+
}
2325
</script>
2426

2527
{#if currentUser}

src/routes/chat/[agentId]/[conversationId]/rich-content/rc-complex-options.svelte

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
<script>
22
import { getContext, onMount } from "svelte";
33
import { fade } from 'svelte/transition';
4-
import { Card, CardBody } from "@sveltestrap/sveltestrap";
54
import { ElementType } from "$lib/helpers/enums";
6-
7-
/** @type {boolean} */
8-
export let disabled = false;
95
10-
/** @type {any[]} */
11-
export let options = [];
12-
13-
/** @type {(args0: string, args1: string) => any} */
14-
export let onConfirm;
6+
/**
7+
* @type {{
8+
* disabled?: boolean,
9+
* options?: any[],
10+
* onConfirm?: (args0: string, args1: string) => any
11+
* }}
12+
*/
13+
let {
14+
disabled = false,
15+
options = [],
16+
onConfirm
17+
} = $props();
1518
1619
/** @type {any[]} */
17-
let cards = [];
20+
let cards = $state([]);
1821
/** @type {any[]} */
19-
let buttons = [];
22+
let buttons = $state([]);
2023
2124
const duration = 1000;
2225
@@ -52,7 +55,7 @@
5255
};
5356
}) || [];
5457
55-
buttons = options?.filter(op => !!!op.title && !!!op.subtitle)?.flatMap(op => {
58+
buttons = options?.filter(op => !op.title && !op.subtitle)?.flatMap(op => {
5659
// @ts-ignore
5760
return op.buttons?.filter(x => !!x.title)?.map(x => {
5861
return {
@@ -100,8 +103,8 @@
100103
<div class="complex-option-container">
101104
{#each cards as card, idx (idx)}
102105
<div class="card-element" in:fade={{ duration: duration }}>
103-
<Card>
104-
<CardBody class="card-element-body">
106+
<div class="card">
107+
<div class="card-body card-element-body">
105108
{#if !!card.title}
106109
<div class="card-element-title hide-text">{card.title}</div>
107110
{/if}
@@ -124,28 +127,28 @@
124127
<button
125128
class={`btn btn-sm m-1 ${option.is_secondary ? 'btn-outline-secondary': 'btn-outline-primary'}`}
126129
disabled={disabled}
127-
on:click={(e) => handleClickOption(e, option)}
130+
onclick={(e) => handleClickOption(e, option)}
128131
>
129132
<span class={`${option.type === ElementType.Web && option.url ? 'link-option' : ''}`}>{option.title}</span>
130133
</button>
131134
{/each}
132135
</div>
133136
{/if}
134-
</CardBody>
135-
</Card>
137+
</div>
138+
</div>
136139
</div>
137140
{/each}
138141
</div>
139142
{/if}
140143
141144
{#if buttons}
142145
<div class="plain-option-container center-option" style="margin-top: 5px;">
143-
{#each buttons as option, index}
146+
{#each buttons as option, index (index)}
144147
<button
145148
class={`btn btn-sm m-1 ${option.is_secondary ? 'btn-outline-secondary': 'btn-outline-primary'}`}
146149
in:fade={{ duration: duration }}
147150
disabled={disabled}
148-
on:click={(e) => handleClickOption(e, option)}
151+
onclick={(e) => handleClickOption(e, option)}
149152
>
150153
{option.title}
151154
</button>

src/routes/chat/[agentId]/[conversationId]/rich-content/rc-disclaimer.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
2-
/** @type {string} */
3-
export let content;
2+
/** @type {{ content: string }} */
3+
let { content } = $props();
44
</script>
55

66
<div class="msg-disclaimer">

src/routes/chat/[agentId]/[conversationId]/rich-content/rc-js-interpreter.svelte

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
import { v4 as uuidv4 } from 'uuid';
77
import LoadingDots from "$lib/common/spinners/LoadingDots.svelte";
88
9-
/** @type {import('$conversationTypes').ChatResponseModel?} */
10-
export let message;
11-
12-
/** @type {string} */
13-
export let containerClasses = '';
14-
15-
/** @type {string} */
16-
export let containerStyles = '';
17-
18-
/** @type {boolean} */
19-
export let scrollable = false;
9+
/**
10+
* @type {{
11+
* message?: import('$conversationTypes').ChatResponseModel | null,
12+
* containerClasses?: string,
13+
* containerStyles?: string,
14+
* scrollable?: boolean
15+
* }}
16+
*/
17+
let {
18+
message = null,
19+
containerClasses = '',
20+
containerStyles = '',
21+
scrollable = false
22+
} = $props();
2023
2124
const scrollbarId = `js-interpreter-scrollbar-${uuidv4()}`;
2225
const options = {
@@ -32,7 +35,7 @@
3235
};
3336
3437
/** @type {boolean} */
35-
let isLoading = false;
38+
let isLoading = $state(false);
3639
3740
onMount(() => {
3841
if (scrollable) {

src/routes/chat/[agentId]/[conversationId]/rich-content/rc-message.svelte

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
import { RichType } from "$lib/helpers/enums";
44
import RcJsInterpreter from "./rc-js-interpreter.svelte";
55
6-
/** @type {import('$conversationTypes').ChatResponseModel?} */
7-
export let message;
6+
/**
7+
* @type {{
8+
* message?: import('$conversationTypes').ChatResponseModel | null,
9+
* containerClasses?: string,
10+
* containerStyles?: string,
11+
* markdownClasses?: string
12+
* }}
13+
*/
14+
let {
15+
message = null,
16+
containerClasses = '',
17+
containerStyles = '',
18+
markdownClasses = ''
19+
} = $props();
820
9-
/** @type {string} */
10-
export let containerClasses = '';
11-
12-
/** @type {string} */
13-
export let containerStyles = '';
14-
15-
/** @type {string} */
16-
export let markdownClasses = '';
17-
18-
$: text = message?.rich_content?.message?.text || message?.text || '';
21+
let text = $derived(message?.rich_content?.message?.text || message?.text || '');
1922
</script>
2023
2124
{#if text}

src/routes/chat/[agentId]/[conversationId]/rich-content/rc-plain-options.svelte

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
import { getContext, onMount } from "svelte";
33
import { fade } from 'svelte/transition';
44
import SveltePlayer from "svelte-player";
5-
import { Card, CardBody } from "@sveltestrap/sveltestrap";
65
import { ElementType } from "$lib/helpers/enums";
76
import ChatFileUploader from "../chat-util/chat-file-uploader.svelte";
87
9-
/** @type {boolean} */
10-
export let isMultiSelect = false;
11-
12-
/** @type {boolean} */
13-
export let disabled = false;
14-
15-
/** @type {any[]} */
16-
export let options = [];
17-
18-
/** @type {(args0: string, args1: string) => any} */
19-
export let onConfirm = () => {};
20-
21-
/** @type {string} */
22-
export let confirmBtnText = 'Continue';
8+
/**
9+
* @type {{
10+
* isMultiSelect?: boolean,
11+
* disabled?: boolean,
12+
* options?: any[],
13+
* onConfirm?: (args0: string, args1: string) => any,
14+
* confirmBtnText?: string
15+
* }}
16+
*/
17+
let {
18+
isMultiSelect = false,
19+
disabled = false,
20+
options = [],
21+
confirmBtnText = 'Continue',
22+
onConfirm = () => {}
23+
} = $props();
2324
2425
const duration = 1000;
2526
const separator = '|';
@@ -29,15 +30,15 @@
2930
];
3031
3132
/** @type {string[]} */
32-
let titleAnswers = [];
33+
let titleAnswers = $state([]);
3334
/** @type {string[]} */
34-
let payloadAnswers = [];
35+
let payloadAnswers = $state([]);
3536
/** @type {any[]} */
36-
let plainOptions = [];
37+
let plainOptions = $state([]);
3738
/** @type {any[]} */
38-
let videoOptions = [];
39+
let videoOptions = $state([]);
3940
/** @type {any} */
40-
let fileOption;
41+
let fileOption = $state(undefined);
4142
4243
const { autoScrollToBottom } = getContext('chat-window-context');
4344
@@ -87,7 +88,7 @@
8788
op.isClicked = !op.isClicked;
8889
if (op.isClicked) {
8990
titleAnswers = [...titleAnswers, op.title];
90-
if (!!op.payload) {
91+
if (op.payload) {
9192
payloadAnswers = [...payloadAnswers, op.payload];
9293
}
9394
} else {
@@ -131,18 +132,18 @@
131132
132133
{#if videoOptions}
133134
<div class="video-option-container center-option">
134-
{#each videoOptions as video, index}
135+
{#each videoOptions as video}
135136
<div class="video-element-card" in:fade={{ duration: duration }}>
136-
<Card>
137-
<CardBody>
137+
<div class="card">
138+
<div class="card-body">
138139
<div class="video-element-title">
139140
{video.title}
140141
</div>
141142
<div class="video-element-player">
142143
<SveltePlayer url={video.payload} controls />
143144
</div>
144-
</CardBody>
145-
</Card>
145+
</div>
146+
</div>
146147
</div>
147148
{/each}
148149
</div>
@@ -156,7 +157,7 @@
156157
class:active={!!option.isClicked}
157158
disabled={disabled}
158159
in:fade={{ duration: duration }}
159-
on:click={(e) => handleClickOption(e, option, index)}
160+
onclick={(e) => handleClickOption(e, option, index)}
160161
>
161162
<span class={`${option.type === ElementType.Web && option.url ? 'link-option' : ''}`}>
162163
{option.title}
@@ -168,8 +169,8 @@
168169
class="btn btn-outline-success btn-sm m-1"
169170
name="confirm"
170171
in:fade={{ duration: duration }}
171-
disabled={disabled || plainOptions.every(x => !!!x.isClicked)}
172-
on:click={(e) => handleConfirm(e)}
172+
disabled={disabled || plainOptions.every(x => !x.isClicked)}
173+
onclick={(e) => handleConfirm(e)}
173174
>
174175
{confirmBtnText || 'Continue'}
175176
</button>

0 commit comments

Comments
 (0)