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.
@@ -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