@brizz/sdk 0.1.18 → 0.1.20

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
@@ -287,10 +287,23 @@ const result = await startSession(
287
287
 
288
288
  **Session Methods:**
289
289
  - `session.updateProperties({ key: value })` - Add custom properties to the session span
290
- - `session.setInput(text)` - (Optional) Manually track input text
291
- - `session.setOutput(text)` - (Optional) Manually track output text
290
+ - `session.setInput(text, context?)` - (Optional) Manually track input text; optional context bag attaches per-turn metadata rendered in the dashboard's Context panel
291
+ - `session.setOutput(text, context?)` - (Optional) Manually track output text; optional context bag attaches per-turn metadata rendered in the dashboard's Context panel
292
292
  - `session.setTitle(text)` - Set a session title (typically used with `mode: 'title'`)
293
293
 
294
+ **Per-turn context example:**
295
+
296
+ ```typescript
297
+ await startSession('session-123', async (session) => {
298
+ session.setInput('Why is my bill high?', { selected_invoice: 'INV-9182' });
299
+ const response = await openai.chat.completions.create({ ... });
300
+ session.setOutput(response.choices[0].message.content, {
301
+ message_id: 'msg-42',
302
+ sources: ['doc-abc'],
303
+ });
304
+ });
305
+ ```
306
+
294
307
  **When to use manual input/output tracking:**
295
308
 
296
309
  In most cases, Brizz automatically captures inputs and outputs from your LLM calls. Use `setInput`/`setOutput` for special scenarios:
package/dist/index.cjs CHANGED
@@ -505,7 +505,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
505
505
 
506
506
  // src/internal/version.ts
507
507
  function getSDKVersion() {
508
- return "0.1.18";
508
+ return "0.1.20";
509
509
  }
510
510
 
511
511
  // src/internal/log/processors/log-processor.ts
@@ -1145,6 +1145,8 @@ var PROPERTIES_CONTEXT_KEY = (0, import_api2.createContextKey)(PROPERTIES);
1145
1145
  var SESSION_OBJECT_CONTEXT_KEY = (0, import_api2.createContextKey)("brizz.session.object");
1146
1146
  var SESSION_INPUT = "brizz.session.input";
1147
1147
  var SESSION_OUTPUT = "brizz.session.output";
1148
+ var SESSION_INPUT_CONTEXT = "brizz.session.input.context";
1149
+ var SESSION_OUTPUT_CONTEXT = "brizz.session.output.context";
1148
1150
  var SESSION_SPAN_NAME = "brizz.start_session";
1149
1151
  var SESSION_TITLE_SPAN_NAME = "brizz.session_title";
1150
1152
  var SESSION_TITLE_GENERATION = "session.title_generation";
@@ -1584,6 +1586,14 @@ var BrizzSpanExporter = class {
1584
1586
  // src/internal/trace/processors/span-processor.ts
1585
1587
  var import_api4 = require("@opentelemetry/api");
1586
1588
  var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
1589
+ function applyContextAttributes(span) {
1590
+ const sessionProperties = import_api4.context.active().getValue(PROPERTIES_CONTEXT_KEY);
1591
+ if (sessionProperties) {
1592
+ for (const [key, value] of Object.entries(sessionProperties)) {
1593
+ span.setAttribute(`${BRIZZ}.${key}`, value);
1594
+ }
1595
+ }
1596
+ }
1587
1597
  var DEFAULT_MASKING_RULES = [
1588
1598
  {
1589
1599
  mode: "partial",
@@ -1618,12 +1628,7 @@ var BrizzSimpleSpanProcessor = class extends import_sdk_trace_base.SimpleSpanPro
1618
1628
  if (maskingConfig) {
1619
1629
  maskSpan(span, maskingConfig);
1620
1630
  }
1621
- const associationProperties = import_api4.context.active().getValue(PROPERTIES_CONTEXT_KEY);
1622
- if (associationProperties) {
1623
- for (const [key, value] of Object.entries(associationProperties)) {
1624
- span.setAttribute(`${BRIZZ}.${key}`, value);
1625
- }
1626
- }
1631
+ applyContextAttributes(span);
1627
1632
  super.onStart(span, parentContext);
1628
1633
  }
1629
1634
  };
@@ -1638,12 +1643,7 @@ var BrizzBatchSpanProcessor = class extends import_sdk_trace_base.BatchSpanProce
1638
1643
  if (maskingConfig) {
1639
1644
  maskSpan(span, maskingConfig);
1640
1645
  }
1641
- const associationProperties = import_api4.context.active().getValue(PROPERTIES_CONTEXT_KEY);
1642
- if (associationProperties) {
1643
- for (const [key, value] of Object.entries(associationProperties)) {
1644
- span.setAttribute(`${BRIZZ}.${key}`, value);
1645
- }
1646
- }
1646
+ applyContextAttributes(span);
1647
1647
  super.onStart(span, parentContext);
1648
1648
  }
1649
1649
  };
