netra-sdk 1.9.0 → 1.10.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 +68 -0
- package/dist/index.cjs +146 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -4
- package/dist/index.d.ts +68 -4
- package/dist/index.js +144 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.cts
CHANGED
|
@@ -77,7 +77,7 @@ declare const DEFAULT_INSTRUMENTS: Set<NetraInstruments>;
|
|
|
77
77
|
declare class Config {
|
|
78
78
|
static readonly SDK_NAME = "netra";
|
|
79
79
|
static readonly LIBRARY_NAME = "netra";
|
|
80
|
-
static readonly LIBRARY_VERSION = "1.
|
|
80
|
+
static readonly LIBRARY_VERSION = "1.10.0";
|
|
81
81
|
static readonly TRIAL_BLOCK_DURATION_SECONDS = 900;
|
|
82
82
|
static readonly TRACE_ORIGIN_KEY = "netra.trace.origin";
|
|
83
83
|
static readonly TRACE_ORIGIN_EVALUATION = "evaluation";
|
|
@@ -883,9 +883,18 @@ declare class Dashboard {
|
|
|
883
883
|
/**
|
|
884
884
|
* Prompts API Models
|
|
885
885
|
*/
|
|
886
|
+
/** Default TTL (seconds) for prompt cache when useCache is true and cacheTtl is omitted. */
|
|
887
|
+
declare const PROMPT_CACHE_TTL_SECONDS = 60;
|
|
886
888
|
interface GetPromptParams {
|
|
887
889
|
name: string;
|
|
888
890
|
label?: string;
|
|
891
|
+
/** When true, serve from in-memory cache when available (default: false). */
|
|
892
|
+
useCache?: boolean;
|
|
893
|
+
/**
|
|
894
|
+
* Per-call TTL in seconds.
|
|
895
|
+
* When omitted with useCache: true, uses PROMPT_CACHE_TTL_SECONDS (60).
|
|
896
|
+
*/
|
|
897
|
+
cacheTtl?: number;
|
|
889
898
|
}
|
|
890
899
|
/**
|
|
891
900
|
* Prompt response is intentionally flexible because
|
|
@@ -896,16 +905,67 @@ type PromptResponse = Record<string, any>;
|
|
|
896
905
|
declare class Prompts {
|
|
897
906
|
private config;
|
|
898
907
|
private client;
|
|
908
|
+
private cache;
|
|
899
909
|
constructor(config: Config);
|
|
910
|
+
/** Clear all cached prompt entries. */
|
|
911
|
+
clearCache(): void;
|
|
900
912
|
/**
|
|
901
913
|
* Fetch prompt version by name and label.
|
|
902
914
|
*
|
|
903
|
-
* @param params.name
|
|
904
|
-
* @param params.label
|
|
915
|
+
* @param params.name - Name of the prompt (required)
|
|
916
|
+
* @param params.label - Label of the prompt version (default: "production")
|
|
917
|
+
* @param params.useCache - When true, read/write the in-memory cache (default: false)
|
|
918
|
+
* @param params.cacheTtl - Per-call cache TTL in seconds (default: PROMPT_CACHE_TTL_SECONDS)
|
|
905
919
|
*/
|
|
906
920
|
getPrompt(params: GetPromptParams): Promise<PromptResponse | null>;
|
|
907
921
|
}
|
|
908
922
|
|
|
923
|
+
/**
|
|
924
|
+
* Models API Models
|
|
925
|
+
*/
|
|
926
|
+
/** Default TTL (seconds) for model pricing cache when useCache is true and cacheTtl is omitted. */
|
|
927
|
+
declare const MODEL_PRICING_CACHE_TTL_SECONDS = 300;
|
|
928
|
+
interface ModelPrice {
|
|
929
|
+
usageType: string;
|
|
930
|
+
minUnits: number;
|
|
931
|
+
maxUnits: number;
|
|
932
|
+
price: number;
|
|
933
|
+
unitValue: number;
|
|
934
|
+
}
|
|
935
|
+
interface ModelPricing {
|
|
936
|
+
name: string;
|
|
937
|
+
projectId: string | null;
|
|
938
|
+
matchPattern: string;
|
|
939
|
+
prices: ModelPrice[];
|
|
940
|
+
}
|
|
941
|
+
interface GetModelPricingParams {
|
|
942
|
+
name?: string;
|
|
943
|
+
/** When true, read/write in-memory cache (default: false). */
|
|
944
|
+
useCache?: boolean;
|
|
945
|
+
/**
|
|
946
|
+
* Per-call TTL in seconds.
|
|
947
|
+
* When omitted with useCache: true, uses MODEL_PRICING_CACHE_TTL_SECONDS (300).
|
|
948
|
+
*/
|
|
949
|
+
cacheTtl?: number;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
declare class Models {
|
|
953
|
+
private config;
|
|
954
|
+
private client;
|
|
955
|
+
private cache;
|
|
956
|
+
constructor(config: Config);
|
|
957
|
+
/** Clear all cached model pricing entries. */
|
|
958
|
+
clearCache(): void;
|
|
959
|
+
/**
|
|
960
|
+
* Fetch model pricing from the backend.
|
|
961
|
+
*
|
|
962
|
+
* @param params.name - Optional model name filter
|
|
963
|
+
* @param params.useCache - When true, read/write the in-memory cache (default: false)
|
|
964
|
+
* @param params.cacheTtl - Per-call cache TTL in seconds (default: MODEL_PRICING_CACHE_TTL_SECONDS)
|
|
965
|
+
*/
|
|
966
|
+
getModelPricing(params?: GetModelPricingParams): Promise<ModelPricing[] | null>;
|
|
967
|
+
}
|
|
968
|
+
|
|
909
969
|
/**
|
|
910
970
|
* Instrumentation Span Processor
|
|
911
971
|
*
|
|
@@ -1790,8 +1850,12 @@ declare class Netra {
|
|
|
1790
1850
|
static dashboard: Dashboard;
|
|
1791
1851
|
static simulation: Simulation;
|
|
1792
1852
|
static prompts: Prompts;
|
|
1853
|
+
static models: Models;
|
|
1793
1854
|
static getConfig(): Config;
|
|
1794
1855
|
static isInitialized(): boolean;
|
|
1856
|
+
/**
|
|
1857
|
+
* Initialize the Netra SDK.
|
|
1858
|
+
*/
|
|
1795
1859
|
static init(config?: NetraConfig): Promise<void>;
|
|
1796
1860
|
static shutdown(): Promise<void>;
|
|
1797
1861
|
static getTraceId(): string | undefined;
|
|
@@ -1829,4 +1893,4 @@ declare class Netra {
|
|
|
1829
1893
|
static withBlockedSpansLocal: typeof withBlockedSpansLocal;
|
|
1830
1894
|
}
|
|
1831
1895
|
|
|
1832
|
-
export { type ActionModel, type AfterAllFn, type AfterFn, Aggregation, BaseTask, type BeforeAllFn, type BeforeFn, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetPromptParams, GroupBy, type InitializeRunResult, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, Measure, type Metrics, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, type ProcessedFile, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, type SafeStringifyOptions, Scope, ScrubbingSpanProcessor, SerializationSpanProcessor, type SessionDetailsResponse, type SessionDetailsToolCall, type SessionDetailsTrace, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationHooks, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, TruncatingSerializer, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, safeStringify, span, task, workflow };
|
|
1896
|
+
export { type ActionModel, type AfterAllFn, type AfterFn, Aggregation, BaseTask, type BeforeAllFn, type BeforeFn, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetModelPricingParams, type GetPromptParams, GroupBy, type InitializeRunResult, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, MODEL_PRICING_CACHE_TTL_SECONDS, Measure, type Metrics, type ModelPrice, type ModelPricing, Models, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, PROMPT_CACHE_TTL_SECONDS, type ProcessedFile, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, type SafeStringifyOptions, Scope, ScrubbingSpanProcessor, SerializationSpanProcessor, type SessionDetailsResponse, type SessionDetailsToolCall, type SessionDetailsTrace, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationHooks, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, TruncatingSerializer, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, safeStringify, span, task, workflow };
|
package/dist/index.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ declare const DEFAULT_INSTRUMENTS: Set<NetraInstruments>;
|
|
|
77
77
|
declare class Config {
|
|
78
78
|
static readonly SDK_NAME = "netra";
|
|
79
79
|
static readonly LIBRARY_NAME = "netra";
|
|
80
|
-
static readonly LIBRARY_VERSION = "1.
|
|
80
|
+
static readonly LIBRARY_VERSION = "1.10.0";
|
|
81
81
|
static readonly TRIAL_BLOCK_DURATION_SECONDS = 900;
|
|
82
82
|
static readonly TRACE_ORIGIN_KEY = "netra.trace.origin";
|
|
83
83
|
static readonly TRACE_ORIGIN_EVALUATION = "evaluation";
|
|
@@ -883,9 +883,18 @@ declare class Dashboard {
|
|
|
883
883
|
/**
|
|
884
884
|
* Prompts API Models
|
|
885
885
|
*/
|
|
886
|
+
/** Default TTL (seconds) for prompt cache when useCache is true and cacheTtl is omitted. */
|
|
887
|
+
declare const PROMPT_CACHE_TTL_SECONDS = 60;
|
|
886
888
|
interface GetPromptParams {
|
|
887
889
|
name: string;
|
|
888
890
|
label?: string;
|
|
891
|
+
/** When true, serve from in-memory cache when available (default: false). */
|
|
892
|
+
useCache?: boolean;
|
|
893
|
+
/**
|
|
894
|
+
* Per-call TTL in seconds.
|
|
895
|
+
* When omitted with useCache: true, uses PROMPT_CACHE_TTL_SECONDS (60).
|
|
896
|
+
*/
|
|
897
|
+
cacheTtl?: number;
|
|
889
898
|
}
|
|
890
899
|
/**
|
|
891
900
|
* Prompt response is intentionally flexible because
|
|
@@ -896,16 +905,67 @@ type PromptResponse = Record<string, any>;
|
|
|
896
905
|
declare class Prompts {
|
|
897
906
|
private config;
|
|
898
907
|
private client;
|
|
908
|
+
private cache;
|
|
899
909
|
constructor(config: Config);
|
|
910
|
+
/** Clear all cached prompt entries. */
|
|
911
|
+
clearCache(): void;
|
|
900
912
|
/**
|
|
901
913
|
* Fetch prompt version by name and label.
|
|
902
914
|
*
|
|
903
|
-
* @param params.name
|
|
904
|
-
* @param params.label
|
|
915
|
+
* @param params.name - Name of the prompt (required)
|
|
916
|
+
* @param params.label - Label of the prompt version (default: "production")
|
|
917
|
+
* @param params.useCache - When true, read/write the in-memory cache (default: false)
|
|
918
|
+
* @param params.cacheTtl - Per-call cache TTL in seconds (default: PROMPT_CACHE_TTL_SECONDS)
|
|
905
919
|
*/
|
|
906
920
|
getPrompt(params: GetPromptParams): Promise<PromptResponse | null>;
|
|
907
921
|
}
|
|
908
922
|
|
|
923
|
+
/**
|
|
924
|
+
* Models API Models
|
|
925
|
+
*/
|
|
926
|
+
/** Default TTL (seconds) for model pricing cache when useCache is true and cacheTtl is omitted. */
|
|
927
|
+
declare const MODEL_PRICING_CACHE_TTL_SECONDS = 300;
|
|
928
|
+
interface ModelPrice {
|
|
929
|
+
usageType: string;
|
|
930
|
+
minUnits: number;
|
|
931
|
+
maxUnits: number;
|
|
932
|
+
price: number;
|
|
933
|
+
unitValue: number;
|
|
934
|
+
}
|
|
935
|
+
interface ModelPricing {
|
|
936
|
+
name: string;
|
|
937
|
+
projectId: string | null;
|
|
938
|
+
matchPattern: string;
|
|
939
|
+
prices: ModelPrice[];
|
|
940
|
+
}
|
|
941
|
+
interface GetModelPricingParams {
|
|
942
|
+
name?: string;
|
|
943
|
+
/** When true, read/write in-memory cache (default: false). */
|
|
944
|
+
useCache?: boolean;
|
|
945
|
+
/**
|
|
946
|
+
* Per-call TTL in seconds.
|
|
947
|
+
* When omitted with useCache: true, uses MODEL_PRICING_CACHE_TTL_SECONDS (300).
|
|
948
|
+
*/
|
|
949
|
+
cacheTtl?: number;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
declare class Models {
|
|
953
|
+
private config;
|
|
954
|
+
private client;
|
|
955
|
+
private cache;
|
|
956
|
+
constructor(config: Config);
|
|
957
|
+
/** Clear all cached model pricing entries. */
|
|
958
|
+
clearCache(): void;
|
|
959
|
+
/**
|
|
960
|
+
* Fetch model pricing from the backend.
|
|
961
|
+
*
|
|
962
|
+
* @param params.name - Optional model name filter
|
|
963
|
+
* @param params.useCache - When true, read/write the in-memory cache (default: false)
|
|
964
|
+
* @param params.cacheTtl - Per-call cache TTL in seconds (default: MODEL_PRICING_CACHE_TTL_SECONDS)
|
|
965
|
+
*/
|
|
966
|
+
getModelPricing(params?: GetModelPricingParams): Promise<ModelPricing[] | null>;
|
|
967
|
+
}
|
|
968
|
+
|
|
909
969
|
/**
|
|
910
970
|
* Instrumentation Span Processor
|
|
911
971
|
*
|
|
@@ -1790,8 +1850,12 @@ declare class Netra {
|
|
|
1790
1850
|
static dashboard: Dashboard;
|
|
1791
1851
|
static simulation: Simulation;
|
|
1792
1852
|
static prompts: Prompts;
|
|
1853
|
+
static models: Models;
|
|
1793
1854
|
static getConfig(): Config;
|
|
1794
1855
|
static isInitialized(): boolean;
|
|
1856
|
+
/**
|
|
1857
|
+
* Initialize the Netra SDK.
|
|
1858
|
+
*/
|
|
1795
1859
|
static init(config?: NetraConfig): Promise<void>;
|
|
1796
1860
|
static shutdown(): Promise<void>;
|
|
1797
1861
|
static getTraceId(): string | undefined;
|
|
@@ -1829,4 +1893,4 @@ declare class Netra {
|
|
|
1829
1893
|
static withBlockedSpansLocal: typeof withBlockedSpansLocal;
|
|
1830
1894
|
}
|
|
1831
1895
|
|
|
1832
|
-
export { type ActionModel, type AfterAllFn, type AfterFn, Aggregation, BaseTask, type BeforeAllFn, type BeforeFn, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetPromptParams, GroupBy, type InitializeRunResult, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, Measure, type Metrics, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, type ProcessedFile, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, type SafeStringifyOptions, Scope, ScrubbingSpanProcessor, SerializationSpanProcessor, type SessionDetailsResponse, type SessionDetailsToolCall, type SessionDetailsTrace, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationHooks, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, TruncatingSerializer, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, safeStringify, span, task, workflow };
|
|
1896
|
+
export { type ActionModel, type AfterAllFn, type AfterFn, Aggregation, BaseTask, type BeforeAllFn, type BeforeFn, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetModelPricingParams, type GetPromptParams, GroupBy, type InitializeRunResult, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, MODEL_PRICING_CACHE_TTL_SECONDS, Measure, type Metrics, type ModelPrice, type ModelPricing, Models, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, PROMPT_CACHE_TTL_SECONDS, type ProcessedFile, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, type SafeStringifyOptions, Scope, ScrubbingSpanProcessor, SerializationSpanProcessor, type SessionDetailsResponse, type SessionDetailsToolCall, type SessionDetailsTrace, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationHooks, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, TruncatingSerializer, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, safeStringify, span, task, workflow };
|
package/dist/index.js
CHANGED
|
@@ -579,7 +579,7 @@ var Usage = class {
|
|
|
579
579
|
};
|
|
580
580
|
|
|
581
581
|
// src/version.ts
|
|
582
|
-
var SDK_VERSION = "1.
|
|
582
|
+
var SDK_VERSION = "1.10.0";
|
|
583
583
|
|
|
584
584
|
// src/config.ts
|
|
585
585
|
var NetraInstruments = /* @__PURE__ */ ((NetraInstruments2) => {
|
|
@@ -2992,6 +2992,33 @@ var Dashboard = class {
|
|
|
2992
2992
|
}
|
|
2993
2993
|
};
|
|
2994
2994
|
|
|
2995
|
+
// src/cache.ts
|
|
2996
|
+
var TTLCache = class {
|
|
2997
|
+
constructor(defaultTtl = 60) {
|
|
2998
|
+
this.store = /* @__PURE__ */ new Map();
|
|
2999
|
+
this.defaultTtl = defaultTtl;
|
|
3000
|
+
}
|
|
3001
|
+
get(key) {
|
|
3002
|
+
const entry = this.store.get(key);
|
|
3003
|
+
if (!entry) return void 0;
|
|
3004
|
+
if (performance.now() > entry.expiresAt) {
|
|
3005
|
+
this.store.delete(key);
|
|
3006
|
+
return void 0;
|
|
3007
|
+
}
|
|
3008
|
+
return entry.value;
|
|
3009
|
+
}
|
|
3010
|
+
set(key, value, ttl) {
|
|
3011
|
+
const ttlMs = (ttl ?? this.defaultTtl) * 1e3;
|
|
3012
|
+
this.store.set(key, { value, expiresAt: performance.now() + ttlMs });
|
|
3013
|
+
}
|
|
3014
|
+
invalidate(key) {
|
|
3015
|
+
this.store.delete(key);
|
|
3016
|
+
}
|
|
3017
|
+
clear() {
|
|
3018
|
+
this.store.clear();
|
|
3019
|
+
}
|
|
3020
|
+
};
|
|
3021
|
+
|
|
2995
3022
|
// src/api/prompts/client.ts
|
|
2996
3023
|
var PromptsHttpClient = class extends NetraHttpClient {
|
|
2997
3024
|
constructor(config) {
|
|
@@ -3027,17 +3054,27 @@ var PromptsHttpClient = class extends NetraHttpClient {
|
|
|
3027
3054
|
}
|
|
3028
3055
|
};
|
|
3029
3056
|
|
|
3057
|
+
// src/api/prompts/models.ts
|
|
3058
|
+
var PROMPT_CACHE_TTL_SECONDS = 60;
|
|
3059
|
+
|
|
3030
3060
|
// src/api/prompts/api.ts
|
|
3031
3061
|
var Prompts = class {
|
|
3032
3062
|
constructor(config) {
|
|
3033
3063
|
this.config = config;
|
|
3034
3064
|
this.client = new PromptsHttpClient(config);
|
|
3065
|
+
this.cache = new TTLCache(PROMPT_CACHE_TTL_SECONDS);
|
|
3066
|
+
}
|
|
3067
|
+
/** Clear all cached prompt entries. */
|
|
3068
|
+
clearCache() {
|
|
3069
|
+
this.cache.clear();
|
|
3035
3070
|
}
|
|
3036
3071
|
/**
|
|
3037
3072
|
* Fetch prompt version by name and label.
|
|
3038
3073
|
*
|
|
3039
|
-
* @param params.name
|
|
3040
|
-
* @param params.label
|
|
3074
|
+
* @param params.name - Name of the prompt (required)
|
|
3075
|
+
* @param params.label - Label of the prompt version (default: "production")
|
|
3076
|
+
* @param params.useCache - When true, read/write the in-memory cache (default: false)
|
|
3077
|
+
* @param params.cacheTtl - Per-call cache TTL in seconds (default: PROMPT_CACHE_TTL_SECONDS)
|
|
3041
3078
|
*/
|
|
3042
3079
|
async getPrompt(params) {
|
|
3043
3080
|
if (!params || typeof params.name !== "string" || !params.name) {
|
|
@@ -3045,11 +3082,99 @@ var Prompts = class {
|
|
|
3045
3082
|
return null;
|
|
3046
3083
|
}
|
|
3047
3084
|
const label = params.label ?? "production";
|
|
3085
|
+
const useCache = params.useCache === true;
|
|
3086
|
+
const cacheKey = `prompt:${params.name}:${label}`;
|
|
3087
|
+
if (useCache) {
|
|
3088
|
+
const cached = this.cache.get(cacheKey);
|
|
3089
|
+
if (cached !== void 0) {
|
|
3090
|
+
return cached;
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3048
3093
|
const result = await this.client.getPromptVersion(params.name, label);
|
|
3049
3094
|
if (!result) {
|
|
3050
3095
|
return null;
|
|
3051
3096
|
}
|
|
3052
|
-
|
|
3097
|
+
const data = result.data ?? null;
|
|
3098
|
+
if (data !== null && useCache) {
|
|
3099
|
+
this.cache.set(cacheKey, data, params.cacheTtl);
|
|
3100
|
+
}
|
|
3101
|
+
return data;
|
|
3102
|
+
}
|
|
3103
|
+
};
|
|
3104
|
+
|
|
3105
|
+
// src/api/models/client.ts
|
|
3106
|
+
var ModelsHttpClient = class extends NetraHttpClient {
|
|
3107
|
+
constructor(config) {
|
|
3108
|
+
super(config, "NETRA_MODELS_TIMEOUT", 10);
|
|
3109
|
+
}
|
|
3110
|
+
async getModelPricing(name) {
|
|
3111
|
+
if (!this.isInitialized()) {
|
|
3112
|
+
Logger.error(
|
|
3113
|
+
"netra.models: Models client is not initialized; cannot fetch model pricing"
|
|
3114
|
+
);
|
|
3115
|
+
return null;
|
|
3116
|
+
}
|
|
3117
|
+
try {
|
|
3118
|
+
const params = name ? { name } : void 0;
|
|
3119
|
+
const response = await this.get("/sdk/models", params);
|
|
3120
|
+
if (!response.ok) {
|
|
3121
|
+
const errorMessage = response.data?.error?.message ?? "Unknown error";
|
|
3122
|
+
Logger.error(
|
|
3123
|
+
`netra.models: Failed to fetch model pricing: ${errorMessage}`
|
|
3124
|
+
);
|
|
3125
|
+
return null;
|
|
3126
|
+
}
|
|
3127
|
+
const items = this.extractData(response, null);
|
|
3128
|
+
if (items !== null && !Array.isArray(items)) {
|
|
3129
|
+
Logger.error(
|
|
3130
|
+
"netra.models: Unexpected response format; expected an array"
|
|
3131
|
+
);
|
|
3132
|
+
return null;
|
|
3133
|
+
}
|
|
3134
|
+
return items;
|
|
3135
|
+
} catch (err) {
|
|
3136
|
+
const message = err?.response?.data?.error?.message ?? err?.message ?? "";
|
|
3137
|
+
Logger.error("netra.models: Failed to fetch model pricing:", message);
|
|
3138
|
+
return null;
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
};
|
|
3142
|
+
|
|
3143
|
+
// src/api/models/models.ts
|
|
3144
|
+
var MODEL_PRICING_CACHE_TTL_SECONDS = 300;
|
|
3145
|
+
|
|
3146
|
+
// src/api/models/api.ts
|
|
3147
|
+
var Models = class {
|
|
3148
|
+
constructor(config) {
|
|
3149
|
+
this.config = config;
|
|
3150
|
+
this.client = new ModelsHttpClient(config);
|
|
3151
|
+
this.cache = new TTLCache(MODEL_PRICING_CACHE_TTL_SECONDS);
|
|
3152
|
+
}
|
|
3153
|
+
/** Clear all cached model pricing entries. */
|
|
3154
|
+
clearCache() {
|
|
3155
|
+
this.cache.clear();
|
|
3156
|
+
}
|
|
3157
|
+
/**
|
|
3158
|
+
* Fetch model pricing from the backend.
|
|
3159
|
+
*
|
|
3160
|
+
* @param params.name - Optional model name filter
|
|
3161
|
+
* @param params.useCache - When true, read/write the in-memory cache (default: false)
|
|
3162
|
+
* @param params.cacheTtl - Per-call cache TTL in seconds (default: MODEL_PRICING_CACHE_TTL_SECONDS)
|
|
3163
|
+
*/
|
|
3164
|
+
async getModelPricing(params = {}) {
|
|
3165
|
+
const useCache = params.useCache === true;
|
|
3166
|
+
const cacheKey = `model:pricing:${params.name ?? "all"}`;
|
|
3167
|
+
if (useCache) {
|
|
3168
|
+
const cached = this.cache.get(cacheKey);
|
|
3169
|
+
if (cached !== void 0) {
|
|
3170
|
+
return cached;
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
const data = await this.client.getModelPricing(params.name);
|
|
3174
|
+
if (data !== null && useCache) {
|
|
3175
|
+
this.cache.set(cacheKey, data, params.cacheTtl);
|
|
3176
|
+
}
|
|
3177
|
+
return data;
|
|
3053
3178
|
}
|
|
3054
3179
|
};
|
|
3055
3180
|
|
|
@@ -13325,6 +13450,9 @@ var Netra = class {
|
|
|
13325
13450
|
static isInitialized() {
|
|
13326
13451
|
return this._initialized;
|
|
13327
13452
|
}
|
|
13453
|
+
/**
|
|
13454
|
+
* Initialize the Netra SDK.
|
|
13455
|
+
*/
|
|
13328
13456
|
static async init(config = {}) {
|
|
13329
13457
|
if (this._initialized) {
|
|
13330
13458
|
Logger.warn("Netra.init() called more than once; ignoring subsequent calls.");
|
|
@@ -13366,6 +13494,11 @@ var Netra = class {
|
|
|
13366
13494
|
} catch (e) {
|
|
13367
13495
|
Logger.warn("Netra: failed to initialize prompts client:", e);
|
|
13368
13496
|
}
|
|
13497
|
+
try {
|
|
13498
|
+
this.models = new Models(cfg);
|
|
13499
|
+
} catch (e) {
|
|
13500
|
+
Logger.warn("Netra: failed to initialize models client:", e);
|
|
13501
|
+
}
|
|
13369
13502
|
this._initialized = true;
|
|
13370
13503
|
Logger.info("Netra successfully initialized.");
|
|
13371
13504
|
{
|
|
@@ -13433,6 +13566,12 @@ Received ${signal}. Shutting down Netra SDK...`);
|
|
|
13433
13566
|
} catch (e) {
|
|
13434
13567
|
Logger.error("Error during Netra trace shutdown:", e);
|
|
13435
13568
|
}
|
|
13569
|
+
try {
|
|
13570
|
+
this.prompts?.clearCache();
|
|
13571
|
+
this.models?.clearCache();
|
|
13572
|
+
} catch (e) {
|
|
13573
|
+
Logger.error("Error clearing SDK API caches:", e);
|
|
13574
|
+
}
|
|
13436
13575
|
this._initialized = false;
|
|
13437
13576
|
this._tracer = void 0;
|
|
13438
13577
|
}
|
|
@@ -13591,6 +13730,6 @@ Netra._metricsEnabled = false;
|
|
|
13591
13730
|
Netra.withBlockedSpansLocal = withBlockedSpansLocal;
|
|
13592
13731
|
var index_default = Netra;
|
|
13593
13732
|
|
|
13594
|
-
export { Aggregation, BaseTask, ChartType, Config, ConversationType, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, DimensionField, EntryStatus, Evaluation, FilterField, FilterType, FilteringSpanExporter, GroupBy, InstrumentationSpanProcessor, Measure, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, Operator, Prompts, RunEntryContext, RunStatus, Scope, ScrubbingSpanProcessor, SerializationSpanProcessor, SessionSpanProcessor, Simulation, SpanIOProcessor, SpanType, TrialAwareOTLPExporter, TruncatingSerializer, Usage, agent, index_default as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, safeStringify, span, task, workflow };
|
|
13733
|
+
export { Aggregation, BaseTask, ChartType, Config, ConversationType, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, DimensionField, EntryStatus, Evaluation, FilterField, FilterType, FilteringSpanExporter, GroupBy, InstrumentationSpanProcessor, MODEL_PRICING_CACHE_TTL_SECONDS, Measure, Models, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, Operator, PROMPT_CACHE_TTL_SECONDS, Prompts, RunEntryContext, RunStatus, Scope, ScrubbingSpanProcessor, SerializationSpanProcessor, SessionSpanProcessor, Simulation, SpanIOProcessor, SpanType, TrialAwareOTLPExporter, TruncatingSerializer, Usage, agent, index_default as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, safeStringify, span, task, workflow };
|
|
13595
13734
|
//# sourceMappingURL=index.js.map
|
|
13596
13735
|
//# sourceMappingURL=index.js.map
|