ydc-agent 1.0.0

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 ADDED
@@ -0,0 +1,217 @@
1
+ # ydc-agent
2
+
3
+ [![npm version](https://img.shields.io/npm/v/ydc-agent.svg)](https://www.npmjs.com/package/ydc-agent)
4
+ [![npm downloads](https://img.shields.io/npm/dm/ydc-agent.svg)](https://www.npmjs.com/package/ydc-agent)
5
+
6
+ MCP server for You.com AI agents with OpenAI-compatible API.
7
+
8
+ > 📖 Other languages: 繁體中文 | 简体中文 | 日本語 (see README_ZH_TW.md, README_ZH_CN.md, README_JA.md)
9
+
10
+ ## MCP Configuration
11
+
12
+ ### Claude Desktop / Cursor / Windsurf
13
+
14
+ Add to your MCP config file:
15
+
16
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
17
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
18
+ **Cursor/Windsurf**: `.cursor/mcp.json` or `.windsurf/mcp.json`
19
+
20
+ ```json
21
+ {
22
+ "mcpServers": {
23
+ "ydc-agent": {
24
+ "command": "npx",
25
+ "args": ["-y", "ydc-agent"],
26
+ "env": {
27
+ "YDC_API_KEY": "your-api-key"
28
+ }
29
+ }
30
+ }
31
+ }
32
+ ```
33
+
34
+ ### With Multiple API Keys
35
+
36
+ ```json
37
+ {
38
+ "mcpServers": {
39
+ "ydc-agent": {
40
+ "command": "npx",
41
+ "args": ["-y", "ydc-agent"],
42
+ "env": {
43
+ "YDC_API_KEYS": "key1,key2,key3",
44
+ "YDC_KEY_MODE": "round-robin"
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ Key modes: `round-robin` (default), `sequential`, `random`
52
+
53
+ ## Available MCP Tools
54
+
55
+ | Tool | Description |
56
+ |------|-------------|
57
+ | `you_search` | Web and news search |
58
+ | `you_express` | Fast AI answers |
59
+ | `you_advanced` | Complex reasoning with compute/research tools |
60
+ | `you_agent` | Custom AI agent with intelligent prompt enhancement |
61
+ | `you_chat` | OpenAI-compatible chat with conversation history |
62
+ | `you_conversation_list` | List active conversations |
63
+ | `you_conversation_get` | Get conversation history |
64
+ | `you_conversation_delete` | Delete conversation |
65
+ | `you_key_status` | API key usage statistics |
66
+ | `openai_server_control` | Start/stop OpenAI-compatible HTTP server |
67
+
68
+ ### Built-in AI Guidance
69
+
70
+ Tool descriptions include guidance for AI callers:
71
+
72
+ | Tool | Built-in Feature |
73
+ |------|------------------|
74
+ | `you_search` | Guides AI to use `call_count=5+` for diverse results |
75
+ | `you_express` | Guides AI to use `call_count=5+` for diverse opinions |
76
+ | `you_advanced` | **AI Capability Rule**: If caller is GPT-3.5+, results are reference material only - use `call_count=5+` for multiple perspectives |
77
+ | `you_agent` | **Failure Tracking**: Auto-tracks failures, suggests switching to `you_advanced` after threshold (default: 3 failures) |
78
+
79
+ ## AI Calling Decision Guide
80
+
81
+ ### ⚠️ For GPT-3.5+ Level AI
82
+
83
+ If you are GPT-3.5 or above (GPT-4, Claude 3.5, etc.):
84
+ - `you_advanced` results are **reference material**, not authoritative answers
85
+ - Use `call_count=5+` to gather multiple perspectives, then integrate with your own judgment
86
+ - Avoid `call_count=1` for single answers (wastes multi-perspective capability)
87
+
88
+ ### Quick Reference
89
+
90
+ | Use Case | Tool | Parameters |
91
+ |----------|------|------------|
92
+ | Diverse viewpoints | `you_advanced` | `call_count=5-10, summary=true, show_results=true` |
93
+ | Quick opinions | `you_express` | `call_count=10-20, show_results=true` |
94
+ | Deep research | `you_advanced` | `agent_type="advanced-4.5-research", call_count=1` |
95
+ | Web search | `you_search` | `call_count=5-20, show_results=true` |
96
+
97
+ ### ⚠️ Common Mistakes
98
+
99
+ | Wrong | Correct |
100
+ |-------|---------|
101
+ | `call_count=1` for single answer | `call_count=5+` for diverse perspectives |
102
+ | Treat results as authoritative | Treat as reference, integrate yourself |
103
+ | `call_count=10` with `you_advanced` | Use `you_express` or `call_count=3-5` |
104
+
105
+ ## Models / Agent Types
106
+
107
+ | Model | Description |
108
+ |-------|-------------|
109
+ | `express` | Fast responses |
110
+ | `research` | Deep analysis |
111
+ | `advanced-3.0-high` | Compute tools (default) |
112
+ | `advanced-4.5-high-research` | Full tools (compute + research) |
113
+ | `<custom-agent-id>` | Any custom You.com agent ID |
114
+
115
+ ### Custom Agent ID
116
+
117
+ You can use any custom You.com agent ID as the model name:
118
+
119
+ ```bash
120
+ curl -X POST http://localhost:3002/v1/chat/completions \
121
+ -H "Authorization: Bearer token" \
122
+ -H "Content-Type: application/json" \
123
+ -d '{"model":"your-custom-agent-uuid","messages":[{"role":"user","content":"Hello"}]}'
124
+ ```
125
+
126
+ ## OpenAI-Compatible Server
127
+
128
+ Start via npx:
129
+
130
+ ```bash
131
+ # Start with single API key
132
+ npx ydc-agent --openai --api-key YOUR_API_KEY
133
+
134
+ # Start with multiple API keys (round-robin)
135
+ npx ydc-agent --openai --api-keys KEY1,KEY2,KEY3
136
+
137
+ # With custom port and key mode
138
+ npx ydc-agent --openai --api-keys KEY1,KEY2 --port 3003 --key-mode random
139
+
140
+ # With access token authentication
141
+ npx ydc-agent --openai --api-key YOUR_API_KEY --access-token SECRET
142
+
143
+ # With custom agents (name:id format)
144
+ npx ydc-agent --openai --api-key YOUR_API_KEY --agent mybot:uuid-here --agent another:uuid2
145
+ ```
146
+
147
+ Or via MCP tool `openai_server_control`.
148
+
149
+ ### Endpoints
150
+
151
+ - `POST /v1/chat/completions` - Chat completions
152
+ - `GET /v1/models` - List models
153
+ - `GET /health` - Health check
154
+
155
+ ### Usage
156
+
157
+ ```bash
158
+ curl -X POST http://localhost:3002/v1/chat/completions \
159
+ -H "Authorization: Bearer token" \
160
+ -H "Content-Type: application/json" \
161
+ -d '{"model":"express","messages":[{"role":"user","content":"Hello"}]}'
162
+ ```
163
+
164
+ ## Environment Variables
165
+
166
+ | Variable | Description | Default |
167
+ |----------|-------------|---------|
168
+ | `YDC_API_KEY` | You.com API key | required |
169
+ | `YDC_API_KEYS` | Multiple keys (comma-separated) | - |
170
+ | `YDC_KEY_MODE` | round-robin / sequential / random | round-robin |
171
+ | `YDC_OPENAI_PORT` | HTTP server port | 3002 |
172
+ | `YDC_CONVERSATION_STORE` | sqlite / memory | sqlite |
173
+ | `YDC_OPENAI_ACCESS_TOKENS` | Allowed tokens (comma-separated) | - |
174
+ | `YDC_CUSTOM_AGENTS` | Custom agents (name:id,name2:id2) | - |
175
+ | `YDC_AGENT_FAILURE_THRESHOLD` | you_agent failure threshold before disable | 3 |
176
+
177
+ ## PM2 Deployment
178
+
179
+ For production deployment with PM2:
180
+
181
+ ```bash
182
+ # Using ecosystem config
183
+ pm2 start ecosystem.config.cjs
184
+
185
+ # Or direct command (Windows)
186
+ pm2 start "cmd /c npx ydc-agent --openai --api-key YOUR_KEY" --name ydc
187
+ ```
188
+
189
+ ## Cloudflare Worker Deployment
190
+
191
+ Deploy as a serverless Cloudflare Worker with D1 database for conversation storage.
192
+
193
+ ### Quick Deploy
194
+
195
+ [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/linuxdo-ref/ydc-agent&authed=true)
196
+
197
+ ### Manual Deploy
198
+
199
+ 1. Create D1 database in Cloudflare Dashboard
200
+ 2. Create Worker and paste `cloudflare/worker.js`
201
+ 3. Add environment variables: `YDC_API_KEYS`, `ACCESS_TOKEN` (optional)
202
+ 4. Bind D1 database as `YDC_DB`
203
+ 5. Visit `/setup` to initialize database
204
+
205
+ ### Worker Features
206
+
207
+ - OpenAI & Anthropic API compatible
208
+ - D1 database for conversation history
209
+ - Multi API key support (random selection)
210
+ - Custom agents via `CUSTOM_AGENTS` env var
211
+ - Setup page at `/setup` for configuration
212
+
213
+ See [cloudflare/README.md](cloudflare/README.md) for detailed instructions.
214
+
215
+ ## License
216
+
217
+ MIT
package/README_JA.md ADDED
@@ -0,0 +1,189 @@
1
+ # ydc-agent
2
+
3
+ [![npm version](https://img.shields.io/npm/v/ydc-agent.svg)](https://www.npmjs.com/package/ydc-agent)
4
+ [![npm downloads](https://img.shields.io/npm/dm/ydc-agent.svg)](https://www.npmjs.com/package/ydc-agent)
5
+
6
+ You.com AI エージェント用 MCP サーバー、OpenAI 互換 API 対応。
7
+
8
+ ## MCP 設定
9
+
10
+ ### Claude Desktop / Cursor / Windsurf
11
+
12
+ MCP 設定ファイルに追加:
13
+
14
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
15
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
16
+ **Cursor/Windsurf**: `.cursor/mcp.json` または `.windsurf/mcp.json`
17
+
18
+ ```json
19
+ {
20
+ "mcpServers": {
21
+ "ydc-agent": {
22
+ "command": "npx",
23
+ "args": ["-y", "ydc-agent"],
24
+ "env": {
25
+ "YDC_API_KEY": "your-api-key"
26
+ }
27
+ }
28
+ }
29
+ }
30
+ ```
31
+
32
+ ### 複数 API Key 設定
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "ydc-agent": {
38
+ "command": "npx",
39
+ "args": ["-y", "ydc-agent"],
40
+ "env": {
41
+ "YDC_API_KEYS": "key1,key2,key3",
42
+ "YDC_KEY_MODE": "round-robin"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ Key モード:`round-robin`(デフォルト)、`sequential`、`random`
50
+
51
+ ## 利用可能な MCP ツール
52
+
53
+ | ツール | 説明 |
54
+ |--------|------|
55
+ | `you_search` | ウェブ・ニュース検索 |
56
+ | `you_express` | 高速 AI 回答 |
57
+ | `you_advanced` | 複雑な推論(計算/リサーチツール付き) |
58
+ | `you_agent` | カスタム AI エージェント(インテリジェントプロンプト強化) |
59
+ | `you_chat` | OpenAI 互換チャット(会話履歴付き) |
60
+ | `you_conversation_list` | 会話一覧 |
61
+ | `you_conversation_get` | 会話履歴取得 |
62
+ | `you_conversation_delete` | 会話削除 |
63
+ | `you_key_status` | API Key 使用統計 |
64
+ | `openai_server_control` | OpenAI 互換 HTTP サーバーの起動/停止 |
65
+
66
+ ### 組み込み AI ガイダンス
67
+
68
+ ツール説明には AI 呼び出し元へのガイダンスが含まれています:
69
+
70
+ | ツール | 組み込み機能 |
71
+ |--------|--------------|
72
+ | `you_search` | AI に `call_count=5+` で多様な検索結果を取得するよう誘導 |
73
+ | `you_express` | AI に `call_count=5+` で多様な意見を取得するよう誘導 |
74
+ | `you_advanced` | **AI 能力ルール**:呼び出し元が GPT-3.5+ の場合、結果は参考資料のみ - `call_count=5+` で多様な視点を収集すべき |
75
+ | `you_agent` | **失敗追跡**:失敗回数を自動追跡、閾値(デフォルト 3 回)超過後に `you_advanced` への切り替えを提案 |
76
+
77
+ ## モデル / Agent タイプ
78
+
79
+ | モデル | 説明 |
80
+ |--------|------|
81
+ | `express` | 高速レスポンス |
82
+ | `research` | 深い分析 |
83
+ | `advanced-3.0-high` | 計算ツール(デフォルト) |
84
+ | `advanced-4.5-high-research` | フルツール(計算 + リサーチ) |
85
+ | `<custom-agent-id>` | 任意のカスタム You.com agent ID |
86
+
87
+ ### カスタム Agent ID
88
+
89
+ 任意の You.com カスタム agent ID をモデル名として使用可能:
90
+
91
+ ```bash
92
+ curl -X POST http://localhost:3002/v1/chat/completions \
93
+ -H "Authorization: Bearer token" \
94
+ -H "Content-Type: application/json" \
95
+ -d '{"model":"your-custom-agent-uuid","messages":[{"role":"user","content":"こんにちは"}]}'
96
+ ```
97
+
98
+ ## OpenAI 互換サーバー
99
+
100
+ npx で起動:
101
+
102
+ ```bash
103
+ # 単一 API key
104
+ npx ydc-agent --openai --api-key YOUR_API_KEY
105
+
106
+ # 複数 API keys(ローテーション)
107
+ npx ydc-agent --openai --api-keys KEY1,KEY2,KEY3
108
+
109
+ # カスタムポートと key モード
110
+ npx ydc-agent --openai --api-keys KEY1,KEY2 --port 3003 --key-mode random
111
+
112
+ # アクセストークン認証付き
113
+ npx ydc-agent --openai --api-key YOUR_API_KEY --access-token SECRET
114
+
115
+ # カスタム agents 付き(name:id 形式)
116
+ npx ydc-agent --openai --api-key YOUR_API_KEY --agent mybot:uuid-here --agent another:uuid2
117
+ ```
118
+
119
+ または MCP ツール `openai_server_control` 経由。
120
+
121
+ ### API エンドポイント
122
+
123
+ - `POST /v1/chat/completions` - チャット完了
124
+ - `GET /v1/models` - モデル一覧
125
+ - `GET /health` - ヘルスチェック
126
+
127
+ ### 使用例
128
+
129
+ ```bash
130
+ curl -X POST http://localhost:3002/v1/chat/completions \
131
+ -H "Authorization: Bearer token" \
132
+ -H "Content-Type: application/json" \
133
+ -d '{"model":"express","messages":[{"role":"user","content":"こんにちは"}]}'
134
+ ```
135
+
136
+ ## 環境変数
137
+
138
+ | 変数 | 説明 | デフォルト |
139
+ |------|------|------------|
140
+ | `YDC_API_KEY` | You.com API キー | 必須 |
141
+ | `YDC_API_KEYS` | 複数キー(カンマ区切り) | - |
142
+ | `YDC_KEY_MODE` | round-robin / sequential / random | round-robin |
143
+ | `YDC_OPENAI_PORT` | HTTP サーバーポート | 3002 |
144
+ | `YDC_CONVERSATION_STORE` | sqlite / memory | sqlite |
145
+ | `YDC_OPENAI_ACCESS_TOKENS` | 許可トークン(カンマ区切り) | - |
146
+ | `YDC_CUSTOM_AGENTS` | カスタム agents(name:id,name2:id2) | - |
147
+ | `YDC_AGENT_FAILURE_THRESHOLD` | you_agent 失敗閾値(無効化まで) | 3 |
148
+
149
+ ## PM2 デプロイ
150
+
151
+ PM2 を使用した本番環境デプロイ:
152
+
153
+ ```bash
154
+ # ecosystem 設定を使用
155
+ pm2 start ecosystem.config.cjs
156
+
157
+ # または直接コマンド(Windows)
158
+ pm2 start "cmd /c npx ydc-agent --openai --api-key YOUR_KEY" --name ydc
159
+ ```
160
+
161
+ ## Cloudflare Worker デプロイ
162
+
163
+ サーバーレス Cloudflare Worker としてデプロイ、D1 データベースで会話履歴を保存。
164
+
165
+ ### クイックデプロイ
166
+
167
+ [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/linuxdo-ref/ydc-agent&authed=true)
168
+
169
+ ### 手動デプロイ
170
+
171
+ 1. Cloudflare Dashboard で D1 データベースを作成
172
+ 2. Worker を作成し `cloudflare/worker.js` を貼り付け
173
+ 3. 環境変数を追加:`YDC_API_KEYS`、`ACCESS_TOKEN`(オプション)
174
+ 4. D1 データベースを `YDC_DB` としてバインド
175
+ 5. `/setup` にアクセスしてデータベースを初期化
176
+
177
+ ### Worker 機能
178
+
179
+ - OpenAI と Anthropic API 互換
180
+ - D1 データベースで会話履歴を保存
181
+ - 複数 API Key 対応(ランダム選択)
182
+ - カスタム agents(`CUSTOM_AGENTS` 環境変数経由)
183
+ - 設定ページ `/setup` で構成
184
+
185
+ 詳細は [cloudflare/README.md](cloudflare/README.md) を参照。
186
+
187
+ ## ライセンス
188
+
189
+ MIT
@@ -0,0 +1,189 @@
1
+ # ydc-agent
2
+
3
+ [![npm version](https://img.shields.io/npm/v/ydc-agent.svg)](https://www.npmjs.com/package/ydc-agent)
4
+ [![npm downloads](https://img.shields.io/npm/dm/ydc-agent.svg)](https://www.npmjs.com/package/ydc-agent)
5
+
6
+ You.com AI 代理的 MCP 服务器,支持 OpenAI 兼容 API。
7
+
8
+ ## MCP 配置
9
+
10
+ ### Claude Desktop / Cursor / Windsurf
11
+
12
+ 添加到 MCP 配置文件:
13
+
14
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
15
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
16
+ **Cursor/Windsurf**: `.cursor/mcp.json` 或 `.windsurf/mcp.json`
17
+
18
+ ```json
19
+ {
20
+ "mcpServers": {
21
+ "ydc-agent": {
22
+ "command": "npx",
23
+ "args": ["-y", "ydc-agent"],
24
+ "env": {
25
+ "YDC_API_KEY": "your-api-key"
26
+ }
27
+ }
28
+ }
29
+ }
30
+ ```
31
+
32
+ ### 多 API Key 配置
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "ydc-agent": {
38
+ "command": "npx",
39
+ "args": ["-y", "ydc-agent"],
40
+ "env": {
41
+ "YDC_API_KEYS": "key1,key2,key3",
42
+ "YDC_KEY_MODE": "round-robin"
43
+ }
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ Key 模式:`round-robin`(默认)、`sequential`、`random`
50
+
51
+ ## 可用 MCP 工具
52
+
53
+ | 工具 | 说明 |
54
+ |------|------|
55
+ | `you_search` | 网页与新闻搜索 |
56
+ | `you_express` | 快速 AI 回答 |
57
+ | `you_advanced` | 复杂推理(含计算/研究工具) |
58
+ | `you_agent` | 自定义 AI 代理(智能提示增强) |
59
+ | `you_chat` | OpenAI 兼容聊天(含对话历史) |
60
+ | `you_conversation_list` | 列出对话 |
61
+ | `you_conversation_get` | 获取对话历史 |
62
+ | `you_conversation_delete` | 删除对话 |
63
+ | `you_key_status` | API Key 使用统计 |
64
+ | `openai_server_control` | 启动/停止 OpenAI 兼容 HTTP 服务器 |
65
+
66
+ ### 内置 AI 引导功能
67
+
68
+ 工具描述中包含对 AI 调用方的引导:
69
+
70
+ | 工具 | 内置功能 |
71
+ |------|----------|
72
+ | `you_search` | 引导 AI 使用 `call_count=5+` 获取多元搜索结果 |
73
+ | `you_express` | 引导 AI 使用 `call_count=5+` 获取多元意见 |
74
+ | `you_advanced` | **AI 能力规则**:如果调用方是 GPT-3.5+,结果仅作为参考资料 - 应使用 `call_count=5+` 收集多元观点 |
75
+ | `you_agent` | **累错追踪**:自动追踪失败次数,超过阈值(默认 3 次)后建议切换到 `you_advanced` |
76
+
77
+ ## 模型 / Agent 类型
78
+
79
+ | 模型 | 说明 |
80
+ |------|------|
81
+ | `express` | 快速响应 |
82
+ | `research` | 深度分析 |
83
+ | `advanced-3.0-high` | 计算工具(默认) |
84
+ | `advanced-4.5-high-research` | 完整工具(计算 + 研究) |
85
+ | `<custom-agent-id>` | 任意自定义 You.com agent ID |
86
+
87
+ ### 自定义 Agent ID
88
+
89
+ 可使用任意 You.com 自定义 agent ID 作为 model 名称:
90
+
91
+ ```bash
92
+ curl -X POST http://localhost:3002/v1/chat/completions \
93
+ -H "Authorization: Bearer token" \
94
+ -H "Content-Type: application/json" \
95
+ -d '{"model":"your-custom-agent-uuid","messages":[{"role":"user","content":"你好"}]}'
96
+ ```
97
+
98
+ ## OpenAI 兼容服务器
99
+
100
+ 通过 npx 启动:
101
+
102
+ ```bash
103
+ # 单个 API key
104
+ npx ydc-agent --openai --api-key YOUR_API_KEY
105
+
106
+ # 多个 API keys(轮换)
107
+ npx ydc-agent --openai --api-keys KEY1,KEY2,KEY3
108
+
109
+ # 自定义 port 和 key 模式
110
+ npx ydc-agent --openai --api-keys KEY1,KEY2 --port 3003 --key-mode random
111
+
112
+ # 带 access token 验证
113
+ npx ydc-agent --openai --api-key YOUR_API_KEY --access-token SECRET
114
+
115
+ # 带自定义 agents(name:id 格式)
116
+ npx ydc-agent --openai --api-key YOUR_API_KEY --agent mybot:uuid-here --agent another:uuid2
117
+ ```
118
+
119
+ 或通过 MCP 工具 `openai_server_control`。
120
+
121
+ ### API 端点
122
+
123
+ - `POST /v1/chat/completions` - 聊天完成
124
+ - `GET /v1/models` - 列出模型
125
+ - `GET /health` - 健康检查
126
+
127
+ ### 使用示例
128
+
129
+ ```bash
130
+ curl -X POST http://localhost:3002/v1/chat/completions \
131
+ -H "Authorization: Bearer token" \
132
+ -H "Content-Type: application/json" \
133
+ -d '{"model":"express","messages":[{"role":"user","content":"你好"}]}'
134
+ ```
135
+
136
+ ## 环境变量
137
+
138
+ | 变量 | 说明 | 默认值 |
139
+ |------|------|--------|
140
+ | `YDC_API_KEY` | You.com API 密钥 | 必填 |
141
+ | `YDC_API_KEYS` | 多个密钥(逗号分隔) | - |
142
+ | `YDC_KEY_MODE` | round-robin / sequential / random | round-robin |
143
+ | `YDC_OPENAI_PORT` | HTTP 服务器端口 | 3002 |
144
+ | `YDC_CONVERSATION_STORE` | sqlite / memory | sqlite |
145
+ | `YDC_OPENAI_ACCESS_TOKENS` | 允许的 token(逗号分隔) | - |
146
+ | `YDC_CUSTOM_AGENTS` | 自定义 agents(name:id,name2:id2) | - |
147
+ | `YDC_AGENT_FAILURE_THRESHOLD` | you_agent 失败阈值(超过后停用) | 3 |
148
+
149
+ ## PM2 部署
150
+
151
+ 使用 PM2 进行生产环境部署:
152
+
153
+ ```bash
154
+ # 使用 ecosystem 配置
155
+ pm2 start ecosystem.config.cjs
156
+
157
+ # 或直接命令(Windows)
158
+ pm2 start "cmd /c npx ydc-agent --openai --api-key YOUR_KEY" --name ydc
159
+ ```
160
+
161
+ ## Cloudflare Worker 部署
162
+
163
+ 部署为无服务器 Cloudflare Worker,使用 D1 数据库存储对话历史。
164
+
165
+ ### 快速部署
166
+
167
+ [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/linuxdo-ref/ydc-agent&authed=true)
168
+
169
+ ### 手动部署
170
+
171
+ 1. 在 Cloudflare Dashboard 创建 D1 数据库
172
+ 2. 创建 Worker 并粘贴 `cloudflare/worker.js`
173
+ 3. 添加环境变量:`YDC_API_KEYS`、`ACCESS_TOKEN`(可选)
174
+ 4. 绑定 D1 数据库为 `YDC_DB`
175
+ 5. 访问 `/setup` 初始化数据库
176
+
177
+ ### Worker 功能
178
+
179
+ - OpenAI 与 Anthropic API 兼容
180
+ - D1 数据库存储对话历史
181
+ - 多 API Key 支持(随机选择)
182
+ - 自定义 agents(通过 `CUSTOM_AGENTS` 环境变量)
183
+ - 设置页面 `/setup` 进行配置
184
+
185
+ 详细说明请参阅 [cloudflare/README.md](cloudflare/README.md)。
186
+
187
+ ## 许可证
188
+
189
+ MIT