@freestyle-sh/with-opencode 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -92,17 +92,49 @@ new VmOpenCode({
92
92
  username: "admin", // Optional: Basic auth username (default: "opencode" when password is set)
93
93
  password: "secret", // Optional: Basic auth password
94
94
  },
95
+ env: {
96
+ ANTHROPIC_API_KEY: "sk-ant-...", // Optional: Environment variables for OpenCode
97
+ },
95
98
  });
96
99
  ```
97
100
 
98
- | Option | Type | Default | Description |
99
- | ----------------- | -------- | ------------ | ------------------------------------------------ |
100
- | `server.port` | `number` | `4096` | Port for the OpenCode API server |
101
- | `server.username` | `string` | `"opencode"` | Basic auth username (only used if password set) |
102
- | `server.password` | `string` | - | Basic auth password for the API server |
103
- | `web.port` | `number` | `4097` | Port for the OpenCode web UI |
104
- | `web.username` | `string` | `"opencode"` | Basic auth username (only used if password set) |
105
- | `web.password` | `string` | - | Basic auth password for the web UI |
101
+ | Option | Type | Default | Description |
102
+ | ----------------- | ------------------------ | ------------ | ------------------------------------------------ |
103
+ | `server.port` | `number` | `4096` | Port for the OpenCode API server |
104
+ | `server.username` | `string` | `"opencode"` | Basic auth username (only used if password set) |
105
+ | `server.password` | `string` | - | Basic auth password for the API server |
106
+ | `web.port` | `number` | `4097` | Port for the OpenCode web UI |
107
+ | `web.username` | `string` | `"opencode"` | Basic auth username (only used if password set) |
108
+ | `web.password` | `string` | - | Basic auth password for the web UI |
109
+ | `env` | `Record<string, string>` | `{}` | Environment variables passed to OpenCode processes |
110
+
111
+ ## Environment Variables
112
+
113
+ OpenCode requires API keys to interact with AI providers. When running in a Freestyle VM, pass the required keys using the `env` option.
114
+
115
+ > **Note:** Environment variables are stored as plain text in the VM's startup scripts. Users with direct or indirect access to the VM may be able to view these values. Use appropriately scoped API keys and rotate them if the VM is shared or exposed.
116
+
117
+ | Variable | Description |
118
+ | --------------------- | -------------------------- |
119
+ | `ANTHROPIC_API_KEY` | API key for Claude models |
120
+ | `OPENAI_API_KEY` | API key for OpenAI models |
121
+ | `OPENROUTER_API_KEY` | API key for OpenRouter |
122
+
123
+ See [OpenCode Providers](https://opencode.ai/docs/providers/) for all supported providers and their environment variables.
124
+
125
+ ```typescript
126
+ const { vm } = await freestyle.vms.create({
127
+ spec: new VmSpec({
128
+ with: {
129
+ opencode: new VmOpenCode({
130
+ env: {
131
+ ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY!,
132
+ },
133
+ }),
134
+ },
135
+ }),
136
+ });
137
+ ```
106
138
 
107
139
  ## API
108
140
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import * as freestyle_sandboxes from 'freestyle-sandboxes';
2
2
  import { VmWith, VmWithInstance, VmSpec } from 'freestyle-sandboxes';
3
3
  import * as _opencode_ai_sdk_v2 from '@opencode-ai/sdk/v2';
4
+ import { Config } from '@opencode-ai/sdk/v2';
5
+ export { Config as OpenCodeConfig } from '@opencode-ai/sdk/v2';
4
6
 
5
7
  type OpenCodeAuthOptions = {
6
8
  password?: string;
@@ -20,6 +22,8 @@ type OpenCodeOptions = {
20
22
  web?: {
21
23
  port?: number;
22
24
  } & OpenCodeAuthOptions;
25
+ env?: Record<string, string>;
26
+ config?: Config;
23
27
  };
24
28
  type OpenCodeResolvedOptions = {
25
29
  server: {
@@ -28,6 +32,8 @@ type OpenCodeResolvedOptions = {
28
32
  web: {
29
33
  port: number;
30
34
  } & ResolvedOpenCodeAuthOptions;
35
+ env: Record<string, string>;
36
+ config?: Config;
31
37
  };
32
38
  declare class VmOpenCode extends VmWith<VmOpenCodeInstance> {
33
39
  options: OpenCodeResolvedOptions;
package/dist/index.js CHANGED
@@ -13,40 +13,56 @@ class VmOpenCode extends VmWith {
13
13
  port: options?.server?.port ?? 4096,
14
14
  ...resolveAuth(options?.server)
15
15
  },
16
- web: { port: options?.web?.port ?? 4097, ...resolveAuth(options?.web) }
16
+ web: {
17
+ port: options?.web?.port ?? 4097,
18
+ ...resolveAuth(options?.web)
19
+ },
20
+ env: options?.env ?? {},
21
+ config: options?.config
17
22
  };
18
23
  }
19
24
  configureSnapshotSpec(spec) {
20
- const webAuthEnv = this.options.web.username ? `OPENCODE_SERVER_USERNAME=${this.options.web.username} OPENCODE_SERVER_PASSWORD=${this.options.web.password}`.trim() : "";
21
- const serverAuthEnv = this.options.server.username ? `OPENCODE_SERVER_USERNAME=${this.options.server.username} OPENCODE_SERVER_PASSWORD=${this.options.server.password}`.trim() : "";
25
+ const envExports = Object.entries(this.options.env).map(([k, v]) => `export ${k}="${v}"`).join("\n");
26
+ const webAuthEnv = this.options.web.username ? `export OPENCODE_SERVER_USERNAME="${this.options.web.username}"
27
+ export OPENCODE_SERVER_PASSWORD="${this.options.web.password}"` : "";
28
+ const serverAuthEnv = this.options.server.username ? `export OPENCODE_SERVER_USERNAME="${this.options.server.username}"
29
+ export OPENCODE_SERVER_PASSWORD="${this.options.server.password}"` : "";
30
+ const configPath = "/opt/opencode-config.json";
31
+ const configExport = this.options.config ? `export OPENCODE_CONFIG="${configPath}"` : "";
32
+ const additionalFiles = {
33
+ "/opt/install-opencode.sh": {
34
+ content: `#!/bin/bash
35
+ curl -fsSL https://opencode.ai/install | bash
36
+ `
37
+ },
38
+ "/opt/run-opencode-web.sh": {
39
+ content: `#!/bin/bash
40
+ export PATH="$HOME/.local/bin:$PATH"
41
+ ${webAuthEnv}
42
+ ${configExport}
43
+ ${envExports}
44
+ /root/.opencode/bin/opencode web --hostname 0.0.0.0 --port ${this.options.web.port}
45
+ `
46
+ },
47
+ "/opt/run-opencode-server.sh": {
48
+ content: `#!/bin/bash
49
+ export PATH="$HOME/.local/bin:$PATH"
50
+ ${serverAuthEnv}
51
+ ${configExport}
52
+ ${envExports}
53
+ /root/.opencode/bin/opencode serve --hostname 0.0.0.0 --port ${this.options.server.port}
54
+ `
55
+ }
56
+ };
57
+ if (this.options.config) {
58
+ additionalFiles[configPath] = {
59
+ content: JSON.stringify(this.options.config, null, 2)
60
+ };
61
+ }
22
62
  return this.composeSpecs(
23
63
  spec,
24
64
  new VmSpec({
25
- additionalFiles: {
26
- "/opt/install-opencode.sh": {
27
- content: `
28
- #!/bin/bash
29
-
30
- curl -fsSL https://opencode.ai/install | bash
31
- `
32
- },
33
- "/opt/run-opencode-web.sh": {
34
- content: `
35
- #!/bin/bash
36
-
37
- export PATH="$HOME/.local/bin:$PATH"
38
- ${webAuthEnv} /root/.opencode/bin/opencode web --hostname 0.0.0.0 --port ${this.options.web.port}
39
- `
40
- },
41
- "/opt/run-opencode-server.sh": {
42
- content: `
43
- #!/bin/bash
44
-
45
- export PATH="$HOME/.local/bin:$PATH"
46
- ${serverAuthEnv} /root/.opencode/bin/opencode serve --hostname 0.0.0.0 --port ${this.options.server.port}
47
- `
48
- }
49
- },
65
+ additionalFiles,
50
66
  systemd: {
51
67
  services: [
52
68
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freestyle-sh/with-opencode",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "packageManager": "pnpm@10.11.0",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -9,6 +9,7 @@
9
9
  },
10
10
  "devDependencies": {
11
11
  "@freestyle-sh/with-web-terminal": "workspace:*",
12
+ "@types/node": "^25.1.0",
12
13
  "pkgroll": "^2.11.2",
13
14
  "typescript": "^5.8.3"
14
15
  },