@letterbook/ai-chat 0.1.0 → 0.1.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 +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -5
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ console.log(result.queued, result.evaluationAfterSeconds);
|
|
|
33
33
|
|
|
34
34
|
Set `LETTERBOOK_API_KEY`, or instantiate `new letterbook.Letterbook({ apiKey })` for explicit configuration.
|
|
35
35
|
Set `debounceSeconds` to control how long Letterbook waits after the last message before evaluating the conversation.
|
|
36
|
+
If OpenTelemetry is configured in your app, the SDK automatically propagates the active trace context with each capture request.
|
|
36
37
|
|
|
37
38
|
If `customerEmail` is omitted, the SDK looks for `properties.customer_email`, `properties.email`, or an email-shaped `userId`.
|
|
38
39
|
Email is only required if Letterbook promotes the capture to a ticket.
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface LetterbookOptions {
|
|
|
12
12
|
timeoutMs?: number;
|
|
13
13
|
raiseOnError?: boolean;
|
|
14
14
|
fetch?: typeof fetch;
|
|
15
|
+
otelEnabled?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export interface CaptureInput {
|
|
17
18
|
userId: string;
|
|
@@ -51,6 +52,7 @@ export declare class Letterbook {
|
|
|
51
52
|
private readonly timeoutMs;
|
|
52
53
|
private readonly raiseOnError;
|
|
53
54
|
private readonly fetchFn;
|
|
55
|
+
private readonly otelEnabled;
|
|
54
56
|
constructor(options?: LetterbookOptions);
|
|
55
57
|
capture(input: CaptureInput): Promise<CaptureResult>;
|
|
56
58
|
private postJson;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { context, propagation } from "@opentelemetry/api";
|
|
1
2
|
const DEFAULT_BASE_URL = "https://api.letterbook.ai/api";
|
|
2
3
|
export class LetterbookError extends Error {
|
|
3
4
|
constructor(message) {
|
|
@@ -11,12 +12,14 @@ export class Letterbook {
|
|
|
11
12
|
timeoutMs;
|
|
12
13
|
raiseOnError;
|
|
13
14
|
fetchFn;
|
|
15
|
+
otelEnabled;
|
|
14
16
|
constructor(options = {}) {
|
|
15
17
|
this.apiKey = options.apiKey ?? readEnv("LETTERBOOK_API_KEY");
|
|
16
18
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
17
19
|
this.timeoutMs = options.timeoutMs ?? 10_000;
|
|
18
20
|
this.raiseOnError = options.raiseOnError ?? false;
|
|
19
21
|
this.fetchFn = options.fetch ?? globalThis.fetch;
|
|
22
|
+
this.otelEnabled = options.otelEnabled ?? true;
|
|
20
23
|
if (!this.fetchFn) {
|
|
21
24
|
throw new LetterbookError("A fetch implementation is required.");
|
|
22
25
|
}
|
|
@@ -81,13 +84,17 @@ export class Letterbook {
|
|
|
81
84
|
const controller = new AbortController();
|
|
82
85
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
83
86
|
try {
|
|
87
|
+
const headers = {
|
|
88
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
89
|
+
"Content-Type": "application/json",
|
|
90
|
+
"User-Agent": "@letterbook/ai-chat/0.1.0",
|
|
91
|
+
};
|
|
92
|
+
if (this.otelEnabled) {
|
|
93
|
+
propagation.inject(context.active(), headers);
|
|
94
|
+
}
|
|
84
95
|
const response = await this.fetchFn(`${this.baseUrl}${path}`, {
|
|
85
96
|
method: "POST",
|
|
86
|
-
headers
|
|
87
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
88
|
-
"Content-Type": "application/json",
|
|
89
|
-
"User-Agent": "@letterbook/ai-chat/0.1.0",
|
|
90
|
-
},
|
|
97
|
+
headers,
|
|
91
98
|
body: JSON.stringify(payload),
|
|
92
99
|
signal: controller.signal,
|
|
93
100
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@letterbook/ai-chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "TypeScript SDK for capturing AI chat issues in Letterbook.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,5 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"typescript": "~5.8.3"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@opentelemetry/api": "^1.9.0"
|
|
35
38
|
}
|
|
36
39
|
}
|