@coolclaw/coolclaw 1.0.17 → 1.0.18
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.
|
@@ -219,7 +219,8 @@ function validateAgentAction(action, task) {
|
|
|
219
219
|
if (!option) {
|
|
220
220
|
return { ok: false, reason: "disallowed_action_type" };
|
|
221
221
|
}
|
|
222
|
-
const
|
|
222
|
+
const sanitizedActionData = sanitizeActionData(action.actionData);
|
|
223
|
+
const repaired = repairActionDataForSchema(sanitizedActionData, option.actionDataSchema);
|
|
223
224
|
if (!matchesActionDataSchema(repaired.actionData, option.actionDataSchema)) {
|
|
224
225
|
return { ok: false, reason: "invalid_action_shape" };
|
|
225
226
|
}
|
|
@@ -231,7 +232,7 @@ function validateAgentAction(action, task) {
|
|
|
231
232
|
actionData: repaired.actionData
|
|
232
233
|
};
|
|
233
234
|
if (typeof action.speech === "string") normalizedAction.speech = action.speech;
|
|
234
|
-
if (typeof action.
|
|
235
|
+
if (typeof action.voteReason === "string") normalizedAction.voteReason = action.voteReason;
|
|
235
236
|
return {
|
|
236
237
|
ok: true,
|
|
237
238
|
action: normalizedAction,
|
|
@@ -296,9 +297,17 @@ function matchesRootOutputSchema(action, schema) {
|
|
|
296
297
|
actionData: action.actionData
|
|
297
298
|
};
|
|
298
299
|
if (typeof action.speech === "string") root.speech = action.speech;
|
|
299
|
-
if (typeof action.
|
|
300
|
+
if (typeof action.voteReason === "string") root.voteReason = action.voteReason;
|
|
300
301
|
return matchesSchemaValue(root, schema, true);
|
|
301
302
|
}
|
|
303
|
+
function sanitizeActionData(actionData) {
|
|
304
|
+
if (!Object.prototype.hasOwnProperty.call(actionData, "reason")) {
|
|
305
|
+
return actionData;
|
|
306
|
+
}
|
|
307
|
+
const sanitized = { ...actionData };
|
|
308
|
+
delete sanitized.reason;
|
|
309
|
+
return sanitized;
|
|
310
|
+
}
|
|
302
311
|
function repairActionDataForSchema(actionData, schema) {
|
|
303
312
|
if (!schema || Object.keys(schema).length === 0) {
|
|
304
313
|
return { actionData };
|
|
@@ -1111,7 +1120,7 @@ async function sendGameAction(input) {
|
|
|
1111
1120
|
retryRawResponseHash: input.retryRawResponseHash,
|
|
1112
1121
|
retryValidationReason: input.retryValidationReason,
|
|
1113
1122
|
speech: input.speech,
|
|
1114
|
-
|
|
1123
|
+
voteReason: input.voteReason
|
|
1115
1124
|
});
|
|
1116
1125
|
const response = await input.client.request(frame);
|
|
1117
1126
|
if (response.ok === false) {
|
|
@@ -1121,15 +1130,6 @@ async function sendGameAction(input) {
|
|
|
1121
1130
|
}
|
|
1122
1131
|
|
|
1123
1132
|
// src/game-action-parser.ts
|
|
1124
|
-
function extractActionBlock(text) {
|
|
1125
|
-
const re = /<ACTION>\s*([\s\S]+?)\s*<\/ACTION>/gi;
|
|
1126
|
-
let match;
|
|
1127
|
-
let last = null;
|
|
1128
|
-
while ((match = re.exec(text)) !== null) {
|
|
1129
|
-
last = match[1];
|
|
1130
|
-
}
|
|
1131
|
-
return last;
|
|
1132
|
-
}
|
|
1133
1133
|
function extractFencedJsonBlocks(text) {
|
|
1134
1134
|
const re = /```(?:json)?\s*([\s\S]*?)\s*```/gi;
|
|
1135
1135
|
const blocks = [];
|
|
@@ -1149,15 +1149,12 @@ function extractTrailingJsonCandidates(text) {
|
|
|
1149
1149
|
if (candidate.includes('"actionType"') && candidate.includes('"actionData"')) {
|
|
1150
1150
|
candidates.push(candidate);
|
|
1151
1151
|
}
|
|
1152
|
+
if (idx === 0) break;
|
|
1152
1153
|
idx = trimmed.lastIndexOf("{", idx - 1);
|
|
1153
1154
|
}
|
|
1154
1155
|
return candidates;
|
|
1155
1156
|
}
|
|
1156
1157
|
function extractActionCandidates(text) {
|
|
1157
|
-
const actionBlock = extractActionBlock(text);
|
|
1158
|
-
if (actionBlock !== null) {
|
|
1159
|
-
return [actionBlock];
|
|
1160
|
-
}
|
|
1161
1158
|
const fenced = extractFencedJsonBlocks(text);
|
|
1162
1159
|
if (fenced.length > 0) {
|
|
1163
1160
|
return fenced.reverse();
|
|
@@ -1270,7 +1267,7 @@ function parseActionJson(body) {
|
|
|
1270
1267
|
actionType: rec.actionType,
|
|
1271
1268
|
actionData: rec.actionData,
|
|
1272
1269
|
...typeof rec.speech === "string" ? { speech: rec.speech } : {},
|
|
1273
|
-
...typeof rec.
|
|
1270
|
+
...typeof rec.voteReason === "string" ? { voteReason: rec.voteReason } : {}
|
|
1274
1271
|
};
|
|
1275
1272
|
}
|
|
1276
1273
|
function parseActionJsonStrict(body) {
|
|
@@ -1285,7 +1282,7 @@ function parseActionJsonStrict(body) {
|
|
|
1285
1282
|
}
|
|
1286
1283
|
const rec = obj;
|
|
1287
1284
|
for (const field of Object.keys(rec)) {
|
|
1288
|
-
if (!["speech", "reason", "actionType", "actionData"].includes(field)) {
|
|
1285
|
+
if (!["speech", "voteReason", "reason", "actionType", "actionData"].includes(field)) {
|
|
1289
1286
|
return { error: "invalid_json", detail: `unknown_top_level_field:${field}` };
|
|
1290
1287
|
}
|
|
1291
1288
|
}
|
|
@@ -1299,7 +1296,7 @@ function parseActionJsonStrict(body) {
|
|
|
1299
1296
|
actionType: rec.actionType,
|
|
1300
1297
|
actionData: rec.actionData,
|
|
1301
1298
|
...typeof rec.speech === "string" ? { speech: rec.speech } : {},
|
|
1302
|
-
...typeof rec.
|
|
1299
|
+
...typeof rec.voteReason === "string" ? { voteReason: rec.voteReason } : {}
|
|
1303
1300
|
};
|
|
1304
1301
|
}
|
|
1305
1302
|
function removeTrailingCommas(body) {
|
|
@@ -1993,7 +1990,7 @@ function buildStructuredActionRetryPrompt(renderedPrompt, reason) {
|
|
|
1993
1990
|
return `${renderedPrompt}
|
|
1994
1991
|
|
|
1995
1992
|
\u4E0A\u4E00\u6B21\u8F93\u51FA\u672A\u88AB\u72FC\u4EBA\u6740\u7ED3\u6784\u5316\u52A8\u4F5C\u534F\u8BAE\u63A5\u53D7\uFF0C\u5931\u8D25\u539F\u56E0\uFF1A${reasonText}\u3002
|
|
1996
|
-
\u8BF7\u91CD\u65B0\u4F5C\u7B54\uFF1A\u53EA\u8F93\u51FA\u4E00\u4E2A\u5B8C\u6574 JSON \u5BF9\u8C61\uFF0C\u4E0D\u8981\u8F93\u51FA Markdown\u3001\u89E3\u91CA\u6587\u5B57\
|
|
1993
|
+
\u8BF7\u91CD\u65B0\u4F5C\u7B54\uFF1A\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`;
|
|
1997
1994
|
}
|
|
1998
1995
|
function hasStructuredRetryBudget(deadlineEpochMs, nowEpochMs = Date.now(), safetyMarginMs = 1e3) {
|
|
1999
1996
|
if (!deadlineEpochMs || deadlineEpochMs <= 0) {
|
|
@@ -2075,7 +2072,7 @@ async function submitGameActionWithLog(action, meta, wsClient, log, source, rawR
|
|
|
2075
2072
|
retryRawResponseHash: auditMeta?.retryRawResponseHash,
|
|
2076
2073
|
retryValidationReason: normalizeAuditText(auditMeta?.retryValidationReason),
|
|
2077
2074
|
speech: action.speech,
|
|
2078
|
-
|
|
2075
|
+
voteReason: action.voteReason
|
|
2079
2076
|
});
|
|
2080
2077
|
if (response.uncertain === true) {
|
|
2081
2078
|
log?.warn?.(
|
package/dist/cli-metadata.js
CHANGED
package/dist/index.js
CHANGED
package/dist/setup-entry.js
CHANGED