forked from activepieces/activepieces
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
032d19a
commit 29dc36d
Showing
8 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"extends": [ | ||
"../../../../.eslintrc.json" | ||
], | ||
"ignorePatterns": [ | ||
"!**/*" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx", | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {}, | ||
"extends": [ | ||
"plugin:prettier/recommended" | ||
], | ||
"plugins": ["prettier"] | ||
}, | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# pieces-dust | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build pieces-dust` to build the library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-dust", | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "pieces-dust", | ||
"$schema": "../../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/pieces/community/dust/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": [ | ||
"{options.outputPath}" | ||
], | ||
"options": { | ||
"outputPath": "dist/packages/pieces/community/dust", | ||
"tsConfig": "packages/pieces/community/dust/tsconfig.lib.json", | ||
"packageJson": "packages/pieces/community/dust/package.json", | ||
"main": "packages/pieces/community/dust/src/index.ts", | ||
"assets": [ | ||
"packages/pieces/community/dust/*.md" | ||
], | ||
"buildableProjectDepsInPackageJsonType": "dependencies", | ||
"updateBuildableProjectDepsInPackageJson": true | ||
} | ||
}, | ||
"publish": { | ||
"command": "node tools/scripts/publish.mjs pieces-dust {args.ver} {args.tag}", | ||
"dependsOn": [ | ||
"build" | ||
] | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/pieces/community/dust/**/*.ts" | ||
] | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
createPiece, | ||
PieceAuth, | ||
Property, | ||
} from '@activepieces/pieces-framework'; | ||
import { createConversation } from './lib/actions/create-conversation'; | ||
|
||
export const dustAuth = PieceAuth.CustomAuth({ | ||
description: 'Dust authentication requires an API key.', | ||
required: true, | ||
props: { | ||
apiKey: PieceAuth.SecretText({ | ||
displayName: 'API key', | ||
required: true, | ||
}), | ||
workspaceId: Property.ShortText({ | ||
displayName: 'Dust workspace ID', | ||
required: true, | ||
description: "Can be found in any of the workspace's URL", | ||
}), | ||
}, | ||
}); | ||
|
||
export const dust = createPiece({ | ||
displayName: 'Dust', | ||
auth: dustAuth, | ||
minimumSupportedRelease: '0.9.0', | ||
logoUrl: 'https://cdn.activepieces.com/pieces/dust.png', | ||
authors: ['AdamSelene'], | ||
actions: [createConversation], | ||
triggers: [], | ||
}); |
94 changes: 94 additions & 0 deletions
94
packages/pieces/community/dust/src/lib/actions/create-conversation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { dustAuth } from '../..'; | ||
import { | ||
httpClient, | ||
HttpMethod, | ||
HttpRequest, | ||
} from '@activepieces/pieces-common'; | ||
|
||
const DUST_BASE_URL = 'https://dust.tt/api/v1/w'; | ||
export const createConversation = createAction({ | ||
// auth: check https://www.activepieces.com/docs/developers/piece-reference/authentication, | ||
name: 'createConversation', | ||
displayName: 'Create conversation', | ||
description: '', | ||
auth: dustAuth, | ||
props: { | ||
query: Property.LongText({ displayName: 'Query', required: true }), | ||
assistant: Property.ShortText({ displayName: 'Assistant', required: true }), | ||
timeZone: Property.ShortText({ | ||
displayName: 'Time zone', | ||
required: true, | ||
defaultValue: 'Europe/Paris', | ||
}), | ||
username: Property.ShortText({ | ||
displayName: 'Username', | ||
required: true, | ||
}), | ||
fullName: Property.ShortText({ | ||
displayName: 'Full name', | ||
required: false, | ||
}), | ||
profilePictureUrl: Property.ShortText({ | ||
displayName: 'Profile picture URL', | ||
required: false, | ||
}), | ||
}, | ||
async run({ auth, propsValue }) { | ||
const request: HttpRequest = { | ||
method: HttpMethod.POST, | ||
url: `${DUST_BASE_URL}/${auth.workspaceId}/assistant/conversations`, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${auth.apiKey}`, | ||
}, | ||
body: JSON.stringify( | ||
{ | ||
visibility: 'unlisted', | ||
title: null, | ||
message: { | ||
content: propsValue.query, | ||
mentions: [{ configurationId: propsValue.assistant }], | ||
context: { | ||
timezone: 'Europe/Paris', | ||
username: propsValue.username, | ||
email: null, | ||
fullName: propsValue.fullName, | ||
profilePictureUrl: propsValue.profilePictureUrl, | ||
}, | ||
}, | ||
}, | ||
(key, value) => (typeof value === 'undefined' ? null : value) | ||
), | ||
}; | ||
const body = (await httpClient.sendRequest(request)).body; | ||
const conversationId = body['conversation']['sId']; | ||
const getConversation = async (conversationId: string) => { | ||
return httpClient.sendRequest({ | ||
method: HttpMethod.GET, | ||
url: `${DUST_BASE_URL}/${auth.workspaceId}/assistant/conversations/${conversationId}`, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${auth.apiKey}`, | ||
}, | ||
}); | ||
}; | ||
|
||
let conversation = await getConversation(conversationId); | ||
|
||
let retries = 0; | ||
while ( | ||
!['succeeded', 'errored'].includes( | ||
conversation.body['conversation']['content']?.at(-1)?.at(0)?.status | ||
) && | ||
retries < 12 // 2mn | ||
) { | ||
await new Promise((f) => setTimeout(f, 10000)); | ||
|
||
conversation = await getConversation(conversationId); | ||
retries += 1; | ||
} | ||
|
||
return conversation.body; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": "../../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.ts"] | ||
} |