@raindrop-ai/ai-sdk 0.0.5 → 0.0.7
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 +9 -2
- package/dist/{chunk-5DKYVVJZ.mjs → chunk-6ICSE4FE.mjs} +21 -5
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +21 -4
- package/dist/index.mjs +1 -1
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +21 -4
- 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 +21 -4
- package/dist/index.workers.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,14 +16,15 @@ yarn add @raindrop-ai/ai-sdk
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import * as ai from "ai";
|
|
19
|
-
import { createRaindropAISDK } from "@raindrop-ai/ai-sdk";
|
|
19
|
+
import { createRaindropAISDK, eventMetadata } from "@raindrop-ai/ai-sdk";
|
|
20
20
|
|
|
21
21
|
const raindrop = createRaindropAISDK({
|
|
22
22
|
writeKey: process.env.RAINDROP_WRITE_KEY!,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
const { generateText } = raindrop.wrap(ai, {
|
|
26
|
-
|
|
26
|
+
// userId is optional here (but recommended). If omitted here, you can still provide it per-call via eventMetadata(). Otherwise events will be skipped.
|
|
27
|
+
context: { convoId: "convo_456", eventName: "chat_message" },
|
|
27
28
|
// optional: full control over event input/output, metadata, and attachments
|
|
28
29
|
buildEvent: (messages) => {
|
|
29
30
|
const lastUser = [...messages].reverse().find((m) => m.role === "user");
|
|
@@ -38,6 +39,10 @@ const { generateText } = raindrop.wrap(ai, {
|
|
|
38
39
|
const result = await generateText({
|
|
39
40
|
model: /* your AI SDK model */,
|
|
40
41
|
prompt: "Hello!",
|
|
42
|
+
experimental_telemetry: {
|
|
43
|
+
isEnabled: true,
|
|
44
|
+
metadata: eventMetadata({ userId: "user_123" }),
|
|
45
|
+
},
|
|
41
46
|
});
|
|
42
47
|
|
|
43
48
|
// Identify a user (optional)
|
|
@@ -49,6 +54,8 @@ await raindrop.users.identify({
|
|
|
49
54
|
await raindrop.flush();
|
|
50
55
|
```
|
|
51
56
|
|
|
57
|
+
If `userId` is missing from both `wrap()` context and `eventMetadata()`, the SDK logs a warning (once) and skips sending events.
|
|
58
|
+
|
|
52
59
|
## Runtime support
|
|
53
60
|
|
|
54
61
|
### Node.js (recommended)
|
|
@@ -84,7 +84,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
84
84
|
// package.json
|
|
85
85
|
var package_default = {
|
|
86
86
|
name: "@raindrop-ai/ai-sdk",
|
|
87
|
-
version: "0.0.
|
|
87
|
+
version: "0.0.7"};
|
|
88
88
|
|
|
89
89
|
// src/internal/version.ts
|
|
90
90
|
var libraryName = package_default.name;
|
|
@@ -270,19 +270,21 @@ var EventShipper = class {
|
|
|
270
270
|
}
|
|
271
271
|
return;
|
|
272
272
|
}
|
|
273
|
+
const { wizardSession, ...restProperties } = (_e = accumulated.properties) != null ? _e : {};
|
|
273
274
|
const payload = {
|
|
274
275
|
event_id: eventId,
|
|
275
276
|
user_id: userId,
|
|
276
277
|
event: eventName,
|
|
277
|
-
timestamp: (
|
|
278
|
+
timestamp: (_f = accumulated.timestamp) != null ? _f : (/* @__PURE__ */ new Date()).toISOString(),
|
|
278
279
|
ai_data: {
|
|
279
280
|
input: accumulated.input,
|
|
280
281
|
output: accumulated.output,
|
|
281
282
|
model: accumulated.model,
|
|
282
|
-
convo_id: (
|
|
283
|
+
convo_id: (_g = accumulated.convoId) != null ? _g : sticky.convoId
|
|
283
284
|
},
|
|
284
285
|
properties: {
|
|
285
|
-
...
|
|
286
|
+
...restProperties,
|
|
287
|
+
...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
|
|
286
288
|
$context: this.context
|
|
287
289
|
},
|
|
288
290
|
attachments: accumulated.attachments,
|
|
@@ -1239,6 +1241,17 @@ function attrsFromGenAiRequest(options) {
|
|
|
1239
1241
|
}
|
|
1240
1242
|
|
|
1241
1243
|
// src/internal/wrap/wrapAISDK.ts
|
|
1244
|
+
var warnedMissingUserId = false;
|
|
1245
|
+
function warnMissingUserIdOnce() {
|
|
1246
|
+
if (warnedMissingUserId) return;
|
|
1247
|
+
warnedMissingUserId = true;
|
|
1248
|
+
console.warn(
|
|
1249
|
+
"[raindrop-ai/ai-sdk] userId was not provided in wrap() context or via eventMetadata(). Events will be skipped unless a userId is provided."
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
function _resetWarnedMissingUserId() {
|
|
1253
|
+
warnedMissingUserId = false;
|
|
1254
|
+
}
|
|
1242
1255
|
function extractRaindropMetadata(metadata) {
|
|
1243
1256
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1244
1257
|
const result = {};
|
|
@@ -1409,6 +1422,7 @@ function setupOperation(params) {
|
|
|
1409
1422
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
1410
1423
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1411
1424
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1425
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1412
1426
|
const eventId = (_c = (_b = (_a = callTimeCtx.eventId) != null ? _a : mergedCtx.eventId) != null ? _b : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1413
1427
|
const ctx = { ...mergedCtx, eventId };
|
|
1414
1428
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
@@ -1762,6 +1776,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1762
1776
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1763
1777
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1764
1778
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1779
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1765
1780
|
const inherited = await getCurrentParentSpanContext();
|
|
1766
1781
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1767
1782
|
const ctx = { ...mergedCtx};
|
|
@@ -1949,6 +1964,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1949
1964
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1950
1965
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1951
1966
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1967
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1952
1968
|
const inherited = await getCurrentParentSpanContext();
|
|
1953
1969
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1954
1970
|
const ctx = { ...mergedCtx};
|
|
@@ -2676,4 +2692,4 @@ function createRaindropAISDK(opts) {
|
|
|
2676
2692
|
};
|
|
2677
2693
|
}
|
|
2678
2694
|
|
|
2679
|
-
export { createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
|
2695
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
package/dist/index.d.mts
CHANGED
|
@@ -79,6 +79,8 @@ declare function currentSpan(): ContextSpan;
|
|
|
79
79
|
*/
|
|
80
80
|
declare function withCurrent<R>(span: ContextSpan, callback: () => R): R;
|
|
81
81
|
|
|
82
|
+
declare function _resetWarnedMissingUserId(): void;
|
|
83
|
+
|
|
82
84
|
/**
|
|
83
85
|
* Options for creating event metadata for call-time context override.
|
|
84
86
|
*/
|
|
@@ -154,7 +156,7 @@ type RaindropAISDKOptions = {
|
|
|
154
156
|
};
|
|
155
157
|
};
|
|
156
158
|
type RaindropAISDKContext = {
|
|
157
|
-
userId
|
|
159
|
+
userId?: string;
|
|
158
160
|
eventId?: string;
|
|
159
161
|
eventName?: string;
|
|
160
162
|
convoId?: string;
|
|
@@ -247,4 +249,4 @@ type RaindropAISDKClient = {
|
|
|
247
249
|
};
|
|
248
250
|
declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
|
|
249
251
|
|
|
250
|
-
export { type AISDKMessage, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
|
252
|
+
export { type AISDKMessage, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,8 @@ declare function currentSpan(): ContextSpan;
|
|
|
79
79
|
*/
|
|
80
80
|
declare function withCurrent<R>(span: ContextSpan, callback: () => R): R;
|
|
81
81
|
|
|
82
|
+
declare function _resetWarnedMissingUserId(): void;
|
|
83
|
+
|
|
82
84
|
/**
|
|
83
85
|
* Options for creating event metadata for call-time context override.
|
|
84
86
|
*/
|
|
@@ -154,7 +156,7 @@ type RaindropAISDKOptions = {
|
|
|
154
156
|
};
|
|
155
157
|
};
|
|
156
158
|
type RaindropAISDKContext = {
|
|
157
|
-
userId
|
|
159
|
+
userId?: string;
|
|
158
160
|
eventId?: string;
|
|
159
161
|
eventName?: string;
|
|
160
162
|
convoId?: string;
|
|
@@ -247,4 +249,4 @@ type RaindropAISDKClient = {
|
|
|
247
249
|
};
|
|
248
250
|
declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
|
|
249
251
|
|
|
250
|
-
export { type AISDKMessage, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
|
252
|
+
export { type AISDKMessage, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
package/dist/index.js
CHANGED
|
@@ -86,7 +86,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
86
86
|
// package.json
|
|
87
87
|
var package_default = {
|
|
88
88
|
name: "@raindrop-ai/ai-sdk",
|
|
89
|
-
version: "0.0.
|
|
89
|
+
version: "0.0.7"};
|
|
90
90
|
|
|
91
91
|
// src/internal/version.ts
|
|
92
92
|
var libraryName = package_default.name;
|
|
@@ -272,19 +272,21 @@ var EventShipper = class {
|
|
|
272
272
|
}
|
|
273
273
|
return;
|
|
274
274
|
}
|
|
275
|
+
const { wizardSession, ...restProperties } = (_e = accumulated.properties) != null ? _e : {};
|
|
275
276
|
const payload = {
|
|
276
277
|
event_id: eventId,
|
|
277
278
|
user_id: userId,
|
|
278
279
|
event: eventName,
|
|
279
|
-
timestamp: (
|
|
280
|
+
timestamp: (_f = accumulated.timestamp) != null ? _f : (/* @__PURE__ */ new Date()).toISOString(),
|
|
280
281
|
ai_data: {
|
|
281
282
|
input: accumulated.input,
|
|
282
283
|
output: accumulated.output,
|
|
283
284
|
model: accumulated.model,
|
|
284
|
-
convo_id: (
|
|
285
|
+
convo_id: (_g = accumulated.convoId) != null ? _g : sticky.convoId
|
|
285
286
|
},
|
|
286
287
|
properties: {
|
|
287
|
-
...
|
|
288
|
+
...restProperties,
|
|
289
|
+
...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
|
|
288
290
|
$context: this.context
|
|
289
291
|
},
|
|
290
292
|
attachments: accumulated.attachments,
|
|
@@ -1241,6 +1243,17 @@ function attrsFromGenAiRequest(options) {
|
|
|
1241
1243
|
}
|
|
1242
1244
|
|
|
1243
1245
|
// src/internal/wrap/wrapAISDK.ts
|
|
1246
|
+
var warnedMissingUserId = false;
|
|
1247
|
+
function warnMissingUserIdOnce() {
|
|
1248
|
+
if (warnedMissingUserId) return;
|
|
1249
|
+
warnedMissingUserId = true;
|
|
1250
|
+
console.warn(
|
|
1251
|
+
"[raindrop-ai/ai-sdk] userId was not provided in wrap() context or via eventMetadata(). Events will be skipped unless a userId is provided."
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
function _resetWarnedMissingUserId() {
|
|
1255
|
+
warnedMissingUserId = false;
|
|
1256
|
+
}
|
|
1244
1257
|
function extractRaindropMetadata(metadata) {
|
|
1245
1258
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1246
1259
|
const result = {};
|
|
@@ -1411,6 +1424,7 @@ function setupOperation(params) {
|
|
|
1411
1424
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
1412
1425
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1413
1426
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1427
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1414
1428
|
const eventId = (_c = (_b = (_a = callTimeCtx.eventId) != null ? _a : mergedCtx.eventId) != null ? _b : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1415
1429
|
const ctx = { ...mergedCtx, eventId };
|
|
1416
1430
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
@@ -1764,6 +1778,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1764
1778
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1765
1779
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1766
1780
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1781
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1767
1782
|
const inherited = await getCurrentParentSpanContext();
|
|
1768
1783
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1769
1784
|
const ctx = { ...mergedCtx};
|
|
@@ -1951,6 +1966,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1951
1966
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1952
1967
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1953
1968
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1969
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1954
1970
|
const inherited = await getCurrentParentSpanContext();
|
|
1955
1971
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1956
1972
|
const ctx = { ...mergedCtx};
|
|
@@ -2678,6 +2694,7 @@ function createRaindropAISDK(opts) {
|
|
|
2678
2694
|
};
|
|
2679
2695
|
}
|
|
2680
2696
|
|
|
2697
|
+
exports._resetWarnedMissingUserId = _resetWarnedMissingUserId;
|
|
2681
2698
|
exports.createRaindropAISDK = createRaindropAISDK;
|
|
2682
2699
|
exports.currentSpan = currentSpan;
|
|
2683
2700
|
exports.eventMetadata = eventMetadata;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-6ICSE4FE.mjs';
|
package/dist/index.node.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
|
|
1
|
+
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|
package/dist/index.node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
|
|
1
|
+
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|
package/dist/index.node.js
CHANGED
|
@@ -90,7 +90,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
90
90
|
// package.json
|
|
91
91
|
var package_default = {
|
|
92
92
|
name: "@raindrop-ai/ai-sdk",
|
|
93
|
-
version: "0.0.
|
|
93
|
+
version: "0.0.7"};
|
|
94
94
|
|
|
95
95
|
// src/internal/version.ts
|
|
96
96
|
var libraryName = package_default.name;
|
|
@@ -276,19 +276,21 @@ var EventShipper = class {
|
|
|
276
276
|
}
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
|
+
const { wizardSession, ...restProperties } = (_e = accumulated.properties) != null ? _e : {};
|
|
279
280
|
const payload = {
|
|
280
281
|
event_id: eventId,
|
|
281
282
|
user_id: userId,
|
|
282
283
|
event: eventName,
|
|
283
|
-
timestamp: (
|
|
284
|
+
timestamp: (_f = accumulated.timestamp) != null ? _f : (/* @__PURE__ */ new Date()).toISOString(),
|
|
284
285
|
ai_data: {
|
|
285
286
|
input: accumulated.input,
|
|
286
287
|
output: accumulated.output,
|
|
287
288
|
model: accumulated.model,
|
|
288
|
-
convo_id: (
|
|
289
|
+
convo_id: (_g = accumulated.convoId) != null ? _g : sticky.convoId
|
|
289
290
|
},
|
|
290
291
|
properties: {
|
|
291
|
-
...
|
|
292
|
+
...restProperties,
|
|
293
|
+
...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
|
|
292
294
|
$context: this.context
|
|
293
295
|
},
|
|
294
296
|
attachments: accumulated.attachments,
|
|
@@ -1245,6 +1247,17 @@ function attrsFromGenAiRequest(options) {
|
|
|
1245
1247
|
}
|
|
1246
1248
|
|
|
1247
1249
|
// src/internal/wrap/wrapAISDK.ts
|
|
1250
|
+
var warnedMissingUserId = false;
|
|
1251
|
+
function warnMissingUserIdOnce() {
|
|
1252
|
+
if (warnedMissingUserId) return;
|
|
1253
|
+
warnedMissingUserId = true;
|
|
1254
|
+
console.warn(
|
|
1255
|
+
"[raindrop-ai/ai-sdk] userId was not provided in wrap() context or via eventMetadata(). Events will be skipped unless a userId is provided."
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
function _resetWarnedMissingUserId() {
|
|
1259
|
+
warnedMissingUserId = false;
|
|
1260
|
+
}
|
|
1248
1261
|
function extractRaindropMetadata(metadata) {
|
|
1249
1262
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1250
1263
|
const result = {};
|
|
@@ -1415,6 +1428,7 @@ function setupOperation(params) {
|
|
|
1415
1428
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
1416
1429
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1417
1430
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1431
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1418
1432
|
const eventId = (_c = (_b = (_a = callTimeCtx.eventId) != null ? _a : mergedCtx.eventId) != null ? _b : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1419
1433
|
const ctx = { ...mergedCtx, eventId };
|
|
1420
1434
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
@@ -1768,6 +1782,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1768
1782
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1769
1783
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1770
1784
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1785
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1771
1786
|
const inherited = await getCurrentParentSpanContext();
|
|
1772
1787
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1773
1788
|
const ctx = { ...mergedCtx};
|
|
@@ -1955,6 +1970,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1955
1970
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1956
1971
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1957
1972
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1973
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1958
1974
|
const inherited = await getCurrentParentSpanContext();
|
|
1959
1975
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1960
1976
|
const ctx = { ...mergedCtx};
|
|
@@ -2685,6 +2701,7 @@ function createRaindropAISDK(opts) {
|
|
|
2685
2701
|
// src/index.node.ts
|
|
2686
2702
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
2687
2703
|
|
|
2704
|
+
exports._resetWarnedMissingUserId = _resetWarnedMissingUserId;
|
|
2688
2705
|
exports.createRaindropAISDK = createRaindropAISDK;
|
|
2689
2706
|
exports.currentSpan = currentSpan;
|
|
2690
2707
|
exports.eventMetadata = eventMetadata;
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-6ICSE4FE.mjs';
|
|
2
2
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
3
|
|
|
4
4
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
|
package/dist/index.workers.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
|
|
1
|
+
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|
package/dist/index.workers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
|
|
1
|
+
export { AISDKMessage, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => {
|
package/dist/index.workers.js
CHANGED
|
@@ -90,7 +90,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
90
90
|
// package.json
|
|
91
91
|
var package_default = {
|
|
92
92
|
name: "@raindrop-ai/ai-sdk",
|
|
93
|
-
version: "0.0.
|
|
93
|
+
version: "0.0.7"};
|
|
94
94
|
|
|
95
95
|
// src/internal/version.ts
|
|
96
96
|
var libraryName = package_default.name;
|
|
@@ -276,19 +276,21 @@ var EventShipper = class {
|
|
|
276
276
|
}
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
|
+
const { wizardSession, ...restProperties } = (_e = accumulated.properties) != null ? _e : {};
|
|
279
280
|
const payload = {
|
|
280
281
|
event_id: eventId,
|
|
281
282
|
user_id: userId,
|
|
282
283
|
event: eventName,
|
|
283
|
-
timestamp: (
|
|
284
|
+
timestamp: (_f = accumulated.timestamp) != null ? _f : (/* @__PURE__ */ new Date()).toISOString(),
|
|
284
285
|
ai_data: {
|
|
285
286
|
input: accumulated.input,
|
|
286
287
|
output: accumulated.output,
|
|
287
288
|
model: accumulated.model,
|
|
288
|
-
convo_id: (
|
|
289
|
+
convo_id: (_g = accumulated.convoId) != null ? _g : sticky.convoId
|
|
289
290
|
},
|
|
290
291
|
properties: {
|
|
291
|
-
...
|
|
292
|
+
...restProperties,
|
|
293
|
+
...wizardSession ? { "raindrop.wizardSession": wizardSession } : {},
|
|
292
294
|
$context: this.context
|
|
293
295
|
},
|
|
294
296
|
attachments: accumulated.attachments,
|
|
@@ -1245,6 +1247,17 @@ function attrsFromGenAiRequest(options) {
|
|
|
1245
1247
|
}
|
|
1246
1248
|
|
|
1247
1249
|
// src/internal/wrap/wrapAISDK.ts
|
|
1250
|
+
var warnedMissingUserId = false;
|
|
1251
|
+
function warnMissingUserIdOnce() {
|
|
1252
|
+
if (warnedMissingUserId) return;
|
|
1253
|
+
warnedMissingUserId = true;
|
|
1254
|
+
console.warn(
|
|
1255
|
+
"[raindrop-ai/ai-sdk] userId was not provided in wrap() context or via eventMetadata(). Events will be skipped unless a userId is provided."
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
function _resetWarnedMissingUserId() {
|
|
1259
|
+
warnedMissingUserId = false;
|
|
1260
|
+
}
|
|
1248
1261
|
function extractRaindropMetadata(metadata) {
|
|
1249
1262
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1250
1263
|
const result = {};
|
|
@@ -1415,6 +1428,7 @@ function setupOperation(params) {
|
|
|
1415
1428
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
1416
1429
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1417
1430
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1431
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1418
1432
|
const eventId = (_c = (_b = (_a = callTimeCtx.eventId) != null ? _a : mergedCtx.eventId) != null ? _b : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1419
1433
|
const ctx = { ...mergedCtx, eventId };
|
|
1420
1434
|
const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
|
|
@@ -1768,6 +1782,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1768
1782
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1769
1783
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1770
1784
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1785
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1771
1786
|
const inherited = await getCurrentParentSpanContext();
|
|
1772
1787
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1773
1788
|
const ctx = { ...mergedCtx};
|
|
@@ -1955,6 +1970,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1955
1970
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1956
1971
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
1957
1972
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1973
|
+
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1958
1974
|
const inherited = await getCurrentParentSpanContext();
|
|
1959
1975
|
const eventId = (_c = (_b2 = (_a2 = callTimeCtx.eventId) != null ? _a2 : mergedCtx.eventId) != null ? _b2 : inherited == null ? void 0 : inherited.eventId) != null ? _c : randomUUID();
|
|
1960
1976
|
const ctx = { ...mergedCtx};
|
|
@@ -2687,6 +2703,7 @@ if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
|
|
2687
2703
|
globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
|
|
2688
2704
|
}
|
|
2689
2705
|
|
|
2706
|
+
exports._resetWarnedMissingUserId = _resetWarnedMissingUserId;
|
|
2690
2707
|
exports.createRaindropAISDK = createRaindropAISDK;
|
|
2691
2708
|
exports.currentSpan = currentSpan;
|
|
2692
2709
|
exports.eventMetadata = eventMetadata;
|
package/dist/index.workers.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-6ICSE4FE.mjs';
|
|
2
2
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
3
|
|
|
4
4
|
if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
package/package.json
CHANGED