@sensu-ai/sdk 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sensu-ai/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "exports": {
package/src/client.ts CHANGED
@@ -22,6 +22,7 @@ import type {
22
22
  DeployPromptVersionOptions,
23
23
  StartSessionOptions,
24
24
  ResumeSessionOptions,
25
+ RetrievalChunkInput,
25
26
  } from './types.js';
26
27
 
27
28
  // ---------------------------------------------------------------------------
@@ -86,6 +87,7 @@ export class StepHandle {
86
87
  async trackLlm(opts: TrackLlmOptions): Promise<unknown> {
87
88
  const startMs = Date.now();
88
89
  const spanId = randomUUID();
90
+ const llmCallId = opts.llmCallId ?? randomUUID();
89
91
 
90
92
  this.client.enqueue({
91
93
  ...this.base(),
@@ -113,10 +115,11 @@ export class StepHandle {
113
115
  const usage = extractUsage(result, opts.model);
114
116
  const contextBreakdown = opts.extractContextBreakdown?.(result);
115
117
 
116
- this.client.enqueue({
118
+ (this.client.enqueue as (e: unknown) => void)({
117
119
  ...this.base(),
118
120
  span_id: spanId,
119
121
  event_type: 'llm.request.completed',
122
+ llm_call_id: llmCallId,
120
123
  provider: opts.provider,
121
124
  model: opts.model,
122
125
  max_context_tokens: opts.maxContextTokens,
@@ -124,6 +127,8 @@ export class StepHandle {
124
127
  status,
125
128
  ...usage,
126
129
  ...(contextBreakdown ? { context_breakdown: contextBreakdown } : {}),
130
+ ...(opts.messagesSnapshot?.length ? { messages_snapshot: opts.messagesSnapshot } : {}),
131
+ ...(opts.referencedChunkIds?.length ? { referenced_chunk_ids: opts.referencedChunkIds } : {}),
127
132
  });
128
133
 
129
134
  if (err) throw err;
@@ -213,10 +218,18 @@ export class StepHandle {
213
218
 
214
219
  /** Emit a raw retrieval completed event (when you have the stats already) */
215
220
  recordRetrieval(opts: RawRetrievalOptions): void {
221
+ const chunks: RetrievalChunkInput[] | undefined = opts.chunks;
216
222
  this.client.enqueue({
217
223
  ...this.base(),
218
224
  event_type: 'retrieval.completed',
219
- ...opts,
225
+ vector_store_id: opts.vectorStoreId,
226
+ top_k: opts.topK,
227
+ latency_ms: opts.latencyMs,
228
+ chunks_returned: opts.chunksReturned,
229
+ tokens_injected: opts.tokensInjected,
230
+ similarity_score_avg: opts.similarityScoreAvg,
231
+ status: opts.status,
232
+ ...(chunks?.length ? { chunks } : {}),
220
233
  });
221
234
  }
222
235
 
@@ -443,6 +456,8 @@ export class RunHandle {
443
456
  score: opts.score,
444
457
  evaluator_id: opts.evaluatorId,
445
458
  model_used_for_eval: opts.modelUsedForEval,
459
+ ...(opts.stepId ? { step_id: opts.stepId } : {}),
460
+ ...(opts.llmCallId ? { llm_call_id: opts.llmCallId } : {}),
446
461
  });
447
462
  }
448
463
 
package/src/types.ts CHANGED
@@ -35,6 +35,13 @@ export interface ContextBreakdown {
35
35
  retrieval_tokens?: number;
36
36
  }
37
37
 
38
+ export interface MessageSnapshotItem {
39
+ role: 'system' | 'user' | 'assistant' | 'tool';
40
+ tool_name?: string;
41
+ token_count: number;
42
+ content_hash: string;
43
+ }
44
+
38
45
  export interface TrackLlmOptions {
39
46
  provider: string;
40
47
  model: string;
@@ -46,6 +53,12 @@ export interface TrackLlmOptions {
46
53
  * Called with the raw response after fn() resolves.
47
54
  */
48
55
  extractContextBreakdown?: (result: unknown) => ContextBreakdown | undefined;
56
+ /** Stable ID for this LLM call — used to link eval scores. Generated if omitted. */
57
+ llmCallId?: string;
58
+ /** Snapshot of every message in the context window sent to this LLM call. */
59
+ messagesSnapshot?: MessageSnapshotItem[];
60
+ /** IDs of retrieval chunks whose content the model actually referenced in its output. */
61
+ referencedChunkIds?: string[];
49
62
  }
50
63
 
51
64
  export interface LlmResult {
@@ -89,6 +102,14 @@ export interface TrackRetrievalOptions {
89
102
  topK?: number;
90
103
  }
91
104
 
105
+ export interface RetrievalChunkInput {
106
+ chunk_id: string;
107
+ source?: string;
108
+ token_count: number;
109
+ similarity_score?: number;
110
+ content_preview?: string;
111
+ }
112
+
92
113
  export interface RawRetrievalOptions {
93
114
  vectorStoreId?: string;
94
115
  topK?: number;
@@ -97,6 +118,8 @@ export interface RawRetrievalOptions {
97
118
  tokensInjected?: number;
98
119
  similarityScoreAvg?: number;
99
120
  status?: 'success' | 'error';
121
+ /** Per-chunk detail for retrieval noise analysis. */
122
+ chunks?: RetrievalChunkInput[];
100
123
  }
101
124
 
102
125
  export interface TrackEmbeddingOptions {
@@ -132,6 +155,10 @@ export interface RecordEvalScoreOptions {
132
155
  score: number;
133
156
  evaluatorId?: string;
134
157
  modelUsedForEval?: string;
158
+ /** Step ID this eval score is linked to — enables quality correlation view. */
159
+ stepId?: string;
160
+ /** LLM call ID this eval score is linked to — must match the llmCallId used in trackLlm(). */
161
+ llmCallId?: string;
135
162
  }
136
163
 
137
164
  // ---------------------------------------------------------------------------