// 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
import { randomUUID } from "crypto";
var MemoryVoiceStorage = class {
  store = /* @__PURE__ */ new Map();
  async persist(source, opts) {
    const bytes = await source.fetchBytes();
    const id = 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
    };
  }
};
export {
  DEFAULT_LANGUAGE,
  DEFAULT_MIME,
  MemoryVoiceStorage,
  MockSTTProvider,
  processVoice
};
//# sourceMappingURL=index.mjs.map