n8n-nodes-rooyai 1.0.4 → 1.0.6

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.
@@ -13,7 +13,7 @@ class RooyaiAgent {
13
13
  icon: 'file:rooyai.svg',
14
14
  group: ['transform'],
15
15
  version: 1,
16
- description: 'Chat with AI models via OpenRouter or OpenAI',
16
+ description: 'Chat with AI models via OpenRouter',
17
17
  defaults: { name: 'Rooyai AI Agent' },
18
18
  inputs: ['main'],
19
19
  outputs: ['main'],
@@ -23,10 +23,14 @@ class RooyaiAgent {
23
23
  displayName: 'Model',
24
24
  name: 'model',
25
25
  type: 'options',
26
- typeOptions: {
27
- loadOptionsMethod: 'getModels',
28
- },
29
- default: '',
26
+ options: [
27
+ { name: 'GPT-4o', value: 'openai/gpt-4o' },
28
+ { name: 'GPT-4o Mini', value: 'openai/gpt-4o-mini' },
29
+ { name: 'Claude 3.5 Sonnet', value: 'anthropic/claude-3.5-sonnet' },
30
+ { name: 'Gemini Pro 1.5', value: 'google/gemini-pro-1.5' },
31
+ { name: 'Llama 3.1 70B', value: 'meta-llama/llama-3.1-70b-instruct' },
32
+ ],
33
+ default: 'openai/gpt-4o-mini',
30
34
  description: 'Select AI model',
31
35
  },
32
36
  {
@@ -99,42 +103,12 @@ class RooyaiAgent {
99
103
  },
100
104
  ],
101
105
  };
102
- this.methods = {
103
- loadOptions: {
104
- async getModels() {
105
- const credentials = await this.getCredentials('rooyaiOpenRouter');
106
- const providerType = credentials.providerType;
107
- if (providerType === 'openrouter') {
108
- return [
109
- { name: 'GPT-4o', value: 'openai/gpt-4o' },
110
- { name: 'GPT-4o Mini', value: 'openai/gpt-4o-mini' },
111
- { name: 'Claude 3.5 Sonnet', value: 'anthropic/claude-3.5-sonnet' },
112
- { name: 'Claude 3 Opus', value: 'anthropic/claude-3-opus' },
113
- { name: 'Gemini Pro 1.5', value: 'google/gemini-pro-1.5' },
114
- { name: 'Llama 3.1 70B', value: 'meta-llama/llama-3.1-70b-instruct' },
115
- { name: 'Mistral Large', value: 'mistralai/mistral-large' },
116
- { name: 'DeepSeek V3', value: 'deepseek/deepseek-chat' },
117
- ];
118
- }
119
- else {
120
- return [
121
- { name: 'GPT-4o', value: 'gpt-4o' },
122
- { name: 'GPT-4o Mini', value: 'gpt-4o-mini' },
123
- { name: 'GPT-4 Turbo', value: 'gpt-4-turbo' },
124
- { name: 'GPT-3.5 Turbo', value: 'gpt-3.5-turbo' },
125
- { name: 'GPT-4', value: 'gpt-4' },
126
- ];
127
- }
128
- },
129
- },
130
- };
131
106
  }
