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