@coolclaw/coolclaw 1.0.19 → 1.0.21
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)) {
|
|
@@ -679,6 +691,9 @@ function isArenaModelQueryEnvelope(envelope) {
|
|
|
679
691
|
function isArenaVoiceSelectEnvelope(envelope) {
|
|
680
692
|
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
693
|
}
|
|
694
|
+
function isArenaPluginUpgradeEnvelope(envelope) {
|
|
695
|
+
return envelope.metadata?.arenaPluginUpgradeRequest === true && typeof envelope.metadata.eventId === "string" && envelope.metadata.eventId.length > 0;
|
|
696
|
+
}
|
|
682
697
|
function mapNotificationFrame(frame) {
|
|
683
698
|
const payload = isRecord3(frame.payload) ? frame.payload : {};
|
|
684
699
|
const seq = typeof payload.seq === "number" ? payload.seq : void 0;
|
|
@@ -723,6 +738,9 @@ function mapNotificationFrame(frame) {
|
|
|
723
738
|
if (notifyType === ARENA_VOICE_SELECT_NOTIFY_TYPE) {
|
|
724
739
|
return mapArenaVoiceSelectFrame(frame, payload, seq);
|
|
725
740
|
}
|
|
741
|
+
if (notifyType === ARENA_PLUGIN_UPGRADE_NOTIFY_TYPE) {
|
|
742
|
+
return mapArenaPluginUpgradeFrame(frame, payload, seq);
|
|
743
|
+
}
|
|
726
744
|
const postId = payload.postId != null ? String(payload.postId) : "";
|
|
727
745
|
return {
|
|
728
746
|
id: frame.id,
|
|
@@ -840,6 +858,29 @@ function mapArenaReportShareFrame(frame, payload, seq) {
|
|
|
840
858
|
}
|
|
841
859
|
};
|
|
842
860
|
}
|
|
861
|
+
function mapArenaPluginUpgradeFrame(frame, payload, seq) {
|
|
862
|
+
const eventId = typeof payload.eventId === "string" && payload.eventId.length > 0 ? payload.eventId : frame.id;
|
|
863
|
+
const traceId = typeof payload.traceId === "string" ? payload.traceId : "";
|
|
864
|
+
const upgradePayload = isRecord3(payload.payload) ? payload.payload : {};
|
|
865
|
+
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";
|
|
866
|
+
return {
|
|
867
|
+
id: eventId,
|
|
868
|
+
channel: "coolclaw",
|
|
869
|
+
conversationId: `notification:arena_plugin_upgrade:${eventId}`,
|
|
870
|
+
text: prompt,
|
|
871
|
+
messageType: frame.type,
|
|
872
|
+
seq,
|
|
873
|
+
shouldReply: true,
|
|
874
|
+
metadata: {
|
|
875
|
+
sourceFrameId: frame.id,
|
|
876
|
+
payload: frame.payload,
|
|
877
|
+
pluginUpgradePayload: upgradePayload,
|
|
878
|
+
arenaPluginUpgradeRequest: true,
|
|
879
|
+
eventId,
|
|
880
|
+
traceId
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
}
|
|
843
884
|
function rememberArenaReportShareEventId(eventId) {
|
|
844
885
|
if (processedArenaReportShareEventIds.has(eventId)) return;
|
|
845
886
|
processedArenaReportShareEventIds.add(eventId);
|
|
@@ -867,6 +908,15 @@ function rememberArenaVoiceSelectEventId(eventId) {
|
|
|
867
908
|
if (expired) processedArenaVoiceSelectEventIds.delete(expired);
|
|
868
909
|
}
|
|
869
910
|
}
|
|
911
|
+
function rememberArenaPluginUpgradeEventId(eventId) {
|
|
912
|
+
if (processedArenaPluginUpgradeEventIds.has(eventId)) return;
|
|
913
|
+
processedArenaPluginUpgradeEventIds.add(eventId);
|
|
914
|
+
processedArenaPluginUpgradeEventOrder.push(eventId);
|
|
915
|
+
while (processedArenaPluginUpgradeEventOrder.length > PLUGIN_UPGRADE_DEDUPE_LIMIT) {
|
|
916
|
+
const expired = processedArenaPluginUpgradeEventOrder.shift();
|
|
917
|
+
if (expired) processedArenaPluginUpgradeEventIds.delete(expired);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
870
920
|
function mapGameEventFrame(frame, payload) {
|
|
871
921
|
const eventType = typeof payload.eventType === "string" ? payload.eventType : "UNKNOWN";
|
|
872
922
|
const agentTask = normalizeAgentTask(payload.agentTask);
|
|
@@ -2035,12 +2085,50 @@ function logAckFailure(params) {
|
|
|
2035
2085
|
const target = params.target ? ` target=${params.target}` : "";
|
|
2036
2086
|
params.log(`${params.channel} ack cleanup failed${target}: ${String(params.error)}`);
|
|
2037
2087
|
}
|
|
2038
|
-
function buildStructuredActionRetryPrompt(renderedPrompt, reason) {
|
|
2088
|
+
function buildStructuredActionRetryPrompt(renderedPrompt, reason, agentTask) {
|
|
2039
2089
|
const reasonText = reason && reason.trim().length > 0 ? reason.trim() : "invalid_output";
|
|
2090
|
+
const translatedReason = translateStructuredRetryReason(reasonText);
|
|
2091
|
+
const allowedActionTypes2 = agentTask?.actionContract?.options?.map((option) => option.actionType).filter((actionType) => typeof actionType === "string" && actionType.length > 0) ?? [];
|
|
2092
|
+
const allowedLine = allowedActionTypes2.length > 0 ? `
|
|
2093
|
+
\u5F53\u524D\u53EA\u5141\u8BB8 actionType\uFF1A${allowedActionTypes2.join("\u3001")}\u3002` : "";
|
|
2094
|
+
const forbiddenNames = [...forbiddenLegacyActionNames(allowedActionTypes2), "SUBMIT_ACTION", "reason", "content"];
|
|
2095
|
+
const forbiddenLine = allowedActionTypes2.length > 0 ? `
|
|
2096
|
+
\u4E0D\u8981\u4F7F\u7528 ${joinChineseOr(forbiddenNames)}\u3002` : "";
|
|
2040
2097
|
return `${renderedPrompt}
|
|
2041
2098
|
|
|
2042
|
-
|
|
2043
|
-
\u8BF7\u91CD\u65B0\
|
|
2099
|
+
${translatedReason}${allowedLine}${forbiddenLine}
|
|
2100
|
+
\u8BF7\u6309\u4E0A\u65B9\u3010\u8F93\u51FA\u683C\u5F0F\u3011\u91CD\u65B0\u8F93\u51FA\u5B8C\u6574 JSON\uFF1B\u53EA\u8F93\u51FA\u4E00\u4E2A\u5B8C\u6574 JSON \u5BF9\u8C61\uFF0C\u4E0D\u8981\u8F93\u51FA Markdown\u3001\u89E3\u91CA\u6587\u5B57\u6216\u4EE3\u7801\u5757\u3002`;
|
|
2101
|
+
}
|
|
2102
|
+
function translateStructuredRetryReason(reasonText) {
|
|
2103
|
+
if (reasonText === "disallowed_action_type") {
|
|
2104
|
+
return "\u4E0A\u4E00\u6B21\u8F93\u51FA\u672A\u88AB\u63A5\u53D7\uFF1AactionType \u4E0D\u5728\u5F53\u524D\u5141\u8BB8\u5217\u8868\u3002";
|
|
2105
|
+
}
|
|
2106
|
+
if (reasonText === "invalid_action_shape") {
|
|
2107
|
+
return "\u4E0A\u4E00\u6B21\u8F93\u51FA\u672A\u88AB\u63A5\u53D7\uFF1AJSON \u5B57\u6BB5\u7ED3\u6784\u4E0D\u7B26\u5408\u5F53\u524D\u3010\u8F93\u51FA\u683C\u5F0F\u3011\u3002";
|
|
2108
|
+
}
|
|
2109
|
+
if (reasonText === "missing_contract") {
|
|
2110
|
+
return "\u4E0A\u4E00\u6B21\u8F93\u51FA\u672A\u88AB\u63A5\u53D7\uFF1A\u5F53\u524D\u4EFB\u52A1\u7F3A\u5C11\u53EF\u63D0\u4EA4\u7684\u52A8\u4F5C\u5951\u7EA6\u3002";
|
|
2111
|
+
}
|
|
2112
|
+
return `\u4E0A\u4E00\u6B21\u8F93\u51FA\u672A\u88AB\u63A5\u53D7\uFF0C\u5931\u8D25\u539F\u56E0\uFF1A${reasonText}\u3002`;
|
|
2113
|
+
}
|
|
2114
|
+
function forbiddenLegacyActionNames(allowedActionTypes2) {
|
|
2115
|
+
const legacyNames = allowedActionTypes2.map((actionType) => {
|
|
2116
|
+
if (actionType === "WOLF_KILL") return "WOLF_TURN";
|
|
2117
|
+
if (actionType === "WITCH_SAVE" || actionType === "WITCH_POISON" || actionType === "WITCH_PASS") return "WITCH_TURN";
|
|
2118
|
+
if (actionType === "SEER_CHECK") return "SEER_TURN";
|
|
2119
|
+
if (actionType === "DAY_SPEAK") return "DAY_SPEAK_TURN";
|
|
2120
|
+
if (actionType === "DAY_VOTE") return "DAY_VOTE_TURN";
|
|
2121
|
+
if (actionType === "LAST_WORD") return "LAST_WORD_TURN";
|
|
2122
|
+
if (actionType === "HUNTER_SHOOT" || actionType === "HUNTER_PASS") return "HUNTER_SKILL_TURN";
|
|
2123
|
+
return void 0;
|
|
2124
|
+
}).filter((name) => Boolean(name));
|
|
2125
|
+
return [...new Set(legacyNames)];
|
|
2126
|
+
}
|
|
2127
|
+
function joinChineseOr(values) {
|
|
2128
|
+
if (values.length <= 1) {
|
|
2129
|
+
return values.join("");
|
|
2130
|
+
}
|
|
2131
|
+
return `${values.slice(0, -1).join("\u3001")} \u6216 ${values[values.length - 1]}`;
|
|
2044
2132
|
}
|
|
2045
2133
|
function hasStructuredRetryBudget(deadlineEpochMs, nowEpochMs = Date.now(), safetyMarginMs = 1e3) {
|
|
2046
2134
|
if (!deadlineEpochMs || deadlineEpochMs <= 0) {
|
|
@@ -2885,7 +2973,7 @@ var coolclawChannelPlugin = createChatChannelPlugin({
|
|
|
2885
2973
|
gameModelActionRejected = void 0;
|
|
2886
2974
|
gameModelActionType = void 0;
|
|
2887
2975
|
gameValidationReason = void 0;
|
|
2888
|
-
const retryPrompt = buildStructuredActionRetryPrompt(envelope.text, retryReason);
|
|
2976
|
+
const retryPrompt = buildStructuredActionRetryPrompt(envelope.text, retryReason, gameMeta.agentTask);
|
|
2889
2977
|
await dispatchGameReply({
|
|
2890
2978
|
...gameBaseReplyContext,
|
|
2891
2979
|
Body: retryPrompt,
|
package/dist/cli-metadata.js
CHANGED
package/dist/index.js
CHANGED
package/dist/setup-entry.js
CHANGED