@raindrop-ai/ai-sdk 0.0.22 → 0.0.23

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 CHANGED
@@ -192,6 +192,135 @@ v7 additionally runs:
192
192
  - **E2E native telemetry** - Real AI SDK v7 with MSW-intercepted payloads
193
193
  - **Subagent nesting** - Span hierarchy for nested generateText inside tool execution
194
194
 
195
+ ## Manual Traces
196
+
197
+ Create trace spans manually alongside (or instead of) auto-instrumented ones. Useful for custom operations, DSL command extraction, or building trace trees for custom agent loops.
198
+
199
+ Spans share the same trace tree as auto-instrumented spans when you pass matching `eventId` values.
200
+
201
+ All three methods are available on every entrypoint (`.`, `./workers`, `./browser`).
202
+
203
+ ### One-shot spans
204
+
205
+ Use `createSpan` when the operation is already complete and you know the duration:
206
+
207
+ ```ts
208
+ raindrop.traces.createSpan({
209
+ name: "SET theme=dark",
210
+ eventId: "evt_123",
211
+ operationId: "ai.toolCall", // appears as a tool call in the dashboard
212
+ input: "SET theme=dark",
213
+ output: "OK",
214
+ durationMs: 12,
215
+ });
216
+
217
+ // Failed span
218
+ raindrop.traces.createSpan({
219
+ name: "SET layout=invalid",
220
+ eventId: "evt_123",
221
+ operationId: "ai.toolCall",
222
+ input: "SET layout=invalid",
223
+ error: "Invalid layout value",
224
+ durationMs: 8,
225
+ });
226
+ ```
227
+
228
+ ### Lifecycle spans
229
+
230
+ Use `startSpan` / `endSpan` to time an operation in real time:
231
+
232
+ ```ts
233
+ const span = raindrop.traces.startSpan({
234
+ name: "database_query",
235
+ eventId: "evt_123",
236
+ operationId: "ai.toolCall",
237
+ });
238
+
239
+ try {
240
+ const result = await db.query("SELECT ...");
241
+ raindrop.traces.endSpan(span);
242
+ } catch (err) {
243
+ raindrop.traces.endSpan(span, { error: err });
244
+ }
245
+ ```
246
+
247
+ ### Nested spans
248
+
249
+ Pass a span as `parent` to build a trace tree:
250
+
251
+ ```ts
252
+ const eventId = "evt_456";
253
+
254
+ const agentTurn = raindrop.traces.startSpan({ name: "agent_turn", eventId });
255
+
256
+ const subagent = raindrop.traces.startSpan({
257
+ name: "search_subagent",
258
+ eventId,
259
+ parent: agentTurn,
260
+ });
261
+
262
+ raindrop.traces.createSpan({
263
+ name: "grep_search",
264
+ eventId,
265
+ parent: subagent,
266
+ operationId: "ai.toolCall",
267
+ input: { pattern: "execute" },
268
+ output: { matches: 12 },
269
+ durationMs: 120,
270
+ });
271
+
272
+ raindrop.traces.endSpan(subagent);
273
+ raindrop.traces.endSpan(agentTurn);
274
+
275
+ await raindrop.flush();
276
+ ```
277
+
278
+ ### Mixing with auto-instrumented spans
279
+
280
+ Use the same `eventId` for both `wrap()` calls and manual spans — they appear in the same trace tree:
281
+
282
+ ```ts
283
+ const eventId = crypto.randomUUID();
284
+ const { generateText } = raindrop.wrap(ai, {
285
+ context: { userId: "user_123" },
286
+ });
287
+
288
+ await generateText({
289
+ model: openai("gpt-4o"),
290
+ prompt: "Analyze this data",
291
+ experimental_telemetry: {
292
+ isEnabled: true,
293
+ metadata: eventMetadata({ eventId }),
294
+ },
295
+ });
296
+
297
+ raindrop.traces.createSpan({
298
+ name: "post_processing",
299
+ eventId,
300
+ input: "raw",
301
+ output: "processed",
302
+ durationMs: 50,
303
+ });
304
+
305
+ await raindrop.flush();
306
+ ```
307
+
308
+ ### API reference
309
+
310
+ | Method | Description |
311
+ |--------|-------------|
312
+ | `raindrop.traces.createSpan(args)` | One-shot span with known duration |
313
+ | `raindrop.traces.startSpan(args)` | Start a span, returns a `TraceSpan` handle |
314
+ | `raindrop.traces.endSpan(span, extra?)` | Close a span opened with `startSpan` |
315
+
316
+ **`createSpan` args:** `name`, `eventId`, `operationId?`, `parent?`, `input?`, `output?`, `durationMs`, `error?`
317
+
318
+ **`startSpan` args:** `name`, `eventId`, `operationId?`, `parent?`
319
+
320
+ **`endSpan` extra:** `error?` (`Error | string`)
321
+
322
+ Set `operationId: "ai.toolCall"` to make spans appear as tool calls in the Raindrop dashboard.
323
+
195
324
  ## Notes
196
325
 
197
326
  - Spans include `ai.telemetry.metadata.raindrop.eventId` for correlation, and **omit** `ai.telemetry.metadata.raindrop.userId` to prevent duplicate span→event creation server-side.
@@ -4007,7 +4007,7 @@ function extractNestedTokens(usage, key) {
4007
4007
  // package.json
4008
4008
  var package_default = {
4009
4009
  name: "@raindrop-ai/ai-sdk",
4010
- version: "0.0.22"};
4010
+ version: "0.0.23"};
4011
4011
 
4012
4012
  // src/internal/version.ts
4013
4013
  var libraryName = package_default.name;
@@ -832,7 +832,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
832
832
  // package.json
833
833
  var package_default = {
834
834
  name: "@raindrop-ai/ai-sdk",
835
- version: "0.0.22"};
835
+ version: "0.0.23"};
836
836
 
837
837
  // src/internal/version.ts
838
838
  var libraryName = package_default.name;
@@ -830,7 +830,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
830
830
  // package.json
831
831
  var package_default = {
832
832
  name: "@raindrop-ai/ai-sdk",
833
- version: "0.0.22"};
833
+ version: "0.0.23"};
834
834
 
835
835
  // src/internal/version.ts
836
836
  var libraryName = package_default.name;
@@ -837,7 +837,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
837
837
  // package.json
838
838
  var package_default = {
839
839
  name: "@raindrop-ai/ai-sdk",
840
- version: "0.0.22"};
840
+ version: "0.0.23"};
841
841
 
842
842
  // src/internal/version.ts
843
843
  var libraryName = package_default.name;
@@ -1,4 +1,4 @@
1
- export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-7NLWLLB4.mjs';
1
+ export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-VQZMQSBQ.mjs';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
@@ -837,7 +837,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
837
837
  // package.json
838
838
  var package_default = {
839
839
  name: "@raindrop-ai/ai-sdk",
840
- version: "0.0.22"};
840
+ version: "0.0.23"};
841
841
 
842
842
  // src/internal/version.ts
843
843
  var libraryName = package_default.name;
@@ -1,4 +1,4 @@
1
- export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-7NLWLLB4.mjs';
1
+ export { RaindropTelemetryIntegration, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, eventMetadataFromChatRequest, getContextManager, withCurrent } from './chunk-VQZMQSBQ.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.22",
3
+ "version": "0.0.23",
4
4
  "description": "Standalone Vercel AI SDK integration for Raindrop (events + OTLP/HTTP JSON traces, no OTEL runtime)",
5
5
  "main": "dist/index.node.js",
6
6
  "module": "dist/index.node.mjs",