@freestyle-sh/with-opencode 0.0.4 → 0.0.6

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;
@@ -21,6 +23,7 @@ type OpenCodeOptions = {
21
23
  port?: number;
22
24
  } & OpenCodeAuthOptions;
23
25
  env?: Record<string, string>;
26
+ config?: Config;
24
27
  };
25
28
  type OpenCodeResolvedOptions = {
26
29
  server: {
@@ -30,6 +33,7 @@ type OpenCodeResolvedOptions = {
30
33
  port: number;
31
34
  } & ResolvedOpenCodeAuthOptions;
32
35
  env: Record<string, string>;
36
+ config?: Config;
33
37
  };
34
38
  declare class VmOpenCode extends VmWith<VmOpenCodeInstance> {
35
39
  options: OpenCodeResolvedOptions;
package/dist/index.js CHANGED
@@ -17,7 +17,8 @@ class VmOpenCode extends VmWith {
17
17
  port: options?.web?.port ?? 4097,
18
18
  ...resolveAuth(options?.web)
19
19
  },
20
- env: options?.env ?? {}
20
+ env: options?.env ?? {},
21
+ config: options?.config
21
22
  };
22
23
  }
23
24
  configureSnapshotSpec(spec) {
@@ -26,32 +27,42 @@ class VmOpenCode extends VmWith {
26
27
  export OPENCODE_SERVER_PASSWORD="${this.options.web.password}"` : "";
27
28
  const serverAuthEnv = this.options.server.username ? `export OPENCODE_SERVER_USERNAME="${this.options.server.username}"
28
29
  export OPENCODE_SERVER_PASSWORD="${this.options.server.password}"` : "";
29
- return this.composeSpecs(
30
- spec,
31
- new VmSpec({
32
- additionalFiles: {
33
- "/opt/install-opencode.sh": {
34
- content: `#!/bin/bash
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
35
  curl -fsSL https://opencode.ai/install | bash
36
36
  `
37
- },
38
- "/opt/run-opencode-web.sh": {
39
- content: `#!/bin/bash
37
+ },
38
+ "/opt/run-opencode-web.sh": {
39
+ content: `#!/bin/bash
40
40
  export PATH="$HOME/.local/bin:$PATH"
41
41
  ${webAuthEnv}
42
+ ${configExport}
42
43
  ${envExports}
43
44
  /root/.opencode/bin/opencode web --hostname 0.0.0.0 --port ${this.options.web.port}
44
45
  `
45
- },
46
- "/opt/run-opencode-server.sh": {
47
- content: `#!/bin/bash
46
+ },
47
+ "/opt/run-opencode-server.sh": {
48
+ content: `#!/bin/bash
48
49
  export PATH="$HOME/.local/bin:$PATH"
49
50
  ${serverAuthEnv}
51
+ ${configExport}
50
52
  ${envExports}
51
53
  /root/.opencode/bin/opencode serve --hostname 0.0.0.0 --port ${this.options.server.port}
52
54
  `
53
- }
54
- },
55
+ }
56
+ };
57
+ if (this.options.config) {
58
+ additionalFiles[configPath] = {
59
+ content: JSON.stringify(this.options.config, null, 2)
60
+ };
61
+ }
62
+ return this.composeSpecs(
63
+ spec,
64
+ new VmSpec({
65
+ additionalFiles,
55
66
  systemd: {
56
67
  services: [
57
68
  {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@freestyle-sh/with-opencode",
3
- "version": "0.0.4",
4
- "packageManager": "pnpm@10.11.0",
3
+ "version": "0.0.6",
5
4
  "private": false,
6
5
  "dependencies": {
7
6
  "@opencode-ai/sdk": "^1.1.42",
8
7
  "freestyle-sandboxes": "^0.1.13"
9
8
  },
10
9
  "devDependencies": {
11
- "@freestyle-sh/with-web-terminal": "workspace:*",
10
+ "@types/node": "^25.1.0",
12
11
  "pkgroll": "^2.11.2",
13
- "typescript": "^5.8.3"
12
+ "typescript": "^5.8.3",
13
+ "@freestyle-sh/with-web-terminal": "0.0.2"
14
14
  },
15
15
  "type": "module",
16
16
  "main": "./dist/index.js",
@@ -26,7 +26,6 @@
26
26
  "dist"
27
27
  ],
28
28
  "scripts": {
29
- "build": "pkgroll",
30
- "prepublishOnly": "pnpm run build"
29
+ "build": "pkgroll"
31
30
  }
32
- }
31
+ }