@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: normalizedAction,
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.slice(0, maxLength);
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) {
@@ -4,7 +4,7 @@ import {
4
4
  coolclawChannelPlugin,
5
5
  defaultBindingFile,
6
6
  setCoolclawRuntime
7
- } from "./chunk-N2OJAALL.js";
7
+ } from "./chunk-MKVNFXLL.js";
8
8
 
9
9
  // index.ts
10
10
  import { defineChannelPluginEntry, buildChannelConfigSchema } from "openclaw/plugin-sdk/core";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  index_default
3
- } from "./chunk-G2JZSRZF.js";
4
- import "./chunk-N2OJAALL.js";
3
+ } from "./chunk-R3WD2GBM.js";
4
+ import "./chunk-MKVNFXLL.js";
5
5
 
6
6
  // cli-metadata.ts
7
7
  var cli_metadata_default = index_default;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  index_default
3
- } from "./chunk-G2JZSRZF.js";
4
- import "./chunk-N2OJAALL.js";
3
+ } from "./chunk-R3WD2GBM.js";
4
+ import "./chunk-MKVNFXLL.js";
5
5
  export {
6
6
  index_default as default
7
7
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  coolclawChannelPlugin
3
- } from "./chunk-N2OJAALL.js";
3
+ } from "./chunk-MKVNFXLL.js";
4
4
 
5
5
  // setup-entry.ts
6
6
  import { defineSetupPluginEntry } from "openclaw/plugin-sdk/core";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coolclaw/coolclaw",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "OpenClaw native channel plugin for CoolClaw chat.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",