Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import { dustAuth, DustAuthType } from '../..';
import { DUST_BASE_URL } from '../common';
import {
httpClient,
HttpMethod,
HttpRequest,
} from '@activepieces/pieces-common';
import { createClient } from '../common';
import mime from 'mime-types';

export const addFragmentToConversation = createAction({
Expand All @@ -27,33 +22,26 @@ export const addFragmentToConversation = createAction({
}),
},
async run({ auth, propsValue }) {
const client = createClient(auth as DustAuthType);

const mimeType = propsValue.fragmentName
? mime.lookup(propsValue.fragmentName) ||
mime.lookup(propsValue.fragment.filename)
: mime.lookup(propsValue.fragment.filename);
const payload = {
content: propsValue.fragment.data.toString('utf-8'),
title: propsValue.fragmentName || propsValue.fragment.filename,
contentType: mimeType || 'text/plain',
context: null,
url: null,
};

const dustAuth = auth as DustAuthType;
const response = await client.createContentFragment(payload);

const request: HttpRequest = {
method: HttpMethod.POST,
url: `${DUST_BASE_URL[dustAuth.region || 'us']}/${
dustAuth.workspaceId
}/assistant/conversations/${propsValue.conversationId}/content_fragments`,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${auth.apiKey}`,
},
body: JSON.stringify(
{
content: propsValue.fragment.data.toString('utf-8'),
title: propsValue.fragmentName || propsValue.fragment.filename,
contentType: mimeType || 'text/plain',
context: null,
url: null,
},
(key, value) => (typeof value === 'undefined' ? null : value)
),
};
return (await httpClient.sendRequest(request)).body;
if (response.isErr()) {
throw new Error(`API Error: ${response.error.message}`);
}

return response.value;
},
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
httpClient,
HttpMethod,
HttpRequest,
} from '@activepieces/pieces-common';
import { dustAuth, DustAuthType } from '../..';
import {
assistantProp,
DUST_BASE_URL,
createClient,
getConversationContent,
timeoutProp,
timezoneProp,
Expand All @@ -32,36 +27,33 @@ export const replyToConversation = createAction({
timeout: timeoutProp,
},
async run({ auth, propsValue }) {
const dustAuth = auth as DustAuthType;
const request: HttpRequest = {
method: HttpMethod.POST,
url: `${DUST_BASE_URL[dustAuth.region || 'us']}/${
dustAuth.workspaceId
}/assistant/conversations/${propsValue.conversationId}/messages`,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${auth.apiKey}`,
},
body: JSON.stringify(
{
content: propsValue.query,
mentions: [{ configurationId: propsValue.assistant }],
context: {
timezone: propsValue.timezone,
username: propsValue.username,
email: null,
fullName: null,
profilePictureUrl: null,
},
const client = createClient(auth as DustAuthType);

const payload = {
conversationId: propsValue.conversationId,
message: {
content: propsValue.query,
mentions: [{ configurationId: propsValue.assistant }],
context: {
timezone: propsValue.timezone,
username: propsValue.username,
email: null,
fullName: null,
profilePictureUrl: null,
},
(key, value) => (typeof value === 'undefined' ? null : value)
),
},
};
await httpClient.sendRequest(request);

const response = await client.postUserMessage(payload);

if (response.isErr()) {
throw new Error(`API Error: ${response.error.message}`);
}

return await getConversationContent(
propsValue.conversationId,
propsValue.timeout,
dustAuth
auth as DustAuthType
);
},
});
21 changes: 9 additions & 12 deletions packages/pieces/community/dust/src/lib/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Property } from '@activepieces/pieces-framework';
import {
httpClient,
HttpMessageBody,
HttpMethod,
} from '@activepieces/pieces-common';
import { DustAuthType } from '..';
import { DustAPI } from '@dust-tt/client';
Expand Down Expand Up @@ -80,16 +78,15 @@ export async function getConversationContent(
auth: DustAuthType
) {
const getConversation = async (conversationId: string) => {
return httpClient.sendRequest({
method: HttpMethod.GET,
url: `${DUST_BASE_URL[auth.region || 'us']}/${
auth.workspaceId
}/assistant/conversations/${conversationId}`,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${auth.apiKey}`,
},
});
const client = createClient(auth as DustAuthType);

const response = await client.getConversation({ conversationId: conversationId });

if (response.isErr()) {
throw new Error(`API Error: ${response.error.message}`);
}

return response.value;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: getConversation now returns response.value, but the surrounding loop still reads conversation.body (lines 98/108/115/122) and getConversationStatus expects the { conversation: { content } } envelope. The SDK unwraps that, so conversation.body is undefined and status parsing will throw. Please confirm the SDK's return shape and drop the .body / ['conversation'] indirection accordingly.

};

let conversation = await getConversation(conversationId);
Expand Down
Loading