"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/personality/index.ts
var personality_exports = {};
__export(personality_exports, {
  CALIBRATION_DIMENSIONS: () => CALIBRATION_DIMENSIONS,
  CALIBRATION_DIRECTIONS: () => CALIBRATION_DIRECTIONS,
  EMOJI_POLICIES: () => EMOJI_POLICIES,
  PERSONALITY_CHANNELS: () => PERSONALITY_CHANNELS,
  SELF_REFERENCES: () => SELF_REFERENCES,
  SENTENCE_LENGTHS: () => SENTENCE_LENGTHS,
  TONE_DIRECTNESS: () => TONE_DIRECTNESS,
  TONE_ENERGIES: () => TONE_ENERGIES,
  TONE_HUMORS: () => TONE_HUMORS,
  TONE_REGISTERS: () => TONE_REGISTERS,
  applyCalibrationsToPersonality: () => applyCalibrationsToPersonality,
  applyChannelOverride: () => applyChannelOverride,
  buildSystemPrompt: () => buildSystemPrompt,
  makeMockPersonality: () => makeMockPersonality,
  partialPersonalitySchema: () => partialPersonalitySchema,
  personalityDefinitionSchema: () => personalityDefinitionSchema,
  personalityStyleSchema: () => personalityStyleSchema,
  personalityToneSchema: () => personalityToneSchema
});
module.exports = __toCommonJS(personality_exports);

// src/personality/types.ts
var import_zod = require("zod");
var TONE_REGISTERS = [
  "formal",
  "professional",
  "casual",
  "warm"
];
var TONE_ENERGIES = ["calm", "measured", "energetic"];
var TONE_HUMORS = ["none", "subtle", "dry", "warm"];
var TONE_DIRECTNESS = [
  "diplomatic",
  "balanced",
  "direct",
  "blunt"
];
var SENTENCE_LENGTHS = ["short", "medium", "mixed"];
var EMOJI_POLICIES = ["never", "sparingly", "situational"];
var SELF_REFERENCES = ["first-person", "never-self-refer"];
var PERSONALITY_CHANNELS = [
  "telegram",
  "email",
  "dashboard",
  "voice"
];
var semverRegex = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
var personalityToneSchema = import_zod.z.object({
  register: import_zod.z.enum(TONE_REGISTERS),
  energy: import_zod.z.enum(TONE_ENERGIES),
  humor: import_zod.z.enum(TONE_HUMORS),
  directness: import_zod.z.enum(TONE_DIRECTNESS)
});
var personalityStyleSchema = import_zod.z.object({
  sentenceLength: import_zod.z.enum(SENTENCE_LENGTHS),
  listsAllowed: import_zod.z.boolean(),
  emojiPolicy: import_zod.z.enum(EMOJI_POLICIES),
  addressTheUserAs: import_zod.z.string().min(1).max(120).optional(),
  selfReference: import_zod.z.enum(SELF_REFERENCES).optional()
});
var partialPersonalitySchema = import_zod.z.object({
  tone: personalityToneSchema.partial().optional(),
  style: personalityStyleSchema.partial().optional(),
  preferredPhrasing: import_zod.z.array(import_zod.z.string()).optional(),
  avoidPhrasing: import_zod.z.array(import_zod.z.string()).optional(),
  signaturePhrases: import_zod.z.array(import_zod.z.string()).optional(),
  doList: import_zod.z.array(import_zod.z.string()).optional(),
  dontList: import_zod.z.array(import_zod.z.string()).optional()
});
var personalityDefinitionSchema = import_zod.z.object({
  name: import_zod.z.string().min(1).max(120),
  role: import_zod.z.string().min(1).max(240),
  about: import_zod.z.string().min(1).max(2e3),
  tone: personalityToneSchema,
  style: personalityStyleSchema,
  preferredPhrasing: import_zod.z.array(import_zod.z.string()),
  avoidPhrasing: import_zod.z.array(import_zod.z.string()),
  signaturePhrases: import_zod.z.array(import_zod.z.string()).optional(),
  doList: import_zod.z.array(import_zod.z.string()),
  dontList: import_zod.z.array(import_zod.z.string()),
  channels: import_zod.z.object({
    telegram: partialPersonalitySchema.optional(),
    email: partialPersonalitySchema.optional(),
    dashboard: partialPersonalitySchema.optional(),
    voice: partialPersonalitySchema.optional()
  }).optional(),
  version: import_zod.z.string().regex(semverRegex, "version must be valid semver"),
  updatedAt: import_zod.z.date()
});
var CALIBRATION_DIMENSIONS = [
  "register",
  "energy",
  "humor",
  "directness",
  "sentenceLength",
  "verbosity",
  "emojiPolicy"
];
var CALIBRATION_DIRECTIONS = [
  "less",
  "more",
  "softer",
  "sharper"
];

