@ai-matrx/media 0.15.48 → 0.15.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-matrx/media
2
2
 
3
+ ## 0.15.49
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/media/v0.15.48..npm/media/v0.15.49 -- apps/shared/media`).
7
+ No source changes intended and no consumer action required.
8
+
3
9
  ## 0.15.48
4
10
 
5
11
  Automatic changed-only republish (docs/metadata drift since the last tag — see
package/dist/speech.cjs CHANGED
@@ -809,6 +809,8 @@ var init_cartesia_socket = __esm({
809
809
  #listeners = /* @__PURE__ */ new Map();
810
810
  /** Set when the provider refused this account and reconnecting cannot help. */
811
811
  #refused = null;
812
+ /** Sends accepted per context, for the usage idempotency key. */
813
+ #sendCounts = /* @__PURE__ */ new Map();
812
814
  constructor(native, options) {
813
815
  this.#native = native;
814
816
  this.#options = options;
@@ -878,7 +880,7 @@ var init_cartesia_socket = __esm({
878
880
  source = new CartesiaAudioSource(this.#options.sampleRate);
879
881
  this.#sources.set(contextId, source);
880
882
  }
881
- await this.#native.send({
883
+ const sent = this.#native.send({
882
884
  context_id: contextId,
883
885
  model_id: request.modelId,
884
886
  transcript: request.transcript,
@@ -895,6 +897,8 @@ var init_cartesia_socket = __esm({
895
897
  max_buffer_delay_ms: request.maxBufferDelayMs,
896
898
  generation_config: request.generationConfig
897
899
  });
900
+ await sent;
901
+ this.#reportUsage(contextId, request);
898
902
  return {
899
903
  source,
900
904
  on: (_event, listener) => {
@@ -904,6 +908,25 @@ var init_cartesia_socket = __esm({
904
908
  }
905
909
  };
906
910
  }
911
+ /**
912
+ * Cartesia bills the characters it is sent. Report each accepted send once: the context id plus a
913
+ * per-context sequence is the idempotency key, so the host's retries can never double-bill.
914
+ */
915
+ #reportUsage(contextId, request) {
916
+ const characters = request.transcript?.length ?? 0;
917
+ if (characters <= 0) return;
918
+ const sequence = (this.#sendCounts.get(contextId) ?? 0) + 1;
919
+ this.#sendCounts.set(contextId, sequence);
920
+ try {
921
+ speechPorts().reportProviderUsage?.({
922
+ provider: "cartesia",
923
+ model: request.modelId,
924
+ usage_id: `${contextId}:${sequence}`,
925
+ characters
926
+ });
927
+ } catch {
928
+ }
929
+ }
907
930
  continue(request) {
908
931
  return this.send(request);
909
932
  }