refactor: consolidate coercion contracts (#122458)

* refactor: consolidate coercion contracts

Centralize exact string, record, numeric, date, Boolean, argument, and structured-error coercions while preserving call-site semantics.

Migrate canonical-name collisions and deprecated internal SDK bypasses, deleting 55 net production/tooling lines. Expand declaration ownership enforcement to 101 allowed helpers and add a narrow export-completeness audit.

* fix: preserve standalone script coercions

Keep copied Control UI tooling self-contained and retain the trusted release harness module-relative source seam when the harness runs against an old target cwd.
This commit is contained in:
Peter Steinberger
2026-08-11 23:26:37 -07:00
committed by GitHub
parent 66fe424590
commit b080dd1e76
276 changed files with 1685 additions and 1663 deletions
+10 -19
View File
@@ -9,6 +9,7 @@ import type {
ToolResultMessage,
} from "@openclaw/llm-core";
import type { EventStream as SourceEventStream } from "@openclaw/llm-core";
import { coerceErrorMessage } from "@openclaw/normalization-core/error-coercion";
import { asOptionalRecord } from "@openclaw/normalization-core/record-coerce";
import { TranscriptNotContinuableError } from "./errors.js";
import { uuidv7 } from "./harness/session/uuid.js";
@@ -1332,7 +1333,7 @@ async function prepareToolCall(
} catch (error) {
return {
kind: "immediate",
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
result: createErrorToolResult(coerceErrorMessage(error)),
isError: true,
};
}
@@ -1360,11 +1361,7 @@ async function validateToolCallForBatchAdmission(
outcome: {
kind: "immediate",
result: createErrorToolResult(
signal?.aborted
? "Operation aborted"
: resolution.error instanceof Error
? resolution.error.message
: String(resolution.error),
signal?.aborted ? "Operation aborted" : coerceErrorMessage(resolution.error),
),
isError: true,
},
@@ -1390,7 +1387,7 @@ async function validateToolCallForBatchAdmission(
kind: "immediate",
outcome: {
kind: "immediate",
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
result: createErrorToolResult(coerceErrorMessage(error)),
isError: true,
},
};
@@ -1404,7 +1401,7 @@ async function validateToolCallForBatchAdmission(
kind: "immediate",
outcome: {
kind: "immediate",
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
result: createErrorToolResult(coerceErrorMessage(error)),
isError: true,
errorKind: "argument-validation",
},
@@ -1452,7 +1449,7 @@ async function prepareToolCallExecution(
return {
kind: "immediate",
outcome: {
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
result: createErrorToolResult(coerceErrorMessage(error)),
isError: true,
executionStarted: false,
},
@@ -1508,7 +1505,7 @@ async function prepareToolCallExecution(
throw implementationStartError.error;
}
return {
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
result: createErrorToolResult(coerceErrorMessage(error)),
isError: true,
executionStarted,
...(executionStarted && signal?.aborted && error === signal.reason
@@ -1570,11 +1567,7 @@ async function prepareToolCallExecution(
return {
kind: "immediate",
outcome: {
result: createErrorToolResult(
internalPreparation.outcome.error instanceof Error
? internalPreparation.outcome.error.message
: String(internalPreparation.outcome.error),
),
result: createErrorToolResult(coerceErrorMessage(internalPreparation.outcome.error)),
isError: true,
executionStarted: false,
},
@@ -1627,7 +1620,7 @@ async function finalizeExecutedToolCall(
isError = afterResult.isError ?? isError;
}
} catch (error) {
result = createErrorToolResult(error instanceof Error ? error.message : String(error));
result = createErrorToolResult(coerceErrorMessage(error));
isError = true;
}
}
@@ -1692,9 +1685,7 @@ async function finalizeToolCallOutcome(
isError: afterResult.isError ?? finalized.isError,
};
} catch (error) {
const errorResult = createErrorToolResult(
error instanceof Error ? error.message : String(error),
);
const errorResult = createErrorToolResult(coerceErrorMessage(error));
return {
...finalized,
result: {