refactor: dedupe tlon monitor record helper

This commit is contained in:
Peter Steinberger
2026-04-06 22:28:18 +01:00
parent bd71ddabbd
commit 7ebd78cf1b
5 changed files with 5 additions and 20 deletions

View File

@@ -1,14 +1,10 @@
import type { RuntimeEnv } from "../../api.js";
import { extractCites, extractMessageText, type ParsedCite } from "./utils.js";
import { asRecord, extractCites, extractMessageText, type ParsedCite } from "./utils.js";
type TlonScryApi = {
scry: (path: string) => Promise<unknown>;
};
function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}
export function createTlonCitationResolver(params: { api: TlonScryApi; runtime: RuntimeEnv }) {
const { api, runtime } = params;

View File

@@ -1,10 +1,6 @@
import type { RuntimeEnv } from "../../api.js";
import type { Foreigns } from "../urbit/foreigns.js";
import { formatChangesDate } from "./utils.js";
function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}
import { asRecord, formatChangesDate } from "./utils.js";
function formatErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);

View File

@@ -1,9 +1,5 @@
import type { RuntimeEnv } from "../../api.js";
import { extractMessageText } from "./utils.js";
function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}
import { asRecord, extractMessageText } from "./utils.js";
function formatErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);

View File

@@ -28,6 +28,7 @@ import {
mergeUniqueStrings,
shouldMigrateTlonSetting,
} from "./settings-helpers.js";
import { asRecord } from "./utils.js";
import {
extractMessageText,
formatModelName,
@@ -45,10 +46,6 @@ export type MonitorTlonOpts = {
accountId?: string | null;
};
function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}
function readString(record: Record<string, unknown> | null, key: string): string | undefined {
const value = record?.[key];
return typeof value === "string" ? value : undefined;

View File

@@ -181,7 +181,7 @@ export async function resolveAuthorizedMessageText(params: {
return citedContent + rawText;
}
function asRecord(value: unknown): Record<string, unknown> | null {
export function asRecord(value: unknown): Record<string, unknown> | null {
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
}