n8n-nodes-rooyai 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class RooyaiAgent implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RooyaiAgent = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class RooyaiAgent {
9
+ constructor() {
10
+ this.description = {
11
+ displayName: 'Rooyai AI Agent',
12
+ name: 'rooyaiAgent',
13
+ icon: 'fa:robot',
14
+ group: ['transform'],
15
+ version: 1,
16
+ description: 'Chat with AI models via OpenRouter',
17
+ defaults: {
18
+ name: 'Rooyai AI Agent',
19
+ },
20
+ inputs: ['main'],
21
+ outputs: ['main'],
22
+ credentials: [
23
+ {
24
+ name: 'rooyaiOpenRouter',
25
+ required: true,
26
+ },
27
+ ],
28
+ properties: [
29
+ {
30
+ displayName: 'Model',
31
+ name: 'model',
32
+ type: 'options',
33
+ options: [
34
+ { name: 'GPT-4o', value: 'openai/gpt-4o' },
35
+ { name: 'GPT-4o Mini', value: 'openai/gpt-4o-mini' },
36
+ { name: 'Claude 3.5 Sonnet', value: 'anthropic/claude-3.5-sonnet' },
37
+ { name: 'Claude 3 Opus', value: 'anthropic/claude-3-opus' },
38
+ { name: 'Gemini Pro 1.5', value: 'google/gemini-pro-1.5' },
39
+ { name: 'Llama 3.1 70B', value: 'meta-llama/llama-3.1-70b-instruct' },
40
+ { name: 'Mistral Large', value: 'mistralai/mistral-large' },
41
+ ],
42
+ default: 'openai/gpt-4o-mini',
43
+ description: 'Select the AI model',
44
+ },
45
+ {
46
+ displayName: 'Messages',
47
+ name: 'messages',
48
+ type: 'fixedCollection',
49
+ typeOptions: {
50
+ multipleValues: true,
51
+ },
52
+ default: {},
53
+ placeholder: 'Add Message',
54
+ options: [
55
+ {
56
+ name: 'messageValues',
57
+ displayName: 'Message',
58
+ values: [
59
+ {
60
+ displayName: 'Role',
61
+ name: 'role',
62
+ type: 'options',
63
+ options: [
64
+ { name: 'User', value: 'user' },
65
+ { name: 'System', value: 'system' },
66
+ { name: 'Assistant', value: 'assistant' },
67
+ ],
68
+ default: 'user',
69
+ },
70
+ {
71
+ displayName: 'Text',
72
+ name: 'text',
73
+ type: 'string',
74
+ typeOptions: {
75
+ rows: 4,
76
+ },
77
+ default: '',
78
+ },
79
+ ],
80
+ },
81
+ ],
82
+ },
83
+ {
84
+ displayName: 'Options',
85
+ name: 'options',
86
+ type: 'collection',
87
+ placeholder: 'Add Option',
88
+ default: {},
89
+ options: [
90
+ {
91
+ displayName: 'Temperature',
92
+ name: 'temperature',
93
+ type: 'number',
94
+ default: 0.7,
95
+ typeOptions: {
96
+ minValue: 0,
97
+ maxValue: 2,
98
+ numberStepSize: 0.1,
99
+ },
100
+ },
101
+ {
102
+ displayName: 'Max Tokens',
103
+ name: 'maxTokens',
104
+ type: 'number',
105
+ default: 2000,
106
+ },
107
+ ],
108
+ },
109
+ {
110
+ displayName: 'Simplify Output',
111
+ name: 'simplifyOutput',
112
+ type: 'boolean',
113
+ default: true,
114
+ },
115
+ ],
116
+ };
117
+ }
118
+ async execute() {
119
+ const items = this.getInputData();
120
+ const returnData = [];
121
+ const credentials = await this.getCredentials('rooyaiOpenRouter');
122
+ for (let i = 0; i < items.length; i++) {
123
+ try {
124
+ const model = this.getNodeParameter('model', i);
125
+ const messagesInput = this.getNodeParameter('messages', i, {});
126
+ const options = this.getNodeParameter('options', i, {});
127
+ const simplifyOutput = this.getNodeParameter('simplifyOutput', i);
128
+ const messages = [];
129
+ if (messagesInput.messageValues && Array.isArray(messagesInput.messageValues)) {
130
+ for (const msg of messagesInput.messageValues) {
131
+ messages.push({
132
+ role: msg.role,
133
+ content: msg.text,
134
+ });
135
+ }
136
+ }
137
+ const response = await axios_1.default.post('https://openrouter.ai/api/v1/chat/completions', {
138
+ model,
139
+ messages,
140
+ temperature: options.temperature || 0.7,
141
+ max_tokens: options.maxTokens || 2000,
142
+ }, {
143
+ headers: {
144
+ 'Authorization': `Bearer ${credentials.apiKey}`,
145
+ 'Content-Type': 'application/json',
146
+ 'HTTP-Referer': 'https://rooyai.com',
147
+ 'X-Title': 'Rooyai AI',
148
+ },
149
+ });
150
+ if (simplifyOutput) {
151
+ returnData.push({
152
+ json: {
153
+ message: response.data.choices[0].message.content,
154
+ model: response.data.model,
155
+ },
156
+ });
157
+ }
158
+ else {
159
+ returnData.push({ json: response.data });
160
+ }
161
+ }
162
+ catch (error) {
163
+ if (this.continueOnFail()) {
164
+ returnData.push({ json: { error: error.message } });
165
+ }
166
+ else {
167
+ throw error;
168
+ }
169
+ }
170
+ }
171
+ return [returnData];
172
+ }
173
+ }
174
+ exports.RooyaiAgent = RooyaiAgent;
@@ -0,0 +1,7 @@
1
+ import { ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class RooyaiOpenRouter implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RooyaiOpenRouter = void 0;
4
+ class RooyaiOpenRouter {
5
+ constructor() {
6
+ this.name = 'rooyaiOpenRouter';
7
+ this.displayName = 'Rooyai OpenRouter API';
8
+ this.documentationUrl = 'https://openrouter.ai/docs';
9
+ this.properties = [
10
+ {
11
+ displayName: 'API Key',
12
+ name: 'apiKey',
13
+ type: 'string',
14
+ typeOptions: { password: true },
15
+ default: '',
16
+ required: true,
17
+ description: 'Your OpenRouter API Key from https://openrouter.ai/keys',
18
+ },
19
+ ];
20
+ }
21
+ }
22
+ exports.RooyaiOpenRouter = RooyaiOpenRouter;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "n8n-nodes-rooyai",
3
+ "version": "1.0.0",
4
+ "description": "Rooyai AI Agent for n8n - OpenRouter Integration",
5
+ "keywords": ["n8n-community-node-package"],
6
+ "license": "MIT",
7
+ "author": "Rooyai",
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "n8n": {
17
+ "credentials": [
18
+ "dist/RooyaiOpenRouter.credentials.js"
19
+ ],
20
+ "nodes": [
21
+ "dist/RooyaiAgent.node.js"
22
+ ]
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^20.0.0",
26
+ "n8n-workflow": "^1.0.0",
27
+ "typescript": "^5.0.0"
28
+ },
29
+ "dependencies": {
30
+ "axios": "^1.6.0"
31
+ }
32
+ }