@raindrop-ai/wizard 0.0.3 → 0.0.4
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/src/docs/vercel-ai-sdk.mdx +52 -45
- package/package.json +1 -1
|
@@ -234,25 +234,26 @@ If you need full manual control over attachments, set `autoAttachment: false` in
|
|
|
234
234
|
`context` in `wrap()` is optional and useful for defaults. If both are
|
|
235
235
|
present, call-time `eventMetadata()` wins.
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
await generateText({
|
|
248
|
-
model,
|
|
249
|
-
prompt,
|
|
250
|
-
experimental_telemetry: {
|
|
251
|
-
isEnabled: true,
|
|
252
|
-
metadata: eventMetadata({ userId: actualUserId }),
|
|
237
|
+
```typescript
|
|
238
|
+
const { generateText } = raindrop.wrap(ai, {
|
|
239
|
+
context: {
|
|
240
|
+
userId, // Fallback defaults
|
|
241
|
+
properties: {
|
|
242
|
+
wizardSession: '__WIZARD_SESSION_UUID__', // REQUIRED
|
|
253
243
|
},
|
|
254
|
-
}
|
|
255
|
-
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await generateText({
|
|
248
|
+
model,
|
|
249
|
+
prompt,
|
|
250
|
+
experimental_telemetry: {
|
|
251
|
+
isEnabled: true,
|
|
252
|
+
metadata: eventMetadata({ userId: actualUserId }),
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
256
257
|
</Info>
|
|
257
258
|
|
|
258
259
|
---
|
|
@@ -431,14 +432,32 @@ const person = await result.object;
|
|
|
431
432
|
## ToolLoopAgent
|
|
432
433
|
|
|
433
434
|
<Info>Requires AI SDK v6 or later.</Info>
|
|
435
|
+
ToolLoopAgent is wrapped automatically. Both `generate()` and `stream()` trace tool
|
|
436
|
+
calls with their arguments and results. Pass per-call context via the top-level `metadata`
|
|
437
|
+
parameter.
|
|
438
|
+
|
|
439
|
+
### Typescript
|
|
440
|
+
|
|
441
|
+
`raindrop.wrap(ai)` changes the `ToolLoopAgent` method signatures to accept
|
|
442
|
+
top-level `metadata`, so typing against `ai.ToolLoopAgent` can cause TypeScript
|
|
443
|
+
errors. If you define your own agent type, wrap the AI SDK type with
|
|
444
|
+
`AgentWithMetadata` so `metadata` is still accepted on `generate()` and
|
|
445
|
+
`stream()`:
|
|
434
446
|
|
|
435
|
-
|
|
436
|
-
|
|
447
|
+
```typescript
|
|
448
|
+
import * as ai from 'ai';
|
|
449
|
+
import type { ToolSet } from 'ai';
|
|
450
|
+
import type { AgentWithMetadata } from '@raindrop-ai/ai-sdk';
|
|
451
|
+
|
|
452
|
+
export type YourToolLoopAgent = AgentWithMetadata<
|
|
453
|
+
ai.ToolLoopAgent<unknown, ToolSet, any>
|
|
454
|
+
>;
|
|
455
|
+
```
|
|
437
456
|
|
|
438
457
|
### generate
|
|
439
458
|
|
|
440
459
|
```typescript
|
|
441
|
-
import
|
|
460
|
+
import * as ai from 'ai';
|
|
442
461
|
import { openai } from '@ai-sdk/openai';
|
|
443
462
|
import { z } from 'zod';
|
|
444
463
|
import { createRaindropAISDK, eventMetadata } from '@raindrop-ai/ai-sdk';
|
|
@@ -447,15 +466,9 @@ const raindrop = createRaindropAISDK({
|
|
|
447
466
|
writeKey: process.env.RAINDROP_WRITE_KEY!,
|
|
448
467
|
});
|
|
449
468
|
|
|
450
|
-
const
|
|
451
|
-
context: {
|
|
452
|
-
properties: {
|
|
453
|
-
wizardSession: '__WIZARD_SESSION_UUID__', // REQUIRED
|
|
454
|
-
},
|
|
455
|
-
},
|
|
456
|
-
});
|
|
469
|
+
const wrapped = raindrop.wrap(ai);
|
|
457
470
|
|
|
458
|
-
const weatherTool = tool({
|
|
471
|
+
const weatherTool = ai.tool({
|
|
459
472
|
description: 'Get current weather',
|
|
460
473
|
parameters: z.object({ city: z.string() }),
|
|
461
474
|
execute: async ({ city }) => {
|
|
@@ -470,14 +483,11 @@ const agent = new ToolLoopAgent({
|
|
|
470
483
|
});
|
|
471
484
|
|
|
472
485
|
const result = await agent.generate({
|
|
473
|
-
prompt
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
eventName,
|
|
479
|
-
}),
|
|
480
|
-
},
|
|
486
|
+
prompt,
|
|
487
|
+
metadata: eventMetadata({
|
|
488
|
+
userId,
|
|
489
|
+
eventName,
|
|
490
|
+
}),
|
|
481
491
|
});
|
|
482
492
|
```
|
|
483
493
|
|
|
@@ -487,14 +497,11 @@ const result = await agent.generate({
|
|
|
487
497
|
import { eventMetadata } from '@raindrop-ai/ai-sdk';
|
|
488
498
|
|
|
489
499
|
const result = await agent.stream({
|
|
490
|
-
prompt
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
eventName,
|
|
496
|
-
}),
|
|
497
|
-
},
|
|
500
|
+
prompt,
|
|
501
|
+
metadata: eventMetadata({
|
|
502
|
+
userId,
|
|
503
|
+
eventName,
|
|
504
|
+
}),
|
|
498
505
|
});
|
|
499
506
|
|
|
500
507
|
for await (const chunk of result.textStream) {
|