@brizz/sdk 0.1.42 → 0.1.44
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 +44 -0
- package/dist/{chunk-QUV5HYJ2.cjs → chunk-3IGBYXLR.cjs} +4 -4
- package/dist/{chunk-FORVS4QW.cjs → chunk-5WBPX342.cjs} +7 -1
- package/dist/chunk-A3HH5OUL.cjs +240 -0
- package/dist/chunk-AELIATPI.js +240 -0
- package/dist/{chunk-Y7NMZAQT.js → chunk-AOT5NJDV.js} +6 -0
- package/dist/{chunk-7FQQHF5U.js → chunk-APOYOP7D.js} +1 -1
- package/dist/index.cjs +270 -128
- package/dist/index.js +154 -12
- package/dist/{interrupt-ERCX5RXR.js → interrupt-A6O7N72X.js} +2 -2
- package/dist/interrupt-IKOUBQGN.cjs +12 -0
- package/dist/{mcp-GVGTOWHP.cjs → mcp-5FSUXYHM.cjs} +97 -100
- package/dist/{mcp-5BFXKN63.js → mcp-7EJXVCPI.js} +83 -86
- package/dist/types/cjs/index.d.ts +2 -2
- package/dist/types/cjs/internal/instrumentation/mcp/client-session.d.ts +24 -0
- package/dist/types/cjs/internal/instrumentation/mcp/session.d.ts +3 -1
- package/dist/types/cjs/internal/sdk.d.ts +2 -0
- package/dist/types/cjs/internal/semantic-conventions.d.ts +3 -0
- package/dist/types/cjs/internal/trace/agent.d.ts +18 -0
- package/dist/types/cjs/internal/trace/index.d.ts +2 -0
- package/dist/types/cjs/internal/trace/session.d.ts +2 -1
- package/dist/types/esm/index.d.ts +2 -2
- package/dist/types/esm/internal/instrumentation/mcp/client-session.d.ts +24 -0
- package/dist/types/esm/internal/instrumentation/mcp/session.d.ts +3 -1
- package/dist/types/esm/internal/sdk.d.ts +2 -0
- package/dist/types/esm/internal/semantic-conventions.d.ts +3 -0
- package/dist/types/esm/internal/trace/agent.d.ts +18 -0
- package/dist/types/esm/internal/trace/index.d.ts +2 -0
- package/dist/types/esm/internal/trace/session.d.ts +2 -1
- package/package.json +10 -10
- package/dist/chunk-K3NPYISB.cjs +0 -8
- package/dist/chunk-KVOGOKOB.js +0 -8
- package/dist/interrupt-3NXOTY4N.cjs +0 -12
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getSDKVersion
|
|
3
|
-
|
|
2
|
+
getSDKVersion,
|
|
3
|
+
isEnabled,
|
|
4
|
+
isSessionToolCall,
|
|
5
|
+
patchListToolsResult,
|
|
6
|
+
popTrackingArguments,
|
|
7
|
+
resolveSessionId,
|
|
8
|
+
resolveTransportSessionId,
|
|
9
|
+
sessionToolResult,
|
|
10
|
+
stampAndPropagateSession
|
|
11
|
+
} from "./chunk-AELIATPI.js";
|
|
4
12
|
import {
|
|
5
13
|
logger
|
|
6
14
|
} from "./chunk-Y4HNUX3Q.js";
|
|
7
|
-
import
|
|
8
|
-
BRIZZ,
|
|
9
|
-
PROPERTIES_CONTEXT_KEY,
|
|
10
|
-
SESSION_ID
|
|
11
|
-
} from "./chunk-Y7NMZAQT.js";
|
|
15
|
+
import "./chunk-AOT5NJDV.js";
|
|
12
16
|
import "./chunk-3RG5ZIWI.js";
|
|
13
17
|
|
|
14
18
|
// src/internal/instrumentation/mcp/instrumentation.ts
|
|
@@ -17,7 +21,7 @@ import { trace as trace2 } from "@opentelemetry/api";
|
|
|
17
21
|
import { InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
|
|
18
22
|
|
|
19
23
|
// src/internal/instrumentation/mcp/patches/protocol.ts
|
|
20
|
-
import { context
|
|
24
|
+
import { context, propagation, SpanKind as SpanKind2, trace } from "@opentelemetry/api";
|
|
21
25
|
|
|
22
26
|
// src/internal/instrumentation/mcp/schemas.ts
|
|
23
27
|
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
@@ -130,70 +134,6 @@ function extractTools(result) {
|
|
|
130
134
|
);
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
// src/internal/instrumentation/mcp/session.ts
|
|
134
|
-
import { context } from "@opentelemetry/api";
|
|
135
|
-
var FALLBACK_SESSION_ID = /* @__PURE__ */ Symbol("brizz.mcp.fallback-session-id");
|
|
136
|
-
var FALLBACK_SESSION_ID_BYTES = 16;
|
|
137
|
-
function generateSessionId() {
|
|
138
|
-
let id = "";
|
|
139
|
-
for (let i = 0; i < FALLBACK_SESSION_ID_BYTES; i++) {
|
|
140
|
-
id += Math.floor(Math.random() * 256).toString(16).padStart(2, "0");
|
|
141
|
-
}
|
|
142
|
-
return id;
|
|
143
|
-
}
|
|
144
|
-
function isSessionCarrier(value) {
|
|
145
|
-
return typeof value === "object" && value !== null;
|
|
146
|
-
}
|
|
147
|
-
function resolveTransportSessionId(protocol) {
|
|
148
|
-
if (!isSessionCarrier(protocol)) {
|
|
149
|
-
return void 0;
|
|
150
|
-
}
|
|
151
|
-
return protocol.sessionId ?? protocol._transport?.sessionId;
|
|
152
|
-
}
|
|
153
|
-
function resolveSessionId(protocol, baseContext) {
|
|
154
|
-
if (!isSessionCarrier(protocol)) {
|
|
155
|
-
return void 0;
|
|
156
|
-
}
|
|
157
|
-
const fromTransport = resolveTransportSessionId(protocol);
|
|
158
|
-
if (fromTransport) {
|
|
159
|
-
return fromTransport;
|
|
160
|
-
}
|
|
161
|
-
try {
|
|
162
|
-
const bound = baseContext.getValue(PROPERTIES_CONTEXT_KEY);
|
|
163
|
-
if (bound?.[SESSION_ID]) {
|
|
164
|
-
return void 0;
|
|
165
|
-
}
|
|
166
|
-
} catch {
|
|
167
|
-
}
|
|
168
|
-
protocol[FALLBACK_SESSION_ID] ??= generateSessionId();
|
|
169
|
-
return protocol[FALLBACK_SESSION_ID];
|
|
170
|
-
}
|
|
171
|
-
function stampAndPropagateSession(span, sessionId, baseContext = context.active()) {
|
|
172
|
-
if (!sessionId) {
|
|
173
|
-
return { context: baseContext, sessionId: null };
|
|
174
|
-
}
|
|
175
|
-
if (span.isRecording()) {
|
|
176
|
-
try {
|
|
177
|
-
span.setAttribute(`${BRIZZ}.${SESSION_ID}`, sessionId);
|
|
178
|
-
} catch (error) {
|
|
179
|
-
logger.warn(
|
|
180
|
-
`Brizz MCP: failed to stamp session id on span: ${String(error)}`
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
const prev = baseContext.getValue(PROPERTIES_CONTEXT_KEY);
|
|
186
|
-
const merged = prev ? { ...prev, [SESSION_ID]: sessionId } : { [SESSION_ID]: sessionId };
|
|
187
|
-
return {
|
|
188
|
-
context: baseContext.setValue(PROPERTIES_CONTEXT_KEY, merged),
|
|
189
|
-
sessionId
|
|
190
|
-
};
|
|
191
|
-
} catch (error) {
|
|
192
|
-
logger.warn(`Brizz MCP: failed to attach session context: ${String(error)}`);
|
|
193
|
-
return { context: baseContext, sessionId };
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
137
|
// src/internal/instrumentation/mcp/patches/attributes.ts
|
|
198
138
|
import { SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
199
139
|
function deriveSpanName(method, params) {
|
|
@@ -431,8 +371,8 @@ function wrapRequest(original, tracer) {
|
|
|
431
371
|
return original.apply(this, args);
|
|
432
372
|
}
|
|
433
373
|
return executeAroundSpan(span, request.method, () => {
|
|
434
|
-
const ctx = trace.setSpan(
|
|
435
|
-
return
|
|
374
|
+
const ctx = trace.setSpan(context.active(), span);
|
|
375
|
+
return context.with(ctx, () => original.apply(this, args));
|
|
436
376
|
});
|
|
437
377
|
};
|
|
438
378
|
}
|
|
@@ -447,11 +387,15 @@ function wrapOnRequest(original, tracer) {
|
|
|
447
387
|
return original.apply(this, args);
|
|
448
388
|
}
|
|
449
389
|
const method = request.method;
|
|
390
|
+
if (method === METHOD_TOOLS_CALL && isSessionToolCall(request)) {
|
|
391
|
+
return answerSessionToolCall(this, request, tracer, args, original);
|
|
392
|
+
}
|
|
450
393
|
const handler = handlers.get(method) ?? this.fallbackRequestHandler;
|
|
451
394
|
if (!handler) {
|
|
452
395
|
return original.apply(this, args);
|
|
453
396
|
}
|
|
454
|
-
const
|
|
397
|
+
const tracking = isEnabled() && method === METHOD_TOOLS_CALL ? popTrackingArguments(request) : {};
|
|
398
|
+
const started = safeStartServerSpan(tracer, request, this, tracking);
|
|
455
399
|
if (!started) {
|
|
456
400
|
return original.apply(this, args);
|
|
457
401
|
}
|
|
@@ -459,9 +403,20 @@ function wrapOnRequest(original, tracer) {
|
|
|
459
403
|
const hooks = {};
|
|
460
404
|
if (method === METHOD_TOOLS_LIST) {
|
|
461
405
|
hooks.onResult = (result) => {
|
|
406
|
+
let advertised = result;
|
|
407
|
+
if (isEnabled()) {
|
|
408
|
+
try {
|
|
409
|
+
advertised = patchListToolsResult(result);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
logger.warn(
|
|
412
|
+
`Brizz MCP: failed to patch tools/list schemas: ${String(error)}`
|
|
413
|
+
);
|
|
414
|
+
advertised = result;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
462
417
|
try {
|
|
463
418
|
emitSchemaSpansFromListResponse(
|
|
464
|
-
|
|
419
|
+
advertised,
|
|
465
420
|
resolveTransportSessionId(this),
|
|
466
421
|
tracer
|
|
467
422
|
);
|
|
@@ -470,6 +425,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
470
425
|
`Brizz MCP: failed to emit tools/list schema spans: ${String(error)}`
|
|
471
426
|
);
|
|
472
427
|
}
|
|
428
|
+
return advertised;
|
|
473
429
|
};
|
|
474
430
|
}
|
|
475
431
|
if (method !== METHOD_TOOLS_CALL) {
|
|
@@ -477,7 +433,7 @@ function wrapOnRequest(original, tracer) {
|
|
|
477
433
|
stampAndPropagateSession(span, resolveSessionId(this, spanCtx), spanCtx);
|
|
478
434
|
};
|
|
479
435
|
}
|
|
480
|
-
const wrappedHandler = (req, extra) =>
|
|
436
|
+
const wrappedHandler = (req, extra) => context.with(
|
|
481
437
|
spanCtx,
|
|
482
438
|
() => executeHandler(span, method, handler, req, extra, hooks)
|
|
483
439
|
);
|
|
@@ -503,6 +459,30 @@ function wrapOnRequest(original, tracer) {
|
|
|
503
459
|
}
|
|
504
460
|
};
|
|
505
461
|
}
|
|
462
|
+
function answerSessionToolCall(protocol, request, tracer, args, original) {
|
|
463
|
+
const handlers = protocol._requestHandlers;
|
|
464
|
+
if (!handlers) {
|
|
465
|
+
return original.apply(protocol, args);
|
|
466
|
+
}
|
|
467
|
+
const { id, result } = sessionToolResult();
|
|
468
|
+
const started = safeStartServerSpan(tracer, request, protocol, { sessionId: id });
|
|
469
|
+
const handler = () => started ? context.with(started.spanCtx, () => result) : result;
|
|
470
|
+
const hadEntry = handlers.has(METHOD_TOOLS_CALL);
|
|
471
|
+
const prev = handlers.get(METHOD_TOOLS_CALL);
|
|
472
|
+
handlers.set(
|
|
473
|
+
METHOD_TOOLS_CALL,
|
|
474
|
+
(req, extra) => started ? executeHandler(started.span, METHOD_TOOLS_CALL, handler, req, extra) : handler(req, extra)
|
|
475
|
+
);
|
|
476
|
+
try {
|
|
477
|
+
return original.apply(protocol, args);
|
|
478
|
+
} finally {
|
|
479
|
+
if (hadEntry) {
|
|
480
|
+
handlers.set(METHOD_TOOLS_CALL, prev);
|
|
481
|
+
} else {
|
|
482
|
+
handlers.delete(METHOD_TOOLS_CALL);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
506
486
|
function executeAroundSpan(span, method, run, hooks) {
|
|
507
487
|
let result;
|
|
508
488
|
try {
|
|
@@ -515,16 +495,16 @@ function executeAroundSpan(span, method, run, hooks) {
|
|
|
515
495
|
}
|
|
516
496
|
if (!isThenable(result)) {
|
|
517
497
|
safeApplyResultAttributes(span, method, result);
|
|
518
|
-
hooks
|
|
498
|
+
const replaced = applyResultHook(hooks, result);
|
|
519
499
|
safeEnd(span);
|
|
520
|
-
return
|
|
500
|
+
return replaced;
|
|
521
501
|
}
|
|
522
502
|
return result.then(
|
|
523
503
|
(value) => {
|
|
524
504
|
safeApplyResultAttributes(span, method, value);
|
|
525
|
-
hooks
|
|
505
|
+
const replaced = applyResultHook(hooks, value);
|
|
526
506
|
safeEnd(span);
|
|
527
|
-
return
|
|
507
|
+
return replaced;
|
|
528
508
|
},
|
|
529
509
|
(error) => {
|
|
530
510
|
safeApplyErrorAttributes(span, error);
|
|
@@ -537,6 +517,18 @@ function executeAroundSpan(span, method, run, hooks) {
|
|
|
537
517
|
function executeHandler(span, method, handler, req, extra, hooks) {
|
|
538
518
|
return executeAroundSpan(span, method, () => handler(req, extra), hooks);
|
|
539
519
|
}
|
|
520
|
+
function applyResultHook(hooks, value) {
|
|
521
|
+
if (!hooks?.onResult) {
|
|
522
|
+
return value;
|
|
523
|
+
}
|
|
524
|
+
try {
|
|
525
|
+
const replaced = hooks.onResult(value);
|
|
526
|
+
return replaced === void 0 ? value : replaced;
|
|
527
|
+
} catch (error) {
|
|
528
|
+
logger.debug(`Brizz MCP: result hook failed: ${String(error)}`);
|
|
529
|
+
return value;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
540
532
|
function safeStartClientSpan(tracer, request, protocol) {
|
|
541
533
|
try {
|
|
542
534
|
const spanName = deriveSpanName(request.method, request.params);
|
|
@@ -552,7 +544,7 @@ function safeStartClientSpan(tracer, request, protocol) {
|
|
|
552
544
|
return null;
|
|
553
545
|
}
|
|
554
546
|
}
|
|
555
|
-
function safeStartServerSpan(tracer, request, protocol) {
|
|
547
|
+
function safeStartServerSpan(tracer, request, protocol, tracking = {}) {
|
|
556
548
|
try {
|
|
557
549
|
const parentCtx = extractParentContext(request);
|
|
558
550
|
const spanName = deriveSpanName(request.method, request.params);
|
|
@@ -562,8 +554,13 @@ function safeStartServerSpan(tracer, request, protocol) {
|
|
|
562
554
|
parentCtx
|
|
563
555
|
);
|
|
564
556
|
applyServerRequestAttributes(span, request, protocol);
|
|
565
|
-
const resolved = request.method === METHOD_TOOLS_CALL ? resolveSessionId(protocol, parentCtx) : void 0;
|
|
566
|
-
const { context: sessCtx } = stampAndPropagateSession(
|
|
557
|
+
const resolved = request.method === METHOD_TOOLS_CALL ? tracking.sessionId ?? resolveSessionId(protocol, parentCtx) : void 0;
|
|
558
|
+
const { context: sessCtx } = stampAndPropagateSession(
|
|
559
|
+
span,
|
|
560
|
+
resolved,
|
|
561
|
+
parentCtx,
|
|
562
|
+
tracking.intent
|
|
563
|
+
);
|
|
567
564
|
return { span, spanCtx: trace.setSpan(sessCtx, span) };
|
|
568
565
|
} catch (error) {
|
|
569
566
|
logger.debug(`Brizz MCP: failed to open SERVER span: ${String(error)}`);
|
|
@@ -574,14 +571,14 @@ function extractParentContext(request) {
|
|
|
574
571
|
try {
|
|
575
572
|
const meta = request.params?._meta;
|
|
576
573
|
if (meta && typeof meta === "object") {
|
|
577
|
-
return propagation.extract(
|
|
574
|
+
return propagation.extract(context.active(), meta);
|
|
578
575
|
}
|
|
579
576
|
} catch (error) {
|
|
580
577
|
logger.debug(
|
|
581
578
|
`Brizz MCP: failed to extract parent context from _meta: ${String(error)}`
|
|
582
579
|
);
|
|
583
580
|
}
|
|
584
|
-
return
|
|
581
|
+
return context.active();
|
|
585
582
|
}
|
|
586
583
|
function isThenable(value) {
|
|
587
584
|
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
@@ -2,8 +2,8 @@ import './internal/instrumentation/auto-init.js';
|
|
|
2
2
|
export { Brizz, type IBrizzInitializeOptions } from './internal/sdk.js';
|
|
3
3
|
export { type IInstrumentModules, type IMCPManualModules, } from './internal/instrumentation/index.js';
|
|
4
4
|
export { emitEvent, emitEventWithSessionId } from './internal/log/index.js';
|
|
5
|
-
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
|
-
export type { IMuteOptions } from './internal/trace/index.js';
|
|
5
|
+
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startAgent, withAgent, setAgent, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
|
+
export type { IMuteOptions, AgentRef, IAgent, IAgentOptions } from './internal/trace/index.js';
|
|
7
7
|
export { getMetricsExporter, getMetricsReader } from './internal/metric/index.js';
|
|
8
8
|
export type { IMaskingConfig, ISpanMaskingConfig, ILogMaskingConfig, IEventMaskingConfig, IEventMaskingRule, MaskingMode, IAttributesMaskingRule, } from './internal/masking/index.js';
|
|
9
9
|
export { DEFAULT_PII_PATTERNS } from './internal/masking/patterns.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const DEFAULT_SESSION_PARAM = "brizz_mcp_session_id";
|
|
2
|
+
export declare const DEFAULT_SESSION_TOOL_NAME = "brizz_start_session";
|
|
3
|
+
export declare const INTENT_PARAM = "brizz_intent";
|
|
4
|
+
export interface IMCPSessionTrackingConfig {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
intent?: boolean;
|
|
7
|
+
sessionParamName?: string;
|
|
8
|
+
sessionToolName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function configure(config: IMCPSessionTrackingConfig | boolean | undefined): void;
|
|
11
|
+
export declare function isEnabled(): boolean;
|
|
12
|
+
export declare function sessionParam(): string;
|
|
13
|
+
export declare function sessionToolNameValue(): string;
|
|
14
|
+
export interface ITrackingArguments {
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
intent?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function isSessionToolCall(request: unknown): boolean;
|
|
19
|
+
export declare function sessionToolResult(): {
|
|
20
|
+
id: string;
|
|
21
|
+
result: unknown;
|
|
22
|
+
};
|
|
23
|
+
export declare function patchListToolsResult(result: unknown): unknown;
|
|
24
|
+
export declare function popTrackingArguments(request: unknown): ITrackingArguments;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Context, Span } from '@opentelemetry/api';
|
|
2
|
+
export declare const INTENT_PROPERTY = "internal.intent";
|
|
2
3
|
export interface ISessionAttachResult {
|
|
3
4
|
context: Context;
|
|
4
5
|
sessionId: string | null;
|
|
5
6
|
}
|
|
7
|
+
export declare function generateSessionId(): string;
|
|
6
8
|
export declare function resolveTransportSessionId(protocol: unknown): string | undefined;
|
|
7
9
|
export declare function resolveSessionId(protocol: unknown, baseContext: Context): string | undefined;
|
|
8
|
-
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context): ISessionAttachResult;
|
|
10
|
+
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context, intent?: string): ISessionAttachResult;
|
|
@@ -3,6 +3,7 @@ import type { LogRecordExporter } from '@opentelemetry/sdk-logs';
|
|
|
3
3
|
import type { MetricReader } from '@opentelemetry/sdk-metrics';
|
|
4
4
|
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
5
5
|
import { type IInstrumentModules } from './instrumentation/index.js';
|
|
6
|
+
import { type IMCPSessionTrackingConfig } from './instrumentation/mcp/client-session.js';
|
|
6
7
|
import type { LogLevel } from './logger.js';
|
|
7
8
|
import { type IMaskingConfig } from './masking/index.js';
|
|
8
9
|
export interface IBrizzInitializeOptions {
|
|
@@ -13,6 +14,7 @@ export interface IBrizzInitializeOptions {
|
|
|
13
14
|
dsn?: string;
|
|
14
15
|
headers?: Record<string, string>;
|
|
15
16
|
disableBatch?: boolean;
|
|
17
|
+
mcpSessionTracking?: IMCPSessionTrackingConfig | boolean;
|
|
16
18
|
environment?: string;
|
|
17
19
|
masking?: boolean | IMaskingConfig;
|
|
18
20
|
logLevel?: LogLevel | string;
|
|
@@ -26,6 +26,9 @@ export declare const SERVICE_NAME_ATTRIBUTE = "brizz.service.name";
|
|
|
26
26
|
export declare const SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
27
27
|
export declare const SESSION_TITLE_GENERATION = "session.title_generation";
|
|
28
28
|
export declare const SESSION_TITLE = "brizz.session.title";
|
|
29
|
+
export declare const AGENT_ID = "internal.agent.id";
|
|
30
|
+
export declare const AGENT_PARENT_ID = "internal.agent.parent_id";
|
|
31
|
+
export declare const AGENT_NAME = "internal.agent.name";
|
|
29
32
|
export declare const INTERRUPT_TOOLS = "brizz.internal.interrupt";
|
|
30
33
|
export declare const INTERNAL_EVENT_PREFIX = "brizz.internal.";
|
|
31
34
|
export declare const EXTERNAL_LINK_EVENT_NAME = "brizz.internal.external_link";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IAgent {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly parentId: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly traceparent: string;
|
|
6
|
+
readonly sessionId: string;
|
|
7
|
+
readonly token: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IAgentOptions {
|
|
10
|
+
name?: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
parentId?: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
}
|
|
15
|
+
export type AgentRef = string | IAgentOptions;
|
|
16
|
+
export declare function startAgent<T>(agent: AgentRef, callback: (agent: IAgent) => T): T;
|
|
17
|
+
export declare function withAgent<F extends (this: any, ...args: any[]) => any>(agent: AgentRef, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
18
|
+
export declare function setAgent(agent: AgentRef): IAgent;
|
|
@@ -2,3 +2,5 @@ export { TracingModule, getSpanExporter, getSpanProcessor } from './tracing.js';
|
|
|
2
2
|
export { BrizzBatchSpanProcessor, BrizzSimpleSpanProcessor } from './processors/span-processor.js';
|
|
3
3
|
export { withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './session.js';
|
|
4
4
|
export type { IMuteOptions } from './session.js';
|
|
5
|
+
export { startAgent, withAgent, setAgent } from './agent.js';
|
|
6
|
+
export type { AgentRef, IAgent, IAgentOptions } from './agent.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Span, AttributeValue } from '@opentelemetry/api';
|
|
1
|
+
import type { Context, Span, AttributeValue } from '@opentelemetry/api';
|
|
2
2
|
export declare function setCurrentSpanCustomProperties(properties: Record<string, AttributeValue>): void;
|
|
3
3
|
export declare function callWithProperties<A extends unknown[], F extends (...args: A) => ReturnType<F>>(properties: {
|
|
4
4
|
[name: string]: string;
|
|
@@ -6,6 +6,7 @@ export declare function callWithProperties<A extends unknown[], F extends (...ar
|
|
|
6
6
|
export declare function withProperties<F extends (this: any, ...args: any[]) => any>(properties: {
|
|
7
7
|
[name: string]: string;
|
|
8
8
|
}, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
9
|
+
export declare function propagatePropertiesImperatively(properties: Record<string, string>, base?: Context): void;
|
|
9
10
|
export declare function setUser(user: {
|
|
10
11
|
id: string;
|
|
11
12
|
email?: string;
|
|
@@ -2,8 +2,8 @@ import './internal/instrumentation/auto-init.js';
|
|
|
2
2
|
export { Brizz, type IBrizzInitializeOptions } from './internal/sdk.js';
|
|
3
3
|
export { type IInstrumentModules, type IMCPManualModules, } from './internal/instrumentation/index.js';
|
|
4
4
|
export { emitEvent, emitEventWithSessionId } from './internal/log/index.js';
|
|
5
|
-
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
|
-
export type { IMuteOptions } from './internal/trace/index.js';
|
|
5
|
+
export { getSpanExporter, getSpanProcessor, withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startAgent, withAgent, setAgent, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './internal/trace/index.js';
|
|
6
|
+
export type { IMuteOptions, AgentRef, IAgent, IAgentOptions } from './internal/trace/index.js';
|
|
7
7
|
export { getMetricsExporter, getMetricsReader } from './internal/metric/index.js';
|
|
8
8
|
export type { IMaskingConfig, ISpanMaskingConfig, ILogMaskingConfig, IEventMaskingConfig, IEventMaskingRule, MaskingMode, IAttributesMaskingRule, } from './internal/masking/index.js';
|
|
9
9
|
export { DEFAULT_PII_PATTERNS } from './internal/masking/patterns.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const DEFAULT_SESSION_PARAM = "brizz_mcp_session_id";
|
|
2
|
+
export declare const DEFAULT_SESSION_TOOL_NAME = "brizz_start_session";
|
|
3
|
+
export declare const INTENT_PARAM = "brizz_intent";
|
|
4
|
+
export interface IMCPSessionTrackingConfig {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
intent?: boolean;
|
|
7
|
+
sessionParamName?: string;
|
|
8
|
+
sessionToolName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function configure(config: IMCPSessionTrackingConfig | boolean | undefined): void;
|
|
11
|
+
export declare function isEnabled(): boolean;
|
|
12
|
+
export declare function sessionParam(): string;
|
|
13
|
+
export declare function sessionToolNameValue(): string;
|
|
14
|
+
export interface ITrackingArguments {
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
intent?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function isSessionToolCall(request: unknown): boolean;
|
|
19
|
+
export declare function sessionToolResult(): {
|
|
20
|
+
id: string;
|
|
21
|
+
result: unknown;
|
|
22
|
+
};
|
|
23
|
+
export declare function patchListToolsResult(result: unknown): unknown;
|
|
24
|
+
export declare function popTrackingArguments(request: unknown): ITrackingArguments;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Context, Span } from '@opentelemetry/api';
|
|
2
|
+
export declare const INTENT_PROPERTY = "internal.intent";
|
|
2
3
|
export interface ISessionAttachResult {
|
|
3
4
|
context: Context;
|
|
4
5
|
sessionId: string | null;
|
|
5
6
|
}
|
|
7
|
+
export declare function generateSessionId(): string;
|
|
6
8
|
export declare function resolveTransportSessionId(protocol: unknown): string | undefined;
|
|
7
9
|
export declare function resolveSessionId(protocol: unknown, baseContext: Context): string | undefined;
|
|
8
|
-
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context): ISessionAttachResult;
|
|
10
|
+
export declare function stampAndPropagateSession(span: Span, sessionId: string | null | undefined, baseContext?: Context, intent?: string): ISessionAttachResult;
|
|
@@ -3,6 +3,7 @@ import type { LogRecordExporter } from '@opentelemetry/sdk-logs';
|
|
|
3
3
|
import type { MetricReader } from '@opentelemetry/sdk-metrics';
|
|
4
4
|
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
5
5
|
import { type IInstrumentModules } from './instrumentation/index.js';
|
|
6
|
+
import { type IMCPSessionTrackingConfig } from './instrumentation/mcp/client-session.js';
|
|
6
7
|
import type { LogLevel } from './logger.js';
|
|
7
8
|
import { type IMaskingConfig } from './masking/index.js';
|
|
8
9
|
export interface IBrizzInitializeOptions {
|
|
@@ -13,6 +14,7 @@ export interface IBrizzInitializeOptions {
|
|
|
13
14
|
dsn?: string;
|
|
14
15
|
headers?: Record<string, string>;
|
|
15
16
|
disableBatch?: boolean;
|
|
17
|
+
mcpSessionTracking?: IMCPSessionTrackingConfig | boolean;
|
|
16
18
|
environment?: string;
|
|
17
19
|
masking?: boolean | IMaskingConfig;
|
|
18
20
|
logLevel?: LogLevel | string;
|
|
@@ -26,6 +26,9 @@ export declare const SERVICE_NAME_ATTRIBUTE = "brizz.service.name";
|
|
|
26
26
|
export declare const SESSION_TITLE_SPAN_NAME = "brizz.session_title";
|
|
27
27
|
export declare const SESSION_TITLE_GENERATION = "session.title_generation";
|
|
28
28
|
export declare const SESSION_TITLE = "brizz.session.title";
|
|
29
|
+
export declare const AGENT_ID = "internal.agent.id";
|
|
30
|
+
export declare const AGENT_PARENT_ID = "internal.agent.parent_id";
|
|
31
|
+
export declare const AGENT_NAME = "internal.agent.name";
|
|
29
32
|
export declare const INTERRUPT_TOOLS = "brizz.internal.interrupt";
|
|
30
33
|
export declare const INTERNAL_EVENT_PREFIX = "brizz.internal.";
|
|
31
34
|
export declare const EXTERNAL_LINK_EVENT_NAME = "brizz.internal.external_link";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IAgent {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly parentId: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly traceparent: string;
|
|
6
|
+
readonly sessionId: string;
|
|
7
|
+
readonly token: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IAgentOptions {
|
|
10
|
+
name?: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
parentId?: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
}
|
|
15
|
+
export type AgentRef = string | IAgentOptions;
|
|
16
|
+
export declare function startAgent<T>(agent: AgentRef, callback: (agent: IAgent) => T): T;
|
|
17
|
+
export declare function withAgent<F extends (this: any, ...args: any[]) => any>(agent: AgentRef, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
18
|
+
export declare function setAgent(agent: AgentRef): IAgent;
|
|
@@ -2,3 +2,5 @@ export { TracingModule, getSpanExporter, getSpanProcessor } from './tracing.js';
|
|
|
2
2
|
export { BrizzBatchSpanProcessor, BrizzSimpleSpanProcessor } from './processors/span-processor.js';
|
|
3
3
|
export { withSessionId, callWithSessionId, withProperties, callWithProperties, withMute, callWithMute, setCurrentSpanCustomProperties, setUser, setOrganization, setMessageId, setSessionId, setServiceName, withServiceName, callWithServiceName, withUser, callWithUser, withOrganization, callWithOrganization, withMessageId, callWithMessageId, Session, SessionTitle, startSession, startSessionTitle, getActiveSession, addExternalLink, recordFeedback, recordMetric, } from './session.js';
|
|
4
4
|
export type { IMuteOptions } from './session.js';
|
|
5
|
+
export { startAgent, withAgent, setAgent } from './agent.js';
|
|
6
|
+
export type { AgentRef, IAgent, IAgentOptions } from './agent.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Span, AttributeValue } from '@opentelemetry/api';
|
|
1
|
+
import type { Context, Span, AttributeValue } from '@opentelemetry/api';
|
|
2
2
|
export declare function setCurrentSpanCustomProperties(properties: Record<string, AttributeValue>): void;
|
|
3
3
|
export declare function callWithProperties<A extends unknown[], F extends (...args: A) => ReturnType<F>>(properties: {
|
|
4
4
|
[name: string]: string;
|
|
@@ -6,6 +6,7 @@ export declare function callWithProperties<A extends unknown[], F extends (...ar
|
|
|
6
6
|
export declare function withProperties<F extends (this: any, ...args: any[]) => any>(properties: {
|
|
7
7
|
[name: string]: string;
|
|
8
8
|
}, fn: F, thisArg?: ThisParameterType<F>): F;
|
|
9
|
+
export declare function propagatePropertiesImperatively(properties: Record<string, string>, base?: Context): void;
|
|
9
10
|
export declare function setUser(user: {
|
|
10
11
|
id: string;
|
|
11
12
|
email?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brizz/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenTelemetry-based observability SDK for AI applications",
|
|
6
6
|
"keywords": [
|
|
@@ -101,32 +101,32 @@
|
|
|
101
101
|
"registry": "https://registry.npmjs.org/"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"@ai-sdk/anthropic": "^4.0.
|
|
105
|
-
"@ai-sdk/openai": "^4.0.
|
|
106
|
-
"@ai-sdk/otel": "^1.0.
|
|
104
|
+
"@ai-sdk/anthropic": "^4.0.40",
|
|
105
|
+
"@ai-sdk/openai": "^4.0.44",
|
|
106
|
+
"@ai-sdk/otel": "^1.0.70",
|
|
107
107
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
108
108
|
"@arizeai/openinference-instrumentation-mcp": "^0.2.24",
|
|
109
109
|
"@babel/core": "^8.0.1",
|
|
110
110
|
"@babel/preset-env": "^8.0.2",
|
|
111
111
|
"@babel/preset-typescript": "^8.0.1",
|
|
112
112
|
"@changesets/changelog-github": "^1.0.0",
|
|
113
|
-
"@changesets/cli": "^3.0.
|
|
114
|
-
"@google/genai": "^2.
|
|
113
|
+
"@changesets/cli": "^3.0.1",
|
|
114
|
+
"@google/genai": "^2.18.0",
|
|
115
115
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
116
116
|
"@traceloop/instrumentation-google-generativeai": "^0.27.0",
|
|
117
117
|
"@traceloop/instrumentation-vertexai": "^0.27.0",
|
|
118
118
|
"@types/jest": "^30.0.0",
|
|
119
119
|
"@types/node": "^26.2.0",
|
|
120
|
-
"ai": "^7.0.
|
|
120
|
+
"ai": "^7.0.70",
|
|
121
121
|
"babel-jest": "^30.4.1",
|
|
122
122
|
"jest": "^30.4.2",
|
|
123
123
|
"jest-environment-jsdom": "^30.4.1",
|
|
124
|
-
"openai": "^7.
|
|
125
|
-
"oxlint": "^1.
|
|
124
|
+
"openai": "^7.5.0",
|
|
125
|
+
"oxlint": "^1.79.0",
|
|
126
126
|
"prettier": "^3.9.6",
|
|
127
127
|
"tsup": "^8.5.1",
|
|
128
128
|
"typescript": "^7.0.2",
|
|
129
|
-
"vitest": "^4.1.
|
|
129
|
+
"vitest": "^4.1.11",
|
|
130
130
|
"zod": "^4.4.3"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|
package/dist/chunk-K3NPYISB.cjs
DELETED
package/dist/chunk-KVOGOKOB.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _chunkQUV5HYJ2cjs = require('./chunk-QUV5HYJ2.cjs');
|
|
6
|
-
require('./chunk-FORVS4QW.cjs');
|
|
7
|
-
require('./chunk-OBGZSXTJ.cjs');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.InterruptPropagator = _chunkQUV5HYJ2cjs.InterruptPropagator; exports._resetInterruptState = _chunkQUV5HYJ2cjs._resetInterruptState; exports.createInterruptIntegration = _chunkQUV5HYJ2cjs.createInterruptIntegration;
|