tracia 0.3.9 → 0.3.12
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/index.d.mts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +78 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -1
package/dist/index.d.mts
CHANGED
|
@@ -8,9 +8,17 @@ interface RunVariables {
|
|
|
8
8
|
}
|
|
9
9
|
interface RunOptions {
|
|
10
10
|
model?: string;
|
|
11
|
+
/** Run a specific prompt version instead of the latest */
|
|
12
|
+
version?: number;
|
|
11
13
|
tags?: string[];
|
|
12
14
|
userId?: string;
|
|
13
15
|
sessionId?: string;
|
|
16
|
+
/** Trace ID to group related spans together */
|
|
17
|
+
traceId?: string;
|
|
18
|
+
/** Parent span ID for chaining spans in a sequence */
|
|
19
|
+
parentSpanId?: string;
|
|
20
|
+
/** Full conversation messages for multi-turn (skips template rendering) */
|
|
21
|
+
messages?: LocalPromptMessage[];
|
|
14
22
|
}
|
|
15
23
|
interface TokenUsage {
|
|
16
24
|
inputTokens: number;
|
|
@@ -33,6 +41,8 @@ interface RunResult {
|
|
|
33
41
|
toolCalls?: ToolCall[];
|
|
34
42
|
/** Parsed JSON when the prompt has an output schema configured */
|
|
35
43
|
structuredOutput?: Record<string, unknown>;
|
|
44
|
+
/** Full conversation messages for multi-turn continuation */
|
|
45
|
+
messages?: LocalPromptMessage[];
|
|
36
46
|
}
|
|
37
47
|
declare enum TraciaErrorCode {
|
|
38
48
|
UNAUTHORIZED = "UNAUTHORIZED",
|
|
@@ -53,7 +63,8 @@ declare enum TraciaErrorCode {
|
|
|
53
63
|
declare enum LLMProvider {
|
|
54
64
|
OPENAI = "openai",
|
|
55
65
|
ANTHROPIC = "anthropic",
|
|
56
|
-
GOOGLE = "google"
|
|
66
|
+
GOOGLE = "google",
|
|
67
|
+
AMAZON_BEDROCK = "amazon_bedrock"
|
|
57
68
|
}
|
|
58
69
|
interface ApiSuccessResponse {
|
|
59
70
|
text: string;
|
|
@@ -66,6 +77,7 @@ interface ApiSuccessResponse {
|
|
|
66
77
|
finishReason?: FinishReason;
|
|
67
78
|
toolCalls?: ToolCall[];
|
|
68
79
|
structuredOutput?: Record<string, unknown>;
|
|
80
|
+
messages?: LocalPromptMessage[];
|
|
69
81
|
}
|
|
70
82
|
type MessageRole = 'system' | 'developer' | 'user' | 'assistant' | 'tool';
|
|
71
83
|
interface PromptMessage {
|
|
@@ -112,7 +124,7 @@ type SpanStatus = 'SUCCESS' | 'ERROR';
|
|
|
112
124
|
interface SpanListItem {
|
|
113
125
|
id: string;
|
|
114
126
|
spanId: string;
|
|
115
|
-
traceId: string;
|
|
127
|
+
traceId: string | null;
|
|
116
128
|
parentSpanId: string | null;
|
|
117
129
|
promptSlug: string;
|
|
118
130
|
model: string;
|
|
@@ -127,7 +139,7 @@ interface SpanListItem {
|
|
|
127
139
|
interface Span {
|
|
128
140
|
id: string;
|
|
129
141
|
spanId: string;
|
|
130
|
-
traceId: string;
|
|
142
|
+
traceId: string | null;
|
|
131
143
|
parentSpanId: string | null;
|
|
132
144
|
promptSlug: string;
|
|
133
145
|
promptVersion: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,17 @@ interface RunVariables {
|
|
|
8
8
|
}
|
|
9
9
|
interface RunOptions {
|
|
10
10
|
model?: string;
|
|
11
|
+
/** Run a specific prompt version instead of the latest */
|
|
12
|
+
version?: number;
|
|
11
13
|
tags?: string[];
|
|
12
14
|
userId?: string;
|
|
13
15
|
sessionId?: string;
|
|
16
|
+
/** Trace ID to group related spans together */
|
|
17
|
+
traceId?: string;
|
|
18
|
+
/** Parent span ID for chaining spans in a sequence */
|
|
19
|
+
parentSpanId?: string;
|
|
20
|
+
/** Full conversation messages for multi-turn (skips template rendering) */
|
|
21
|
+
messages?: LocalPromptMessage[];
|
|
14
22
|
}
|
|
15
23
|
interface TokenUsage {
|
|
16
24
|
inputTokens: number;
|
|
@@ -33,6 +41,8 @@ interface RunResult {
|
|
|
33
41
|
toolCalls?: ToolCall[];
|
|
34
42
|
/** Parsed JSON when the prompt has an output schema configured */
|
|
35
43
|
structuredOutput?: Record<string, unknown>;
|
|
44
|
+
/** Full conversation messages for multi-turn continuation */
|
|
45
|
+
messages?: LocalPromptMessage[];
|
|
36
46
|
}
|
|
37
47
|
declare enum TraciaErrorCode {
|
|
38
48
|
UNAUTHORIZED = "UNAUTHORIZED",
|
|
@@ -53,7 +63,8 @@ declare enum TraciaErrorCode {
|
|
|
53
63
|
declare enum LLMProvider {
|
|
54
64
|
OPENAI = "openai",
|
|
55
65
|
ANTHROPIC = "anthropic",
|
|
56
|
-
GOOGLE = "google"
|
|
66
|
+
GOOGLE = "google",
|
|
67
|
+
AMAZON_BEDROCK = "amazon_bedrock"
|
|
57
68
|
}
|
|
58
69
|
interface ApiSuccessResponse {
|
|
59
70
|
text: string;
|
|
@@ -66,6 +77,7 @@ interface ApiSuccessResponse {
|
|
|
66
77
|
finishReason?: FinishReason;
|
|
67
78
|
toolCalls?: ToolCall[];
|
|
68
79
|
structuredOutput?: Record<string, unknown>;
|
|
80
|
+
messages?: LocalPromptMessage[];
|
|
69
81
|
}
|
|
70
82
|
type MessageRole = 'system' | 'developer' | 'user' | 'assistant' | 'tool';
|
|
71
83
|
interface PromptMessage {
|
|
@@ -112,7 +124,7 @@ type SpanStatus = 'SUCCESS' | 'ERROR';
|
|
|
112
124
|
interface SpanListItem {
|
|
113
125
|
id: string;
|
|
114
126
|
spanId: string;
|
|
115
|
-
traceId: string;
|
|
127
|
+
traceId: string | null;
|
|
116
128
|
parentSpanId: string | null;
|
|
117
129
|
promptSlug: string;
|
|
118
130
|
model: string;
|
|
@@ -127,7 +139,7 @@ interface SpanListItem {
|
|
|
127
139
|
interface Span {
|
|
128
140
|
id: string;
|
|
129
141
|
spanId: string;
|
|
130
|
-
traceId: string;
|
|
142
|
+
traceId: string | null;
|
|
131
143
|
parentSpanId: string | null;
|
|
132
144
|
promptSlug: string;
|
|
133
145
|
promptVersion: number;
|
package/dist/index.js
CHANGED
|
@@ -72,11 +72,12 @@ var LLMProvider = /* @__PURE__ */ ((LLMProvider2) => {
|
|
|
72
72
|
LLMProvider2["OPENAI"] = "openai";
|
|
73
73
|
LLMProvider2["ANTHROPIC"] = "anthropic";
|
|
74
74
|
LLMProvider2["GOOGLE"] = "google";
|
|
75
|
+
LLMProvider2["AMAZON_BEDROCK"] = "amazon_bedrock";
|
|
75
76
|
return LLMProvider2;
|
|
76
77
|
})(LLMProvider || {});
|
|
77
78
|
|
|
78
79
|
// src/client.ts
|
|
79
|
-
var SDK_VERSION = "0.3.
|
|
80
|
+
var SDK_VERSION = "0.3.12";
|
|
80
81
|
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
81
82
|
function mapApiErrorCodeToTraciaErrorCode(apiCode) {
|
|
82
83
|
const codeMap = {
|
|
@@ -201,6 +202,9 @@ var Prompts = class {
|
|
|
201
202
|
if (options?.model) {
|
|
202
203
|
requestBody.model = options.model;
|
|
203
204
|
}
|
|
205
|
+
if (options?.version != null) {
|
|
206
|
+
requestBody.version = options.version;
|
|
207
|
+
}
|
|
204
208
|
if (options?.tags && options.tags.length > 0) {
|
|
205
209
|
requestBody.tags = options.tags;
|
|
206
210
|
}
|
|
@@ -210,6 +214,15 @@ var Prompts = class {
|
|
|
210
214
|
if (options?.sessionId) {
|
|
211
215
|
requestBody.sessionId = options.sessionId;
|
|
212
216
|
}
|
|
217
|
+
if (options?.traceId) {
|
|
218
|
+
requestBody.traceId = options.traceId;
|
|
219
|
+
}
|
|
220
|
+
if (options?.parentSpanId) {
|
|
221
|
+
requestBody.parentSpanId = options.parentSpanId;
|
|
222
|
+
}
|
|
223
|
+
if (options?.messages && options.messages.length > 0) {
|
|
224
|
+
requestBody.messages = options.messages;
|
|
225
|
+
}
|
|
213
226
|
const response = await this.client.post(
|
|
214
227
|
`/api/v1/prompts/${encodeURIComponent(slug)}/run`,
|
|
215
228
|
requestBody
|
|
@@ -224,7 +237,8 @@ var Prompts = class {
|
|
|
224
237
|
cost: response.cost,
|
|
225
238
|
finishReason: response.finishReason,
|
|
226
239
|
toolCalls: response.toolCalls,
|
|
227
|
-
structuredOutput: response.structuredOutput
|
|
240
|
+
structuredOutput: response.structuredOutput,
|
|
241
|
+
messages: response.messages
|
|
228
242
|
};
|
|
229
243
|
}
|
|
230
244
|
};
|
|
@@ -318,7 +332,17 @@ var MODEL_TO_PROVIDER = {
|
|
|
318
332
|
"gemini-2.5-flash-preview-09-2025": "google" /* GOOGLE */,
|
|
319
333
|
"gemini-2.5-pro": "google" /* GOOGLE */,
|
|
320
334
|
"gemini-3-pro-preview": "google" /* GOOGLE */,
|
|
321
|
-
"gemini-3-flash-preview": "google" /* GOOGLE
|
|
335
|
+
"gemini-3-flash-preview": "google" /* GOOGLE */,
|
|
336
|
+
// Amazon Bedrock
|
|
337
|
+
"anthropic.claude-haiku-4-5-20251001-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
338
|
+
"anthropic.claude-sonnet-4-20250514-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
339
|
+
"anthropic.claude-sonnet-4-5-20250929-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
340
|
+
"anthropic.claude-opus-4-5-20251101-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
341
|
+
"anthropic.claude-opus-4-6-v1": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
342
|
+
"amazon.nova-micro-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
343
|
+
"amazon.nova-lite-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
344
|
+
"amazon.nova-pro-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */,
|
|
345
|
+
"mistral.pixtral-large-2502-v1:0": "amazon_bedrock" /* AMAZON_BEDROCK */
|
|
322
346
|
};
|
|
323
347
|
function getProviderForModel(modelId) {
|
|
324
348
|
return MODEL_TO_PROVIDER[modelId];
|
|
@@ -329,6 +353,7 @@ var aiSdk = null;
|
|
|
329
353
|
var openaiProvider = null;
|
|
330
354
|
var anthropicProvider = null;
|
|
331
355
|
var googleProvider = null;
|
|
356
|
+
var bedrockProvider = null;
|
|
332
357
|
async function loadAISdk() {
|
|
333
358
|
if (aiSdk) return aiSdk;
|
|
334
359
|
try {
|
|
@@ -377,6 +402,18 @@ async function loadGoogleProvider() {
|
|
|
377
402
|
);
|
|
378
403
|
}
|
|
379
404
|
}
|
|
405
|
+
async function loadBedrockProvider() {
|
|
406
|
+
if (bedrockProvider) return bedrockProvider;
|
|
407
|
+
try {
|
|
408
|
+
bedrockProvider = await import("@ai-sdk/amazon-bedrock");
|
|
409
|
+
return bedrockProvider;
|
|
410
|
+
} catch {
|
|
411
|
+
throw new TraciaError(
|
|
412
|
+
"MISSING_PROVIDER_SDK" /* MISSING_PROVIDER_SDK */,
|
|
413
|
+
"Amazon Bedrock provider not installed. Install it with: npm install @ai-sdk/amazon-bedrock"
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
380
417
|
function combineAbortSignals(userSignal, timeoutMs) {
|
|
381
418
|
if (!timeoutMs && !userSignal) return void 0;
|
|
382
419
|
if (timeoutMs && !userSignal) return AbortSignal.timeout(timeoutMs);
|
|
@@ -398,10 +435,39 @@ function combineAbortSignals(userSignal, timeoutMs) {
|
|
|
398
435
|
function sanitizeErrorMessage(message) {
|
|
399
436
|
return message.replace(/\b(sk-|tr_|key-|api[_-]?key[=:\s]+)[a-zA-Z0-9_-]{10,}\b/gi, "[REDACTED]").replace(/Bearer\s+[a-zA-Z0-9_.-]+/gi, "Bearer [REDACTED]").replace(/Basic\s+[a-zA-Z0-9+/=]{20,}/gi, "Basic [REDACTED]").replace(/(authorization[=:\s]+)[^\s,}]+/gi, "$1[REDACTED]");
|
|
400
437
|
}
|
|
438
|
+
var BEDROCK_VENDOR_PREFIXES = ["anthropic.", "amazon.", "meta.", "mistral.", "cohere.", "deepseek."];
|
|
439
|
+
var KNOWN_REGION_PREFIXES = ["us", "eu", "ap", "sa", "ca", "me", "af"];
|
|
440
|
+
function getBedrockRegionPrefix(region) {
|
|
441
|
+
return region.split("-")[0];
|
|
442
|
+
}
|
|
443
|
+
function applyBedrockRegionPrefix(model, region) {
|
|
444
|
+
const prefix = getBedrockRegionPrefix(region);
|
|
445
|
+
const firstDot = model.indexOf(".");
|
|
446
|
+
if (firstDot === -1) return `${prefix}.${model}`;
|
|
447
|
+
const beforeDot = model.substring(0, firstDot);
|
|
448
|
+
if (KNOWN_REGION_PREFIXES.includes(beforeDot)) {
|
|
449
|
+
return `${prefix}.${model.substring(firstDot + 1)}`;
|
|
450
|
+
}
|
|
451
|
+
return `${prefix}.${model}`;
|
|
452
|
+
}
|
|
453
|
+
function isBedrockModel(model) {
|
|
454
|
+
if (BEDROCK_VENDOR_PREFIXES.some((prefix) => model.startsWith(prefix))) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
const firstDot = model.indexOf(".");
|
|
458
|
+
if (firstDot > 0 && KNOWN_REGION_PREFIXES.includes(model.substring(0, firstDot))) {
|
|
459
|
+
const afterRegion = model.substring(firstDot + 1);
|
|
460
|
+
return BEDROCK_VENDOR_PREFIXES.some((prefix) => afterRegion.startsWith(prefix));
|
|
461
|
+
}
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
401
464
|
function resolveProvider(model, explicitProvider) {
|
|
402
465
|
if (explicitProvider) return explicitProvider;
|
|
403
466
|
const fromRegistry = getProviderForModel(model);
|
|
404
467
|
if (fromRegistry) return fromRegistry;
|
|
468
|
+
if (isBedrockModel(model)) {
|
|
469
|
+
return "amazon_bedrock" /* AMAZON_BEDROCK */;
|
|
470
|
+
}
|
|
405
471
|
if (model.startsWith("gpt-") || model.startsWith("o1") || model.startsWith("o3") || model.startsWith("o4")) {
|
|
406
472
|
return "openai" /* OPENAI */;
|
|
407
473
|
}
|
|
@@ -433,6 +499,12 @@ async function getLanguageModel(provider, model, apiKey) {
|
|
|
433
499
|
const google = createGoogleGenerativeAI({ apiKey });
|
|
434
500
|
return google(model);
|
|
435
501
|
}
|
|
502
|
+
case "amazon_bedrock" /* AMAZON_BEDROCK */: {
|
|
503
|
+
const { createAmazonBedrock } = await loadBedrockProvider();
|
|
504
|
+
const region = process.env.AWS_REGION ?? "eu-central-1";
|
|
505
|
+
const bedrock = apiKey ? createAmazonBedrock({ apiKey, region }) : createAmazonBedrock({ region });
|
|
506
|
+
return bedrock(applyBedrockRegionPrefix(model, region));
|
|
507
|
+
}
|
|
436
508
|
default:
|
|
437
509
|
throw new TraciaError(
|
|
438
510
|
"UNSUPPORTED_MODEL" /* UNSUPPORTED_MODEL */,
|
|
@@ -1001,7 +1073,8 @@ var SPAN_STATUS_ERROR = "ERROR";
|
|
|
1001
1073
|
var ENV_VAR_MAP = {
|
|
1002
1074
|
["openai" /* OPENAI */]: "OPENAI_API_KEY",
|
|
1003
1075
|
["anthropic" /* ANTHROPIC */]: "ANTHROPIC_API_KEY",
|
|
1004
|
-
["google" /* GOOGLE */]: "GOOGLE_API_KEY"
|
|
1076
|
+
["google" /* GOOGLE */]: "GOOGLE_API_KEY",
|
|
1077
|
+
["amazon_bedrock" /* AMAZON_BEDROCK */]: "BEDROCK_API_KEY"
|
|
1005
1078
|
};
|
|
1006
1079
|
function convertResponsesItemToMessage(item) {
|
|
1007
1080
|
if ("role" in item && (item.role === "developer" || item.role === "user")) {
|
|
@@ -1676,6 +1749,7 @@ var Tracia = class {
|
|
|
1676
1749
|
const envVar = ENV_VAR_MAP[provider];
|
|
1677
1750
|
const key = process.env[envVar];
|
|
1678
1751
|
if (!key) {
|
|
1752
|
+
if (provider === "amazon_bedrock" /* AMAZON_BEDROCK */) return "";
|
|
1679
1753
|
throw new TraciaError(
|
|
1680
1754
|
"MISSING_PROVIDER_API_KEY" /* MISSING_PROVIDER_API_KEY */,
|
|
1681
1755
|
`Missing API key for ${provider}. Set the ${envVar} environment variable or provide providerApiKey in options.`
|