@brizz/sdk 0.1.14 → 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 +53 -0
- package/dist/index.cjs +86 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +83 -6
- 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 +30 -30
package/dist/index.d.cts
CHANGED
|
@@ -130,11 +130,23 @@ declare class Session {
|
|
|
130
130
|
private inputs;
|
|
131
131
|
private outputs;
|
|
132
132
|
constructor(sessionId: string, span: Span);
|
|
133
|
-
setInput(text: string): void;
|
|
134
|
-
setOutput(text: string): void;
|
|
133
|
+
setInput(text: string | null): void;
|
|
134
|
+
setOutput(text: string | null): void;
|
|
135
|
+
setTitle(title: string): void;
|
|
135
136
|
updateProperties(properties: Record<string, AttributeValue>): void;
|
|
136
137
|
}
|
|
137
|
-
declare
|
|
138
|
+
declare class SessionTitle {
|
|
139
|
+
private readonly span;
|
|
140
|
+
constructor(span: Span);
|
|
141
|
+
setTitle(title: string): void;
|
|
142
|
+
}
|
|
143
|
+
declare function getActiveSession(): Session | undefined;
|
|
144
|
+
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
|
|
145
|
+
mode?: 'default' | 'title';
|
|
146
|
+
}): T;
|
|
147
|
+
declare function startSessionTitle<T>(callback: (title: SessionTitle) => T, options?: {
|
|
148
|
+
sessionId?: string;
|
|
149
|
+
}): T;
|
|
138
150
|
|
|
139
151
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
140
152
|
declare function getMetricsReader(): MetricReader;
|
|
@@ -152,4 +164,4 @@ declare namespace init {
|
|
|
152
164
|
export { };
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, Session, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, withProperties, withSessionId };
|
|
167
|
+
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, Session, SessionTitle, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getActiveSession, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, startSessionTitle, withProperties, withSessionId };
|
package/dist/index.d.ts
CHANGED
|
@@ -130,11 +130,23 @@ declare class Session {
|
|
|
130
130
|
private inputs;
|
|
131
131
|
private outputs;
|
|
132
132
|
constructor(sessionId: string, span: Span);
|
|
133
|
-
setInput(text: string): void;
|
|
134
|
-
setOutput(text: string): void;
|
|
133
|
+
setInput(text: string | null): void;
|
|
134
|
+
setOutput(text: string | null): void;
|
|
135
|
+
setTitle(title: string): void;
|
|
135
136
|
updateProperties(properties: Record<string, AttributeValue>): void;
|
|
136
137
|
}
|
|
137
|
-
declare
|
|
138
|
+
declare class SessionTitle {
|
|
139
|
+
private readonly span;
|
|
140
|
+
constructor(span: Span);
|
|
141
|
+
setTitle(title: string): void;
|
|
142
|
+
}
|
|
143
|
+
declare function getActiveSession(): Session | undefined;
|
|
144
|
+
declare function startSession<T>(sessionId: string, callback: (session: Session) => T, extraProperties?: Record<string, AttributeValue>, options?: {
|
|
145
|
+
mode?: 'default' | 'title';
|
|
146
|
+
}): T;
|
|
147
|
+
declare function startSessionTitle<T>(callback: (title: SessionTitle) => T, options?: {
|
|
148
|
+
sessionId?: string;
|
|
149
|
+
}): T;
|
|
138
150
|
|
|
139
151
|
declare function getMetricsExporter(): OTLPMetricExporter;
|
|
140
152
|
declare function getMetricsReader(): MetricReader;
|
|
@@ -152,4 +164,4 @@ declare namespace init {
|
|
|
152
164
|
export { };
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, Session, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, withProperties, withSessionId };
|
|
167
|
+
export { Brizz, DEFAULT_PII_PATTERNS, type IAttributesMaskingRule, type IBrizzInitializeOptions, type IEventMaskingConfig, type IEventMaskingRule, type IInstrumentModules, type ILogMaskingConfig, type ILogger, type IMaskingConfig, type ISpanMaskingConfig, LogLevel, type MaskingMode, type RuntimeInfo, Session, SessionTitle, callWithProperties, callWithSessionId, detectRuntime, emitEvent, getActiveSession, getLogLevel, getMetricsExporter, getMetricsReader, getSpanExporter, getSpanProcessor, init, logger, maskAttributes, maskValue, setLogLevel, startSession, startSessionTitle, withProperties, withSessionId };
|
package/dist/index.js
CHANGED
|
@@ -445,7 +445,7 @@ import {
|
|
|
445
445
|
|
|
446
446
|
// src/internal/version.ts
|
|
447
447
|
function getSDKVersion() {
|
|
448
|
-
return "0.1.
|
|
448
|
+
return "0.1.16";
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
// src/internal/log/processors/log-processor.ts
|
|
@@ -1082,9 +1082,13 @@ var BRIZZ = "brizz";
|
|
|
1082
1082
|
var PROPERTIES = "properties";
|
|
1083
1083
|
var SESSION_ID = "session.id";
|
|
1084
1084
|
var PROPERTIES_CONTEXT_KEY = createContextKey(PROPERTIES);
|
|
1085
|
+
var SESSION_OBJECT_CONTEXT_KEY = createContextKey("brizz.session.object");
|
|
1085
1086
|
var SESSION_INPUT = "brizz.session.input";
|
|
1086
1087
|
var SESSION_OUTPUT = "brizz.session.output";
|
|
1087
1088
|
var SESSION_SPAN_NAME = "brizz.start_session";
|
|
1089
|
+
var SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
1090
|
+
var SESSION_TITLE_GENERATION = "session.title_generation";
|
|
1091
|
+
var SESSION_TITLE = "brizz.session.title";
|
|
1088
1092
|
|
|
1089
1093
|
// src/internal/log/processors/log-processor.ts
|
|
1090
1094
|
var DEFAULT_LOG_MASKING_RULES = [
|
|
@@ -1717,7 +1721,7 @@ var Session = class {
|
|
|
1717
1721
|
* Use when you need to track specific input data that differs from what's sent to the LLM.
|
|
1718
1722
|
* Multiple calls accumulate in an array.
|
|
1719
1723
|
*
|
|
1720
|
-
* @param text - Text to append to session input
|
|
1724
|
+
* @param text - Text to append to session input, or null to append null
|
|
1721
1725
|
*/
|
|
1722
1726
|
setInput(text) {
|
|
1723
1727
|
this.inputs.push(text);
|
|
@@ -1728,12 +1732,20 @@ var Session = class {
|
|
|
1728
1732
|
* Use when you need to track specific output data that differs from what's received from the LLM.
|
|
1729
1733
|
* Multiple calls accumulate in an array.
|
|
1730
1734
|
*
|
|
1731
|
-
* @param text - Text to append to session output
|
|
1735
|
+
* @param text - Text to append to session output, or null to append null
|
|
1732
1736
|
*/
|
|
1733
1737
|
setOutput(text) {
|
|
1734
1738
|
this.outputs.push(text);
|
|
1735
1739
|
this.span.setAttribute(SESSION_OUTPUT, JSON.stringify(this.outputs));
|
|
1736
1740
|
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Set the session title on the span.
|
|
1743
|
+
*
|
|
1744
|
+
* @param title - The generated title string
|
|
1745
|
+
*/
|
|
1746
|
+
setTitle(title) {
|
|
1747
|
+
this.span.setAttribute(SESSION_TITLE, title);
|
|
1748
|
+
}
|
|
1737
1749
|
/**
|
|
1738
1750
|
* Update custom properties on the session span.
|
|
1739
1751
|
* Properties are prefixed with 'brizz.'.
|
|
@@ -1746,9 +1758,28 @@ var Session = class {
|
|
|
1746
1758
|
}
|
|
1747
1759
|
}
|
|
1748
1760
|
};
|
|
1749
|
-
|
|
1761
|
+
var SessionTitle = class {
|
|
1762
|
+
span;
|
|
1763
|
+
constructor(span) {
|
|
1764
|
+
this.span = span;
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Set the generated title on the wrapper span.
|
|
1768
|
+
*
|
|
1769
|
+
* @param title - The generated title string
|
|
1770
|
+
*/
|
|
1771
|
+
setTitle(title) {
|
|
1772
|
+
this.span.setAttribute(SESSION_TITLE, title);
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
|
+
function getActiveSession() {
|
|
1776
|
+
return context3.active().getValue(SESSION_OBJECT_CONTEXT_KEY);
|
|
1777
|
+
}
|
|
1778
|
+
function startSession(sessionId, callback, extraProperties, options) {
|
|
1779
|
+
const isTitle = options?.mode === "title";
|
|
1780
|
+
const spanName = isTitle ? SESSION_TITLE_SPAN_NAME : SESSION_SPAN_NAME;
|
|
1750
1781
|
const tracer = trace.getTracer("@brizz/sdk");
|
|
1751
|
-
return tracer.startActiveSpan(
|
|
1782
|
+
return tracer.startActiveSpan(spanName, (span) => {
|
|
1752
1783
|
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
1753
1784
|
if (extraProperties) {
|
|
1754
1785
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
@@ -1757,14 +1788,57 @@ function startSession(sessionId, callback, extraProperties) {
|
|
|
1757
1788
|
}
|
|
1758
1789
|
const session = new Session(sessionId, span);
|
|
1759
1790
|
const contextProperties = { [SESSION_ID]: sessionId };
|
|
1791
|
+
if (isTitle) {
|
|
1792
|
+
contextProperties[SESSION_TITLE_GENERATION] = "true";
|
|
1793
|
+
}
|
|
1760
1794
|
if (extraProperties) {
|
|
1761
1795
|
for (const [key, value] of Object.entries(extraProperties)) {
|
|
1762
1796
|
contextProperties[key] = String(value);
|
|
1763
1797
|
}
|
|
1764
1798
|
}
|
|
1765
1799
|
return callWithProperties(contextProperties, () => {
|
|
1800
|
+
const sessionCtx = context3.active().setValue(SESSION_OBJECT_CONTEXT_KEY, session);
|
|
1801
|
+
return context3.with(sessionCtx, () => {
|
|
1802
|
+
try {
|
|
1803
|
+
const result = callback(session);
|
|
1804
|
+
if (result && typeof result.then === "function") {
|
|
1805
|
+
return result.then((value) => {
|
|
1806
|
+
span.end();
|
|
1807
|
+
return value;
|
|
1808
|
+
}).catch((error) => {
|
|
1809
|
+
span.recordException(error);
|
|
1810
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1811
|
+
span.end();
|
|
1812
|
+
throw error;
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
span.end();
|
|
1816
|
+
return result;
|
|
1817
|
+
} catch (error) {
|
|
1818
|
+
span.recordException(error);
|
|
1819
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1820
|
+
span.end();
|
|
1821
|
+
throw error;
|
|
1822
|
+
}
|
|
1823
|
+
});
|
|
1824
|
+
});
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
function startSessionTitle(callback, options) {
|
|
1828
|
+
const resolvedSessionId = options?.sessionId ?? getActiveSession()?.sessionId;
|
|
1829
|
+
const tracer = trace.getTracer("@brizz/sdk");
|
|
1830
|
+
return tracer.startActiveSpan(SESSION_TITLE_SPAN_NAME, (span) => {
|
|
1831
|
+
if (resolvedSessionId) {
|
|
1832
|
+
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, resolvedSessionId);
|
|
1833
|
+
}
|
|
1834
|
+
const sessionTitle = new SessionTitle(span);
|
|
1835
|
+
const properties = { [SESSION_TITLE_GENERATION]: "true" };
|
|
1836
|
+
if (resolvedSessionId) {
|
|
1837
|
+
properties[SESSION_ID] = resolvedSessionId;
|
|
1838
|
+
}
|
|
1839
|
+
return callWithProperties(properties, () => {
|
|
1766
1840
|
try {
|
|
1767
|
-
const result = callback(
|
|
1841
|
+
const result = callback(sessionTitle);
|
|
1768
1842
|
if (result && typeof result.then === "function") {
|
|
1769
1843
|
return result.then((value) => {
|
|
1770
1844
|
span.end();
|
|
@@ -2037,11 +2111,13 @@ export {
|
|
|
2037
2111
|
DEFAULT_PII_PATTERNS,
|
|
2038
2112
|
LogLevel,
|
|
2039
2113
|
Session,
|
|
2114
|
+
SessionTitle,
|
|
2040
2115
|
SeverityNumber2 as SeverityNumber,
|
|
2041
2116
|
callWithProperties,
|
|
2042
2117
|
callWithSessionId,
|
|
2043
2118
|
detectRuntime,
|
|
2044
2119
|
emitEvent,
|
|
2120
|
+
getActiveSession,
|
|
2045
2121
|
getLogLevel,
|
|
2046
2122
|
getMetricsExporter,
|
|
2047
2123
|
getMetricsReader,
|
|
@@ -2053,6 +2129,7 @@ export {
|
|
|
2053
2129
|
maskValue,
|
|
2054
2130
|
setLogLevel,
|
|
2055
2131
|
startSession,
|
|
2132
|
+
startSessionTitle,
|
|
2056
2133
|
withProperties,
|
|
2057
2134
|
withSessionId
|
|
2058
2135
|
};
|