@aiagenta2z/onekey-gateway 0.1.3 → 0.1.5
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 +66 -22
- package/dist/cli.js +161 -1
- package/dist/gateway.d.ts +97 -0
- package/dist/gateway.js +1049 -0
- package/dist/monitor.d.ts +9 -0
- package/dist/monitor.js +112 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# OneKey Gateway
|
|
2
2
|
AI Agent Gateway to Commercial APIs, Skills, MCPs and more using just one access key for most benefits.
|
|
3
|
+
Registry your APIs and omni converter to other formats: API2MCP,API2Skills,API2CLI and more.
|
|
3
4
|
|
|
4
5
|
[GitHub](https://github.com/aiagenta2z/onekey-gateway)|[Document](http://www.deepnlp.org/doc/onekey_gateway)|[AI Agent Marketplace](http://www.deepnlp.org/store/ai-agent)|[AI Agent Search](http://www.deepnlp.org/search/agent) | [AI Agent A2Z Deployment](https://deepnlp.org/doc/agent_mcp_deployment) | [Agent A2Z Payment](https://www.deepnlp.org/doc/agent_a2z_payment)
|
|
5
6
|
|
|
7
|
+
## Product Hunt
|
|
8
|
+
- Launch pack: `docs/product-hunt/LAUNCH_CHECKLIST.md`
|
|
9
|
+
- Templates: `docs/product-hunt/TEMPLATES.md`
|
|
10
|
+
- Runbook: `docs/product-hunt/RUNBOOK.md`
|
|
11
|
+
- Weekly AI agent launch digest (email): `onekey ph-digest --days 7`
|
|
12
|
+
|
|
6
13
|
**Onekey Gateway** focuses on commercial agent APIs/MCPs/Skills, which typically require multiple subscriptions or access keys for web search,image generation, financial data, 3D rendering.
|
|
7
14
|
Our mission is to help users authenticate once and enjoy the most benefits, discounted, pay-as-you-go usage. Accessing Agent APIs, MCPs, and LLMs across 30+ categories and 100+ tools via our credit system,
|
|
8
|
-
you can eliminate multiple expensive subscriptions and maximize your benefits. More SOTA agent/models are available in the [DeepNLP AI Agent Mareketplace](https://deepnlp.org/store/ai-agent).
|
|
15
|
+
you can eliminate multiple expensive subscriptions and maximize your benefits. More SOTA agent/models are available in the [DeepNLP AI Agent Mareketplace](https://www.deepnlp.org/store/ai-agent).
|
|
9
16
|
|
|
10
17
|
## Overview
|
|
11
18
|
[OneKey Gateway Document](https://www.deepnlp.org/doc/onekey_gateway)
|
|
@@ -19,6 +26,8 @@ OneKey Gateway provides CLI tool, Restful API, MCP, Skills and Python/Typescript
|
|
|
19
26
|
| LLM | Allow your AI clients to call LLM endpoint proxy [OneKey LLM Router Doc](https://www.deepnlp.org/doc/onekey_llm_router) | https://agent.deepnlp.org/llm | `onekey llm` |
|
|
20
27
|
|
|
21
28
|
|
|
29
|
+
Want to register your API? See the top ranked onekey gateway called [Agent API Skills MCP Calls Ranking](https://deepnlp.org/agent/rankings)
|
|
30
|
+
|
|
22
31
|
| Gateway Type | Description |
|
|
23
32
|
|---------------------------------------------------|----------------------------------------------------------------------------------------|
|
|
24
33
|
| Register Your New API | [OneKey Gateway Registry Documents](https://www.deepnlp.org/doc/onekey_agent_registry) |
|
|
@@ -139,7 +148,7 @@ prompt:
|
|
|
139
148
|
|
|
140
149
|
```bash
|
|
141
150
|
export DEEPNLP_ONEKEY_ROUTER_ACCESS=YOUR_ACCESS_KEY
|
|
142
|
-
onekey agent craftsman-agent/craftsman-agent generate_lego_build_plan '{"prompt":"Build Lego yacht with 5 decks using blue and white bricks","images":[],"mode":"basic"}' --timeout
|
|
151
|
+
onekey agent craftsman-agent/craftsman-agent generate_lego_build_plan '{"prompt":"Build Lego yacht with 5 decks using blue and white bricks","images":[],"mode":"basic"}' --timeout 60000
|
|
143
152
|
```
|
|
144
153
|
|
|
145
154
|
3D Step by Step Assembly Charts
|
|
@@ -147,6 +156,22 @@ onekey agent craftsman-agent/craftsman-agent generate_lego_build_plan '{"prompt"
|
|
|
147
156
|
<img src="https://raw.githubusercontent.com/AI-Hub-Admin/Craftsman-Agent/refs/heads/main/docs/craftsman_agent_2.jpg" style="width:500px" alt="Image generation">
|
|
148
157
|
|
|
149
158
|
|
|
159
|
+
### Example 4. Generate Tesla Car Wrap
|
|
160
|
+
|
|
161
|
+
prompt: model YL F1 race car blue and purple with stars
|
|
162
|
+
model: tesla_model_yl
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
export DEEPNLP_ONEKEY_ROUTER_ACCESS=YOUR_ACCESS_KEY
|
|
166
|
+
npx onekey agent craftsman-agent/craftsman-agent generate_tesla_wraps '{"prompt":"I would like to paint my tesla model YL similar to F1 race car, color of a blue and purple with stars","images":[],"mode":"basic","car_model":"tesla_model_yl","output_number":1}'
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
<img src="https://raw.githubusercontent.com/AI-Hub-Admin/Craftsman-Agent/refs/heads/main/docs/model_yl_racing.png" style="width:500px" alt="Tesla Model YL">
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
{"success":true,"text":"","images":[{"url":"https://us-static.aiagenta2z.com/local/files-wd/onekey_llm_router/722aa763-ec48-48b5-acfd-c569f89ffc50.png"}]}
|
|
173
|
+
```
|
|
174
|
+
|
|
150
175
|
|
|
151
176
|
## Tutorial
|
|
152
177
|
|
|
@@ -162,7 +187,7 @@ Supported ids can be found in the table below.
|
|
|
162
187
|
**CLI**
|
|
163
188
|
|
|
164
189
|
```bash
|
|
165
|
-
onekey agent google-maps/google-maps maps_search_places '{"query":"New York City Italian Restaurants"}' --timeout
|
|
190
|
+
onekey agent google-maps/google-maps maps_search_places '{"query":"New York City Italian Restaurants"}' --timeout 60000
|
|
166
191
|
```
|
|
167
192
|
|
|
168
193
|
**Skills**
|
|
@@ -204,28 +229,29 @@ Put below config into your clients
|
|
|
204
229
|
### OneKey LLM Router
|
|
205
230
|
Call Gemini 3 LLM and Image Nano Banana model
|
|
206
231
|
```bash
|
|
207
|
-
onekey llm --provider gemini --model gemini-3-flash-preview --messages @messages.json --temperature 0.7 --response-format json --timeout
|
|
232
|
+
onekey llm --provider gemini --model gemini-3-flash-preview --messages @messages.json --temperature 0.7 --response-format json --timeout 60000
|
|
208
233
|
```
|
|
209
234
|
|
|
210
235
|
## Gateway Categories
|
|
211
236
|
|
|
212
|
-
| Domain | Unique Id | Skill ID | API ID
|
|
213
|
-
|
|
214
|
-
| Map (Google) | google-maps/google-maps [Doc](./docs/google-maps/README.md) | google-maps | maps_directions<br>maps_distance_matrix<br>maps_elevation<br>maps_geocode<br>maps_place_details<br>maps_reverse_geocode<br>maps_search_places
|
|
215
|
-
| Map (Amap/Gaode Map) | amap-maps-streamableHTTP/amap-maps-streamableHTTP [Doc](./docs/amap-maps-streamableHTTP/README.md) | amap-maps-streamableHTTP | maps_around_search<br>maps_direction_bicycling<br>maps_direction_driving<br>maps_direction_transit_integrated<br>maps_direction_walking<br>maps_distance<br>maps_geo<br>maps_ip_location<br>maps_regeocode<br>maps_schema_navi<br>maps_schema_personal_map<br>maps_schema_take_taxi<br>maps_search_detail<br>maps_text_search<br>maps_weather
|
|
216
|
-
| Map (Baidu) | baidu-maps-sse/baidu-maps-sse [Doc](./docs/baidu-maps-sse/README.md) | baidu-maps-sse | maps_directions<br>maps_distance_matrix<br>maps_elevation<br>maps_geocode<br>maps_place_details<br>maps_reverse_geocode<br>maps_search_places
|
|
217
|
-
| Image Search | bing-image-search-mcp/bing-image-search-mcp [Doc](./docs/bing-image-search-mcp/README.md) | bing-image-search-mcp | search_images<br>search_images_batch
|
|
218
|
-
| Web Search | brave-search/brave-search [Doc](./docs/brave-search/README.md) | brave-search | brave_local_search<br>brave_web_search
|
|
219
|
-
| Web Search | google-search/google-search [Doc](./docs/google-search/README.md) | google-search | google_search
|
|
220
|
-
| Web Search | tavily-remote-mcp/tavily-remote-mcp [Doc](./docs/tavily-remote-mcp/README.md) | tavily-remote-mcp | tavily_crawl<br>tavily_extract<br>tavily_map<br>tavily_research<br>tavily_search
|
|
221
|
-
| Web Crawl / Browser | firecrawl-mcp/firecrawl-mcp [Doc](./docs/firecrawl-mcp/README.md) | firecrawl-mcp | firecrawl_agent<br>firecrawl_agent_status<br>firecrawl_browser_create<br>firecrawl_browser_delete<br>firecrawl_browser_execute<br>firecrawl_browser_list<br>firecrawl_check_crawl_status<br>firecrawl_crawl<br>firecrawl_extract<br>firecrawl_map<br>firecrawl_scrape<br>firecrawl_search
|
|
222
|
-
| Image Generation | gemini/gemini [Doc](./docs/gemini/README.md) | gemini (Nano Banana) | generate_image_gemini<br>generate_image_nano_banana<br>generate_image_nano_banana_with_reference<br>ocr_extract_text_from_image<br>list_items_from_image
|
|
223
|
-
| Image Generation | gemini-nano-banana/gemini-nano-banana [Doc](./docs/gemini-nano-banana/README.md) | gemini-nano-banana | generate_image_gemini<br>generate_image_nano_banana<br>generate_image_nano_banana_with_reference<br>ocr_extract_text_from_image<br>list_items_from_image
|
|
237
|
+
| Domain | Unique Id | Skill ID | API ID |
|
|
238
|
+
|----------------------|----------------------------------------------------------------------------------------------------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
239
|
+
| Map (Google) | google-maps/google-maps [Doc](./docs/google-maps/README.md) | google-maps | maps_directions<br>maps_distance_matrix<br>maps_elevation<br>maps_geocode<br>maps_place_details<br>maps_reverse_geocode<br>maps_search_places |
|
|
240
|
+
| Map (Amap/Gaode Map) | amap-maps-streamableHTTP/amap-maps-streamableHTTP [Doc](./docs/amap-maps-streamableHTTP/README.md) | amap-maps-streamableHTTP | maps_around_search<br>maps_direction_bicycling<br>maps_direction_driving<br>maps_direction_transit_integrated<br>maps_direction_walking<br>maps_distance<br>maps_geo<br>maps_ip_location<br>maps_regeocode<br>maps_schema_navi<br>maps_schema_personal_map<br>maps_schema_take_taxi<br>maps_search_detail<br>maps_text_search<br>maps_weather |
|
|
241
|
+
| Map (Baidu) | baidu-maps-sse/baidu-maps-sse [Doc](./docs/baidu-maps-sse/README.md) | baidu-maps-sse | maps_directions<br>maps_distance_matrix<br>maps_elevation<br>maps_geocode<br>maps_place_details<br>maps_reverse_geocode<br>maps_search_places |
|
|
242
|
+
| Image Search | bing-image-search-mcp/bing-image-search-mcp [Doc](./docs/bing-image-search-mcp/README.md) | bing-image-search-mcp | search_images<br>search_images_batch |
|
|
243
|
+
| Web Search | brave-search/brave-search [Doc](./docs/brave-search/README.md) | brave-search | brave_local_search<br>brave_web_search |
|
|
244
|
+
| Web Search | google-search/google-search [Doc](./docs/google-search/README.md) | google-search | google_search |
|
|
245
|
+
| Web Search | tavily-remote-mcp/tavily-remote-mcp [Doc](./docs/tavily-remote-mcp/README.md) | tavily-remote-mcp | tavily_crawl<br>tavily_extract<br>tavily_map<br>tavily_research<br>tavily_search |
|
|
246
|
+
| Web Crawl / Browser | firecrawl-mcp/firecrawl-mcp [Doc](./docs/firecrawl-mcp/README.md) | firecrawl-mcp | firecrawl_agent<br>firecrawl_agent_status<br>firecrawl_browser_create<br>firecrawl_browser_delete<br>firecrawl_browser_execute<br>firecrawl_browser_list<br>firecrawl_check_crawl_status<br>firecrawl_crawl<br>firecrawl_extract<br>firecrawl_map<br>firecrawl_scrape<br>firecrawl_search |
|
|
247
|
+
| Image Generation | gemini/gemini [Doc](./docs/gemini/README.md) | gemini (Nano Banana) | generate_image_gemini<br>generate_image_nano_banana<br>generate_image_nano_banana_with_reference<br>ocr_extract_text_from_image<br>list_items_from_image |
|
|
248
|
+
| Image Generation | gemini-nano-banana/gemini-nano-banana [Doc](./docs/gemini-nano-banana/README.md) | gemini-nano-banana | generate_image_gemini<br>generate_image_nano_banana<br>generate_image_nano_banana_with_reference<br>ocr_extract_text_from_image<br>list_items_from_image |
|
|
224
249
|
| Charts | mcp-server-chart/mcp-server-chart [Doc](./docs/mcp-server-chart/README.md) | mcp-server-chart | generate_area_chart<br>generate_bar_chart<br>generate_boxplot_chart<br>generate_column_chart<br>generate_district_map<br>generate_dual_axes_chart<br>generate_fishbone_diagram<br>generate_flow_diagram<br>generate_funnel_chart<br>generate_histogram_chart<br>generate_line_chart<br>generate_liquid_chart<br>generate_mind_map<br>generate_network_graph<br>generate_organization_chart<br>generate_path_map<br>generate_pie_chart<br>generate_pin_map<br>generate_radar_chart<br>generate_sankey_chart<br>generate_scatter_chart<br>generate_spreadsheet<br>generate_treemap_chart<br>generate_venn_chart<br>generate_violin_chart<br>generate_waterfall_chart<br>generate_word_cloud_chart |
|
|
225
|
-
| Research QA | perplexity/perplexity [Doc](./docs/perplexity/README.md) | perplexity | perplexity_ask<br>perplexity_reason<br>perplexity_research<br>perplexity_search
|
|
226
|
-
| 3D Generation | craftsman-agent/craftsman-agent [Doc](./docs/craftsman-agent/README.md) | craftsman-agent | generate_lego_build_plan<br>generate_minecraft_build_plan<br>generate_tesla_wraps
|
|
227
|
-
| Finance | aiagenta2z/financeagent [Doc](./docs
|
|
228
|
-
|
|
250
|
+
| Research QA | perplexity/perplexity [Doc](./docs/perplexity/README.md) | perplexity | perplexity_ask<br>perplexity_reason<br>perplexity_research<br>perplexity_search |
|
|
251
|
+
| 3D Generation | craftsman-agent/craftsman-agent [Doc](./docs/craftsman-agent/README.md) | craftsman-agent | generate_lego_build_plan<br>generate_minecraft_build_plan<br>generate_tesla_wraps |
|
|
252
|
+
| Finance | aiagenta2z/financeagent [Doc](./docs/financeagent/README.md) | financeagent | get_hk_stock_market_hkex<br>get_cn_stock_market_shanghai_shenzhen<br>get_us_stock_market_nyse_nasdaq_dow<br>get_uk_stock_market_lse<br>get_india_stock_market_nse_india |
|
|
253
|
+
| Healthcare | fdcnal/usda-fooddata-central-agent [Doc](./docs/healthcare/README.md) | usda-fooddata-central-agent | get_foods_multiple<br>get_food_by_id<br>list_foods<br>search_foods |
|
|
254
|
+
| Healthcare | aiagenta2z/healthcaregent [Doc](./docs/healthcare/README.md) | healthcareagent | |
|
|
229
255
|
|
|
230
256
|
|
|
231
257
|
#### Example 1: Google Maps Search
|
|
@@ -265,6 +291,26 @@ https://us-static.aiagenta2z.com/local/files-wd/user_2177/7629e198-b10c-4a8b-8f6
|
|
|
265
291
|
```
|
|
266
292
|
|
|
267
293
|
|
|
294
|
+
#### OneKey Gateway CLI
|
|
295
|
+
|
|
296
|
+
Use OneKey Agent Gateway `gateway` commands to use the AI Agent Orchestration timetable to connect your local codex/claude code/gemini agent to
|
|
297
|
+
the Human-Agent Collaborative timetable, fetching agent tasks by pull method from Coachowl AI Agent Timetable.
|
|
298
|
+
See [CoachOwl Website](https://coachowl.aiagenta2z.com/index) and [CoachOwl GitHub](https://github.com/AI-Hub-Admin/CoachOwl-Agent-Timetable) for more details of usage.
|
|
299
|
+
|
|
300
|
+
```shell
|
|
301
|
+
export DEEPNLP_ONEKEY_ROUTER_ACCESS=${YOUR_ACCESS_KEY}
|
|
302
|
+
## Running
|
|
303
|
+
# Locally Fetch Task from Endpoint at http://0.0.0.0:7115
|
|
304
|
+
# Production: https://coachowl.aiagenta2z.com
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
### Debug Local Mode Usage
|
|
308
|
+
npx onekey gateway coachowl/coachowl --foreground --env local
|
|
309
|
+
|
|
310
|
+
### Production Background Task Usage: --env production, runs in background
|
|
311
|
+
npx onekey gateway coachowl/coachowl
|
|
312
|
+
```
|
|
313
|
+
|
|
268
314
|
### Related
|
|
269
315
|
[OneKey Gateway Documentation](https://www.deepnlp.org/doc/onekey_gateway)
|
|
270
316
|
[AI Agent Marketplace](https://www.deepnlp.org/store/ai-agent)
|
|
@@ -273,5 +319,3 @@ https://us-static.aiagenta2z.com/local/files-wd/user_2177/7629e198-b10c-4a8b-8f6
|
|
|
273
319
|
[Agent Infra Deployment](https://www.deepnlp.org/workspace/deploy)
|
|
274
320
|
[A2Z Payment SDK](https://www.deepnlp.org/agent/agent-a2z-payment)
|
|
275
321
|
|
|
276
|
-
|
|
277
|
-
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
7
|
const client_1 = require("./client");
|
|
8
|
+
const gateway_1 = require("./gateway");
|
|
9
|
+
const monitor_1 = require("./monitor");
|
|
5
10
|
const fs_1 = require("fs");
|
|
11
|
+
const child_process_1 = require("child_process");
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
6
13
|
const DEFAULT_TIMEOUT_MS = 60000;
|
|
7
14
|
function parseArgs(argv) {
|
|
8
15
|
const flags = {};
|
|
@@ -66,6 +73,12 @@ function resolveAccessKey(flags) {
|
|
|
66
73
|
}
|
|
67
74
|
return client_1.constants.DEFAULT_ACCESS_KEY;
|
|
68
75
|
}
|
|
76
|
+
// default value for interval in seconds
|
|
77
|
+
function resolveInterval(flags) {
|
|
78
|
+
if (typeof flags.interval === "string")
|
|
79
|
+
return flags.interval;
|
|
80
|
+
return "600"; // seconds
|
|
81
|
+
}
|
|
69
82
|
function warnIfUsingDefault(accessKey, flags) {
|
|
70
83
|
const keyFlag = flags.key;
|
|
71
84
|
const envKey = process.env.DEEPNLP_ONEKEY_ROUTER_ACCESS;
|
|
@@ -81,16 +94,25 @@ Usage:
|
|
|
81
94
|
onekey mcp <server_name> [--name config_name] [--timeout <ms>]
|
|
82
95
|
onekey llm --provider <provider> --model <model> --messages <json|@file> [--temperature <num>] [--response-format <format>] [--options <json|@file>] [--timeout <ms>]
|
|
83
96
|
onekey llm --payload <json|@file> [--timeout <ms>]
|
|
97
|
+
onekey gateway <unique_id> [--mode pull|callback] [--env local|production] [--port 18000] [--interval 900]
|
|
98
|
+
onekey monitor [--url <url>] [--interval <seconds>] [--timeout <ms>] [--webhook <url>] [--fail-after <n>] [--once]
|
|
99
|
+
onekey ph-digest [--days 7] [--to <email>] [--from <email>] [--send] [--subject <text>]
|
|
100
|
+
[--smtp-url <url> | --smtp-host <host> [--smtp-port <port>] [--smtp-user <user>] [--smtp-pass <pass>]]
|
|
84
101
|
|
|
85
102
|
Flags:
|
|
86
103
|
--key <access_key> Override DEEPNLP_ONEKEY_ROUTER_ACCESS
|
|
87
104
|
--timeout <ms> Request timeout in milliseconds (float, default ${DEFAULT_TIMEOUT_MS})
|
|
105
|
+
--foreground Run gateway in foreground (default: background)
|
|
106
|
+
--log <path> Background log file or directory (default: .onekey/onekey-gateway.log)
|
|
88
107
|
--help Show help
|
|
89
108
|
|
|
90
109
|
Examples:
|
|
91
110
|
onekey agent google-maps/google-maps maps_search_places '{"query":"New York City Italian Restaurants"}'
|
|
111
|
+
onekey agent craftsman-agent/craftsman-agent generate_tesla_wraps '{"prompt":"I would like to paint my tesla model YL similar to F1 race car, color of a blue and purple with stars","images":[],"mode":"basic","car_model":"tesla_model_y_2025_base","output_number":1}' --timeout 60000
|
|
92
112
|
onekey mcp google-maps
|
|
93
|
-
onekey llm --provider gemini --model gemini-3-flash-preview --messages @messages.json --temperature 0.7 --response-format json --timeout
|
|
113
|
+
onekey llm --provider gemini --model gemini-3-flash-preview --messages @messages.json --temperature 0.7 --response-format json --timeout 60000
|
|
114
|
+
onekey monitor --url http://127.0.0.1:18000/healthz --interval 10 --webhook <optional>
|
|
115
|
+
onekey ph-digest --days 7
|
|
94
116
|
`;
|
|
95
117
|
process.stdout.write(text);
|
|
96
118
|
}
|
|
@@ -196,6 +218,138 @@ async function runLlm(positionals, flags) {
|
|
|
196
218
|
const result = await (0, client_1.llmRouter)(payload, accessKey, { timeoutMs });
|
|
197
219
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
198
220
|
}
|
|
221
|
+
async function runGateway(positionals, flags) {
|
|
222
|
+
const isForeground = Boolean(flags.foreground || flags.fg);
|
|
223
|
+
// Background by default: spawn a detached child and return PID
|
|
224
|
+
if (!isForeground) {
|
|
225
|
+
const rawLogFlag = typeof flags.log === "string" ? flags.log : undefined;
|
|
226
|
+
let logPath = rawLogFlag ?? path_1.default.join(".onekey", "onekey-gateway.log");
|
|
227
|
+
// If a directory is provided, write default filename inside it.
|
|
228
|
+
try {
|
|
229
|
+
if (logPath.endsWith(path_1.default.sep) ||
|
|
230
|
+
((0, fs_1.existsSync)(logPath) && (0, fs_1.statSync)(logPath).isDirectory())) {
|
|
231
|
+
logPath = path_1.default.join(logPath, "onekey-gateway.log");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
// ignore stat failures; openSync will surface errors
|
|
236
|
+
}
|
|
237
|
+
(0, fs_1.mkdirSync)(path_1.default.dirname(logPath), { recursive: true });
|
|
238
|
+
const outFd = (0, fs_1.openSync)(logPath, "a");
|
|
239
|
+
const errFd = (0, fs_1.openSync)(logPath, "a");
|
|
240
|
+
const argv = process.argv.slice(1); // [cli.js, ...]
|
|
241
|
+
const childArgv = [
|
|
242
|
+
...argv,
|
|
243
|
+
"--foreground",
|
|
244
|
+
...(rawLogFlag ? [] : ["--log", logPath])
|
|
245
|
+
];
|
|
246
|
+
const child = (0, child_process_1.spawn)(process.execPath, childArgv, {
|
|
247
|
+
detached: true,
|
|
248
|
+
stdio: ["ignore", outFd, errFd]
|
|
249
|
+
});
|
|
250
|
+
child.unref();
|
|
251
|
+
(0, fs_1.closeSync)(outFd);
|
|
252
|
+
(0, fs_1.closeSync)(errFd);
|
|
253
|
+
process.stdout.write("OneKey Gateway started successfully in background mode.\n");
|
|
254
|
+
process.stdout.write(`Logs: ${logPath}\n`);
|
|
255
|
+
if (child.pid)
|
|
256
|
+
process.stdout.write(`PID: ${child.pid}\n`);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const accessKey = resolveAccessKey(flags);
|
|
260
|
+
warnIfUsingDefault(accessKey, flags);
|
|
261
|
+
const timeoutMs = parseTimeoutMs(flags);
|
|
262
|
+
await (0, gateway_1.runGateway)(positionals, { ...flags, interval: resolveInterval(flags), key: accessKey, timeout: String(timeoutMs) });
|
|
263
|
+
}
|
|
264
|
+
function parseIntFlag(flags, key, fallback) {
|
|
265
|
+
const raw = flags[key];
|
|
266
|
+
if (raw === undefined)
|
|
267
|
+
return fallback;
|
|
268
|
+
if (raw === true)
|
|
269
|
+
throw new Error(`--${key} requires a value`);
|
|
270
|
+
if (typeof raw !== "string")
|
|
271
|
+
return fallback;
|
|
272
|
+
const n = Number(raw.trim());
|
|
273
|
+
if (!Number.isFinite(n))
|
|
274
|
+
throw new Error(`--${key} must be a number`);
|
|
275
|
+
return Math.floor(n);
|
|
276
|
+
}
|
|
277
|
+
async function runMonitorCmd(positionals, flags) {
|
|
278
|
+
if (positionals.length > 0) {
|
|
279
|
+
throw new Error("monitor does not take positionals");
|
|
280
|
+
}
|
|
281
|
+
const url = typeof flags.url === "string" ? flags.url : "http://127.0.0.1:18000/health";
|
|
282
|
+
const intervalSeconds = parseIntFlag(flags, "interval", 10);
|
|
283
|
+
const timeoutMs = parseIntFlag(flags, "timeout", 5000);
|
|
284
|
+
const failAfter = parseIntFlag(flags, "fail-after", 3);
|
|
285
|
+
const webhookUrl = typeof flags.webhook === "string" ? flags.webhook : undefined;
|
|
286
|
+
const once = Boolean(flags.once);
|
|
287
|
+
if (intervalSeconds <= 0)
|
|
288
|
+
throw new Error("--interval must be > 0 (seconds)");
|
|
289
|
+
if (timeoutMs <= 0)
|
|
290
|
+
throw new Error("--timeout must be > 0 (ms)");
|
|
291
|
+
if (failAfter <= 0)
|
|
292
|
+
throw new Error("--fail-after must be > 0");
|
|
293
|
+
await (0, monitor_1.runMonitor)({
|
|
294
|
+
url,
|
|
295
|
+
intervalMs: intervalSeconds * 1000,
|
|
296
|
+
timeoutMs,
|
|
297
|
+
webhookUrl,
|
|
298
|
+
failAfter,
|
|
299
|
+
once
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
//
|
|
303
|
+
// async function runPhDigest(positionals: string[], flags: Record<string, string | boolean>) {
|
|
304
|
+
// if (positionals.length > 0) {
|
|
305
|
+
// throw new Error("ph-digest does not take positionals");
|
|
306
|
+
// }
|
|
307
|
+
//
|
|
308
|
+
// const days = parseIntFlag(flags, "days", 7);
|
|
309
|
+
// if (days <= 0 || days > 60) throw new Error("--days must be between 1 and 60");
|
|
310
|
+
//
|
|
311
|
+
// const now = new Date();
|
|
312
|
+
// const entries = await fetchProductHuntAiAgentDigest({ days, now });
|
|
313
|
+
// const markdown = renderDigestMarkdown(entries, { days, now });
|
|
314
|
+
//
|
|
315
|
+
// const shouldSend = Boolean(flags.send);
|
|
316
|
+
// if (!shouldSend) {
|
|
317
|
+
// process.stdout.write(markdown);
|
|
318
|
+
// return;
|
|
319
|
+
// }
|
|
320
|
+
//
|
|
321
|
+
// const to = typeof flags.to === "string" ? flags.to : undefined;
|
|
322
|
+
// const from = typeof flags.from === "string" ? flags.from : undefined;
|
|
323
|
+
// if (!to) throw new Error("--to is required when using --send");
|
|
324
|
+
// if (!from) throw new Error("--from is required when using --send");
|
|
325
|
+
//
|
|
326
|
+
// const subject =
|
|
327
|
+
// typeof flags.subject === "string" ? flags.subject : `Product Hunt AI agent launches (last ${days} days)`;
|
|
328
|
+
//
|
|
329
|
+
// const smtpUrl = typeof flags["smtp-url"] === "string" ? flags["smtp-url"] : process.env.SMTP_URL;
|
|
330
|
+
// const smtpHost = typeof flags["smtp-host"] === "string" ? flags["smtp-host"] : process.env.SMTP_HOST;
|
|
331
|
+
// const smtpPortRaw = typeof flags["smtp-port"] === "string" ? flags["smtp-port"] : process.env.SMTP_PORT;
|
|
332
|
+
// const smtpPort = smtpPortRaw ? Number(smtpPortRaw) : undefined;
|
|
333
|
+
// const smtpUser = typeof flags["smtp-user"] === "string" ? flags["smtp-user"] : process.env.SMTP_USER;
|
|
334
|
+
// const smtpPass = typeof flags["smtp-pass"] === "string" ? flags["smtp-pass"] : process.env.SMTP_PASS;
|
|
335
|
+
//
|
|
336
|
+
// if (!smtpUrl && !smtpHost) {
|
|
337
|
+
// throw new Error("Missing SMTP configuration. Provide --smtp-url or set SMTP_URL (or SMTP_HOST).");
|
|
338
|
+
// }
|
|
339
|
+
//
|
|
340
|
+
// await sendDigestEmail({
|
|
341
|
+
// to,
|
|
342
|
+
// from,
|
|
343
|
+
// subject,
|
|
344
|
+
// markdown,
|
|
345
|
+
// smtpUrl,
|
|
346
|
+
// smtpHost,
|
|
347
|
+
// smtpPort: smtpPort && Number.isFinite(smtpPort) ? Math.floor(smtpPort) : undefined,
|
|
348
|
+
// smtpUser,
|
|
349
|
+
// smtpPass
|
|
350
|
+
// });
|
|
351
|
+
// process.stdout.write(`Sent digest to ${to}\n`);
|
|
352
|
+
// }
|
|
199
353
|
async function main() {
|
|
200
354
|
const parsed = parseArgs(process.argv.slice(2));
|
|
201
355
|
const { command, positionals, flags } = parsed;
|
|
@@ -214,6 +368,12 @@ async function main() {
|
|
|
214
368
|
case "llm":
|
|
215
369
|
await runLlm(positionals, flags);
|
|
216
370
|
return;
|
|
371
|
+
case "gateway":
|
|
372
|
+
await runGateway(positionals, flags);
|
|
373
|
+
return;
|
|
374
|
+
case "monitor":
|
|
375
|
+
await runMonitorCmd(positionals, flags);
|
|
376
|
+
return;
|
|
217
377
|
default:
|
|
218
378
|
throw new Error(`Unknown command: ${command}`);
|
|
219
379
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
type GatewayRoutes = {
|
|
2
|
+
get_tasks: string;
|
|
3
|
+
claim_task: string;
|
|
4
|
+
post_result: string;
|
|
5
|
+
update_health: string;
|
|
6
|
+
update_log: string;
|
|
7
|
+
};
|
|
8
|
+
type GatewayProfile = {
|
|
9
|
+
endpoint: string;
|
|
10
|
+
auth_header: string;
|
|
11
|
+
routes: GatewayRoutes;
|
|
12
|
+
agents_clis?: string[];
|
|
13
|
+
};
|
|
14
|
+
type GatewayEndpointConfig = Record<string, {
|
|
15
|
+
local?: GatewayProfile;
|
|
16
|
+
production?: GatewayProfile;
|
|
17
|
+
}>;
|
|
18
|
+
type GetTasksResponse = {
|
|
19
|
+
success?: boolean;
|
|
20
|
+
tasks?: any[];
|
|
21
|
+
connected_agents?: string[];
|
|
22
|
+
};
|
|
23
|
+
export declare const COACHOWL_TIMETABLE_GATEWAY = "https://coachowl.aiagenta2z.com";
|
|
24
|
+
export declare const DEFAULT_LOCAL_GATEWAY = "http://0.0.0.0:7115";
|
|
25
|
+
export declare function loadConfigFile(filePath: string): unknown | null;
|
|
26
|
+
export declare function loadGatewayEndpointConfigSync(): GatewayEndpointConfig;
|
|
27
|
+
export declare function resolveGatewayProfile(uniqueId: string, mode?: "local" | "production"): GatewayProfile;
|
|
28
|
+
/**
|
|
29
|
+
"local": {
|
|
30
|
+
"endpoint": "http://0.0.0.0:7115",
|
|
31
|
+
"auth_header": "X-OneKey",
|
|
32
|
+
"routes": {
|
|
33
|
+
"get_tasks": "/api/v1/agent/tasks/get",
|
|
34
|
+
"claim_task": "/api/v1/agent/tasks/claim",
|
|
35
|
+
"post_result": "/api/v1/agent/tasks/post"
|
|
36
|
+
},
|
|
37
|
+
"agents_clis": ["codex","gemini","claude","openclaw"]
|
|
38
|
+
}
|
|
39
|
+
*/
|
|
40
|
+
export declare function getAgentTasks(accessKey: string, profileOrGatewayUrl?: GatewayProfile | string): Promise<GetTasksResponse>;
|
|
41
|
+
export declare function claimAgentTask(accessKey: string, payload: {
|
|
42
|
+
agent_id: string;
|
|
43
|
+
agent_name?: string;
|
|
44
|
+
habit_id: string;
|
|
45
|
+
execution_date: string;
|
|
46
|
+
}, profileOrGatewayUrl?: GatewayProfile | string): Promise<any>;
|
|
47
|
+
export type AgentResult = {
|
|
48
|
+
success: boolean;
|
|
49
|
+
content: string;
|
|
50
|
+
exitCode: number | null;
|
|
51
|
+
error?: string;
|
|
52
|
+
};
|
|
53
|
+
export declare function runLocalAgent(cli: string, prompt: string, accessKey: string, profile: GatewayProfile, executionContext: any, timeoutMs?: number, opts?: {
|
|
54
|
+
cwd?: string;
|
|
55
|
+
taskDir?: string;
|
|
56
|
+
}): Promise<AgentResult>;
|
|
57
|
+
export declare function runCodex(prompt: string, accessKey: string, profile: GatewayProfile, executionContext: any, timeoutMs?: number, opts?: {
|
|
58
|
+
cwd?: string;
|
|
59
|
+
taskDir?: string;
|
|
60
|
+
}): Promise<AgentResult>;
|
|
61
|
+
export declare function runGemini(prompt: string, accessKey: string, profile: GatewayProfile, executionContext: any, timeoutMs?: number, opts?: {
|
|
62
|
+
cwd?: string;
|
|
63
|
+
taskDir?: string;
|
|
64
|
+
}): Promise<AgentResult>;
|
|
65
|
+
export declare function runClaude(prompt: string, accessKey: string, profile: GatewayProfile, executionContext: any, timeoutMs?: number, opts?: {
|
|
66
|
+
cwd?: string;
|
|
67
|
+
taskDir?: string;
|
|
68
|
+
}): Promise<AgentResult>;
|
|
69
|
+
export declare function runGenericCLI(cli: string, args: string[], timeoutMs?: number, label?: string, cwd?: string, taskDir?: string): Promise<AgentResult>;
|
|
70
|
+
export declare function runGenericCLIWithMonitor(cli: string, args: string[], accessKey: string, profile: GatewayProfile, executionContext: {
|
|
71
|
+
habit_id?: string;
|
|
72
|
+
execution_id?: string;
|
|
73
|
+
root_execution_id?: string;
|
|
74
|
+
agent_id?: string;
|
|
75
|
+
agent_name?: string;
|
|
76
|
+
}, timeoutMs?: number, label?: string, cwd?: string, taskDir?: string): Promise<AgentResult>;
|
|
77
|
+
export declare function postAgentTaskResult(accessKey: string, result: {
|
|
78
|
+
habit_id: string;
|
|
79
|
+
execution_id: string;
|
|
80
|
+
root_execution_id: string;
|
|
81
|
+
content: string;
|
|
82
|
+
images?: any[];
|
|
83
|
+
agent_id: string;
|
|
84
|
+
status: "starting" | "running" | "completed";
|
|
85
|
+
agent_name: string;
|
|
86
|
+
}, profileOrGatewayUrl?: GatewayProfile | string): Promise<any>;
|
|
87
|
+
type GatewayRuntimeContext = {
|
|
88
|
+
uniqueId: string;
|
|
89
|
+
accessKey?: string;
|
|
90
|
+
profile: GatewayProfile;
|
|
91
|
+
timeoutMs: number;
|
|
92
|
+
concurrency: number;
|
|
93
|
+
};
|
|
94
|
+
export declare function startPullWorker(ctx: GatewayRuntimeContext, intervalMs?: number): Promise<void>;
|
|
95
|
+
export declare function startCallbackServer(ctx: GatewayRuntimeContext, port: number): Promise<void>;
|
|
96
|
+
export declare function runGateway(positionals: string[], flags?: Record<string, string | boolean>): Promise<void>;
|
|
97
|
+
export {};
|