@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,4 +1,4 @@
1
- export { AISDKChatRequestLike, AISDKChatRequestMessageLike, AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, RaindropTelemetryIntegration, RaindropTelemetryIntegrationOptions, SelfDiagnosticsOptions, SelfDiagnosticsSignalDefinition, SelfDiagnosticsSignalDefinitions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './index.mjs';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-DGziajf_.mjs';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -1,4 +1,4 @@
1
- export { AISDKChatRequestLike, AISDKChatRequestMessageLike, AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, RaindropTelemetryIntegration, RaindropTelemetryIntegrationOptions, SelfDiagnosticsOptions, SelfDiagnosticsSignalDefinition, SelfDiagnosticsSignalDefinitions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './index.js';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-DGziajf_.js';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -4,7 +4,7 @@ var async_hooks = require('async_hooks');
4
4
 
5
5
  // src/index.node.ts
6
6
 
7
- // ../core/dist/chunk-FOHDGBT5.js
7
+ // ../core/dist/chunk-H6VSZSLN.js
8
8
  function getCrypto() {
9
9
  const c = globalThis.crypto;
10
10
  return c;
@@ -622,49 +622,25 @@ var NOOP_SPAN = {
622
622
  log() {
623
623
  }
624
624
  };
625
- function isPromiseLike(value) {
626
- return value !== null && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
625
+ function getAsyncLocalStorageCtor() {
626
+ return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
627
627
  }
628
- var PendingAsyncLocalStorage = class {
628
+ var SynchronousContextStorage = class {
629
629
  constructor() {
630
- this._real = null;
631
630
  this._stack = [];
632
631
  }
633
- setReal(real) {
634
- const current = this._stack.length ? this._stack[this._stack.length - 1] : void 0;
635
- this._real = real;
636
- if (current !== void 0 && typeof this._real.enterWith === "function") {
637
- this._real.enterWith(current);
638
- }
632
+ isEmpty() {
633
+ return this._stack.length === 0;
639
634
  }
640
635
  getStore() {
641
- var _a, _b;
642
- return (_b = (_a = this._real) == null ? void 0 : _a.getStore()) != null ? _b : this._stack[this._stack.length - 1];
636
+ return this._stack[this._stack.length - 1];
643
637
  }
644
638
  run(store, callback) {
645
- if (this._real) {
646
- return this._real.run(store, callback);
647
- }
648
639
  this._stack.push(store);
649
640
  try {
650
- const result = callback();
651
- if (isPromiseLike(result)) {
652
- return result.then(
653
- (value) => {
654
- this._stack.pop();
655
- return value;
656
- },
657
- (err) => {
658
- this._stack.pop();
659
- throw err;
660
- }
661
- );
662
- }
663
- this._stack.pop();
664
- return result;
665
- } catch (err) {
641
+ return callback();
642
+ } finally {
666
643
  this._stack.pop();
667
- throw err;
668
644
  }
669
645
  }
670
646
  };
@@ -672,53 +648,29 @@ var ContextManager = class {
672
648
  };
673
649
  var RaindropContextManager = class extends ContextManager {
674
650
  constructor() {
675
- var _a;
676
651
  super();
677
- this._storage = null;
678
- this._pending = null;
679
- this._initPromise = null;
680
- const isNode = typeof process !== "undefined" && typeof ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) === "string";
681
- const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
652
+ this._fallback = null;
653
+ const Ctor = getAsyncLocalStorageCtor();
682
654
  if (Ctor) {
683
655
  this._storage = new Ctor();
684
- this._pending = null;
685
- this._initPromise = null;
686
656
  return;
687
657
  }
688
- if (isNode) {
689
- this._pending = new PendingAsyncLocalStorage();
690
- this._storage = this._pending;
691
- this._initPromise = this._initialize();
692
- } else {
693
- this._storage = null;
694
- this._pending = null;
695
- this._initPromise = null;
696
- }
658
+ this._fallback = new SynchronousContextStorage();
659
+ this._storage = this._fallback;
697
660
  }
698
- async _initialize() {
699
- try {
700
- const mod = await import('async_hooks');
701
- const real = new mod.AsyncLocalStorage();
702
- if (this._pending) {
703
- this._pending.setReal(real);
704
- }
705
- this._storage = real;
706
- } catch (e) {
707
- this._storage = null;
708
- }
709
- }
710
- async ensureReady() {
711
- if (this._initPromise) {
712
- await this._initPromise;
713
- this._initPromise = null;
714
- }
661
+ maybeAdoptAsyncLocalStorage() {
662
+ if (!this._fallback || !this._fallback.isEmpty()) return;
663
+ const Ctor = getAsyncLocalStorageCtor();
664
+ if (!Ctor) return;
665
+ this._storage = new Ctor();
666
+ this._fallback = null;
715
667
  }
716
668
  isReady() {
717
- return this._initPromise === null;
669
+ return true;
718
670
  }
719
671
  getParentSpanIds() {
720
- var _a;
721
- const span = (_a = this._storage) == null ? void 0 : _a.getStore();
672
+ this.maybeAdoptAsyncLocalStorage();
673
+ const span = this._storage.getStore();
722
674
  if (!span || span === NOOP_SPAN) return void 0;
723
675
  return {
724
676
  traceIdB64: span.traceIdB64,
@@ -727,12 +679,12 @@ var RaindropContextManager = class extends ContextManager {
727
679
  };
728
680
  }
729
681
  runInContext(span, callback) {
730
- if (!this._storage) return callback();
682
+ this.maybeAdoptAsyncLocalStorage();
731
683
  return this._storage.run(span, callback);
732
684
  }
733
685
  getCurrentSpan() {
734
- var _a;
735
- return (_a = this._storage) == null ? void 0 : _a.getStore();
686
+ this.maybeAdoptAsyncLocalStorage();
687
+ return this._storage.getStore();
736
688
  }
737
689
  };
738
690
  var _contextManager = null;
@@ -750,17 +702,10 @@ function withCurrent(span, callback) {
750
702
  return getContextManager().runInContext(span, callback);
751
703
  }
752
704
  async function getCurrentParentSpanContext() {
753
- const cm = getContextManager();
754
- if (cm instanceof RaindropContextManager) {
755
- await cm.ensureReady();
756
- }
757
- return cm.getParentSpanIds();
705
+ return getContextManager().getParentSpanIds();
758
706
  }
759
707
  async function runWithParentSpanContext(ctx, fn) {
760
708
  const cm = getContextManager();
761
- if (cm instanceof RaindropContextManager) {
762
- await cm.ensureReady();
763
- }
764
709
  const span = {
765
710
  traceIdB64: ctx.traceIdB64,
766
711
  spanIdB64: ctx.spanIdB64,
@@ -787,11 +732,12 @@ async function* asyncGeneratorWithCurrent(span, gen) {
787
732
  nextValue = yield result.value;
788
733
  }
789
734
  }
735
+ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
790
736
 
791
737
  // package.json
792
738
  var package_default = {
793
739
  name: "@raindrop-ai/ai-sdk",
794
- version: "0.0.19-beta.4"};
740
+ version: "0.0.20"};
795
741
 
796
742
  // src/internal/version.ts
797
743
  var libraryName = package_default.name;
@@ -1063,17 +1009,29 @@ function extractTextFromMessageContent(content) {
1063
1009
  }
1064
1010
  return result.length ? result : void 0;
1065
1011
  }
1066
- function extractInputAttachmentsFromArgs(args) {
1067
- if (!isRecord(args)) return void 0;
1012
+ function messagesFromArgs(args) {
1068
1013
  const messages = args["messages"];
1069
- if (!Array.isArray(messages)) return void 0;
1014
+ if (Array.isArray(messages)) return messages;
1015
+ const prompt = args["prompt"];
1016
+ if (Array.isArray(prompt)) return prompt;
1017
+ return void 0;
1018
+ }
1019
+ function lastUserMessageFromArgs(args) {
1020
+ const messages = messagesFromArgs(args);
1021
+ if (!messages) return void 0;
1070
1022
  for (let i = messages.length - 1; i >= 0; i--) {
1071
1023
  const message = messages[i];
1072
- if (!isRecord(message) || message["role"] !== "user") continue;
1073
- return attachmentsFromContent(message["content"], "input");
1024
+ if (isRecord(message) && message["role"] === "user") {
1025
+ return message;
1026
+ }
1074
1027
  }
1075
1028
  return void 0;
1076
1029
  }
1030
+ function extractInputAttachmentsFromArgs(args) {
1031
+ var _a;
1032
+ if (!isRecord(args)) return void 0;
1033
+ return attachmentsFromContent((_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"], "input");
1034
+ }
1077
1035
  async function extractOutputAttachmentsFromResult(result) {
1078
1036
  if (!isRecord(result)) return void 0;
1079
1037
  const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
@@ -1087,26 +1045,20 @@ async function extractOutputAttachmentsFromResult(result) {
1087
1045
  return attachmentsFromContent(result["content"], "output");
1088
1046
  }
1089
1047
  function lastUserMessageTextFromArgs(args) {
1090
- var _a;
1048
+ var _a, _b;
1091
1049
  if (!isRecord(args)) return void 0;
1092
- const messages = args["messages"];
1093
- if (!Array.isArray(messages)) return void 0;
1094
- for (let i = messages.length - 1; i >= 0; i--) {
1095
- const message = messages[i];
1096
- if (!isRecord(message) || message["role"] !== "user") continue;
1097
- const content = message["content"];
1098
- const text = extractTextFromMessageContent(content);
1099
- if (text !== void 0) return text;
1100
- return (_a = safeJsonWithUint8(content)) != null ? _a : String(content);
1101
- }
1102
- return void 0;
1050
+ const content = (_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"];
1051
+ if (content === void 0) return void 0;
1052
+ const text = extractTextFromMessageContent(content);
1053
+ if (text !== void 0) return text;
1054
+ return (_b = safeJsonWithUint8(content)) != null ? _b : String(content);
1103
1055
  }
1104
1056
  function extractInputFromArgs(args) {
1105
1057
  var _a;
1106
1058
  if (!isRecord(args)) return void 0;
1107
1059
  const prompt = args["prompt"];
1108
1060
  if (typeof prompt === "string") return prompt;
1109
- const messages = args["messages"];
1061
+ const messages = messagesFromArgs(args);
1110
1062
  if (Array.isArray(messages) && messages.length > 0) {
1111
1063
  const last = messages[messages.length - 1];
1112
1064
  if (isRecord(last)) {
@@ -1128,7 +1080,7 @@ function coerceMessagesFromArgs(args) {
1128
1080
  if (typeof args["system"] === "string" && args["system"]) {
1129
1081
  result.push({ role: "system", content: args["system"] });
1130
1082
  }
1131
- const messages = args["messages"];
1083
+ const messages = messagesFromArgs(args);
1132
1084
  if (Array.isArray(messages)) {
1133
1085
  for (const message of messages) {
1134
1086
  if (isRecord(message) && typeof message["role"] === "string") {
@@ -1,4 +1,4 @@
1
- export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-MDH47MA5.mjs';
1
+ export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-FD5GVIE2.mjs';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
@@ -1,4 +1,4 @@
1
- export { AISDKChatRequestLike, AISDKChatRequestMessageLike, AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, RaindropTelemetryIntegration, RaindropTelemetryIntegrationOptions, SelfDiagnosticsOptions, SelfDiagnosticsSignalDefinition, SelfDiagnosticsSignalDefinitions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './index.mjs';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-DGziajf_.mjs';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -1,4 +1,4 @@
1
- export { AISDKChatRequestLike, AISDKChatRequestMessageLike, AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, RaindropTelemetryIntegration, RaindropTelemetryIntegrationOptions, SelfDiagnosticsOptions, SelfDiagnosticsSignalDefinition, SelfDiagnosticsSignalDefinitions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './index.js';
1
+ export { A as AISDKChatRequestLike, a as AISDKChatRequestMessageLike, b as AISDKMessage, c as AgentCallMetadata, d as AgentWithMetadata, e as Attachment, B as BuildEventPatch, C as ContextManager, f as ContextSpan, E as EventBuilder, g as EventMetadataOptions, I as IdentifyInput, R as RaindropAISDKClient, h as RaindropAISDKContext, i as RaindropAISDKOptions, j as RaindropTelemetryIntegration, k as RaindropTelemetryIntegrationOptions, S as SelfDiagnosticsOptions, l as SelfDiagnosticsSignalDefinition, m as SelfDiagnosticsSignalDefinitions, W as WrapAISDKOptions, n as WrappedAI, o as WrappedAISDK, _ as _resetWarnedMissingUserId, p as createRaindropAISDK, q as currentSpan, r as eventMetadata, s as eventMetadataFromChatRequest, t as getContextManager, w as withCurrent } from './index-DGziajf_.js';
2
2
 
3
3
  declare global {
4
4
  var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
@@ -4,7 +4,7 @@ var async_hooks = require('async_hooks');
4
4
 
5
5
  // src/index.workers.ts
6
6
 
7
- // ../core/dist/chunk-FOHDGBT5.js
7
+ // ../core/dist/chunk-H6VSZSLN.js
8
8
  function getCrypto() {
9
9
  const c = globalThis.crypto;
10
10
  return c;
@@ -622,49 +622,25 @@ var NOOP_SPAN = {
622
622
  log() {
623
623
  }
624
624
  };
625
- function isPromiseLike(value) {
626
- return value !== null && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
625
+ function getAsyncLocalStorageCtor() {
626
+ return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
627
627
  }
628
- var PendingAsyncLocalStorage = class {
628
+ var SynchronousContextStorage = class {
629
629
  constructor() {
630
- this._real = null;
631
630
  this._stack = [];
632
631
  }
633
- setReal(real) {
634
- const current = this._stack.length ? this._stack[this._stack.length - 1] : void 0;
635
- this._real = real;
636
- if (current !== void 0 && typeof this._real.enterWith === "function") {
637
- this._real.enterWith(current);
638
- }
632
+ isEmpty() {
633
+ return this._stack.length === 0;
639
634
  }
640
635
  getStore() {
641
- var _a, _b;
642
- return (_b = (_a = this._real) == null ? void 0 : _a.getStore()) != null ? _b : this._stack[this._stack.length - 1];
636
+ return this._stack[this._stack.length - 1];
643
637
  }
644
638
  run(store, callback) {
645
- if (this._real) {
646
- return this._real.run(store, callback);
647
- }
648
639
  this._stack.push(store);
649
640
  try {
650
- const result = callback();
651
- if (isPromiseLike(result)) {
652
- return result.then(
653
- (value) => {
654
- this._stack.pop();
655
- return value;
656
- },
657
- (err) => {
658
- this._stack.pop();
659
- throw err;
660
- }
661
- );
662
- }
663
- this._stack.pop();
664
- return result;
665
- } catch (err) {
641
+ return callback();
642
+ } finally {
666
643
  this._stack.pop();
667
- throw err;
668
644
  }
669
645
  }
670
646
  };
@@ -672,53 +648,29 @@ var ContextManager = class {
672
648
  };
673
649
  var RaindropContextManager = class extends ContextManager {
674
650
  constructor() {
675
- var _a;
676
651
  super();
677
- this._storage = null;
678
- this._pending = null;
679
- this._initPromise = null;
680
- const isNode = typeof process !== "undefined" && typeof ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) === "string";
681
- const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
652
+ this._fallback = null;
653
+ const Ctor = getAsyncLocalStorageCtor();
682
654
  if (Ctor) {
683
655
  this._storage = new Ctor();
684
- this._pending = null;
685
- this._initPromise = null;
686
656
  return;
687
657
  }
688
- if (isNode) {
689
- this._pending = new PendingAsyncLocalStorage();
690
- this._storage = this._pending;
691
- this._initPromise = this._initialize();
692
- } else {
693
- this._storage = null;
694
- this._pending = null;
695
- this._initPromise = null;
696
- }
658
+ this._fallback = new SynchronousContextStorage();
659
+ this._storage = this._fallback;
697
660
  }
698
- async _initialize() {
699
- try {
700
- const mod = await import('async_hooks');
701
- const real = new mod.AsyncLocalStorage();
702
- if (this._pending) {
703
- this._pending.setReal(real);
704
- }
705
- this._storage = real;
706
- } catch (e) {
707
- this._storage = null;
708
- }
709
- }
710
- async ensureReady() {
711
- if (this._initPromise) {
712
- await this._initPromise;
713
- this._initPromise = null;
714
- }
661
+ maybeAdoptAsyncLocalStorage() {
662
+ if (!this._fallback || !this._fallback.isEmpty()) return;
663
+ const Ctor = getAsyncLocalStorageCtor();
664
+ if (!Ctor) return;
665
+ this._storage = new Ctor();
666
+ this._fallback = null;
715
667
  }
716
668
  isReady() {
717
- return this._initPromise === null;
669
+ return true;
718
670
  }
719
671
  getParentSpanIds() {
720
- var _a;
721
- const span = (_a = this._storage) == null ? void 0 : _a.getStore();
672
+ this.maybeAdoptAsyncLocalStorage();
673
+ const span = this._storage.getStore();
722
674
  if (!span || span === NOOP_SPAN) return void 0;
723
675
  return {
724
676
  traceIdB64: span.traceIdB64,
@@ -727,12 +679,12 @@ var RaindropContextManager = class extends ContextManager {
727
679
  };
728
680
  }
729
681
  runInContext(span, callback) {
730
- if (!this._storage) return callback();
682
+ this.maybeAdoptAsyncLocalStorage();
731
683
  return this._storage.run(span, callback);
732
684
  }
733
685
  getCurrentSpan() {
734
- var _a;
735
- return (_a = this._storage) == null ? void 0 : _a.getStore();
686
+ this.maybeAdoptAsyncLocalStorage();
687
+ return this._storage.getStore();
736
688
  }
737
689
  };
738
690
  var _contextManager = null;
@@ -750,17 +702,10 @@ function withCurrent(span, callback) {
750
702
  return getContextManager().runInContext(span, callback);
751
703
  }
752
704
  async function getCurrentParentSpanContext() {
753
- const cm = getContextManager();
754
- if (cm instanceof RaindropContextManager) {
755
- await cm.ensureReady();
756
- }
757
- return cm.getParentSpanIds();
705
+ return getContextManager().getParentSpanIds();
758
706
  }
759
707
  async function runWithParentSpanContext(ctx, fn) {
760
708
  const cm = getContextManager();
761
- if (cm instanceof RaindropContextManager) {
762
- await cm.ensureReady();
763
- }
764
709
  const span = {
765
710
  traceIdB64: ctx.traceIdB64,
766
711
  spanIdB64: ctx.spanIdB64,
@@ -787,11 +732,12 @@ async function* asyncGeneratorWithCurrent(span, gen) {
787
732
  nextValue = yield result.value;
788
733
  }
789
734
  }
735
+ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
790
736
 
791
737
  // package.json
792
738
  var package_default = {
793
739
  name: "@raindrop-ai/ai-sdk",
794
- version: "0.0.19-beta.4"};
740
+ version: "0.0.20"};
795
741
 
796
742
  // src/internal/version.ts
797
743
  var libraryName = package_default.name;
@@ -1063,17 +1009,29 @@ function extractTextFromMessageContent(content) {
1063
1009
  }
1064
1010
  return result.length ? result : void 0;
1065
1011
  }
1066
- function extractInputAttachmentsFromArgs(args) {
1067
- if (!isRecord(args)) return void 0;
1012
+ function messagesFromArgs(args) {
1068
1013
  const messages = args["messages"];
1069
- if (!Array.isArray(messages)) return void 0;
1014
+ if (Array.isArray(messages)) return messages;
1015
+ const prompt = args["prompt"];
1016
+ if (Array.isArray(prompt)) return prompt;
1017
+ return void 0;
1018
+ }
1019
+ function lastUserMessageFromArgs(args) {
1020
+ const messages = messagesFromArgs(args);
1021
+ if (!messages) return void 0;
1070
1022
  for (let i = messages.length - 1; i >= 0; i--) {
1071
1023
  const message = messages[i];
1072
- if (!isRecord(message) || message["role"] !== "user") continue;
1073
- return attachmentsFromContent(message["content"], "input");
1024
+ if (isRecord(message) && message["role"] === "user") {
1025
+ return message;
1026
+ }
1074
1027
  }
1075
1028
  return void 0;
1076
1029
  }
1030
+ function extractInputAttachmentsFromArgs(args) {
1031
+ var _a;
1032
+ if (!isRecord(args)) return void 0;
1033
+ return attachmentsFromContent((_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"], "input");
1034
+ }
1077
1035
  async function extractOutputAttachmentsFromResult(result) {
1078
1036
  if (!isRecord(result)) return void 0;
1079
1037
  const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
@@ -1087,26 +1045,20 @@ async function extractOutputAttachmentsFromResult(result) {
1087
1045
  return attachmentsFromContent(result["content"], "output");
1088
1046
  }
1089
1047
  function lastUserMessageTextFromArgs(args) {
1090
- var _a;
1048
+ var _a, _b;
1091
1049
  if (!isRecord(args)) return void 0;
1092
- const messages = args["messages"];
1093
- if (!Array.isArray(messages)) return void 0;
1094
- for (let i = messages.length - 1; i >= 0; i--) {
1095
- const message = messages[i];
1096
- if (!isRecord(message) || message["role"] !== "user") continue;
1097
- const content = message["content"];
1098
- const text = extractTextFromMessageContent(content);
1099
- if (text !== void 0) return text;
1100
- return (_a = safeJsonWithUint8(content)) != null ? _a : String(content);
1101
- }
1102
- return void 0;
1050
+ const content = (_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"];
1051
+ if (content === void 0) return void 0;
1052
+ const text = extractTextFromMessageContent(content);
1053
+ if (text !== void 0) return text;
1054
+ return (_b = safeJsonWithUint8(content)) != null ? _b : String(content);
1103
1055
  }
1104
1056
  function extractInputFromArgs(args) {
1105
1057
  var _a;
1106
1058
  if (!isRecord(args)) return void 0;
1107
1059
  const prompt = args["prompt"];
1108
1060
  if (typeof prompt === "string") return prompt;
1109
- const messages = args["messages"];
1061
+ const messages = messagesFromArgs(args);
1110
1062
  if (Array.isArray(messages) && messages.length > 0) {
1111
1063
  const last = messages[messages.length - 1];
1112
1064
  if (isRecord(last)) {
@@ -1128,7 +1080,7 @@ function coerceMessagesFromArgs(args) {
1128
1080
  if (typeof args["system"] === "string" && args["system"]) {
1129
1081
  result.push({ role: "system", content: args["system"] });
1130
1082
  }
1131
- const messages = args["messages"];
1083
+ const messages = messagesFromArgs(args);
1132
1084
  if (Array.isArray(messages)) {
1133
1085
  for (const message of messages) {
1134
1086
  if (isRecord(message) && typeof message["role"] === "string") {
@@ -1,4 +1,4 @@
1
- export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-MDH47MA5.mjs';
1
+ export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-FD5GVIE2.mjs';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@raindrop-ai/ai-sdk",
3
- "version": "0.0.19-beta.4",
3
+ "version": "0.0.20",
4
4
  "description": "Standalone Vercel AI SDK integration for Raindrop (events + OTLP/HTTP JSON traces, no OTEL runtime)",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
5
+ "main": "dist/index.node.js",
6
+ "module": "dist/index.node.mjs",
7
+ "types": "dist/index.node.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "node": {
12
- "import": "./dist/index.node.mjs",
13
- "require": "./dist/index.node.js"
14
- },
15
- "import": "./dist/index.mjs",
16
- "require": "./dist/index.js"
10
+ "types": "./dist/index.node.d.ts",
11
+ "import": "./dist/index.node.mjs",
12
+ "require": "./dist/index.node.js"
13
+ },
14
+ "./browser": {
15
+ "types": "./dist/index.browser.d.ts",
16
+ "import": "./dist/index.browser.mjs",
17
+ "require": "./dist/index.browser.js"
17
18
  },
18
19
  "./workers": {
19
20
  "types": "./dist/index.workers.d.ts",
@@ -51,20 +52,6 @@
51
52
  "peerDependencies": {
52
53
  "ai": ">=4 <8"
53
54
  },
54
- "tsup": {
55
- "entry": [
56
- "src/index.ts",
57
- "src/index.node.ts"
58
- ],
59
- "format": [
60
- "cjs",
61
- "esm"
62
- ],
63
- "dts": {
64
- "resolve": true
65
- },
66
- "clean": true
67
- },
68
55
  "publishConfig": {
69
56
  "access": "public"
70
57
  }
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-MDH47MA5.mjs';
File without changes
File without changes