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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +190 -0
  3. package/dist/assets/opencode.svg +6 -0
  4. package/dist/credentials/OpenCodeApi.credentials.d.ts +8 -0
  5. package/dist/credentials/OpenCodeApi.credentials.js +50 -0
  6. package/dist/credentials/OpenCodeApi.credentials.js.map +1 -0
  7. package/dist/nodes/OpenCode/OpenCode.node.d.ts +13 -0
  8. package/dist/nodes/OpenCode/OpenCode.node.js +787 -0
  9. package/dist/nodes/OpenCode/OpenCode.node.js.map +1 -0
  10. package/dist/nodes/OpenCode/actions/config/getProviders.d.ts +2 -0
  11. package/dist/nodes/OpenCode/actions/config/getProviders.js +19 -0
  12. package/dist/nodes/OpenCode/actions/config/getProviders.js.map +1 -0
  13. package/dist/nodes/OpenCode/actions/config/index.d.ts +4 -0
  14. package/dist/nodes/OpenCode/actions/config/index.js +15 -0
  15. package/dist/nodes/OpenCode/actions/config/index.js.map +1 -0
  16. package/dist/nodes/OpenCode/actions/index.d.ts +5 -0
  17. package/dist/nodes/OpenCode/actions/index.js +26 -0
  18. package/dist/nodes/OpenCode/actions/index.js.map +1 -0
  19. package/dist/nodes/OpenCode/actions/message/command.d.ts +2 -0
  20. package/dist/nodes/OpenCode/actions/message/command.js +102 -0
  21. package/dist/nodes/OpenCode/actions/message/command.js.map +1 -0
  22. package/dist/nodes/OpenCode/actions/message/getMessage.d.ts +2 -0
  23. package/dist/nodes/OpenCode/actions/message/getMessage.js +21 -0
  24. package/dist/nodes/OpenCode/actions/message/getMessage.js.map +1 -0
  25. package/dist/nodes/OpenCode/actions/message/index.d.ts +9 -0
  26. package/dist/nodes/OpenCode/actions/message/index.js +35 -0
  27. package/dist/nodes/OpenCode/actions/message/index.js.map +1 -0
  28. package/dist/nodes/OpenCode/actions/message/list.d.ts +2 -0
  29. package/dist/nodes/OpenCode/actions/message/list.js +37 -0
  30. package/dist/nodes/OpenCode/actions/message/list.js.map +1 -0
  31. package/dist/nodes/OpenCode/actions/message/send.d.ts +2 -0
  32. package/dist/nodes/OpenCode/actions/message/send.js +124 -0
  33. package/dist/nodes/OpenCode/actions/message/send.js.map +1 -0
  34. package/dist/nodes/OpenCode/actions/message/sendAsync.d.ts +2 -0
  35. package/dist/nodes/OpenCode/actions/message/sendAsync.js +88 -0
  36. package/dist/nodes/OpenCode/actions/message/sendAsync.js.map +1 -0
  37. package/dist/nodes/OpenCode/actions/message/shell.d.ts +2 -0
  38. package/dist/nodes/OpenCode/actions/message/shell.js +102 -0
  39. package/dist/nodes/OpenCode/actions/message/shell.js.map +1 -0
  40. package/dist/nodes/OpenCode/actions/session/abort.d.ts +2 -0
  41. package/dist/nodes/OpenCode/actions/session/abort.js +24 -0
  42. package/dist/nodes/OpenCode/actions/session/abort.js.map +1 -0
  43. package/dist/nodes/OpenCode/actions/session/create.d.ts +2 -0
  44. package/dist/nodes/OpenCode/actions/session/create.js +21 -0
  45. package/dist/nodes/OpenCode/actions/session/create.js.map +1 -0
  46. package/dist/nodes/OpenCode/actions/session/delete.d.ts +2 -0
  47. package/dist/nodes/OpenCode/actions/session/delete.js +24 -0
  48. package/dist/nodes/OpenCode/actions/session/delete.js.map +1 -0
  49. package/dist/nodes/OpenCode/actions/session/get.d.ts +2 -0
  50. package/dist/nodes/OpenCode/actions/session/get.js +20 -0
  51. package/dist/nodes/OpenCode/actions/session/get.js.map +1 -0
  52. package/dist/nodes/OpenCode/actions/session/index.d.ts +9 -0
  53. package/dist/nodes/OpenCode/actions/session/index.js +35 -0
  54. package/dist/nodes/OpenCode/actions/session/index.js.map +1 -0
  55. package/dist/nodes/OpenCode/actions/session/list.d.ts +2 -0
  56. package/dist/nodes/OpenCode/actions/session/list.js +18 -0
  57. package/dist/nodes/OpenCode/actions/session/list.js.map +1 -0
  58. package/dist/nodes/OpenCode/actions/session/status.d.ts +2 -0
  59. package/dist/nodes/OpenCode/actions/session/status.js +19 -0
  60. package/dist/nodes/OpenCode/actions/session/status.js.map +1 -0
  61. package/dist/nodes/OpenCode/helpers/api.d.ts +13 -0
  62. package/dist/nodes/OpenCode/helpers/api.js +62 -0
  63. package/dist/nodes/OpenCode/helpers/api.js.map +1 -0
  64. package/dist/nodes/OpenCode/opencode.svg +6 -0
  65. package/dist/nodes/OpenCode/types/index.d.ts +100 -0
  66. package/dist/nodes/OpenCode/types/index.js +3 -0
  67. package/dist/nodes/OpenCode/types/index.js.map +1 -0
  68. package/dist/nodes/OpenCodeChatModel/ChatOpenCode.d.ts +57 -0
  69. package/dist/nodes/OpenCodeChatModel/ChatOpenCode.js +270 -0
  70. package/dist/nodes/OpenCodeChatModel/ChatOpenCode.js.map +1 -0
  71. package/dist/nodes/OpenCodeChatModel/OpenCodeChatModel.node.d.ts +11 -0
  72. package/dist/nodes/OpenCodeChatModel/OpenCodeChatModel.node.js +217 -0
  73. package/dist/nodes/OpenCodeChatModel/OpenCodeChatModel.node.js.map +1 -0
  74. package/dist/nodes/OpenCodeChatModel/opencode.svg +6 -0
  75. package/dist/nodes/OpenCodeTool/OpenCodeTool.node.d.ts +11 -0
  76. package/dist/nodes/OpenCodeTool/OpenCodeTool.node.js +319 -0
  77. package/dist/nodes/OpenCodeTool/OpenCodeTool.node.js.map +1 -0
  78. package/dist/nodes/OpenCodeTool/opencode.svg +6 -0
  79. package/package.json +67 -0