// src/personality/calibration.ts
function applyCalibrationsToPersonality(personality, recentCalibrations) {
  if (recentCalibrations.length === 0) {
    return { ...personality, tone: { ...personality.tone }, style: { ...personality.style } };
  }
  const ordered = [...recentCalibrations].sort(
    (a, b) => a.createdAt.getTime() - b.createdAt.getTime()
  );
  let register = personality.tone.register;
  let energy = personality.tone.energy;
  let humor = personality.tone.humor;
  let directness = personality.tone.directness;
  let sentenceLength = personality.style.sentenceLength;
  let emojiPolicy = personality.style.emojiPolicy;
  for (const cal of ordered) {
    const { dimension, direction } = cal.payload;
    switch (dimension) {
      case "register":
        register = step(TONE_REGISTERS, register, direction);
        break;
      case "energy":
        energy = step(TONE_ENERGIES, energy, direction);
        break;
      case "humor":
        humor = step(TONE_HUMORS, humor, direction);
        break;
      case "directness":
        directness = step(TONE_DIRECTNESS, directness, direction);
        break;
      case "sentenceLength":
      case "verbosity":
        sentenceLength = step(SENTENCE_LENGTHS, sentenceLength, direction);
        break;
      case "emojiPolicy":
        emojiPolicy = step(EMOJI_POLICIES, emojiPolicy, direction);
        break;
    }
  }
  return {
    ...personality,
    tone: { register, energy, humor, directness },
    style: { ...personality.style, sentenceLength, emojiPolicy }
  };
}
function step(scale, current, direction) {
  const idx = scale.indexOf(current);
  if (idx === -1) return current;
  const delta = directionToDelta(direction);
  const next = Math.max(0, Math.min(scale.length - 1, idx + delta));
  return scale[next];
}
function directionToDelta(direction) {
  switch (direction) {
    case "less":
    case "softer":
      return -1;
    case "more":
    case "sharper":
      return 1;
  }
}

// src/personality/channels.ts
function applyChannelOverride(base, channel) {
  const override = base.channels?.[channel];
  const merged = {
    name: base.name,
    role: base.role,
    about: base.about,
    tone: { ...base.tone, ...override?.tone ?? {} },
    style: { ...base.style, ...override?.style ?? {} },
    preferredPhrasing: mergeList(
      base.preferredPhrasing,
      override?.preferredPhrasing
    ),
    avoidPhrasing: mergeList(base.avoidPhrasing, override?.avoidPhrasing),
    signaturePhrases: mergeOptionalList(
      base.signaturePhrases,
      override?.signaturePhrases
    ),
    doList: mergeList(base.doList, override?.doList),
    dontList: mergeList(base.dontList, override?.dontList),
    version: base.version,
    updatedAt: base.updatedAt
  };
  return merged;
}
function mergeList(base, addition) {
  if (!addition || addition.length === 0) return [...base];
  const seen = /* @__PURE__ */ new Set();
  const out = [];
  for (const item of [...base, ...addition]) {
    if (seen.has(item)) continue;
    seen.add(item);
    out.push(item);
  }
  return out;
}
function mergeOptionalList(base, addition) {
  if (!base && !addition) return void 0;
  return mergeList(base ?? [], addition);
}

