迁移到 bun 框架,移除 js 文件依赖;增加对 tools 参数的校验
This commit is contained in:
@@ -73,12 +73,12 @@ src/
|
||||
### agents
|
||||
|
||||
```text
|
||||
.opencode/agents/tjwater-assistant.md
|
||||
.opencode/agents/agent.md
|
||||
```
|
||||
|
||||
这里定义默认 agent 的角色、行为规则、模型配置和工具使用策略。
|
||||
|
||||
当前项目已将 always-loaded instructions 收敛到 `tjwater-assistant.md`,`opencode.json` 不再额外配置 `instructions` 数组。
|
||||
当前项目已将 always-loaded instructions 收敛到 `agent.md`,`opencode.json` 不再额外配置 `instructions` 数组。
|
||||
|
||||
### tools
|
||||
|
||||
@@ -152,17 +152,17 @@ typescript
|
||||
|
||||
默认部署不需要全局安装 `opencode` CLI。服务会通过 `@opencode-ai/sdk` 的 embedded 模式启动 opencode server。
|
||||
|
||||
根目录的 npm scripts 已经封装 `.opencode` 依赖安装和类型检查,日常只需要在 `TJWaterAgent/` 根目录操作。
|
||||
根目录的 Bun scripts 已经封装 `.opencode` 依赖安装和类型检查,日常只需要在 `TJWaterAgent/` 根目录操作。
|
||||
|
||||
### 本地开发
|
||||
|
||||
```bash
|
||||
cd TJWaterAgent
|
||||
npm install
|
||||
npm run dev
|
||||
bun install
|
||||
bun run dev
|
||||
```
|
||||
|
||||
`npm install` 会通过 `postinstall` 自动执行 `.opencode` 依赖安装;`npm run dev` 启动前会检查 `.opencode/tools` 的类型。
|
||||
`bun install` 会通过 `postinstall` 自动执行 `.opencode` 依赖安装;`bun run dev` 启动前会检查 `.opencode/tools` 的类型。
|
||||
|
||||
开发模式支持热重载,以下文件变化会触发服务重启并重新拉起 embedded opencode:
|
||||
|
||||
@@ -173,7 +173,7 @@ opencode.json
|
||||
.local.env
|
||||
```
|
||||
|
||||
因此修改 agent prompt、tools、skills、模型配置或本地环境变量后,不需要手动重启 `npm run dev`。
|
||||
因此修改 agent prompt、tools、skills、模型配置或本地环境变量后,不需要手动重启 `bun run dev`。
|
||||
|
||||
本地开发可以在项目根目录的 `.local.env` 中配置环境变量:
|
||||
|
||||
@@ -188,29 +188,28 @@ TJWATER_API_BASE_URL=http://127.0.0.1:8000
|
||||
|
||||
```bash
|
||||
cd TJWaterAgent
|
||||
npm install
|
||||
npm run build
|
||||
npm run start
|
||||
bun install
|
||||
bun run check
|
||||
bun run start
|
||||
```
|
||||
|
||||
也可以使用一条命令完成构建并启动:
|
||||
|
||||
```bash
|
||||
cd TJWaterAgent
|
||||
npm install
|
||||
npm run start:prod
|
||||
bun install
|
||||
bun run start:prod
|
||||
```
|
||||
|
||||
### 常用脚本
|
||||
|
||||
| 命令 | 作用 |
|
||||
| --- | --- |
|
||||
| `npm run dev` | 类型检查 `.opencode` tools 后,以 watch 模式启动服务,并监听 `src`、`.opencode`、`opencode.json`、`.local.env` |
|
||||
| `npm run build` | 构建服务并类型检查 `.opencode` tools |
|
||||
| `npm run start` | 启动已构建的 `dist/server.js` |
|
||||
| `npm run start:prod` | 先构建再启动 |
|
||||
| `npm run check` | 执行完整构建检查 |
|
||||
| `npm run install:opencode` | 手动安装 `.opencode` 依赖 |
|
||||
| `bun run dev` | 类型检查 `.opencode` tools 后,以 watch 模式直接运行 `src/server.ts` |
|
||||
| `bun run check` | 执行完整类型检查(服务与 `.opencode` tools) |
|
||||
| `bun run start` | 直接运行 `src/server.ts` |
|
||||
| `bun run start:prod` | 先类型检查再启动 |
|
||||
| `bun run install:opencode` | 手动安装 `.opencode` 依赖 |
|
||||
|
||||
### 模型与 API 配置
|
||||
|
||||
@@ -231,13 +230,13 @@ src/config.ts 的 OPENCODE_MODEL 默认值
|
||||
如果需要临时覆盖模型,可以在启动时设置:
|
||||
|
||||
```bash
|
||||
OPENCODE_MODEL=deepseek/deepseek-v4-pro npm run start
|
||||
OPENCODE_MODEL=deepseek/deepseek-v4-pro bun run start
|
||||
```
|
||||
|
||||
DeepSeek API key 不写入代码,部署时通过环境变量设置:
|
||||
|
||||
```bash
|
||||
DEEPSEEK_API_KEY=sk-xxx npm run start
|
||||
DEEPSEEK_API_KEY=sk-xxx bun run start
|
||||
```
|
||||
|
||||
`opencode.json` 已配置从环境变量读取:
|
||||
@@ -259,7 +258,7 @@ DEEPSEEK_API_KEY=sk-xxx npm run start
|
||||
```bash
|
||||
OPENCODE_CONFIG_CONTENT='{"provider":{"deepseek":{"options":{"baseURL":"https://your-api.example.com/v1"}}}}' \
|
||||
DEEPSEEK_API_KEY=sk-xxx \
|
||||
npm run start
|
||||
bun run start
|
||||
```
|
||||
|
||||
也可以使用 opencode 的 `/connect` 命令写入用户级凭据,但服务部署更推荐使用环境变量。
|
||||
|
||||
Reference in New Issue
Block a user