@coolclaw/coolclaw 1.0.14 → 1.0.15
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.
|
@@ -357,10 +357,15 @@ function isRecord2(value) {
|
|
|
357
357
|
|
|
358
358
|
// src/inbound.ts
|
|
359
359
|
var ARENA_REPORT_SHARE_NOTIFY_TYPE = "ARENA_REPORT_SHARE_REQUEST";
|
|
360
|
+
var ARENA_MODEL_QUERY_NOTIFY_TYPE = "ARENA_MODEL_QUERY_REQUEST";
|
|
360
361
|
var REPORT_SHARE_DEDUPE_LIMIT = 500;
|
|
362
|
+
var MODEL_QUERY_DEDUPE_LIMIT = 500;
|
|
361
363
|
var processedArenaReportShareEventIds = /* @__PURE__ */ new Set();
|
|
362
364
|
var processedArenaReportShareEventOrder = [];
|
|
363
365
|
var inFlightArenaReportShareEventIds = /* @__PURE__ */ new Map();
|
|
366
|
+
var processedArenaModelQueryEventIds = /* @__PURE__ */ new Set();
|
|
367
|
+
var processedArenaModelQueryEventOrder = [];
|
|
368
|
+
var inFlightArenaModelQueryEventIds = /* @__PURE__ */ new Map();
|
|
364
369
|
function mapInboundFrame(frame) {
|
|
365
370
|
if (frame.type === "PRIVATE_MESSAGE") {
|
|
366
371
|
const payload = assertPrivatePayload(frame.payload);
|
|
@@ -421,40 +426,54 @@ async function handleInboundFrame(input) {
|
|
|
421
426
|
await ackFrameSeq(input);
|
|
422
427
|
return;
|
|
423
428
|
}
|
|
424
|
-
let
|
|
429
|
+
let dedupeState = null;
|
|
425
430
|
if (isArenaReportShareEnvelope(envelope)) {
|
|
426
|
-
|
|
427
|
-
|
|
431
|
+
dedupeState = {
|
|
432
|
+
eventId: String(envelope.metadata.eventId),
|
|
433
|
+
processed: processedArenaReportShareEventIds,
|
|
434
|
+
inFlight: inFlightArenaReportShareEventIds,
|
|
435
|
+
remember: rememberArenaReportShareEventId
|
|
436
|
+
};
|
|
437
|
+
} else if (isArenaModelQueryEnvelope(envelope)) {
|
|
438
|
+
dedupeState = {
|
|
439
|
+
eventId: String(envelope.metadata.eventId),
|
|
440
|
+
processed: processedArenaModelQueryEventIds,
|
|
441
|
+
inFlight: inFlightArenaModelQueryEventIds,
|
|
442
|
+
remember: rememberArenaModelQueryEventId
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
if (dedupeState) {
|
|
446
|
+
if (dedupeState.processed.has(dedupeState.eventId)) {
|
|
428
447
|
await ackFrameSeq(input);
|
|
429
448
|
return;
|
|
430
449
|
}
|
|
431
|
-
const inFlight =
|
|
450
|
+
const inFlight = dedupeState.inFlight.get(dedupeState.eventId);
|
|
432
451
|
if (inFlight) {
|
|
433
452
|
await inFlight;
|
|
434
|
-
if (
|
|
453
|
+
if (dedupeState.processed.has(dedupeState.eventId)) {
|
|
435
454
|
await ackFrameSeq(input);
|
|
436
455
|
return;
|
|
437
456
|
}
|
|
438
457
|
}
|
|
439
458
|
}
|
|
440
459
|
let inFlightDeferred = null;
|
|
441
|
-
if (
|
|
460
|
+
if (dedupeState) {
|
|
442
461
|
inFlightDeferred = createDeferred();
|
|
443
462
|
inFlightDeferred.promise.catch(() => void 0);
|
|
444
|
-
|
|
463
|
+
dedupeState.inFlight.set(dedupeState.eventId, inFlightDeferred.promise);
|
|
445
464
|
}
|
|
446
465
|
try {
|
|
447
466
|
await input.dispatch(envelope);
|
|
448
|
-
if (
|
|
449
|
-
|
|
467
|
+
if (dedupeState) {
|
|
468
|
+
dedupeState.remember(dedupeState.eventId);
|
|
450
469
|
inFlightDeferred?.resolve();
|
|
451
470
|
}
|
|
452
471
|
} catch (error) {
|
|
453
472
|
inFlightDeferred?.reject(error);
|
|
454
473
|
throw error;
|
|
455
474
|
} finally {
|
|
456
|
-
if (
|
|
457
|
-
|
|
475
|
+
if (dedupeState) {
|
|
476
|
+
dedupeState.inFlight.delete(dedupeState.eventId);
|
|
458
477
|
}
|
|
459
478
|
}
|
|
460
479
|
await ackProcessedSeq(input, envelope);
|
|
@@ -471,6 +490,9 @@ function createDeferred() {
|
|
|
471
490
|
function isArenaReportShareEnvelope(envelope) {
|
|
472
491
|
return envelope.metadata?.arenaReportShareRequest === true && typeof envelope.metadata.eventId === "string" && envelope.metadata.eventId.length > 0;
|
|
473
492
|
}
|
|
493
|
+
function isArenaModelQueryEnvelope(envelope) {
|
|
494
|
+
return envelope.metadata?.arenaModelQueryRequest === true && typeof envelope.metadata.eventId === "string" && envelope.metadata.eventId.length > 0 && typeof envelope.metadata.callbackUrl === "string" && envelope.metadata.callbackUrl.length > 0;
|
|
495
|
+
}
|
|
474
496
|
function mapNotificationFrame(frame) {
|
|
475
497
|
const payload = isRecord3(frame.payload) ? frame.payload : {};
|
|
476
498
|
const seq = typeof payload.seq === "number" ? payload.seq : void 0;
|
|
@@ -509,6 +531,9 @@ function mapNotificationFrame(frame) {
|
|
|
509
531
|
if (notifyType === ARENA_REPORT_SHARE_NOTIFY_TYPE) {
|
|
510
532
|
return mapArenaReportShareFrame(frame, payload, seq);
|
|
511
533
|
}
|
|
534
|
+
if (notifyType === ARENA_MODEL_QUERY_NOTIFY_TYPE) {
|
|
535
|
+
return mapArenaModelQueryFrame(frame, payload, seq);
|
|
536
|
+
}
|
|
512
537
|
const postId = payload.postId != null ? String(payload.postId) : "";
|
|
513
538
|
return {
|
|
514
539
|
id: frame.id,
|
|
@@ -523,6 +548,41 @@ function mapNotificationFrame(frame) {
|
|
|
523
548
|
}
|
|
524
549
|
return null;
|
|
525
550
|
}
|
|
551
|
+
function mapArenaModelQueryFrame(frame, payload, seq) {
|
|
552
|
+
const eventId = typeof payload.eventId === "string" && payload.eventId.length > 0 ? payload.eventId : frame.id;
|
|
553
|
+
const traceId = typeof payload.traceId === "string" ? payload.traceId : "";
|
|
554
|
+
const modelQueryPayload = isRecord3(payload.payload) ? payload.payload : {};
|
|
555
|
+
const roomId = Number(modelQueryPayload.roomId ?? 0);
|
|
556
|
+
const seatNumber = Number(modelQueryPayload.seatNumber ?? 0);
|
|
557
|
+
const seatEpoch = modelQueryPayload.seatEpoch != null ? String(modelQueryPayload.seatEpoch) : "";
|
|
558
|
+
const callbackUrl = typeof modelQueryPayload.callbackUrl === "string" ? modelQueryPayload.callbackUrl : "";
|
|
559
|
+
if (!callbackUrl) {
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
const deadlineEpochMs = Number(modelQueryPayload.deadlineEpochMs ?? 0);
|
|
563
|
+
return {
|
|
564
|
+
id: eventId,
|
|
565
|
+
channel: "coolclaw",
|
|
566
|
+
conversationId: `notification:arena_model_query:${eventId}`,
|
|
567
|
+
text: "/model",
|
|
568
|
+
messageType: frame.type,
|
|
569
|
+
seq,
|
|
570
|
+
shouldReply: true,
|
|
571
|
+
metadata: {
|
|
572
|
+
sourceFrameId: frame.id,
|
|
573
|
+
payload: frame.payload,
|
|
574
|
+
modelQueryPayload,
|
|
575
|
+
arenaModelQueryRequest: true,
|
|
576
|
+
eventId,
|
|
577
|
+
traceId,
|
|
578
|
+
roomId,
|
|
579
|
+
seatNumber,
|
|
580
|
+
seatEpoch,
|
|
581
|
+
callbackUrl,
|
|
582
|
+
deadlineEpochMs
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
}
|
|
526
586
|
function mapArenaReportShareFrame(frame, payload, seq) {
|
|
527
587
|
const eventId = typeof payload.eventId === "string" && payload.eventId.length > 0 ? payload.eventId : frame.id;
|
|
528
588
|
const traceId = typeof payload.traceId === "string" ? payload.traceId : "";
|
|
@@ -555,6 +615,15 @@ function rememberArenaReportShareEventId(eventId) {
|
|
|
555
615
|
if (expired) processedArenaReportShareEventIds.delete(expired);
|
|
556
616
|
}
|
|
557
617
|
}
|
|
618
|
+
function rememberArenaModelQueryEventId(eventId) {
|
|
619
|
+
if (processedArenaModelQueryEventIds.has(eventId)) return;
|
|
620
|
+
processedArenaModelQueryEventIds.add(eventId);
|
|
621
|
+
processedArenaModelQueryEventOrder.push(eventId);
|
|
622
|
+
while (processedArenaModelQueryEventOrder.length > MODEL_QUERY_DEDUPE_LIMIT) {
|
|
623
|
+
const expired = processedArenaModelQueryEventOrder.shift();
|
|
624
|
+
if (expired) processedArenaModelQueryEventIds.delete(expired);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
558
627
|
function mapGameEventFrame(frame, payload) {
|
|
559
628
|
const eventType = typeof payload.eventType === "string" ? payload.eventType : "UNKNOWN";
|
|
560
629
|
const agentTask = normalizeAgentTask(payload.agentTask);
|
|
@@ -1027,6 +1096,117 @@ function parseErrorReason(error) {
|
|
|
1027
1096
|
return error.error;
|
|
1028
1097
|
}
|
|
1029
1098
|
|
|
1099
|
+
// src/arena-model-query.ts
|
|
1100
|
+
function parseArenaModelCurrent(rawText) {
|
|
1101
|
+
if (!rawText) return null;
|
|
1102
|
+
const match = /^\s*Current\s*[::]\s*(.+)$/im.exec(rawText);
|
|
1103
|
+
if (!match) return null;
|
|
1104
|
+
const firstToken = match[1].trim().split(/\s+/)[0] ?? "";
|
|
1105
|
+
const normalized = trimModelToken(firstToken);
|
|
1106
|
+
if (!normalized || normalized.length > 255 || normalized.endsWith("/")) return null;
|
|
1107
|
+
if (/^(usage|help|available|models?|current)$/i.test(normalized)) return null;
|
|
1108
|
+
return normalized;
|
|
1109
|
+
}
|
|
1110
|
+
async function submitArenaModelQueryCallback(input) {
|
|
1111
|
+
const start = Date.now();
|
|
1112
|
+
const rawHash = input.rawText ? sha256Hex(input.rawText) : "";
|
|
1113
|
+
const rawPreview = rawResponsePreview(input.rawText) ?? "";
|
|
1114
|
+
try {
|
|
1115
|
+
if (!input.meta.callbackUrl || !input.token) {
|
|
1116
|
+
input.log?.warn?.(
|
|
1117
|
+
`[ARENA-MODEL] callback skipped eventId=${input.meta.eventId} reason=missing_callback_or_token rawHash=${rawHash} rawPreview=${rawPreview}`
|
|
1118
|
+
);
|
|
1119
|
+
return { ok: false, error: "missing_callback_or_token" };
|
|
1120
|
+
}
|
|
1121
|
+
const fetchImpl = input.fetchImpl ?? globalThis.fetch;
|
|
1122
|
+
if (typeof fetchImpl !== "function") {
|
|
1123
|
+
input.log?.warn?.(`[ARENA-MODEL] callback skipped eventId=${input.meta.eventId} reason=fetch_unavailable`);
|
|
1124
|
+
return { ok: false, error: "fetch_unavailable" };
|
|
1125
|
+
}
|
|
1126
|
+
const response = await fetchImpl(input.meta.callbackUrl, {
|
|
1127
|
+
method: "POST",
|
|
1128
|
+
headers: {
|
|
1129
|
+
Authorization: `Bearer ${input.token}`,
|
|
1130
|
+
"Content-Type": "application/json"
|
|
1131
|
+
},
|
|
1132
|
+
body: JSON.stringify({
|
|
1133
|
+
eventId: input.meta.eventId,
|
|
1134
|
+
roomId: input.meta.roomId,
|
|
1135
|
+
seatNumber: input.meta.seatNumber,
|
|
1136
|
+
seatEpoch: input.meta.seatEpoch,
|
|
1137
|
+
rawText: input.rawText
|
|
1138
|
+
})
|
|
1139
|
+
});
|
|
1140
|
+
const body = await readJsonObject(response);
|
|
1141
|
+
const data = isRecord4(body.data) ? body.data : body;
|
|
1142
|
+
const accepted = data.accepted === true;
|
|
1143
|
+
const result = { ok: response.ok, status: response.status, accepted };
|
|
1144
|
+
const level = response.ok ? "info" : "warn";
|
|
1145
|
+
input.log?.[level]?.(
|
|
1146
|
+
`[ARENA-MODEL] callback status=${response.status} accepted=${accepted} eventId=${input.meta.eventId} roomId=${input.meta.roomId} seatEpoch=${input.meta.seatEpoch} elapsedMs=${Date.now() - start} rawHash=${rawHash} rawPreview=${rawPreview}`
|
|
1147
|
+
);
|
|
1148
|
+
return result;
|
|
1149
|
+
} catch (error) {
|
|
1150
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1151
|
+
input.log?.warn?.(
|
|
1152
|
+
`[ARENA-MODEL] callback failed eventId=${input.meta.eventId} roomId=${input.meta.roomId} seatEpoch=${input.meta.seatEpoch} elapsedMs=${Date.now() - start} err=${message} rawHash=${rawHash} rawPreview=${rawPreview}`
|
|
1153
|
+
);
|
|
1154
|
+
return { ok: false, error: message };
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
function createArenaModelQueryReplyCollector(input) {
|
|
1158
|
+
const blocks = [];
|
|
1159
|
+
let submitted = false;
|
|
1160
|
+
const submit = input.submit ?? ((rawText) => submitArenaModelQueryCallback({
|
|
1161
|
+
meta: input.meta,
|
|
1162
|
+
token: input.token,
|
|
1163
|
+
rawText,
|
|
1164
|
+
log: input.log
|
|
1165
|
+
}));
|
|
1166
|
+
async function submitOnce(rawText, reason) {
|
|
1167
|
+
if (submitted) return;
|
|
1168
|
+
submitted = true;
|
|
1169
|
+
input.log?.info?.(
|
|
1170
|
+
`[ARENA-MODEL] dispatch submit reason=${reason} eventId=${input.meta.eventId} roomId=${input.meta.roomId} seatEpoch=${input.meta.seatEpoch} blocks=${blocks.length} parsed=${parseArenaModelCurrent(rawText) ? "true" : "false"}`
|
|
1171
|
+
);
|
|
1172
|
+
await submit(rawText);
|
|
1173
|
+
}
|
|
1174
|
+
return {
|
|
1175
|
+
async deliver(text) {
|
|
1176
|
+
if (submitted || !text) return;
|
|
1177
|
+
blocks.push(text);
|
|
1178
|
+
const full = blocks.join("");
|
|
1179
|
+
input.log?.info?.(
|
|
1180
|
+
`[ARENA-MODEL] dispatch block eventId=${input.meta.eventId} roomId=${input.meta.roomId} seatEpoch=${input.meta.seatEpoch} blocks=${blocks.length} parsed=${parseArenaModelCurrent(full) ? "true" : "false"}`
|
|
1181
|
+
);
|
|
1182
|
+
if (parseArenaModelCurrent(full)) {
|
|
1183
|
+
await submitOnce(full, "parsed");
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
async finalize() {
|
|
1187
|
+
if (submitted) return;
|
|
1188
|
+
await submitOnce(blocks.join(""), "final");
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function trimModelToken(token) {
|
|
1193
|
+
let value = token.trim();
|
|
1194
|
+
value = value.replace(/^[`"'“”‘’<({\[【]+/, "");
|
|
1195
|
+
value = value.replace(/[`"'“”‘’>)}\]】。..,,;;::]+$/g, "");
|
|
1196
|
+
return value.trim();
|
|
1197
|
+
}
|
|
1198
|
+
async function readJsonObject(response) {
|
|
1199
|
+
try {
|
|
1200
|
+
const body = await response.json();
|
|
1201
|
+
return isRecord4(body) ? body : {};
|
|
1202
|
+
} catch {
|
|
1203
|
+
return {};
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
function isRecord4(value) {
|
|
1207
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1030
1210
|
// src/ws-client.ts
|
|
1031
1211
|
import WebSocket from "ws";
|
|
1032
1212
|
var CoolclawWsClient = class {
|
|
@@ -1239,18 +1419,18 @@ var CoolclawWsClient = class {
|
|
|
1239
1419
|
}
|
|
1240
1420
|
};
|
|
1241
1421
|
function readPingInterval(payload) {
|
|
1242
|
-
if (!
|
|
1422
|
+
if (!isRecord5(payload) || typeof payload.pingIntervalMs !== "number" || payload.pingIntervalMs <= 0) {
|
|
1243
1423
|
return void 0;
|
|
1244
1424
|
}
|
|
1245
1425
|
return payload.pingIntervalMs;
|
|
1246
1426
|
}
|
|
1247
1427
|
function readErrorMessage(payload) {
|
|
1248
|
-
if (
|
|
1428
|
+
if (isRecord5(payload) && typeof payload.message === "string") {
|
|
1249
1429
|
return payload.message;
|
|
1250
1430
|
}
|
|
1251
1431
|
return "CoolClaw request failed";
|
|
1252
1432
|
}
|
|
1253
|
-
function
|
|
1433
|
+
function isRecord5(value) {
|
|
1254
1434
|
return typeof value === "object" && value !== null;
|
|
1255
1435
|
}
|
|
1256
1436
|
|
|
@@ -1406,6 +1586,18 @@ function isNoReplyText(text) {
|
|
|
1406
1586
|
const lastLine = lines.at(-1)?.toUpperCase();
|
|
1407
1587
|
return lastLine ? noReplyTokens.has(lastLine) : false;
|
|
1408
1588
|
}
|
|
1589
|
+
function shouldSuppressCoolclawTextDelivery(envelope) {
|
|
1590
|
+
return envelope.metadata?.gameEvent === true || isArenaReportShareEnvelope(envelope) || isArenaModelQueryEnvelope(envelope);
|
|
1591
|
+
}
|
|
1592
|
+
async function finalizeArenaModelQueryAfterDispatchError(params) {
|
|
1593
|
+
if (!params.collector) {
|
|
1594
|
+
return false;
|
|
1595
|
+
}
|
|
1596
|
+
const errMsg = params.error instanceof Error ? params.error.message : String(params.error);
|
|
1597
|
+
params.log?.warn?.(`[ARENA-MODEL] dispatch failed; submitting fallback callback eventId=${params.eventId ?? ""} err=${errMsg}`);
|
|
1598
|
+
await params.collector.finalize();
|
|
1599
|
+
return true;
|
|
1600
|
+
}
|
|
1409
1601
|
var runtimeClients = /* @__PURE__ */ new Map();
|
|
1410
1602
|
function setRuntimeClient(accountKey, client) {
|
|
1411
1603
|
runtimeClients.set(accountKey, client);
|
|
@@ -1555,18 +1747,37 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1555
1747
|
dispatch: async (envelope) => {
|
|
1556
1748
|
const isGameEvent = envelope.metadata?.gameEvent === true;
|
|
1557
1749
|
const isArenaReportShare = isArenaReportShareEnvelope(envelope);
|
|
1750
|
+
const isArenaModelQuery = isArenaModelQueryEnvelope(envelope);
|
|
1751
|
+
const suppressChatTextDelivery = shouldSuppressCoolclawTextDelivery(envelope);
|
|
1558
1752
|
const gameMeta = isGameEvent ? envelope.metadata : null;
|
|
1753
|
+
const modelQueryMeta = isArenaModelQuery ? envelope.metadata : null;
|
|
1559
1754
|
let gameSubmitted = false;
|
|
1560
1755
|
let gameFallbackReason = null;
|
|
1561
1756
|
let gameModelActionType;
|
|
1562
1757
|
let gameValidationReason;
|
|
1563
1758
|
let gameModelActionRejected;
|
|
1564
1759
|
const gameBuffer = [];
|
|
1760
|
+
const modelQueryCollector = modelQueryMeta ? createArenaModelQueryReplyCollector({
|
|
1761
|
+
meta: modelQueryMeta,
|
|
1762
|
+
token,
|
|
1763
|
+
log: ctx.log
|
|
1764
|
+
}) : null;
|
|
1565
1765
|
if (isGameEvent && gameMeta) {
|
|
1566
1766
|
ctx.log?.info?.(
|
|
1567
1767
|
`[GAME-TASK] dispatch start gameId=${gameMeta.gameId} roomId=${gameMeta.roomId} eventType=${gameMeta.eventType} eventId=${gameMeta.eventId} promptPolicyVersion=${gameMeta.promptPolicyVersion ?? ""} renderedPromptHash=${gameMeta.renderedPromptHash ?? ""} conversationId=${envelope.conversationId}`
|
|
1568
1768
|
);
|
|
1569
1769
|
}
|
|
1770
|
+
if (modelQueryMeta) {
|
|
1771
|
+
let callbackHost = "";
|
|
1772
|
+
try {
|
|
1773
|
+
callbackHost = new URL(modelQueryMeta.callbackUrl).host;
|
|
1774
|
+
} catch {
|
|
1775
|
+
callbackHost = "invalid";
|
|
1776
|
+
}
|
|
1777
|
+
ctx.log?.info?.(
|
|
1778
|
+
`[ARENA-MODEL] inbound eventId=${modelQueryMeta.eventId} traceId=${modelQueryMeta.traceId ?? ""} roomId=${modelQueryMeta.roomId} seatEpoch=${modelQueryMeta.seatEpoch} callbackHost=${callbackHost} conversationId=${envelope.conversationId}`
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1570
1781
|
const runtime = getCoolclawRuntime();
|
|
1571
1782
|
let runtimeChannel;
|
|
1572
1783
|
try {
|
|
@@ -1589,6 +1800,15 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1589
1800
|
}
|
|
1590
1801
|
return;
|
|
1591
1802
|
}
|
|
1803
|
+
if (modelQueryMeta) {
|
|
1804
|
+
await submitArenaModelQueryCallback({
|
|
1805
|
+
meta: modelQueryMeta,
|
|
1806
|
+
token,
|
|
1807
|
+
rawText: "",
|
|
1808
|
+
log: ctx.log
|
|
1809
|
+
});
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1592
1812
|
throw err;
|
|
1593
1813
|
}
|
|
1594
1814
|
try {
|
|
@@ -1614,13 +1834,13 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1614
1834
|
ctx.cfg.session?.store,
|
|
1615
1835
|
{ agentId: route.agentId }
|
|
1616
1836
|
);
|
|
1617
|
-
const senderLabel = envelope.sender ? `${envelope.sender.userType.toLowerCase()}:${envelope.sender.userId}` : isGameEvent ? `game:${gameMeta.gameId}` : "unknown";
|
|
1837
|
+
const senderLabel = envelope.sender ? `${envelope.sender.userType.toLowerCase()}:${envelope.sender.userId}` : isGameEvent ? `game:${gameMeta.gameId}` : modelQueryMeta ? `arena-model:${modelQueryMeta.roomId}` : "unknown";
|
|
1618
1838
|
let deliveryTarget;
|
|
1619
1839
|
if (envelope.group) {
|
|
1620
1840
|
deliveryTarget = `coolclaw:group:${envelope.group.groupId}`;
|
|
1621
1841
|
} else if (envelope.sender) {
|
|
1622
1842
|
deliveryTarget = `coolclaw:${envelope.sender.userType.toLowerCase()}:${envelope.sender.userId}`;
|
|
1623
|
-
} else if (isGameEvent) {
|
|
1843
|
+
} else if (isGameEvent || isArenaModelQuery) {
|
|
1624
1844
|
deliveryTarget = `coolclaw:agent:${account.agentId}`;
|
|
1625
1845
|
} else {
|
|
1626
1846
|
deliveryTarget = normalizeCoolclawTarget(envelope.conversationId);
|
|
@@ -1684,6 +1904,10 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1684
1904
|
if (!payload.text) return;
|
|
1685
1905
|
const replyText = String(payload.text);
|
|
1686
1906
|
if (!isGameEvent && isNoReplyText(replyText)) return;
|
|
1907
|
+
if (modelQueryCollector) {
|
|
1908
|
+
await modelQueryCollector.deliver(replyText);
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1687
1911
|
if (isGameEvent && gameMeta) {
|
|
1688
1912
|
if (gameSubmitted) return;
|
|
1689
1913
|
gameBuffer.push(String(payload.text));
|
|
@@ -1727,6 +1951,10 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1727
1951
|
ctx.log?.info?.(`[ARENA-REPORT-SHARE] ignored non-chat completion text eventId=${envelope.metadata.eventId ?? ""}`);
|
|
1728
1952
|
return;
|
|
1729
1953
|
}
|
|
1954
|
+
if (suppressChatTextDelivery) {
|
|
1955
|
+
ctx.log?.error?.(`[ARENA-MODEL] chat delivery blocked eventId=${envelope.metadata.eventId ?? ""}`);
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1730
1958
|
try {
|
|
1731
1959
|
let replyTarget;
|
|
1732
1960
|
if (envelope.group) {
|
|
@@ -1751,9 +1979,20 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
1751
1979
|
gameFallbackReason = "no_valid_action_in_llm_output";
|
|
1752
1980
|
}
|
|
1753
1981
|
}
|
|
1982
|
+
if (modelQueryCollector) {
|
|
1983
|
+
await modelQueryCollector.finalize();
|
|
1984
|
+
}
|
|
1754
1985
|
} catch (err) {
|
|
1755
1986
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
1756
1987
|
ctx.log?.error(`Inbound dispatch error: ${errMsg}`);
|
|
1988
|
+
if (await finalizeArenaModelQueryAfterDispatchError({
|
|
1989
|
+
collector: modelQueryCollector,
|
|
1990
|
+
eventId: modelQueryMeta?.eventId,
|
|
1991
|
+
error: err,
|
|
1992
|
+
log: ctx.log
|
|
1993
|
+
})) {
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1757
1996
|
if (isGameEvent && gameMeta && !gameSubmitted) {
|
|
1758
1997
|
gameFallbackReason = `dispatch_error: ${errMsg}`;
|
|
1759
1998
|
}
|
package/dist/cli-metadata.js
CHANGED
package/dist/index.js
CHANGED
package/dist/setup-entry.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coolclaw/coolclaw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "OpenClaw native channel plugin for Riddle/CoolClaw chat.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"runtimeSetupEntry": "./dist/setup-entry.js",
|
|
73
73
|
"install": {
|
|
74
74
|
"npmSpec": "@coolclaw/coolclaw",
|
|
75
|
-
"expectedIntegrity": "sha512-
|
|
75
|
+
"expectedIntegrity": "sha512-W0ARihskllfGJhQE00/znWvLszcLNgSa1FZPblBs176iVJ/o6jR+7N3Khl8njWMtrvd1v3nkrB4eIuvEiIg4vg==",
|
|
76
76
|
"defaultChoice": "npm",
|
|
77
77
|
"minHostVersion": ">=2026.3.22"
|
|
78
78
|
},
|