refactor(records): reuse canonical object guard · openclaw/openclaw@9122e76
vincentkoc
·
2026-06-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { isRecord } from "@openclaw/normalization-core/record-coerce"; |
1 | 2 | import { projectRuntimeToolInputSchema } from "./tool-schema-json-projection.js"; |
2 | 3 | |
3 | 4 | type AnthropicToolDescriptor = { |
@@ -33,10 +34,6 @@ export type AnthropicProjectedToolChoice =
|
33 | 34 | | { readonly type: "none" } |
34 | 35 | | ({ readonly type: "tool"; readonly name: string } & AnthropicParallelToolChoice); |
35 | 36 | |
36 | | -function isRecord(value: unknown): value is Record<string, unknown> { |
37 | | -return Boolean(value) && typeof value === "object" && !Array.isArray(value); |
38 | | -} |
39 | | - |
40 | 37 | function isProviderSupportedViolation(violation: string): boolean { |
41 | 38 | return violation.endsWith(".$dynamicRef") || violation.endsWith(".$dynamicAnchor"); |
42 | 39 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@
|
2 | 2 | * Claude CLI argument helpers for OpenClaw-managed bundle MCP config. |
3 | 3 | */ |
4 | 4 | import fs from "node:fs/promises"; |
| 5 | +import { isRecord } from "@openclaw/normalization-core/record-coerce"; |
5 | 6 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
6 | 7 | |
7 | 8 | /** Find an existing Claude `--mcp-config` argument value. */ |
@@ -45,10 +46,6 @@ export function injectClaudeMcpConfigArgs(
|
45 | 46 | return next; |
46 | 47 | } |
47 | 48 | |
48 | | -function isRecord(value: unknown): value is Record<string, unknown> { |
49 | | -return typeof value === "object" && value !== null && !Array.isArray(value); |
50 | | -} |
51 | | - |
52 | 49 | /** Writes the active per-attempt capture token into OpenClaw's generated Claude MCP config. */ |
53 | 50 | export async function writeClaudeMcpCaptureConfig(params: { |
54 | 51 | mcpConfigPath: string; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@
|
2 | 2 | * Manages reusable Claude CLI stdio sessions for CLI-backed agent turns. |
3 | 3 | */ |
4 | 4 | import crypto from "node:crypto"; |
| 5 | +import { isRecord } from "@openclaw/normalization-core/record-coerce"; |
5 | 6 | import type { ReplyBackendHandle } from "../../auto-reply/reply/reply-run-registry.js"; |
6 | 7 | import type { CliBackendConfig } from "../../config/types.js"; |
7 | 8 | import { |
@@ -731,10 +732,6 @@ function parseSessionId(parsed: Record<string, unknown>): string | undefined {
|
731 | 732 | return sessionId || undefined; |
732 | 733 | } |
733 | 734 | |
734 | | -function isRecord(value: unknown): value is Record<string, unknown> { |
735 | | -return Boolean(value && typeof value === "object" && !Array.isArray(value)); |
736 | | -} |
737 | | - |
738 | 735 | function normalizePositiveInt( |
739 | 736 | value: number | undefined, |
740 | 737 | fallback: number, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { isRecord } from "@openclaw/normalization-core/record-coerce"; |
1 | 2 | /** |
2 | 3 | * Emits diagnostic model-call events around embedded-agent stream functions. |
3 | 4 | */ |
@@ -107,10 +108,6 @@ function assignRequestPayloadBytes(state: ModelCallObservationState, payload: un
|
107 | 108 | } |
108 | 109 | } |
109 | 110 | |
110 | | -function isRecord(value: unknown): value is Record<string, unknown> { |
111 | | -return Boolean(value) && typeof value === "object" && !Array.isArray(value); |
112 | | -} |
113 | | - |
114 | 111 | function utf8StringByteLength(value: string): number { |
115 | 112 | return Buffer.byteLength(value, "utf8"); |
116 | 113 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@
|
2 | 2 | * Prepares session managers and transcript state before embedded runs. |
3 | 3 | */ |
4 | 4 | import fs from "node:fs/promises"; |
| 5 | +import { isRecord } from "@openclaw/normalization-core/record-coerce"; |
5 | 6 | import { serializeJsonlLine, writeJsonlLines } from "../../config/sessions/transcript-jsonl.js"; |
6 | 7 | import { invalidateSessionFileRepairCache } from "../session-file-repair.js"; |
7 | 8 | |
@@ -13,10 +14,6 @@ type SessionHeaderEntry = {
|
13 | 14 | }; |
14 | 15 | type SessionMessageEntry = { type: "message"; message?: { role?: string } }; |
15 | 16 | |
16 | | -function isRecord(value: unknown): value is Record<string, unknown> { |
17 | | -return typeof value === "object" && value !== null && !Array.isArray(value); |
18 | | -} |
19 | | - |
20 | 17 | async function assertExistingHeaderIsReadable(sessionFile: string): Promise<void> { |
21 | 18 | const content = await fs.readFile(sessionFile, "utf-8"); |
22 | 19 | const firstLine = content.split("\n").find((line) => line.trim()); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@
|
4 | 4 | import { randomUUID } from "node:crypto"; |
5 | 5 | import fs from "node:fs/promises"; |
6 | 6 | import path from "node:path"; |
| 7 | +import { isRecord } from "@openclaw/normalization-core/record-coerce"; |
7 | 8 | import { isSessionTranscriptSideAppendEntry } from "../../config/sessions/transcript-tree.js"; |
8 | 9 | import { CURRENT_SESSION_VERSION } from "../../config/sessions/version.js"; |
9 | 10 | import { appendRegularFile } from "../../infra/fs-safe.js"; |
@@ -65,10 +66,6 @@ const repairableToolCallContentTypes = new Set([
|
65 | 66 | |
66 | 67 | const invalidJsonlSlotType = "__openclaw_invalid_jsonl_slot"; |
67 | 68 | |
68 | | -function isRecord(value: unknown): value is Record<string, unknown> { |
69 | | -return Boolean(value) && typeof value === "object" && !Array.isArray(value); |
70 | | -} |
71 | | - |
72 | 69 | function isString(value: unknown): value is string { |
73 | 70 | return typeof value === "string" && value.trim() !== ""; |
74 | 71 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。