@freestyle-sh/with-opencode 0.0.2 → 0.0.4
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/dist/index.d.ts +4 -2
- package/dist/index.js +26 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as freestyle_sandboxes from 'freestyle-sandboxes';
|
|
2
2
|
import { VmWith, VmWithInstance, VmSpec } from 'freestyle-sandboxes';
|
|
3
|
-
import * as
|
|
3
|
+
import * as _opencode_ai_sdk_v2 from '@opencode-ai/sdk/v2';
|
|
4
4
|
|
|
5
5
|
type OpenCodeAuthOptions = {
|
|
6
6
|
password?: string;
|
|
@@ -20,6 +20,7 @@ type OpenCodeOptions = {
|
|
|
20
20
|
web?: {
|
|
21
21
|
port?: number;
|
|
22
22
|
} & OpenCodeAuthOptions;
|
|
23
|
+
env?: Record<string, string>;
|
|
23
24
|
};
|
|
24
25
|
type OpenCodeResolvedOptions = {
|
|
25
26
|
server: {
|
|
@@ -28,6 +29,7 @@ type OpenCodeResolvedOptions = {
|
|
|
28
29
|
web: {
|
|
29
30
|
port: number;
|
|
30
31
|
} & ResolvedOpenCodeAuthOptions;
|
|
32
|
+
env: Record<string, string>;
|
|
31
33
|
};
|
|
32
34
|
declare class VmOpenCode extends VmWith<VmOpenCodeInstance> {
|
|
33
35
|
options: OpenCodeResolvedOptions;
|
|
@@ -44,7 +46,7 @@ declare class VmOpenCodeInstance extends VmWithInstance {
|
|
|
44
46
|
client({ domain }?: {
|
|
45
47
|
domain?: string;
|
|
46
48
|
}): Promise<{
|
|
47
|
-
client:
|
|
49
|
+
client: _opencode_ai_sdk_v2.OpencodeClient;
|
|
48
50
|
}>;
|
|
49
51
|
routeWeb({ domain }?: {
|
|
50
52
|
domain?: string;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VmWith, VmSpec, VmWithInstance } from 'freestyle-sandboxes';
|
|
2
|
-
import { createOpencodeClient } from '@opencode-ai/sdk';
|
|
2
|
+
import { createOpencodeClient } from '@opencode-ai/sdk/v2';
|
|
3
3
|
|
|
4
4
|
function resolveAuth(opts) {
|
|
5
5
|
return opts?.password ? { password: opts.password, username: opts.username ?? "opencode" } : {};
|
|
@@ -13,38 +13,43 @@ class VmOpenCode extends VmWith {
|
|
|
13
13
|
port: options?.server?.port ?? 4096,
|
|
14
14
|
...resolveAuth(options?.server)
|
|
15
15
|
},
|
|
16
|
-
web: {
|
|
16
|
+
web: {
|
|
17
|
+
port: options?.web?.port ?? 4097,
|
|
18
|
+
...resolveAuth(options?.web)
|
|
19
|
+
},
|
|
20
|
+
env: options?.env ?? {}
|
|
17
21
|
};
|
|
18
22
|
}
|
|
19
23
|
configureSnapshotSpec(spec) {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
24
|
+
const envExports = Object.entries(this.options.env).map(([k, v]) => `export ${k}="${v}"`).join("\n");
|
|
25
|
+
const webAuthEnv = this.options.web.username ? `export OPENCODE_SERVER_USERNAME="${this.options.web.username}"
|
|
26
|
+
export OPENCODE_SERVER_PASSWORD="${this.options.web.password}"` : "";
|
|
27
|
+
const serverAuthEnv = this.options.server.username ? `export OPENCODE_SERVER_USERNAME="${this.options.server.username}"
|
|
28
|
+
export OPENCODE_SERVER_PASSWORD="${this.options.server.password}"` : "";
|
|
22
29
|
return this.composeSpecs(
|
|
23
30
|
spec,
|
|
24
31
|
new VmSpec({
|
|
25
32
|
additionalFiles: {
|
|
26
33
|
"/opt/install-opencode.sh": {
|
|
27
|
-
content:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
curl -fsSL https://opencode.ai/install | bash
|
|
31
|
-
`
|
|
34
|
+
content: `#!/bin/bash
|
|
35
|
+
curl -fsSL https://opencode.ai/install | bash
|
|
36
|
+
`
|
|
32
37
|
},
|
|
33
38
|
"/opt/run-opencode-web.sh": {
|
|
34
|
-
content:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
content: `#!/bin/bash
|
|
40
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
41
|
+
${webAuthEnv}
|
|
42
|
+
${envExports}
|
|
43
|
+
/root/.opencode/bin/opencode web --hostname 0.0.0.0 --port ${this.options.web.port}
|
|
44
|
+
`
|
|
40
45
|
},
|
|
41
46
|
"/opt/run-opencode-server.sh": {
|
|
42
|
-
content:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
content: `#!/bin/bash
|
|
48
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
49
|
+
${serverAuthEnv}
|
|
50
|
+
${envExports}
|
|
51
|
+
/root/.opencode/bin/opencode serve --hostname 0.0.0.0 --port ${this.options.server.port}
|
|
52
|
+
`
|
|
48
53
|
}
|
|
49
54
|
},
|
|
50
55
|
systemd: {
|