Merge pull request #1503 from automatisch/feature/helix-app

feat: Implement Helix app with new chat action
This commit is contained in:
Ömer Faruk Aydın
2024-01-02 21:20:50 +01:00
committed by GitHub
10 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import newChat from './new-chat';
export default [newChat];

View File

@@ -0,0 +1,50 @@
import FormData from 'form-data';
import defineAction from '../../../../helpers/define-action';
export default defineAction({
name: 'New chat',
key: 'newChat',
description: 'Create a new chat session for Helix AI.',
arguments: [
{
label: 'Input',
key: 'input',
type: 'string' as const,
required: true,
description: 'Prompt to start the chat with.',
variables: true,
},
],
async run($) {
const formData = new FormData();
formData.append('input', $.step.parameters.input as string);
formData.append('mode', 'inference');
formData.append('type', 'text');
const sessionResponse = await $.http.post('/api/v1/sessions', formData, {
headers: {
...formData.getHeaders(),
},
});
const sessionId = sessionResponse.data.id;
let chatGenerated = false;
while (!chatGenerated) {
const response = await $.http.get(`/api/v1/sessions/${sessionId}`);
const message =
response.data.interactions[response.data.interactions.length - 1];
if (message.creator === 'system' && message.state === 'complete') {
$.setActionItem({
raw: message,
});
chatGenerated = true;
}
}
},
});

View File

@@ -0,0 +1,6 @@
<svg role="img" viewBox="0 0 47 68" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M15.9268 3.41382L15.7675 21.2642L15.5102 52.1134V58.1779C15.4898 58.7861 15.631 59.3888 15.9194 59.9247C16.2078 60.4606 16.6331 60.9105 17.1519 61.2285L24.1843 65.296L25.6299 66.1291C27.7314 67.3481 30.1162 67.9938 32.5456 68.0014C34.975 68.009 37.3638 67.3783 39.4729 66.1724C41.5819 64.9666 43.3372 63.2278 44.563 61.1303C45.7888 59.0328 46.442 56.65 46.4574 54.2206L46.7147 23.3837V17.258C46.7207 16.6458 46.564 16.0429 46.2604 15.5112C45.9569 14.9795 45.5175 14.538 44.9873 14.2319L39.7559 11.218L36.5337 9.36804L21.0602 0.436718C20.5374 0.146102 19.9481 -0.00382494 19.3501 0.00160738C18.752 0.0070397 18.1655 0.167645 17.6482 0.467709C17.1308 0.767772 16.7001 1.19701 16.3984 1.71343C16.0967 2.22985 15.9342 2.81576 15.9268 3.41382Z" fill="#16C3E4" fill-opacity="0.8"></path>
<g style="mix-blend-mode:hard-light">
<path d="M31.3986 35.0108L31.1636 63.0174C31.1434 63.6524 30.9604 64.2716 30.6322 64.8156C30.304 65.3596 29.8415 65.8101 29.2892 66.1241C28.7368 66.4381 28.1131 66.605 27.4777 66.6088C26.8423 66.6126 26.2166 66.4532 25.6605 66.1458L1.80552 52.1981C1.25401 51.8682 0.797643 51.4008 0.481139 50.8416C0.164634 50.2823 -0.00115693 49.6505 6.0768e-06 49.0079L0.23497 21.1867C0.25531 20.5542 0.437144 19.9374 0.763178 19.395C1.08921 18.8526 1.5486 18.4026 2.09766 18.0879C2.64672 17.7731 3.26719 17.604 3.90005 17.5967C4.53292 17.5894 5.15714 17.744 5.71334 18.046L29.5684 31.8082C30.1263 32.1361 30.5887 32.6041 30.9098 33.1659C31.2309 33.7277 31.3994 34.3637 31.3986 35.0108Z" fill="#C43BBB"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -0,0 +1,45 @@
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
export default {
fields: [
{
key: 'screenName',
label: 'Screen Name',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'Screen name of your connection to be used on Automatisch UI.',
clickToCopy: false,
},
{
key: 'instanceUrl',
label: 'Helix instance URL',
type: 'string' as const,
required: false,
readOnly: false,
value: 'https://app.tryhelix.ai',
placeholder: 'https://app.tryhelix.ai',
description:
'Your Helix instance URL. Default is https://app.tryhelix.ai.',
clickToCopy: true,
},
{
key: 'apiKey',
label: 'API Key',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'Helix API Key of your account.',
clickToCopy: false,
},
],
verifyCredentials,
isStillVerified,
};

View File

@@ -0,0 +1,9 @@
import { IGlobalVariable } from '@automatisch/types';
import verifyCredentials from './verify-credentials';
const isStillVerified = async ($: IGlobalVariable) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -0,0 +1,11 @@
import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => {
await $.http.get('/api/v1/sessions');
await $.auth.set({
screenName: $.auth.data.screenName,
});
};
export default verifyCredentials;

View File

@@ -0,0 +1,12 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
if ($.auth.data?.apiKey) {
const authorizationHeader = `Bearer ${$.auth.data.apiKey}`;
requestConfig.headers.Authorization = authorizationHeader;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -0,0 +1,13 @@
import { TBeforeRequest } from '@automatisch/types';
const setBaseUrl: TBeforeRequest = ($, requestConfig) => {
if ($.auth.data.instanceUrl) {
requestConfig.baseURL = $.auth.data.instanceUrl as string;
} else if ($.app.apiBaseUrl) {
requestConfig.baseURL = $.app.apiBaseUrl as string;
}
return requestConfig;
};
export default setBaseUrl;

View File

View File

@@ -0,0 +1,19 @@
import defineApp from '../../helpers/define-app';
import setBaseUrl from './common/set-base-url';
import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import actions from './actions';
export default defineApp({
name: 'Helix',
key: 'helix',
baseUrl: 'https://tryhelix.ai',
apiBaseUrl: 'https://app.tryhelix.ai',
iconUrl: '{BASE_URL}/apps/helix/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/apps/helix/connection',
primaryColor: '000000',
supportsConnections: true,
beforeRequest: [setBaseUrl, addAuthHeader],
auth,
actions,
});