@raindrop-ai/ai-sdk 0.0.7 → 0.0.9
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/{chunk-6ICSE4FE.mjs → chunk-R5GGKTXI.mjs} +41 -20
- package/dist/index.d.mts +49 -3
- package/dist/index.d.ts +49 -3
- package/dist/index.js +41 -20
- 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 +41 -20
- 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 +41 -20
- package/dist/index.workers.mjs +1 -1
- package/package.json +4 -1
|
@@ -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.9"};
|
|
88
88
|
|
|
89
89
|
// src/internal/version.ts
|
|
90
90
|
var libraryName = package_default.name;
|
|
@@ -118,13 +118,15 @@ var EventShipper = class {
|
|
|
118
118
|
this.sticky = /* @__PURE__ */ new Map();
|
|
119
119
|
this.timers = /* @__PURE__ */ new Map();
|
|
120
120
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
121
|
-
var _a, _b;
|
|
122
|
-
if (!opts.writeKey)
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
var _a, _b, _c;
|
|
122
|
+
if (opts.enabled && !opts.writeKey) {
|
|
123
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
|
|
124
|
+
}
|
|
125
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
126
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
125
127
|
this.enabled = opts.enabled;
|
|
126
128
|
this.debug = opts.debug;
|
|
127
|
-
this.partialFlushMs = (
|
|
129
|
+
this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
|
|
128
130
|
this.context = getRuntimeContext();
|
|
129
131
|
}
|
|
130
132
|
isDebugEnabled() {
|
|
@@ -472,16 +474,18 @@ var TraceShipper = class {
|
|
|
472
474
|
constructor(opts) {
|
|
473
475
|
this.queue = [];
|
|
474
476
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
475
|
-
var _a, _b, _c, _d;
|
|
476
|
-
if (!opts.writeKey)
|
|
477
|
-
|
|
478
|
-
|
|
477
|
+
var _a, _b, _c, _d, _e;
|
|
478
|
+
if (opts.enabled && !opts.writeKey) {
|
|
479
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
|
|
480
|
+
}
|
|
481
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
482
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
479
483
|
this.enabled = opts.enabled;
|
|
480
484
|
this.debug = opts.debug;
|
|
481
485
|
this.debugSpans = opts.debugSpans === true;
|
|
482
|
-
this.flushIntervalMs = (
|
|
483
|
-
this.maxBatchSize = (
|
|
484
|
-
this.maxQueueSize = (
|
|
486
|
+
this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
|
|
487
|
+
this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
|
|
488
|
+
this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
|
|
485
489
|
}
|
|
486
490
|
isDebugEnabled() {
|
|
487
491
|
return this.debug;
|
|
@@ -1252,6 +1256,14 @@ function warnMissingUserIdOnce() {
|
|
|
1252
1256
|
function _resetWarnedMissingUserId() {
|
|
1253
1257
|
warnedMissingUserId = false;
|
|
1254
1258
|
}
|
|
1259
|
+
function extractRaindropCallOptions(options) {
|
|
1260
|
+
if (!isRecord(options)) return {};
|
|
1261
|
+
const em = options["metadata"];
|
|
1262
|
+
if (isRecord(em)) return extractRaindropMetadata(em);
|
|
1263
|
+
const telemetry = extractExperimentalTelemetry(options);
|
|
1264
|
+
if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
|
|
1265
|
+
return {};
|
|
1266
|
+
}
|
|
1255
1267
|
function extractRaindropMetadata(metadata) {
|
|
1256
1268
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1257
1269
|
const result = {};
|
|
@@ -1774,7 +1786,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1774
1786
|
const operation = `${className}.generate`;
|
|
1775
1787
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1776
1788
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1777
|
-
const callTimeCtx =
|
|
1789
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1778
1790
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1779
1791
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1780
1792
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -1962,7 +1974,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1962
1974
|
const operation = `${className}.stream`;
|
|
1963
1975
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1964
1976
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1965
|
-
const callTimeCtx =
|
|
1977
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1966
1978
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1967
1979
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1968
1980
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -2548,6 +2560,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
2548
2560
|
});
|
|
2549
2561
|
}
|
|
2550
2562
|
function resolveContext(context, info) {
|
|
2563
|
+
if (context === void 0) return {};
|
|
2551
2564
|
return typeof context === "function" ? context(info) : context;
|
|
2552
2565
|
}
|
|
2553
2566
|
function wrapOnFinish(args, onFinish) {
|
|
@@ -2631,18 +2644,26 @@ function envDebugEnabled() {
|
|
|
2631
2644
|
}
|
|
2632
2645
|
function createRaindropAISDK(opts) {
|
|
2633
2646
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2634
|
-
const
|
|
2635
|
-
const
|
|
2647
|
+
const writeKey = opts.writeKey;
|
|
2648
|
+
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
2649
|
+
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
2650
|
+
const eventsEnabled = eventsRequested && !!writeKey;
|
|
2651
|
+
const tracesEnabled = tracesRequested && !!writeKey;
|
|
2636
2652
|
const envDebug = envDebugEnabled();
|
|
2653
|
+
if (!writeKey && (eventsRequested || tracesRequested)) {
|
|
2654
|
+
console.warn(
|
|
2655
|
+
"[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
|
|
2656
|
+
);
|
|
2657
|
+
}
|
|
2637
2658
|
const eventShipper = new EventShipper({
|
|
2638
|
-
writeKey
|
|
2659
|
+
writeKey,
|
|
2639
2660
|
endpoint: opts.endpoint,
|
|
2640
2661
|
enabled: eventsEnabled,
|
|
2641
2662
|
debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
|
|
2642
2663
|
partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
|
|
2643
2664
|
});
|
|
2644
2665
|
const traceShipper = new TraceShipper({
|
|
2645
|
-
writeKey
|
|
2666
|
+
writeKey,
|
|
2646
2667
|
endpoint: opts.endpoint,
|
|
2647
2668
|
enabled: tracesEnabled,
|
|
2648
2669
|
debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
|
|
@@ -2654,7 +2675,7 @@ function createRaindropAISDK(opts) {
|
|
|
2654
2675
|
return {
|
|
2655
2676
|
wrap(aiSDK, options) {
|
|
2656
2677
|
return wrapAISDK(aiSDK, {
|
|
2657
|
-
options,
|
|
2678
|
+
options: options != null ? options : {},
|
|
2658
2679
|
eventShipper,
|
|
2659
2680
|
traceShipper
|
|
2660
2681
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -127,6 +127,48 @@ type EventMetadataOptions = {
|
|
|
127
127
|
* ```
|
|
128
128
|
*/
|
|
129
129
|
declare function eventMetadata(options: EventMetadataOptions): Record<string, string>;
|
|
130
|
+
type AgentCallMetadata = ReturnType<typeof eventMetadata>;
|
|
131
|
+
type NormalizeUnknownAgentOptions<T> = T extends {
|
|
132
|
+
options: infer CallOptions;
|
|
133
|
+
} ? unknown extends CallOptions ? Omit<T, "options"> & {
|
|
134
|
+
options?: never;
|
|
135
|
+
} : T : T;
|
|
136
|
+
/**
|
|
137
|
+
* Wraps an agent instance type so `generate()` and `stream()` accept optional
|
|
138
|
+
* Raindrop call metadata while preserving original return types.
|
|
139
|
+
*/
|
|
140
|
+
type AgentWithMetadata<A> = A extends {
|
|
141
|
+
generate: (...args: infer GenerateArgs) => infer GenerateReturn;
|
|
142
|
+
stream: (...args: infer StreamArgs) => infer StreamReturn;
|
|
143
|
+
} ? Omit<A, "generate" | "stream"> & {
|
|
144
|
+
generate(...args: GenerateArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
|
|
145
|
+
metadata?: AgentCallMetadata;
|
|
146
|
+
}, ...Rest] : GenerateArgs): GenerateReturn;
|
|
147
|
+
stream(...args: StreamArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
|
|
148
|
+
metadata?: AgentCallMetadata;
|
|
149
|
+
}, ...Rest] : StreamArgs): StreamReturn;
|
|
150
|
+
} : A;
|
|
151
|
+
/**
|
|
152
|
+
* Structural wrapper type for AI SDK modules.
|
|
153
|
+
*
|
|
154
|
+
* - AI SDK v6: rewrites `ToolLoopAgent` constructor instance methods to accept
|
|
155
|
+
* `metadata` on `generate/stream`.
|
|
156
|
+
* - AI SDK v4/v5: no `ToolLoopAgent` export, so the type is unchanged.
|
|
157
|
+
*/
|
|
158
|
+
type WrappedAISDK<T extends object> = T extends {
|
|
159
|
+
ToolLoopAgent: abstract new (...args: any[]) => any;
|
|
160
|
+
} ? Omit<T, "ToolLoopAgent"> & {
|
|
161
|
+
ToolLoopAgent: new (...args: ConstructorParameters<T["ToolLoopAgent"]>) => AgentWithMetadata<InstanceType<T["ToolLoopAgent"]>>;
|
|
162
|
+
} : T;
|
|
163
|
+
/**
|
|
164
|
+
* Backward-compatible alias for wrapped AI SDK module types.
|
|
165
|
+
*
|
|
166
|
+
* This alias intentionally avoids referencing `import("ai")` to satisfy type
|
|
167
|
+
* resolution without requiring `ai` to be installed.
|
|
168
|
+
*
|
|
169
|
+
* Prefer `WrappedAISDK<typeof ai>` in app code when you have an `ai` import.
|
|
170
|
+
*/
|
|
171
|
+
type WrappedAI<T extends object = any> = WrappedAISDK<T>;
|
|
130
172
|
type Attachment = {
|
|
131
173
|
attachment_id?: string;
|
|
132
174
|
name?: string;
|
|
@@ -139,7 +181,11 @@ type Attachment = {
|
|
|
139
181
|
type: "text" | "image" | "iframe";
|
|
140
182
|
});
|
|
141
183
|
type RaindropAISDKOptions = {
|
|
142
|
-
|
|
184
|
+
/**
|
|
185
|
+
* API write key. If omitted, telemetry shipping is disabled but `wrap()` is
|
|
186
|
+
* still available for a consistent integration surface.
|
|
187
|
+
*/
|
|
188
|
+
writeKey?: string;
|
|
143
189
|
endpoint?: string;
|
|
144
190
|
traces?: {
|
|
145
191
|
enabled?: boolean;
|
|
@@ -217,7 +263,7 @@ type EventPatch = {
|
|
|
217
263
|
timestamp?: string;
|
|
218
264
|
};
|
|
219
265
|
type RaindropAISDKClient = {
|
|
220
|
-
wrap<T extends object>(aiSDK: T, options
|
|
266
|
+
wrap<T extends object>(aiSDK: T, options?: WrapAISDKOptions): WrappedAISDK<T>;
|
|
221
267
|
events: {
|
|
222
268
|
patch(eventId: string, patch: EventPatch): Promise<void>;
|
|
223
269
|
addAttachments(eventId: string, attachments: Attachment[]): Promise<void>;
|
|
@@ -249,4 +295,4 @@ type RaindropAISDKClient = {
|
|
|
249
295
|
};
|
|
250
296
|
declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
|
|
251
297
|
|
|
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 };
|
|
298
|
+
export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
package/dist/index.d.ts
CHANGED
|
@@ -127,6 +127,48 @@ type EventMetadataOptions = {
|
|
|
127
127
|
* ```
|
|
128
128
|
*/
|
|
129
129
|
declare function eventMetadata(options: EventMetadataOptions): Record<string, string>;
|
|
130
|
+
type AgentCallMetadata = ReturnType<typeof eventMetadata>;
|
|
131
|
+
type NormalizeUnknownAgentOptions<T> = T extends {
|
|
132
|
+
options: infer CallOptions;
|
|
133
|
+
} ? unknown extends CallOptions ? Omit<T, "options"> & {
|
|
134
|
+
options?: never;
|
|
135
|
+
} : T : T;
|
|
136
|
+
/**
|
|
137
|
+
* Wraps an agent instance type so `generate()` and `stream()` accept optional
|
|
138
|
+
* Raindrop call metadata while preserving original return types.
|
|
139
|
+
*/
|
|
140
|
+
type AgentWithMetadata<A> = A extends {
|
|
141
|
+
generate: (...args: infer GenerateArgs) => infer GenerateReturn;
|
|
142
|
+
stream: (...args: infer StreamArgs) => infer StreamReturn;
|
|
143
|
+
} ? Omit<A, "generate" | "stream"> & {
|
|
144
|
+
generate(...args: GenerateArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
|
|
145
|
+
metadata?: AgentCallMetadata;
|
|
146
|
+
}, ...Rest] : GenerateArgs): GenerateReturn;
|
|
147
|
+
stream(...args: StreamArgs extends [infer Options, ...infer Rest] ? [NormalizeUnknownAgentOptions<Options> & {
|
|
148
|
+
metadata?: AgentCallMetadata;
|
|
149
|
+
}, ...Rest] : StreamArgs): StreamReturn;
|
|
150
|
+
} : A;
|
|
151
|
+
/**
|
|
152
|
+
* Structural wrapper type for AI SDK modules.
|
|
153
|
+
*
|
|
154
|
+
* - AI SDK v6: rewrites `ToolLoopAgent` constructor instance methods to accept
|
|
155
|
+
* `metadata` on `generate/stream`.
|
|
156
|
+
* - AI SDK v4/v5: no `ToolLoopAgent` export, so the type is unchanged.
|
|
157
|
+
*/
|
|
158
|
+
type WrappedAISDK<T extends object> = T extends {
|
|
159
|
+
ToolLoopAgent: abstract new (...args: any[]) => any;
|
|
160
|
+
} ? Omit<T, "ToolLoopAgent"> & {
|
|
161
|
+
ToolLoopAgent: new (...args: ConstructorParameters<T["ToolLoopAgent"]>) => AgentWithMetadata<InstanceType<T["ToolLoopAgent"]>>;
|
|
162
|
+
} : T;
|
|
163
|
+
/**
|
|
164
|
+
* Backward-compatible alias for wrapped AI SDK module types.
|
|
165
|
+
*
|
|
166
|
+
* This alias intentionally avoids referencing `import("ai")` to satisfy type
|
|
167
|
+
* resolution without requiring `ai` to be installed.
|
|
168
|
+
*
|
|
169
|
+
* Prefer `WrappedAISDK<typeof ai>` in app code when you have an `ai` import.
|
|
170
|
+
*/
|
|
171
|
+
type WrappedAI<T extends object = any> = WrappedAISDK<T>;
|
|
130
172
|
type Attachment = {
|
|
131
173
|
attachment_id?: string;
|
|
132
174
|
name?: string;
|
|
@@ -139,7 +181,11 @@ type Attachment = {
|
|
|
139
181
|
type: "text" | "image" | "iframe";
|
|
140
182
|
});
|
|
141
183
|
type RaindropAISDKOptions = {
|
|
142
|
-
|
|
184
|
+
/**
|
|
185
|
+
* API write key. If omitted, telemetry shipping is disabled but `wrap()` is
|
|
186
|
+
* still available for a consistent integration surface.
|
|
187
|
+
*/
|
|
188
|
+
writeKey?: string;
|
|
143
189
|
endpoint?: string;
|
|
144
190
|
traces?: {
|
|
145
191
|
enabled?: boolean;
|
|
@@ -217,7 +263,7 @@ type EventPatch = {
|
|
|
217
263
|
timestamp?: string;
|
|
218
264
|
};
|
|
219
265
|
type RaindropAISDKClient = {
|
|
220
|
-
wrap<T extends object>(aiSDK: T, options
|
|
266
|
+
wrap<T extends object>(aiSDK: T, options?: WrapAISDKOptions): WrappedAISDK<T>;
|
|
221
267
|
events: {
|
|
222
268
|
patch(eventId: string, patch: EventPatch): Promise<void>;
|
|
223
269
|
addAttachments(eventId: string, attachments: Attachment[]): Promise<void>;
|
|
@@ -249,4 +295,4 @@ type RaindropAISDKClient = {
|
|
|
249
295
|
};
|
|
250
296
|
declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
|
|
251
297
|
|
|
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 };
|
|
298
|
+
export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _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.9"};
|
|
90
90
|
|
|
91
91
|
// src/internal/version.ts
|
|
92
92
|
var libraryName = package_default.name;
|
|
@@ -120,13 +120,15 @@ var EventShipper = class {
|
|
|
120
120
|
this.sticky = /* @__PURE__ */ new Map();
|
|
121
121
|
this.timers = /* @__PURE__ */ new Map();
|
|
122
122
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
123
|
-
var _a, _b;
|
|
124
|
-
if (!opts.writeKey)
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
var _a, _b, _c;
|
|
124
|
+
if (opts.enabled && !opts.writeKey) {
|
|
125
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
|
|
126
|
+
}
|
|
127
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
128
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
127
129
|
this.enabled = opts.enabled;
|
|
128
130
|
this.debug = opts.debug;
|
|
129
|
-
this.partialFlushMs = (
|
|
131
|
+
this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
|
|
130
132
|
this.context = getRuntimeContext();
|
|
131
133
|
}
|
|
132
134
|
isDebugEnabled() {
|
|
@@ -474,16 +476,18 @@ var TraceShipper = class {
|
|
|
474
476
|
constructor(opts) {
|
|
475
477
|
this.queue = [];
|
|
476
478
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
477
|
-
var _a, _b, _c, _d;
|
|
478
|
-
if (!opts.writeKey)
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
var _a, _b, _c, _d, _e;
|
|
480
|
+
if (opts.enabled && !opts.writeKey) {
|
|
481
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
|
|
482
|
+
}
|
|
483
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
484
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
481
485
|
this.enabled = opts.enabled;
|
|
482
486
|
this.debug = opts.debug;
|
|
483
487
|
this.debugSpans = opts.debugSpans === true;
|
|
484
|
-
this.flushIntervalMs = (
|
|
485
|
-
this.maxBatchSize = (
|
|
486
|
-
this.maxQueueSize = (
|
|
488
|
+
this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
|
|
489
|
+
this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
|
|
490
|
+
this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
|
|
487
491
|
}
|
|
488
492
|
isDebugEnabled() {
|
|
489
493
|
return this.debug;
|
|
@@ -1254,6 +1258,14 @@ function warnMissingUserIdOnce() {
|
|
|
1254
1258
|
function _resetWarnedMissingUserId() {
|
|
1255
1259
|
warnedMissingUserId = false;
|
|
1256
1260
|
}
|
|
1261
|
+
function extractRaindropCallOptions(options) {
|
|
1262
|
+
if (!isRecord(options)) return {};
|
|
1263
|
+
const em = options["metadata"];
|
|
1264
|
+
if (isRecord(em)) return extractRaindropMetadata(em);
|
|
1265
|
+
const telemetry = extractExperimentalTelemetry(options);
|
|
1266
|
+
if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
|
|
1267
|
+
return {};
|
|
1268
|
+
}
|
|
1257
1269
|
function extractRaindropMetadata(metadata) {
|
|
1258
1270
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1259
1271
|
const result = {};
|
|
@@ -1776,7 +1788,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1776
1788
|
const operation = `${className}.generate`;
|
|
1777
1789
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1778
1790
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1779
|
-
const callTimeCtx =
|
|
1791
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1780
1792
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1781
1793
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1782
1794
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -1964,7 +1976,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1964
1976
|
const operation = `${className}.stream`;
|
|
1965
1977
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1966
1978
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1967
|
-
const callTimeCtx =
|
|
1979
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1968
1980
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1969
1981
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1970
1982
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -2550,6 +2562,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
2550
2562
|
});
|
|
2551
2563
|
}
|
|
2552
2564
|
function resolveContext(context, info) {
|
|
2565
|
+
if (context === void 0) return {};
|
|
2553
2566
|
return typeof context === "function" ? context(info) : context;
|
|
2554
2567
|
}
|
|
2555
2568
|
function wrapOnFinish(args, onFinish) {
|
|
@@ -2633,18 +2646,26 @@ function envDebugEnabled() {
|
|
|
2633
2646
|
}
|
|
2634
2647
|
function createRaindropAISDK(opts) {
|
|
2635
2648
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2636
|
-
const
|
|
2637
|
-
const
|
|
2649
|
+
const writeKey = opts.writeKey;
|
|
2650
|
+
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
2651
|
+
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
2652
|
+
const eventsEnabled = eventsRequested && !!writeKey;
|
|
2653
|
+
const tracesEnabled = tracesRequested && !!writeKey;
|
|
2638
2654
|
const envDebug = envDebugEnabled();
|
|
2655
|
+
if (!writeKey && (eventsRequested || tracesRequested)) {
|
|
2656
|
+
console.warn(
|
|
2657
|
+
"[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
|
|
2658
|
+
);
|
|
2659
|
+
}
|
|
2639
2660
|
const eventShipper = new EventShipper({
|
|
2640
|
-
writeKey
|
|
2661
|
+
writeKey,
|
|
2641
2662
|
endpoint: opts.endpoint,
|
|
2642
2663
|
enabled: eventsEnabled,
|
|
2643
2664
|
debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
|
|
2644
2665
|
partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
|
|
2645
2666
|
});
|
|
2646
2667
|
const traceShipper = new TraceShipper({
|
|
2647
|
-
writeKey
|
|
2668
|
+
writeKey,
|
|
2648
2669
|
endpoint: opts.endpoint,
|
|
2649
2670
|
enabled: tracesEnabled,
|
|
2650
2671
|
debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
|
|
@@ -2656,7 +2677,7 @@ function createRaindropAISDK(opts) {
|
|
|
2656
2677
|
return {
|
|
2657
2678
|
wrap(aiSDK, options) {
|
|
2658
2679
|
return wrapAISDK(aiSDK, {
|
|
2659
|
-
options,
|
|
2680
|
+
options: options != null ? options : {},
|
|
2660
2681
|
eventShipper,
|
|
2661
2682
|
traceShipper
|
|
2662
2683
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-R5GGKTXI.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, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
|
|
1
|
+
export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _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, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
|
|
1
|
+
export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _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.9"};
|
|
94
94
|
|
|
95
95
|
// src/internal/version.ts
|
|
96
96
|
var libraryName = package_default.name;
|
|
@@ -124,13 +124,15 @@ var EventShipper = class {
|
|
|
124
124
|
this.sticky = /* @__PURE__ */ new Map();
|
|
125
125
|
this.timers = /* @__PURE__ */ new Map();
|
|
126
126
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
127
|
-
var _a, _b;
|
|
128
|
-
if (!opts.writeKey)
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
if (opts.enabled && !opts.writeKey) {
|
|
129
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
|
|
130
|
+
}
|
|
131
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
132
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
131
133
|
this.enabled = opts.enabled;
|
|
132
134
|
this.debug = opts.debug;
|
|
133
|
-
this.partialFlushMs = (
|
|
135
|
+
this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
|
|
134
136
|
this.context = getRuntimeContext();
|
|
135
137
|
}
|
|
136
138
|
isDebugEnabled() {
|
|
@@ -478,16 +480,18 @@ var TraceShipper = class {
|
|
|
478
480
|
constructor(opts) {
|
|
479
481
|
this.queue = [];
|
|
480
482
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
481
|
-
var _a, _b, _c, _d;
|
|
482
|
-
if (!opts.writeKey)
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
var _a, _b, _c, _d, _e;
|
|
484
|
+
if (opts.enabled && !opts.writeKey) {
|
|
485
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
|
|
486
|
+
}
|
|
487
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
488
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
485
489
|
this.enabled = opts.enabled;
|
|
486
490
|
this.debug = opts.debug;
|
|
487
491
|
this.debugSpans = opts.debugSpans === true;
|
|
488
|
-
this.flushIntervalMs = (
|
|
489
|
-
this.maxBatchSize = (
|
|
490
|
-
this.maxQueueSize = (
|
|
492
|
+
this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
|
|
493
|
+
this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
|
|
494
|
+
this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
|
|
491
495
|
}
|
|
492
496
|
isDebugEnabled() {
|
|
493
497
|
return this.debug;
|
|
@@ -1258,6 +1262,14 @@ function warnMissingUserIdOnce() {
|
|
|
1258
1262
|
function _resetWarnedMissingUserId() {
|
|
1259
1263
|
warnedMissingUserId = false;
|
|
1260
1264
|
}
|
|
1265
|
+
function extractRaindropCallOptions(options) {
|
|
1266
|
+
if (!isRecord(options)) return {};
|
|
1267
|
+
const em = options["metadata"];
|
|
1268
|
+
if (isRecord(em)) return extractRaindropMetadata(em);
|
|
1269
|
+
const telemetry = extractExperimentalTelemetry(options);
|
|
1270
|
+
if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
|
|
1271
|
+
return {};
|
|
1272
|
+
}
|
|
1261
1273
|
function extractRaindropMetadata(metadata) {
|
|
1262
1274
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1263
1275
|
const result = {};
|
|
@@ -1780,7 +1792,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1780
1792
|
const operation = `${className}.generate`;
|
|
1781
1793
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1782
1794
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1783
|
-
const callTimeCtx =
|
|
1795
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1784
1796
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1785
1797
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1786
1798
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -1968,7 +1980,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1968
1980
|
const operation = `${className}.stream`;
|
|
1969
1981
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1970
1982
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1971
|
-
const callTimeCtx =
|
|
1983
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1972
1984
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1973
1985
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1974
1986
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -2554,6 +2566,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
2554
2566
|
});
|
|
2555
2567
|
}
|
|
2556
2568
|
function resolveContext(context, info) {
|
|
2569
|
+
if (context === void 0) return {};
|
|
2557
2570
|
return typeof context === "function" ? context(info) : context;
|
|
2558
2571
|
}
|
|
2559
2572
|
function wrapOnFinish(args, onFinish) {
|
|
@@ -2637,18 +2650,26 @@ function envDebugEnabled() {
|
|
|
2637
2650
|
}
|
|
2638
2651
|
function createRaindropAISDK(opts) {
|
|
2639
2652
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2640
|
-
const
|
|
2641
|
-
const
|
|
2653
|
+
const writeKey = opts.writeKey;
|
|
2654
|
+
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
2655
|
+
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
2656
|
+
const eventsEnabled = eventsRequested && !!writeKey;
|
|
2657
|
+
const tracesEnabled = tracesRequested && !!writeKey;
|
|
2642
2658
|
const envDebug = envDebugEnabled();
|
|
2659
|
+
if (!writeKey && (eventsRequested || tracesRequested)) {
|
|
2660
|
+
console.warn(
|
|
2661
|
+
"[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
|
|
2662
|
+
);
|
|
2663
|
+
}
|
|
2643
2664
|
const eventShipper = new EventShipper({
|
|
2644
|
-
writeKey
|
|
2665
|
+
writeKey,
|
|
2645
2666
|
endpoint: opts.endpoint,
|
|
2646
2667
|
enabled: eventsEnabled,
|
|
2647
2668
|
debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
|
|
2648
2669
|
partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
|
|
2649
2670
|
});
|
|
2650
2671
|
const traceShipper = new TraceShipper({
|
|
2651
|
-
writeKey
|
|
2672
|
+
writeKey,
|
|
2652
2673
|
endpoint: opts.endpoint,
|
|
2653
2674
|
enabled: tracesEnabled,
|
|
2654
2675
|
debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
|
|
@@ -2660,7 +2681,7 @@ function createRaindropAISDK(opts) {
|
|
|
2660
2681
|
return {
|
|
2661
2682
|
wrap(aiSDK, options) {
|
|
2662
2683
|
return wrapAISDK(aiSDK, {
|
|
2663
|
-
options,
|
|
2684
|
+
options: options != null ? options : {},
|
|
2664
2685
|
eventShipper,
|
|
2665
2686
|
traceShipper
|
|
2666
2687
|
});
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-R5GGKTXI.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, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.mjs';
|
|
1
|
+
export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _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, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './index.js';
|
|
1
|
+
export { AISDKMessage, AgentCallMetadata, AgentWithMetadata, Attachment, BuildEventPatch, ContextManager, ContextSpan, EventBuilder, EventMetadataOptions, IdentifyInput, RaindropAISDKClient, RaindropAISDKContext, RaindropAISDKOptions, WrapAISDKOptions, WrappedAI, WrappedAISDK, _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.9"};
|
|
94
94
|
|
|
95
95
|
// src/internal/version.ts
|
|
96
96
|
var libraryName = package_default.name;
|
|
@@ -124,13 +124,15 @@ var EventShipper = class {
|
|
|
124
124
|
this.sticky = /* @__PURE__ */ new Map();
|
|
125
125
|
this.timers = /* @__PURE__ */ new Map();
|
|
126
126
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
127
|
-
var _a, _b;
|
|
128
|
-
if (!opts.writeKey)
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
if (opts.enabled && !opts.writeKey) {
|
|
129
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when events are enabled");
|
|
130
|
+
}
|
|
131
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
132
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
131
133
|
this.enabled = opts.enabled;
|
|
132
134
|
this.debug = opts.debug;
|
|
133
|
-
this.partialFlushMs = (
|
|
135
|
+
this.partialFlushMs = (_c = opts.partialFlushMs) != null ? _c : 1e3;
|
|
134
136
|
this.context = getRuntimeContext();
|
|
135
137
|
}
|
|
136
138
|
isDebugEnabled() {
|
|
@@ -478,16 +480,18 @@ var TraceShipper = class {
|
|
|
478
480
|
constructor(opts) {
|
|
479
481
|
this.queue = [];
|
|
480
482
|
this.inFlight = /* @__PURE__ */ new Set();
|
|
481
|
-
var _a, _b, _c, _d;
|
|
482
|
-
if (!opts.writeKey)
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
var _a, _b, _c, _d, _e;
|
|
484
|
+
if (opts.enabled && !opts.writeKey) {
|
|
485
|
+
throw new Error("[raindrop-ai/ai-sdk] writeKey is required when traces are enabled");
|
|
486
|
+
}
|
|
487
|
+
this.writeKey = (_a = opts.writeKey) != null ? _a : "";
|
|
488
|
+
this.baseUrl = (_b = formatEndpoint(opts.endpoint)) != null ? _b : "https://api.raindrop.ai/v1/";
|
|
485
489
|
this.enabled = opts.enabled;
|
|
486
490
|
this.debug = opts.debug;
|
|
487
491
|
this.debugSpans = opts.debugSpans === true;
|
|
488
|
-
this.flushIntervalMs = (
|
|
489
|
-
this.maxBatchSize = (
|
|
490
|
-
this.maxQueueSize = (
|
|
492
|
+
this.flushIntervalMs = (_c = opts.flushIntervalMs) != null ? _c : 1e3;
|
|
493
|
+
this.maxBatchSize = (_d = opts.maxBatchSize) != null ? _d : 50;
|
|
494
|
+
this.maxQueueSize = (_e = opts.maxQueueSize) != null ? _e : 5e3;
|
|
491
495
|
}
|
|
492
496
|
isDebugEnabled() {
|
|
493
497
|
return this.debug;
|
|
@@ -1258,6 +1262,14 @@ function warnMissingUserIdOnce() {
|
|
|
1258
1262
|
function _resetWarnedMissingUserId() {
|
|
1259
1263
|
warnedMissingUserId = false;
|
|
1260
1264
|
}
|
|
1265
|
+
function extractRaindropCallOptions(options) {
|
|
1266
|
+
if (!isRecord(options)) return {};
|
|
1267
|
+
const em = options["metadata"];
|
|
1268
|
+
if (isRecord(em)) return extractRaindropMetadata(em);
|
|
1269
|
+
const telemetry = extractExperimentalTelemetry(options);
|
|
1270
|
+
if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
|
|
1271
|
+
return {};
|
|
1272
|
+
}
|
|
1261
1273
|
function extractRaindropMetadata(metadata) {
|
|
1262
1274
|
if (!metadata || typeof metadata !== "object") return {};
|
|
1263
1275
|
const result = {};
|
|
@@ -1780,7 +1792,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1780
1792
|
const operation = `${className}.generate`;
|
|
1781
1793
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1782
1794
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1783
|
-
const callTimeCtx =
|
|
1795
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1784
1796
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1785
1797
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1786
1798
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -1968,7 +1980,7 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
1968
1980
|
const operation = `${className}.stream`;
|
|
1969
1981
|
const wrapTimeCtx = resolveContext(deps.options.context, { operation, args: mergedArgs });
|
|
1970
1982
|
const telemetry = extractExperimentalTelemetry(mergedArgs);
|
|
1971
|
-
const callTimeCtx =
|
|
1983
|
+
const callTimeCtx = extractRaindropCallOptions(mergedArgs);
|
|
1972
1984
|
const mergedCtx = mergeContexts(wrapTimeCtx, callTimeCtx);
|
|
1973
1985
|
if (!mergedCtx.userId) warnMissingUserIdOnce();
|
|
1974
1986
|
const inherited = await getCurrentParentSpanContext();
|
|
@@ -2554,6 +2566,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
|
|
|
2554
2566
|
});
|
|
2555
2567
|
}
|
|
2556
2568
|
function resolveContext(context, info) {
|
|
2569
|
+
if (context === void 0) return {};
|
|
2557
2570
|
return typeof context === "function" ? context(info) : context;
|
|
2558
2571
|
}
|
|
2559
2572
|
function wrapOnFinish(args, onFinish) {
|
|
@@ -2637,18 +2650,26 @@ function envDebugEnabled() {
|
|
|
2637
2650
|
}
|
|
2638
2651
|
function createRaindropAISDK(opts) {
|
|
2639
2652
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2640
|
-
const
|
|
2641
|
-
const
|
|
2653
|
+
const writeKey = opts.writeKey;
|
|
2654
|
+
const eventsRequested = ((_a = opts.events) == null ? void 0 : _a.enabled) !== false;
|
|
2655
|
+
const tracesRequested = ((_b = opts.traces) == null ? void 0 : _b.enabled) !== false;
|
|
2656
|
+
const eventsEnabled = eventsRequested && !!writeKey;
|
|
2657
|
+
const tracesEnabled = tracesRequested && !!writeKey;
|
|
2642
2658
|
const envDebug = envDebugEnabled();
|
|
2659
|
+
if (!writeKey && (eventsRequested || tracesRequested)) {
|
|
2660
|
+
console.warn(
|
|
2661
|
+
"[raindrop-ai/ai-sdk] writeKey not provided; telemetry shipping is disabled"
|
|
2662
|
+
);
|
|
2663
|
+
}
|
|
2643
2664
|
const eventShipper = new EventShipper({
|
|
2644
|
-
writeKey
|
|
2665
|
+
writeKey,
|
|
2645
2666
|
endpoint: opts.endpoint,
|
|
2646
2667
|
enabled: eventsEnabled,
|
|
2647
2668
|
debug: ((_c = opts.events) == null ? void 0 : _c.debug) === true || envDebug,
|
|
2648
2669
|
partialFlushMs: (_d = opts.events) == null ? void 0 : _d.partialFlushMs
|
|
2649
2670
|
});
|
|
2650
2671
|
const traceShipper = new TraceShipper({
|
|
2651
|
-
writeKey
|
|
2672
|
+
writeKey,
|
|
2652
2673
|
endpoint: opts.endpoint,
|
|
2653
2674
|
enabled: tracesEnabled,
|
|
2654
2675
|
debug: ((_e = opts.traces) == null ? void 0 : _e.debug) === true || envDebug,
|
|
@@ -2660,7 +2681,7 @@ function createRaindropAISDK(opts) {
|
|
|
2660
2681
|
return {
|
|
2661
2682
|
wrap(aiSDK, options) {
|
|
2662
2683
|
return wrapAISDK(aiSDK, {
|
|
2663
|
-
options,
|
|
2684
|
+
options: options != null ? options : {},
|
|
2664
2685
|
eventShipper,
|
|
2665
2686
|
traceShipper
|
|
2666
2687
|
});
|
package/dist/index.workers.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-R5GGKTXI.mjs';
|
|
2
2
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
3
|
|
|
4
4
|
if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raindrop-ai/ai-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Standalone Vercel AI SDK integration for Raindrop (events + OTLP/HTTP JSON traces, no OTEL runtime)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
"tsx": "^4.20.3",
|
|
46
46
|
"typescript": "^5.3.3"
|
|
47
47
|
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"ai": ">=4 <7"
|
|
50
|
+
},
|
|
48
51
|
"tsup": {
|
|
49
52
|
"entry": [
|
|
50
53
|
"src/index.ts",
|