@raindrop-ai/ai-sdk 0.0.1

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 ADDED
@@ -0,0 +1,132 @@
1
+ # `@raindrop-ai/ai-sdk`
2
+
3
+ Standalone Vercel AI SDK integration for Raindrop:
4
+
5
+ - **Events**: sends a `track_partial` payload to `POST /v1/events/track_partial` when the model finishes
6
+ - **Standalone traces**: ships spans directly to `POST /v1/traces` as **OTLP/HTTP JSON**
7
+ - **No OpenTelemetry SDK init**: avoids global OTEL registration conflicts
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ yarn add @raindrop-ai/ai-sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import * as ai from "ai";
19
+ import { createRaindropAISDK } from "@raindrop-ai/ai-sdk";
20
+
21
+ const raindrop = createRaindropAISDK({
22
+ writeKey: process.env.RAINDROP_WRITE_KEY!,
23
+ });
24
+
25
+ const { generateText } = raindrop.wrap(ai, {
26
+ context: { userId: "user_123", convoId: "convo_456", eventName: "chat_message" },
27
+ // optional: full control over event input/output, metadata, and attachments
28
+ buildEvent: (messages) => {
29
+ const lastUser = [...messages].reverse().find((m) => m.role === "user");
30
+ const lastAssistant = [...messages].reverse().find((m) => m.role === "assistant");
31
+ return {
32
+ input: typeof lastUser?.content === "string" ? lastUser.content : undefined,
33
+ output: typeof lastAssistant?.content === "string" ? lastAssistant.content : undefined,
34
+ };
35
+ },
36
+ });
37
+
38
+ const result = await generateText({
39
+ model: /* your AI SDK model */,
40
+ prompt: "Hello!",
41
+ });
42
+
43
+ await raindrop.flush();
44
+ ```
45
+
46
+ ## Runtime support
47
+
48
+ ### Node.js (recommended)
49
+
50
+ Use the default import:
51
+
52
+ ```ts
53
+ import { createRaindropAISDK } from "@raindrop-ai/ai-sdk";
54
+ ```
55
+
56
+ ### Cloudflare Workers
57
+
58
+ Cloudflare Workers can provide `AsyncLocalStorage` via `node:async_hooks` when `nodejs_compat` is enabled ([docs](https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/)).
59
+
60
+ Use the Workers entrypoint:
61
+
62
+ ```ts
63
+ import { createRaindropAISDK } from "@raindrop-ai/ai-sdk/workers";
64
+ ```
65
+
66
+ If `nodejs_compat` is not enabled, AsyncLocalStorage-based context propagation cannot work.
67
+
68
+ ## Supported AI SDK Versions
69
+
70
+ This package is tested against multiple Vercel AI SDK versions:
71
+
72
+ | Version | Status |
73
+ |---------|--------|
74
+ | v4.x | ✅ Supported |
75
+ | v5.x | ✅ Supported |
76
+ | v6.x | ✅ Supported |
77
+
78
+ ### Version Differences Handled
79
+
80
+ | Feature | v4 | v5 | v6 |
81
+ |---------|----|----|-----|
82
+ | `finishReason` | String (`"stop"`) | String (`"stop"`) | Object (`{ unified: "stop" }`) |
83
+ | `usage` tokens | `promptTokens`/`completionTokens` | `inputTokens`/`outputTokens` | `inputTokens`/`outputTokens` |
84
+ | `Output.object().responseFormat` | N/A | Plain object | Promise |
85
+
86
+ ## Testing
87
+
88
+ Tests are organized to verify compatibility across AI SDK versions:
89
+
90
+ ```
91
+ packages/ai-sdk/
92
+ ├── tests/
93
+ │ ├── v4/ # AI SDK v4 (pins ai@^4.1.17)
94
+ │ │ ├── ai-sdk.v4.test.ts
95
+ │ │ ├── wrapper.test.ts
96
+ │ │ └── http-payloads.test.ts
97
+ │ ├── v5/ # AI SDK v5 (pins ai@^5.0.0)
98
+ │ │ ├── ai-sdk.v5.test.ts
99
+ │ │ ├── wrapper.test.ts
100
+ │ │ └── http-payloads.test.ts
101
+ │ └── v6/ # AI SDK v6 (pins ai@^6.0.0)
102
+ │ ├── ai-sdk.v6.test.ts
103
+ │ ├── wrapper.test.ts
104
+ │ └── http-payloads.test.ts
105
+ ```
106
+
107
+ ### Running Tests
108
+
109
+ ```bash
110
+ # Run all version tests (requires OPENAI_API_KEY and RAINDROP_WRITE_KEY in .env)
111
+ yarn test
112
+
113
+ # Run specific version
114
+ yarn test:v4
115
+ yarn test:v5
116
+ yarn test:v6
117
+
118
+ # Quick smoke test (real LLM calls, single version)
119
+ yarn smoke:min
120
+ ```
121
+
122
+ ### Test Coverage
123
+
124
+ Each version runs:
125
+ - **Wrapper tests** - API shape, wrapper creation, tools passthrough
126
+ - **HTTP payload tests** - MSW-based payload validation for each spec version
127
+ - **Version-specific tests** - API differences (finishReason format, usage naming)
128
+
129
+ ## Notes
130
+
131
+ - Spans include `ai.telemetry.metadata.raindrop.eventId` for correlation, and **omit** `ai.telemetry.metadata.raindrop.userId` to prevent duplicate span→event creation server-side.
132
+