Skip to content

Commit 1eab971

Browse files
committed
dust init
1 parent 004872e commit 1eab971

File tree

4 files changed

+150
-6
lines changed

4 files changed

+150
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import dust from "../../dust.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "dust-talk-assistant",
6+
name: "Talk to Assistant",
7+
description: "Send a message to an assistant on Dust and receive an answer. [See the documentation](https://docs.dust.tt/reference/post_api-v1-w-wid-assistant-conversations-cid-messages)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
dust,
12+
content: {
13+
propDefinition: [
14+
dust,
15+
"content",
16+
],
17+
},
18+
assistantId: {
19+
type: "string",
20+
label: "Assistant ID",
21+
description: "The unique identifier of the assistant.",
22+
},
23+
conversationId: {
24+
type: "string",
25+
label: "Conversation ID",
26+
description: "The unique identifier of the conversation.",
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.dust.sendMessageToAssistant({
31+
content: this.content,
32+
assistantId: this.assistantId,
33+
conversationId: this.conversationId,
34+
});
35+
$.export("$summary", "Successfully sent message to assistant");
36+
return response;
37+
},
38+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import dust from "../../dust.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "dust-upload-document",
6+
name: "Upload Document",
7+
description: "Adds a document to a chosen Dust data source or folder. [See the documentation](https://docs.dust.tt/reference/post_api-v1-w-wid-data-sources-name-documents-documentid)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
dust,
12+
document: {
13+
propDefinition: [
14+
dust,
15+
"document",
16+
],
17+
},
18+
destination: {
19+
propDefinition: [
20+
dust,
21+
"destination",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.dust.upsertDocument({
27+
document: this.document,
28+
destination: this.destination,
29+
});
30+
31+
$.export("$summary", `Successfully uploaded document to destination ${this.destination}`);
32+
return response;
33+
},
34+
};

components/dust/dust.app.mjs

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,83 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "dust",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
content: {
8+
type: "string",
9+
label: "Message Content",
10+
description: "The content of the message to be sent to the assistant",
11+
},
12+
document: {
13+
type: "string",
14+
label: "Document",
15+
description: "The content of the document to be uploaded",
16+
},
17+
destination: {
18+
type: "string",
19+
label: "Destination",
20+
description: "The destination data source or folder where the document will be uploaded",
21+
async options() {
22+
const dataSources = await this.listDataSources();
23+
return dataSources.map((dataSource) => ({
24+
label: dataSource.name,
25+
value: dataSource.id,
26+
}));
27+
},
28+
},
29+
},
530
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
31+
_baseUrl() {
32+
return "https://dust.tt/api/v1";
33+
},
34+
async _makeRequest(opts = {}) {
35+
const {
36+
$ = this,
37+
method = "GET",
38+
path = "/",
39+
headers,
40+
...otherOpts
41+
} = opts;
42+
43+
return axios($, {
44+
...otherOpts,
45+
method,
46+
url: this._baseUrl() + path,
47+
headers: {
48+
...headers,
49+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
50+
},
51+
});
52+
},
53+
async listDataSources(opts = {}) {
54+
return this._makeRequest({
55+
path: `/w/${this.$auth.workspace_id}/data_sources`,
56+
...opts,
57+
});
58+
},
59+
async sendMessageToAssistant({
60+
content, assistantId, conversationId,
61+
}) {
62+
return this._makeRequest({
63+
method: "POST",
64+
path: `/w/${this.$auth.workspace_id}/assistant/conversations/${conversationId}/messages`,
65+
data: {
66+
content,
67+
assistantId,
68+
},
69+
});
70+
},
71+
async upsertDocument({
72+
document, destination,
73+
}) {
74+
return this._makeRequest({
75+
method: "POST",
76+
path: `/w/${this.$auth.workspace_id}/data_sources/${destination}/documents/${document.documentId}`,
77+
data: {
78+
text: document,
79+
},
80+
});
981
},
1082
},
11-
};
83+
};

components/dust/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)