import {
  ensureMemoryDir
} from "./chunk-ND6MY37M.js";
import {
  generateMemId
} from "./chunk-RIAAGL2E.js";
import {
  MEMORY_PATTERNS,
  appendNode
} from "./chunk-DFR4DJBM.js";
import {
  ErrorCodes,
  createError
} from "./chunk-RXRKBBSM.js";

// ../memory/dist/mem-start-core.js
import { randomUUID } from "crypto";
var DEFAULTS = {
  AGENT_TYPE: "unknown",
  CONTEXT_TIER: "full"
};
var ERROR_MESSAGES = {
  WU_ID_REQUIRED: "wuId is required",
  WU_ID_INVALID: "Invalid WU ID format. Expected pattern: WU-XXX (e.g., WU-123)"
};
function isValidWuId(wuId) {
  return MEMORY_PATTERNS.WU_ID.test(wuId);
}
function generateSessionContent(wuId, agentType, contextTier) {
  return `Session started for ${wuId}. Agent: ${agentType}, Context: ${contextTier}`;
}
async function startSession(baseDir, options) {
  const { wuId, agentType = DEFAULTS.AGENT_TYPE, contextTier = DEFAULTS.CONTEXT_TIER } = options;
  if (!wuId) {
    throw createError(ErrorCodes.VALIDATION_ERROR, ERROR_MESSAGES.WU_ID_REQUIRED);
  }
  if (!isValidWuId(wuId)) {
    throw createError(ErrorCodes.INVALID_WU_ID, ERROR_MESSAGES.WU_ID_INVALID);
  }
  const memoryDir = await ensureMemoryDir(baseDir);
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
  const sessionId = randomUUID();
  const content = generateSessionContent(wuId, agentType, contextTier);
  const idContent = `${content}-${timestamp}-${sessionId}`;
  const id = generateMemId(idContent);
  const sessionNode = {
    id,
    type: "session",
    lifecycle: "wu",
    content,
    created_at: timestamp,
    wu_id: wuId,
    session_id: sessionId,
    metadata: {
      agentType,
      contextTier
    }
  };
  await appendNode(memoryDir, sessionNode);
  return {
    success: true,
    session: sessionNode
  };
}

export {
  startSession
};
