mirror of
https://github.com/ArthurDanjou/artagents.git
synced 2026-01-24 17:10:26 +01:00
feat: add chat and file management APIs, implement chat loading and saving functionality
- Introduced new API endpoints for chat management including posting and retrieving chat messages. - Implemented file upload and deletion functionalities for chat and other files. - Added utility functions for streaming text and loading chat data. - Created TypeScript types for models and agents used in the application. - Configured TypeScript settings for server and project. - Added favicon and workspace configuration for pnpm.
This commit is contained in:
27
server/api/chats/[...pathname].get.ts
Normal file
27
server/api/chats/[...pathname].get.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { streamToText } from '~~/server/utils/stream'
|
||||
|
||||
export default eventHandler(async (event) => {
|
||||
const { pathname } = getRouterParams(event)
|
||||
|
||||
try {
|
||||
const stream = await hubBlob().serve(event, `chats/${pathname}.json`)
|
||||
|
||||
if (!(stream instanceof ReadableStream)) {
|
||||
throw new Error('Le stream n\'est pas valide')
|
||||
}
|
||||
|
||||
const read = await streamToText(stream)
|
||||
|
||||
try {
|
||||
return JSON.parse(read)
|
||||
}
|
||||
catch (jsonError) {
|
||||
console.error('Erreur lors du parsing JSON:', jsonError)
|
||||
return { error: 'Erreur de format JSON' }
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Erreur lors du traitement du stream:', error)
|
||||
return { error: 'Erreur serveur' }
|
||||
}
|
||||
})
|
||||
18
server/api/chats/index.post.ts
Normal file
18
server/api/chats/index.post.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export default eventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
const file = new File([body.file.content], body.file.name, { type: 'application/json' })
|
||||
|
||||
if (!file || !file.size) {
|
||||
throw createError({ statusCode: 400, message: 'No file provided' })
|
||||
}
|
||||
|
||||
ensureBlob(file, {
|
||||
maxSize: '1MB',
|
||||
types: ['application/jsonml+json', 'application/json']
|
||||
})
|
||||
|
||||
return hubBlob().put(file.name, file, {
|
||||
addRandomSuffix: false,
|
||||
prefix: 'chats'
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user