@letterbook/ai-chat 0.1.1 → 1.0.0

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
@@ -1,11 +1,13 @@
1
1
  # Letterbook AI Chat TypeScript SDK
2
2
 
3
- Capture AI chat turns from your application so conversations can appear in the Letterbook platform when customers need help.
3
+ Send AI chat turns to Letterbook so customer issues can be detected from the full conversation.
4
+
5
+ Each call captures one turn in the conversation. It does not create a ticket by itself. Letterbook queues the turns, waits for the conversation to go quiet, scans the transcript on the backend with an LLM, and creates a ticket only when it finds a relevant customer issue.
4
6
 
5
7
  ```ts
6
8
  import * as letterbook from "@letterbook/ai-chat";
7
9
 
8
- const result = await letterbook.capture({
10
+ const result = await letterbook.recordTurn({
9
11
  userId: "user123",
10
12
  event: "user_message",
11
13
  model: "gpt_4",
@@ -37,3 +39,5 @@ If OpenTelemetry is configured in your app, the SDK automatically propagates the
37
39
 
38
40
  If `customerEmail` is omitted, the SDK looks for `properties.customer_email`, `properties.email`, or an email-shaped `userId`.
39
41
  Email is only required if Letterbook promotes the capture to a ticket.
42
+
43
+ `letterbook.captureTurn(...)` and `letterbook.capture(...)` are deprecated compatibility aliases for `letterbook.recordTurn(...)`.
package/dist/index.d.ts CHANGED
@@ -54,8 +54,24 @@ export declare class Letterbook {
54
54
  private readonly fetchFn;
55
55
  private readonly otelEnabled;
56
56
  constructor(options?: LetterbookOptions);
57
+ recordTurn(input: CaptureInput): Promise<CaptureResult>;
58
+ /**
59
+ * @deprecated Use recordTurn instead. captureTurn remains as a compatibility alias.
60
+ */
61
+ captureTurn(input: CaptureInput): Promise<CaptureResult>;
62
+ /**
63
+ * @deprecated Use recordTurn instead. capture remains as a compatibility alias.
64
+ */
57
65
  capture(input: CaptureInput): Promise<CaptureResult>;
58
66
  private postJson;
59
67
  private fail;
60
68
  }
69
+ /**
70
+ * @deprecated Use recordTurn instead. capture remains as a compatibility alias.
71
+ */
61
72
  export declare function capture(input: CaptureInput, options?: LetterbookOptions): Promise<CaptureResult>;
73
+ /**
74
+ * @deprecated Use recordTurn instead. captureTurn remains as a compatibility alias.
75
+ */
76
+ export declare function captureTurn(input: CaptureInput, options?: LetterbookOptions): Promise<CaptureResult>;
77
+ export declare function recordTurn(input: CaptureInput, options?: LetterbookOptions): Promise<CaptureResult>;
package/dist/index.js CHANGED
@@ -24,12 +24,12 @@ export class Letterbook {
24
24
  throw new LetterbookError("A fetch implementation is required.");
25
25
  }
26
26
  }
27
- async capture(input) {
27
+ async recordTurn(input) {
28
28
  if (input.input == null && input.output == null) {
29
- throw new LetterbookError("letterbook.capture requires at least one of input or output");
29
+ throw new LetterbookError("letterbook.recordTurn requires at least one of input or output");
30
30
  }
31
31
  if (input.debounceSeconds != null && input.debounceSeconds < 1) {
32
- throw new LetterbookError("letterbook.capture debounceSeconds must be at least 1");
32
+ throw new LetterbookError("letterbook.recordTurn debounceSeconds must be at least 1");
33
33
  }
34
34
  if (input.ticketEnabled === false) {
35
35
  return {
@@ -80,6 +80,18 @@ export class Letterbook {
80
80
  return this.fail(error instanceof Error ? error.message : String(error));
81
81
  }
82
82
  }
83
+ /**
84
+ * @deprecated Use recordTurn instead. captureTurn remains as a compatibility alias.
85
+ */
86
+ async captureTurn(input) {
87
+ return this.recordTurn(input);
88
+ }
89
+ /**
90
+ * @deprecated Use recordTurn instead. capture remains as a compatibility alias.
91
+ */
92
+ async capture(input) {
93
+ return this.recordTurn(input);
94
+ }
83
95
  async postJson(path, payload) {
84
96
  const controller = new AbortController();
85
97
  const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
@@ -87,7 +99,7 @@ export class Letterbook {
87
99
  const headers = {
88
100
  Authorization: `Bearer ${this.apiKey}`,
89
101
  "Content-Type": "application/json",
90
- "User-Agent": "@letterbook/ai-chat/0.1.0",
102
+ "User-Agent": "@letterbook/ai-chat/1.0.0",
91
103
  };
92
104
  if (this.otelEnabled) {
93
105
  propagation.inject(context.active(), headers);
@@ -119,8 +131,20 @@ export class Letterbook {
119
131
  };
120
132
  }
121
133
  }
134
+ /**
135
+ * @deprecated Use recordTurn instead. capture remains as a compatibility alias.
136
+ */
122
137
  export async function capture(input, options = {}) {
123
- return new Letterbook(options).capture(input);
138
+ return recordTurn(input, options);
139
+ }
140
+ /**
141
+ * @deprecated Use recordTurn instead. captureTurn remains as a compatibility alias.
142
+ */
143
+ export async function captureTurn(input, options = {}) {
144
+ return recordTurn(input, options);
145
+ }
146
+ export async function recordTurn(input, options = {}) {
147
+ return new Letterbook(options).recordTurn(input);
124
148
  }
125
149
  function normalizeAttachments(attachments) {
126
150
  return attachments.map((attachment) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@letterbook/ai-chat",
3
- "version": "0.1.1",
4
- "description": "TypeScript SDK for capturing AI chat issues in Letterbook.",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript SDK for sending AI chat turns to Letterbook for issue detection.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",