tracia 0.3.1 → 0.3.3
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 +24 -6
- package/dist/index.d.ts +24 -6
- package/dist/index.js +43 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -267,8 +267,8 @@ interface RunLocalInput {
|
|
|
267
267
|
stopSequences?: string[];
|
|
268
268
|
/** Timeout in milliseconds for the LLM call */
|
|
269
269
|
timeoutMs?: number;
|
|
270
|
-
/** Provider-specific options passed directly to the SDK */
|
|
271
|
-
customOptions?: Record<string, unknown
|
|
270
|
+
/** Provider-specific options passed directly to the AI SDK (e.g., { openai: { strictJsonSchema: true } }) */
|
|
271
|
+
customOptions?: Record<string, Record<string, unknown>>;
|
|
272
272
|
variables?: Record<string, string>;
|
|
273
273
|
providerApiKey?: string;
|
|
274
274
|
tags?: string[];
|
|
@@ -466,6 +466,8 @@ interface RunResponsesInput {
|
|
|
466
466
|
traceId?: string;
|
|
467
467
|
/** Parent span ID for chaining spans in a sequence */
|
|
468
468
|
parentSpanId?: string;
|
|
469
|
+
/** Provider-specific options passed directly to the AI SDK (e.g., { openai: { strictJsonSchema: true } }) */
|
|
470
|
+
customOptions?: Record<string, Record<string, unknown>>;
|
|
469
471
|
}
|
|
470
472
|
/**
|
|
471
473
|
* Final result from a Responses API call.
|
|
@@ -613,8 +615,13 @@ declare class TraciaSession {
|
|
|
613
615
|
private readonly tracia;
|
|
614
616
|
private traceId;
|
|
615
617
|
private lastSpanId;
|
|
616
|
-
/**
|
|
617
|
-
|
|
618
|
+
/**
|
|
619
|
+
* @internal
|
|
620
|
+
* @param tracia - The Tracia client instance
|
|
621
|
+
* @param initialTraceId - Optional trace ID to continue an existing trace
|
|
622
|
+
* @param initialParentSpanId - Optional parent span ID to chain from
|
|
623
|
+
*/
|
|
624
|
+
constructor(tracia: Tracia, initialTraceId?: string, initialParentSpanId?: string);
|
|
618
625
|
/**
|
|
619
626
|
* Get the current session's trace ID (the ID that groups all spans together).
|
|
620
627
|
* Returns null if no spans have been made yet.
|
|
@@ -784,11 +791,19 @@ declare class Tracia {
|
|
|
784
791
|
* Sessions automatically chain spans by setting traceId and parentSpanId,
|
|
785
792
|
* creating a linked sequence of spans that can be viewed together in the Tracia dashboard.
|
|
786
793
|
*
|
|
794
|
+
* @param options - Optional configuration for the session
|
|
795
|
+
* @param options.traceId - Continue an existing trace instead of starting a new one
|
|
796
|
+
* @param options.parentSpanId - Chain from an existing span
|
|
797
|
+
*
|
|
787
798
|
* @example
|
|
788
799
|
* ```typescript
|
|
800
|
+
* // Start a new trace
|
|
789
801
|
* const session = tracia.createSession()
|
|
790
802
|
*
|
|
791
|
-
* //
|
|
803
|
+
* // Or continue an existing trace (e.g., across HTTP requests)
|
|
804
|
+
* const session = tracia.createSession({ traceId: previousTraceId })
|
|
805
|
+
*
|
|
806
|
+
* // First call - creates or continues the trace group
|
|
792
807
|
* const result1 = await session.runLocal({
|
|
793
808
|
* model: 'gpt-4o',
|
|
794
809
|
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
@@ -801,7 +816,10 @@ declare class Tracia {
|
|
|
801
816
|
* })
|
|
802
817
|
* ```
|
|
803
818
|
*/
|
|
804
|
-
createSession(
|
|
819
|
+
createSession(options?: {
|
|
820
|
+
traceId?: string;
|
|
821
|
+
parentSpanId?: string;
|
|
822
|
+
}): TraciaSession;
|
|
805
823
|
private validateRunLocalInput;
|
|
806
824
|
private scheduleSpanCreation;
|
|
807
825
|
private createSpanWithRetry;
|
package/dist/index.d.ts
CHANGED
|
@@ -267,8 +267,8 @@ interface RunLocalInput {
|
|
|
267
267
|
stopSequences?: string[];
|
|
268
268
|
/** Timeout in milliseconds for the LLM call */
|
|
269
269
|
timeoutMs?: number;
|
|
270
|
-
/** Provider-specific options passed directly to the SDK */
|
|
271
|
-
customOptions?: Record<string, unknown
|
|
270
|
+
/** Provider-specific options passed directly to the AI SDK (e.g., { openai: { strictJsonSchema: true } }) */
|
|
271
|
+
customOptions?: Record<string, Record<string, unknown>>;
|
|
272
272
|
variables?: Record<string, string>;
|
|
273
273
|
providerApiKey?: string;
|
|
274
274
|
tags?: string[];
|
|
@@ -466,6 +466,8 @@ interface RunResponsesInput {
|
|
|
466
466
|
traceId?: string;
|
|
467
467
|
/** Parent span ID for chaining spans in a sequence */
|
|
468
468
|
parentSpanId?: string;
|
|
469
|
+
/** Provider-specific options passed directly to the AI SDK (e.g., { openai: { strictJsonSchema: true } }) */
|
|
470
|
+
customOptions?: Record<string, Record<string, unknown>>;
|
|
469
471
|
}
|
|
470
472
|
/**
|
|
471
473
|
* Final result from a Responses API call.
|
|
@@ -613,8 +615,13 @@ declare class TraciaSession {
|
|
|
613
615
|
private readonly tracia;
|
|
614
616
|
private traceId;
|
|
615
617
|
private lastSpanId;
|
|
616
|
-
/**
|
|
617
|
-
|
|
618
|
+
/**
|
|
619
|
+
* @internal
|
|
620
|
+
* @param tracia - The Tracia client instance
|
|
621
|
+
* @param initialTraceId - Optional trace ID to continue an existing trace
|
|
622
|
+
* @param initialParentSpanId - Optional parent span ID to chain from
|
|
623
|
+
*/
|
|
624
|
+
constructor(tracia: Tracia, initialTraceId?: string, initialParentSpanId?: string);
|
|
618
625
|
/**
|
|
619
626
|
* Get the current session's trace ID (the ID that groups all spans together).
|
|
620
627
|
* Returns null if no spans have been made yet.
|
|
@@ -784,11 +791,19 @@ declare class Tracia {
|
|
|
784
791
|
* Sessions automatically chain spans by setting traceId and parentSpanId,
|
|
785
792
|
* creating a linked sequence of spans that can be viewed together in the Tracia dashboard.
|
|
786
793
|
*
|
|
794
|
+
* @param options - Optional configuration for the session
|
|
795
|
+
* @param options.traceId - Continue an existing trace instead of starting a new one
|
|
796
|
+
* @param options.parentSpanId - Chain from an existing span
|
|
797
|
+
*
|
|
787
798
|
* @example
|
|
788
799
|
* ```typescript
|
|
800
|
+
* // Start a new trace
|
|
789
801
|
* const session = tracia.createSession()
|
|
790
802
|
*
|
|
791
|
-
* //
|
|
803
|
+
* // Or continue an existing trace (e.g., across HTTP requests)
|
|
804
|
+
* const session = tracia.createSession({ traceId: previousTraceId })
|
|
805
|
+
*
|
|
806
|
+
* // First call - creates or continues the trace group
|
|
792
807
|
* const result1 = await session.runLocal({
|
|
793
808
|
* model: 'gpt-4o',
|
|
794
809
|
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
@@ -801,7 +816,10 @@ declare class Tracia {
|
|
|
801
816
|
* })
|
|
802
817
|
* ```
|
|
803
818
|
*/
|
|
804
|
-
createSession(
|
|
819
|
+
createSession(options?: {
|
|
820
|
+
traceId?: string;
|
|
821
|
+
parentSpanId?: string;
|
|
822
|
+
}): TraciaSession;
|
|
805
823
|
private validateRunLocalInput;
|
|
806
824
|
private scheduleSpanCreation;
|
|
807
825
|
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.3";
|
|
80
80
|
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
81
81
|
function mapApiErrorCodeToTraciaErrorCode(apiCode) {
|
|
82
82
|
const codeMap = {
|
|
@@ -513,6 +513,17 @@ function extractToolCalls(toolCalls) {
|
|
|
513
513
|
arguments: tc.input ?? {}
|
|
514
514
|
}));
|
|
515
515
|
}
|
|
516
|
+
function mergeProviderOptions(userOptions) {
|
|
517
|
+
const defaults = {
|
|
518
|
+
openai: { strictJsonSchema: false }
|
|
519
|
+
};
|
|
520
|
+
if (!userOptions) return defaults;
|
|
521
|
+
const merged = { ...defaults };
|
|
522
|
+
for (const [provider, options] of Object.entries(userOptions)) {
|
|
523
|
+
merged[provider] = { ...merged[provider], ...options };
|
|
524
|
+
}
|
|
525
|
+
return merged;
|
|
526
|
+
}
|
|
516
527
|
async function complete(options) {
|
|
517
528
|
const { generateText } = await loadAISdk();
|
|
518
529
|
const provider = resolveProvider(options.model, options.provider);
|
|
@@ -531,7 +542,8 @@ async function complete(options) {
|
|
|
531
542
|
stopSequences: options.stopSequences,
|
|
532
543
|
tools: convertedTools,
|
|
533
544
|
toolChoice: convertedToolChoice,
|
|
534
|
-
abortSignal: options.timeoutMs ? AbortSignal.timeout(options.timeoutMs) : void 0
|
|
545
|
+
abortSignal: options.timeoutMs ? AbortSignal.timeout(options.timeoutMs) : void 0,
|
|
546
|
+
providerOptions: mergeProviderOptions(options.providerOptions)
|
|
535
547
|
});
|
|
536
548
|
const toolCalls = extractToolCalls(result.toolCalls);
|
|
537
549
|
return {
|
|
@@ -578,7 +590,8 @@ function stream(options) {
|
|
|
578
590
|
stopSequences: options.stopSequences,
|
|
579
591
|
tools: convertedTools,
|
|
580
592
|
toolChoice: convertedToolChoice,
|
|
581
|
-
abortSignal
|
|
593
|
+
abortSignal,
|
|
594
|
+
providerOptions: mergeProviderOptions(options.providerOptions)
|
|
582
595
|
});
|
|
583
596
|
for await (const chunk of result.textStream) {
|
|
584
597
|
yield chunk;
|
|
@@ -683,7 +696,8 @@ function responsesStream(options) {
|
|
|
683
696
|
messages: convertedMessages,
|
|
684
697
|
maxOutputTokens: options.maxOutputTokens,
|
|
685
698
|
tools: convertedTools,
|
|
686
|
-
abortSignal
|
|
699
|
+
abortSignal,
|
|
700
|
+
providerOptions: mergeProviderOptions(options.providerOptions)
|
|
687
701
|
});
|
|
688
702
|
for await (const chunk of result.textStream) {
|
|
689
703
|
fullText += chunk;
|
|
@@ -764,11 +778,18 @@ function responsesStream(options) {
|
|
|
764
778
|
|
|
765
779
|
// src/session.ts
|
|
766
780
|
var TraciaSession = class {
|
|
767
|
-
/**
|
|
768
|
-
|
|
781
|
+
/**
|
|
782
|
+
* @internal
|
|
783
|
+
* @param tracia - The Tracia client instance
|
|
784
|
+
* @param initialTraceId - Optional trace ID to continue an existing trace
|
|
785
|
+
* @param initialParentSpanId - Optional parent span ID to chain from
|
|
786
|
+
*/
|
|
787
|
+
constructor(tracia, initialTraceId, initialParentSpanId) {
|
|
769
788
|
this.traceId = null;
|
|
770
789
|
this.lastSpanId = null;
|
|
771
790
|
this.tracia = tracia;
|
|
791
|
+
this.traceId = initialTraceId ?? null;
|
|
792
|
+
this.lastSpanId = initialParentSpanId ?? null;
|
|
772
793
|
}
|
|
773
794
|
/**
|
|
774
795
|
* Get the current session's trace ID (the ID that groups all spans together).
|
|
@@ -1059,6 +1080,7 @@ var Tracia = class {
|
|
|
1059
1080
|
stopSequences: input.stopSequences,
|
|
1060
1081
|
tools: input.tools,
|
|
1061
1082
|
toolChoice: input.toolChoice,
|
|
1083
|
+
providerOptions: input.customOptions,
|
|
1062
1084
|
timeoutMs: input.timeoutMs
|
|
1063
1085
|
});
|
|
1064
1086
|
} catch (error) {
|
|
@@ -1217,7 +1239,8 @@ var Tracia = class {
|
|
|
1217
1239
|
tools: input.tools,
|
|
1218
1240
|
maxOutputTokens: input.maxOutputTokens,
|
|
1219
1241
|
timeoutMs: input.timeoutMs,
|
|
1220
|
-
signal
|
|
1242
|
+
signal,
|
|
1243
|
+
providerOptions: input.customOptions
|
|
1221
1244
|
});
|
|
1222
1245
|
let collectedText = "";
|
|
1223
1246
|
const scheduleSpan = this.scheduleSpanCreation.bind(this);
|
|
@@ -1347,7 +1370,8 @@ var Tracia = class {
|
|
|
1347
1370
|
tools: input.tools,
|
|
1348
1371
|
toolChoice: input.toolChoice,
|
|
1349
1372
|
timeoutMs: input.timeoutMs,
|
|
1350
|
-
signal
|
|
1373
|
+
signal,
|
|
1374
|
+
providerOptions: input.customOptions
|
|
1351
1375
|
});
|
|
1352
1376
|
let collectedText = "";
|
|
1353
1377
|
const scheduleSpan = this.scheduleSpanCreation.bind(this);
|
|
@@ -1500,11 +1524,19 @@ var Tracia = class {
|
|
|
1500
1524
|
* Sessions automatically chain spans by setting traceId and parentSpanId,
|
|
1501
1525
|
* creating a linked sequence of spans that can be viewed together in the Tracia dashboard.
|
|
1502
1526
|
*
|
|
1527
|
+
* @param options - Optional configuration for the session
|
|
1528
|
+
* @param options.traceId - Continue an existing trace instead of starting a new one
|
|
1529
|
+
* @param options.parentSpanId - Chain from an existing span
|
|
1530
|
+
*
|
|
1503
1531
|
* @example
|
|
1504
1532
|
* ```typescript
|
|
1533
|
+
* // Start a new trace
|
|
1505
1534
|
* const session = tracia.createSession()
|
|
1506
1535
|
*
|
|
1507
|
-
* //
|
|
1536
|
+
* // Or continue an existing trace (e.g., across HTTP requests)
|
|
1537
|
+
* const session = tracia.createSession({ traceId: previousTraceId })
|
|
1538
|
+
*
|
|
1539
|
+
* // First call - creates or continues the trace group
|
|
1508
1540
|
* const result1 = await session.runLocal({
|
|
1509
1541
|
* model: 'gpt-4o',
|
|
1510
1542
|
* messages: [{ role: 'user', content: 'What is the weather?' }],
|
|
@@ -1517,8 +1549,8 @@ var Tracia = class {
|
|
|
1517
1549
|
* })
|
|
1518
1550
|
* ```
|
|
1519
1551
|
*/
|
|
1520
|
-
createSession() {
|
|
1521
|
-
return new TraciaSession(this);
|
|
1552
|
+
createSession(options) {
|
|
1553
|
+
return new TraciaSession(this, options?.traceId, options?.parentSpanId);
|
|
1522
1554
|
}
|
|
1523
1555
|
validateRunLocalInput(input) {
|
|
1524
1556
|
if (!input.model || input.model.trim() === "") {
|