export function flattenPageKeys(
  keys: { key: string; value: string }[] = []
): Record<string, string> {
  return keys.reduce((acc, curr) => {
    if (curr.key && typeof curr.value === "string") {
      acc[curr.key] = curr.value;
    }
    return acc;
  }, {} as Record<string, string>);
}

export function replacePromptVariables(
  template: string,
  variables: Record<string, string>
): string {
  return template.replace(/@(\w+)/g, (_, key) => {
    return variables.hasOwnProperty(key) ? variables[key] : `@${key}`;
  });
}
