koishi-plugin-aka-sa-caller 0.0.2 → 0.0.3
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/lib/index.js +12 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -65,14 +65,22 @@ function apply(ctx, config) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
__name(submitAnalysis, "submitAnalysis");
|
|
68
|
-
async function pollTaskStatus(taskId) {
|
|
68
|
+
async function pollTaskStatus(taskId, symbol) {
|
|
69
69
|
for (let i = 0; i < config.maxPollAttempts; i++) {
|
|
70
70
|
try {
|
|
71
71
|
const response = await ctx.http.get(`${config.apiUrl}/api/analysis/task/${taskId}`);
|
|
72
72
|
if (response.success) {
|
|
73
73
|
const task = response.task;
|
|
74
74
|
if (task.status === "completed" && task.result) {
|
|
75
|
-
|
|
75
|
+
const analyses = task.result.analyses;
|
|
76
|
+
if (analyses && analyses.length > 0) {
|
|
77
|
+
const analysis = analyses.find((a) => a.symbol === symbol);
|
|
78
|
+
if (analysis) {
|
|
79
|
+
return analysis;
|
|
80
|
+
}
|
|
81
|
+
ctx.logger.warn(`未找到 ${symbol} 的分析结果,返回第一个结果`);
|
|
82
|
+
return analyses[0];
|
|
83
|
+
}
|
|
76
84
|
} else if (task.status === "failed") {
|
|
77
85
|
ctx.logger.error(`任务失败: ${task.error}`);
|
|
78
86
|
return null;
|
|
@@ -144,7 +152,7 @@ function apply(ctx, config) {
|
|
|
144
152
|
if (!taskId) {
|
|
145
153
|
return "❌ 提交分析任务失败,请稍后重试";
|
|
146
154
|
}
|
|
147
|
-
const result = await pollTaskStatus(taskId);
|
|
155
|
+
const result = await pollTaskStatus(taskId, stock.symbol);
|
|
148
156
|
if (!result) {
|
|
149
157
|
return "❌ 分析失败或超时,请稍后重试";
|
|
150
158
|
}
|
|
@@ -176,7 +184,7 @@ function apply(ctx, config) {
|
|
|
176
184
|
if (!taskId) {
|
|
177
185
|
return "❌ 提交分析任务失败,请稍后重试";
|
|
178
186
|
}
|
|
179
|
-
const result = await pollTaskStatus(taskId);
|
|
187
|
+
const result = await pollTaskStatus(taskId, stock.symbol);
|
|
180
188
|
if (!result) {
|
|
181
189
|
return "❌ 分析失败或超时,请稍后重试";
|
|
182
190
|
}
|