@coolclaw/coolclaw 1.0.20 → 1.0.22
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.
|
@@ -530,9 +530,11 @@ function isRecord2(value) {
|
|
|
530
530
|
var ARENA_REPORT_SHARE_NOTIFY_TYPE = "ARENA_REPORT_SHARE_REQUEST";
|
|
531
531
|
var ARENA_MODEL_QUERY_NOTIFY_TYPE = "ARENA_MODEL_QUERY_REQUEST";
|
|
532
532
|
var ARENA_VOICE_SELECT_NOTIFY_TYPE = "ARENA_VOICE_SELECT_REQUEST";
|
|
533
|
+
var ARENA_PLUGIN_UPGRADE_NOTIFY_TYPE = "ARENA_PLUGIN_UPGRADE_REQUEST";
|
|
533
534
|
var REPORT_SHARE_DEDUPE_LIMIT = 500;
|
|
534
535
|
var MODEL_QUERY_DEDUPE_LIMIT = 500;
|
|
535
536
|
var VOICE_SELECT_DEDUPE_LIMIT = 500;
|
|
537
|
+
var PLUGIN_UPGRADE_DEDUPE_LIMIT = 500;
|
|
536
538
|
var processedArenaReportShareEventIds = /* @__PURE__ */ new Set();
|
|
537
539
|
var processedArenaReportShareEventOrder = [];
|
|
538
540
|
var inFlightArenaReportShareEventIds = /* @__PURE__ */ new Map();
|
|
@@ -542,6 +544,9 @@ var inFlightArenaModelQueryEventIds = /* @__PURE__ */ new Map();
|
|
|
542
544
|
var processedArenaVoiceSelectEventIds = /* @__PURE__ */ new Set();
|
|
543
545
|
var processedArenaVoiceSelectEventOrder = [];
|
|
544
546
|
var inFlightArenaVoiceSelectEventIds = /* @__PURE__ */ new Map();
|
|
547
|
+
var processedArenaPluginUpgradeEventIds = /* @__PURE__ */ new Set();
|
|
548
|
+
var processedArenaPluginUpgradeEventOrder = [];
|
|
549
|
+
var inFlightArenaPluginUpgradeEventIds = /* @__PURE__ */ new Map();
|
|
545
550
|
function mapInboundFrame(frame) {
|
|
546
551
|
if (frame.type === "PRIVATE_MESSAGE") {
|
|
547
552
|
const payload = assertPrivatePayload(frame.payload);
|
|
@@ -624,6 +629,13 @@ async function handleInboundFrame(input) {
|
|
|
624
629
|
inFlight: inFlightArenaVoiceSelectEventIds,
|
|
625
630
|
remember: rememberArenaVoiceSelectEventId
|
|
626
631
|
};
|
|
632
|
+
} else if (isArenaPluginUpgradeEnvelope(envelope)) {
|
|
633
|
+
dedupeState = {
|
|
634
|
+
eventId: String(envelope.metadata.eventId),
|
|
635
|
+
processed: processedArenaPluginUpgradeEventIds,
|
|
636
|
+
inFlight: inFlightArenaPluginUpgradeEventIds,
|
|
637
|
+
remember: rememberArenaPluginUpgradeEventId
|
|
638
|
+
};
|
|
627
639
|
}
|
|
628
640
|
if (dedupeState) {
|
|
629
641
|
if (dedupeState.processed.has(dedupeState.eventId)) {
|
|
@@ -639,6 +651,10 @@ async function handleInboundFrame(input) {
|
|
|
639
651
|
}
|
|
640
652
|
}
|
|
641
653
|
}
|
|
654
|
+
const gameEventEnvelope = isGameEventEnvelope(envelope);
|
|
655
|
+
if (gameEventEnvelope) {
|
|
656
|
+
await ackProcessedSeq(input, envelope);
|
|
657
|
+
}
|
|
642
658
|
let inFlightDeferred = null;
|
|
643
659
|
if (dedupeState) {
|
|
644
660
|
inFlightDeferred = createDeferred();
|
|
@@ -659,7 +675,9 @@ async function handleInboundFrame(input) {
|
|
|
659
675
|
dedupeState.inFlight.delete(dedupeState.eventId);
|
|
660
676
|
}
|
|
661
677
|
}
|
|
662
|
-
|
|
678
|
+
if (!gameEventEnvelope) {
|
|
679
|
+
await ackProcessedSeq(input, envelope);
|
|
680
|
+
}
|
|
663
681
|
}
|
|
664
682
|
function createDeferred() {
|
|
665
683
|
let resolve;
|
|
@@ -679,6 +697,12 @@ function isArenaModelQueryEnvelope(envelope) {
|
|
|
679
697
|
function isArenaVoiceSelectEnvelope(envelope) {
|
|
680
698
|
return envelope.metadata?.arenaVoiceSelectRequest === true && typeof envelope.metadata.eventId === "string" && envelope.metadata.eventId.length > 0 && typeof envelope.metadata.callbackUrl === "string" && envelope.metadata.callbackUrl.length > 0;
|
|
681
699
|
}
|
|
700
|
+
function isArenaPluginUpgradeEnvelope(envelope) {
|
|
701
|
+
return envelope.metadata?.arenaPluginUpgradeRequest === true && typeof envelope.metadata.eventId === "string" && envelope.metadata.eventId.length > 0;
|
|
702
|
+
}
|
|
703
|
+
function isGameEventEnvelope(envelope) {
|
|
704
|
+
return envelope.metadata?.gameEvent === true;
|
|
705
|
+
}
|
|
682
706
|
function mapNotificationFrame(frame) {
|
|
683
707
|
const payload = isRecord3(frame.payload) ? frame.payload : {};
|
|
684
708
|
const seq = typeof payload.seq === "number" ? payload.seq : void 0;
|
|
@@ -723,6 +747,9 @@ function mapNotificationFrame(frame) {
|
|
|
723
747
|
if (notifyType === ARENA_VOICE_SELECT_NOTIFY_TYPE) {
|
|
724
748
|
return mapArenaVoiceSelectFrame(frame, payload, seq);
|
|
725
749
|
}
|
|
750
|
+
if (notifyType === ARENA_PLUGIN_UPGRADE_NOTIFY_TYPE) {
|
|
751
|
+
return mapArenaPluginUpgradeFrame(frame, payload, seq);
|
|
752
|
+
}
|
|
726
753
|
const postId = payload.postId != null ? String(payload.postId) : "";
|
|
727
754
|
return {
|
|
728
755
|
id: frame.id,
|
|
@@ -840,6 +867,29 @@ function mapArenaReportShareFrame(frame, payload, seq) {
|
|
|
840
867
|
}
|
|
841
868
|
};
|
|
842
869
|
}
|
|
870
|
+
function mapArenaPluginUpgradeFrame(frame, payload, seq) {
|
|
871
|
+
const eventId = typeof payload.eventId === "string" && payload.eventId.length > 0 ? payload.eventId : frame.id;
|
|
872
|
+
const traceId = typeof payload.traceId === "string" ? payload.traceId : "";
|
|
873
|
+
const upgradePayload = isRecord3(payload.payload) ? payload.payload : {};
|
|
874
|
+
const prompt = typeof upgradePayload.prompt === "string" && upgradePayload.prompt.length > 0 ? upgradePayload.prompt : "\u8BF7\u5347\u7EA7 Clawtopia \u7684\u63D2\u4EF6\u548C Skill\uFF0C\u5347\u7EA7\u540E\u91CD\u65B0\u8FDE\u63A5\u81F3 Clawtopia\u3002";
|
|
875
|
+
return {
|
|
876
|
+
id: eventId,
|
|
877
|
+
channel: "coolclaw",
|
|
878
|
+
conversationId: `notification:arena_plugin_upgrade:${eventId}`,
|
|
879
|
+
text: prompt,
|
|
880
|
+
messageType: frame.type,
|
|
881
|
+
seq,
|
|
882
|
+
shouldReply: true,
|
|
883
|
+
metadata: {
|
|
884
|
+
sourceFrameId: frame.id,
|
|
885
|
+
payload: frame.payload,
|
|
886
|
+
pluginUpgradePayload: upgradePayload,
|
|
887
|
+
arenaPluginUpgradeRequest: true,
|
|
888
|
+
eventId,
|
|
889
|
+
traceId
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
}
|
|
843
893
|
function rememberArenaReportShareEventId(eventId) {
|
|
844
894
|
if (processedArenaReportShareEventIds.has(eventId)) return;
|
|
845
895
|
processedArenaReportShareEventIds.add(eventId);
|
|
@@ -867,6 +917,15 @@ function rememberArenaVoiceSelectEventId(eventId) {
|
|
|
867
917
|
if (expired) processedArenaVoiceSelectEventIds.delete(expired);
|
|
868
918
|
}
|
|
869
919
|
}
|
|
920
|
+
function rememberArenaPluginUpgradeEventId(eventId) {
|
|
921
|
+
if (processedArenaPluginUpgradeEventIds.has(eventId)) return;
|
|
922
|
+
processedArenaPluginUpgradeEventIds.add(eventId);
|
|
923
|
+
processedArenaPluginUpgradeEventOrder.push(eventId);
|
|
924
|
+
while (processedArenaPluginUpgradeEventOrder.length > PLUGIN_UPGRADE_DEDUPE_LIMIT) {
|
|
925
|
+
const expired = processedArenaPluginUpgradeEventOrder.shift();
|
|
926
|
+
if (expired) processedArenaPluginUpgradeEventIds.delete(expired);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
870
929
|
function mapGameEventFrame(frame, payload) {
|
|
871
930
|
const eventType = typeof payload.eventType === "string" ? payload.eventType : "UNKNOWN";
|
|
872
931
|
const agentTask = normalizeAgentTask(payload.agentTask);
|
|
@@ -2086,6 +2145,12 @@ function hasStructuredRetryBudget(deadlineEpochMs, nowEpochMs = Date.now(), safe
|
|
|
2086
2145
|
}
|
|
2087
2146
|
return nowEpochMs < deadlineEpochMs - Math.max(0, safetyMarginMs);
|
|
2088
2147
|
}
|
|
2148
|
+
function isGameDeadlineExpired(deadlineEpochMs, nowEpochMs = Date.now()) {
|
|
2149
|
+
return typeof deadlineEpochMs === "number" && deadlineEpochMs > 0 && nowEpochMs >= deadlineEpochMs;
|
|
2150
|
+
}
|
|
2151
|
+
function isTerminalGameActionSubmitStatus(status) {
|
|
2152
|
+
return status === "submitted" || status === "uncertain" || status === "expired";
|
|
2153
|
+
}
|
|
2089
2154
|
function shouldSubmitStructuredRejectedOutput(params) {
|
|
2090
2155
|
if (!params.structuredTask || params.gameSubmitted) {
|
|
2091
2156
|
return false;
|
|
@@ -2119,6 +2184,12 @@ function assertInboundRuntimeAvailable(runtime, context) {
|
|
|
2119
2184
|
throw new Error(`CoolClaw runtime.channel unavailable while dispatching ${context.messageType}`);
|
|
2120
2185
|
}
|
|
2121
2186
|
async function submitGameActionWithLog(action, meta, wsClient, log, source, rawResponse, auditMeta) {
|
|
2187
|
+
if (isGameDeadlineExpired(meta.deadlineEpochMs)) {
|
|
2188
|
+
log?.warn?.(
|
|
2189
|
+
`[GAME-ACTION] submit skipped: deadline expired source=${source} eventId=${meta.eventId} deadlineEpochMs=${meta.deadlineEpochMs}`
|
|
2190
|
+
);
|
|
2191
|
+
return "expired";
|
|
2192
|
+
}
|
|
2122
2193
|
if (!wsClient.isConnected()) {
|
|
2123
2194
|
log?.error?.(`[GAME-ACTION] submit skipped: ws not connected eventId=${meta.eventId}`);
|
|
2124
2195
|
return "failed";
|
|
@@ -2299,7 +2370,7 @@ async function submitStructuredFinalActionWithLog(params) {
|
|
|
2299
2370
|
}
|
|
2300
2371
|
);
|
|
2301
2372
|
return {
|
|
2302
|
-
submitted: status
|
|
2373
|
+
submitted: isTerminalGameActionSubmitStatus(status),
|
|
2303
2374
|
status,
|
|
2304
2375
|
reason: status === "failed" ? `llm_action_submit_failed:${validation.action.actionType}` : void 0,
|
|
2305
2376
|
rawHash,
|
|
@@ -2786,7 +2857,7 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
2786
2857
|
retryValidationReason: structuredTask && gameReplyAttempt > 0 ? validation.repairReason : void 0
|
|
2787
2858
|
}
|
|
2788
2859
|
);
|
|
2789
|
-
if (submitted
|
|
2860
|
+
if (isTerminalGameActionSubmitStatus(submitted)) {
|
|
2790
2861
|
gameSubmitted = true;
|
|
2791
2862
|
} else {
|
|
2792
2863
|
gameFallbackReason = `llm_action_submit_failed:${validation.action.actionType}`;
|
package/dist/cli-metadata.js
CHANGED
package/dist/index.js
CHANGED
package/dist/setup-entry.js
CHANGED