n8n-nodes-rooyai 1.0.0 → 1.0.1

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.
@@ -14,17 +14,10 @@ class RooyaiAgent {
14
14
  group: ['transform'],
15
15
  version: 1,
16
16
  description: 'Chat with AI models via OpenRouter',
17
- defaults: {
18
- name: 'Rooyai AI Agent',
19
- },
17
+ defaults: { name: 'Rooyai AI Agent' },
20
18
  inputs: ['main'],
21
19
  outputs: ['main'],
22
- credentials: [
23
- {
24
- name: 'rooyaiOpenRouter',
25
- required: true,
26
- },
27
- ],
20
+ credentials: [{ name: 'rooyaiOpenRouter', required: true }],
28
21
  properties: [
29
22
  {
30
23
  displayName: 'Model',
@@ -34,25 +27,20 @@ class RooyaiAgent {
34
27
  { name: 'GPT-4o', value: 'openai/gpt-4o' },
35
28
  { name: 'GPT-4o Mini', value: 'openai/gpt-4o-mini' },
36
29
  { name: 'Claude 3.5 Sonnet', value: 'anthropic/claude-3.5-sonnet' },
37
- { name: 'Claude 3 Opus', value: 'anthropic/claude-3-opus' },
38
30
  { name: 'Gemini Pro 1.5', value: 'google/gemini-pro-1.5' },
39
31
  { name: 'Llama 3.1 70B', value: 'meta-llama/llama-3.1-70b-instruct' },
40
- { name: 'Mistral Large', value: 'mistralai/mistral-large' },
41
32
  ],
42
33
  default: 'openai/gpt-4o-mini',
43
- description: 'Select the AI model',
34
+ description: 'Select AI model',
44
35
  },
45
36
  {
46
37
  displayName: 'Messages',
47
38
  name: 'messages',
48
39
  type: 'fixedCollection',
49
- typeOptions: {
50
- multipleValues: true,
51
- },
40
+ typeOptions: { multipleValues: true },
52
41
  default: {},
53
42
  placeholder: 'Add Message',
54
- options: [
55
- {
43
+ options: [{
56
44
  name: 'messageValues',
57
45
  displayName: 'Message',
58
46
  values: [
@@ -71,14 +59,12 @@ class RooyaiAgent {
71
59
  displayName: 'Text',
72
60
  name: 'text',
73
61
  type: 'string',
74
- typeOptions: {
75
- rows: 4,
76
- },
62
+ typeOptions: { rows: 4 },
77
63
  default: '',
64
+ description: 'Message content',
78
65
  },
79
66
  ],
80
- },
81
- ],
67
+ }],
82
68
  },
83
69
  {
84
70
  displayName: 'Options',
@@ -97,12 +83,14 @@ class RooyaiAgent {
97
83
  maxValue: 2,
98
84
  numberStepSize: 0.1,
99
85
  },
86
+ description: 'Controls randomness (0 = focused, 2 = creative)',
100
87
  },
101
88
  {
102
89
  displayName: 'Max Tokens',
103
90
  name: 'maxTokens',
104
91
  type: 'number',
105
92
  default: 2000,
93
+ description: 'Maximum response length',
106
94
  },
107
95
  ],
108
96
  },
@@ -111,11 +99,13 @@ class RooyaiAgent {
111
99
  name: 'simplifyOutput',
112
100
  type: 'boolean',
113
101
  default: true,
102
+ description: 'Whether to return only the message text',
114
103
  },
115
104
  ],
116
105
  };
117
106
  }
