/**
 * Generic object utilities shared across protocol modules.
 * Only truly protocol-agnostic helpers belong here — Anthropic/OpenAI-specific
 * checks stay in their respective format modules.
 */

/**
 * Returns true if `val` is a plain object (not null, not an array).
 */
export function isPlainRecord(val: unknown): val is Record<string, unknown> {
  return typeof val === "object" && val !== null && !Array.isArray(val);
}

/**
 * Safe property access via Object.getOwnPropertyDescriptor.
 * Returns `undefined` when obj is not an object or the property does not exist.
 */
export function safeGetOwnProperty(obj: unknown, key: string): unknown {
  if (obj === null || typeof obj !== "object" || Array.isArray(obj)) return undefined;
  const desc = Object.getOwnPropertyDescriptor(obj, key);
  return desc?.value;
}
