@sentrial/sdk 0.1.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.
- package/README.md +208 -0
- package/dist/index.cjs +595 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +642 -0
- package/dist/index.d.ts +642 -0
- package/dist/index.js +556 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# @sentrial/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for [Sentrial](https://sentrial.com) - AI agent observability and monitoring.
|
|
4
|
+
|
|
5
|
+
Track sessions, tool calls, and metrics to power:
|
|
6
|
+
- **Signal detection**: Auto-detect patterns and anomalies
|
|
7
|
+
- **Root cause analysis**: Understand WHY agents fail
|
|
8
|
+
- **Code fixer**: AI-suggested fixes with GitHub PRs
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @sentrial/sdk
|
|
14
|
+
# or
|
|
15
|
+
pnpm add @sentrial/sdk
|
|
16
|
+
# or
|
|
17
|
+
yarn add @sentrial/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { SentrialClient } from '@sentrial/sdk';
|
|
24
|
+
|
|
25
|
+
const client = new SentrialClient({
|
|
26
|
+
apiKey: process.env.SENTRIAL_API_KEY!,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
async function runAgent(userId: string, input: string) {
|
|
30
|
+
// 1. Create session
|
|
31
|
+
const sessionId = await client.createSession({
|
|
32
|
+
name: `Support: ${input.slice(0, 50)}`,
|
|
33
|
+
agentName: 'support-agent',
|
|
34
|
+
userId,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// 2. Track tool calls
|
|
39
|
+
await client.trackToolCall({
|
|
40
|
+
sessionId,
|
|
41
|
+
toolName: 'search_kb',
|
|
42
|
+
toolInput: { query: input },
|
|
43
|
+
toolOutput: { articles: ['KB-001'] },
|
|
44
|
+
reasoning: 'Searching knowledge base',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// 3. Process and respond
|
|
48
|
+
const response = await processInput(input);
|
|
49
|
+
|
|
50
|
+
// 4. Complete session
|
|
51
|
+
await client.completeSession({
|
|
52
|
+
sessionId,
|
|
53
|
+
success: true,
|
|
54
|
+
customMetrics: { satisfaction: 4.5 },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return response;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
await client.completeSession({
|
|
60
|
+
sessionId,
|
|
61
|
+
success: false,
|
|
62
|
+
failureReason: error instanceof Error ? error.message : 'Unknown error',
|
|
63
|
+
});
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Simple API (begin/finish pattern)
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { sentrial } from '@sentrial/sdk';
|
|
73
|
+
|
|
74
|
+
sentrial.configure({ apiKey: 'sentrial_live_xxx' });
|
|
75
|
+
|
|
76
|
+
async function handleMessage(userId: string, message: string) {
|
|
77
|
+
const interaction = await sentrial.begin({
|
|
78
|
+
userId,
|
|
79
|
+
event: 'chat_message',
|
|
80
|
+
input: message,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const response = await agent.process(message);
|
|
85
|
+
|
|
86
|
+
await interaction.finish({
|
|
87
|
+
output: response,
|
|
88
|
+
success: true,
|
|
89
|
+
customMetrics: { satisfaction: 4.5 },
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return response;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
await interaction.finish({
|
|
95
|
+
success: false,
|
|
96
|
+
failureReason: error.message,
|
|
97
|
+
});
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Configuration
|
|
104
|
+
|
|
105
|
+
### Environment Variables
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
SENTRIAL_API_URL=https://api.sentrial.com
|
|
109
|
+
SENTRIAL_API_KEY=sentrial_live_xxx
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Explicit Configuration
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
const client = new SentrialClient({
|
|
116
|
+
apiKey: 'sentrial_live_xxx',
|
|
117
|
+
apiUrl: 'https://api.sentrial.com', // Optional
|
|
118
|
+
failSilently: true, // Default: true (errors logged but don't crash)
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Cost Calculation
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { calculateOpenAICost, calculateAnthropicCost, calculateGoogleCost } from '@sentrial/sdk';
|
|
126
|
+
|
|
127
|
+
const openaiCost = calculateOpenAICost({
|
|
128
|
+
model: 'gpt-4o',
|
|
129
|
+
inputTokens: 1000,
|
|
130
|
+
outputTokens: 500,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const anthropicCost = calculateAnthropicCost({
|
|
134
|
+
model: 'claude-3-5-sonnet',
|
|
135
|
+
inputTokens: 1000,
|
|
136
|
+
outputTokens: 500,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const googleCost = calculateGoogleCost({
|
|
140
|
+
model: 'gemini-2.0-flash',
|
|
141
|
+
inputTokens: 1000,
|
|
142
|
+
outputTokens: 500,
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Error Handling
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { SentrialClient, SentrialError } from '@sentrial/sdk';
|
|
150
|
+
|
|
151
|
+
const client = new SentrialClient({
|
|
152
|
+
apiKey: '...',
|
|
153
|
+
failSilently: false, // Enable errors during development
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
await client.createSession({...});
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error instanceof SentrialError) {
|
|
160
|
+
if (error.isAuthError()) {
|
|
161
|
+
console.error('Invalid API key');
|
|
162
|
+
} else if (error.isRateLimitError()) {
|
|
163
|
+
console.error('Rate limited');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## API Reference
|
|
171
|
+
|
|
172
|
+
### SentrialClient
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
class SentrialClient {
|
|
176
|
+
constructor(config?: SentrialClientConfig);
|
|
177
|
+
|
|
178
|
+
createSession(params: CreateSessionParams): Promise<string | null>;
|
|
179
|
+
trackToolCall(params: TrackToolCallParams): Promise<Event | null>;
|
|
180
|
+
trackDecision(params: TrackDecisionParams): Promise<Event | null>;
|
|
181
|
+
trackError(params: TrackErrorParams): Promise<Event | null>;
|
|
182
|
+
completeSession(params: CompleteSessionParams): Promise<Session | null>;
|
|
183
|
+
begin(params: BeginParams): Promise<Interaction>;
|
|
184
|
+
|
|
185
|
+
// Static cost calculators
|
|
186
|
+
static calculateOpenAICost(params: CostParams): number;
|
|
187
|
+
static calculateAnthropicCost(params: CostParams): number;
|
|
188
|
+
static calculateGoogleCost(params: CostParams): number;
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Interaction
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
class Interaction {
|
|
196
|
+
setOutput(output: string): void;
|
|
197
|
+
finish(params?: FinishParams): Promise<Session | null>;
|
|
198
|
+
trackToolCall(params: Omit<TrackToolCallParams, 'sessionId'>): Promise<Event | null>;
|
|
199
|
+
trackDecision(params: Omit<TrackDecisionParams, 'sessionId'>): Promise<Event | null>;
|
|
200
|
+
trackError(params: Omit<TrackErrorParams, 'sessionId'>): Promise<Event | null>;
|
|
201
|
+
getSessionId(): string | null;
|
|
202
|
+
isDegraded(): boolean;
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT
|