cue-console 0.1.18 → 0.1.19
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/package.json +1 -1
- package/src/components/chat-view.tsx +21 -4
- package/src/lib/actions.ts +2 -12
- package/src/lib/db.ts +19 -0
package/package.json
CHANGED
|
@@ -236,14 +236,26 @@ function ChatViewContent({ type, id, name, onBack }: ChatViewProps) {
|
|
|
236
236
|
convId: id,
|
|
237
237
|
limit: 80,
|
|
238
238
|
});
|
|
239
|
-
if (res.success
|
|
239
|
+
if (!res.success) {
|
|
240
|
+
setNotice(`Bot tick failed: ${res.error}`);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (!res.acquired) {
|
|
244
|
+
setNotice("Bot is busy in another window");
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (res.replied === 0) {
|
|
248
|
+
setNotice("Bot is enabled (no pending to reply)");
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (res.replied > 0) {
|
|
240
252
|
await refreshLatest();
|
|
241
253
|
}
|
|
242
254
|
} catch {
|
|
243
255
|
} finally {
|
|
244
256
|
botTickBusyRef.current = false;
|
|
245
257
|
}
|
|
246
|
-
}, [id, refreshLatest, type]);
|
|
258
|
+
}, [id, refreshLatest, setNotice, type]);
|
|
247
259
|
|
|
248
260
|
const toggleBot = useCallback(async (): Promise<boolean> => {
|
|
249
261
|
const prev = botEnabled;
|
|
@@ -287,7 +299,12 @@ function ChatViewContent({ type, id, name, onBack }: ChatViewProps) {
|
|
|
287
299
|
limit: 80,
|
|
288
300
|
});
|
|
289
301
|
if (cancelled) return;
|
|
290
|
-
if (res.success
|
|
302
|
+
if (!res.success) {
|
|
303
|
+
setNotice(`Bot tick failed: ${res.error}`);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (!res.acquired) return;
|
|
307
|
+
if (res.replied > 0) {
|
|
291
308
|
await refreshLatest();
|
|
292
309
|
}
|
|
293
310
|
} catch {
|
|
@@ -302,7 +319,7 @@ function ChatViewContent({ type, id, name, onBack }: ChatViewProps) {
|
|
|
302
319
|
cancelled = true;
|
|
303
320
|
clearInterval(interval);
|
|
304
321
|
};
|
|
305
|
-
}, [botEnabled, id, refreshLatest, type]);
|
|
322
|
+
}, [botEnabled, id, refreshLatest, setNotice, type]);
|
|
306
323
|
|
|
307
324
|
|
|
308
325
|
const handleTitleChange = async (newTitle: string) => {
|
package/src/lib/actions.ts
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
moveMessageQueueItem,
|
|
41
41
|
acquireWorkerLease,
|
|
42
42
|
processMessageQueueTick,
|
|
43
|
+
getAgentPendingRequests,
|
|
43
44
|
getLastRequestsByAgents,
|
|
44
45
|
getLastResponsesByAgents,
|
|
45
46
|
getPendingCountsByAgents,
|
|
@@ -177,18 +178,7 @@ export async function processBotTick(args: {
|
|
|
177
178
|
const limit = Math.max(1, Math.min(200, args.limit ?? 50));
|
|
178
179
|
const pending =
|
|
179
180
|
convType === "agent"
|
|
180
|
-
?
|
|
181
|
-
.filter((r) => r.status === "PENDING")
|
|
182
|
-
.filter((r) => {
|
|
183
|
-
if (!r.payload) return true;
|
|
184
|
-
try {
|
|
185
|
-
const obj = JSON.parse(r.payload) as Record<string, unknown>;
|
|
186
|
-
return !(obj?.type === "confirm" && obj?.variant === "pause");
|
|
187
|
-
} catch {
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
.slice(0, limit)
|
|
181
|
+
? getAgentPendingRequests(convId, limit)
|
|
192
182
|
: getGroupPendingRequests(convId).slice(0, limit);
|
|
193
183
|
|
|
194
184
|
let replied = 0;
|
package/src/lib/db.ts
CHANGED
|
@@ -922,6 +922,25 @@ export function getPendingRequests(): CueRequest[] {
|
|
|
922
922
|
.all() as CueRequest[];
|
|
923
923
|
}
|
|
924
924
|
|
|
925
|
+
export function getAgentPendingRequests(agentId: string, limit: number = 200): CueRequest[] {
|
|
926
|
+
const cleanAgentId = String(agentId || "").trim();
|
|
927
|
+
if (!cleanAgentId) return [];
|
|
928
|
+
const lim = Math.max(1, Math.min(500, Math.floor(Number(limit) || 0)));
|
|
929
|
+
return getDb()
|
|
930
|
+
.prepare(
|
|
931
|
+
`SELECT * FROM cue_requests
|
|
932
|
+
WHERE agent_id = ?
|
|
933
|
+
AND status = 'PENDING'
|
|
934
|
+
AND NOT (
|
|
935
|
+
COALESCE(payload, '') LIKE '%"type"%confirm%'
|
|
936
|
+
AND COALESCE(payload, '') LIKE '%"variant"%pause%'
|
|
937
|
+
)
|
|
938
|
+
ORDER BY created_at ASC
|
|
939
|
+
LIMIT ?`
|
|
940
|
+
)
|
|
941
|
+
.all(cleanAgentId, lim) as CueRequest[];
|
|
942
|
+
}
|
|
943
|
+
|
|
925
944
|
export function getRequestsByAgent(agentId: string): CueRequest[] {
|
|
926
945
|
return getDb()
|
|
927
946
|
.prepare(
|