@sensu-ai/sdk 0.1.5 → 0.5.0

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.
@@ -0,0 +1,128 @@
1
+ import type { TelemetryEvent } from '@sensu-ai/shared';
2
+ import type { SensuClientOptions, StartRunOptions, StartStepOptions, TrackLlmOptions, TrackStreamingLlmOptions, TrackToolOptions, RawLlmCallOptions, TrackRetrievalOptions, RawRetrievalOptions, TrackEmbeddingOptions, RawEmbeddingOptions, RecordFeedbackOptions, RecordEvalScoreOptions, HandoffOptions, SpawnRunOptions, TrackGuardrailOptions, RawGuardrailOptions, RecordPromptRenderOptions, DeployPromptVersionOptions, StartSessionOptions, ResumeSessionOptions } from './types.js';
3
+ export declare class StepHandle {
4
+ private readonly client;
5
+ readonly stepId: string;
6
+ readonly runId: string;
7
+ readonly sessionId: string;
8
+ readonly agentId: string;
9
+ readonly orgId: string;
10
+ readonly traceId: string;
11
+ readonly spanId: string;
12
+ private sequence;
13
+ private stepName?;
14
+ private ended;
15
+ constructor(client: SensuClient, opts: {
16
+ stepId: string;
17
+ runId: string;
18
+ sessionId: string;
19
+ agentId: string;
20
+ orgId: string;
21
+ traceId: string;
22
+ spanId: string;
23
+ sequence: number;
24
+ name?: string;
25
+ });
26
+ private base;
27
+ /** Track an LLM call — wraps fn(), measures latency, emits event */
28
+ trackLlm(opts: TrackLlmOptions): Promise<unknown>;
29
+ /**
30
+ * Track a streaming LLM call — consumes the async iterable, measures TTFT,
31
+ * and emits stream.token.received events as tokens arrive.
32
+ * Returns the full concatenated text.
33
+ */
34
+ trackStreamingLlm(opts: TrackStreamingLlmOptions): Promise<string>;
35
+ /** Emit a raw LLM call event (when you have the stats already) */
36
+ recordLlm(opts: RawLlmCallOptions): void;
37
+ /** Track a tool call — wraps fn(), measures latency */
38
+ trackTool(opts: TrackToolOptions): Promise<unknown>;
39
+ /** Track a retrieval call — wraps fn(), measures latency, emits started + completed */
40
+ trackRetrieval(opts: TrackRetrievalOptions): Promise<unknown>;
41
+ /** Emit a raw retrieval completed event (when you have the stats already) */
42
+ recordRetrieval(opts: RawRetrievalOptions): void;
43
+ /** Track an embedding call — wraps fn(), measures latency */
44
+ trackEmbedding(opts: TrackEmbeddingOptions): Promise<unknown>;
45
+ /** Emit a raw embedding event */
46
+ recordEmbedding(opts: RawEmbeddingOptions): void;
47
+ /** Track a guardrail check — wraps fn(), measures latency, handles block */
48
+ trackGuardrail(opts: TrackGuardrailOptions): Promise<'pass' | 'fail' | 'modified'>;
49
+ /** Emit a raw guardrail result (check or block) */
50
+ recordGuardrail(opts: RawGuardrailOptions): void;
51
+ /** Record a prompt template render event */
52
+ recordPromptRender(opts: RecordPromptRenderOptions): void;
53
+ end(): Promise<void>;
54
+ }
55
+ export declare class RunHandle {
56
+ private readonly client;
57
+ readonly runId: string;
58
+ readonly sessionId: string;
59
+ readonly agentId: string;
60
+ readonly orgId: string;
61
+ readonly traceId: string;
62
+ readonly spanId: string;
63
+ private stepCount;
64
+ private ended;
65
+ constructor(client: SensuClient, opts: {
66
+ runId: string;
67
+ sessionId: string;
68
+ agentId: string;
69
+ orgId: string;
70
+ traceId: string;
71
+ spanId: string;
72
+ });
73
+ private base;
74
+ startStep(opts?: StartStepOptions): StepHandle;
75
+ /** Record user feedback for this run */
76
+ recordFeedback(opts: RecordFeedbackOptions): void;
77
+ /** Record an automated eval score for this run */
78
+ recordEvalScore(opts: RecordEvalScoreOptions): void;
79
+ /** Emit an agent.handoff event from this run to another agent */
80
+ handoff(opts: HandoffOptions): void;
81
+ end(status?: 'completed' | 'failed'): Promise<void>;
82
+ }
83
+ export declare class SensuClient {
84
+ private readonly apiKey;
85
+ private readonly baseUrl;
86
+ private readonly agentId;
87
+ private readonly orgId;
88
+ private readonly batchSize;
89
+ private readonly flushIntervalMs;
90
+ readonly disabled: boolean;
91
+ private readonly disableLivePricing;
92
+ private readonly onLoopDetected?;
93
+ private readonly loopThreshold;
94
+ private readonly runToolCallCounts;
95
+ private readonly pricingCache;
96
+ private buffer;
97
+ private flushTimer;
98
+ constructor(opts?: SensuClientOptions);
99
+ /** Enqueue an event for batched sending */
100
+ enqueue(event: TelemetryEvent): void;
101
+ /** Flush all buffered events to the Sensu API */
102
+ flush(): Promise<void>;
103
+ /** Track a tool call for loop detection; fires onLoopDetected when threshold is reached. */
104
+ notifyToolCall(runId: string, toolName: string): void;
105
+ /** Remove per-run loop counters when the run ends to avoid memory leaks. */
106
+ clearRunLoopState(runId: string): void;
107
+ /** Start a new agent run */
108
+ startRun(opts?: StartRunOptions): RunHandle;
109
+ /**
110
+ * Spawn a child agent run from within a parent run.
111
+ * Emits `agent.spawned` on the parent and returns a RunHandle for the child.
112
+ */
113
+ spawnRun(parentRun: RunHandle, opts: SpawnRunOptions): RunHandle;
114
+ /** Explicitly start a session (sets channel and end_user_id) */
115
+ startSession(opts?: StartSessionOptions): string;
116
+ /** Resume a previous session */
117
+ resumeSession(opts: ResumeSessionOptions): string;
118
+ /** Record a prompt version deployment (org-level event, not tied to a run) */
119
+ deployPromptVersion(opts: DeployPromptVersionOptions): void;
120
+ /**
121
+ * Resolve per-1M-token pricing for a model.
122
+ * Fetches from the Senzu API on first use and caches for the session lifetime.
123
+ * Falls back to the bundled MODEL_PRICING table if the API is unreachable or the
124
+ * model is unknown, and to a near-zero sentinel if it's missing from both.
125
+ */
126
+ resolvePricing(provider: string, model: string): Promise<[number, number]>;
127
+ destroy(): void;
128
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EAEjB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAs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