Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/lib/helpers/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ axios.interceptors.response.use(
// If the request was successful, return the response
loaderStore.set(false);
const user = getUserStore();

const isExpired = Date.now() / 1000 > user.expires;
if (isExpired) {
if (isExpired || response?.status === 401) {
redirectToLogin();
return Promise.reject('user token expired!');
}
Expand All @@ -39,7 +38,7 @@ axios.interceptors.response.use(
const user = getUserStore();

const isExpired = Date.now() / 1000 > user.expires;
if (isExpired || (error.response && error.response.status === 401)) {
if (isExpired || error?.response?.status === 401) {
redirectToLogin();
return Promise.reject(error);
} else if (!skipGlobalError(error.config)) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/types/agentTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @property {import('$commonTypes').Pagination} pager - Pagination
* @property {string[]?} [types]
* @property {string[]?} [agentNames]
* @property {string} [similarName]
* @property {string?} [similarName]
* @property {string[]?} [labels]
* @property {boolean} [isPublic]
* @property {boolean} [disabled]
Expand Down
9 changes: 9 additions & 0 deletions src/lib/helpers/types/conversationTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ IRichContent.prototype.elements;
*/
IRichContent.prototype.quick_replies;

/**
* The code rich content.
*
* @name language
* @type {string}
* @instance
*/
IRichContent.prototype.code_script;

/**
* The language of the code rich content.
*
Expand Down
4 changes: 2 additions & 2 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1340,8 +1340,8 @@
e.preventDefault();

let text = message?.rich_content?.message?.text || message?.text || '';
if (message?.rich_content?.rich_type === RichType.ProgramCode) {
text = message?.rich_content?.message?.text;
if (message?.rich_content?.message?.rich_type === RichType.ProgramCode) {
text = message?.rich_content?.message?.code_script || text;
}

navigator.clipboard.writeText(text).then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

function initCode() {
try {
const text = message?.rich_content?.message?.text || message?.text || '';
const text = message?.rich_content?.message?.code_script || message?.rich_content?.message?.text || message?.text || '';
const parsedText = marked.lexer(text);
// @ts-ignore
const codeText = parsedText.filter(x => !!x.text).map(x => x.text).join('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
{#if message?.rich_content?.message?.rich_type === RichType.ProgramCode
&& message?.rich_content?.message?.language === 'javascript'}
<RcJsInterpreter message={message} scrollable />
{:else if message?.rich_content?.message?.rich_type === RichType.ProgramCode}
<Markdown containerClasses={markdownClasses} text={message?.text} rawText />
{:else}
<Markdown containerClasses={markdownClasses} text={text} rawText />
{/if}
Expand Down
23 changes: 18 additions & 5 deletions src/routes/page/agent/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@
pageSize: $page.url.searchParams.get("pageSize")
}, { defaultPageSize: pageSize });

const similarName = $page.url.searchParams.get("similarName")?.trim();

filter = {
...filter,
pager: {
...filter.pager,
page: pageNum,
size: pageSizeNum
}
},
similarName: similarName
};

user = await myInfo();
Expand All @@ -92,7 +95,7 @@
},
types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null,
labels: selectedAgentLabels?.length > 0 ? selectedAgentLabels : null,
similarName: event.payload || null
similarName: event.payload?.trim() || null
};

getPagedAgents();
Expand All @@ -105,7 +108,11 @@

function getPagedAgents() {
isLoading = true;
getAgents(filter, true).then(data => {
const innerFilter = {
...filter,
similarName: filter.similarName ? decodeURIComponent(filter.similarName) : null
};
getAgents(innerFilter, true).then(data => {
agents = data;
}).catch(() => {
agents = { items: [], count: 0 };
Expand Down Expand Up @@ -171,10 +178,16 @@
count: totalItemsCount || 0
};

setUrlQueryParams($page.url, [
const queryParams = [
{ key: 'page', value: `${pager.page}` },
{ key: 'pageSize', value: `${pager.size}` }
], () => goToUrl(`${$page.url.pathname}${$page.url.search}`));
];

if (filter.similarName) {
queryParams.push({ key: 'similarName', value: encodeURIComponent(filter.similarName) });
}

setUrlQueryParams($page.url, queryParams, () => goToUrl(`${$page.url.pathname}${$page.url.search}`));
}

/**
Expand Down
19 changes: 18 additions & 1 deletion src/routes/page/agent/[agentId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import AgentTabs from './agent-tabs.svelte';
import { page } from '$app/stores';
import { deleteAgent, getAgent, saveAgent } from '$lib/services/agent-service.js';
import { onMount } from 'svelte';
import { onDestroy, onMount } from 'svelte';
import { _ } from 'svelte-i18n'
import Swal from 'sweetalert2'
import { goto } from '$app/navigation';
import { AgentExtensions } from '$lib/helpers/utils/agent';
import AgentTemplate from './agent-components/agent-template.svelte';
import { globalEventStore } from '$lib/helpers/store';
import { GlobalEvent } from '$lib/helpers/enums';

/** @type {import('$agentTypes').AgentModel} */
let agent;
Expand All @@ -30,6 +32,8 @@
let agentTemplateCmp = null;
/** @type {any} */
let agentTabsCmp = null;
/** @type {any} */
let unsubscriber;

/** @type {boolean} */
let isLoading = false;
Expand All @@ -45,8 +49,21 @@
}).finally(() => {
isLoading = false;
});

unsubscriber = globalEventStore.subscribe((/** @type {import('$commonTypes').GlobalEvent} */ event) => {
if (event.name !== GlobalEvent.Search) return;

const similarName = event.payload?.trim();
if (similarName) {
window.location.href = `/page/agent?page=${1}&pageSize=${12}&similarName=${encodeURIComponent(similarName)}`;
}
});
});

onDestroy(() => {
unsubscriber?.();
});

function updateCurrentAgent() {
Swal.fire({
title: 'Are you sure?',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
{#if dialog?.rich_content?.message?.rich_type === RichType.ProgramCode
&& dialog?.rich_content?.message?.language === 'javascript'}
<RcJsInterpreter message={dialog} scrollable containerStyles={'color: var(--bs-primary);'} />
{:else if dialog?.rich_content?.message?.rich_type === RichType.ProgramCode}
<Markdown
containerClasses={'dialog-item-text'}
text={dialog?.text}
rawText
/>
{:else}
<Markdown
containerClasses={'dialog-item-text'}
Expand Down