@brizz/sdk 0.1.14 → 0.1.15
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 +20 -0
- package/dist/index.cjs +32 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +31 -23
- package/dist/index.js.map +1 -1
- package/dist/preload.cjs +2 -1
- package/dist/preload.cjs.map +1 -1
- package/dist/preload.js +2 -1
- package/dist/preload.js.map +1 -1
- package/package.json +28 -28
package/README.md
CHANGED
|
@@ -313,6 +313,26 @@ await startSession('session-456', async (session) => {
|
|
|
313
313
|
});
|
|
314
314
|
```
|
|
315
315
|
|
|
316
|
+
### Accessing the Active Session
|
|
317
|
+
|
|
318
|
+
Use `getActiveSession()` to retrieve the current session from anywhere within a `startSession` scope — no need to pass the session object through your call stack:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
import { startSession, getActiveSession } from '@brizz/sdk';
|
|
322
|
+
|
|
323
|
+
function deepHelper() {
|
|
324
|
+
const session = getActiveSession();
|
|
325
|
+
session?.updateProperties({ step: 'helper' });
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
await startSession('session-123', async () => {
|
|
329
|
+
deepHelper(); // accesses session without it being passed as a parameter
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// Outside a session, returns undefined
|
|
333
|
+
getActiveSession(); // undefined
|
|
334
|
+
```
|
|
335
|
+
|
|
316
336
|
### Function Wrapper Pattern
|
|
317
337
|
|
|
318
338
|
For simpler cases where you just need to tag traces with a session ID:
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
callWithSessionId: () => callWithSessionId,
|
|
40
40
|
detectRuntime: () => detectRuntime,
|
|
41
41
|
emitEvent: () => emitEvent,
|
|
42
|
+
getActiveSession: () => getActiveSession,
|
|
42
43
|
getLogLevel: () => getLogLevel,
|
|
43
44
|
getMetricsExporter: () => getMetricsExporter,
|
|
44
45
|
getMetricsReader: () => getMetricsReader,
|
|
@@ -493,7 +494,7 @@ var import_sdk_logs2 = require("@opentelemetry/sdk-logs");
|
|
|
493
494
|
|
|
494
495
|
// src/internal/version.ts
|
|
495
496
|
function getSDKVersion() {
|
|
496
|
-
return "0.1.
|
|
497
|
+
return "0.1.15";
|
|
497
498
|
}
|
|
498
499
|
|
|
499
500
|
// src/internal/log/processors/log-processor.ts
|
|
@@ -1130,6 +1131,7 @@ var BRIZZ = "brizz";
|
|
|
1130
1131
|
var PROPERTIES = "properties";
|
|
1131
1132
|
var SESSION_ID = "session.id";
|
|
1132
1133
|
var PROPERTIES_CONTEXT_KEY = (0, import_api2.createContextKey)(PROPERTIES);
|
|
1134
|
+
var SESSION_OBJECT_CONTEXT_KEY = (0, import_api2.createContextKey)("brizz.session.object");
|
|
1133
1135
|
var SESSION_INPUT = "brizz.session.input";
|
|
1134
1136
|
var SESSION_OUTPUT = "brizz.session.output";
|
|
1135
1137
|
var SESSION_SPAN_NAME = "brizz.start_session";
|
|
@@ -1762,7 +1764,7 @@ var Session = class {
|
|
|
1762
1764
|
* Use when you need to track specific input data that differs from what's sent to the LLM.
|
|
1763
1765
|
* Multiple calls accumulate in an array.
|
|
1764
1766
|
*
|
|
1765
|
-
* @param text - Text to append to session input
|
|
1767
|
+
* @param text - Text to append to session input, or null to append null
|
|
1766
1768
|
*/
|
|
1767
1769
|
setInput(text) {
|
|
1768
1770
|
this.inputs.push(text);
|
|
@@ -1773,7 +1775,7 @@ var Session = class {
|
|
|
1773
1775
|
* Use when you need to track specific output data that differs from what's received from the LLM.
|
|
1774
1776
|
* Multiple calls accumulate in an array.
|
|
1775
1777
|
*
|
|
1776
|
-
* @param text - Text to append to session output
|
|
1778
|
+
* @param text - Text to append to session output, or null to append null
|
|
1777
1779
|
*/
|
|
1778
1780
|
setOutput(text) {
|
|
1779
1781
|
this.outputs.push(text);
|
|
@@ -1791,6 +1793,9 @@ var Session = class {
|
|
|
1791
1793
|
}
|
|
1792
1794
|
}
|
|
1793
1795
|
};
|
|
1796
|
+
function getActiveSession() {
|
|
1797
|
+
return import_api5.context.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1798
|
+
}
|
|
1794
1799
|
function startSession(sessionId, callback, extraProperties) {
|
|
1795
1800
|
const tracer = import_api5.trace.getTracer("@brizz/sdk");
|
|
1796
1801
|
return tracer.startActiveSpan(SESSION_SPAN_NAME, (span) => {
|
|
@@ -1808,27 +1813,30 @@ function startSession(sessionId, callback, extraProperties) {
|
|
|
1808
1813
|
}
|
|
1809
1814
|
}
|
|
1810
1815
|
return callWithProperties(contextProperties, () => {
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
return value
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1816
|
+
const sessionCtx = import_api5.context.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1817
|
+
return import_api5.context.with(sessionCtx, () => {
|
|
1818
|
+
try {
|
|
1819
|
+
const result = callback(session);
|
|
1820
|
+
if (result && typeof result.then === "function") {
|
|
1821
|
+
return result.then((value) => {
|
|
1822
|
+
span.end();
|
|
1823
|
+
return value;
|
|
1824
|
+
}).catch((error) => {
|
|
1825
|
+
span.recordException(error);
|
|
1826
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1827
|
+
span.end();
|
|
1828
|
+
throw error;
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
span.end();
|
|
1832
|
+
return result;
|
|
1833
|
+
} catch (error) {
|
|
1834
|
+
span.recordException(error);
|
|
1835
|
+
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1836
|
+
span.end();
|
|
1837
|
+
throw error;
|
|
1823
1838
|
}
|
|
1824
|
-
|
|
1825
|
-
return result;
|
|
1826
|
-
} catch (error) {
|
|
1827
|
-
span.recordException(error);
|
|
1828
|
-
span.setStatus({ code: import_api5.SpanStatusCode.ERROR });
|
|
1829
|
-
span.end();
|
|
1830
|
-
throw error;
|
|
1831
|
-
}
|
|
1839
|
+
});
|
|
1832
1840
|
});
|
|
1833
1841
|
});
|
|
1834
1842
|
}
|
|
@@ -2088,6 +2096,7 @@ var init_exports = {};
|
|
|
2088
2096
|
callWithSessionId,
|
|
2089
2097
|
detectRuntime,
|
|
2090
2098
|
emitEvent,
|
|
2099
|
+
getActiveSession,
|
|
2091
2100
|
getLogLevel,
|
|
2092
2101
|
getMetricsExporter,
|
|
2093
2102
|
getMetricsReader,
|