132
107
  async execute() {
133
- var _a, _b, _c, _d;
108
+ var _a, _b, _c, _d, _e, _f, _g;
134
109
  const items = this.getInputData();
135
110
  const returnData = [];
136
111
  const credentials = await this.getCredentials('rooyaiOpenRouter');
137
- const providerType = credentials.providerType;
138
112
  for (let i = 0; i < items.length; i++) {
139
113
  try {
140
114
  const model = this.getNodeParameter('model', i);
@@ -144,34 +118,31 @@ class RooyaiAgent {
144
118
  const messages = [];
145
119
  if (messagesInput.messageValues && Array.isArray(messagesInput.messageValues)) {
146
120
  for (const msg of messagesInput.messageValues) {
147
- messages.push({ role: msg.role, content: msg.text });
121
+ messages.push({
122
+ role: msg.role,
123
+ content: msg.text
124
+ });
148
125
  }
149
126
  }
150
- let apiUrl = '';
151
- let headers = {
152
- 'Authorization': `Bearer ${credentials.apiKey}`,
153
- 'Content-Type': 'application/json',
154
- };
155
- if (providerType === 'openrouter') {
156
- apiUrl = 'https://openrouter.ai/api/v1/chat/completions';
157
- headers['HTTP-Referer'] = 'https://rooyai.com';
158
- headers['X-Title'] = 'Rooyai AI Agent';
159
- }
160
- else {
161
- apiUrl = 'https://api.openai.com/v1/chat/completions';
162
- }
163
- const response = await axios_1.default.post(apiUrl, {
127
+ const response = await axios_1.default.post('https://openrouter.ai/api/v1/chat/completions', {
164
128
  model,
165
129
  messages,
166
130
  temperature: options.temperature || 0.7,
167
131
  max_tokens: options.maxTokens || 2000,
168
- }, { headers });
132
+ }, {
133
+ headers: {
134
+ 'Authorization': `Bearer ${credentials.apiKey}`,
135
+ 'Content-Type': 'application/json',
136
+ 'HTTP-Referer': 'https://rooyai.com',
137
+ 'X-Title': 'Rooyai AI Agent',
138
+ },
139
+ });
169
140
  if (simplifyOutput) {
170
141
  returnData.push({
171
142
  json: {
172
143
  message: response.data.choices[0].message.content,
173
144
  model: response.data.model,
174
- },
145
+ }
175
146
  });
176
147
  }
177
148
  else {
@@ -181,27 +152,18 @@ class RooyaiAgent {
181
152
  catch (error) {
182
153
  const errorMsg = ((_c = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) || error.message;
183
154
  const errorStatus = (_d = error.response) === null || _d === void 0 ? void 0 : _d.status;
184
- let hint = '';
185
- if (errorStatus === 401) {
186
- hint = 'Invalid API Key. Check your credential.';
187
- }
188
- else if (errorStatus === 429) {
189
- hint = 'Rate limit exceeded.';
190
- }
191
- else if (errorStatus === 402) {
192
- hint = 'Insufficient credits.';
193
- }
155
+ const errorCode = (_g = (_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.code;
194
156
  if (this.continueOnFail()) {
195
157
  returnData.push({
196
158
  json: {
197
159
  error: errorMsg,
198
160
  status: errorStatus,
199
- hint: hint || 'Unknown error',
200
- },
161
+ code: errorCode
162
+ }
201
163
  });
202
164
  }
203
165
  else {
204
- throw new Error(`API Error (${errorStatus}): ${errorMsg}. ${hint}`);
166
+ throw new Error(`OpenRouter API Error (${errorStatus}): ${errorMsg}`);
205
167
  }
206
168
  }
207
169
  }
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" viewBox="0 0 60 60">
2
+ <defs>
3
+ <linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%">
4
+ <stop offset="0%" style="stop-color:#6B7BD6;stop-opacity:1" />
5
+ <stop offset="100%" style="stop-color:#7B68EE;stop-opacity:1" />
6
+ </linearGradient>
7
+ </defs>
8
+ <circle cx="30" cy="30" r="26" fill="url(#grad)"/>
9
+ <text x="30" y="40" font-family="Arial, sans-serif" font-size="28" font-weight="bold" fill="#FFFFFF" text-anchor="middle">R</text>
10
+ </svg>
package/package.json CHANGED
@@ -1,29 +1,48 @@
1
1
  {
2
2
  "name": "n8n-nodes-rooyai",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Rooyai AI Agent for n8n",
5
5
  "keywords": [
6
6
  "n8n-community-node-package"
7
7
  ],
8
8
  "license": "MIT",
9
- "main": "index.js",
10
- "scripts": {
11
- "build": "tsc"
9
+ "author": {
10
+ "name": "Rooyai",
11
+ "email": "contact@rooyai.com"
12
12
  },
13
- "files": [
14
- "dist"
15
- ],
13
+ "community": {
14
+ "author": "Rooyai"
15
+ },
16
+ "main": "index.js",
16
17
  "n8n": {
17
- "credentials": [
18
- "dist/RooyaiOpenRouter.credentials.js"
19
- ],
18
+ "n8nNodesApiVersion": 1,
20
19
  "nodes": [
21
20
  "dist/RooyaiAgent.node.js"
22
21
  ]
23
22
  },
23
+ "scripts": {
24
+ "build": "tsc --outDir dist && copyfiles -f rooyai.svg dist",
25
+ "dev": "tsc --watch",
26
+ "format": "prettier --write '**/*.ts'",
27
+ "lint": "eslint src --ext .ts",
28
+ "lintfix": "eslint src --ext .ts --fix",
29
+ "prepublishOnly": "npm run build"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
24
34
  "devDependencies": {
25
- "n8n-workflow": "^1.0.0",
26
- "typescript": "^5.0.0"
35
+ "@types/express": "^4.17.6",
36
+ "@types/request-promise-native": "^1.0.17",
37
+ "@typescript-eslint/parser": "^5.45.0",
38
+ "copyfiles": "^2.4.1",
39
+ "eslint": "^8.29.0",
40
+ "eslint-plugin-n8n-nodes-base": "^1.11.0",
41
+ "gulp": "^4.0.2",
42
+ "n8n-core": "^0.141.0",
43
+ "n8n-workflow": "^0.141.0",
44
+ "prettier": "^2.8.0",
45
+ "typescript": "^4.9.3"
27
46
  },
28
47
  "dependencies": {
29
48
  "axios": "^1.6.0"