// src/personality/builder.ts
function buildSystemPrompt(args) {
  const channelResolved = applyChannelOverride(args.personality, args.channel);
  const calibrated = applyCalibrationsToPersonality(
    channelResolved,
    args.recentCalibrations ?? []
  );
  const sections = [];
  sections.push(renderIdentity(calibrated));
  sections.push(renderVoice(calibrated));
  const vocab = renderVocabulary(calibrated);
  if (vocab) sections.push(vocab);
  const rules = renderRules(calibrated);
  if (rules) sections.push(rules);
  sections.push(renderChannelNotes(args.channel, calibrated));
  if (args.includeCapabilitiesHint) {
    sections.push(
      "Capabilities: you have access to a set of tools. When you are asked what you can do, describe your tools accurately \u2014 do not invent capabilities you do not have."
    );
  }
  if (args.context && args.context.trim().length > 0) {
    sections.push(`Context:
${args.context.trim()}`);
  }
  const calibrationNotes = renderCalibrations(args.recentCalibrations);
  if (calibrationNotes) sections.push(calibrationNotes);
  if (args.task && args.task.trim().length > 0) {
    sections.push(`Task:
${args.task.trim()}`);
  }
  return sections.join("\n\n");
}
function renderIdentity(p) {
  return [
    `You are ${p.name}, ${p.role}.`,
    p.about.trim()
  ].join(" ");
}
function renderVoice(p) {
  const lines = [
    "Voice and style:",
    `- Register: ${p.tone.register}`,
    `- Energy: ${p.tone.energy}`,
    `- Humor: ${p.tone.humor}`,
    `- Directness: ${p.tone.directness}`,
    `- Sentence length: ${p.style.sentenceLength}`,
    `- Lists allowed: ${p.style.listsAllowed ? "yes" : "no"}`,
    `- Emoji policy: ${p.style.emojiPolicy}`
  ];
  if (p.style.addressTheUserAs) {
    lines.push(`- Address the user as: ${p.style.addressTheUserAs}`);
  }
  if (p.style.selfReference) {
    lines.push(`- Self-reference: ${p.style.selfReference}`);
  }
  return lines.join("\n");
}
function renderVocabulary(p) {
  const blocks = [];
  if (p.preferredPhrasing.length > 0) {
    blocks.push(
      `Preferred phrasing:
${bulletize(p.preferredPhrasing)}`
    );
  }
  if (p.avoidPhrasing.length > 0) {
    blocks.push(`Avoid:
${bulletize(p.avoidPhrasing)}`);
  }
  if (p.signaturePhrases && p.signaturePhrases.length > 0) {
    blocks.push(`Signature phrases:
${bulletize(p.signaturePhrases)}`);
  }
  return blocks.length > 0 ? blocks.join("\n\n") : null;
}
function renderRules(p) {
  const blocks = [];
  if (p.doList.length > 0) {
    blocks.push(`Do:
${bulletize(p.doList)}`);
  }
  if (p.dontList.length > 0) {
    blocks.push(`Don't:
${bulletize(p.dontList)}`);
  }
  return blocks.length > 0 ? blocks.join("\n\n") : null;
}
function renderChannelNotes(channel, p) {
  const baseLine = `Channel: ${channel}.`;
  switch (channel) {
    case "telegram":
      return `${baseLine} Reply in HTML-safe text. Short paragraphs. ${p.style.listsAllowed ? "Lists allowed for structured information." : "Avoid bulleted lists."}`;
    case "email":
      return `${baseLine} Reply in paragraph form. No markdown formatting. Sign off appropriately for the register.`;
    case "dashboard":
      return `${baseLine} Reply in markdown. Lists, headings, and code blocks are allowed where they aid readability.`;
    case "voice":
      return `${baseLine} Reply in spoken-language sentences only. No markdown, no lists, no bullet points. The response will be read aloud.`;
  }
}
function renderCalibrations(calibrations) {
  if (!calibrations || calibrations.length === 0) return null;
  const lines = calibrations.map((c) => {
    const note = c.payload.note ? ` \u2014 ${c.payload.note}` : "";
    return `- ${c.payload.direction} ${c.payload.dimension}${note}`;
  });
  return [
    "Recent tone calibration from the user:",
    ...lines
  ].join("\n");
}
function bulletize(items) {
  return items.map((item) => `- ${item}`).join("\n");
}

// src/personality/mock.ts
function makeMockPersonality(overrides = {}) {
  const base = {
    name: "Sam",
    role: "general-purpose assistant",
    about: "A helpful assistant used in agent-kit tests. Sam keeps replies tight and useful.",
    tone: {
      register: "professional",
      energy: "measured",
      humor: "subtle",
      directness: "balanced"
    },
    style: {
      sentenceLength: "mixed",
      listsAllowed: true,
      emojiPolicy: "never",
      addressTheUserAs: "you",
      selfReference: "first-person"
    },
    preferredPhrasing: ["here's the answer", "happy to help"],
    avoidPhrasing: ["as an AI language model", "I cannot"],
    signaturePhrases: ["let me check that"],
    doList: [
      "answer the user's actual question",
      "say when you don't know something"
    ],
    dontList: [
      "invent capabilities you don't have",
      "pad replies with filler"
    ],
    channels: {
      telegram: {
        style: { sentenceLength: "short", emojiPolicy: "sparingly" }
      },
      email: {
        tone: { register: "formal" },
        style: { sentenceLength: "medium", listsAllowed: false }
      },
      dashboard: {},
      voice: {
        style: {
          sentenceLength: "short",
          listsAllowed: false,
          emojiPolicy: "never"
        }
      }
    },
    version: "1.0.0",
    updatedAt: /* @__PURE__ */ new Date("2026-05-22T00:00:00Z")
  };
  return { ...base, ...overrides };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CALIBRATION_DIMENSIONS,
  CALIBRATION_DIRECTIONS,
  EMOJI_POLICIES,
  PERSONALITY_CHANNELS,
  SELF_REFERENCES,
  SENTENCE_LENGTHS,
  TONE_DIRECTNESS,
  TONE_ENERGIES,
  TONE_HUMORS,
  TONE_REGISTERS,
  applyCalibrationsToPersonality,
  applyChannelOverride,
  buildSystemPrompt,
  makeMockPersonality,
  partialPersonalitySchema,
  personalityDefinitionSchema,
  personalityStyleSchema,
  personalityToneSchema
});
//# sourceMappingURL=index.js.map