Agent par défaut
This commit is contained in:
1 parent
cf10b9073b
commit
f74e4d1043
24 files changed
+385
-37
No files matched your search
@@ -6,5 +6,5 @@ export const agentApi = {
|
||||
getAgent: (space: string, id: string) => api.get<Agent>(`/agent/${space}/${id}`),
|
||||
createAgent: (space: string,data: Partial<Agent>) => api.post<Agent>(`/agent/${space}`, data),
|
||||
updateAgent: (space: string,data: Partial<Agent>) => api.put<Agent>(`/agent/${space}`, data),
|
||||
deleteAgent: (space: string,id: string) => api.delete(`/agent/${space}/${id}`),
|
||||
deleteAgent: (space: string, id: string) => api.delete(`/agent/${space}/${id}`),
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { api } from '../client';
|
||||
import type { Team } from "$lib/types/api"
|
||||
|
||||
export const teamApi = {
|
||||
getSpace: (space: string) => api.get<Team>(`/team/${space}`),
|
||||
updateSpace: (space: string,data: Partial<Team>) => api.put<Team>(`/team/${space}`, data),
|
||||
};
|
||||
@@ -1,10 +1,18 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import {uiState} from "$lib/state/ui.svelte"
|
||||
let {label='', icon='', link=''} = $props();
|
||||
|
||||
const closeDrawer = (e: Event) => {
|
||||
e.preventDefault()
|
||||
uiState.sidebarMobileOpen=false
|
||||
uiState.menuContentVisible=false
|
||||
goto(link)
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="my-2 block">
|
||||
<a class="p-2 w-full text-left menuitem block" href={link}>
|
||||
<a class="p-2 w-full text-left menuitem block" href={link} onclick={closeDrawer}>
|
||||
<i class={[icon]}></i>
|
||||
{#if uiState.menuContentVisible}
|
||||
<span class="ml-4">{label}</span>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
<div id="menu" class="flex-1 overflow-y-scroll">
|
||||
<Menu label="Nouveau chat" icon="icon-plus" link={`/${spaceid}`}/>
|
||||
<Menu label="Nouveau chat" icon="icon-plus" link={`/${spaceid}`} />
|
||||
<Menu label="Conversations" icon="icon-chat" link={`/${spaceid}/history`}/>
|
||||
<Menu label="Planification" icon="icon-tasks" link={`/${spaceid}/tasks`}/>
|
||||
<Menu label="Connaissances" icon="icon-graduation-cap" link={`/${spaceid}/kb`}/>
|
||||
|
||||
@@ -31,7 +31,7 @@ export interface UserTeam {
|
||||
export interface Team {
|
||||
id: string
|
||||
label: string
|
||||
defaultModelId: string
|
||||
defaultAgentId: string
|
||||
_version: string
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
import type { Agent } from '$lib/types/api'
|
||||
import type { PageProps } from './$types';
|
||||
import { agentApi } from "$lib/api/endpoints/agent"
|
||||
import { teamApi } from '$lib/api/endpoints/team';
|
||||
|
||||
//import { validateUrl } from '$lib/utilities/validators'
|
||||
import AgentForm from './AgentForm.svelte'
|
||||
import { untrack } from 'svelte';
|
||||
import { space as spaceState } from "$lib/state/space.svelte"
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
|
||||
let agents = $state(data.agents)
|
||||
let space = $state(untrack(()=>data.space))
|
||||
let agents = $state(untrack(()=>data.agents))
|
||||
let addingAgent = $state(false)
|
||||
let editingAgent = $state(null as string|null)
|
||||
let agentForm = $state({} as Agent)
|
||||
@@ -38,7 +42,7 @@
|
||||
}
|
||||
|
||||
if (errors.size === 0) {
|
||||
agentApi.createAgent(data.space, a)
|
||||
agentApi.createAgent(data.space.id, a)
|
||||
.then((p)=>{
|
||||
agents.push(p)
|
||||
addingAgent= false
|
||||
@@ -61,7 +65,7 @@
|
||||
errors.set("name","Le nom est obligatoire !")
|
||||
}
|
||||
if (errors.size === 0) {
|
||||
agentApi.updateAgent(data.space,a)
|
||||
agentApi.updateAgent(data.space.id,a)
|
||||
.then((p)=>{
|
||||
agents = agents.map((it: Agent)=>{return p.id===it.id ? p : it})
|
||||
editingAgent = null
|
||||
@@ -76,7 +80,7 @@
|
||||
const handleEditAgent = async (id: string) => {
|
||||
errors.clear()
|
||||
if (addingAgent) return
|
||||
agentApi.getAgent(data.space,id)
|
||||
agentApi.getAgent(data.space.id,id)
|
||||
.then((a)=>{
|
||||
agents = agents.filter((it)=>it.id===a.id ? a : it)
|
||||
editingAgent = id
|
||||
@@ -85,13 +89,25 @@
|
||||
}
|
||||
|
||||
const handleDeleteAgent = (id: string) => {
|
||||
agentApi.deleteAgent(data.space,id)
|
||||
agentApi.deleteAgent(data.space.id,id)
|
||||
.then(() => {
|
||||
agents = agents.filter((it: Agent)=>it.id!==id)
|
||||
})
|
||||
.catch((err) => {console.log(err)})
|
||||
}
|
||||
|
||||
const handleDefaultAgent = (agentId: string) => {
|
||||
let updSpace = space
|
||||
updSpace.defaultAgentId = agentId
|
||||
teamApi.updateSpace(updSpace.id, updSpace).then((newdata)=>{
|
||||
console.log(newdata)
|
||||
spaceState.spaces.map((s)=>s.id===spaceState.current?newdata:s)
|
||||
space=newdata
|
||||
}).catch((err)=>{
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
@@ -129,10 +145,13 @@
|
||||
<div class="flex-1">
|
||||
<span>{ agent.name }</span>
|
||||
</div>
|
||||
<button class="bt small mx-1" class:highlight={agent.id===space.defaultAgentId} onclick={()=>handleDefaultAgent(agent.id)} title="Modifier">
|
||||
Agent par défaut
|
||||
</button>
|
||||
<button class="bt small mx-1" onclick={()=>handleEditAgent(agent.id)} title="Modifier">
|
||||
<i class="icon-edit"></i>
|
||||
</button>
|
||||
<button class="bt small mx-1" onclick={()=>handleDeleteAgent(agent.id)} title="Supprimer">
|
||||
<button class="bt small mx-1" onclick={()=>handleDeleteAgent(agent.id)} title="Supprimer">
|
||||
<i class="icon-trash-empty"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { agentApi } from "$lib/api/endpoints/agent"
|
||||
import {providerApi} from "$lib/api/endpoints/provider"
|
||||
import { providerApi } from "$lib/api/endpoints/provider"
|
||||
import { teamApi } from "$lib/api/endpoints/team"
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load: PageLoad = async ({ params }) => {
|
||||
return {
|
||||
title: 'Paramétrage : Agents',
|
||||
back: "../settings",
|
||||
space: params.space,
|
||||
//space: params.space,
|
||||
space: await teamApi.getSpace(params.space),
|
||||
agents: await agentApi.getAgents(params.space),
|
||||
providersModels: await providerApi.getProvidersModels(params.space),
|
||||
};
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
<script lang="ts">
|
||||
|
||||
import { SvelteMap } from 'svelte/reactivity';
|
||||
import { untrack } from 'svelte';
|
||||
|
||||
import type { Provider} from '$lib/types/api'
|
||||
import type { PageProps } from './$types';
|
||||
import { providerApi } from "$lib/api/endpoints/provider"
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
import { validateUrl } from '$lib/utilities/validators'
|
||||
import ProviderForm from './ProviderForm.svelte'
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
|
||||
let providers = $state([] as Provider[])
|
||||
let providers = $state(untrack(()=>data.providers))
|
||||
let addingProvider = $state(false)
|
||||
let editingProvider = $state(null as string|null)
|
||||
let providerForm = $state({} as Provider)
|
||||
let errors = new SvelteMap<string,string>()
|
||||
|
||||
|
||||
onMount(async ()=>{
|
||||
providers = await providerApi.getProviders(data.space)
|
||||
})
|
||||
|
||||
const enterAddProviderHandler = () => {
|
||||
if (editingProvider) return
|
||||
errors.clear()
|
||||
@@ -121,10 +116,13 @@
|
||||
/>
|
||||
{/key}
|
||||
{:else}
|
||||
<div class="rounded border border-dashed p-2 border-stone-500 cursor-pointer" onclick={enterAddProviderHandler} tabindex="0">
|
||||
<button class="rounded w-full border border-dashed p-2 border-stone-500 cursor-pointer"
|
||||
onclick={enterAddProviderHandler}
|
||||
tabindex="0"
|
||||
>
|
||||
<i class="icon-plus"></i>
|
||||
Ajouter un fournisseur
|
||||
</div>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#each providers as p (p.id) }
|
||||
@@ -144,10 +142,18 @@
|
||||
<span>{ p.name }</span>
|
||||
<span class="text-stone-500">({ p.type })</span>
|
||||
</div>
|
||||
<button class="bt small mx-1" onclick={()=>handleEditProvider(p.id)}>
|
||||
<button
|
||||
class="bt small mx-1"
|
||||
onclick={()=>handleEditProvider(p.id)}
|
||||
aria-label="Modifier"
|
||||
>
|
||||
<i class="icon-edit"></i>
|
||||
</button>
|
||||
<button class="bt small mx-1" onclick={()=>handleDeleteProvider(p.id)}>
|
||||
<button
|
||||
class="bt small mx-1"
|
||||
onclick={()=>handleDeleteProvider(p.id)}
|
||||
aria-label="Supprimer"
|
||||
>
|
||||
<i class="icon-trash-empty"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -7,5 +7,6 @@ export const load: PageLoad = async ({params}) => {
|
||||
back: "../settings",
|
||||
space: params.space,
|
||||
providerTypes: await providerApi.providerTypes(),
|
||||
providers: await providerApi.getProviders(params.space),
|
||||
};
|
||||
}
|
||||
@@ -30,13 +30,13 @@ h2 {
|
||||
}
|
||||
.bt {
|
||||
appearance: button;
|
||||
@apply min-w-40 cursor-pointer rounded bg-stone-300 px-4 py-1 font-bold transition-all duration-300 hover:bg-stone-200 dark:bg-stone-800 dark:hover:bg-stone-700;
|
||||
@apply min-w-40 cursor-pointer rounded bg-stone-300 px-4 py-1 transition-all duration-300 hover:bg-stone-200 dark:bg-stone-800 dark:hover:bg-stone-700;
|
||||
&.small {
|
||||
@apply min-w-0 px-2 py-1;
|
||||
}
|
||||
&.changed,
|
||||
&.saving {
|
||||
@apply bg-sky-300 dark:bg-sky-700;
|
||||
@apply bg-cyan-400 dark:bg-cyan-600;
|
||||
}
|
||||
&.saved {
|
||||
@apply bg-green-300 dark:bg-green-700;
|
||||
@@ -47,6 +47,9 @@ h2 {
|
||||
&.disabled {
|
||||
@apply text-stone-400 hover:bg-stone-200 dark:hover:bg-stone-800;
|
||||
}
|
||||
&.highlight {
|
||||
@apply text-sky-700 dark:text-sky-300;
|
||||
}
|
||||
}
|
||||
.menuitem {
|
||||
@apply text-stone-950 dark:text-stone-300 hover:dark:text-stone-50;
|
||||
|
||||
Reference in new issue
Block a user