@brizz/sdk 0.1.15 → 0.1.16

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
@@ -288,6 +288,7 @@ const result = await startSession(
288
288
  - `session.updateProperties({ key: value })` - Add custom properties to the session span
289
289
  - `session.setInput(text)` - (Optional) Manually track input text
290
290
  - `session.setOutput(text)` - (Optional) Manually track output text
291
+ - `session.setTitle(text)` - Set a session title (typically used with `mode: 'title'`)
291
292
 
292
293
  **When to use manual input/output tracking:**
293
294
 
@@ -313,6 +314,38 @@ await startSession('session-456', async (session) => {
313
314
  });
314
315
  ```
315
316
 
317
+ ### Session Title Generation
318
+
319
+ If you use an LLM call to generate session titles, wrap it so those spans don't appear as part of the conversation:
320
+
321
+ ```typescript
322
+ import { startSession, startSessionTitle } from '@brizz/sdk';
323
+
324
+ await startSession('session-123', async (session) => {
325
+ const response = await openai.chat.completions.create({...});
326
+
327
+ // Title generation — excluded from conversation view
328
+ await startSessionTitle(async (title) => {
329
+ const t = await openai.chat.completions.create({
330
+ model: 'gpt-4',
331
+ messages: [{ role: 'user', content: 'Summarize this chat in 3 words' }],
332
+ });
333
+ title.setTitle(t.choices[0].message.content);
334
+ });
335
+ });
336
+
337
+ // Or use mode: 'title' on startSession directly
338
+ await startSession('session-123', async (session) => {
339
+ const t = await openai.chat.completions.create({...});
340
+ session.setTitle(t.choices[0].message.content);
341
+ }, undefined, { mode: 'title' });
342
+
343
+ // Or use startSessionTitle outside a session (pass sessionId explicitly)
344
+ await startSessionTitle(async (title) => {
345
+ title.setTitle('My Title');
346
+ }, { sessionId: 'session-123' });
347
+ ```
348
+
316
349
  ### Accessing the Active Session
317
350
 
318
351
  Use `getActiveSession()` to retrieve the current session from anywhere within a `startSession` scope — no need to pass the session object through your call stack:
package/dist/index.cjs CHANGED
@@ -34,6 +34,7 @@ __export(src_exports, {
34
34
  DEFAULT_PII_PATTERNS: () => DEFAULT_PII_PATTERNS,
35
35
  LogLevel: () => LogLevel,
36
36
  Session: () => Session,
37
+ SessionTitle: () => SessionTitle,
37
38
  SeverityNumber: () => import_api_logs2.SeverityNumber,
38
39
  callWithProperties: () => callWithProperties,
39
40
  callWithSessionId: () => callWithSessionId,
@@ -51,6 +52,7 @@ __export(src_exports, {
51
52
  maskValue: () => maskValue,
52
53
  setLogLevel: () => setLogLevel,
53
54
  startSession: () => startSession,
55
+ startSessionTitle: () => startSessionTitle,
54
56
  withProperties: () => withProperties,
55
57
  withSessionId: () => withSessionId
56
58
  });
@@ -494,7 +496,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
494
496
 
495
497
  // src/internal/version.ts
496
498
  function getSDKVersion() {
497
- return "0.1.15";
499
+ return "0.1.16";
498
500
  }
499
501
 
500
502
  // src/internal/log/processors/log-processor.ts
@@ -1135,6 +1137,9 @@ var SESSION_OBJECT_CONTEXT_KEY = (0, import_api2.createContextKey)("brizz.sessio
1135
1137
  var SESSION_INPUT = "brizz.session.input";
1136
1138
  var SESSION_OUTPUT = "brizz.session.output";
1137
1139
  var SESSION_SPAN_NAME = "brizz.start_session";
1140
+ var SESSION_TITLE_SPAN_NAME = "brizz.session_title";
1141
+ var SESSION_TITLE_GENERATION = "session.title_generation";
1142
+ var SESSION_TITLE = "brizz.session.title";
1138
1143
 
1139
1144
  // src/internal/log/processors/log-processor.ts
1140
1145
  var DEFAULT_LOG_MASKING_RULES = [
@@ -1781,6 +1786,14 @@ var Session = class {
1781
1786
  this.outputs.push(text);
1782
1787
  this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1783
1788
  }
1789
+ /**
1790
+ * Set the session title on the span.
1791
+ *
1792
+ * @param title - The generated title string
1793
+ */
1794
+ setTitle(title) {
1795
+ this.span.setAttribute(SESSION_TITLE, title);
1796
+ }
1784
1797
  /**
1785
1798
  * Update custom properties on the session span.
1786
1799
  * Properties are prefixed with 'brizz.'.
@@ -1793,12 +1806,28 @@ var Session = class {
1793
1806
  }
1794
1807
  }
1795
1808
  };
1809
+ var SessionTitle = class {
1810
+ span;
1811
+ constructor(span) {
1812
+ this.span = span;
1813
+ }
1814
+ /**
1815
+ * Set the generated title on the wrapper span.
1816
+ *
1817
+ * @param title - The generated title string
1818
+ */
1819
+ setTitle(title) {
1820
+ this.span.setAttribute(SESSION_TITLE, title);
1821
+ }
1822
+ };
1796
1823
  function getActiveSession() {
1797
1824
  return import_api5.context.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
1798
1825
  }
1799
- function startSession(sessionId, callback, extraProperties) {
1826
+ function startSession(sessionId, callback, extraProperties, options) {
1827
+ const isTitle = options?.mode === "title";
1828
+ const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
1800
1829
  const tracer = import_api5.trace.getTracer("@brizz/sdk");
1801
- return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
1830
+ return tracer.startActiveSpan(spanName, (span) => {
1802
1831
  span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
1803
1832
  if (extraProperties) {
1804
1833
  for (const [key, value] of Object.entries(extraProperties)) {
@@ -1807,6 +1836,9 @@ function startSession(sessionId, callback, extraProperties) {
1807
1836
  }
1808
1837
  const session = new Session(sessionId, span);
1809
1838
  const contextProperties = { [SESSION_ID]: sessionId };
1839
+ if (isTitle) {
1840
+ contextProperties[SESSION_TITLE_GENERATION] = "true";
1841
+ }
1810
1842
  if (extraProperties) {
1811
1843
  for (const [key, value] of Object.entries(extraProperties)) {
1812
1844
  contextProperties[key] = String(value);
@@ -1840,6 +1872,43 @@ function startSession(sessionId, callback, extraProperties) {
1840
1872
  });
1841
1873
  });
1842
1874
  }
1875
+ function startSessionTitle(callback, options) {
1876
+ const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
1877
+ const tracer = import_api5.trace.getTracer("@brizz/sdk");
1878
+ return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
1879
+ if (resolvedSessionId) {
1880
+ span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
1881
+ }
1882
+ const sessionTitle = new SessionTitle(span);
1883
+ const properties = { [SESSION_TITLE_GENERATION]: "true" };
1884
+ if (resolvedSessionId) {
1885
+ properties[SESSION_ID] = resolvedSessionId;
1886
+ }
1887
+ return callWithProperties(properties, () => {
1888
+ try {
1889
+ const result = callback(sessionTitle);
1890
+ if (result && typeof result.then === "function") {
1891
+ return result.then((value) => {
1892
+ span.end();
1893
+ return value;
1894
+ }).catch((error) => {
1895
+ span.recordException(error);
1896
+ span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
1897
+ span.end();
1898
+ throw error;
1899
+ });
1900
+ }
1901
+ span.end();
1902
+ return result;
1903
+ } catch (error) {
1904
+ span.recordException(error);
1905
+ span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
1906
+ span.end();
1907
+ throw error;
1908
+ }
1909
+ });
1910
+ });
1911
+ }
1843
1912
 
1844
1913
  // src/internal/sdk.ts
1845
1914
  var _Brizz = class __Brizz {
@@ -2091,6 +2160,7 @@ var init_exports = {};
2091
2160
  DEFAULT_PII_PATTERNS,
2092
2161
  LogLevel,
2093
2162
  Session,
2163
+ SessionTitle,
2094
2164
  SeverityNumber,
2095
2165
  callWithProperties,
2096
2166
  callWithSessionId,
@@ -2108,6 +2178,7 @@ var init_exports = {};
2108
2178
  maskValue,
2109
2179
  setLogLevel,
2110
2180
  startSession,
2181
+ startSessionTitle,
2111
2182
  withProperties,
2112
2183
  withSessionId
2113
2184
  });