@breadcrumb-sdk/ai-sdk 0.0.2
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 +87 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @breadcrumb-sdk/ai-sdk
|
|
2
|
+
|
|
3
|
+
Trace Vercel AI SDK calls with Breadcrumb. Pass `experimental_telemetry` to any `generateText`, `streamText`, or `generateObject` call and it shows up in your dashboard automatically.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @breadcrumb-sdk/core @breadcrumb-sdk/ai-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { init } from "@breadcrumb-sdk/core";
|
|
15
|
+
import { initAiSdk } from "@breadcrumb-sdk/ai-sdk";
|
|
16
|
+
import { generateText } from "ai";
|
|
17
|
+
import { anthropic } from "@ai-sdk/anthropic";
|
|
18
|
+
|
|
19
|
+
const bc = init({ apiKey: "bc_...", baseUrl: "https://your-breadcrumb-instance.com" });
|
|
20
|
+
const { telemetry } = initAiSdk(bc);
|
|
21
|
+
|
|
22
|
+
const { text } = await generateText({
|
|
23
|
+
model: anthropic("claude-opus-4-6"),
|
|
24
|
+
prompt: "What is TypeScript?",
|
|
25
|
+
experimental_telemetry: telemetry("answer-question"),
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Each call with `telemetry()` shows up as its own trace in the dashboard. No other setup needed.
|
|
30
|
+
|
|
31
|
+
## Grouping calls into one trace
|
|
32
|
+
|
|
33
|
+
If you want multiple calls to appear under a single trace, wrap them in `bc.trace()`:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
await bc.trace("chat-request", async () => {
|
|
37
|
+
await generateText({ ..., experimental_telemetry: telemetry("plan") });
|
|
38
|
+
await generateText({ ..., experimental_telemetry: telemetry("respond") });
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
You can also mix in manual steps — for example a retrieval step that isn't an LLM call:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
await bc.trace("rag-pipeline", async () => {
|
|
46
|
+
const docs = await bc.span("retrieve", async (span) => {
|
|
47
|
+
span.set({ metadata: { source: "vector-db", top_k: 5 } });
|
|
48
|
+
return await vectorSearch(query);
|
|
49
|
+
}, { type: "retrieval" });
|
|
50
|
+
|
|
51
|
+
await generateText({
|
|
52
|
+
model,
|
|
53
|
+
prompt: `Context: ${docs.join("\n")}\n\nQuestion: ${query}`,
|
|
54
|
+
experimental_telemetry: telemetry("generate"),
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
### `initAiSdk(bc)`
|
|
62
|
+
|
|
63
|
+
Takes your `bc` instance and returns the `telemetry` helper. Call once after `init()`.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const { telemetry } = initAiSdk(bc);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
### `telemetry(functionId, metadata?)`
|
|
72
|
+
|
|
73
|
+
Returns the config to pass to `experimental_telemetry`.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
experimental_telemetry: telemetry("my-step")
|
|
77
|
+
experimental_telemetry: telemetry("my-step", { userId: "u_123", temperature: 0.7 })
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
| Parameter | Type | Description |
|
|
81
|
+
|-----------|------|-------------|
|
|
82
|
+
| `functionId` | `string` | Name shown in the trace UI |
|
|
83
|
+
| `metadata` | `Record<string, string \| number \| boolean \| ...[]>` | Extra data attached to the span |
|
|
84
|
+
|
|
85
|
+
## Compatibility
|
|
86
|
+
|
|
87
|
+
Works with AI SDK 5 and AI SDK 6.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Integrates Breadcrumb with the Vercel AI SDK (v5 and v6).
|
|
6
|
+
*
|
|
7
|
+
* The AI SDK emits OpenTelemetry spans automatically when
|
|
8
|
+
* experimental_telemetry is enabled. Because init() registers the OTel
|
|
9
|
+
* provider globally, those spans flow through the BreadcrumbSpanExporter
|
|
10
|
+
* without any additional configuration.
|
|
11
|
+
*
|
|
12
|
+
* A single AI SDK call with no active trace() context becomes its own root
|
|
13
|
+
* trace automatically — no wrapping needed.
|
|
14
|
+
*/
|
|
15
|
+
function initAiSdk(_bc) {
|
|
16
|
+
const telemetry = (functionId, metadata) => ({
|
|
17
|
+
isEnabled: true,
|
|
18
|
+
functionId,
|
|
19
|
+
...metadata !== void 0 ? { metadata } : {}
|
|
20
|
+
});
|
|
21
|
+
return { telemetry };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.initAiSdk = initAiSdk
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Breadcrumb } from "@breadcrumb-sdk/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type AttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
5
|
+
type TelemetryFn = (functionId: string, metadata?: Record<string, AttributeValue>) => {
|
|
6
|
+
isEnabled: true;
|
|
7
|
+
functionId: string;
|
|
8
|
+
metadata?: Record<string, AttributeValue>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Integrates Breadcrumb with the Vercel AI SDK (v5 and v6).
|
|
12
|
+
*
|
|
13
|
+
* The AI SDK emits OpenTelemetry spans automatically when
|
|
14
|
+
* experimental_telemetry is enabled. Because init() registers the OTel
|
|
15
|
+
* provider globally, those spans flow through the BreadcrumbSpanExporter
|
|
16
|
+
* without any additional configuration.
|
|
17
|
+
*
|
|
18
|
+
* A single AI SDK call with no active trace() context becomes its own root
|
|
19
|
+
* trace automatically — no wrapping needed.
|
|
20
|
+
*/
|
|
21
|
+
declare function initAiSdk(_bc: Breadcrumb): {
|
|
22
|
+
telemetry: TelemetryFn;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
27
|
+
|
|
28
|
+
export { Breadcrumb, TelemetryFn, initAiSdk };
|
|
29
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":null,"mappings":";;;KAKK,cAAA;AAAA,KAQO,WAAA,GARO,CAAA,UAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAUN,MAVM,CAAA,MAAA,EAUS,cAVT,CAAA,EAAA,GAAA;EAQP,SAAA,EAAA,IAAW;EAAA,UAAA,EAAA,MAAA;EAAA,QAEK,CAAA,EAIf,MAJe,CAAA,MAAA,EAIA,cAJA,CAAA;CAAc;;;AAIvB;;;;;;;;;iBAcH,SAAA,MAAe;aAA0B;;;;AAAzD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Breadcrumb } from "@breadcrumb-sdk/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type AttributeValue = string | number | boolean | string[] | number[] | boolean[];
|
|
5
|
+
type TelemetryFn = (functionId: string, metadata?: Record<string, AttributeValue>) => {
|
|
6
|
+
isEnabled: true;
|
|
7
|
+
functionId: string;
|
|
8
|
+
metadata?: Record<string, AttributeValue>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Integrates Breadcrumb with the Vercel AI SDK (v5 and v6).
|
|
12
|
+
*
|
|
13
|
+
* The AI SDK emits OpenTelemetry spans automatically when
|
|
14
|
+
* experimental_telemetry is enabled. Because init() registers the OTel
|
|
15
|
+
* provider globally, those spans flow through the BreadcrumbSpanExporter
|
|
16
|
+
* without any additional configuration.
|
|
17
|
+
*
|
|
18
|
+
* A single AI SDK call with no active trace() context becomes its own root
|
|
19
|
+
* trace automatically — no wrapping needed.
|
|
20
|
+
*/
|
|
21
|
+
declare function initAiSdk(_bc: Breadcrumb): {
|
|
22
|
+
telemetry: TelemetryFn;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
27
|
+
|
|
28
|
+
export { Breadcrumb, TelemetryFn, initAiSdk };
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":null,"mappings":";;;KAKK,cAAA;AAAA,KAQO,WAAA,GARO,CAAA,UAAA,EAAA,MAAA,EAAA,QAAA,CAAA,EAUN,MAVM,CAAA,MAAA,EAUS,cAVT,CAAA,EAAA,GAAA;EAQP,SAAA,EAAA,IAAW;EAAA,UAAA,EAAA,MAAA;EAAA,QAEK,CAAA,EAIf,MAJe,CAAA,MAAA,EAIA,cAJA,CAAA;CAAc;;;AAIvB;;;;;;;;;iBAcH,SAAA,MAAe;aAA0B;;;;AAAzD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Integrates Breadcrumb with the Vercel AI SDK (v5 and v6).
|
|
4
|
+
*
|
|
5
|
+
* The AI SDK emits OpenTelemetry spans automatically when
|
|
6
|
+
* experimental_telemetry is enabled. Because init() registers the OTel
|
|
7
|
+
* provider globally, those spans flow through the BreadcrumbSpanExporter
|
|
8
|
+
* without any additional configuration.
|
|
9
|
+
*
|
|
10
|
+
* A single AI SDK call with no active trace() context becomes its own root
|
|
11
|
+
* trace automatically — no wrapping needed.
|
|
12
|
+
*/
|
|
13
|
+
function initAiSdk(_bc) {
|
|
14
|
+
const telemetry = (functionId, metadata) => ({
|
|
15
|
+
isEnabled: true,
|
|
16
|
+
functionId,
|
|
17
|
+
...metadata !== void 0 ? { metadata } : {}
|
|
18
|
+
});
|
|
19
|
+
return { telemetry };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { initAiSdk };
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_bc: Breadcrumb","telemetry: TelemetryFn"],"sources":["../src/index.ts"],"sourcesContent":["import type { Breadcrumb } from \"@breadcrumb-sdk/core\";\n\nexport type { Breadcrumb };\n\n// OTel AttributeValue — what the AI SDK's experimental_telemetry.metadata accepts\ntype AttributeValue =\n | string\n | number\n | boolean\n | string[]\n | number[]\n | boolean[];\n\nexport type TelemetryFn = (\n functionId: string,\n metadata?: Record<string, AttributeValue>,\n) => {\n isEnabled: true;\n functionId: string;\n metadata?: Record<string, AttributeValue>;\n};\n\n/**\n * Integrates Breadcrumb with the Vercel AI SDK (v5 and v6).\n *\n * The AI SDK emits OpenTelemetry spans automatically when\n * experimental_telemetry is enabled. Because init() registers the OTel\n * provider globally, those spans flow through the BreadcrumbSpanExporter\n * without any additional configuration.\n *\n * A single AI SDK call with no active trace() context becomes its own root\n * trace automatically — no wrapping needed.\n */\nexport function initAiSdk(_bc: Breadcrumb): { telemetry: TelemetryFn } {\n const telemetry: TelemetryFn = (functionId, metadata) => ({\n isEnabled: true,\n functionId,\n ...(metadata !== undefined ? { metadata } : {}),\n });\n\n return { telemetry };\n}\n"],"mappings":";;;;;;;;;;;;AAiCA,SAAgB,UAAUA,KAA6C;CACrE,MAAMC,YAAyB,CAAC,YAAY,cAAc;EACxD,WAAW;EACX;EACA,GAAI,sBAAyB,EAAE,SAAU,IAAG,CAAE;CAC/C;AAED,QAAO,EAAE,UAAW;AACrB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@breadcrumb-sdk/ai-sdk",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsdown",
|
|
20
|
+
"dev": "tsdown --watch",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "vitest run"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@breadcrumb-sdk/core": "*"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@breadcrumb-sdk/core": "*",
|
|
29
|
+
"tsdown": "^0.9",
|
|
30
|
+
"typescript": "^5.7",
|
|
31
|
+
"vitest": "^3"
|
|
32
|
+
}
|
|
33
|
+
}
|