n8n-nodes-opencode-ai 0.1.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.
- package/LICENSE +21 -0
- package/README.md +190 -0
- package/dist/assets/opencode.svg +6 -0
- package/dist/credentials/OpenCodeApi.credentials.d.ts +8 -0
- package/dist/credentials/OpenCodeApi.credentials.js +50 -0
- package/dist/credentials/OpenCodeApi.credentials.js.map +1 -0
- package/dist/nodes/OpenCode/OpenCode.node.d.ts +13 -0
- package/dist/nodes/OpenCode/OpenCode.node.js +787 -0
- package/dist/nodes/OpenCode/OpenCode.node.js.map +1 -0
- package/dist/nodes/OpenCode/actions/config/getProviders.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/config/getProviders.js +19 -0
- package/dist/nodes/OpenCode/actions/config/getProviders.js.map +1 -0
- package/dist/nodes/OpenCode/actions/config/index.d.ts +4 -0
- package/dist/nodes/OpenCode/actions/config/index.js +15 -0
- package/dist/nodes/OpenCode/actions/config/index.js.map +1 -0
- package/dist/nodes/OpenCode/actions/index.d.ts +5 -0
- package/dist/nodes/OpenCode/actions/index.js +26 -0
- package/dist/nodes/OpenCode/actions/index.js.map +1 -0
- package/dist/nodes/OpenCode/actions/message/command.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/message/command.js +102 -0
- package/dist/nodes/OpenCode/actions/message/command.js.map +1 -0
- package/dist/nodes/OpenCode/actions/message/getMessage.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/message/getMessage.js +21 -0
- package/dist/nodes/OpenCode/actions/message/getMessage.js.map +1 -0
- package/dist/nodes/OpenCode/actions/message/index.d.ts +9 -0
- package/dist/nodes/OpenCode/actions/message/index.js +35 -0
- package/dist/nodes/OpenCode/actions/message/index.js.map +1 -0
- package/dist/nodes/OpenCode/actions/message/list.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/message/list.js +37 -0
- package/dist/nodes/OpenCode/actions/message/list.js.map +1 -0
- package/dist/nodes/OpenCode/actions/message/send.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/message/send.js +124 -0
- package/dist/nodes/OpenCode/actions/message/send.js.map +1 -0
- package/dist/nodes/OpenCode/actions/message/sendAsync.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/message/sendAsync.js +88 -0
- package/dist/nodes/OpenCode/actions/message/sendAsync.js.map +1 -0
- package/dist/nodes/OpenCode/actions/message/shell.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/message/shell.js +102 -0
- package/dist/nodes/OpenCode/actions/message/shell.js.map +1 -0
- package/dist/nodes/OpenCode/actions/session/abort.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/session/abort.js +24 -0
- package/dist/nodes/OpenCode/actions/session/abort.js.map +1 -0
- package/dist/nodes/OpenCode/actions/session/create.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/session/create.js +21 -0
- package/dist/nodes/OpenCode/actions/session/create.js.map +1 -0
- package/dist/nodes/OpenCode/actions/session/delete.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/session/delete.js +24 -0
- package/dist/nodes/OpenCode/actions/session/delete.js.map +1 -0
- package/dist/nodes/OpenCode/actions/session/get.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/session/get.js +20 -0
- package/dist/nodes/OpenCode/actions/session/get.js.map +1 -0
- package/dist/nodes/OpenCode/actions/session/index.d.ts +9 -0
- package/dist/nodes/OpenCode/actions/session/index.js +35 -0
- package/dist/nodes/OpenCode/actions/session/index.js.map +1 -0
- package/dist/nodes/OpenCode/actions/session/list.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/session/list.js +18 -0
- package/dist/nodes/OpenCode/actions/session/list.js.map +1 -0
- package/dist/nodes/OpenCode/actions/session/status.d.ts +2 -0
- package/dist/nodes/OpenCode/actions/session/status.js +19 -0
- package/dist/nodes/OpenCode/actions/session/status.js.map +1 -0
- package/dist/nodes/OpenCode/helpers/api.d.ts +13 -0
- package/dist/nodes/OpenCode/helpers/api.js +62 -0
- package/dist/nodes/OpenCode/helpers/api.js.map +1 -0
- package/dist/nodes/OpenCode/opencode.svg +6 -0
- package/dist/nodes/OpenCode/types/index.d.ts +100 -0
- package/dist/nodes/OpenCode/types/index.js +3 -0
- package/dist/nodes/OpenCode/types/index.js.map +1 -0
- package/dist/nodes/OpenCodeChatModel/ChatOpenCode.d.ts +57 -0
- package/dist/nodes/OpenCodeChatModel/ChatOpenCode.js +270 -0
- package/dist/nodes/OpenCodeChatModel/ChatOpenCode.js.map +1 -0
- package/dist/nodes/OpenCodeChatModel/OpenCodeChatModel.node.d.ts +11 -0
- package/dist/nodes/OpenCodeChatModel/OpenCodeChatModel.node.js +217 -0
- package/dist/nodes/OpenCodeChatModel/OpenCodeChatModel.node.js.map +1 -0
- package/dist/nodes/OpenCodeChatModel/opencode.svg +6 -0
- package/dist/nodes/OpenCodeTool/OpenCodeTool.node.d.ts +11 -0
- package/dist/nodes/OpenCodeTool/OpenCodeTool.node.js +319 -0
- package/dist/nodes/OpenCodeTool/OpenCodeTool.node.js.map +1 -0
- package/dist/nodes/OpenCodeTool/opencode.svg +6 -0
- package/package.json +67 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatOpenCode = void 0;
|
|
4
|
+
const chat_models_1 = require("@langchain/core/language_models/chat_models");
|
|
5
|
+
const messages_1 = require("@langchain/core/messages");
|
|
6
|
+
class ChatOpenCode extends chat_models_1.BaseChatModel {
|
|
7
|
+
static lc_name() {
|
|
8
|
+
return 'ChatOpenCode';
|
|
9
|
+
}
|
|
10
|
+
constructor(fields) {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
super(fields);
|
|
13
|
+
this.baseUrl = fields.baseUrl;
|
|
14
|
+
this.username = fields.username;
|
|
15
|
+
this.password = fields.password;
|
|
16
|
+
this.sessionId = fields.sessionId;
|
|
17
|
+
this.model = fields.model;
|
|
18
|
+
this.timeout = (_a = fields.timeout) !== null && _a !== void 0 ? _a : 300000;
|
|
19
|
+
this.useTemporarySession = (_b = fields.useTemporarySession) !== null && _b !== void 0 ? _b : false;
|
|
20
|
+
this.tempSessionTitle = (_c = fields.tempSessionTitle) !== null && _c !== void 0 ? _c : 'Temporary Chat Session';
|
|
21
|
+
this.boundTools = fields.boundTools;
|
|
22
|
+
}
|
|
23
|
+
_llmType() {
|
|
24
|
+
return 'opencode';
|
|
25
|
+
}
|
|
26
|
+
getAuthHeader() {
|
|
27
|
+
return 'Basic ' + Buffer.from(`${this.username}:${this.password}`).toString('base64');
|
|
28
|
+
}
|
|
29
|
+
async createSession(title) {
|
|
30
|
+
const response = await fetch(`${this.baseUrl}/session`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
'Authorization': this.getAuthHeader(),
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({ title }),
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(`Failed to create session: ${response.status} ${response.statusText}`);
|
|
40
|
+
}
|
|
41
|
+
const data = await response.json();
|
|
42
|
+
return data.id;
|
|
43
|
+
}
|
|
44
|
+
async deleteSession(sessionId) {
|
|
45
|
+
const response = await fetch(`${this.baseUrl}/session/${sessionId}`, {
|
|
46
|
+
method: 'DELETE',
|
|
47
|
+
headers: {
|
|
48
|
+
'Authorization': this.getAuthHeader(),
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
console.error(`Failed to delete session ${sessionId}: ${response.status} ${response.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Bind tools to the model for function calling support
|
|
57
|
+
*/
|
|
58
|
+
bindTools(tools) {
|
|
59
|
+
const toolDefinitions = tools.map((tool) => {
|
|
60
|
+
// Cast to unknown first for safe type handling
|
|
61
|
+
const toolObj = tool;
|
|
62
|
+
const name = String(toolObj.name || 'unknown');
|
|
63
|
+
const description = String(toolObj.description || '');
|
|
64
|
+
const schema = toolObj.schema;
|
|
65
|
+
return { name, description, schema };
|
|
66
|
+
});
|
|
67
|
+
return new ChatOpenCode({
|
|
68
|
+
baseUrl: this.baseUrl,
|
|
69
|
+
username: this.username,
|
|
70
|
+
password: this.password,
|
|
71
|
+
sessionId: this.sessionId,
|
|
72
|
+
model: this.model,
|
|
73
|
+
timeout: this.timeout,
|
|
74
|
+
useTemporarySession: this.useTemporarySession,
|
|
75
|
+
tempSessionTitle: this.tempSessionTitle,
|
|
76
|
+
boundTools: toolDefinitions,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Format tools as a system prompt for models that don't have native tool support
|
|
81
|
+
*/
|
|
82
|
+
formatToolsAsPrompt(tools) {
|
|
83
|
+
const toolDescriptions = tools.map((tool) => {
|
|
84
|
+
let desc = `- ${tool.name}: ${tool.description}`;
|
|
85
|
+
if (tool.schema) {
|
|
86
|
+
desc += `\n Parameters: ${JSON.stringify(tool.schema, null, 2)}`;
|
|
87
|
+
}
|
|
88
|
+
return desc;
|
|
89
|
+
}).join('\n\n');
|
|
90
|
+
return `You have access to the following tools. To use a tool, respond with a JSON object in the following format:
|
|
91
|
+
{"tool": "tool_name", "args": {"arg1": "value1", "arg2": "value2"}}
|
|
92
|
+
|
|
93
|
+
Available tools:
|
|
94
|
+
${toolDescriptions}
|
|
95
|
+
|
|
96
|
+
If you need to use a tool, respond ONLY with the JSON object. If you don't need to use a tool, respond normally with text.`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parse tool calls from the response text
|
|
100
|
+
*/
|
|
101
|
+
parseToolCalls(responseText) {
|
|
102
|
+
const toolCalls = [];
|
|
103
|
+
// Try to find JSON tool calls in the response
|
|
104
|
+
const jsonPattern = /\{[\s\S]*?"tool"[\s\S]*?:[\s\S]*?"[\w]+"[\s\S]*?,[\s\S]*?"args"[\s\S]*?:[\s\S]*?\{[\s\S]*?\}[\s\S]*?\}/g;
|
|
105
|
+
const matches = responseText.match(jsonPattern);
|
|
106
|
+
if (matches) {
|
|
107
|
+
for (const match of matches) {
|
|
108
|
+
try {
|
|
109
|
+
const parsed = JSON.parse(match);
|
|
110
|
+
if (parsed.tool && typeof parsed.tool === 'string') {
|
|
111
|
+
toolCalls.push({
|
|
112
|
+
name: parsed.tool,
|
|
113
|
+
args: parsed.args || {},
|
|
114
|
+
id: `call_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Not valid JSON, skip
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return toolCalls;
|
|
124
|
+
}
|
|
125
|
+
async _generate(messages, options, _runManager) {
|
|
126
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
127
|
+
let sessionId = this.sessionId;
|
|
128
|
+
let shouldDeleteSession = false;
|
|
129
|
+
// Create temporary session if needed
|
|
130
|
+
if (this.useTemporarySession) {
|
|
131
|
+
sessionId = await this.createSession(this.tempSessionTitle);
|
|
132
|
+
shouldDeleteSession = true;
|
|
133
|
+
}
|
|
134
|
+
if (!sessionId) {
|
|
135
|
+
throw new Error('No session ID provided and temporary session mode is not enabled');
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
// Get tools from bound tools or options
|
|
139
|
+
const tools = this.boundTools || (options === null || options === void 0 ? void 0 : options.tools) || [];
|
|
140
|
+
// Prepare messages with tool prompt if tools are available
|
|
141
|
+
let processedMessages = [...messages];
|
|
142
|
+
if (tools.length > 0) {
|
|
143
|
+
const toolPrompt = this.formatToolsAsPrompt(tools);
|
|
144
|
+
// Add tool prompt as system message at the beginning
|
|
145
|
+
processedMessages = [new messages_1.SystemMessage(toolPrompt), ...messages];
|
|
146
|
+
}
|
|
147
|
+
// Convert messages to text (combine all messages for context)
|
|
148
|
+
const messageTexts = [];
|
|
149
|
+
for (const msg of processedMessages) {
|
|
150
|
+
let prefix = '';
|
|
151
|
+
if (msg._getType() === 'system') {
|
|
152
|
+
prefix = '[System]: ';
|
|
153
|
+
}
|
|
154
|
+
else if (msg._getType() === 'human') {
|
|
155
|
+
prefix = '[User]: ';
|
|
156
|
+
}
|
|
157
|
+
else if (msg._getType() === 'ai') {
|
|
158
|
+
prefix = '[Assistant]: ';
|
|
159
|
+
}
|
|
160
|
+
if (typeof msg.content === 'string') {
|
|
161
|
+
messageTexts.push(prefix + msg.content);
|
|
162
|
+
}
|
|
163
|
+
else if (Array.isArray(msg.content)) {
|
|
164
|
+
const text = msg.content
|
|
165
|
+
.filter((part) => typeof part === 'object' && part.type === 'text')
|
|
166
|
+
.map((part) => part.text)
|
|
167
|
+
.join('\n');
|
|
168
|
+
if (text) {
|
|
169
|
+
messageTexts.push(prefix + text);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const messageText = messageTexts.join('\n\n');
|
|
174
|
+
// Build request payload
|
|
175
|
+
const payload = {
|
|
176
|
+
parts: [{ type: 'text', text: messageText }],
|
|
177
|
+
};
|
|
178
|
+
// Add model if specified
|
|
179
|
+
if (this.model && this.model.includes('::')) {
|
|
180
|
+
const [providerID, modelID] = this.model.split('::');
|
|
181
|
+
payload.model = { providerID, modelID };
|
|
182
|
+
}
|
|
183
|
+
// Make API request
|
|
184
|
+
const controller = new AbortController();
|
|
185
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
186
|
+
try {
|
|
187
|
+
const response = await fetch(`${this.baseUrl}/session/${sessionId}/message`, {
|
|
188
|
+
method: 'POST',
|
|
189
|
+
headers: {
|
|
190
|
+
'Content-Type': 'application/json',
|
|
191
|
+
'Authorization': this.getAuthHeader(),
|
|
192
|
+
},
|
|
193
|
+
body: JSON.stringify(payload),
|
|
194
|
+
signal: controller.signal,
|
|
195
|
+
});
|
|
196
|
+
clearTimeout(timeoutId);
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
throw new Error(`OpenCode API error: ${response.status} ${response.statusText}`);
|
|
199
|
+
}
|
|
200
|
+
const data = await response.json();
|
|
201
|
+
// Extract text response
|
|
202
|
+
const responseText = (data.parts || [])
|
|
203
|
+
.filter((p) => p.type === 'text')
|
|
204
|
+
.map((p) => p.text || '')
|
|
205
|
+
.join('\n')
|
|
206
|
+
.trim();
|
|
207
|
+
// Build token usage info
|
|
208
|
+
const tokenUsage = {
|
|
209
|
+
promptTokens: (_c = (_b = (_a = data.info) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.input) !== null && _c !== void 0 ? _c : 0,
|
|
210
|
+
completionTokens: (_f = (_e = (_d = data.info) === null || _d === void 0 ? void 0 : _d.tokens) === null || _e === void 0 ? void 0 : _e.output) !== null && _f !== void 0 ? _f : 0,
|
|
211
|
+
totalTokens: ((_j = (_h = (_g = data.info) === null || _g === void 0 ? void 0 : _g.tokens) === null || _h === void 0 ? void 0 : _h.input) !== null && _j !== void 0 ? _j : 0) + ((_m = (_l = (_k = data.info) === null || _k === void 0 ? void 0 : _k.tokens) === null || _l === void 0 ? void 0 : _l.output) !== null && _m !== void 0 ? _m : 0),
|
|
212
|
+
};
|
|
213
|
+
// Check for tool calls in the response
|
|
214
|
+
const toolCalls = tools.length > 0 ? this.parseToolCalls(responseText) : [];
|
|
215
|
+
// Create AIMessage with or without tool calls
|
|
216
|
+
let aiMessage;
|
|
217
|
+
if (toolCalls.length > 0) {
|
|
218
|
+
aiMessage = new messages_1.AIMessage({
|
|
219
|
+
content: responseText,
|
|
220
|
+
tool_calls: toolCalls.map(tc => ({
|
|
221
|
+
name: tc.name,
|
|
222
|
+
args: tc.args,
|
|
223
|
+
id: tc.id,
|
|
224
|
+
type: 'tool_call',
|
|
225
|
+
})),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
aiMessage = new messages_1.AIMessage(responseText);
|
|
230
|
+
}
|
|
231
|
+
const generation = {
|
|
232
|
+
text: responseText,
|
|
233
|
+
message: aiMessage,
|
|
234
|
+
generationInfo: {
|
|
235
|
+
messageId: (_o = data.info) === null || _o === void 0 ? void 0 : _o.id,
|
|
236
|
+
modelID: (_p = data.info) === null || _p === void 0 ? void 0 : _p.modelID,
|
|
237
|
+
providerID: (_q = data.info) === null || _q === void 0 ? void 0 : _q.providerID,
|
|
238
|
+
cost: (_r = data.info) === null || _r === void 0 ? void 0 : _r.cost,
|
|
239
|
+
sessionId: sessionId,
|
|
240
|
+
wasTemporarySession: shouldDeleteSession,
|
|
241
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
return {
|
|
245
|
+
generations: [generation],
|
|
246
|
+
llmOutput: {
|
|
247
|
+
tokenUsage,
|
|
248
|
+
modelId: (_s = data.info) === null || _s === void 0 ? void 0 : _s.modelID,
|
|
249
|
+
providerId: (_t = data.info) === null || _t === void 0 ? void 0 : _t.providerID,
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
clearTimeout(timeoutId);
|
|
255
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
256
|
+
throw new Error(`OpenCode API request timeout after ${this.timeout}ms`);
|
|
257
|
+
}
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
// Delete temporary session after use
|
|
263
|
+
if (shouldDeleteSession && sessionId) {
|
|
264
|
+
await this.deleteSession(sessionId);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
exports.ChatOpenCode = ChatOpenCode;
|
|
270
|
+
//# sourceMappingURL=ChatOpenCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatOpenCode.js","sourceRoot":"","sources":["../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CAAsC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;gBACzE,CAAC;gBACD,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,qCAAqC;YACrC,IAAI,mBAAmB,IAAI,SAAS,EAAE,CAAC;gBACtC,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;YACrC,CAAC;QACF,CAAC;IACF,CAAC;CACD;AArTD,oCAqTC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ISupplyDataFunctions, ILoadOptionsFunctions, INodeType, INodeTypeDescription, INodePropertyOptions, SupplyData } from 'n8n-workflow';
|
|
2
|
+
export declare class OpenCodeChatModel implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
methods: {
|
|
5
|
+
loadOptions: {
|
|
6
|
+
getSessions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
7
|
+
getModels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenCodeChatModel = void 0;
|
|
4
|
+
const ChatOpenCode_1 = require("./ChatOpenCode");
|
|
5
|
+
class OpenCodeChatModel {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.description = {
|
|
8
|
+
displayName: 'OpenCode Chat Model',
|
|
9
|
+
name: 'lmChatOpenCode',
|
|
10
|
+
icon: 'file:opencode.svg',
|
|
11
|
+
group: ['transform'],
|
|
12
|
+
version: 1,
|
|
13
|
+
description: 'Use OpenCode as a Chat Model for AI Agents',
|
|
14
|
+
defaults: {
|
|
15
|
+
name: 'OpenCode Chat Model',
|
|
16
|
+
},
|
|
17
|
+
codex: {
|
|
18
|
+
categories: ['AI'],
|
|
19
|
+
subcategories: {
|
|
20
|
+
AI: ['Language Models', 'Root Nodes'],
|
|
21
|
+
'Language Models': ['Chat Models (Recommended)'],
|
|
22
|
+
},
|
|
23
|
+
resources: {
|
|
24
|
+
primaryDocumentation: [
|
|
25
|
+
{
|
|
26
|
+
url: 'https://opencode.ai/docs/server/',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
32
|
+
inputs: [],
|
|
33
|
+
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
34
|
+
outputs: ['ai_languageModel'],
|
|
35
|
+
outputNames: ['Model'],
|
|
36
|
+
credentials: [
|
|
37
|
+
{
|
|
38
|
+
name: 'openCodeApi',
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
properties: [
|
|
43
|
+
{
|
|
44
|
+
displayName: 'Session Mode',
|
|
45
|
+
name: 'sessionMode',
|
|
46
|
+
type: 'options',
|
|
47
|
+
options: [
|
|
48
|
+
{
|
|
49
|
+
name: 'Use Existing Session',
|
|
50
|
+
value: 'existing',
|
|
51
|
+
description: 'Use an existing session for conversations',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'Temporary Session',
|
|
55
|
+
value: 'temporary',
|
|
56
|
+
description: 'Create a new session for each request and delete it after response',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
default: 'existing',
|
|
60
|
+
description: 'Choose how to handle sessions',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
displayName: 'Session',
|
|
64
|
+
name: 'sessionId',
|
|
65
|
+
type: 'options',
|
|
66
|
+
typeOptions: {
|
|
67
|
+
loadOptionsMethod: 'getSessions',
|
|
68
|
+
},
|
|
69
|
+
required: true,
|
|
70
|
+
displayOptions: {
|
|
71
|
+
show: {
|
|
72
|
+
sessionMode: ['existing'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
default: '',
|
|
76
|
+
description: 'Select an OpenCode session to use for the chat model',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
displayName: 'Temporary Session Title',
|
|
80
|
+
name: 'tempSessionTitle',
|
|
81
|
+
type: 'string',
|
|
82
|
+
displayOptions: {
|
|
83
|
+
show: {
|
|
84
|
+
sessionMode: ['temporary'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
default: 'Temporary Chat Session',
|
|
88
|
+
description: 'Title for temporary sessions (for debugging purposes)',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
displayName: 'Model',
|
|
92
|
+
name: 'model',
|
|
93
|
+
type: 'options',
|
|
94
|
+
typeOptions: {
|
|
95
|
+
loadOptionsMethod: 'getModels',
|
|
96
|
+
},
|
|
97
|
+
default: '',
|
|
98
|
+
description: 'Select a model (optional, uses default if not specified)',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
displayName: 'Options',
|
|
102
|
+
name: 'options',
|
|
103
|
+
type: 'collection',
|
|
104
|
+
placeholder: 'Add Option',
|
|
105
|
+
default: {},
|
|
106
|
+
options: [
|
|
107
|
+
{
|
|
108
|
+
displayName: 'Timeout (ms)',
|
|
109
|
+
name: 'timeout',
|
|
110
|
+
type: 'number',
|
|
111
|
+
default: 300000,
|
|
112
|
+
description: 'Request timeout in milliseconds (default: 300000 = 5 minutes)',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
this.methods = {
|
|
119
|
+
loadOptions: {
|
|
120
|
+
async getSessions() {
|
|
121
|
+
try {
|
|
122
|
+
const credentials = await this.getCredentials('openCodeApi');
|
|
123
|
+
const baseUrl = credentials.baseUrl;
|
|
124
|
+
const response = await this.helpers.request({
|
|
125
|
+
method: 'GET',
|
|
126
|
+
url: `${baseUrl}/session`,
|
|
127
|
+
auth: {
|
|
128
|
+
user: credentials.username,
|
|
129
|
+
pass: credentials.password,
|
|
130
|
+
},
|
|
131
|
+
json: true,
|
|
132
|
+
});
|
|
133
|
+
const sessions = (Array.isArray(response) ? response : [response]);
|
|
134
|
+
return sessions.map((session) => ({
|
|
135
|
+
name: session.title || `Session ${session.id.substring(0, 8)}...`,
|
|
136
|
+
value: session.id,
|
|
137
|
+
description: `ID: ${session.id}`,
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error('Error loading sessions:', error);
|
|
142
|
+
return [{ name: 'Error loading sessions', value: '' }];
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
async getModels() {
|
|
146
|
+
try {
|
|
147
|
+
const credentials = await this.getCredentials('openCodeApi');
|
|
148
|
+
const baseUrl = credentials.baseUrl;
|
|
149
|
+
const response = await this.helpers.request({
|
|
150
|
+
method: 'GET',
|
|
151
|
+
url: `${baseUrl}/config/providers`,
|
|
152
|
+
auth: {
|
|
153
|
+
user: credentials.username,
|
|
154
|
+
pass: credentials.password,
|
|
155
|
+
},
|
|
156
|
+
json: true,
|
|
157
|
+
});
|
|
158
|
+
const options = [
|
|
159
|
+
{ name: '(Default)', value: '' },
|
|
160
|
+
];
|
|
161
|
+
const providers = (response.providers || []);
|
|
162
|
+
for (const provider of providers) {
|
|
163
|
+
if (provider.models && typeof provider.models === 'object') {
|
|
164
|
+
const modelList = Object.values(provider.models);
|
|
165
|
+
for (const model of modelList) {
|
|
166
|
+
options.push({
|
|
167
|
+
name: `${provider.name || provider.id}: ${model.name || model.id}`,
|
|
168
|
+
value: `${provider.id}::${model.id}`,
|
|
169
|
+
description: `Provider: ${provider.id}`,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return options;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error('Error loading models:', error);
|
|
178
|
+
return [{ name: '(Default)', value: '' }];
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
async supplyData(itemIndex) {
|
|
185
|
+
var _a;
|
|
186
|
+
const credentials = await this.getCredentials('openCodeApi');
|
|
187
|
+
const sessionMode = this.getNodeParameter('sessionMode', itemIndex);
|
|
188
|
+
const model = this.getNodeParameter('model', itemIndex, '');
|
|
189
|
+
const options = this.getNodeParameter('options', itemIndex, {});
|
|
190
|
+
const timeout = (_a = options.timeout) !== null && _a !== void 0 ? _a : 300000;
|
|
191
|
+
// Determine session configuration based on mode
|
|
192
|
+
const useTemporarySession = sessionMode === 'temporary';
|
|
193
|
+
let sessionId;
|
|
194
|
+
let tempSessionTitle;
|
|
195
|
+
if (useTemporarySession) {
|
|
196
|
+
tempSessionTitle = this.getNodeParameter('tempSessionTitle', itemIndex, 'Temporary Chat Session');
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
sessionId = this.getNodeParameter('sessionId', itemIndex);
|
|
200
|
+
}
|
|
201
|
+
const chatModel = new ChatOpenCode_1.ChatOpenCode({
|
|
202
|
+
baseUrl: credentials.baseUrl,
|
|
203
|
+
username: credentials.username,
|
|
204
|
+
password: credentials.password,
|
|
205
|
+
sessionId,
|
|
206
|
+
model: model || undefined,
|
|
207
|
+
timeout,
|
|
208
|
+
useTemporarySession,
|
|
209
|
+
tempSessionTitle,
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
response: chatModel,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.OpenCodeChatModel = OpenCodeChatModel;
|
|
217
|
+
//# sourceMappingURL=OpenCodeChatModel.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenCodeChatModel.node.js","sourceRoot":"","sources":["../../../src/nodes/OpenCodeChatModel/OpenCodeChatModel.node.ts"],"names":[],"mappings":";;;AASA,iDAA8C;AAmB9C,MAAa,iBAAiB;IAA9B;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AG,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,SAAS,CAAW,CAAC;QAC9E,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAW,CAAC;QACtE,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAgB,CAAC;QAC/E,MAAM,OAAO,GAAG,MAAC,OAAO,CAAC,OAAkB,mCAAI,MAAM,CAAC;QAEtD,gDAAgD;QAChD,MAAM,mBAAmB,GAAG,WAAW,KAAK,WAAW,CAAC;QACxD,IAAI,SAA6B,CAAC;QAClC,IAAI,gBAAoC,CAAC;QAEzC,IAAI,mBAAmB,EAAE,CAAC;YACzB,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,SAAS,EAAE,wBAAwB,CAAW,CAAC;QAC7G,CAAC;aAAM,CAAC;YACP,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,SAAS,CAAW,CAAC;QACrE,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,2BAAY,CAAC;YAClC,OAAO,EAAE,WAAW,CAAC,OAAO;YAC5B,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,SAAS;YACT,KAAK,EAAE,KAAK,IAAI,SAAS;YACzB,OAAO;YACP,mBAAmB;YACnB,gBAAgB;SAChB,CAAC,CAAC;QAEH,OAAO;YACN,QAAQ,EAAE,SAAS;SACnB,CAAC;IACH,CAAC;CACD;AA3ND,8CA2NC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60" fill="none">
|
|
2
|
+
<rect width="60" height="60" rx="8" fill="#1a1a2e"/>
|
|
3
|
+
<path d="M20 22L12 30L20 38" stroke="#00d9ff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
+
<path d="M40 22L48 30L40 38" stroke="#00d9ff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
+
<path d="M35 16L25 44" stroke="#ff6b6b" stroke-width="3" stroke-linecap="round"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ISupplyDataFunctions, ILoadOptionsFunctions, INodeType, INodeTypeDescription, INodePropertyOptions, SupplyData } from 'n8n-workflow';
|
|
2
|
+
export declare class OpenCodeTool implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
methods: {
|
|
5
|
+
loadOptions: {
|
|
6
|
+
getSessions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
7
|
+
getModels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData>;
|
|
11
|
+
}
|