chutes-plugin 0.1.1 → 0.1.3

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,2 @@
1
+ #!/usr/bin/env node
2
+ import './cli/index.js';
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './index.js';
package/dist/cli/index.js CHANGED
@@ -42,32 +42,24 @@ async function install(options) {
42
42
  let installType = options.type;
43
43
  if (!installType) {
44
44
  console.log("Choose installation type:");
45
- console.log("1. Project (install to .opencode/plugin/)");
46
- console.log("2. Global (install to ~/.config/opencode/plugin/)");
47
- console.log(`3. NPM (add to opencode.json for auto-install)
45
+ console.log("1. Project (copy plugin files to .opencode/plugin/)");
46
+ console.log("2. Global (copy plugin files to ~/.config/opencode/plugin/)");
47
+ console.log(`3. NPM (add "chutes-plugin" to opencode.json)
48
48
  `);
49
49
  const readline = await import("readline");
50
50
  const rl = readline.createInterface({
51
51
  input: process.stdin,
52
52
  output: process.stdout
53
53
  });
54
- try {
55
- installType = await new Promise((resolve, reject) => {
56
- rl.question("> ", (answer) => {
57
- rl.close();
58
- resolve(answer.trim());
59
- });
60
- setTimeout(() => {
61
- rl.close();
62
- reject(new Error("Timeout waiting for user input"));
63
- }, 1e4);
54
+ installType = await new Promise((resolve) => {
55
+ rl.question("> ", (answer) => {
56
+ rl.close();
57
+ resolve(answer.trim());
64
58
  });
65
- } catch {
66
- console.log(`No input detected, defaulting to npm installation...
67
- `);
68
- installType = "npm";
69
- }
59
+ });
70
60
  }
61
+ console.log(`Installing type: ${installType}
62
+ `);
71
63
  switch (installType) {
72
64
  case "1":
73
65
  case "project":
@@ -82,153 +74,85 @@ async function install(options) {
82
74
  await installNpm();
83
75
  break;
84
76
  default:
85
- console.log(`Invalid installation type: "${installType}"`);
77
+ console.log(`\u274C Invalid installation type: "${installType}"`);
86
78
  console.log("Please choose: 1 (project), 2 (global), or 3 (npm)");
87
79
  process.exit(1);
88
80
  }
89
81
  }
90
82
  async function installProject() {
91
83
  const projectDir = process.cwd();
92
- const opencodeDir = path.join(projectDir, ".opencode");
93
- const pluginDir = path.join(opencodeDir, "plugin", "chutes-plugin");
84
+ const pluginDir = path.join(projectDir, ".opencode", "plugin", "chutes-plugin");
94
85
  console.log(`Installing to project...
95
86
  `);
96
- try {
97
- if (!fs.existsSync(opencodeDir)) {
98
- fs.mkdirSync(opencodeDir, { recursive: true });
99
- }
100
- if (!fs.existsSync(path.join(opencodeDir, "plugin"))) {
101
- fs.mkdirSync(path.join(opencodeDir, "plugin"), { recursive: true });
102
- }
103
- fs.mkdirSync(pluginDir, { recursive: true });
104
- const distDir = path.join(__dirname, "..", "..", "dist");
105
- if (fs.existsSync(distDir)) {
106
- fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
107
- }
108
- const srcCliDir = path.join(__dirname, "..");
109
- if (fs.existsSync(srcCliDir)) {
110
- fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
111
- }
112
- const packageJsonPath = path.join(opencodeDir, "opencode.json");
113
- let config = {};
114
- if (fs.existsSync(packageJsonPath)) {
115
- const content = fs.readFileSync(packageJsonPath, "utf-8");
116
- try {
117
- config = JSON.parse(content);
118
- } catch {
119
- console.log("\u26A0\uFE0F Warning: Could not parse existing opencode.json, creating new one");
120
- config = {};
121
- }
122
- }
123
- const plugins = config.plugins || [];
124
- if (!Array.isArray(plugins)) {
125
- config.plugins = [];
126
- }
127
- const pluginPath = "./.opencode/plugin/chutes-plugin/dist/index.js";
128
- if (!plugins.includes(pluginPath)) {
129
- config.plugins.push(pluginPath);
130
- }
131
- fs.writeFileSync(packageJsonPath, JSON.stringify(config, null, 2));
132
- console.log("\u2705 Successfully installed to project!");
133
- console.log(`
134
- Next steps:`);
135
- console.log("1. Start OpenCode: opencode");
136
- console.log("2. Connect your Chutes token: /connect chutes");
137
- console.log(`3. Select a Chutes model from the dropdown
87
+ console.log(`Copying plugin files to .opencode/plugin/...
138
88
  `);
139
- } catch (error) {
140
- console.log(`\u274C Error installing to project: ${error instanceof Error ? error.message : String(error)}`);
141
- process.exit(1);
89
+ fs.mkdirSync(pluginDir, { recursive: true });
90
+ const distDir = path.join(__dirname, "..", "..", "dist");
91
+ if (fs.existsSync(distDir)) {
92
+ fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
93
+ }
94
+ const srcCliDir = path.join(__dirname, "..");
95
+ if (fs.existsSync(srcCliDir)) {
96
+ fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
142
97
  }
98
+ console.log("\u2705 Plugin files installed to .opencode/plugin/chutes-plugin/");
99
+ console.log(` Location: ${pluginDir}`);
100
+ console.log(`
101
+ Note: Plugins in .opencode/plugin/ are auto-loaded by OpenCode.
102
+ `);
143
103
  }
144
104
  async function installGlobal() {
145
105
  const homeDir = process.env.HOME || process.env.USERPROFILE;
146
106
  if (!homeDir) {
147
- console.log("\u274C Error: Could not determine home directory");
107
+ console.error("\u274C Error: Could not determine home directory");
148
108
  process.exit(1);
149
109
  }
150
110
  const configDir = path.join(homeDir, ".config", "opencode");
151
111
  const pluginDir = path.join(configDir, "plugin", "chutes-plugin");
152
112
  console.log(`Installing globally...
153
113
  `);
154
- try {
155
- fs.mkdirSync(pluginDir, { recursive: true });
156
- const distDir = path.join(__dirname, "..", "..", "dist");
157
- if (fs.existsSync(distDir)) {
158
- fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
159
- }
160
- const srcCliDir = path.join(__dirname, "..");
161
- if (fs.existsSync(srcCliDir)) {
162
- fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
163
- }
164
- const configPath = path.join(configDir, "opencode.json");
165
- let config = {};
166
- if (fs.existsSync(configPath)) {
167
- const content = fs.readFileSync(configPath, "utf-8");
168
- try {
169
- config = JSON.parse(content);
170
- } catch {
171
- console.log("\u26A0\uFE0F Warning: Could not parse existing opencode.json, creating new one");
172
- config = {};
173
- }
174
- }
175
- config.plugins = config.plugins || [];
176
- if (!Array.isArray(config.plugins)) {
177
- config.plugins = [];
178
- }
179
- const pluginPath = `${configDir}/plugin/chutes-plugin/dist/index.js`;
180
- if (!config.plugins.includes(pluginPath)) {
181
- config.plugins.push(pluginPath);
182
- }
183
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
184
- console.log("\u2705 Successfully installed globally!");
185
- console.log(`
186
- Next steps:`);
187
- console.log("1. Start OpenCode: opencode");
188
- console.log("2. Connect your Chutes token: /connect chutes");
189
- console.log(`3. Select a Chutes model from the dropdown
190
- `);
191
- } catch (error) {
192
- console.log(`\u274C Error installing globally: ${error instanceof Error ? error.message : String(error)}`);
193
- process.exit(1);
114
+ fs.mkdirSync(pluginDir, { recursive: true });
115
+ const distDir = path.join(__dirname, "..", "..", "dist");
116
+ if (fs.existsSync(distDir)) {
117
+ fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
118
+ }
119
+ const srcCliDir = path.join(__dirname, "..");
120
+ if (fs.existsSync(srcCliDir)) {
121
+ fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
194
122
  }
123
+ console.log("\u2705 Plugin files installed globally!");
124
+ console.log(` Location: ${pluginDir}`);
125
+ console.log(`
126
+ Note: Plugins in ~/.config/opencode/plugin/ are auto-loaded by OpenCode.
127
+ `);
195
128
  }
196
129
  async function installNpm() {
197
130
  const projectDir = process.cwd();
198
131
  const configPath = path.join(projectDir, "opencode.json");
199
132
  console.log(`Installing via npm...
200
133
  `);
201
- try {
202
- let config = {};
203
- if (fs.existsSync(configPath)) {
204
- const content = fs.readFileSync(configPath, "utf-8");
205
- try {
206
- config = JSON.parse(content);
207
- } catch {
208
- console.log("\u26A0\uFE0F Warning: Could not parse existing opencode.json, creating new one");
209
- config = {};
210
- }
211
- }
212
- config.plugins = config.plugins || [];
213
- if (!Array.isArray(config.plugins)) {
214
- config.plugins = [];
215
- }
216
- if (!config.plugins.includes("chutes-plugin")) {
217
- config.plugins.push("chutes-plugin");
134
+ let config = {};
135
+ if (fs.existsSync(configPath)) {
136
+ const content = fs.readFileSync(configPath, "utf-8");
137
+ try {
138
+ config = JSON.parse(content);
139
+ } catch (e) {
140
+ console.error("\u274C Failed to parse opencode.json:", e);
141
+ process.exit(1);
218
142
  }
219
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
220
- console.log('\u2705 Added "chutes-plugin" to opencode.json!');
221
- console.log(`
222
- Next steps:`);
223
- console.log("1. Start OpenCode: opencode");
224
- console.log("2. The plugin will be auto-installed on first run");
225
- console.log("3. Connect your Chutes token: /connect chutes");
226
- console.log(`4. Select a Chutes model from the dropdown
227
- `);
228
- } catch (error) {
229
- console.log(`\u274C Error installing via npm: ${error instanceof Error ? error.message : String(error)}`);
230
- process.exit(1);
231
143
  }
144
+ config.plugins = config.plugins || [];
145
+ if (!Array.isArray(config.plugins)) {
146
+ config.plugins = [];
147
+ }
148
+ const plugins = config.plugins;
149
+ if (!plugins.includes("chutes-plugin")) {
150
+ plugins.push("chutes-plugin");
151
+ }
152
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
153
+ console.log('\u2705 Added "chutes-plugin" to opencode.json!');
154
+ console.log(` OpenCode will auto-install the plugin on next startup.
155
+ `);
232
156
  }
233
157
  var __dirname = "/home/mark182/code/chutes-plugin/src/cli";
234
158
  var init_install = () => {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chutes-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Chutes Models plugin for OpenCode - Access 48+ state-of-the-art AI models through the Chutes API",
5
5
  "author": {
6
6
  "name": "Gianmarco Martinelli",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "bin": {
17
- "chutes-plugin": "dist/cli/index.js"
17
+ "chutes-plugin": "dist/cli/chutes-plugin.js"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -26,7 +26,8 @@
26
26
  "files": [
27
27
  "dist",
28
28
  "src/version.ts",
29
- "src/cli"
29
+ "src/cli",
30
+ "bin"
30
31
  ],
31
32
  "dependencies": {
32
33
  "@opencode-ai/plugin": "1.0.85",
@@ -13,9 +13,9 @@ export async function install(options: InstallOptions): Promise<void> {
13
13
 
14
14
  if (!installType) {
15
15
  console.log('Choose installation type:');
16
- console.log('1. Project (install to .opencode/plugin/)');
17
- console.log('2. Global (install to ~/.config/opencode/plugin/)');
18
- console.log('3. NPM (add to opencode.json for auto-install)\n');
16
+ console.log('1. Project (copy plugin files to .opencode/plugin/)');
17
+ console.log('2. Global (copy plugin files to ~/.config/opencode/plugin/)');
18
+ console.log('3. NPM (add "chutes-plugin" to opencode.json)\n');
19
19
 
20
20
  const readline = await import('node:readline');
21
21
  const rl = readline.createInterface({
@@ -23,24 +23,16 @@ export async function install(options: InstallOptions): Promise<void> {
23
23
  output: process.stdout,
24
24
  });
25
25
 
26
- try {
27
- installType = await new Promise<string>((resolve, reject) => {
28
- rl.question('> ', (answer) => {
29
- rl.close();
30
- resolve(answer.trim());
31
- });
32
-
33
- setTimeout(() => {
34
- rl.close();
35
- reject(new Error('Timeout waiting for user input'));
36
- }, 10000);
26
+ installType = await new Promise<string>((resolve) => {
27
+ rl.question('> ', (answer) => {
28
+ rl.close();
29
+ resolve(answer.trim());
37
30
  });
38
- } catch {
39
- console.log('No input detected, defaulting to npm installation...\n');
40
- installType = 'npm';
41
- }
31
+ });
42
32
  }
43
33
 
34
+ console.log(`Installing type: ${installType}\n`);
35
+
44
36
  switch (installType) {
45
37
  case '1':
46
38
  case 'project':
@@ -55,7 +47,7 @@ export async function install(options: InstallOptions): Promise<void> {
55
47
  await installNpm();
56
48
  break;
57
49
  default:
58
- console.log(`Invalid installation type: "${installType}"`);
50
+ console.log(`❌ Invalid installation type: "${installType}"`);
59
51
  console.log('Please choose: 1 (project), 2 (global), or 3 (npm)');
60
52
  process.exit(1);
61
53
  }
@@ -63,73 +55,32 @@ export async function install(options: InstallOptions): Promise<void> {
63
55
 
64
56
  async function installProject(): Promise<void> {
65
57
  const projectDir = process.cwd();
66
- const opencodeDir = path.join(projectDir, '.opencode');
67
- const pluginDir = path.join(opencodeDir, 'plugin', 'chutes-plugin');
58
+ const pluginDir = path.join(projectDir, '.opencode', 'plugin', 'chutes-plugin');
68
59
 
69
60
  console.log('Installing to project...\n');
61
+ console.log('Copying plugin files to .opencode/plugin/...\n');
70
62
 
71
- try {
72
- if (!fs.existsSync(opencodeDir)) {
73
- fs.mkdirSync(opencodeDir, { recursive: true });
74
- }
63
+ fs.mkdirSync(pluginDir, { recursive: true });
75
64
 
76
- if (!fs.existsSync(path.join(opencodeDir, 'plugin'))) {
77
- fs.mkdirSync(path.join(opencodeDir, 'plugin'), { recursive: true });
78
- }
79
-
80
- fs.mkdirSync(pluginDir, { recursive: true });
81
-
82
- const distDir = path.join(__dirname, '..', '..', 'dist');
83
- if (fs.existsSync(distDir)) {
84
- fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
85
- }
86
-
87
- const srcCliDir = path.join(__dirname, '..');
88
- if (fs.existsSync(srcCliDir)) {
89
- fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
90
- }
91
-
92
- const packageJsonPath = path.join(opencodeDir, 'opencode.json');
93
- let config: Record<string, unknown> = {};
94
- if (fs.existsSync(packageJsonPath)) {
95
- const content = fs.readFileSync(packageJsonPath, 'utf-8');
96
- try {
97
- config = JSON.parse(content);
98
- } catch {
99
- console.log('⚠️ Warning: Could not parse existing opencode.json, creating new one');
100
- config = {};
101
- }
102
- }
103
-
104
- const plugins = (config.plugins as string[]) || [];
105
- if (!Array.isArray(plugins)) {
106
- config.plugins = [];
107
- }
108
-
109
- const pluginPath = './.opencode/plugin/chutes-plugin/dist/index.js';
110
- if (!plugins.includes(pluginPath)) {
111
- config.plugins.push(pluginPath);
112
- }
65
+ const distDir = path.join(__dirname, '..', '..', 'dist');
66
+ if (fs.existsSync(distDir)) {
67
+ fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
68
+ }
113
69
 
114
- fs.writeFileSync(packageJsonPath, JSON.stringify(config, null, 2));
115
-
116
- console.log(' Successfully installed to project!');
117
- console.log('\nNext steps:');
118
- console.log('1. Start OpenCode: opencode');
119
- console.log('2. Connect your Chutes token: /connect chutes');
120
- console.log('3. Select a Chutes model from the dropdown\n');
121
- } catch (error) {
122
- console.log(
123
- `❌ Error installing to project: ${error instanceof Error ? error.message : String(error)}`
124
- );
125
- process.exit(1);
70
+ const srcCliDir = path.join(__dirname, '..');
71
+ if (fs.existsSync(srcCliDir)) {
72
+ fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
126
73
  }
74
+
75
+ console.log('✅ Plugin files installed to .opencode/plugin/chutes-plugin/');
76
+ console.log(` Location: ${pluginDir}`);
77
+ console.log('\nNote: Plugins in .opencode/plugin/ are auto-loaded by OpenCode.\n');
127
78
  }
128
79
 
129
80
  async function installGlobal(): Promise<void> {
130
81
  const homeDir = process.env.HOME || process.env.USERPROFILE;
131
82
  if (!homeDir) {
132
- console.log('❌ Error: Could not determine home directory');
83
+ console.error('❌ Error: Could not determine home directory');
133
84
  process.exit(1);
134
85
  }
135
86
 
@@ -138,54 +89,21 @@ async function installGlobal(): Promise<void> {
138
89
 
139
90
  console.log('Installing globally...\n');
140
91
 
141
- try {
142
- fs.mkdirSync(pluginDir, { recursive: true });
143
-
144
- const distDir = path.join(__dirname, '..', '..', 'dist');
145
- if (fs.existsSync(distDir)) {
146
- fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
147
- }
148
-
149
- const srcCliDir = path.join(__dirname, '..');
150
- if (fs.existsSync(srcCliDir)) {
151
- fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
152
- }
92
+ fs.mkdirSync(pluginDir, { recursive: true });
153
93
 
154
- const configPath = path.join(configDir, 'opencode.json');
155
- let config: Record<string, unknown> = {};
156
- if (fs.existsSync(configPath)) {
157
- const content = fs.readFileSync(configPath, 'utf-8');
158
- try {
159
- config = JSON.parse(content);
160
- } catch {
161
- console.log('⚠️ Warning: Could not parse existing opencode.json, creating new one');
162
- config = {};
163
- }
164
- }
165
-
166
- config.plugins = config.plugins || [];
167
- if (!Array.isArray(config.plugins)) {
168
- config.plugins = [];
169
- }
170
-
171
- const pluginPath = `${configDir}/plugin/chutes-plugin/dist/index.js`;
172
- if (!config.plugins.includes(pluginPath)) {
173
- config.plugins.push(pluginPath);
174
- }
94
+ const distDir = path.join(__dirname, '..', '..', 'dist');
95
+ if (fs.existsSync(distDir)) {
96
+ fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
97
+ }
175
98
 
176
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
177
-
178
- console.log(' Successfully installed globally!');
179
- console.log('\nNext steps:');
180
- console.log('1. Start OpenCode: opencode');
181
- console.log('2. Connect your Chutes token: /connect chutes');
182
- console.log('3. Select a Chutes model from the dropdown\n');
183
- } catch (error) {
184
- console.log(
185
- `❌ Error installing globally: ${error instanceof Error ? error.message : String(error)}`
186
- );
187
- process.exit(1);
99
+ const srcCliDir = path.join(__dirname, '..');
100
+ if (fs.existsSync(srcCliDir)) {
101
+ fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
188
102
  }
103
+
104
+ console.log('✅ Plugin files installed globally!');
105
+ console.log(` Location: ${pluginDir}`);
106
+ console.log('\nNote: Plugins in ~/.config/opencode/plugin/ are auto-loaded by OpenCode.\n');
189
107
  }
190
108
 
191
109
  async function installNpm(): Promise<void> {
@@ -194,39 +112,29 @@ async function installNpm(): Promise<void> {
194
112
 
195
113
  console.log('Installing via npm...\n');
196
114
 
197
- try {
198
- let config: Record<string, unknown> = {};
199
- if (fs.existsSync(configPath)) {
200
- const content = fs.readFileSync(configPath, 'utf-8');
201
- try {
202
- config = JSON.parse(content);
203
- } catch {
204
- console.log('⚠️ Warning: Could not parse existing opencode.json, creating new one');
205
- config = {};
206
- }
207
- }
208
-
209
- config.plugins = config.plugins || [];
210
- if (!Array.isArray(config.plugins)) {
211
- config.plugins = [];
115
+ let config: Record<string, unknown> = {};
116
+ if (fs.existsSync(configPath)) {
117
+ const content = fs.readFileSync(configPath, 'utf-8');
118
+ try {
119
+ config = JSON.parse(content);
120
+ } catch (e) {
121
+ console.error('❌ Failed to parse opencode.json:', e);
122
+ process.exit(1);
212
123
  }
124
+ }
213
125
 
214
- if (!config.plugins.includes('chutes-plugin')) {
215
- config.plugins.push('chutes-plugin');
216
- }
126
+ config.plugins = config.plugins || [];
127
+ if (!Array.isArray(config.plugins)) {
128
+ config.plugins = [];
129
+ }
217
130
 
218
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
219
-
220
- console.log('✅ Added "chutes-plugin" to opencode.json!');
221
- console.log('\nNext steps:');
222
- console.log('1. Start OpenCode: opencode');
223
- console.log('2. The plugin will be auto-installed on first run');
224
- console.log('3. Connect your Chutes token: /connect chutes');
225
- console.log('4. Select a Chutes model from the dropdown\n');
226
- } catch (error) {
227
- console.log(
228
- `❌ Error installing via npm: ${error instanceof Error ? error.message : String(error)}`
229
- );
230
- process.exit(1);
131
+ const plugins = config.plugins as string[];
132
+ if (!plugins.includes('chutes-plugin')) {
133
+ plugins.push('chutes-plugin');
231
134
  }
135
+
136
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
137
+
138
+ console.log('✅ Added "chutes-plugin" to opencode.json!');
139
+ console.log(' OpenCode will auto-install the plugin on next startup.\n');
232
140
  }