@brizz/sdk 0.1.32 → 0.1.34

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
@@ -497,6 +497,90 @@ import { callWithSessionId } from '@brizz/sdk';
497
497
  await callWithSessionId('session-123', processUserWorkflow, null, 'user-456');
498
498
  ```
499
499
 
500
+ ### Identifying Users, Organizations & Messages
501
+
502
+ Attach the end-user, their organization, and a per-message id with typed setters. Call them inside a session — they apply to the turn's spans:
503
+
504
+ ```typescript
505
+ import { startSession, setUser, setOrganization, setMessageId } from '@brizz/sdk';
506
+
507
+ await startSession(sessionId, async () => {
508
+ setUser({ id: user.id, email: user.email, role: user.role, plan: user.plan });
509
+ setOrganization({ id: org.id, name: org.name, plan: org.plan, domain: org.domain });
510
+ setMessageId(message.id); // your own id, to reference this message later
511
+
512
+ return agent.run(prompt);
513
+ });
514
+ ```
515
+
516
+ Only `id` is required. Each field maps to its own attribute (`brizz.user.id`, `brizz.organization.plan`, `brizz.message.id`, …). For anything beyond the named fields, pass a `traits` record — each entry becomes `brizz.user.<key>` / `brizz.organization.<key>`:
517
+
518
+ ```typescript
519
+ setUser({ id: user.id, traits: { department: 'sales', signup_source: 'referral' } });
520
+ setOrganization({ id: org.id, traits: { industry: 'fintech' } });
521
+ ```
522
+
523
+ The same setters are available on the session object (`session.setUser(...)`) and as scoped wrappers (`callWithUser` / `withUser`).
524
+
525
+ ### Recording Feedback
526
+
527
+ Capture an end-user's reaction to a specific reply — a 👍/👎, a rating, a reason. Pair it with the message id you set on the turn:
528
+
529
+ ```typescript
530
+ import { startSession, setMessageId, recordFeedback } from '@brizz/sdk';
531
+
532
+ await startSession(sessionId, async () => {
533
+ setMessageId(message.id); // the id you'll reference this reply by
534
+ const reply = await agent.run(prompt);
535
+ recordFeedback('thumbs_up'); // defaults to the current message
536
+ });
537
+ ```
538
+
539
+ Only `type` is required; `score`, `reason`, `comment`, and `source` are optional, and `attributes` adds free-form `brizz.feedback.<key>` entries. Feedback is anchored by `messageId` and/or `sessionId`, so you can send it later — even minutes or days after the reply — by passing the id(s) explicitly:
540
+
541
+ ```typescript
542
+ recordFeedback('thumbs_down', { messageId: message.id, sessionId, reason: 'inaccurate' });
543
+ ```
544
+
545
+ ### Recording Metrics
546
+
547
+ Report a number your own system already computes about an interaction — an eval score, a customer rating, a latency, a cost. It becomes a real Brizz metric you can filter and chart by, rather than an untyped bag of event attributes.
548
+
549
+ ```typescript
550
+ import { startSession, recordMetric } from '@brizz/sdk';
551
+
552
+ await startSession(sessionId, async () => {
553
+ const reply = await agent.run(prompt);
554
+
555
+ const score = await myEvaluator.score(prompt, reply);
556
+ recordMetric({
557
+ name: 'quality_score',
558
+ value: score,
559
+ unit: 'score',
560
+ minValue: 0,
561
+ maxValue: 1,
562
+ polarity: 'positive',
563
+ });
564
+ });
565
+ ```
566
+
567
+ `polarity` tells Brizz which direction is good — a rising `quality_score` is an improvement, a rising `hallucination_rate` is a regression. `minValue` / `maxValue` describe the scale, so a 4 out of 5 isn't read as a 4 out of 1.
568
+
569
+ Scoring often happens after the fact. Pass `sessionId` to attach a metric from anywhere, and `timestamp` to say *when the measured thing happened*, so a nightly job lands the score on the turn it describes rather than on the evaluation run:
570
+
571
+ ```typescript
572
+ recordMetric({
573
+ name: 'quality_score',
574
+ value: await judge.score(session),
575
+ sessionId: session.id,
576
+ timestamp: session.endedAt,
577
+ comment: 'graded by the nightly LLM judge',
578
+ attributes: { evaluator: 'gpt-4o', rubric: 'v2' },
579
+ });
580
+ ```
581
+
582
+ `attributes` are flat labels you can slice the metric by. Re-reporting the same metric supersedes the previous value, so a re-score wins over the original.
583
+
500
584
  ### Custom Properties
501
585
 
502
586
  Add custom properties to telemetry context:
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  INTERRUPT_TOOLS
3
- } from "./chunk-VGMJ3KUM.js";
3
+ } from "./chunk-QY4VADPP.js";
4
4
 
5
5
  // src/internal/instrumentation/vercel-ai/interrupt.ts
6
6
  import { trace } from "@opentelemetry/api";