Skip to content

Commit 9122e76

Browse files
committed
refactor(records): reuse canonical object guard
1 parent 769579b commit 9122e76

6 files changed

Lines changed: 6 additions & 24 deletions

File tree

src/agents/anthropic-tool-projection.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecord } from "@openclaw/normalization-core/record-coerce";
12
import { projectRuntimeToolInputSchema } from "./tool-schema-json-projection.js";
23

34
type AnthropicToolDescriptor = {
@@ -33,10 +34,6 @@ export type AnthropicProjectedToolChoice =
3334
| { readonly type: "none" }
3435
| ({ readonly type: "tool"; readonly name: string } & AnthropicParallelToolChoice);
3536

36-
function isRecord(value: unknown): value is Record<string, unknown> {
37-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
38-
}
39-
4037
function isProviderSupportedViolation(violation: string): boolean {
4138
return violation.endsWith(".$dynamicRef") || violation.endsWith(".$dynamicAnchor");
4239
}

src/agents/cli-runner/bundle-mcp-claude.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Claude CLI argument helpers for OpenClaw-managed bundle MCP config.
33
*/
44
import fs from "node:fs/promises";
5+
import { isRecord } from "@openclaw/normalization-core/record-coerce";
56
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
67

78
/** Find an existing Claude `--mcp-config` argument value. */
@@ -45,10 +46,6 @@ export function injectClaudeMcpConfigArgs(
4546
return next;
4647
}
4748

48-
function isRecord(value: unknown): value is Record<string, unknown> {
49-
return typeof value === "object" && value !== null && !Array.isArray(value);
50-
}
51-
5249
/** Writes the active per-attempt capture token into OpenClaw's generated Claude MCP config. */
5350
export async function writeClaudeMcpCaptureConfig(params: {
5451
mcpConfigPath: string;

src/agents/cli-runner/claude-live-session.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Manages reusable Claude CLI stdio sessions for CLI-backed agent turns.
33
*/
44
import crypto from "node:crypto";
5+
import { isRecord } from "@openclaw/normalization-core/record-coerce";
56
import type { ReplyBackendHandle } from "../../auto-reply/reply/reply-run-registry.js";
67
import type { CliBackendConfig } from "../../config/types.js";
78
import {
@@ -731,10 +732,6 @@ function parseSessionId(parsed: Record<string, unknown>): string | undefined {
731732
return sessionId || undefined;
732733
}
733734

734-
function isRecord(value: unknown): value is Record<string, unknown> {
735-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
736-
}
737-
738735
function normalizePositiveInt(
739736
value: number | undefined,
740737
fallback: number,

src/agents/embedded-agent-runner/run/attempt.model-diagnostic-events.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isRecord } from "@openclaw/normalization-core/record-coerce";
12
/**
23
* Emits diagnostic model-call events around embedded-agent stream functions.
34
*/
@@ -107,10 +108,6 @@ function assignRequestPayloadBytes(state: ModelCallObservationState, payload: un
107108
}
108109
}
109110

110-
function isRecord(value: unknown): value is Record<string, unknown> {
111-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
112-
}
113-
114111
function utf8StringByteLength(value: string): number {
115112
return Buffer.byteLength(value, "utf8");
116113
}

src/agents/embedded-agent-runner/session-manager-init.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Prepares session managers and transcript state before embedded runs.
33
*/
44
import fs from "node:fs/promises";
5+
import { isRecord } from "@openclaw/normalization-core/record-coerce";
56
import { serializeJsonlLine, writeJsonlLines } from "../../config/sessions/transcript-jsonl.js";
67
import { invalidateSessionFileRepairCache } from "../session-file-repair.js";
78

@@ -13,10 +14,6 @@ type SessionHeaderEntry = {
1314
};
1415
type SessionMessageEntry = { type: "message"; message?: { role?: string } };
1516

16-
function isRecord(value: unknown): value is Record<string, unknown> {
17-
return typeof value === "object" && value !== null && !Array.isArray(value);
18-
}
19-
2017
async function assertExistingHeaderIsReadable(sessionFile: string): Promise<void> {
2118
const content = await fs.readFile(sessionFile, "utf-8");
2219
const firstLine = content.split("\n").find((line) => line.trim());

src/agents/embedded-agent-runner/transcript-file-state.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { randomUUID } from "node:crypto";
55
import fs from "node:fs/promises";
66
import path from "node:path";
7+
import { isRecord } from "@openclaw/normalization-core/record-coerce";
78
import { isSessionTranscriptSideAppendEntry } from "../../config/sessions/transcript-tree.js";
89
import { CURRENT_SESSION_VERSION } from "../../config/sessions/version.js";
910
import { appendRegularFile } from "../../infra/fs-safe.js";
@@ -65,10 +66,6 @@ const repairableToolCallContentTypes = new Set([
6566

6667
const invalidJsonlSlotType = "__openclaw_invalid_jsonl_slot";
6768

68-
function isRecord(value: unknown): value is Record<string, unknown> {
69-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
70-
}
71-
7269
function isString(value: unknown): value is string {
7370
return typeof value === "string" && value.trim() !== "";
7471
}

0 commit comments

Comments
 (0)