"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/voice/index.ts
var voice_exports = {};
__export(voice_exports, {
  DEFAULT_LANGUAGE: () => DEFAULT_LANGUAGE,
  DEFAULT_MIME: () => DEFAULT_MIME,
  MemoryVoiceStorage: () => MemoryVoiceStorage,
  MockSTTProvider: () => MockSTTProvider,
  processVoice: () => processVoice
});
module.exports = __toCommonJS(voice_exports);

// src/voice/types.ts
var DEFAULT_LANGUAGE = "en-AU";
var DEFAULT_MIME = "audio/ogg";

// src/voice/orchestrator.ts
async function processVoice(args) {
  const bytes = await args.source.fetchBytes();
  const memoisedSource = {
    ...args.source,
    fetchBytes: async () => bytes
  };
  const mimeType = args.source.mimeType ?? DEFAULT_MIME;
  const language = args.language ?? DEFAULT_LANGUAGE;
  const [persistResult, sttResult] = await Promise.all([
    args.storage.persist(memoisedSource, {
      agentId: args.ctx.agentId,
      ...args.ctx.userId !== void 0 ? { userId: args.ctx.userId } : {}
    }),
    args.stt.transcribe({
      audioBytes: bytes,
      mimeType,
      language,
      ...args.enableSpeakerDiarization !== void 0 ? { enableSpeakerDiarization: args.enableSpeakerDiarization } : {},
      ...args.expectedSpeakers !== void 0 ? { expectedSpeakers: args.expectedSpeakers } : {}
    })
  ]);
  return {
    ...sttResult,
    audioUrl: persistResult.url,
    audioKey: persistResult.key
  };
}

// src/voice/mock-storage.ts
var import_node_crypto = require("crypto");
var MemoryVoiceStorage = class {
  store = /* @__PURE__ */ new Map();
  async persist(source, opts) {
    const bytes = await source.fetchBytes();
    const id = (0, import_node_crypto.randomUUID)();
    const key = opts.userId ? `${opts.agentId}/${opts.userId}/${id}` : `${opts.agentId}/${id}`;
    this.store.set(key, bytes);
    return { url: `memory://${key}`, key };
  }
  get(key) {
    return this.store.get(key);
  }
  has(key) {
    return this.store.has(key);
  }
  size() {
    return this.store.size;
  }
  clear() {
    this.store.clear();
  }
};

// src/voice/mock-stt.ts
var MockSTTProvider = class {
  name;
  fixed;
  queue;
  /** All transcribe() calls recorded in order. Useful for assertions in tests. */
  calls = [];
  constructor(opts = {}) {
    this.name = opts.name ?? "mock-stt";
    if (opts.result !== void 0) this.fixed = opts.result;
    this.queue = opts.queue ? [...opts.queue] : [];
  }
  async transcribe(args) {
    this.calls.push(args);
    if (this.queue.length > 0) {
      return this.queue.shift();
    }
    if (this.fixed) return this.fixed;
    return {
      text: "",
      segments: [],
      duration: args.audioBytes.length === 0 ? 0 : 1,
      language: args.language ?? DEFAULT_LANGUAGE,
      confidence: 0
    };
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_LANGUAGE,
  DEFAULT_MIME,
  MemoryVoiceStorage,
  MockSTTProvider,
  processVoice
});
//# sourceMappingURL=index.js.map