@raindrop-ai/ai-sdk 0.0.19-beta.4 → 0.0.20

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // ../core/dist/chunk-FOHDGBT5.js
3
+ // ../core/dist/chunk-H6VSZSLN.js
4
4
  function getCrypto() {
5
5
  const c = globalThis.crypto;
6
6
  return c;
@@ -618,49 +618,25 @@ var NOOP_SPAN = {
618
618
  log() {
619
619
  }
620
620
  };
621
- function isPromiseLike(value) {
622
- return value !== null && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
621
+ function getAsyncLocalStorageCtor() {
622
+ return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
623
623
  }
624
- var PendingAsyncLocalStorage = class {
624
+ var SynchronousContextStorage = class {
625
625
  constructor() {
626
- this._real = null;
627
626
  this._stack = [];
628
627
  }
629
- setReal(real) {
630
- const current = this._stack.length ? this._stack[this._stack.length - 1] : void 0;
631
- this._real = real;
632
- if (current !== void 0 && typeof this._real.enterWith === "function") {
633
- this._real.enterWith(current);
634
- }
628
+ isEmpty() {
629
+ return this._stack.length === 0;
635
630
  }
636
631
  getStore() {
637
- var _a, _b;
638
- return (_b = (_a = this._real) == null ? void 0 : _a.getStore()) != null ? _b : this._stack[this._stack.length - 1];
632
+ return this._stack[this._stack.length - 1];
639
633
  }
640
634
  run(store, callback) {
641
- if (this._real) {
642
- return this._real.run(store, callback);
643
- }
644
635
  this._stack.push(store);
645
636
  try {
646
- const result = callback();
647
- if (isPromiseLike(result)) {
648
- return result.then(
649
- (value) => {
650
- this._stack.pop();
651
- return value;
652
- },
653
- (err) => {
654
- this._stack.pop();
655
- throw err;
656
- }
657
- );
658
- }
659
- this._stack.pop();
660
- return result;
661
- } catch (err) {
637
+ return callback();
638
+ } finally {
662
639
  this._stack.pop();
663
- throw err;
664
640
  }
665
641
  }
666
642
  };
@@ -668,53 +644,29 @@ var ContextManager = class {
668
644
  };
669
645
  var RaindropContextManager = class extends ContextManager {
670
646
  constructor() {
671
- var _a;
672
647
  super();
673
- this._storage = null;
674
- this._pending = null;
675
- this._initPromise = null;
676
- const isNode = typeof process !== "undefined" && typeof ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) === "string";
677
- const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
648
+ this._fallback = null;
649
+ const Ctor = getAsyncLocalStorageCtor();
678
650
  if (Ctor) {
679
651
  this._storage = new Ctor();
680
- this._pending = null;
681
- this._initPromise = null;
682
652
  return;
683
653
  }
684
- if (isNode) {
685
- this._pending = new PendingAsyncLocalStorage();
686
- this._storage = this._pending;
687
- this._initPromise = this._initialize();
688
- } else {
689
- this._storage = null;
690
- this._pending = null;
691
- this._initPromise = null;
692
- }
654
+ this._fallback = new SynchronousContextStorage();
655
+ this._storage = this._fallback;
693
656
  }
694
- async _initialize() {
695
- try {
696
- const mod = await import('async_hooks');
697
- const real = new mod.AsyncLocalStorage();
698
- if (this._pending) {
699
- this._pending.setReal(real);
700
- }
701
- this._storage = real;
702
- } catch (e) {
703
- this._storage = null;
704
- }
705
- }
706
- async ensureReady() {
707
- if (this._initPromise) {
708
- await this._initPromise;
709
- this._initPromise = null;
710
- }
657
+ maybeAdoptAsyncLocalStorage() {
658
+ if (!this._fallback || !this._fallback.isEmpty()) return;
659
+ const Ctor = getAsyncLocalStorageCtor();
660
+ if (!Ctor) return;
661
+ this._storage = new Ctor();
662
+ this._fallback = null;
711
663
  }
712
664
  isReady() {
713
- return this._initPromise === null;
665
+ return true;
714
666
  }
715
667
  getParentSpanIds() {
716
- var _a;
717
- const span = (_a = this._storage) == null ? void 0 : _a.getStore();
668
+ this.maybeAdoptAsyncLocalStorage();
669
+ const span = this._storage.getStore();
718
670
  if (!span || span === NOOP_SPAN) return void 0;
719
671
  return {
720
672
  traceIdB64: span.traceIdB64,
@@ -723,12 +675,12 @@ var RaindropContextManager = class extends ContextManager {
723
675
  };
724
676
  }
725
677
  runInContext(span, callback) {
726
- if (!this._storage) return callback();
678
+ this.maybeAdoptAsyncLocalStorage();
727
679
  return this._storage.run(span, callback);
728
680
  }
729
681
  getCurrentSpan() {
730
- var _a;
731
- return (_a = this._storage) == null ? void 0 : _a.getStore();
682
+ this.maybeAdoptAsyncLocalStorage();
683
+ return this._storage.getStore();
732
684
  }
733
685
  };
734
686
  var _contextManager = null;
@@ -746,17 +698,10 @@ function withCurrent(span, callback) {
746
698
  return getContextManager().runInContext(span, callback);
747
699
  }
748
700
  async function getCurrentParentSpanContext() {
749
- const cm = getContextManager();
750
- if (cm instanceof RaindropContextManager) {
751
- await cm.ensureReady();
752
- }
753
- return cm.getParentSpanIds();
701
+ return getContextManager().getParentSpanIds();
754
702
  }
755
703
  async function runWithParentSpanContext(ctx, fn) {
756
704
  const cm = getContextManager();
757
- if (cm instanceof RaindropContextManager) {
758
- await cm.ensureReady();
759
- }
760
705
  const span = {
761
706
  traceIdB64: ctx.traceIdB64,
762
707
  spanIdB64: ctx.spanIdB64,
@@ -787,7 +732,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
787
732
  // package.json
788
733
  var package_default = {
789
734
  name: "@raindrop-ai/ai-sdk",
790
- version: "0.0.19-beta.4"};
735
+ version: "0.0.20"};
791
736
 
792
737
  // src/internal/version.ts
793
738
  var libraryName = package_default.name;
@@ -1059,17 +1004,29 @@ function extractTextFromMessageContent(content) {
1059
1004
  }
1060
1005
  return result.length ? result : void 0;
1061
1006
  }
1062
- function extractInputAttachmentsFromArgs(args) {
1063
- if (!isRecord(args)) return void 0;
1007
+ function messagesFromArgs(args) {
1064
1008
  const messages = args["messages"];
1065
- if (!Array.isArray(messages)) return void 0;
1009
+ if (Array.isArray(messages)) return messages;
1010
+ const prompt = args["prompt"];
1011
+ if (Array.isArray(prompt)) return prompt;
1012
+ return void 0;
1013
+ }
1014
+ function lastUserMessageFromArgs(args) {
1015
+ const messages = messagesFromArgs(args);
1016
+ if (!messages) return void 0;
1066
1017
  for (let i = messages.length - 1; i >= 0; i--) {
1067
1018
  const message = messages[i];
1068
- if (!isRecord(message) || message["role"] !== "user") continue;
1069
- return attachmentsFromContent(message["content"], "input");
1019
+ if (isRecord(message) && message["role"] === "user") {
1020
+ return message;
1021
+ }
1070
1022
  }
1071
1023
  return void 0;
1072
1024
  }
1025
+ function extractInputAttachmentsFromArgs(args) {
1026
+ var _a;
1027
+ if (!isRecord(args)) return void 0;
1028
+ return attachmentsFromContent((_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"], "input");
1029
+ }
1073
1030
  async function extractOutputAttachmentsFromResult(result) {
1074
1031
  if (!isRecord(result)) return void 0;
1075
1032
  const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
@@ -1083,26 +1040,20 @@ async function extractOutputAttachmentsFromResult(result) {
1083
1040
  return attachmentsFromContent(result["content"], "output");
1084
1041
  }
1085
1042
  function lastUserMessageTextFromArgs(args) {
1086
- var _a;
1043
+ var _a, _b;
1087
1044
  if (!isRecord(args)) return void 0;
1088
- const messages = args["messages"];
1089
- if (!Array.isArray(messages)) return void 0;
1090
- for (let i = messages.length - 1; i >= 0; i--) {
1091
- const message = messages[i];
1092
- if (!isRecord(message) || message["role"] !== "user") continue;
1093
- const content = message["content"];
1094
- const text = extractTextFromMessageContent(content);
1095
- if (text !== void 0) return text;
1096
- return (_a = safeJsonWithUint8(content)) != null ? _a : String(content);
1097
- }
1098
- return void 0;
1045
+ const content = (_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"];
1046
+ if (content === void 0) return void 0;
1047
+ const text = extractTextFromMessageContent(content);
1048
+ if (text !== void 0) return text;
1049
+ return (_b = safeJsonWithUint8(content)) != null ? _b : String(content);
1099
1050
  }
1100
1051
  function extractInputFromArgs(args) {
1101
1052
  var _a;
1102
1053
  if (!isRecord(args)) return void 0;
1103
1054
  const prompt = args["prompt"];
1104
1055
  if (typeof prompt === "string") return prompt;
1105
- const messages = args["messages"];
1056
+ const messages = messagesFromArgs(args);
1106
1057
  if (Array.isArray(messages) && messages.length > 0) {
1107
1058
  const last = messages[messages.length - 1];
1108
1059
  if (isRecord(last)) {
@@ -1124,7 +1075,7 @@ function coerceMessagesFromArgs(args) {
1124
1075
  if (typeof args["system"] === "string" && args["system"]) {
1125
1076
  result.push({ role: "system", content: args["system"] });
1126
1077
  }
1127
- const messages = args["messages"];
1078
+ const messages = messagesFromArgs(args);
1128
1079
  if (Array.isArray(messages)) {
1129
1080
  for (const message of messages) {
1130
1081
  if (isRecord(message) && typeof message["role"] === "string") {