@canarycoders/ai 0.7.0 → 0.8.1

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/dist/index.cjs CHANGED
@@ -682,6 +682,7 @@ async function* nativeQueueAdapter(frames, includeRaw) {
682
682
  const raw = (v) => includeRaw ? v : void 0;
683
683
  let lastUsage;
684
684
  let lastFinish;
685
+ let lastCost;
685
686
  for await (const frame of frames) {
686
687
  switch (frame.event) {
687
688
  case "start":
@@ -690,11 +691,12 @@ async function* nativeQueueAdapter(frames, includeRaw) {
690
691
  case "error":
691
692
  throw streamError(tryParse(frame.data));
692
693
  case "done":
693
- yield { type: "done", finishReason: lastFinish, usage: lastUsage };
694
+ yield { type: "done", finishReason: lastFinish, usage: lastUsage, cost: lastCost };
694
695
  return;
695
696
  case "chunk": {
696
697
  const chunk = tryParse(frame.data);
697
698
  if (!chunk) break;
699
+ if (chunk.cost) lastCost = chunk.cost;
698
700
  if (chunk.usage) {
699
701
  lastUsage = chunk.usage;
700
702
  yield { type: "usage", usage: chunk.usage, raw: raw(chunk) };
@@ -722,7 +724,7 @@ async function* nativeQueueAdapter(frames, includeRaw) {
722
724
  }
723
725
  }
724
726
  }
725
- yield { type: "done", finishReason: lastFinish, usage: lastUsage };
727
+ yield { type: "done", finishReason: lastFinish, usage: lastUsage, cost: lastCost };
726
728
  }
727
729
  async function* openAIAdapter(frames, includeRaw) {
728
730
  const raw = (v) => includeRaw ? v : void 0;