@tenet-ai/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/dist/client.d.ts +145 -0
- package/dist/client.js +499 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/index.d.ts +32 -0
- package/dist/integrations/index.js +42 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/langchain.d.ts +151 -0
- package/dist/integrations/langchain.js +255 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/integrations/openai.d.ts +166 -0
- package/dist/integrations/openai.js +250 -0
- package/dist/integrations/openai.js.map +1 -0
- package/dist/integrations/vercel-ai.d.ts +185 -0
- package/dist/integrations/vercel-ai.js +297 -0
- package/dist/integrations/vercel-ai.js.map +1 -0
- package/dist/types.d.ts +258 -0
- package/dist/types.js +22 -0
- package/dist/types.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vercel AI SDK integration for Tenet AI.
|
|
4
|
+
*
|
|
5
|
+
* Provides wrappers for the Vercel AI SDK's `generateText` and `streamText`
|
|
6
|
+
* functions that automatically record prompts, responses, tool calls, and
|
|
7
|
+
* model metadata in the Tenet audit trail.
|
|
8
|
+
*
|
|
9
|
+
* This module has **no hard dependency** on the `ai` (Vercel AI SDK) package.
|
|
10
|
+
* All relevant types are defined inline and the wrappers accept generic
|
|
11
|
+
* function references.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { generateText, streamText } from 'ai';
|
|
16
|
+
* import { openai } from '@ai-sdk/openai';
|
|
17
|
+
* import { Tenet } from '@tenet-ai/sdk';
|
|
18
|
+
* import { TenetVercelAITracker } from '@tenet-ai/sdk/integrations/vercel-ai';
|
|
19
|
+
*
|
|
20
|
+
* const tenet = new Tenet({ apiKey: 'tenet_xxx' });
|
|
21
|
+
* const tracker = new TenetVercelAITracker(tenet, {
|
|
22
|
+
* agentId: 'vercel-ai-agent',
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Wrap generateText for automatic tracking
|
|
26
|
+
* const trackedGenerate = tracker.wrapGenerateText(generateText);
|
|
27
|
+
* const result = await trackedGenerate({
|
|
28
|
+
* model: openai('gpt-4o'),
|
|
29
|
+
* prompt: 'What is the meaning of life?',
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Wrap streamText for automatic tracking
|
|
33
|
+
* const trackedStream = tracker.wrapStreamText(streamText);
|
|
34
|
+
* const stream = await trackedStream({
|
|
35
|
+
* model: openai('gpt-4o'),
|
|
36
|
+
* prompt: 'Tell me a story.',
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.TenetVercelAITracker = void 0;
|
|
44
|
+
const crypto_1 = require("crypto");
|
|
45
|
+
const types_1 = require("../types");
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Tracker
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
/**
|
|
50
|
+
* Wrapper for the Vercel AI SDK that records `generateText` and `streamText`
|
|
51
|
+
* calls in the Tenet audit trail.
|
|
52
|
+
*
|
|
53
|
+
* Each call records the full intent -> context -> decision -> execution
|
|
54
|
+
* chain including the prompt, model, tool calls, and token usage.
|
|
55
|
+
*/
|
|
56
|
+
class TenetVercelAITracker {
|
|
57
|
+
client;
|
|
58
|
+
agentId;
|
|
59
|
+
sessionId;
|
|
60
|
+
tags;
|
|
61
|
+
metadata;
|
|
62
|
+
/**
|
|
63
|
+
* @param client - An initialised {@link Tenet} client instance.
|
|
64
|
+
* @param config - Optional configuration overrides.
|
|
65
|
+
*/
|
|
66
|
+
constructor(client, config = {}) {
|
|
67
|
+
this.client = client;
|
|
68
|
+
this.agentId = config.agentId ?? "vercel-ai-agent";
|
|
69
|
+
this.sessionId = config.sessionId ?? (0, crypto_1.randomUUID)();
|
|
70
|
+
this.tags = config.tags ?? [];
|
|
71
|
+
this.metadata = config.metadata ?? {};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Wrap the Vercel AI SDK `generateText` function with automatic Tenet
|
|
75
|
+
* tracking. Returns a new function with the same signature.
|
|
76
|
+
*
|
|
77
|
+
* @param generateText - The `generateText` function from the `ai` package.
|
|
78
|
+
* @returns A wrapped function that records calls in Tenet.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { generateText } from 'ai';
|
|
83
|
+
* const trackedGenerate = tracker.wrapGenerateText(generateText);
|
|
84
|
+
* const result = await trackedGenerate({ model, prompt: 'Hello' });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
wrapGenerateText(generateText) {
|
|
88
|
+
const tracker = this;
|
|
89
|
+
return async (params) => {
|
|
90
|
+
let result;
|
|
91
|
+
let error;
|
|
92
|
+
try {
|
|
93
|
+
result = await generateText(params);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
97
|
+
}
|
|
98
|
+
await tracker.recordGenerateText(params, result, error);
|
|
99
|
+
if (error) {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Wrap the Vercel AI SDK `streamText` function with automatic Tenet
|
|
107
|
+
* tracking. The tracking data is recorded after the stream completes
|
|
108
|
+
* (resolves its promises).
|
|
109
|
+
*
|
|
110
|
+
* @param streamText - The `streamText` function from the `ai` package.
|
|
111
|
+
* @returns A wrapped function that records calls in Tenet.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { streamText } from 'ai';
|
|
116
|
+
* const trackedStream = tracker.wrapStreamText(streamText);
|
|
117
|
+
* const result = await trackedStream({ model, prompt: 'Hello' });
|
|
118
|
+
* for await (const chunk of result.textStream) {
|
|
119
|
+
* process.stdout.write(chunk);
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
wrapStreamText(streamText) {
|
|
124
|
+
const tracker = this;
|
|
125
|
+
return async (params) => {
|
|
126
|
+
let result;
|
|
127
|
+
let error;
|
|
128
|
+
try {
|
|
129
|
+
result = await streamText(params);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
133
|
+
await tracker.recordGenerateText(params, undefined, error);
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
// Record after the full text is available (non-blocking).
|
|
137
|
+
// We kick off a background task that awaits the resolved promises.
|
|
138
|
+
tracker.recordStreamResult(params, result).catch(() => {
|
|
139
|
+
// Swallow background tracking errors.
|
|
140
|
+
});
|
|
141
|
+
return result;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Manually record a `generateText` call. Useful when you want to call
|
|
146
|
+
* `generateText` yourself and record after the fact.
|
|
147
|
+
*
|
|
148
|
+
* @param params - The parameters that were passed to `generateText`.
|
|
149
|
+
* @param result - The result, if the call succeeded.
|
|
150
|
+
* @param error - The error, if the call failed.
|
|
151
|
+
*/
|
|
152
|
+
async recordGenerateText(params, result, error) {
|
|
153
|
+
const success = !error && !!result;
|
|
154
|
+
const text = result?.text ?? "";
|
|
155
|
+
const toolCalls = result?.toolCalls ?? [];
|
|
156
|
+
const toolResults = result?.toolResults ?? [];
|
|
157
|
+
const finishReason = result?.finishReason ?? "unknown";
|
|
158
|
+
const usage = result?.usage;
|
|
159
|
+
await this.record(params, {
|
|
160
|
+
success,
|
|
161
|
+
text,
|
|
162
|
+
toolCalls,
|
|
163
|
+
toolResults,
|
|
164
|
+
finishReason,
|
|
165
|
+
usage,
|
|
166
|
+
error,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// ----- Internal -----
|
|
170
|
+
/**
|
|
171
|
+
* Record a streaming result after its promises resolve.
|
|
172
|
+
*/
|
|
173
|
+
async recordStreamResult(params, result) {
|
|
174
|
+
try {
|
|
175
|
+
const [text, toolCalls, toolResults, finishReason, usage] = await Promise.all([
|
|
176
|
+
result.text,
|
|
177
|
+
result.toolCalls ? result.toolCalls : Promise.resolve([]),
|
|
178
|
+
result.toolResults ? result.toolResults : Promise.resolve([]),
|
|
179
|
+
result.finishReason ? result.finishReason : Promise.resolve("unknown"),
|
|
180
|
+
result.usage ? result.usage : Promise.resolve(undefined),
|
|
181
|
+
]);
|
|
182
|
+
await this.record(params, {
|
|
183
|
+
success: true,
|
|
184
|
+
text,
|
|
185
|
+
toolCalls,
|
|
186
|
+
toolResults,
|
|
187
|
+
finishReason,
|
|
188
|
+
usage,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// Swallow: don't break the stream consumer.
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Core recording logic shared by generate and stream paths.
|
|
197
|
+
*/
|
|
198
|
+
async record(params, data) {
|
|
199
|
+
const { success, text, toolCalls, toolResults, finishReason, usage, error } = data;
|
|
200
|
+
// Derive the goal from the prompt or first user message
|
|
201
|
+
let goal;
|
|
202
|
+
if (params.prompt) {
|
|
203
|
+
goal = params.prompt.slice(0, 200);
|
|
204
|
+
}
|
|
205
|
+
else if (params.messages?.length) {
|
|
206
|
+
const lastUser = [...params.messages].reverse().find((m) => m.role === "user");
|
|
207
|
+
goal = lastUser ? lastUser.content.slice(0, 200) : "vercel-ai-call";
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
goal = "vercel-ai-call";
|
|
211
|
+
}
|
|
212
|
+
// Build options
|
|
213
|
+
const options = [];
|
|
214
|
+
if (toolCalls.length > 0) {
|
|
215
|
+
for (let i = 0; i < toolCalls.length; i++) {
|
|
216
|
+
options.push({
|
|
217
|
+
action: toolCalls[i].toolName,
|
|
218
|
+
score: 1.0 / (i + 1),
|
|
219
|
+
reason: JSON.stringify(toolCalls[i].args).slice(0, 100),
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
options.push({
|
|
225
|
+
action: "generate_response",
|
|
226
|
+
score: success ? 1.0 : 0.0,
|
|
227
|
+
reason: success ? "Text generation" : `error: ${error?.message}`,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const chosenAction = toolCalls.length > 0
|
|
231
|
+
? toolCalls[0].toolName
|
|
232
|
+
: "generate_response";
|
|
233
|
+
// Model version: try to extract a string from the model param
|
|
234
|
+
const modelVersion = typeof params.model === "string"
|
|
235
|
+
? params.model
|
|
236
|
+
: params.model?.modelId
|
|
237
|
+
?? "unknown";
|
|
238
|
+
try {
|
|
239
|
+
// 1. Intent
|
|
240
|
+
const intent = await this.client.createIntent({
|
|
241
|
+
goal,
|
|
242
|
+
agentId: this.agentId,
|
|
243
|
+
sessionId: this.sessionId,
|
|
244
|
+
origin: types_1.OriginType.AGENT,
|
|
245
|
+
});
|
|
246
|
+
// 2. Context
|
|
247
|
+
await intent.snapshotContext({
|
|
248
|
+
prompt: params.prompt ?? null,
|
|
249
|
+
messages: params.messages ?? [],
|
|
250
|
+
system: params.system ?? null,
|
|
251
|
+
model: modelVersion,
|
|
252
|
+
temperature: params.temperature,
|
|
253
|
+
max_tokens: params.maxTokens,
|
|
254
|
+
tools: params.tools ? Object.keys(params.tools) : [],
|
|
255
|
+
});
|
|
256
|
+
// 3. Decision
|
|
257
|
+
await intent.decide({
|
|
258
|
+
options,
|
|
259
|
+
chosenAction,
|
|
260
|
+
confidence: success ? 0.95 : 0.0,
|
|
261
|
+
modelVersion,
|
|
262
|
+
reasoning: success
|
|
263
|
+
? `Finished with reason: ${finishReason}`
|
|
264
|
+
: `Error: ${error?.message}`,
|
|
265
|
+
tags: this.tags,
|
|
266
|
+
metadata: {
|
|
267
|
+
...this.metadata,
|
|
268
|
+
usage: usage ?? null,
|
|
269
|
+
finish_reason: finishReason,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
// 4. Execution
|
|
273
|
+
await intent.execute({
|
|
274
|
+
action: chosenAction,
|
|
275
|
+
target: {
|
|
276
|
+
text: text.slice(0, 2000),
|
|
277
|
+
tool_calls: toolCalls.map((tc) => ({
|
|
278
|
+
name: tc.toolName,
|
|
279
|
+
args: tc.args,
|
|
280
|
+
})),
|
|
281
|
+
tool_results: toolResults.map((tr) => ({
|
|
282
|
+
name: tr.toolName,
|
|
283
|
+
result: tr.result,
|
|
284
|
+
})),
|
|
285
|
+
},
|
|
286
|
+
result: success ? types_1.ResultType.SUCCESS : types_1.ResultType.FAILURE,
|
|
287
|
+
sideEffects: toolCalls.map((tc) => `tool:${tc.toolName}`),
|
|
288
|
+
actor: types_1.ActorType.AGENT,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
// Swallow tracking errors so the caller is not impacted.
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.TenetVercelAITracker = TenetVercelAITracker;
|
|
297
|
+
//# sourceMappingURL=vercel-ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel-ai.js","sourceRoot":"","sources":["../../src/integrations/vercel-ai.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;AAEH,mCAAoC;AAEpC,oCAA2E;AAkG3E,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAa,oBAAoB;IACvB,MAAM,CAAQ;IACd,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,IAAI,CAAW;IACf,QAAQ,CAA0B;IA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= "scheduler"
|
|
5
|
+
}
|
|
6
|
+
export declare enum ResultType {
|
|
7
|
+
SUCCESS = "success",
|
|
8
|
+
FAILURE = "failure",
|
|
9
|
+
PENDING = "pending"
|
|
10
|
+
}
|
|
11
|
+
export declare enum ActorType {
|
|
12
|
+
AGENT = "agent",
|
|
13
|
+
HUMAN = "human"
|
|
14
|
+
}
|
|
15
|
+
export interface TenetConfig {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
endpoint?: string;
|
|
18
|
+
environment?: string;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface ActionOption {
|
|
22
|
+
action: string;
|
|
23
|
+
target?: Record<string, unknown>;
|
|
24
|
+
score: number;
|
|
25
|
+
reason?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ReplayConfig {
|
|
28
|
+
model?: string;
|
|
29
|
+
temperature?: number;
|
|
30
|
+
maxTokens?: number;
|
|
31
|
+
apiBase?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface IntentCreateParams {
|
|
34
|
+
goal: string;
|
|
35
|
+
agentId?: string;
|
|
36
|
+
sessionId?: string;
|
|
37
|
+
origin?: OriginType;
|
|
38
|
+
constraints?: string[];
|
|
39
|
+
parentIntentId?: string;
|
|
40
|
+
mcpServer?: string;
|
|
41
|
+
toolName?: string;
|
|
42
|
+
environment?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface IntentResponse {
|
|
45
|
+
id: string;
|
|
46
|
+
goal: string;
|
|
47
|
+
origin: string;
|
|
48
|
+
constraints: string[];
|
|
49
|
+
agent_id: string;
|
|
50
|
+
session_id: string;
|
|
51
|
+
parent_intent_id?: string;
|
|
52
|
+
mcp_server?: string;
|
|
53
|
+
tool_name?: string;
|
|
54
|
+
environment?: string;
|
|
55
|
+
created_at: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ContextCreateParams {
|
|
58
|
+
intentId: string;
|
|
59
|
+
inputs: Record<string, unknown>;
|
|
60
|
+
externalVersions?: Record<string, string>;
|
|
61
|
+
}
|
|
62
|
+
export interface ContextResponse {
|
|
63
|
+
id: string;
|
|
64
|
+
intent_id: string;
|
|
65
|
+
inputs: Record<string, unknown>;
|
|
66
|
+
external_versions: Record<string, string>;
|
|
67
|
+
snapshot_hash: string;
|
|
68
|
+
created_at: string;
|
|
69
|
+
}
|
|
70
|
+
export interface DecisionCreateParams {
|
|
71
|
+
intentId: string;
|
|
72
|
+
contextId: string;
|
|
73
|
+
options: ActionOption[];
|
|
74
|
+
chosenAction: string;
|
|
75
|
+
confidence: number;
|
|
76
|
+
modelVersion: string;
|
|
77
|
+
rulesEvaluated?: string[];
|
|
78
|
+
reasoning?: string;
|
|
79
|
+
tags?: string[];
|
|
80
|
+
metadata?: Record<string, unknown>;
|
|
81
|
+
replayPrompt?: string;
|
|
82
|
+
replayConfig?: ReplayConfig;
|
|
83
|
+
}
|
|
84
|
+
export interface DecisionResponse {
|
|
85
|
+
id: string;
|
|
86
|
+
intent_id: string;
|
|
87
|
+
context_id: string;
|
|
88
|
+
options: Record<string, unknown>[];
|
|
89
|
+
chosen_action: string;
|
|
90
|
+
confidence: number;
|
|
91
|
+
model_version: string;
|
|
92
|
+
rules_evaluated: string[];
|
|
93
|
+
reasoning?: string;
|
|
94
|
+
tags: string[];
|
|
95
|
+
metadata: Record<string, unknown>;
|
|
96
|
+
replay_prompt?: string;
|
|
97
|
+
replay_config?: Record<string, unknown>;
|
|
98
|
+
created_at: string;
|
|
99
|
+
}
|
|
100
|
+
export interface ExecutionCreateParams {
|
|
101
|
+
decisionId: string;
|
|
102
|
+
action: string;
|
|
103
|
+
target: Record<string, unknown>;
|
|
104
|
+
result?: ResultType;
|
|
105
|
+
sideEffects?: string[];
|
|
106
|
+
revertAction?: Record<string, unknown>;
|
|
107
|
+
actor?: ActorType;
|
|
108
|
+
overrideReason?: string;
|
|
109
|
+
overriddenBy?: string;
|
|
110
|
+
}
|
|
111
|
+
export interface ExecutionResponse {
|
|
112
|
+
id: string;
|
|
113
|
+
decision_id: string;
|
|
114
|
+
action: string;
|
|
115
|
+
target: Record<string, unknown>;
|
|
116
|
+
result: string;
|
|
117
|
+
side_effects: string[];
|
|
118
|
+
revert_action?: Record<string, unknown>;
|
|
119
|
+
actor: string;
|
|
120
|
+
override_reason?: string;
|
|
121
|
+
overridden_by?: string;
|
|
122
|
+
created_at: string;
|
|
123
|
+
session_id?: string;
|
|
124
|
+
}
|
|
125
|
+
export interface TraceParams<T = unknown> {
|
|
126
|
+
agentId: string;
|
|
127
|
+
fn: () => T | Promise<T>;
|
|
128
|
+
metadata?: Record<string, unknown>;
|
|
129
|
+
tags?: string[];
|
|
130
|
+
sessionId?: string;
|
|
131
|
+
modelVersion?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface TraceResult<T = unknown> {
|
|
134
|
+
id: string;
|
|
135
|
+
output: T;
|
|
136
|
+
intentId: string;
|
|
137
|
+
contextId: string;
|
|
138
|
+
decisionId: string;
|
|
139
|
+
executionId: string;
|
|
140
|
+
}
|
|
141
|
+
export interface ReplayParams {
|
|
142
|
+
executionId?: string;
|
|
143
|
+
decisionId?: string;
|
|
144
|
+
compare?: boolean;
|
|
145
|
+
withContextId?: string;
|
|
146
|
+
forceLlmCall?: boolean;
|
|
147
|
+
}
|
|
148
|
+
export interface ReplayResult {
|
|
149
|
+
original_decision: DecisionResponse;
|
|
150
|
+
replayed_decision?: {
|
|
151
|
+
chosen_action: string;
|
|
152
|
+
confidence?: number;
|
|
153
|
+
reasoning?: string;
|
|
154
|
+
raw_response?: string;
|
|
155
|
+
};
|
|
156
|
+
diverged: boolean;
|
|
157
|
+
divergence_reason?: string;
|
|
158
|
+
replay_executed: boolean;
|
|
159
|
+
replay_error?: string;
|
|
160
|
+
diffs: Array<{
|
|
161
|
+
field: string;
|
|
162
|
+
original?: string;
|
|
163
|
+
replayed?: string;
|
|
164
|
+
changed: boolean;
|
|
165
|
+
}>;
|
|
166
|
+
drift_score: number;
|
|
167
|
+
diff: Record<string, unknown>;
|
|
168
|
+
}
|
|
169
|
+
export interface RevertParams {
|
|
170
|
+
executionId: string;
|
|
171
|
+
reason: string;
|
|
172
|
+
force?: boolean;
|
|
173
|
+
}
|
|
174
|
+
export interface RevertResponse {
|
|
175
|
+
execution_id: string;
|
|
176
|
+
revert_action: Record<string, unknown>;
|
|
177
|
+
status: string;
|
|
178
|
+
new_execution_id?: string;
|
|
179
|
+
}
|
|
180
|
+
export interface TimelineEntry {
|
|
181
|
+
type: string;
|
|
182
|
+
id: string;
|
|
183
|
+
timestamp: string;
|
|
184
|
+
summary: string;
|
|
185
|
+
data: Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
export interface SessionTimeline {
|
|
188
|
+
session_id: string;
|
|
189
|
+
entries: TimelineEntry[];
|
|
190
|
+
}
|
|
191
|
+
export interface ListDecisionsParams {
|
|
192
|
+
workspaceId?: string;
|
|
193
|
+
agentId?: string;
|
|
194
|
+
sessionId?: string;
|
|
195
|
+
environment?: string;
|
|
196
|
+
tags?: string[];
|
|
197
|
+
metadataKey?: string;
|
|
198
|
+
metadataValue?: string;
|
|
199
|
+
startTime?: Date;
|
|
200
|
+
endTime?: Date;
|
|
201
|
+
minConfidence?: number;
|
|
202
|
+
maxConfidence?: number;
|
|
203
|
+
limit?: number;
|
|
204
|
+
offset?: number;
|
|
205
|
+
}
|
|
206
|
+
export interface DriftCheckParams {
|
|
207
|
+
workspaceId?: string;
|
|
208
|
+
agentId?: string;
|
|
209
|
+
environment?: string;
|
|
210
|
+
sampleSize?: number;
|
|
211
|
+
timeWindowHours?: number;
|
|
212
|
+
}
|
|
213
|
+
export interface DriftCheckResult {
|
|
214
|
+
workspace_id: string;
|
|
215
|
+
agent_id?: string;
|
|
216
|
+
sample_size: number;
|
|
217
|
+
checked_count: number;
|
|
218
|
+
overall_drift_score: number;
|
|
219
|
+
diverged_count: number;
|
|
220
|
+
results: Array<{
|
|
221
|
+
decision_id: string;
|
|
222
|
+
execution_id: string;
|
|
223
|
+
original_action: string;
|
|
224
|
+
replayed_action?: string;
|
|
225
|
+
drift_score: number;
|
|
226
|
+
diverged: boolean;
|
|
227
|
+
divergence_reason?: string;
|
|
228
|
+
error?: string;
|
|
229
|
+
}>;
|
|
230
|
+
checked_at: string;
|
|
231
|
+
}
|
|
232
|
+
export interface ComplianceReportParams {
|
|
233
|
+
workspaceId?: string;
|
|
234
|
+
startDate?: Date;
|
|
235
|
+
endDate?: Date;
|
|
236
|
+
regulation?: "eu_ai_act" | "hipaa" | "soc2" | "all";
|
|
237
|
+
agentId?: string;
|
|
238
|
+
}
|
|
239
|
+
export interface ComplianceReport {
|
|
240
|
+
workspace_id: string;
|
|
241
|
+
generated_at: string;
|
|
242
|
+
period_start?: string;
|
|
243
|
+
period_end?: string;
|
|
244
|
+
regulation: string;
|
|
245
|
+
summary: {
|
|
246
|
+
total_decisions: number;
|
|
247
|
+
total_executions: number;
|
|
248
|
+
total_agents: number;
|
|
249
|
+
total_sessions: number;
|
|
250
|
+
success_rate: number;
|
|
251
|
+
human_override_count: number;
|
|
252
|
+
avg_confidence: number;
|
|
253
|
+
decisions_with_replay: number;
|
|
254
|
+
drift_events: number;
|
|
255
|
+
};
|
|
256
|
+
agents: Record<string, unknown>[];
|
|
257
|
+
audit_entries: Record<string, unknown>[];
|
|
258
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// --- Enums ---
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ActorType = exports.ResultType = exports.OriginType = void 0;
|
|
5
|
+
var OriginType;
|
|
6
|
+
(function (OriginType) {
|
|
7
|
+
OriginType["HUMAN"] = "human";
|
|
8
|
+
OriginType["AGENT"] = "agent";
|
|
9
|
+
OriginType["SCHEDULER"] = "scheduler";
|
|
10
|
+
})(OriginType || (exports.OriginType = OriginType = {}));
|
|
11
|
+
var ResultType;
|
|
12
|
+
(function (ResultType) {
|
|
13
|
+
ResultType["SUCCESS"] = "success";
|
|
14
|
+
ResultType["FAILURE"] = "failure";
|
|
15
|
+
ResultType["PENDING"] = "pending";
|
|
16
|
+
})(ResultType || (exports.ResultType = ResultType = {}));
|
|
17
|
+
var ActorType;
|
|
18
|
+
(function (ActorType) {
|
|
19
|
+
ActorType["AGENT"] = "agent";
|
|
20
|
+
ActorType["HUMAN"] = "human";
|
|
21
|
+
})(ActorType || (exports.ActorType = ActorType = {}));
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,gBAAgB;;;AAEhB,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,6BAAe,CAAA;IACf,qCAAuB,CAAA;AACzB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAED,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;AACrB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;AACjB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tenet-ai/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Node.js SDK for Tenet AI - Audit trail and replay for AI agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ai",
|
|
16
|
+
"agents",
|
|
17
|
+
"audit",
|
|
18
|
+
"logging",
|
|
19
|
+
"llm",
|
|
20
|
+
"observability",
|
|
21
|
+
"replay",
|
|
22
|
+
"drift-detection"
|
|
23
|
+
],
|
|
24
|
+
"author": "Vinay Badhan <vinay.badhan21.work@gmail.com>",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^25.3.0",
|
|
28
|
+
"typescript": "^5.3.0"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|