118
107
  async execute() {
108
+ var _a, _b, _c, _d, _e, _f, _g;
119
109
  const items = this.getInputData();
120
110
  const returnData = [];
121
111
  const credentials = await this.getCredentials('rooyaiOpenRouter');
@@ -125,15 +115,17 @@ class RooyaiAgent {
125
115
  const messagesInput = this.getNodeParameter('messages', i, {});
126
116
  const options = this.getNodeParameter('options', i, {});
127
117
  const simplifyOutput = this.getNodeParameter('simplifyOutput', i);
118
+ // Build messages array
128
119
  const messages = [];
129
120
  if (messagesInput.messageValues && Array.isArray(messagesInput.messageValues)) {
130
121
  for (const msg of messagesInput.messageValues) {
131
122
  messages.push({
132
123
  role: msg.role,
133
- content: msg.text,
124
+ content: msg.text
134
125
  });
135
126
  }
136
127
  }
128
+ // Call OpenRouter API
137
129
  const response = await axios_1.default.post('https://openrouter.ai/api/v1/chat/completions', {
138
130
  model,
139
131
  messages,
@@ -144,15 +136,16 @@ class RooyaiAgent {
144
136
  'Authorization': `Bearer ${credentials.apiKey}`,
145
137
  'Content-Type': 'application/json',
146
138
  'HTTP-Referer': 'https://rooyai.com',
147
- 'X-Title': 'Rooyai AI',
139
+ 'X-Title': 'Rooyai AI Agent',
148
140
  },
149
141
  });
142
+ // Return response
150
143
  if (simplifyOutput) {
151
144
  returnData.push({
152
145
  json: {
153
146
  message: response.data.choices[0].message.content,
154
147
  model: response.data.model,
155
- },
148
+ }
156
149
  });
157
150
  }
158
151
  else {
@@ -160,11 +153,32 @@ class RooyaiAgent {
160
153
  }
161
154
  }
162
155
  catch (error) {
156
+ // Enhanced error handling
157
+ 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;
158
+ const errorStatus = (_d = error.response) === null || _d === void 0 ? void 0 : _d.status;
159
+ 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;
160
+ let hint = '';
161
+ if (errorStatus === 401) {
162
+ hint = 'Invalid API Key. Check your OpenRouter credential at https://openrouter.ai/keys';
163
+ }
164
+ else if (errorStatus === 429) {
165
+ hint = 'Rate limit exceeded. Wait a moment and try again.';
166
+ }
167
+ else if (errorStatus === 402) {
168
+ hint = 'Insufficient credits. Add credits at https://openrouter.ai/credits';
169
+ }
163
170
  if (this.continueOnFail()) {
164
- returnData.push({ json: { error: error.message } });
171
+ returnData.push({
172
+ json: {
173
+ error: errorMsg,
174
+ status: errorStatus,
175
+ code: errorCode,
176
+ hint: hint || 'Unknown error'
177
+ }
178
+ });
165
179
  }
166
180
  else {
167
- throw error;
181
+ throw new Error(`OpenRouter API Error (${errorStatus}): ${errorMsg}. ${hint}`);
168
182
  }
169
183
  }
170
184
  }
@@ -14,7 +14,6 @@ class RooyaiOpenRouter {
14
14
  typeOptions: { password: true },
15
15
  default: '',
16
16
  required: true,
17
- description: 'Your OpenRouter API Key from https://openrouter.ai/keys',
18
17
  },
19
18
  ];
20
19
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
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"],
3
+ "version": "1.0.1",
4
+ "description": "Rooyai AI Agent for n8n",
5
+ "keywords": [
6
+ "n8n-community-node-package"
7
+ ],
6
8
  "license": "MIT",
7
- "author": "Rooyai",
8
9
  "main": "index.js",
9
10
  "scripts": {
10
- "build": "tsc",
11
- "prepublishOnly": "npm run build"
11
+ "build": "tsc"
12
12
  },
13
13
  "files": [
14
14
  "dist"
@@ -22,7 +22,6 @@
22
22
  ]
23
23
  },
24
24
  "devDependencies": {
25
- "@types/node": "^20.0.0",
26
25
  "n8n-workflow": "^1.0.0",
27
26
  "typescript": "^5.0.0"
28
27
  },
@@ -1,5 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }