@coolclaw/coolclaw 1.0.18 → 1.0.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.
|
@@ -224,19 +224,21 @@ function validateAgentAction(action, task) {
|
|
|
224
224
|
if (!matchesActionDataSchema(repaired.actionData, option.actionDataSchema)) {
|
|
225
225
|
return { ok: false, reason: "invalid_action_shape" };
|
|
226
226
|
}
|
|
227
|
-
if (isStructuredJsonTask(task) && !matchesRootOutputSchema(action, task.outputSchema)) {
|
|
228
|
-
return { ok: false, reason: "invalid_action_shape" };
|
|
229
|
-
}
|
|
230
227
|
const normalizedAction = {
|
|
231
228
|
actionType: action.actionType,
|
|
232
229
|
actionData: repaired.actionData
|
|
233
230
|
};
|
|
234
231
|
if (typeof action.speech === "string") normalizedAction.speech = action.speech;
|
|
235
232
|
if (typeof action.voteReason === "string") normalizedAction.voteReason = action.voteReason;
|
|
233
|
+
const shouldValidateRoot = isStructuredJsonTask(task);
|
|
234
|
+
const repairedRoot = shouldValidateRoot ? repairRootOutputForSchema(normalizedAction, task.outputSchema) : { action: normalizedAction };
|
|
235
|
+
if (!repairedRoot || shouldValidateRoot && !matchesRootOutputSchema(repairedRoot.action, task.outputSchema)) {
|
|
236
|
+
return { ok: false, reason: "invalid_action_shape" };
|
|
237
|
+
}
|
|
236
238
|
return {
|
|
237
239
|
ok: true,
|
|
238
|
-
action:
|
|
239
|
-
repairReason: repaired.repairReason
|
|
240
|
+
action: repairedRoot.action,
|
|
241
|
+
repairReason: combineRepairReasons(repaired.repairReason, repairedRoot.repairReason)
|
|
240
242
|
};
|
|
241
243
|
}
|
|
242
244
|
function backendFallbackAction(task) {
|
|
@@ -330,7 +332,7 @@ function repairActionDataForSchema(actionData, schema) {
|
|
|
330
332
|
if (!repaired) {
|
|
331
333
|
repaired = { ...actionData };
|
|
332
334
|
}
|
|
333
|
-
repaired[field] = value
|
|
335
|
+
repaired[field] = truncateWithEllipsis(value, maxLength);
|
|
334
336
|
truncatedFields.push(field);
|
|
335
337
|
}
|
|
336
338
|
if (truncatedFields.length === 0) {
|
|
@@ -341,6 +343,54 @@ function repairActionDataForSchema(actionData, schema) {
|
|
|
341
343
|
repairReason: truncatedFields.map((field) => `${field}_too_long`).join(",")
|
|
342
344
|
};
|
|
343
345
|
}
|
|
346
|
+
function repairRootOutputForSchema(action, schema) {
|
|
347
|
+
if (!schema || Object.keys(schema).length === 0) {
|
|
348
|
+
return { action };
|
|
349
|
+
}
|
|
350
|
+
const properties = isRecord(schema.properties) ? schema.properties : {};
|
|
351
|
+
let repaired = null;
|
|
352
|
+
const truncatedFields = [];
|
|
353
|
+
for (const field of ["speech", "voteReason"]) {
|
|
354
|
+
const propertySchema = properties[field];
|
|
355
|
+
const value = action[field];
|
|
356
|
+
if (typeof value !== "string" || !isRecord(propertySchema)) {
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (!schemaAllowsType(propertySchema.type, "string") || typeof propertySchema.maxLength !== "number") {
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const maxLength = Math.max(0, Math.floor(propertySchema.maxLength));
|
|
363
|
+
if (value.length <= maxLength) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (!repaired) {
|
|
367
|
+
repaired = { ...action };
|
|
368
|
+
}
|
|
369
|
+
repaired[field] = truncateWithEllipsis(value, maxLength);
|
|
370
|
+
truncatedFields.push(field);
|
|
371
|
+
}
|
|
372
|
+
if (truncatedFields.length === 0) {
|
|
373
|
+
return { action };
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
action: repaired ?? action,
|
|
377
|
+
repairReason: truncatedFields.map((field) => `${field}_too_long`).join(",")
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function combineRepairReasons(first, second) {
|
|
381
|
+
if (!first) return second;
|
|
382
|
+
if (!second) return first;
|
|
383
|
+
return `${first},${second}`;
|
|
384
|
+
}
|
|
385
|
+
function truncateWithEllipsis(value, maxLength) {
|
|
386
|
+
if (value.length <= maxLength) {
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
if (maxLength <= 3) {
|
|
390
|
+
return value.slice(0, Math.max(0, maxLength));
|
|
391
|
+
}
|
|
392
|
+
return `${value.slice(0, maxLength - 3)}...`;
|
|
393
|
+
}
|
|
344
394
|
function matchesSchemaValue(value, schema, required) {
|
|
345
395
|
if (!isRecord(schema)) return true;
|
|
346
396
|
if (value == null) {
|
package/dist/cli-metadata.js
CHANGED
package/dist/index.js
CHANGED
package/dist/setup-entry.js
CHANGED