@@ -1817,31 +1817,45 @@ var Session = class {
1817
1817
  span;
1818
1818
  inputs = [];
1819
1819
  outputs = [];
1820
+ inputContexts = [];
1821
+ outputContexts = [];
1820
1822
  constructor(sessionId, span) {
1821
1823
  this.sessionId = sessionId;
1822
1824
  this.span = span;
1823
1825
  }
1824
1826
  /**
1825
- * (Optional) Append text to session input tracking.
1826
- * Use when you need to track specific input data that differs from what's sent to the LLM.
1827
- * Multiple calls accumulate in an array.
1827
+ * Append a user turn to session input tracking.
1828
+ *
1829
+ * Each call appends one element to `brizz.session.input` (the text) AND one
1830
+ * element to `brizz.session.input.context` (the per-turn context bag). The
1831
+ * two arrays stay index-aligned — the ingestion pipeline zips them together
1832
+ * so the i-th context bag lands on the i-th user_display conversation item's
1833
+ * `span_attributes` map.
1828
1834
  *
1829
- * @param text - Text to append to session input, or null to append null
1835
+ * @param text - Text to append (null becomes a null/"hide marker")
1836
+ * @param context - Optional per-turn context bag to attach to this turn
1830
1837
  */
1831
- setInput(text) {
1838
+ setInput(text, context4) {
1832
1839
  this.inputs.push(text);
1840
+ this.inputContexts.push(context4 ?? {});
1833
1841
  this.span.setAttribute(SESSION_INPUT, JSON.stringify(this.inputs));
1842
+ this.span.setAttribute(SESSION_INPUT_CONTEXT, JSON.stringify(this.inputContexts));
1834
1843
  }
1835
1844
  /**
1836
- * (Optional) Append text to session output tracking.
1837
- * Use when you need to track specific output data that differs from what's received from the LLM.
1838
- * Multiple calls accumulate in an array.
1845
+ * Append an assistant turn to session output tracking.
1846
+ *
1847
+ * Symmetric to {@link setInput} appends one text element and one
1848
+ * context-bag element to the index-aligned `brizz.session.output` /
1849
+ * `brizz.session.output.context` arrays.
1839
1850
  *
1840
- * @param text - Text to append to session output, or null to append null
1851
+ * @param text - Text to append (null becomes a null/"hide marker")
1852
+ * @param context - Optional per-turn context bag to attach to this turn
1841
1853
  */
1842
- setOutput(text) {
1854
+ setOutput(text, context4) {
1843
1855
  this.outputs.push(text);
1856
+ this.outputContexts.push(context4 ?? {});
1844
1857
  this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
1858
+ this.span.setAttribute(SESSION_OUTPUT_CONTEXT, JSON.stringify(this.outputContexts));
1845
1859
  }
1846
1860
  /**
1847
1861
  * Set the session title on the span.