add n8n credential test + migrate to new API endpoint (#2427)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
IAuthenticateGeneric,
|
IAuthenticateGeneric,
|
||||||
|
ICredentialTestRequest,
|
||||||
ICredentialType,
|
ICredentialType,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
@@ -35,4 +36,10 @@ export class SkyvernApi implements ICredentialType {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: '={{$credentials?.baseUrl}}',
|
||||||
|
url: '/api/v1/organizations',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ export class Skyvern implements INodeType {
|
|||||||
request: {
|
request: {
|
||||||
baseURL: '={{$credentials.baseUrl}}',
|
baseURL: '={{$credentials.baseUrl}}',
|
||||||
method: '={{ $value === "dispatch" ? "POST" : "GET" }}' as IHttpRequestMethods,
|
method: '={{ $value === "dispatch" ? "POST" : "GET" }}' as IHttpRequestMethods,
|
||||||
url: '={{"/api/" + ($parameter["taskOptions"]["engine"] ? $parameter["taskOptions"]["engine"] : "v2") + "/tasks"}}',
|
url: '={{"/v1/run/tasks"}}',
|
||||||
},
|
},
|
||||||
send: {
|
send: {
|
||||||
preSend: [
|
preSend: [
|
||||||
@@ -132,46 +132,11 @@ export class Skyvern implements INodeType {
|
|||||||
if (taskOperation === "get") return requestOptions;
|
if (taskOperation === "get") return requestOptions;
|
||||||
|
|
||||||
const taskOptions: IDataObject = this.getNodeParameter('taskOptions') as IDataObject;
|
const taskOptions: IDataObject = this.getNodeParameter('taskOptions') as IDataObject;
|
||||||
if (taskOptions["engine"] !== "v1") return requestOptions;
|
const legacy_engine = taskOptions["engine"] as string | null
|
||||||
|
if (legacy_engine === "v1") {
|
||||||
const credentials = await this.getCredentials('skyvernApi');
|
(requestOptions.body as IDataObject)['engine'] = "skyvern-1.0";
|
||||||
const userPrompt = this.getNodeParameter('userPrompt');
|
}else if (legacy_engine === "v2") {
|
||||||
|
(requestOptions.body as IDataObject)['engine'] = "skyvern-2.0";
|
||||||
// *** capture optional webhook URL ***
|
|
||||||
let webhookUrl: string | undefined;
|
|
||||||
try {
|
|
||||||
webhookUrl = this.getNodeParameter('webhookUrl') as string;
|
|
||||||
} catch (e) {
|
|
||||||
webhookUrl = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const generateBody: IDataObject = {
|
|
||||||
prompt: userPrompt,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await makeRequest(credentials['baseUrl'] + '/api/v1/generate/task', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'x-api-key': credentials['apiKey'],
|
|
||||||
},
|
|
||||||
body: JSON.stringify(generateBody),
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Request to generate Task V1 failed'); // eslint-disable-line
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
requestOptions.body = {
|
|
||||||
url: data.url,
|
|
||||||
navigation_goal: data.navigation_goal,
|
|
||||||
navigation_payload: data.navigation_payload,
|
|
||||||
data_extraction_goal: data.data_extraction_goal,
|
|
||||||
extracted_information_schema: data.extracted_information_schema,
|
|
||||||
} as IDataObject;
|
|
||||||
|
|
||||||
if (webhookUrl) {
|
|
||||||
(requestOptions.body as IDataObject)['webhook_callback_url'] = webhookUrl;
|
|
||||||
}
|
}
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
},
|
},
|
||||||
@@ -196,7 +161,7 @@ export class Skyvern implements INodeType {
|
|||||||
routing: {
|
routing: {
|
||||||
request: {
|
request: {
|
||||||
body: {
|
body: {
|
||||||
user_prompt: '={{$value}}',
|
prompt: '={{$value}}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -222,7 +187,6 @@ export class Skyvern implements INodeType {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// *** New property: optional webhook URL for Task dispatch ***
|
|
||||||
{
|
{
|
||||||
displayName: 'Webhook Callback URL',
|
displayName: 'Webhook Callback URL',
|
||||||
description: 'Optional URL that Skyvern will call when the task finishes',
|
description: 'Optional URL that Skyvern will call when the task finishes',
|
||||||
@@ -239,7 +203,7 @@ export class Skyvern implements INodeType {
|
|||||||
routing: {
|
routing: {
|
||||||
request: {
|
request: {
|
||||||
body: {
|
body: {
|
||||||
webhook_callback_url: '={{$value ? $value : undefined}}',
|
webhook_url: '={{$value ? $value : null}}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -260,7 +224,7 @@ export class Skyvern implements INodeType {
|
|||||||
routing: {
|
routing: {
|
||||||
request: {
|
request: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '={{"/api/" + ($parameter["taskOptions"]["engine"] ? $parameter["taskOptions"]["engine"] : "v2") + "/tasks/" + $value}}',
|
url: '={{"/v1/runs/" + $value}}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -273,10 +237,12 @@ export class Skyvern implements INodeType {
|
|||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Engine',
|
displayName: 'Engine(Deprecated)',
|
||||||
|
description: 'Deprecated: please migrate to use "Engine" option',
|
||||||
name: 'engine',
|
name: 'engine',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
default: 'v2',
|
default: '',
|
||||||
|
required: false,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'TaskV1',
|
name: 'TaskV1',
|
||||||
@@ -286,12 +252,45 @@ export class Skyvern implements INodeType {
|
|||||||
name: 'TaskV2',
|
name: 'TaskV2',
|
||||||
value: 'v2',
|
value: 'v2',
|
||||||
},
|
},
|
||||||
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Engine',
|
||||||
|
name: 'runEngine',
|
||||||
|
type: 'options',
|
||||||
|
default: 'skyvern-2.0',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Skyvern 1.0',
|
||||||
|
value: 'skyvern-1.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Skyvern 2.0',
|
||||||
|
value: 'skyvern-2.0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OpenAI CUA',
|
||||||
|
value: 'openai-cua',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Anthropic CUA',
|
||||||
|
value: 'anthropic-cua',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
routing: {
|
||||||
|
request: {
|
||||||
|
body: {
|
||||||
|
engine: '={{$value}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: ['task'],
|
resource: ['task'],
|
||||||
|
taskOperation: ['dispatch'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -400,7 +399,6 @@ export class Skyvern implements INodeType {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// *** New property: optional webhook URL for Workflow dispatch ***
|
|
||||||
{
|
{
|
||||||
displayName: 'Webhook Callback URL',
|
displayName: 'Webhook Callback URL',
|
||||||
description: 'Optional URL that Skyvern will call when the workflow run finishes',
|
description: 'Optional URL that Skyvern will call when the workflow run finishes',
|
||||||
@@ -417,7 +415,7 @@ export class Skyvern implements INodeType {
|
|||||||
routing: {
|
routing: {
|
||||||
request: {
|
request: {
|
||||||
body: {
|
body: {
|
||||||
webhook_callback_url: '={{$value ? $value : undefined}}',
|
webhook_callback_url: '={{$value ? $value : null}}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "n8n-nodes-skyvern",
|
"name": "n8n-nodes-skyvern",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"description": "Skyvern Node for n8n",
|
"description": "Skyvern Node for n8n",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"n8n-community-node-package"
|
"n8n-community-node-package"
|
||||||
|
|||||||
Reference in New Issue
Block a user