@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.
- package/README.md +22 -3
- package/dist/{chunk-MDH47MA5.mjs → chunk-FD5GVIE2.mjs} +89 -135
- package/dist/index-DGziajf_.d.mts +601 -0
- package/dist/index-DGziajf_.d.ts +601 -0
- package/dist/{index.js → index.browser.js} +52 -101
- package/dist/index.browser.mjs +3948 -0
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +53 -101
- package/dist/index.node.mjs +1 -1
- package/dist/index.workers.d.mts +1 -1
- package/dist/index.workers.d.ts +1 -1
- package/dist/index.workers.js +53 -101
- package/dist/index.workers.mjs +1 -1
- package/package.json +12 -25
- package/dist/index.mjs +0 -1
- /package/dist/{index.d.mts → index.browser.d.mts} +0 -0
- /package/dist/{index.d.ts → index.browser.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -58,7 +58,20 @@ If `userId` is missing from both `wrap()` context and `eventMetadata()`, the SDK
|
|
|
58
58
|
|
|
59
59
|
## Runtime support
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### Browsers and edge runtimes
|
|
62
|
+
|
|
63
|
+
Use the browser entrypoint:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { createRaindropAISDK } from "@raindrop-ai/ai-sdk/browser";
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The SDK works without `async_hooks` shims. When `AsyncLocalStorage` is not available,
|
|
70
|
+
Raindrop falls back to synchronous context scoping: nested work in the same call stack
|
|
71
|
+
still inherits context, but automatic propagation across arbitrary async boundaries is
|
|
72
|
+
not guaranteed.
|
|
73
|
+
|
|
74
|
+
### Node.js
|
|
62
75
|
|
|
63
76
|
Use the default import:
|
|
64
77
|
|
|
@@ -66,17 +79,23 @@ Use the default import:
|
|
|
66
79
|
import { createRaindropAISDK } from "@raindrop-ai/ai-sdk";
|
|
67
80
|
```
|
|
68
81
|
|
|
82
|
+
In Node, the default entrypoint wires up `AsyncLocalStorage` automatically.
|
|
83
|
+
|
|
69
84
|
### Cloudflare Workers
|
|
70
85
|
|
|
71
86
|
Cloudflare Workers can provide `AsyncLocalStorage` via `node:async_hooks` when `nodejs_compat` is enabled ([docs](https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/)).
|
|
72
87
|
|
|
73
|
-
|
|
88
|
+
If `nodejs_compat` is enabled, use the Workers entrypoint:
|
|
74
89
|
|
|
75
90
|
```ts
|
|
76
91
|
import { createRaindropAISDK } from "@raindrop-ai/ai-sdk/workers";
|
|
77
92
|
```
|
|
78
93
|
|
|
79
|
-
|
|
94
|
+
This enables real `AsyncLocalStorage` propagation in Workers.
|
|
95
|
+
|
|
96
|
+
If `nodejs_compat` is not enabled, use the browser entrypoint instead. The SDK still works,
|
|
97
|
+
but it uses the same synchronous fallback described above rather than real
|
|
98
|
+
`AsyncLocalStorage`.
|
|
80
99
|
|
|
81
100
|
## Supported AI SDK Versions
|
|
82
101
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
|
|
3
|
+
// ../core/dist/chunk-H6VSZSLN.js
|
|
2
4
|
function getCrypto() {
|
|
3
5
|
const c = globalThis.crypto;
|
|
4
6
|
return c;
|
|
@@ -616,49 +618,25 @@ var NOOP_SPAN = {
|
|
|
616
618
|
log() {
|
|
617
619
|
}
|
|
618
620
|
};
|
|
619
|
-
function
|
|
620
|
-
return
|
|
621
|
+
function getAsyncLocalStorageCtor() {
|
|
622
|
+
return globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
621
623
|
}
|
|
622
|
-
var
|
|
624
|
+
var SynchronousContextStorage = class {
|
|
623
625
|
constructor() {
|
|
624
|
-
this._real = null;
|
|
625
626
|
this._stack = [];
|
|
626
627
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
this._real = real;
|
|
630
|
-
if (current !== void 0 && typeof this._real.enterWith === "function") {
|
|
631
|
-
this._real.enterWith(current);
|
|
632
|
-
}
|
|
628
|
+
isEmpty() {
|
|
629
|
+
return this._stack.length === 0;
|
|
633
630
|
}
|
|
634
631
|
getStore() {
|
|
635
|
-
|
|
636
|
-
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];
|
|
637
633
|
}
|
|
638
634
|
run(store, callback) {
|
|
639
|
-
if (this._real) {
|
|
640
|
-
return this._real.run(store, callback);
|
|
641
|
-
}
|
|
642
635
|
this._stack.push(store);
|
|
643
636
|
try {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
return result.then(
|
|
647
|
-
(value) => {
|
|
648
|
-
this._stack.pop();
|
|
649
|
-
return value;
|
|
650
|
-
},
|
|
651
|
-
(err) => {
|
|
652
|
-
this._stack.pop();
|
|
653
|
-
throw err;
|
|
654
|
-
}
|
|
655
|
-
);
|
|
656
|
-
}
|
|
657
|
-
this._stack.pop();
|
|
658
|
-
return result;
|
|
659
|
-
} catch (err) {
|
|
637
|
+
return callback();
|
|
638
|
+
} finally {
|
|
660
639
|
this._stack.pop();
|
|
661
|
-
throw err;
|
|
662
640
|
}
|
|
663
641
|
}
|
|
664
642
|
};
|
|
@@ -666,53 +644,29 @@ var ContextManager = class {
|
|
|
666
644
|
};
|
|
667
645
|
var RaindropContextManager = class extends ContextManager {
|
|
668
646
|
constructor() {
|
|
669
|
-
var _a;
|
|
670
647
|
super();
|
|
671
|
-
this.
|
|
672
|
-
|
|
673
|
-
this._initPromise = null;
|
|
674
|
-
const isNode = typeof process !== "undefined" && typeof ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) === "string";
|
|
675
|
-
const Ctor = globalThis.RAINDROP_ASYNC_LOCAL_STORAGE;
|
|
648
|
+
this._fallback = null;
|
|
649
|
+
const Ctor = getAsyncLocalStorageCtor();
|
|
676
650
|
if (Ctor) {
|
|
677
651
|
this._storage = new Ctor();
|
|
678
|
-
this._pending = null;
|
|
679
|
-
this._initPromise = null;
|
|
680
652
|
return;
|
|
681
653
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
this._storage = this._pending;
|
|
685
|
-
this._initPromise = this._initialize();
|
|
686
|
-
} else {
|
|
687
|
-
this._storage = null;
|
|
688
|
-
this._pending = null;
|
|
689
|
-
this._initPromise = null;
|
|
690
|
-
}
|
|
654
|
+
this._fallback = new SynchronousContextStorage();
|
|
655
|
+
this._storage = this._fallback;
|
|
691
656
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
this._storage = real;
|
|
700
|
-
} catch (e) {
|
|
701
|
-
this._storage = null;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
async ensureReady() {
|
|
705
|
-
if (this._initPromise) {
|
|
706
|
-
await this._initPromise;
|
|
707
|
-
this._initPromise = null;
|
|
708
|
-
}
|
|
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;
|
|
709
663
|
}
|
|
710
664
|
isReady() {
|
|
711
|
-
return
|
|
665
|
+
return true;
|
|
712
666
|
}
|
|
713
667
|
getParentSpanIds() {
|
|
714
|
-
|
|
715
|
-
const span =
|
|
668
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
669
|
+
const span = this._storage.getStore();
|
|
716
670
|
if (!span || span === NOOP_SPAN) return void 0;
|
|
717
671
|
return {
|
|
718
672
|
traceIdB64: span.traceIdB64,
|
|
@@ -721,12 +675,12 @@ var RaindropContextManager = class extends ContextManager {
|
|
|
721
675
|
};
|
|
722
676
|
}
|
|
723
677
|
runInContext(span, callback) {
|
|
724
|
-
|
|
678
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
725
679
|
return this._storage.run(span, callback);
|
|
726
680
|
}
|
|
727
681
|
getCurrentSpan() {
|
|
728
|
-
|
|
729
|
-
return
|
|
682
|
+
this.maybeAdoptAsyncLocalStorage();
|
|
683
|
+
return this._storage.getStore();
|
|
730
684
|
}
|
|
731
685
|
};
|
|
732
686
|
var _contextManager = null;
|
|
@@ -744,17 +698,10 @@ function withCurrent(span, callback) {
|
|
|
744
698
|
return getContextManager().runInContext(span, callback);
|
|
745
699
|
}
|
|
746
700
|
async function getCurrentParentSpanContext() {
|
|
747
|
-
|
|
748
|
-
if (cm instanceof RaindropContextManager) {
|
|
749
|
-
await cm.ensureReady();
|
|
750
|
-
}
|
|
751
|
-
return cm.getParentSpanIds();
|
|
701
|
+
return getContextManager().getParentSpanIds();
|
|
752
702
|
}
|
|
753
703
|
async function runWithParentSpanContext(ctx, fn) {
|
|
754
704
|
const cm = getContextManager();
|
|
755
|
-
if (cm instanceof RaindropContextManager) {
|
|
756
|
-
await cm.ensureReady();
|
|
757
|
-
}
|
|
758
705
|
const span = {
|
|
759
706
|
traceIdB64: ctx.traceIdB64,
|
|
760
707
|
spanIdB64: ctx.spanIdB64,
|
|
@@ -781,28 +728,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
|
|
|
781
728
|
nextValue = yield result.value;
|
|
782
729
|
}
|
|
783
730
|
}
|
|
784
|
-
|
|
785
|
-
// package.json
|
|
786
|
-
var package_default = {
|
|
787
|
-
name: "@raindrop-ai/ai-sdk",
|
|
788
|
-
version: "0.0.19-beta.4"};
|
|
789
|
-
|
|
790
|
-
// src/internal/version.ts
|
|
791
|
-
var libraryName = package_default.name;
|
|
792
|
-
var libraryVersion = package_default.version;
|
|
793
|
-
|
|
794
|
-
// src/internal/events.ts
|
|
795
|
-
var EventShipper2 = class extends EventShipper {
|
|
796
|
-
constructor(opts) {
|
|
797
|
-
var _a, _b, _c;
|
|
798
|
-
super({
|
|
799
|
-
...opts,
|
|
800
|
-
sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
|
|
801
|
-
libraryName: (_b = opts.libraryName) != null ? _b : libraryName,
|
|
802
|
-
libraryVersion: (_c = opts.libraryVersion) != null ? _c : libraryVersion
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
};
|
|
731
|
+
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
|
806
732
|
|
|
807
733
|
// src/internal/wrap/helpers.ts
|
|
808
734
|
function isRecord(value) {
|
|
@@ -1057,17 +983,29 @@ function extractTextFromMessageContent(content) {
|
|
|
1057
983
|
}
|
|
1058
984
|
return result.length ? result : void 0;
|
|
1059
985
|
}
|
|
1060
|
-
function
|
|
1061
|
-
if (!isRecord(args)) return void 0;
|
|
986
|
+
function messagesFromArgs(args) {
|
|
1062
987
|
const messages = args["messages"];
|
|
1063
|
-
if (
|
|
988
|
+
if (Array.isArray(messages)) return messages;
|
|
989
|
+
const prompt = args["prompt"];
|
|
990
|
+
if (Array.isArray(prompt)) return prompt;
|
|
991
|
+
return void 0;
|
|
992
|
+
}
|
|
993
|
+
function lastUserMessageFromArgs(args) {
|
|
994
|
+
const messages = messagesFromArgs(args);
|
|
995
|
+
if (!messages) return void 0;
|
|
1064
996
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1065
997
|
const message = messages[i];
|
|
1066
|
-
if (
|
|
1067
|
-
|
|
998
|
+
if (isRecord(message) && message["role"] === "user") {
|
|
999
|
+
return message;
|
|
1000
|
+
}
|
|
1068
1001
|
}
|
|
1069
1002
|
return void 0;
|
|
1070
1003
|
}
|
|
1004
|
+
function extractInputAttachmentsFromArgs(args) {
|
|
1005
|
+
var _a;
|
|
1006
|
+
if (!isRecord(args)) return void 0;
|
|
1007
|
+
return attachmentsFromContent((_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"], "input");
|
|
1008
|
+
}
|
|
1071
1009
|
async function extractOutputAttachmentsFromResult(result) {
|
|
1072
1010
|
if (!isRecord(result)) return void 0;
|
|
1073
1011
|
const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
|
|
@@ -1081,26 +1019,20 @@ async function extractOutputAttachmentsFromResult(result) {
|
|
|
1081
1019
|
return attachmentsFromContent(result["content"], "output");
|
|
1082
1020
|
}
|
|
1083
1021
|
function lastUserMessageTextFromArgs(args) {
|
|
1084
|
-
var _a;
|
|
1022
|
+
var _a, _b;
|
|
1085
1023
|
if (!isRecord(args)) return void 0;
|
|
1086
|
-
const
|
|
1087
|
-
if (
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
const content = message["content"];
|
|
1092
|
-
const text = extractTextFromMessageContent(content);
|
|
1093
|
-
if (text !== void 0) return text;
|
|
1094
|
-
return (_a = safeJsonWithUint8(content)) != null ? _a : String(content);
|
|
1095
|
-
}
|
|
1096
|
-
return void 0;
|
|
1024
|
+
const content = (_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"];
|
|
1025
|
+
if (content === void 0) return void 0;
|
|
1026
|
+
const text = extractTextFromMessageContent(content);
|
|
1027
|
+
if (text !== void 0) return text;
|
|
1028
|
+
return (_b = safeJsonWithUint8(content)) != null ? _b : String(content);
|
|
1097
1029
|
}
|
|
1098
1030
|
function extractInputFromArgs(args) {
|
|
1099
1031
|
var _a;
|
|
1100
1032
|
if (!isRecord(args)) return void 0;
|
|
1101
1033
|
const prompt = args["prompt"];
|
|
1102
1034
|
if (typeof prompt === "string") return prompt;
|
|
1103
|
-
const messages = args
|
|
1035
|
+
const messages = messagesFromArgs(args);
|
|
1104
1036
|
if (Array.isArray(messages) && messages.length > 0) {
|
|
1105
1037
|
const last = messages[messages.length - 1];
|
|
1106
1038
|
if (isRecord(last)) {
|
|
@@ -1122,7 +1054,7 @@ function coerceMessagesFromArgs(args) {
|
|
|
1122
1054
|
if (typeof args["system"] === "string" && args["system"]) {
|
|
1123
1055
|
result.push({ role: "system", content: args["system"] });
|
|
1124
1056
|
}
|
|
1125
|
-
const messages = args
|
|
1057
|
+
const messages = messagesFromArgs(args);
|
|
1126
1058
|
if (Array.isArray(messages)) {
|
|
1127
1059
|
for (const message of messages) {
|
|
1128
1060
|
if (isRecord(message) && typeof message["role"] === "string") {
|
|
@@ -1949,19 +1881,6 @@ var RaindropTelemetryIntegration = class {
|
|
|
1949
1881
|
}
|
|
1950
1882
|
};
|
|
1951
1883
|
|
|
1952
|
-
// src/internal/traces.ts
|
|
1953
|
-
var TraceShipper2 = class extends TraceShipper {
|
|
1954
|
-
constructor(opts) {
|
|
1955
|
-
var _a, _b, _c;
|
|
1956
|
-
super({
|
|
1957
|
-
...opts,
|
|
1958
|
-
sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
|
|
1959
|
-
serviceName: (_b = opts.serviceName) != null ? _b : "raindrop.ai-sdk",
|
|
1960
|
-
serviceVersion: (_c = opts.serviceVersion) != null ? _c : libraryVersion
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
|
-
};
|
|
1964
|
-
|
|
1965
1884
|
// src/internal/wrap/wrapAISDK.ts
|
|
1966
1885
|
var AGENT_REPORTING_TOOL_NAME_DEFAULT = "__raindrop_report";
|
|
1967
1886
|
var AGENT_REPORTING_SIGNALS_DEFAULT = {
|
|
@@ -3867,6 +3786,41 @@ function extractNestedTokens(usage, key) {
|
|
|
3867
3786
|
return void 0;
|
|
3868
3787
|
}
|
|
3869
3788
|
|
|
3789
|
+
// package.json
|
|
3790
|
+
var package_default = {
|
|
3791
|
+
name: "@raindrop-ai/ai-sdk",
|
|
3792
|
+
version: "0.0.20"};
|
|
3793
|
+
|
|
3794
|
+
// src/internal/version.ts
|
|
3795
|
+
var libraryName = package_default.name;
|
|
3796
|
+
var libraryVersion = package_default.version;
|
|
3797
|
+
|
|
3798
|
+
// src/internal/events.ts
|
|
3799
|
+
var EventShipper2 = class extends EventShipper {
|
|
3800
|
+
constructor(opts) {
|
|
3801
|
+
var _a, _b, _c;
|
|
3802
|
+
super({
|
|
3803
|
+
...opts,
|
|
3804
|
+
sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
|
|
3805
|
+
libraryName: (_b = opts.libraryName) != null ? _b : libraryName,
|
|
3806
|
+
libraryVersion: (_c = opts.libraryVersion) != null ? _c : libraryVersion
|
|
3807
|
+
});
|
|
3808
|
+
}
|
|
3809
|
+
};
|
|
3810
|
+
|
|
3811
|
+
// src/internal/traces.ts
|
|
3812
|
+
var TraceShipper2 = class extends TraceShipper {
|
|
3813
|
+
constructor(opts) {
|
|
3814
|
+
var _a, _b, _c;
|
|
3815
|
+
super({
|
|
3816
|
+
...opts,
|
|
3817
|
+
sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
|
|
3818
|
+
serviceName: (_b = opts.serviceName) != null ? _b : "raindrop.ai-sdk",
|
|
3819
|
+
serviceVersion: (_c = opts.serviceVersion) != null ? _c : libraryVersion
|
|
3820
|
+
});
|
|
3821
|
+
}
|
|
3822
|
+
};
|
|
3823
|
+
|
|
3870
3824
|
// src/index.ts
|
|
3871
3825
|
function eventMetadata(options) {
|
|
3872
3826
|
const result = {};
|