tracia 0.3.0 → 0.3.2
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 +9 -1
- package/dist/index.d.mts +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.js +26 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Tracia SDK
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for [Tracia](https://tracia.io)
|
|
3
|
+
TypeScript SDK for [Tracia](https://tracia.io) - store, test, and trace LLM prompts.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -15,8 +15,16 @@ import { Tracia } from 'tracia';
|
|
|
15
15
|
|
|
16
16
|
const tracia = new Tracia({ apiKey: process.env.TRACIA_API_KEY });
|
|
17
17
|
|
|
18
|
+
// Run a prompt stored in Tracia
|
|
18
19
|
const result = await tracia.prompts.run('welcome-email', { name: 'Alice' });
|
|
19
20
|
console.log(result.text);
|
|
21
|
+
|
|
22
|
+
// Or call LLM directly with automatic tracing
|
|
23
|
+
const response = await tracia.runLocal({
|
|
24
|
+
model: 'gpt-4o',
|
|
25
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
26
|
+
});
|
|
27
|
+
console.log(response.text);
|
|
20
28
|
```
|
|
21
29
|
|
|
22
30
|
## Documentation
|
package/dist/index.d.mts
CHANGED
|
@@ -613,8 +613,13 @@ declare class TraciaSession {
|
|
|
613
613
|
private readonly tracia;
|
|
614
614
|
private traceId;
|
|
615
615
|
private lastSpanId;
|
|
616
|
-
/**
|
|
617
|
-
|
|
616
|
+
/**
|
|
617
|
+
* @internal
|
|
618
|
+
* @param tracia - The Tracia client instance
|
|
619
|
+
* @param initialTraceId - Optional trace ID to continue an existing trace
|
|
620
|
+
* @param initialParentSpanId - Optional parent span ID to chain from
|
|
621
|
+
*/
|
|
622
|
+
constructor(tracia: Tracia, initialTraceId?: string, initialParentSpanId?: string);
|
|
618
623
|
/**
|
|
619
624
|
* Get the current session's trace ID (the ID that groups all spans together).
|
|
620
625
|
* Returns null if no spans have been made yet.
|
|
@@ -784,11 +789,19 @@ declare class Tracia {
|
|
|
784
789
|
* Sessions automatically chain spans by setting traceId and parentSpanId,
|
|
785
790
|
* creating a linked sequence of spans that can be viewed together in the Tracia dashboard.
|
|
786
791
|
*
|
|
792
|
+
* @param options - Optional configuration for the session
|
|
793
|
+
* @param options.traceId - Continue an existing trace instead of starting a new one
|
|
794
|
+
* @param options.parentSpanId - Chain from an existing span
|
|
795
|
+
*
|
|
787
796
|
* @example
|
|
788
797
|
* ```typescript
|
|
798
|
+
* // Start a new trace
|
|
789
799
|
* const session = tracia.createSession()
|
|
790
800
|
*
|
|
791
|
-
* //
|
|
801
|
+
* // Or continue an existing trace (e.g., across HTTP requests)
|
|
802
|
+
* const session = tracia.createSession({ traceId: previousTraceId })
|
|
803
|
+
*
|
|
804
|
+
* // First call - creates or continues the trace group
|
|
792
805
|
* const result1 = await session.runLocal({
|
|
793
806
|
* model: 'gpt-4o',
|
|
794
807
|
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
@@ -801,7 +814,10 @@ declare class Tracia {
|
|
|
801
814
|
* })
|
|
802
815
|
* ```
|
|
803
816
|
*/
|
|
804
|
-
createSession(
|
|
817
|
+
createSession(options?: {
|
|
818
|
+
traceId?: string;
|
|
819
|
+
parentSpanId?: string;
|
|
820
|
+
}): TraciaSession;
|
|
805
821
|
private validateRunLocalInput;
|
|
806
822
|
private scheduleSpanCreation;
|
|
807
823
|
private createSpanWithRetry;
|
package/dist/index.d.ts
CHANGED
|
@@ -613,8 +613,13 @@ declare class TraciaSession {
|
|
|
613
613
|
private readonly tracia;
|
|
614
614
|
private traceId;
|
|
615
615
|
private lastSpanId;
|
|
616
|
-
/**
|
|
617
|
-
|
|
616
|
+
/**
|
|
617
|
+
* @internal
|
|
618
|
+
* @param tracia - The Tracia client instance
|
|
619
|
+
* @param initialTraceId - Optional trace ID to continue an existing trace
|
|
620
|
+
* @param initialParentSpanId - Optional parent span ID to chain from
|
|
621
|
+
*/
|
|
622
|
+
constructor(tracia: Tracia, initialTraceId?: string, initialParentSpanId?: string);
|
|
618
623
|
/**
|
|
619
624
|
* Get the current session's trace ID (the ID that groups all spans together).
|
|
620
625
|
* Returns null if no spans have been made yet.
|
|
@@ -784,11 +789,19 @@ declare class Tracia {
|
|
|
784
789
|
* Sessions automatically chain spans by setting traceId and parentSpanId,
|
|
785
790
|
* creating a linked sequence of spans that can be viewed together in the Tracia dashboard.
|
|
786
791
|
*
|
|
792
|
+
* @param options - Optional configuration for the session
|
|
793
|
+
* @param options.traceId - Continue an existing trace instead of starting a new one
|
|
794
|
+
* @param options.parentSpanId - Chain from an existing span
|
|
795
|
+
*
|
|
787
796
|
* @example
|
|
788
797
|
* ```typescript
|
|
798
|
+
* // Start a new trace
|
|
789
799
|
* const session = tracia.createSession()
|
|
790
800
|
*
|
|
791
|
-
* //
|
|
801
|
+
* // Or continue an existing trace (e.g., across HTTP requests)
|
|
802
|
+
* const session = tracia.createSession({ traceId: previousTraceId })
|
|
803
|
+
*
|
|
804
|
+
* // First call - creates or continues the trace group
|
|
792
805
|
* const result1 = await session.runLocal({
|
|
793
806
|
* model: 'gpt-4o',
|
|
794
807
|
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
@@ -801,7 +814,10 @@ declare class Tracia {
|
|
|
801
814
|
* })
|
|
802
815
|
* ```
|
|
803
816
|
*/
|
|
804
|
-
createSession(
|
|
817
|
+
createSession(options?: {
|
|
818
|
+
traceId?: string;
|
|
819
|
+
parentSpanId?: string;
|
|
820
|
+
}): TraciaSession;
|
|
805
821
|
private validateRunLocalInput;
|
|
806
822
|
private scheduleSpanCreation;
|
|
807
823
|
private createSpanWithRetry;
|
package/dist/index.js
CHANGED
|
@@ -76,7 +76,7 @@ var LLMProvider = /* @__PURE__ */ ((LLMProvider2) => {
|
|
|
76
76
|
})(LLMProvider || {});
|
|
77
77
|
|
|
78
78
|
// src/client.ts
|
|
79
|
-
var SDK_VERSION = "0.3.
|
|
79
|
+
var SDK_VERSION = "0.3.2";
|
|
80
80
|
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
81
81
|
function mapApiErrorCodeToTraciaErrorCode(apiCode) {
|
|
82
82
|
const codeMap = {
|
|
@@ -764,11 +764,18 @@ function responsesStream(options) {
|
|
|
764
764
|
|
|
765
765
|
// src/session.ts
|
|
766
766
|
var TraciaSession = class {
|
|
767
|
-
/**
|
|
768
|
-
|
|
767
|
+
/**
|
|
768
|
+
* @internal
|
|
769
|
+
* @param tracia - The Tracia client instance
|
|
770
|
+
* @param initialTraceId - Optional trace ID to continue an existing trace
|
|
771
|
+
* @param initialParentSpanId - Optional parent span ID to chain from
|
|
772
|
+
*/
|
|
773
|
+
constructor(tracia, initialTraceId, initialParentSpanId) {
|
|
769
774
|
this.traceId = null;
|
|
770
775
|
this.lastSpanId = null;
|
|
771
776
|
this.tracia = tracia;
|
|
777
|
+
this.traceId = initialTraceId ?? null;
|
|
778
|
+
this.lastSpanId = initialParentSpanId ?? null;
|
|
772
779
|
}
|
|
773
780
|
/**
|
|
774
781
|
* Get the current session's trace ID (the ID that groups all spans together).
|
|
@@ -1091,7 +1098,7 @@ var Tracia = class {
|
|
|
1091
1098
|
topP: input.topP,
|
|
1092
1099
|
tools: input.tools,
|
|
1093
1100
|
toolCalls: completionResult?.toolCalls,
|
|
1094
|
-
traceId
|
|
1101
|
+
traceId,
|
|
1095
1102
|
parentSpanId: input.parentSpanId
|
|
1096
1103
|
});
|
|
1097
1104
|
}
|
|
@@ -1254,7 +1261,7 @@ var Tracia = class {
|
|
|
1254
1261
|
name: tc.name,
|
|
1255
1262
|
arguments: tc.arguments
|
|
1256
1263
|
})),
|
|
1257
|
-
traceId
|
|
1264
|
+
traceId,
|
|
1258
1265
|
parentSpanId: input.parentSpanId
|
|
1259
1266
|
});
|
|
1260
1267
|
}
|
|
@@ -1290,7 +1297,7 @@ var Tracia = class {
|
|
|
1290
1297
|
userId: input.userId,
|
|
1291
1298
|
sessionId: input.sessionId,
|
|
1292
1299
|
tools: input.tools,
|
|
1293
|
-
traceId
|
|
1300
|
+
traceId,
|
|
1294
1301
|
parentSpanId: input.parentSpanId
|
|
1295
1302
|
});
|
|
1296
1303
|
}
|
|
@@ -1382,7 +1389,7 @@ var Tracia = class {
|
|
|
1382
1389
|
topP: input.topP,
|
|
1383
1390
|
tools: input.tools,
|
|
1384
1391
|
toolCalls: completionResult.toolCalls,
|
|
1385
|
-
traceId
|
|
1392
|
+
traceId,
|
|
1386
1393
|
parentSpanId: input.parentSpanId
|
|
1387
1394
|
});
|
|
1388
1395
|
}
|
|
@@ -1431,7 +1438,7 @@ var Tracia = class {
|
|
|
1431
1438
|
temperature: input.temperature,
|
|
1432
1439
|
maxOutputTokens: input.maxOutputTokens,
|
|
1433
1440
|
topP: input.topP,
|
|
1434
|
-
traceId
|
|
1441
|
+
traceId,
|
|
1435
1442
|
parentSpanId: input.parentSpanId
|
|
1436
1443
|
});
|
|
1437
1444
|
}
|
|
@@ -1500,11 +1507,19 @@ var Tracia = class {
|
|
|
1500
1507
|
* Sessions automatically chain spans by setting traceId and parentSpanId,
|
|
1501
1508
|
* creating a linked sequence of spans that can be viewed together in the Tracia dashboard.
|
|
1502
1509
|
*
|
|
1510
|
+
* @param options - Optional configuration for the session
|
|
1511
|
+
* @param options.traceId - Continue an existing trace instead of starting a new one
|
|
1512
|
+
* @param options.parentSpanId - Chain from an existing span
|
|
1513
|
+
*
|
|
1503
1514
|
* @example
|
|
1504
1515
|
* ```typescript
|
|
1516
|
+
* // Start a new trace
|
|
1505
1517
|
* const session = tracia.createSession()
|
|
1506
1518
|
*
|
|
1507
|
-
* //
|
|
1519
|
+
* // Or continue an existing trace (e.g., across HTTP requests)
|
|
1520
|
+
* const session = tracia.createSession({ traceId: previousTraceId })
|
|
1521
|
+
*
|
|
1522
|
+
* // First call - creates or continues the trace group
|
|
1508
1523
|
* const result1 = await session.runLocal({
|
|
1509
1524
|
* model: 'gpt-4o',
|
|
1510
1525
|
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
@@ -1517,8 +1532,8 @@ var Tracia = class {
|
|
|
1517
1532
|
* })
|
|
1518
1533
|
* ```
|
|
1519
1534
|
*/
|
|
1520
|
-
createSession() {
|
|
1521
|
-
return new TraciaSession(this);
|
|
1535
|
+
createSession(options) {
|
|
1536
|
+
return new TraciaSession(this, options?.traceId, options?.parentSpanId);
|
|
1522
1537
|
}
|
|
1523
1538
|
validateRunLocalInput(input) {
|
|
1524
1539
|
if (!input.model || input.model.trim() === "") {
|