tickflow-assist 0.3.4 → 0.3.6
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 +32 -7
- package/dist/bootstrap.js +4 -1
- package/dist/config/env.d.ts +17 -0
- package/dist/config/env.js +30 -0
- package/dist/config/normalize.js +25 -12
- package/dist/dev/tickflow-assist-cli.js +83 -17
- package/dist/services/alert-service.d.ts +8 -0
- package/dist/services/alert-service.js +327 -45
- package/dist/services/analysis-service.js +4 -3
- package/dist/services/jin10-mcp-service.js +3 -2
- package/dist/services/monitor-service.d.ts +4 -1
- package/dist/services/monitor-service.js +48 -3
- package/dist/services/mx-search-service.js +3 -2
- package/dist/tools/test-alert.tool.js +5 -0
- package/dist/utils/alert-diagnostic-log.d.ts +12 -0
- package/dist/utils/alert-diagnostic-log.js +60 -0
- package/openclaw.plugin.json +80 -23
- package/package.json +10 -5
- package/skills/stock-analysis/SKILL.md +1 -2
package/README.md
CHANGED
|
@@ -2,9 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
基于 [OpenClaw](https://openclaw.ai) 的 A 股监控与分析插件。它使用 [TickFlow](https://tickflow.org/auth/register?ref=BUJ54JEDGE) 获取行情与财务数据,并可选接入 [金十数据 MCP](https://mcp.jin10.com/app/) 快讯流,结合 LLM 生成技术面、基本面、资讯面的综合判断,并把结果持久化到本地 LanceDB。
|
|
4
4
|
|
|
5
|
-
最近更新:`v0.3.4`
|
|
5
|
+
最近更新:`v0.3.5` 对齐 OpenClaw `2026.4.11` metadata 与社区安装提示,修复源码升级时本地链接扫描 `node_modules` 失败的问题,并支持通过环境变量回退 TickFlow / LLM / MX / Jin10 配置。完整发布记录见 <https://github.com/robinspt/tickflow-assist/blob/main/CHANGELOG.md>。
|
|
6
6
|
|
|
7
|
-
当前主线按 OpenClaw `v2026.3.31+` 对齐,并已验证社区安装在 `v2026.4.
|
|
7
|
+
当前主线按 OpenClaw `v2026.3.31+` 对齐,并已验证社区安装在 `v2026.4.11` 上兼容。
|
|
8
|
+
|
|
9
|
+
## 安装前准备
|
|
10
|
+
|
|
11
|
+
在执行社区安装前,建议先确认你已经准备好以下配置:
|
|
12
|
+
|
|
13
|
+
- 核心必需:`tickflowApiKey`、`llmApiKey`、`llmBaseUrl`、`llmModel`
|
|
14
|
+
- 告警投递:`alertChannel`、`alertTarget`、`alertAccount`
|
|
15
|
+
- 可选增强:`mxSearchApiKey`、`jin10ApiToken`
|
|
16
|
+
|
|
17
|
+
其中,`configure-openclaw` 会把上述配置写入 `~/.openclaw/openclaw.json` 的 `plugins.entries["tickflow-assist"].config`,插件启用后会在本地 `databasePath` 下持久化 LanceDB 数据,并运行监控 / 日更等后台服务。
|
|
18
|
+
如果你不想把密钥写进配置文件,运行时也支持环境变量回退,优先级是 `openclaw.json / local.config.json` > 环境变量 > 默认值。
|
|
19
|
+
常用环境变量:`TICKFLOW_ASSIST_TICKFLOW_API_KEY` / `TICKFLOW_API_KEY`、`TICKFLOW_ASSIST_LLM_API_KEY` / `LLM_API_KEY`、`TICKFLOW_ASSIST_LLM_BASE_URL` / `LLM_BASE_URL`、`TICKFLOW_ASSIST_LLM_MODEL` / `LLM_MODEL`、`TICKFLOW_ASSIST_MX_SEARCH_API_KEY` / `MX_SEARCH_API_KEY` / `MX_APIKEY`、`TICKFLOW_ASSIST_JIN10_API_TOKEN` / `JIN10_API_TOKEN`。
|
|
20
|
+
如果你希望尽量避免把密钥落盘,推荐先把这些变量写进 `~/.openclaw/.env`,再运行配置向导补齐非密钥项。
|
|
8
21
|
|
|
9
22
|
## 安装
|
|
10
23
|
|
|
@@ -12,21 +25,21 @@
|
|
|
12
25
|
|
|
13
26
|
```bash
|
|
14
27
|
openclaw plugins install tickflow-assist
|
|
15
|
-
|
|
28
|
+
node ~/.openclaw/extensions/tickflow-assist/dist/dev/tickflow-assist-cli.js configure-openclaw
|
|
16
29
|
cd ~/.openclaw/extensions/tickflow-assist/python && uv sync
|
|
17
30
|
openclaw plugins enable tickflow-assist
|
|
18
31
|
openclaw config validate
|
|
19
32
|
openclaw gateway restart
|
|
20
33
|
```
|
|
21
34
|
|
|
22
|
-
安装阶段允许先落插件,再通过第二条命令写入 `tickflowApiKey`、`llmApiKey` 等正式配置。
|
|
23
|
-
`configure-openclaw` 会写入 `~/.openclaw/openclaw.json` 中的 `plugins.entries["tickflow-assist"].config`,并打印后续建议执行的命令;它不再自动执行 `openclaw`、`uv`
|
|
35
|
+
安装阶段允许先落插件,再通过第二条命令写入 `tickflowApiKey`、`llmApiKey`、`llmBaseUrl`、`llmModel` 等正式配置。
|
|
36
|
+
`configure-openclaw` 会写入 `~/.openclaw/openclaw.json` 中的 `plugins.entries["tickflow-assist"].config`,并打印后续建议执行的命令;它不再自动执行 `openclaw`、`uv` 或系统包安装命令,也不会重新执行插件安装;如果你已经设置了环境变量,密钥项可留空,输入 `-` 可主动清空已有配置并切回环境变量。
|
|
24
37
|
如果检测到 `plugins.installs["tickflow-assist"]` 来自 `clawhub`,向导还会把被旧版本钉死的 `spec` 归一化为 `clawhub:tickflow-assist`,避免后续升级继续锁在旧版本。
|
|
25
38
|
|
|
26
39
|
如果你希望先审阅配置,再只打印最少的后续步骤,可使用:
|
|
27
40
|
|
|
28
41
|
```bash
|
|
29
|
-
|
|
42
|
+
node ~/.openclaw/extensions/tickflow-assist/dist/dev/tickflow-assist-cli.js configure-openclaw --no-enable --no-restart
|
|
30
43
|
```
|
|
31
44
|
|
|
32
45
|
如果你在 Linux 或 macOS 上需要 PNG 告警卡正常显示中文,请额外手动安装 `fontconfig` 与 Noto CJK 一类中文字体,例如:
|
|
@@ -84,6 +97,18 @@ plugins.entries["tickflow-assist"].config
|
|
|
84
97
|
- 能力补充:`mxSearchApiKey`、`jin10ApiToken`
|
|
85
98
|
|
|
86
99
|
其中,`mxSearchApiKey` 用于 `mx_search`、`mx_select_stock` 以及非 `Expert` 财务链路的 lite 补充;`jin10ApiToken` 用于 24 小时金十数据快讯监控;`jin10FlashNightAlert` 默认 `false`(开启夜间静默),设为 `true` 可恢复 24 小时快讯告警;`alertTarget`、`alertAccount` 建议在准备启用 `test_alert`、实时监控告警、金十数据快讯告警和定时通知前一并配好,避免配置不完整导致功能缺失。
|
|
100
|
+
如果你使用环境变量,运行时支持以下回退:
|
|
101
|
+
|
|
102
|
+
- `tickflowApiUrl`:`TICKFLOW_ASSIST_TICKFLOW_API_URL` / `TICKFLOW_API_URL`
|
|
103
|
+
- `tickflowApiKey`:`TICKFLOW_ASSIST_TICKFLOW_API_KEY` / `TICKFLOW_API_KEY`
|
|
104
|
+
- `tickflowApiKeyLevel`:`TICKFLOW_ASSIST_TICKFLOW_API_KEY_LEVEL` / `TICKFLOW_API_KEY_LEVEL`
|
|
105
|
+
- `llmBaseUrl`:`TICKFLOW_ASSIST_LLM_BASE_URL` / `LLM_BASE_URL`
|
|
106
|
+
- `llmApiKey`:`TICKFLOW_ASSIST_LLM_API_KEY` / `LLM_API_KEY`
|
|
107
|
+
- `llmModel`:`TICKFLOW_ASSIST_LLM_MODEL` / `LLM_MODEL`
|
|
108
|
+
- `mxSearchApiUrl`:`TICKFLOW_ASSIST_MX_SEARCH_API_URL` / `MX_SEARCH_API_URL`
|
|
109
|
+
- `mxSearchApiKey`:`TICKFLOW_ASSIST_MX_SEARCH_API_KEY` / `MX_SEARCH_API_KEY` / `MX_APIKEY`
|
|
110
|
+
- `jin10McpUrl`:`TICKFLOW_ASSIST_JIN10_MCP_URL` / `JIN10_MCP_URL`
|
|
111
|
+
- `jin10ApiToken`:`TICKFLOW_ASSIST_JIN10_API_TOKEN` / `JIN10_API_TOKEN`
|
|
87
112
|
|
|
88
113
|
## 功能
|
|
89
114
|
|
|
@@ -107,4 +132,4 @@ plugins.entries["tickflow-assist"].config
|
|
|
107
132
|
|
|
108
133
|
## 仓库
|
|
109
134
|
|
|
110
|
-
- GitHub:
|
|
135
|
+
- GitHub: [robinspt/tickflow-assist](https://github.com/robinspt/tickflow-assist)
|
package/dist/bootstrap.js
CHANGED
|
@@ -75,6 +75,7 @@ import { resolvePreferredOpenClawTmpDir } from "./runtime/openclaw-temp-dir.js";
|
|
|
75
75
|
import { RealtimeMonitorWorker } from "./background/realtime-monitor.worker.js";
|
|
76
76
|
import { DailyUpdateWorker } from "./background/daily-update.worker.js";
|
|
77
77
|
import { Jin10FlashWorker } from "./background/jin10-flash.worker.js";
|
|
78
|
+
import { createAlertDiagnosticLogger } from "./utils/alert-diagnostic-log.js";
|
|
78
79
|
export function createAppContext(config, options = {}) {
|
|
79
80
|
const runtime = {
|
|
80
81
|
configSource: options.configSource ?? "local_config",
|
|
@@ -109,6 +110,7 @@ export function createAppContext(config, options = {}) {
|
|
|
109
110
|
const analysisService = new AnalysisService(config.llmBaseUrl, config.llmApiKey, config.llmModel, analysisLogRepository);
|
|
110
111
|
const watchlistProfileService = new WatchlistProfileService(mxApiService, analysisService);
|
|
111
112
|
const tradingCalendarService = new TradingCalendarService(config.calendarFile);
|
|
113
|
+
const alertDiagnosticLogger = createAlertDiagnosticLogger(config.databasePath);
|
|
112
114
|
const alertService = new AlertService({
|
|
113
115
|
openclawCliBin: config.openclawCliBin,
|
|
114
116
|
channel: config.alertChannel,
|
|
@@ -120,6 +122,7 @@ export function createAppContext(config, options = {}) {
|
|
|
120
122
|
runtime: runtime.pluginRuntime,
|
|
121
123
|
}
|
|
122
124
|
: undefined,
|
|
125
|
+
diagnosticLogger: alertDiagnosticLogger,
|
|
123
126
|
});
|
|
124
127
|
const alertMediaService = new AlertMediaService(config.databasePath, undefined, undefined, resolveAlertMediaTempRootDir());
|
|
125
128
|
const indicatorService = new IndicatorService(config.pythonBin, config.pythonArgs, config.pythonWorkdir, runCommandWithTimeout);
|
|
@@ -137,7 +140,7 @@ export function createAppContext(config, options = {}) {
|
|
|
137
140
|
const postCloseReviewTask = new PostCloseReviewTask();
|
|
138
141
|
const compositeStockAnalysisTask = new CompositeStockAnalysisTask(keyLevelsRepository, analysisLogRepository);
|
|
139
142
|
const compositeAnalysisOrchestrator = new CompositeAnalysisOrchestrator(analysisService, marketAnalysisProvider, financialAnalysisProvider, newsAnalysisProvider, klineTechnicalSignalTask, financialFundamentalTask, financialFundamentalLiteTask, newsCatalystTask, compositeStockAnalysisTask, technicalAnalysisRepository, financialAnalysisRepository, newsAnalysisRepository, compositeAnalysisRepository);
|
|
140
|
-
const monitorService = new MonitorService(config.databasePath, config.requestInterval, config.alertChannel, watchlistService, quoteService, tradingCalendarService, keyLevelsRepository, alertLogRepository, klinesRepository, intradayKlinesRepository, klineService, alertService, alertMediaService);
|
|
143
|
+
const monitorService = new MonitorService(config.databasePath, config.requestInterval, config.alertChannel, watchlistService, quoteService, tradingCalendarService, keyLevelsRepository, alertLogRepository, klinesRepository, intradayKlinesRepository, klineService, alertService, alertMediaService, alertDiagnosticLogger);
|
|
141
144
|
const jin10FlashMonitorService = new Jin10FlashMonitorService(config.databasePath, config.jin10FlashPollInterval, config.jin10FlashRetentionDays, config.jin10FlashNightAlert, watchlistService, jin10McpService, analysisService, alertService, jin10FlashRepository, jin10FlashDeliveryRepository);
|
|
142
145
|
const updateService = new UpdateService(klineService, config.tickflowApiKeyLevel, indicatorService, klinesRepository, indicatorsRepository, intradayKlinesRepository, watchlistService, tradingCalendarService);
|
|
143
146
|
const postCloseReviewService = new PostCloseReviewService(watchlistService, compositeAnalysisOrchestrator, analysisService, postCloseReviewTask, keyLevelsRepository, keyLevelsHistoryRepository, klinesRepository, intradayKlinesRepository, jin10FlashDeliveryRepository, jin10FlashRepository);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const CONFIG_ENV_FALLBACKS: {
|
|
2
|
+
readonly tickflowApiUrl: readonly ["TICKFLOW_ASSIST_TICKFLOW_API_URL", "TICKFLOW_API_URL"];
|
|
3
|
+
readonly tickflowApiKey: readonly ["TICKFLOW_ASSIST_TICKFLOW_API_KEY", "TICKFLOW_API_KEY"];
|
|
4
|
+
readonly tickflowApiKeyLevel: readonly ["TICKFLOW_ASSIST_TICKFLOW_API_KEY_LEVEL", "TICKFLOW_API_KEY_LEVEL"];
|
|
5
|
+
readonly mxSearchApiUrl: readonly ["TICKFLOW_ASSIST_MX_SEARCH_API_URL", "MX_SEARCH_API_URL"];
|
|
6
|
+
readonly mxSearchApiKey: readonly ["TICKFLOW_ASSIST_MX_SEARCH_API_KEY", "MX_SEARCH_API_KEY", "MX_APIKEY"];
|
|
7
|
+
readonly jin10McpUrl: readonly ["TICKFLOW_ASSIST_JIN10_MCP_URL", "JIN10_MCP_URL"];
|
|
8
|
+
readonly jin10ApiToken: readonly ["TICKFLOW_ASSIST_JIN10_API_TOKEN", "JIN10_API_TOKEN"];
|
|
9
|
+
readonly llmBaseUrl: readonly ["TICKFLOW_ASSIST_LLM_BASE_URL", "LLM_BASE_URL"];
|
|
10
|
+
readonly llmApiKey: readonly ["TICKFLOW_ASSIST_LLM_API_KEY", "LLM_API_KEY"];
|
|
11
|
+
readonly llmModel: readonly ["TICKFLOW_ASSIST_LLM_MODEL", "LLM_MODEL"];
|
|
12
|
+
};
|
|
13
|
+
export type EnvBackedConfigKey = keyof typeof CONFIG_ENV_FALLBACKS;
|
|
14
|
+
export declare function getEnvFallbackValue(names: readonly string[], env?: NodeJS.ProcessEnv): string;
|
|
15
|
+
export declare function getConfigEnvFallback(key: EnvBackedConfigKey, env?: NodeJS.ProcessEnv): string;
|
|
16
|
+
export declare function hasConfigEnvFallback(key: EnvBackedConfigKey, env?: NodeJS.ProcessEnv): boolean;
|
|
17
|
+
export declare function formatConfigEnvFallback(key: EnvBackedConfigKey): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const CONFIG_ENV_FALLBACKS = {
|
|
2
|
+
tickflowApiUrl: ["TICKFLOW_ASSIST_TICKFLOW_API_URL", "TICKFLOW_API_URL"],
|
|
3
|
+
tickflowApiKey: ["TICKFLOW_ASSIST_TICKFLOW_API_KEY", "TICKFLOW_API_KEY"],
|
|
4
|
+
tickflowApiKeyLevel: ["TICKFLOW_ASSIST_TICKFLOW_API_KEY_LEVEL", "TICKFLOW_API_KEY_LEVEL"],
|
|
5
|
+
mxSearchApiUrl: ["TICKFLOW_ASSIST_MX_SEARCH_API_URL", "MX_SEARCH_API_URL"],
|
|
6
|
+
mxSearchApiKey: ["TICKFLOW_ASSIST_MX_SEARCH_API_KEY", "MX_SEARCH_API_KEY", "MX_APIKEY"],
|
|
7
|
+
jin10McpUrl: ["TICKFLOW_ASSIST_JIN10_MCP_URL", "JIN10_MCP_URL"],
|
|
8
|
+
jin10ApiToken: ["TICKFLOW_ASSIST_JIN10_API_TOKEN", "JIN10_API_TOKEN"],
|
|
9
|
+
llmBaseUrl: ["TICKFLOW_ASSIST_LLM_BASE_URL", "LLM_BASE_URL"],
|
|
10
|
+
llmApiKey: ["TICKFLOW_ASSIST_LLM_API_KEY", "LLM_API_KEY"],
|
|
11
|
+
llmModel: ["TICKFLOW_ASSIST_LLM_MODEL", "LLM_MODEL"],
|
|
12
|
+
};
|
|
13
|
+
export function getEnvFallbackValue(names, env = process.env) {
|
|
14
|
+
for (const name of names) {
|
|
15
|
+
const value = env[name];
|
|
16
|
+
if (typeof value === "string" && value.trim()) {
|
|
17
|
+
return value.trim();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
export function getConfigEnvFallback(key, env = process.env) {
|
|
23
|
+
return getEnvFallbackValue(CONFIG_ENV_FALLBACKS[key], env);
|
|
24
|
+
}
|
|
25
|
+
export function hasConfigEnvFallback(key, env = process.env) {
|
|
26
|
+
return Boolean(getConfigEnvFallback(key, env));
|
|
27
|
+
}
|
|
28
|
+
export function formatConfigEnvFallback(key) {
|
|
29
|
+
return CONFIG_ENV_FALLBACKS[key].join(" / ");
|
|
30
|
+
}
|
package/dist/config/normalize.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { getConfigEnvFallback } from "./env.js";
|
|
2
3
|
import { normalizeTickflowApiKeyLevel } from "./tickflow-access.js";
|
|
3
4
|
import { DEFAULT_PLUGIN_CONFIG } from "./schema.js";
|
|
4
5
|
function normalizeString(value, fallback = "") {
|
|
@@ -10,6 +11,10 @@ function normalizeString(value, fallback = "") {
|
|
|
10
11
|
}
|
|
11
12
|
return String(value).trim();
|
|
12
13
|
}
|
|
14
|
+
function normalizeStringWithFallback(value, fallback = "") {
|
|
15
|
+
const normalized = normalizeString(value);
|
|
16
|
+
return normalized || fallback;
|
|
17
|
+
}
|
|
13
18
|
function normalizeInteger(value, fallback) {
|
|
14
19
|
const parsed = Number(value ?? fallback);
|
|
15
20
|
return Number.isFinite(parsed) ? Math.max(1, Math.trunc(parsed)) : fallback;
|
|
@@ -40,22 +45,30 @@ function normalizeBoolean(value, fallback) {
|
|
|
40
45
|
}
|
|
41
46
|
export function normalizePluginConfig(input) {
|
|
42
47
|
const raw = (input ?? {});
|
|
43
|
-
const
|
|
44
|
-
const
|
|
48
|
+
const envTickflowApiUrl = getConfigEnvFallback("tickflowApiUrl");
|
|
49
|
+
const envTickflowApiKey = getConfigEnvFallback("tickflowApiKey");
|
|
50
|
+
const envTickflowApiKeyLevel = getConfigEnvFallback("tickflowApiKeyLevel");
|
|
51
|
+
const envMxSearchApiUrl = getConfigEnvFallback("mxSearchApiUrl");
|
|
52
|
+
const envMxSearchApiKey = getConfigEnvFallback("mxSearchApiKey");
|
|
53
|
+
const envJin10McpUrl = getConfigEnvFallback("jin10McpUrl");
|
|
54
|
+
const envJin10ApiToken = getConfigEnvFallback("jin10ApiToken");
|
|
55
|
+
const envLlmBaseUrl = getConfigEnvFallback("llmBaseUrl");
|
|
56
|
+
const envLlmApiKey = getConfigEnvFallback("llmApiKey");
|
|
57
|
+
const envLlmModel = getConfigEnvFallback("llmModel");
|
|
45
58
|
return {
|
|
46
|
-
tickflowApiUrl:
|
|
47
|
-
tickflowApiKey:
|
|
48
|
-
tickflowApiKeyLevel: normalizeTickflowApiKeyLevel(raw.tickflowApiKeyLevel, DEFAULT_PLUGIN_CONFIG.tickflowApiKeyLevel),
|
|
49
|
-
mxSearchApiUrl:
|
|
50
|
-
mxSearchApiKey:
|
|
51
|
-
jin10McpUrl:
|
|
52
|
-
jin10ApiToken:
|
|
59
|
+
tickflowApiUrl: normalizeStringWithFallback(raw.tickflowApiUrl, envTickflowApiUrl || DEFAULT_PLUGIN_CONFIG.tickflowApiUrl),
|
|
60
|
+
tickflowApiKey: normalizeStringWithFallback(raw.tickflowApiKey, envTickflowApiKey),
|
|
61
|
+
tickflowApiKeyLevel: normalizeTickflowApiKeyLevel(normalizeStringWithFallback(raw.tickflowApiKeyLevel, envTickflowApiKeyLevel), DEFAULT_PLUGIN_CONFIG.tickflowApiKeyLevel),
|
|
62
|
+
mxSearchApiUrl: normalizeStringWithFallback(raw.mxSearchApiUrl, envMxSearchApiUrl || DEFAULT_PLUGIN_CONFIG.mxSearchApiUrl),
|
|
63
|
+
mxSearchApiKey: normalizeStringWithFallback(raw.mxSearchApiKey, envMxSearchApiKey || DEFAULT_PLUGIN_CONFIG.mxSearchApiKey),
|
|
64
|
+
jin10McpUrl: normalizeStringWithFallback(raw.jin10McpUrl, envJin10McpUrl || DEFAULT_PLUGIN_CONFIG.jin10McpUrl),
|
|
65
|
+
jin10ApiToken: normalizeStringWithFallback(raw.jin10ApiToken, envJin10ApiToken),
|
|
53
66
|
jin10FlashPollInterval: normalizeInteger(raw.jin10FlashPollInterval, DEFAULT_PLUGIN_CONFIG.jin10FlashPollInterval),
|
|
54
67
|
jin10FlashRetentionDays: normalizeInteger(raw.jin10FlashRetentionDays, DEFAULT_PLUGIN_CONFIG.jin10FlashRetentionDays),
|
|
55
68
|
jin10FlashNightAlert: normalizeBoolean(raw.jin10FlashNightAlert, DEFAULT_PLUGIN_CONFIG.jin10FlashNightAlert),
|
|
56
|
-
llmBaseUrl:
|
|
57
|
-
llmApiKey:
|
|
58
|
-
llmModel:
|
|
69
|
+
llmBaseUrl: normalizeStringWithFallback(raw.llmBaseUrl, envLlmBaseUrl || DEFAULT_PLUGIN_CONFIG.llmBaseUrl),
|
|
70
|
+
llmApiKey: normalizeStringWithFallback(raw.llmApiKey, envLlmApiKey),
|
|
71
|
+
llmModel: normalizeStringWithFallback(raw.llmModel, envLlmModel || DEFAULT_PLUGIN_CONFIG.llmModel),
|
|
59
72
|
databasePath: normalizeString(raw.databasePath, DEFAULT_PLUGIN_CONFIG.databasePath),
|
|
60
73
|
calendarFile: normalizeString(raw.calendarFile, DEFAULT_PLUGIN_CONFIG.calendarFile),
|
|
61
74
|
requestInterval: normalizeInteger(raw.requestInterval, DEFAULT_PLUGIN_CONFIG.requestInterval),
|
|
@@ -6,6 +6,7 @@ import path from "node:path";
|
|
|
6
6
|
import process from "node:process";
|
|
7
7
|
import { createInterface } from "node:readline/promises";
|
|
8
8
|
import JSON5 from "json5";
|
|
9
|
+
import { formatConfigEnvFallback, hasConfigEnvFallback, } from "../config/env.js";
|
|
9
10
|
const PLUGIN_ID = "tickflow-assist";
|
|
10
11
|
const DEFAULT_CONFIG_PATH = path.join(os.homedir(), ".openclaw", "openclaw.json");
|
|
11
12
|
const DEFAULTS = {
|
|
@@ -59,6 +60,14 @@ Options:
|
|
|
59
60
|
--alert-account <name>
|
|
60
61
|
--alert-target <target>
|
|
61
62
|
-h, --help Show this help
|
|
63
|
+
|
|
64
|
+
Environment fallback:
|
|
65
|
+
tickflowApiKey ${formatConfigEnvFallback("tickflowApiKey")}
|
|
66
|
+
llmApiKey ${formatConfigEnvFallback("llmApiKey")}
|
|
67
|
+
llmBaseUrl ${formatConfigEnvFallback("llmBaseUrl")}
|
|
68
|
+
llmModel ${formatConfigEnvFallback("llmModel")}
|
|
69
|
+
mxSearchApiKey ${formatConfigEnvFallback("mxSearchApiKey")}
|
|
70
|
+
jin10ApiToken ${formatConfigEnvFallback("jin10ApiToken")}
|
|
62
71
|
`);
|
|
63
72
|
}
|
|
64
73
|
function parseArgs(argv) {
|
|
@@ -390,7 +399,7 @@ async function promptAlertChannel(rl, configPath, defaultChannel) {
|
|
|
390
399
|
choices.push({ value: "__manual__", label: "手动输入其他通道" });
|
|
391
400
|
selectedChannel = await promptSelect(rl, "检测到 openclaw.json 中已有配置,请选择推送通道", choices, defaultChannel);
|
|
392
401
|
if (selectedChannel === "__manual__") {
|
|
393
|
-
selectedChannel = await promptString(rl, "Alert Channel", defaultChannel, true);
|
|
402
|
+
selectedChannel = await promptString(rl, "Alert Channel", defaultChannel, { required: true });
|
|
394
403
|
}
|
|
395
404
|
}
|
|
396
405
|
else {
|
|
@@ -467,15 +476,29 @@ async function promptForConfig(options, existing, pluginDir, configPath) {
|
|
|
467
476
|
console.log(`OpenClaw 配置文件: ${configPath}`);
|
|
468
477
|
console.log(`插件目录: ${pluginDir}`);
|
|
469
478
|
console.log("");
|
|
470
|
-
|
|
479
|
+
console.log("为避免后续运行时反复补配置,下面这些字段建议一次性填完整。");
|
|
480
|
+
console.log("");
|
|
481
|
+
seed.tickflowApiKey = await promptString(rl, buildEnvAwarePromptLabel("TickFlow API Key", "tickflowApiKey", seed.tickflowApiKey), seed.tickflowApiKey, {
|
|
482
|
+
required: !hasConfigEnvFallback("tickflowApiKey"),
|
|
483
|
+
maskDefault: true,
|
|
484
|
+
allowClear: true,
|
|
485
|
+
});
|
|
471
486
|
seed.tickflowApiKeyLevel = normalizeApiKeyLevel(await promptSelect(rl, "TickFlow 订阅等级", [
|
|
472
487
|
{ value: "Free", label: "Free" },
|
|
473
488
|
{ value: "Start", label: "Start" },
|
|
474
489
|
{ value: "Pro", label: "Pro" },
|
|
475
490
|
{ value: "Expert", label: "Expert" },
|
|
476
491
|
], seed.tickflowApiKeyLevel));
|
|
477
|
-
seed.mxSearchApiKey = await promptString(rl, "MX Search API Key
|
|
478
|
-
|
|
492
|
+
seed.mxSearchApiKey = await promptString(rl, buildEnvAwarePromptLabel("MX Search API Key(建议填写)", "mxSearchApiKey", seed.mxSearchApiKey), seed.mxSearchApiKey, {
|
|
493
|
+
required: false,
|
|
494
|
+
maskDefault: true,
|
|
495
|
+
allowClear: true,
|
|
496
|
+
});
|
|
497
|
+
seed.jin10ApiToken = await promptString(rl, buildEnvAwarePromptLabel("Jin10 API Token(建议填写)", "jin10ApiToken", seed.jin10ApiToken), seed.jin10ApiToken, {
|
|
498
|
+
required: false,
|
|
499
|
+
maskDefault: true,
|
|
500
|
+
allowClear: true,
|
|
501
|
+
});
|
|
479
502
|
seed.jin10FlashPollInterval = await promptInteger(rl, "Jin10 快讯轮询间隔(秒)", seed.jin10FlashPollInterval, 10);
|
|
480
503
|
seed.jin10FlashRetentionDays = await promptInteger(rl, "Jin10 快讯保留天数", seed.jin10FlashRetentionDays, 1);
|
|
481
504
|
const nightAlertChoice = await promptSelect(rl, "Jin10 夜间静默", [
|
|
@@ -483,21 +506,31 @@ async function promptForConfig(options, existing, pluginDir, configPath) {
|
|
|
483
506
|
{ value: "false", label: "开启夜间静默(22:00~06:00 不告警)" },
|
|
484
507
|
], seed.jin10FlashNightAlert ? "true" : "false");
|
|
485
508
|
seed.jin10FlashNightAlert = nightAlertChoice === "true";
|
|
486
|
-
seed.llmBaseUrl = await promptString(rl, "LLM Base URL", seed.llmBaseUrl,
|
|
487
|
-
|
|
488
|
-
|
|
509
|
+
seed.llmBaseUrl = await promptString(rl, buildEnvAwarePromptLabel("LLM Base URL", "llmBaseUrl", seed.llmBaseUrl), seed.llmBaseUrl, {
|
|
510
|
+
required: true,
|
|
511
|
+
allowClear: hasConfigEnvFallback("llmBaseUrl"),
|
|
512
|
+
});
|
|
513
|
+
seed.llmApiKey = await promptString(rl, buildEnvAwarePromptLabel("LLM API Key", "llmApiKey", seed.llmApiKey), seed.llmApiKey, {
|
|
514
|
+
required: !hasConfigEnvFallback("llmApiKey"),
|
|
515
|
+
maskDefault: true,
|
|
516
|
+
allowClear: true,
|
|
517
|
+
});
|
|
518
|
+
seed.llmModel = await promptString(rl, buildEnvAwarePromptLabel("LLM Model", "llmModel", seed.llmModel), seed.llmModel, {
|
|
519
|
+
required: true,
|
|
520
|
+
allowClear: hasConfigEnvFallback("llmModel"),
|
|
521
|
+
});
|
|
489
522
|
console.log("");
|
|
490
523
|
const alertResult = await promptAlertChannel(rl, configPath, seed.alertChannel);
|
|
491
524
|
seed.alertChannel = alertResult.channel;
|
|
492
525
|
seed.alertAccount = alertResult.account;
|
|
493
526
|
let targetLabel = "Alert Target";
|
|
494
527
|
if (seed.alertAccount) {
|
|
495
|
-
targetLabel = `已选通道 [${seed.alertChannel}] 及账号 [${seed.alertAccount}],请输入 Alert Target
|
|
528
|
+
targetLabel = `已选通道 [${seed.alertChannel}] 及账号 [${seed.alertAccount}],请输入 Alert Target(建议填写)`;
|
|
496
529
|
}
|
|
497
530
|
else {
|
|
498
|
-
targetLabel = `已选通道 [${seed.alertChannel}],请输入 Alert Target
|
|
531
|
+
targetLabel = `已选通道 [${seed.alertChannel}],请输入 Alert Target(建议填写)`;
|
|
499
532
|
}
|
|
500
|
-
seed.alertTarget = await promptString(rl, targetLabel, seed.alertTarget, false);
|
|
533
|
+
seed.alertTarget = await promptString(rl, targetLabel, seed.alertTarget, { required: false });
|
|
501
534
|
seed.requestInterval = await promptInteger(rl, "Request Interval (seconds)", seed.requestInterval, 5);
|
|
502
535
|
seed.dailyUpdateNotify = await promptBoolean(rl, "Daily Update Notify", seed.dailyUpdateNotify);
|
|
503
536
|
}
|
|
@@ -507,12 +540,17 @@ async function promptForConfig(options, existing, pluginDir, configPath) {
|
|
|
507
540
|
assertRequired(seed);
|
|
508
541
|
return seed;
|
|
509
542
|
}
|
|
510
|
-
async function promptString(rl, label, defaultValue,
|
|
543
|
+
async function promptString(rl, label, defaultValue, options) {
|
|
511
544
|
while (true) {
|
|
512
|
-
const suffix = defaultValue
|
|
545
|
+
const suffix = defaultValue
|
|
546
|
+
? options.maskDefault ? " [已存在]" : ` [${defaultValue}]`
|
|
547
|
+
: "";
|
|
513
548
|
const answer = (await rl.question(`${label}${suffix}: `)).trim();
|
|
549
|
+
if (options.allowClear && answer === "-") {
|
|
550
|
+
return "";
|
|
551
|
+
}
|
|
514
552
|
const value = answer || defaultValue;
|
|
515
|
-
if (!required || value) {
|
|
553
|
+
if (!options.required || value) {
|
|
516
554
|
return value;
|
|
517
555
|
}
|
|
518
556
|
console.error(`${label} 不能为空`);
|
|
@@ -544,11 +582,11 @@ async function promptBoolean(rl, label, defaultValue) {
|
|
|
544
582
|
}
|
|
545
583
|
}
|
|
546
584
|
function assertRequired(config) {
|
|
547
|
-
if (!config.tickflowApiKey) {
|
|
548
|
-
throw new Error(
|
|
585
|
+
if (!config.tickflowApiKey && !hasConfigEnvFallback("tickflowApiKey")) {
|
|
586
|
+
throw new Error(`tickflowApiKey is required (or set ${formatConfigEnvFallback("tickflowApiKey")})`);
|
|
549
587
|
}
|
|
550
|
-
if (!config.llmApiKey) {
|
|
551
|
-
throw new Error(
|
|
588
|
+
if (!config.llmApiKey && !hasConfigEnvFallback("llmApiKey")) {
|
|
589
|
+
throw new Error(`llmApiKey is required (or set ${formatConfigEnvFallback("llmApiKey")})`);
|
|
552
590
|
}
|
|
553
591
|
}
|
|
554
592
|
function normalizeCommunityInstallSpec(root) {
|
|
@@ -806,6 +844,7 @@ async function configureOpenClaw(options) {
|
|
|
806
844
|
if (normalizedInstallSpec) {
|
|
807
845
|
console.log(`Community install spec normalized: clawhub:${PLUGIN_ID}`);
|
|
808
846
|
}
|
|
847
|
+
printActiveEnvFallbacks(config);
|
|
809
848
|
printNextSteps(options, config);
|
|
810
849
|
}
|
|
811
850
|
async function main() {
|
|
@@ -823,3 +862,30 @@ async function main() {
|
|
|
823
862
|
}
|
|
824
863
|
}
|
|
825
864
|
void main();
|
|
865
|
+
function buildEnvAwarePromptLabel(label, key, currentValue) {
|
|
866
|
+
if (!hasConfigEnvFallback(key)) {
|
|
867
|
+
return label;
|
|
868
|
+
}
|
|
869
|
+
const fallback = formatConfigEnvFallback(key);
|
|
870
|
+
if (currentValue) {
|
|
871
|
+
return `${label}(留空保留当前值;输入 - 清空并改用环境变量 ${fallback})`;
|
|
872
|
+
}
|
|
873
|
+
return `${label}(留空则使用环境变量 ${fallback})`;
|
|
874
|
+
}
|
|
875
|
+
function printActiveEnvFallbacks(config) {
|
|
876
|
+
const activeFallbacks = [
|
|
877
|
+
{ key: "tickflowApiKey", label: "TickFlow API Key", value: config.tickflowApiKey },
|
|
878
|
+
{ key: "mxSearchApiKey", label: "MX Search API Key", value: config.mxSearchApiKey },
|
|
879
|
+
{ key: "jin10ApiToken", label: "Jin10 API Token", value: config.jin10ApiToken },
|
|
880
|
+
{ key: "llmBaseUrl", label: "LLM Base URL", value: config.llmBaseUrl },
|
|
881
|
+
{ key: "llmApiKey", label: "LLM API Key", value: config.llmApiKey },
|
|
882
|
+
{ key: "llmModel", label: "LLM Model", value: config.llmModel },
|
|
883
|
+
].filter(({ key, value }) => !value && hasConfigEnvFallback(key));
|
|
884
|
+
if (activeFallbacks.length === 0) {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
console.log("Active env fallback:");
|
|
888
|
+
for (const entry of activeFallbacks) {
|
|
889
|
+
console.log(` ${entry.label}: ${formatConfigEnvFallback(entry.key)}`);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenClawPluginConfig, OpenClawPluginRuntime } from "../runtime/plugin-api.js";
|
|
2
2
|
import type { KeyLevels } from "../types/domain.js";
|
|
3
|
+
import { AlertDiagnosticLogger } from "../utils/alert-diagnostic-log.js";
|
|
3
4
|
interface AlertRuntimeContext {
|
|
4
5
|
config: OpenClawPluginConfig;
|
|
5
6
|
runtime: OpenClawPluginRuntime;
|
|
@@ -10,6 +11,7 @@ interface AlertServiceOptions {
|
|
|
10
11
|
account: string;
|
|
11
12
|
target: string;
|
|
12
13
|
runtime?: AlertRuntimeContext;
|
|
14
|
+
diagnosticLogger?: AlertDiagnosticLogger;
|
|
13
15
|
}
|
|
14
16
|
export interface AlertSendInput {
|
|
15
17
|
message: string;
|
|
@@ -22,6 +24,7 @@ export interface AlertSendResult {
|
|
|
22
24
|
mediaAttempted: boolean;
|
|
23
25
|
mediaDelivered: boolean;
|
|
24
26
|
error: string | null;
|
|
27
|
+
deliveryUncertain?: boolean;
|
|
25
28
|
}
|
|
26
29
|
export declare class AlertService {
|
|
27
30
|
private readonly options;
|
|
@@ -62,6 +65,11 @@ export declare class AlertService {
|
|
|
62
65
|
private trySendViaRuntime;
|
|
63
66
|
private invokeRuntimeChannelSend;
|
|
64
67
|
private trySendViaCommand;
|
|
68
|
+
private prepareCommandPayload;
|
|
69
|
+
private getCommandRunOptions;
|
|
65
70
|
private buildCliArgs;
|
|
71
|
+
private logCompletion;
|
|
72
|
+
private logTransportFailure;
|
|
73
|
+
private logDiagnostic;
|
|
66
74
|
}
|
|
67
75
|
export {};
|