type Dust = {
apiKey: string
workspaceId: string
}
export async function main(
resource: Dust,
params: {
datasource: string
documentId: string
content: string
sourceUrl?: string
tags?: string[]
}
) {
const { datasource, documentId, content, sourceUrl, tags } = params
const endpoint = `https://dust.tt/api/v1/w/${resource.workspaceId}/data_sources/${datasource}/documents/${documentId}`
const body = {
text: content,
source_url: sourceUrl,
tags: tags
}
const response = await fetch(endpoint, {
method: 'POST',
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${resource.apiKey}`
},
body: JSON.stringify(body)
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data.document
}
Submitted by hugo697 652 days ago