blob: efb55aaab5f279a5f4b571355722fe8be6fa1df3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
---
title: 網路
description: 在浏览器中使用opencode。
---
opencode 可以在浏览器中作为 Web 应用程序执行,消耗终端可以提供同样强大的 AI 编码体验。

## 入門
绕过执行以下命令启动 Web 简介:
```bash
opencode web
```
这将在 `127.0.0.1` 上启动一个具有随机可用端口的本地服务器,并自动在默认浏览器中开启 opencode。
:::caution
如果未设置`OPENCODE_SERVER_PASSWORD`,服务器将不安全。这对于本地使用来说很好,但应该针对网路访问进行设置。
:::
:::tip[Windows 用户]
For the best experience, run `opencode web` from [WSL](/docs/windows-wsl) rather than PowerShell. This ensures proper file system access and terminal integration.
:::
---
## 配置
您可以使用命令列标志或在[config file](/docs/config).conf 中配置Web服务器。
### 端口
默认情况下,opencode 选择一个可用的端口。您可以指定一个端口:
```bash
opencode web --port 4096
```
### 主機名
情况默认下,服务器系结到`127.0.0.1`(仅限本地主机)。要使opencode在您的网路上可访问:
```bash
opencode web --hostname 0.0.0.0
```
使用`0.0.0.0`时,opencode将显示本地地址和网络地址:
```
Local access: http://localhost:4096
Network access: http://192.168.1.100:4096
```
### mDNS 发现
启用 mDNS 使您的服务器在本地网上可以发现:
```bash
opencode web --mdns
```
This automatically sets the hostname to `0.0.0.0` and advertises the server as `opencode.local`.
您可以自定义 mDNS 域名以在同一网路上执行多个示例:
```bash
opencode web --mdns --mdns-domain myproject.local
```
### CORS
允许CORS使用其他域(对于自定义前缀有用):
```bash
opencode web --cors https://example.com
```
### 驗證
要保护访问,请使用 `OPENCODE_SERVER_PASSWORD` 环境变数设置密码:
```bash
OPENCODE_SERVER_PASSWORD=secret opencode web
```
The username defaults to `opencode` but can be changed with `OPENCODE_SERVER_USERNAME`.
---
## 使用网络界面
启动后,网路界面将提供对您的 opencode 会话的访问。
### 会话
從主頁查看和管理您的会话。您可以查看活动会话并開始新会话。

### 服务器狀態
单击“查看服务器”可查看连接的服务器及其狀態。

---
## 连接终端
您可以将终端 TUI 连线到正在执行的 Web 服务器:
```bash
# Start the web server
opencode web --port 4096
# In another terminal, attach the TUI
opencode attach http://localhost:4096
```
这允许您同时使用 Web 界面和终端,共享相同的会话和状态。
---
## 配置文件
You can also configure server settings in your `opencode.json` config file:
```json
{
"server": {
"port": 4096,
"hostname": "0.0.0.0",
"mdns": true,
"cors": ["https://example.com"]
}
}
```
命令行标志优先于配置文件设置。
|