@@ -0,0 +1,787 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenCode = void 0;
4
+ const actions_1 = require("./actions");
5
+ class OpenCode {
6
+ constructor() {
7
+ this.description = {
8
+ displayName: 'OpenCode',
9
+ name: 'openCode',
10
+ icon: 'file:opencode.svg',
11
+ group: ['transform'],
12
+ version: 1,
13
+ subtitle: '={{$parameter["resource"] + ": " + $parameter["operation"]}}',
14
+ description: 'Interact with OpenCode Server API for AI coding assistant sessions',
15
+ defaults: {
16
+ name: 'OpenCode',
17
+ },
18
+ inputs: ['main'],
19
+ outputs: ['main'],
20
+ usableAsTool: true,
21
+ credentials: [
22
+ {
23
+ name: 'openCodeApi',
24
+ required: true,
25
+ },
26
+ ],
27
+ properties: [
28
+ // Resource
29
+ {
30
+ displayName: 'Resource',
31
+ name: 'resource',
32
+ type: 'options',
33
+ noDataExpression: true,
34
+ options: [
35
+ {
36
+ name: 'Session',
37
+ value: 'session',
38
+ description: 'Manage OpenCode sessions',
39
+ },
40
+ {
41
+ name: 'Message',
42
+ value: 'message',
43
+ description: 'Send and receive messages',
44
+ },
45
+ {
46
+ name: 'Config',
47
+ value: 'config',
48
+ description: 'Get configuration and providers',
49
+ },
50
+ ],
51
+ default: 'session',
52
+ },
53
+ // Session Operations
54
+ {
55
+ displayName: 'Operation',
56
+ name: 'operation',
57
+ type: 'options',
58
+ noDataExpression: true,
59
+ displayOptions: {
60
+ show: {
61
+ resource: ['session'],
62
+ },
63
+ },
64
+ options: [
65
+ {
66
+ name: 'List',
67
+ value: 'list',
68
+ description: 'Get all sessions',
69
+ action: 'List all sessions',
70
+ },
71
+ {
72
+ name: 'Get',
73
+ value: 'get',
74
+ description: 'Get a specific session',
75
+ action: 'Get a session',
76
+ },
77
+ {
78
+ name: 'Create',
79
+ value: 'create',
80
+ description: 'Create a new session',
81
+ action: 'Create a session',
82
+ },
83
+ {
84
+ name: 'Delete',
85
+ value: 'delete',
86
+ description: 'Delete a session',
87
+ action: 'Delete a session',
88
+ },
89
+ {
90
+ name: 'Abort',
91
+ value: 'abort',
92
+ description: 'Abort a running session',
93
+ action: 'Abort a session',
94
+ },
95
+ {
96
+ name: 'Status',
97
+ value: 'status',
98
+ description: 'Get status of all sessions',
99
+ action: 'Get session status',
100
+ },
101
+ ],
102
+ default: 'list',
103
+ },
104
+ // Message Operations
105
+ {
106
+ displayName: 'Operation',
107
+ name: 'operation',
108
+ type: 'options',
109
+ noDataExpression: true,
110
+ displayOptions: {
111
+ show: {
112
+ resource: ['message'],
113
+ },
114
+ },
115
+ options: [
116
+ {
117
+ name: 'Send',
118
+ value: 'send',
119
+ description: 'Send a message and wait for response',
120
+ action: 'Send a message',
121
+ },
122
+ {
123
+ name: 'Send Async',
124
+ value: 'sendAsync',
125
+ description: 'Send a message without waiting for response',
126
+ action: 'Send a message async',
127
+ },
128
+ {
129
+ name: 'Execute Command',
130
+ value: 'command',
131
+ description: 'Execute a slash command',
132
+ action: 'Execute a command',
133
+ },
134
+ {
135
+ name: 'Run Shell',
136
+ value: 'shell',
137
+ description: 'Run a shell command',
138
+ action: 'Run shell command',
139
+ },
140
+ {
141
+ name: 'List',
142
+ value: 'list',
143
+ description: 'Get all messages in a session',
144
+ action: 'List messages',
145
+ },
146
+ {
147
+ name: 'Get',
148
+ value: 'get',
149
+ description: 'Get a specific message by ID',
150
+ action: 'Get a message',
151
+ },
152
+ ],
153
+ default: 'send',
154
+ },
155
+ // Config Operations
156
+ {
157
+ displayName: 'Operation',
158
+ name: 'operation',
159
+ type: 'options',
160
+ noDataExpression: true,
161
+ displayOptions: {
162
+ show: {
163
+ resource: ['config'],
164
+ },
165
+ },
166
+ options: [
167
+ {
168
+ name: 'Get Providers',
169
+ value: 'getProviders',
170
+ description: 'Get all available providers and models',
171
+ action: 'Get providers',
172
+ },
173
+ ],
174
+ default: 'getProviders',
175
+ },
176
+ // Session ID (for get, delete, abort)
177
+ {
178
+ displayName: 'Session',
179
+ name: 'sessionId',
180
+ type: 'options',
181
+ typeOptions: {
182
+ loadOptionsMethod: 'getSessions',
183
+ },
184
+ required: true,
185
+ displayOptions: {
186
+ show: {
187
+ resource: ['session'],
188
+ operation: ['get', 'delete', 'abort'],
189
+ },
190
+ },
191
+ default: '',
192
+ description: 'Select a session',
193
+ },
194
+ // Session Mode (for message operations)
195
+ {
196
+ displayName: 'Session Mode',
197
+ name: 'sessionMode',
198
+ type: 'options',
199
+ displayOptions: {
200
+ show: {
201
+ resource: ['message'],
202
+ operation: ['send', 'sendAsync', 'command', 'shell'],
203
+ },
204
+ },
205
+ options: [
206
+ {
207
+ name: 'Use Existing Session',
208
+ value: 'existing',
209
+ description: 'Use an existing session for conversations',
210
+ },
211
+ {
212
+ name: 'Temporary Session',
213
+ value: 'temporary',
214
+ description: 'Create a new session for this request and delete it after response',
215
+ },
216
+ ],
217
+ default: 'existing',
218
+ description: 'Choose how to handle sessions',
219
+ },
220
+ // Session ID (for message operations - existing mode)
221
+ {
222
+ displayName: 'Session',
223
+ name: 'sessionId',
224
+ type: 'options',
225
+ typeOptions: {
226
+ loadOptionsMethod: 'getSessions',
227
+ },
228
+ required: true,
229
+ displayOptions: {
230
+ show: {
231
+ resource: ['message'],
232
+ operation: ['send', 'sendAsync', 'command', 'shell'],
233
+ sessionMode: ['existing'],
234
+ },
235
+ },
236
+ default: '',
237
+ description: 'Select a session for messaging',
238
+ },
239
+ // Session ID (for message list and get operation)
240
+ {
241
+ displayName: 'Session',
242
+ name: 'sessionId',
243
+ type: 'options',
244
+ typeOptions: {
245
+ loadOptionsMethod: 'getSessions',
246
+ },
247
+ required: true,
248
+ displayOptions: {
249
+ show: {
250
+ resource: ['message'],
251
+ operation: ['list', 'get'],
252
+ },
253
+ },
254
+ default: '',
255
+ description: 'Select a session',
256
+ },
257
+ // Message ID (for get operation)
258
+ {
259
+ displayName: 'Message ID',
260
+ name: 'targetMessageId',
261
+ type: 'string',
262
+ required: true,
263
+ displayOptions: {
264
+ show: {
265
+ resource: ['message'],
266
+ operation: ['get'],
267
+ },
268
+ },
269
+ default: '',
270
+ description: 'The ID of the message to retrieve',
271
+ },
272
+ // Limit (for list operation)
273
+ {
274
+ displayName: 'Limit',
275
+ name: 'limit',
276
+ type: 'number',
277
+ displayOptions: {
278
+ show: {
279
+ resource: ['message'],
280
+ operation: ['list'],
281
+ },
282
+ },
283
+ default: 50,
284
+ description: 'Maximum number of messages to return',
285
+ },
286
+ // Temporary Session Title
287
+ {
288
+ displayName: 'Temporary Session Title',
289
+ name: 'tempSessionTitle',
290
+ type: 'string',
291
+ displayOptions: {
292
+ show: {
293
+ resource: ['message'],
294
+ operation: ['send', 'sendAsync', 'command', 'shell'],
295
+ sessionMode: ['temporary'],
296
+ },
297
+ },
298
+ default: 'Temporary Chat Session',
299
+ description: 'Title for temporary sessions (for debugging purposes)',
300
+ },
301
+ // Session Title (for create)
302
+ {
303
+ displayName: 'Title',
304
+ name: 'title',
305
+ type: 'string',
306
+ displayOptions: {
307
+ show: {
308
+ resource: ['session'],
309
+ operation: ['create'],
310
+ },
311
+ },
312
+ default: 'New Session',
313
+ description: 'Title for the new session',
314
+ },
315
+ // Message Text
316
+ {
317
+ displayName: 'Message',
318
+ name: 'message',
319
+ type: 'string',
320
+ typeOptions: {
321
+ rows: 4,
322
+ },
323
+ required: true,
324
+ displayOptions: {
325
+ show: {
326
+ resource: ['message'],
327
+ operation: ['send', 'sendAsync'],
328
+ },
329
+ },
330
+ default: '',
331
+ description: 'The message to send',
332
+ },
333
+ // Model Selection
334
+ {
335
+ displayName: 'Model',
336
+ name: 'model',
337
+ type: 'options',
338
+ typeOptions: {
339
+ loadOptionsMethod: 'getModels',
340
+ },
341
+ displayOptions: {
342
+ show: {
343
+ resource: ['message'],
344
+ operation: ['send', 'sendAsync', 'command', 'shell'],
345
+ },
346
+ },
347
+ default: '',
348
+ description: 'Select a model (optional, uses default if not specified)',
349
+ },
350
+ // Simple Response (for send)
351
+ {
352
+ displayName: 'Simple Response',
353
+ name: 'simpleResponse',
354
+ type: 'boolean',
355
+ displayOptions: {
356
+ show: {
357
+ resource: ['message'],
358
+ operation: ['send'],
359
+ },
360
+ },
361
+ default: false,
362
+ description: 'Whether to return only the response text (true) or full metadata (false)',
363
+ },
364
+ // Simple Response (for shell)
365
+ {
366
+ displayName: 'Simple Response',
367
+ name: 'simpleResponse',
368
+ type: 'boolean',
369
+ displayOptions: {
370
+ show: {
371
+ resource: ['message'],
372
+ operation: ['shell'],
373
+ },
374
+ },
375
+ default: false,
376
+ description: 'Whether to return only the shell output (true) or full metadata (false)',
377
+ },
378
+ // Command (for command operation)
379
+ {
380
+ displayName: 'Command',
381
+ name: 'command',
382
+ type: 'options',
383
+ typeOptions: {
384
+ loadOptionsMethod: 'getCommands',
385
+ },
386
+ required: true,
387
+ displayOptions: {
388
+ show: {
389
+ resource: ['message'],
390
+ operation: ['command'],
391
+ },
392
+ },
393
+ default: '',
394
+ description: 'Select a slash command to execute',
395
+ },
396
+ // Command Arguments (for command operation)
397
+ {
398
+ displayName: 'Command Arguments',
399
+ name: 'commandArguments',
400
+ type: 'string',
401
+ typeOptions: {
402
+ rows: 3,
403
+ },
404
+ displayOptions: {
405
+ show: {
406
+ resource: ['message'],
407
+ operation: ['command'],
408
+ },
409
+ },
410
+ default: '',
411
+ placeholder: '{"key": "value"}',
412
+ description: 'Arguments for the command in JSON format',
413
+ },
414
+ // Shell Command (for shell operation)
415
+ {
416
+ displayName: 'Shell Command',
417
+ name: 'shellCommand',
418
+ type: 'string',
419
+ typeOptions: {
420
+ rows: 3,
421
+ },
422
+ required: true,
423
+ displayOptions: {
424
+ show: {
425
+ resource: ['message'],
426
+ operation: ['shell'],
427
+ },
428
+ },
429
+ default: '',
430
+ placeholder: 'ls -la',
431
+ description: 'The shell command to run',
432
+ },
433
+ // Shell Agent (for shell operation)
434
+ {
435
+ displayName: 'Agent',
436
+ name: 'shellAgent',
437
+ type: 'options',
438
+ typeOptions: {
439
+ loadOptionsMethod: 'getAgents',
440
+ },
441
+ required: true,
442
+ displayOptions: {
443
+ show: {
444
+ resource: ['message'],
445
+ operation: ['shell'],
446
+ },
447
+ },
448
+ default: '',
449
+ description: 'Agent to use for executing the shell command',
450
+ },
451
+ // Options for send/sendAsync operations
452
+ {
453
+ displayName: 'Options',
454
+ name: 'options',
455
+ type: 'collection',
456
+ placeholder: 'Add Option',
457
+ default: {},
458
+ displayOptions: {
459
+ show: {
460
+ resource: ['message'],
461
+ operation: ['send', 'sendAsync'],
462
+ },
463
+ },
464
+ options: [
465
+ {
466
+ displayName: 'Timeout (ms)',
467
+ name: 'timeout',
468
+ type: 'number',
469
+ default: 300000,
470
+ description: 'Request timeout in milliseconds (default: 300000 = 5 minutes)',
471
+ },
472
+ {
473
+ displayName: 'Trim Response',
474
+ name: 'trimResponse',
475
+ type: 'boolean',
476
+ default: true,
477
+ description: 'Whether to trim whitespace from the response text',
478
+ },
479
+ {
480
+ displayName: 'Response Key',
481
+ name: 'responseKey',
482
+ type: 'string',
483
+ default: 'response',
484
+ description: 'The key name for the response text in the output JSON',
485
+ },
486
+ {
487
+ displayName: 'Agent',
488
+ name: 'agent',
489
+ type: 'options',
490
+ typeOptions: {
491
+ loadOptionsMethod: 'getAgents',
492
+ },
493
+ default: '',
494
+ description: 'Agent to use for processing the message (optional)',
495
+ },
496
+ {
497
+ displayName: 'Reference Message ID',
498
+ name: 'messageID',
499
+ type: 'string',
500
+ default: '',
501
+ description: 'Reference message ID for context (optional)',
502
+ },
503
+ {
504
+ displayName: 'System Prompt',
505
+ name: 'system',
506
+ type: 'string',
507
+ typeOptions: {
508
+ rows: 4,
509
+ },
510
+ default: '',
511
+ description: 'System prompt to prepend to the message (optional)',
512
+ },
513
+ {
514
+ displayName: 'No Reply',
515
+ name: 'noReply',
516
+ type: 'boolean',
517
+ default: false,
518
+ description: 'Whether to skip waiting for a response (fire and forget)',
519
+ },
520
+ {
521
+ displayName: 'Tools (JSON)',
522
+ name: 'tools',
523
+ type: 'string',
524
+ typeOptions: {
525
+ rows: 4,
526
+ },
527
+ default: '',
528
+ placeholder: '[{"name": "tool_name", "description": "..."}]',
529
+ description: 'Tool definitions in JSON format (optional)',
530
+ },
531
+ ],
532
+ },
533
+ // Options for command operation
534
+ {
535
+ displayName: 'Options',
536
+ name: 'options',
537
+ type: 'collection',
538
+ placeholder: 'Add Option',
539
+ default: {},
540
+ displayOptions: {
541
+ show: {
542
+ resource: ['message'],
543
+ operation: ['command'],
544
+ },
545
+ },
546
+ options: [
547
+ {
548
+ displayName: 'Timeout (ms)',
549
+ name: 'timeout',
550
+ type: 'number',
551
+ default: 300000,
552
+ description: 'Request timeout in milliseconds (default: 300000 = 5 minutes)',
553
+ },
554
+ {
555
+ displayName: 'Trim Response',
556
+ name: 'trimResponse',
557
+ type: 'boolean',
558
+ default: true,
559
+ description: 'Whether to trim whitespace from the response text',
560
+ },
561
+ {
562
+ displayName: 'Response Key',
563
+ name: 'responseKey',
564
+ type: 'string',
565
+ default: 'response',
566
+ description: 'The key name for the response text in the output JSON',
567
+ },
568
+ {
569
+ displayName: 'Agent',
570
+ name: 'agent',
571
+ type: 'options',
572
+ typeOptions: {
573
+ loadOptionsMethod: 'getAgents',
574
+ },
575
+ default: '',
576
+ description: 'Agent to use for the command (optional)',
577
+ },
578
+ {
579
+ displayName: 'Reference Message ID',
580
+ name: 'messageID',
581
+ type: 'string',
582
+ default: '',
583
+ description: 'Reference message ID for context (optional)',
584
+ },
585
+ ],
586
+ },
587
+ // Options for shell operation
588
+ {
589
+ displayName: 'Options',
590
+ name: 'options',
591
+ type: 'collection',
592
+ placeholder: 'Add Option',
593
+ default: {},
594
+ displayOptions: {
595
+ show: {
596
+ resource: ['message'],
597
+ operation: ['shell'],
598
+ },
599
+ },
600
+ options: [
601
+ {
602
+ displayName: 'Timeout (ms)',
603
+ name: 'timeout',
604
+ type: 'number',
605
+ default: 300000,
606
+ description: 'Request timeout in milliseconds (default: 300000 = 5 minutes)',
607
+ },
608
+ {
609
+ displayName: 'Trim Response',
610
+ name: 'trimResponse',
611
+ type: 'boolean',
612
+ default: true,
613
+ description: 'Whether to trim whitespace from the response text',
614
+ },
615
+ {
616
+ displayName: 'Response Key',
617
+ name: 'responseKey',
618
+ type: 'string',
619
+ default: 'response',
620
+ description: 'The key name for the response text in the output JSON',
621
+ },
622
+ ],
623
+ },
624
+ ],
625
+ };
626
+ this.methods = {
627
+ loadOptions: {
628
+ async getSessions() {
629
+ try {
630
+ const credentials = await this.getCredentials('openCodeApi');
631
+ const baseUrl = credentials.baseUrl;
632
+ const response = await this.helpers.request({
633
+ method: 'GET',
634
+ url: `${baseUrl}/session`,
635
+ auth: {
636
+ user: credentials.username,
637
+ pass: credentials.password,
638
+ },
639
+ json: true,
640
+ });
641
+ const sessions = (Array.isArray(response) ? response : [response]);
642
+ return sessions.map((session) => ({
643
+ name: session.title || `Session ${session.id.substring(0, 8)}...`,
644
+ value: session.id,
645
+ description: `ID: ${session.id}`,
646
+ }));
647
+ }
648
+ catch (error) {
649
+ console.error('Error loading sessions:', error);
650
+ return [{ name: 'Error loading sessions', value: '' }];
651
+ }
652
+ },
653
+ async getModels() {
654
+ try {
655
+ const credentials = await this.getCredentials('openCodeApi');
656
+ const baseUrl = credentials.baseUrl;
657
+ const response = await this.helpers.request({
658
+ method: 'GET',
659
+ url: `${baseUrl}/config/providers`,
660
+ auth: {
661
+ user: credentials.username,
662
+ pass: credentials.password,
663
+ },
664
+ json: true,
665
+ });
666
+ const options = [
667
+ { name: '(Default)', value: '' },
668
+ ];
669
+ const providers = (response.providers || []);
670
+ for (const provider of providers) {
671
+ if (provider.models && typeof provider.models === 'object') {
672
+ // models is an object, not an array
673
+ const modelList = Object.values(provider.models);
674
+ for (const model of modelList) {
675
+ // value format: providerID::modelID (use :: as separator)
676
+ options.push({
677
+ name: `${provider.name || provider.id}: ${model.name || model.id}`,
678
+ value: `${provider.id}::${model.id}`,
679
+ description: `Provider: ${provider.id}`,
680
+ });
681
+ }
682
+ }
683
+ }
684
+ return options;
685
+ }
686
+ catch (error) {
687
+ console.error('Error loading models:', error);
688
+ return [{ name: '(Default)', value: '' }];
689
+ }
690
+ },
691
+ async getAgents() {
692
+ try {
693
+ const credentials = await this.getCredentials('openCodeApi');
694
+ const baseUrl = credentials.baseUrl;
695
+ const response = await this.helpers.request({
696
+ method: 'GET',
697
+ url: `${baseUrl}/agent`,
698
+ auth: {
699
+ user: credentials.username,
700
+ pass: credentials.password,
701
+ },
702
+ json: true,
703
+ });
704
+ const agents = (Array.isArray(response) ? response : []);
705
+ // Find primary agent
706
+ const primaryAgent = agents.find((a) => a.mode === 'primary');
707
+ const otherAgents = agents.filter((a) => a.mode !== 'primary');
708
+ const options = [];
709
+ // Add primary agent first (will be default selection)
710
+ if (primaryAgent) {
711
+ options.push({
712
+ name: `${primaryAgent.name} (Primary)`,
713
+ value: primaryAgent.name,
714
+ description: 'Primary agent',
715
+ });
716
+ }
717
+ // Add other agents
718
+ for (const agent of otherAgents) {
719
+ options.push({
720
+ name: agent.name,
721
+ value: agent.name,
722
+ description: agent.mode ? `Mode: ${agent.mode}` : undefined,
723
+ });
724
+ }
725
+ return options;
726
+ }
727
+ catch (error) {
728
+ console.error('Error loading agents:', error);
729
+ return [{ name: '(Default)', value: '' }];
730
+ }
731
+ },
732
+ async getCommands() {
733
+ try {
734
+ const credentials = await this.getCredentials('openCodeApi');
735
+ const baseUrl = credentials.baseUrl;
736
+ const response = await this.helpers.request({
737
+ method: 'GET',
738
+ url: `${baseUrl}/command`,
739
+ auth: {
740
+ user: credentials.username,
741
+ pass: credentials.password,
742
+ },
743
+ json: true,
744
+ });
745
+ const commands = (Array.isArray(response) ? response : []);
746
+ return commands.map((cmd) => ({
747
+ name: cmd.name,
748
+ value: cmd.name,
749
+ description: cmd.description || `Command: ${cmd.name}`,
750
+ }));
751
+ }
752
+ catch (error) {
753
+ console.error('Error loading commands:', error);
754
+ return [{ name: 'Error loading commands', value: '' }];
755
+ }
756
+ },
757
+ },
758
+ };
759
+ }
760
+ async execute() {
761
+ const items = this.getInputData();
762
+ const returnData = [];
763
+ const resource = this.getNodeParameter('resource', 0);
764
+ const operation = this.getNodeParameter('operation', 0);
765
+ for (let i = 0; i < items.length; i++) {
766
+ try {
767
+ const results = await actions_1.executeAction.call(this, resource, operation, i);
768
+ returnData.push(...results);
769
+ }
770
+ catch (error) {
771
+ if (this.continueOnFail()) {
772
+ returnData.push({
773
+ json: {
774
+ error: error.message,
775
+ },
776
+ pairedItem: { item: i },
777
+ });
778
+ continue;
779
+ }
780
+ throw error;
781
+ }
782
+ }
783
+ return [returnData];
784
+ }
785
+ }
786
+ exports.OpenCode = OpenCode;
787
+ //# sourceMappingURL=OpenCode.node.js.map