langsmith 0.4.3 → 0.4.4
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.cjs +1 -84
- package/dist/client.d.ts +0 -50
- package/dist/client.js +1 -84
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +6 -7
- package/dist/run_trees.js +7 -8
- package/dist/utils/_uuid.cjs +0 -87
- package/dist/utils/_uuid.d.ts +0 -26
- package/dist/utils/_uuid.js +0 -86
- package/package.json +1 -1
- package/dist/utils/prompts_cache.cjs +0 -348
- package/dist/utils/prompts_cache.d.ts +0 -139
- package/dist/utils/prompts_cache.js +0 -311
package/dist/client.cjs
CHANGED
|
@@ -46,7 +46,6 @@ const _uuid_js_1 = require("./utils/_uuid.cjs");
|
|
|
46
46
|
const warn_js_1 = require("./utils/warn.cjs");
|
|
47
47
|
const prompts_js_1 = require("./utils/prompts.cjs");
|
|
48
48
|
const error_js_1 = require("./utils/error.cjs");
|
|
49
|
-
const prompts_cache_js_1 = require("./utils/prompts_cache.cjs");
|
|
50
49
|
const fetch_js_1 = require("./singletons/fetch.cjs");
|
|
51
50
|
const index_js_2 = require("./utils/fast-safe-stringify/index.cjs");
|
|
52
51
|
function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo) {
|
|
@@ -411,12 +410,6 @@ class Client {
|
|
|
411
410
|
writable: true,
|
|
412
411
|
value: void 0
|
|
413
412
|
});
|
|
414
|
-
Object.defineProperty(this, "_promptCache", {
|
|
415
|
-
enumerable: true,
|
|
416
|
-
configurable: true,
|
|
417
|
-
writable: true,
|
|
418
|
-
value: void 0
|
|
419
|
-
});
|
|
420
413
|
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
421
414
|
enumerable: true,
|
|
422
415
|
configurable: true,
|
|
@@ -488,27 +481,6 @@ class Client {
|
|
|
488
481
|
}
|
|
489
482
|
// Cache metadata env vars once during construction to avoid repeatedly scanning process.env
|
|
490
483
|
this.cachedLSEnvVarsForMetadata = (0, env_js_1.getLangSmithEnvVarsMetadata)();
|
|
491
|
-
// Initialize prompt cache
|
|
492
|
-
const cacheEnabled = config.promptCacheEnabled ??
|
|
493
|
-
(0, env_js_1.getLangSmithEnvironmentVariable)("PROMPT_CACHE_ENABLED") === "true";
|
|
494
|
-
if (cacheEnabled) {
|
|
495
|
-
this._promptCache = new prompts_cache_js_1.PromptCache({
|
|
496
|
-
maxSize: config.promptCacheMaxSize ??
|
|
497
|
-
parseInt((0, env_js_1.getLangSmithEnvironmentVariable)("PROMPT_CACHE_MAX_SIZE") ?? "100", 10),
|
|
498
|
-
ttlSeconds: config.promptCacheTtlSeconds ??
|
|
499
|
-
parseFloat((0, env_js_1.getLangSmithEnvironmentVariable)("PROMPT_CACHE_TTL_SECONDS") ??
|
|
500
|
-
"3600"),
|
|
501
|
-
refreshIntervalSeconds: config.promptCacheRefreshIntervalSeconds ??
|
|
502
|
-
parseFloat((0, env_js_1.getLangSmithEnvironmentVariable)("PROMPT_CACHE_REFRESH_INTERVAL_SECONDS") ?? "60"),
|
|
503
|
-
fetchFunc: this._makeFetchPromptFunc(),
|
|
504
|
-
});
|
|
505
|
-
// Load from file if path provided
|
|
506
|
-
const cachePath = config.promptCachePath ??
|
|
507
|
-
(0, env_js_1.getLangSmithEnvironmentVariable)("PROMPT_CACHE_PATH");
|
|
508
|
-
if (cachePath) {
|
|
509
|
-
this._promptCache.load(cachePath);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
484
|
}
|
|
513
485
|
static getDefaultClientConfig() {
|
|
514
486
|
const apiKey = (0, env_js_1.getLangSmithEnvironmentVariable)("API_KEY");
|
|
@@ -3812,29 +3784,7 @@ class Client {
|
|
|
3812
3784
|
});
|
|
3813
3785
|
return response.json();
|
|
3814
3786
|
}
|
|
3815
|
-
|
|
3816
|
-
* Generate a cache key for a prompt.
|
|
3817
|
-
* Format: "{identifier}" or "{identifier}:with_model"
|
|
3818
|
-
*/
|
|
3819
|
-
_getPromptCacheKey(promptIdentifier, includeModel) {
|
|
3820
|
-
const suffix = includeModel ? ":with_model" : "";
|
|
3821
|
-
return `${promptIdentifier}${suffix}`;
|
|
3822
|
-
}
|
|
3823
|
-
/**
|
|
3824
|
-
* Create a fetch function for the prompt cache to use for background refresh.
|
|
3825
|
-
*/
|
|
3826
|
-
_makeFetchPromptFunc() {
|
|
3827
|
-
return async (key) => {
|
|
3828
|
-
// Parse the cache key back to identifier and options
|
|
3829
|
-
const includeModel = key.endsWith(":with_model");
|
|
3830
|
-
const identifier = includeModel ? key.slice(0, -11) : key; // Remove ":with_model"
|
|
3831
|
-
return this._fetchPromptFromApi(identifier, { includeModel });
|
|
3832
|
-
};
|
|
3833
|
-
}
|
|
3834
|
-
/**
|
|
3835
|
-
* Fetch a prompt commit directly from the API (bypassing cache).
|
|
3836
|
-
*/
|
|
3837
|
-
async _fetchPromptFromApi(promptIdentifier, options) {
|
|
3787
|
+
async pullPromptCommit(promptIdentifier, options) {
|
|
3838
3788
|
const [owner, promptName, commitHash] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
|
|
3839
3789
|
const response = await this.caller.call(async () => {
|
|
3840
3790
|
const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
|
|
@@ -3855,22 +3805,6 @@ class Client {
|
|
|
3855
3805
|
examples: result.examples,
|
|
3856
3806
|
};
|
|
3857
3807
|
}
|
|
3858
|
-
async pullPromptCommit(promptIdentifier, options) {
|
|
3859
|
-
// Check cache first if not skipped
|
|
3860
|
-
if (!options?.skipCache && this._promptCache) {
|
|
3861
|
-
const cacheKey = this._getPromptCacheKey(promptIdentifier, options?.includeModel);
|
|
3862
|
-
const cached = this._promptCache.get(cacheKey);
|
|
3863
|
-
if (cached) {
|
|
3864
|
-
return cached;
|
|
3865
|
-
}
|
|
3866
|
-
// Cache miss - fetch from API and cache it
|
|
3867
|
-
const result = await this._fetchPromptFromApi(promptIdentifier, options);
|
|
3868
|
-
this._promptCache.set(cacheKey, result);
|
|
3869
|
-
return result;
|
|
3870
|
-
}
|
|
3871
|
-
// No cache or skip cache - fetch directly
|
|
3872
|
-
return this._fetchPromptFromApi(promptIdentifier, options);
|
|
3873
|
-
}
|
|
3874
3808
|
/**
|
|
3875
3809
|
* This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
|
|
3876
3810
|
* Using this method directly returns the JSON string of the prompt rather than a LangChain object.
|
|
@@ -3879,7 +3813,6 @@ class Client {
|
|
|
3879
3813
|
async _pullPrompt(promptIdentifier, options) {
|
|
3880
3814
|
const promptObject = await this.pullPromptCommit(promptIdentifier, {
|
|
3881
3815
|
includeModel: options?.includeModel,
|
|
3882
|
-
skipCache: options?.skipCache,
|
|
3883
3816
|
});
|
|
3884
3817
|
const prompt = JSON.stringify(promptObject.manifest);
|
|
3885
3818
|
return prompt;
|
|
@@ -3994,22 +3927,6 @@ class Client {
|
|
|
3994
3927
|
throw new Error(`Invalid public ${kind} URL or token: ${urlOrToken}`);
|
|
3995
3928
|
}
|
|
3996
3929
|
}
|
|
3997
|
-
/**
|
|
3998
|
-
* Get the prompt cache instance, if caching is enabled.
|
|
3999
|
-
* Useful for accessing cache metrics or manually managing the cache.
|
|
4000
|
-
*/
|
|
4001
|
-
get promptCache() {
|
|
4002
|
-
return this._promptCache;
|
|
4003
|
-
}
|
|
4004
|
-
/**
|
|
4005
|
-
* Cleanup resources held by the client.
|
|
4006
|
-
* Stops the prompt cache's background refresh timer.
|
|
4007
|
-
*/
|
|
4008
|
-
cleanup() {
|
|
4009
|
-
if (this._promptCache) {
|
|
4010
|
-
this._promptCache.stop();
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
3930
|
/**
|
|
4014
3931
|
* Awaits all pending trace batches. Useful for environments where
|
|
4015
3932
|
* you need to be sure that all tracing requests finish before execution ends,
|
package/dist/client.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { OTELContext } from "./experimental/otel/types.js";
|
|
|
2
2
|
import { AsyncCallerParams } from "./utils/async_caller.js";
|
|
3
3
|
import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShareSchema, Example, ExampleCreate, ExampleUpdate, ExampleUpdateWithoutId, Feedback, FeedbackConfig, FeedbackIngestToken, KVMap, LangChainBaseMessage, LangSmithSettings, LikePromptResponse, Prompt, PromptCommit, PromptSortField, Run, RunCreate, RunUpdate, ScoreType, ExampleSearch, TimeDelta, TracerSession, TracerSessionResult, ValueType, AnnotationQueue, RunWithAnnotationQueueInfo, Attachments, UploadExamplesResponse, UpdateExamplesResponse, DatasetVersion, AnnotationQueueWithDetails } from "./schemas.js";
|
|
4
4
|
import { EvaluationResult, EvaluationResults } from "./evaluation/evaluator.js";
|
|
5
|
-
import { PromptCache } from "./utils/prompts_cache.js";
|
|
6
5
|
export interface ClientConfig {
|
|
7
6
|
apiUrl?: string;
|
|
8
7
|
apiKey?: string;
|
|
@@ -50,29 +49,6 @@ export interface ClientConfig {
|
|
|
50
49
|
* Custom fetch implementation. Useful for testing.
|
|
51
50
|
*/
|
|
52
51
|
fetchImplementation?: typeof fetch;
|
|
53
|
-
/**
|
|
54
|
-
* Whether to enable prompt caching. Defaults to false.
|
|
55
|
-
*/
|
|
56
|
-
promptCacheEnabled?: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Maximum number of prompts to cache. Defaults to 100.
|
|
59
|
-
*/
|
|
60
|
-
promptCacheMaxSize?: number;
|
|
61
|
-
/**
|
|
62
|
-
* Time-to-live for cached prompts in seconds. After this time, cached prompts
|
|
63
|
-
* are considered stale and will be refreshed in the background.
|
|
64
|
-
* Set to null for infinite TTL (offline mode). Defaults to 3600 (1 hour).
|
|
65
|
-
*/
|
|
66
|
-
promptCacheTtlSeconds?: number | null;
|
|
67
|
-
/**
|
|
68
|
-
* How often to check for stale cache entries in seconds. Defaults to 60.
|
|
69
|
-
*/
|
|
70
|
-
promptCacheRefreshIntervalSeconds?: number;
|
|
71
|
-
/**
|
|
72
|
-
* Path to a JSON file to load cached prompts from on initialization.
|
|
73
|
-
* Useful for offline mode.
|
|
74
|
-
*/
|
|
75
|
-
promptCachePath?: string;
|
|
76
52
|
}
|
|
77
53
|
/**
|
|
78
54
|
* Represents the parameters for listing runs (spans) from the Langsmith server.
|
|
@@ -375,7 +351,6 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
375
351
|
private langSmithToOTELTranslator?;
|
|
376
352
|
private fetchImplementation?;
|
|
377
353
|
private cachedLSEnvVarsForMetadata?;
|
|
378
|
-
private _promptCache?;
|
|
379
354
|
private get _fetch();
|
|
380
355
|
private multipartStreamingDisabled;
|
|
381
356
|
private _multipartDisabled;
|
|
@@ -1020,22 +995,8 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
1020
995
|
isArchived?: boolean;
|
|
1021
996
|
}): Promise<Record<string, any>>;
|
|
1022
997
|
deletePrompt(promptIdentifier: string): Promise<void>;
|
|
1023
|
-
/**
|
|
1024
|
-
* Generate a cache key for a prompt.
|
|
1025
|
-
* Format: "{identifier}" or "{identifier}:with_model"
|
|
1026
|
-
*/
|
|
1027
|
-
private _getPromptCacheKey;
|
|
1028
|
-
/**
|
|
1029
|
-
* Create a fetch function for the prompt cache to use for background refresh.
|
|
1030
|
-
*/
|
|
1031
|
-
private _makeFetchPromptFunc;
|
|
1032
|
-
/**
|
|
1033
|
-
* Fetch a prompt commit directly from the API (bypassing cache).
|
|
1034
|
-
*/
|
|
1035
|
-
private _fetchPromptFromApi;
|
|
1036
998
|
pullPromptCommit(promptIdentifier: string, options?: {
|
|
1037
999
|
includeModel?: boolean;
|
|
1038
|
-
skipCache?: boolean;
|
|
1039
1000
|
}): Promise<PromptCommit>;
|
|
1040
1001
|
/**
|
|
1041
1002
|
* This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
|
|
@@ -1044,7 +1005,6 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
1044
1005
|
*/
|
|
1045
1006
|
_pullPrompt(promptIdentifier: string, options?: {
|
|
1046
1007
|
includeModel?: boolean;
|
|
1047
|
-
skipCache?: boolean;
|
|
1048
1008
|
}): Promise<any>;
|
|
1049
1009
|
pushPrompt(promptIdentifier: string, options?: {
|
|
1050
1010
|
object?: any;
|
|
@@ -1070,16 +1030,6 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
1070
1030
|
datasetName?: string;
|
|
1071
1031
|
}): Promise<void>;
|
|
1072
1032
|
private parseTokenOrUrl;
|
|
1073
|
-
/**
|
|
1074
|
-
* Get the prompt cache instance, if caching is enabled.
|
|
1075
|
-
* Useful for accessing cache metrics or manually managing the cache.
|
|
1076
|
-
*/
|
|
1077
|
-
get promptCache(): PromptCache | undefined;
|
|
1078
|
-
/**
|
|
1079
|
-
* Cleanup resources held by the client.
|
|
1080
|
-
* Stops the prompt cache's background refresh timer.
|
|
1081
|
-
*/
|
|
1082
|
-
cleanup(): void;
|
|
1083
1033
|
/**
|
|
1084
1034
|
* Awaits all pending trace batches. Useful for environments where
|
|
1085
1035
|
* you need to be sure that all tracing requests finish before execution ends,
|
package/dist/client.js
CHANGED
|
@@ -9,7 +9,6 @@ import { assertUuid } from "./utils/_uuid.js";
|
|
|
9
9
|
import { warnOnce } from "./utils/warn.js";
|
|
10
10
|
import { parsePromptIdentifier } from "./utils/prompts.js";
|
|
11
11
|
import { raiseForStatus, isLangSmithNotFoundError } from "./utils/error.js";
|
|
12
|
-
import { PromptCache } from "./utils/prompts_cache.js";
|
|
13
12
|
import { _globalFetchImplementationIsNodeFetch, _getFetchImplementation, } from "./singletons/fetch.js";
|
|
14
13
|
import { serialize as serializePayloadForTracing } from "./utils/fast-safe-stringify/index.js";
|
|
15
14
|
export function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo) {
|
|
@@ -373,12 +372,6 @@ export class Client {
|
|
|
373
372
|
writable: true,
|
|
374
373
|
value: void 0
|
|
375
374
|
});
|
|
376
|
-
Object.defineProperty(this, "_promptCache", {
|
|
377
|
-
enumerable: true,
|
|
378
|
-
configurable: true,
|
|
379
|
-
writable: true,
|
|
380
|
-
value: void 0
|
|
381
|
-
});
|
|
382
375
|
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
383
376
|
enumerable: true,
|
|
384
377
|
configurable: true,
|
|
@@ -450,27 +443,6 @@ export class Client {
|
|
|
450
443
|
}
|
|
451
444
|
// Cache metadata env vars once during construction to avoid repeatedly scanning process.env
|
|
452
445
|
this.cachedLSEnvVarsForMetadata = getLangSmithEnvVarsMetadata();
|
|
453
|
-
// Initialize prompt cache
|
|
454
|
-
const cacheEnabled = config.promptCacheEnabled ??
|
|
455
|
-
getLangSmithEnvironmentVariable("PROMPT_CACHE_ENABLED") === "true";
|
|
456
|
-
if (cacheEnabled) {
|
|
457
|
-
this._promptCache = new PromptCache({
|
|
458
|
-
maxSize: config.promptCacheMaxSize ??
|
|
459
|
-
parseInt(getLangSmithEnvironmentVariable("PROMPT_CACHE_MAX_SIZE") ?? "100", 10),
|
|
460
|
-
ttlSeconds: config.promptCacheTtlSeconds ??
|
|
461
|
-
parseFloat(getLangSmithEnvironmentVariable("PROMPT_CACHE_TTL_SECONDS") ??
|
|
462
|
-
"3600"),
|
|
463
|
-
refreshIntervalSeconds: config.promptCacheRefreshIntervalSeconds ??
|
|
464
|
-
parseFloat(getLangSmithEnvironmentVariable("PROMPT_CACHE_REFRESH_INTERVAL_SECONDS") ?? "60"),
|
|
465
|
-
fetchFunc: this._makeFetchPromptFunc(),
|
|
466
|
-
});
|
|
467
|
-
// Load from file if path provided
|
|
468
|
-
const cachePath = config.promptCachePath ??
|
|
469
|
-
getLangSmithEnvironmentVariable("PROMPT_CACHE_PATH");
|
|
470
|
-
if (cachePath) {
|
|
471
|
-
this._promptCache.load(cachePath);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
446
|
}
|
|
475
447
|
static getDefaultClientConfig() {
|
|
476
448
|
const apiKey = getLangSmithEnvironmentVariable("API_KEY");
|
|
@@ -3774,29 +3746,7 @@ export class Client {
|
|
|
3774
3746
|
});
|
|
3775
3747
|
return response.json();
|
|
3776
3748
|
}
|
|
3777
|
-
|
|
3778
|
-
* Generate a cache key for a prompt.
|
|
3779
|
-
* Format: "{identifier}" or "{identifier}:with_model"
|
|
3780
|
-
*/
|
|
3781
|
-
_getPromptCacheKey(promptIdentifier, includeModel) {
|
|
3782
|
-
const suffix = includeModel ? ":with_model" : "";
|
|
3783
|
-
return `${promptIdentifier}${suffix}`;
|
|
3784
|
-
}
|
|
3785
|
-
/**
|
|
3786
|
-
* Create a fetch function for the prompt cache to use for background refresh.
|
|
3787
|
-
*/
|
|
3788
|
-
_makeFetchPromptFunc() {
|
|
3789
|
-
return async (key) => {
|
|
3790
|
-
// Parse the cache key back to identifier and options
|
|
3791
|
-
const includeModel = key.endsWith(":with_model");
|
|
3792
|
-
const identifier = includeModel ? key.slice(0, -11) : key; // Remove ":with_model"
|
|
3793
|
-
return this._fetchPromptFromApi(identifier, { includeModel });
|
|
3794
|
-
};
|
|
3795
|
-
}
|
|
3796
|
-
/**
|
|
3797
|
-
* Fetch a prompt commit directly from the API (bypassing cache).
|
|
3798
|
-
*/
|
|
3799
|
-
async _fetchPromptFromApi(promptIdentifier, options) {
|
|
3749
|
+
async pullPromptCommit(promptIdentifier, options) {
|
|
3800
3750
|
const [owner, promptName, commitHash] = parsePromptIdentifier(promptIdentifier);
|
|
3801
3751
|
const response = await this.caller.call(async () => {
|
|
3802
3752
|
const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
|
|
@@ -3817,22 +3767,6 @@ export class Client {
|
|
|
3817
3767
|
examples: result.examples,
|
|
3818
3768
|
};
|
|
3819
3769
|
}
|
|
3820
|
-
async pullPromptCommit(promptIdentifier, options) {
|
|
3821
|
-
// Check cache first if not skipped
|
|
3822
|
-
if (!options?.skipCache && this._promptCache) {
|
|
3823
|
-
const cacheKey = this._getPromptCacheKey(promptIdentifier, options?.includeModel);
|
|
3824
|
-
const cached = this._promptCache.get(cacheKey);
|
|
3825
|
-
if (cached) {
|
|
3826
|
-
return cached;
|
|
3827
|
-
}
|
|
3828
|
-
// Cache miss - fetch from API and cache it
|
|
3829
|
-
const result = await this._fetchPromptFromApi(promptIdentifier, options);
|
|
3830
|
-
this._promptCache.set(cacheKey, result);
|
|
3831
|
-
return result;
|
|
3832
|
-
}
|
|
3833
|
-
// No cache or skip cache - fetch directly
|
|
3834
|
-
return this._fetchPromptFromApi(promptIdentifier, options);
|
|
3835
|
-
}
|
|
3836
3770
|
/**
|
|
3837
3771
|
* This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
|
|
3838
3772
|
* Using this method directly returns the JSON string of the prompt rather than a LangChain object.
|
|
@@ -3841,7 +3775,6 @@ export class Client {
|
|
|
3841
3775
|
async _pullPrompt(promptIdentifier, options) {
|
|
3842
3776
|
const promptObject = await this.pullPromptCommit(promptIdentifier, {
|
|
3843
3777
|
includeModel: options?.includeModel,
|
|
3844
|
-
skipCache: options?.skipCache,
|
|
3845
3778
|
});
|
|
3846
3779
|
const prompt = JSON.stringify(promptObject.manifest);
|
|
3847
3780
|
return prompt;
|
|
@@ -3956,22 +3889,6 @@ export class Client {
|
|
|
3956
3889
|
throw new Error(`Invalid public ${kind} URL or token: ${urlOrToken}`);
|
|
3957
3890
|
}
|
|
3958
3891
|
}
|
|
3959
|
-
/**
|
|
3960
|
-
* Get the prompt cache instance, if caching is enabled.
|
|
3961
|
-
* Useful for accessing cache metrics or manually managing the cache.
|
|
3962
|
-
*/
|
|
3963
|
-
get promptCache() {
|
|
3964
|
-
return this._promptCache;
|
|
3965
|
-
}
|
|
3966
|
-
/**
|
|
3967
|
-
* Cleanup resources held by the client.
|
|
3968
|
-
* Stops the prompt cache's background refresh timer.
|
|
3969
|
-
*/
|
|
3970
|
-
cleanup() {
|
|
3971
|
-
if (this._promptCache) {
|
|
3972
|
-
this._promptCache.stop();
|
|
3973
|
-
}
|
|
3974
|
-
}
|
|
3975
3892
|
/**
|
|
3976
3893
|
* Awaits all pending trace batches. Useful for environments where
|
|
3977
3894
|
* you need to be sure that all tracing requests finish before execution ends,
|
package/dist/index.cjs
CHANGED
|
@@ -13,4 +13,4 @@ var uuid_js_1 = require("./uuid.cjs");
|
|
|
13
13
|
Object.defineProperty(exports, "uuid7", { enumerable: true, get: function () { return uuid_js_1.uuid7; } });
|
|
14
14
|
Object.defineProperty(exports, "uuid7FromTime", { enumerable: true, get: function () { return uuid_js_1.uuid7FromTime; } });
|
|
15
15
|
// Update using yarn bump-version
|
|
16
|
-
exports.__version__ = "0.4.
|
|
16
|
+
exports.__version__ = "0.4.4";
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
6
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
7
|
-
export declare const __version__ = "0.4.
|
|
7
|
+
export declare const __version__ = "0.4.4";
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
|
4
4
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
5
5
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
6
6
|
// Update using yarn bump-version
|
|
7
|
-
export const __version__ = "0.4.
|
|
7
|
+
export const __version__ = "0.4.4";
|
package/dist/run_trees.cjs
CHANGED
|
@@ -616,15 +616,14 @@ class RunTree {
|
|
|
616
616
|
}
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
|
-
// Remap IDs for the replica using
|
|
620
|
-
// This ensures consistency across runs in the same replica
|
|
621
|
-
// preserving UUID7 properties (time-ordering, monotonicity)
|
|
619
|
+
// Remap IDs for the replica using uuid5 (deterministic)
|
|
620
|
+
// This ensures consistency across runs in the same replica
|
|
622
621
|
const oldId = baseRun.id;
|
|
623
|
-
const newId = (0,
|
|
622
|
+
const newId = (0, uuid_1.v5)(`${oldId}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
624
623
|
// Remap trace_id
|
|
625
624
|
let newTraceId;
|
|
626
625
|
if (baseRun.trace_id) {
|
|
627
|
-
newTraceId = (0,
|
|
626
|
+
newTraceId = (0, uuid_1.v5)(`${baseRun.trace_id}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
628
627
|
}
|
|
629
628
|
else {
|
|
630
629
|
newTraceId = newId;
|
|
@@ -632,7 +631,7 @@ class RunTree {
|
|
|
632
631
|
// Remap parent_run_id
|
|
633
632
|
let newParentId;
|
|
634
633
|
if (baseRun.parent_run_id) {
|
|
635
|
-
newParentId = (0,
|
|
634
|
+
newParentId = (0, uuid_1.v5)(`${baseRun.parent_run_id}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
636
635
|
}
|
|
637
636
|
// Remap dotted_order segments
|
|
638
637
|
let newDottedOrder;
|
|
@@ -641,7 +640,7 @@ class RunTree {
|
|
|
641
640
|
const remappedSegs = segs.map((seg) => {
|
|
642
641
|
// Extract the UUID from the segment (last TIMESTAMP_LENGTH characters)
|
|
643
642
|
const segId = seg.slice(-TIMESTAMP_LENGTH);
|
|
644
|
-
const remappedId = (0,
|
|
643
|
+
const remappedId = (0, uuid_1.v5)(`${segId}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
645
644
|
// Replace the UUID part while keeping the timestamp prefix
|
|
646
645
|
return seg.slice(0, -TIMESTAMP_LENGTH) + remappedId;
|
|
647
646
|
});
|
package/dist/run_trees.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getEnvironmentVariable, getRuntimeEnvironment, } from "./utils/env.js";
|
|
|
7
7
|
import { getDefaultProjectName } from "./utils/project.js";
|
|
8
8
|
import { getLangSmithEnvironmentVariable } from "./utils/env.js";
|
|
9
9
|
import { warnOnce } from "./utils/warn.js";
|
|
10
|
-
import { uuid7FromTime
|
|
10
|
+
import { uuid7FromTime } from "./utils/_uuid.js";
|
|
11
11
|
import { v5 as uuidv5 } from "uuid";
|
|
12
12
|
const TIMESTAMP_LENGTH = 36;
|
|
13
13
|
// DNS namespace for UUID v5 (same as Python's uuid.NAMESPACE_DNS)
|
|
@@ -610,15 +610,14 @@ export class RunTree {
|
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
|
-
// Remap IDs for the replica using
|
|
614
|
-
// This ensures consistency across runs in the same replica
|
|
615
|
-
// preserving UUID7 properties (time-ordering, monotonicity)
|
|
613
|
+
// Remap IDs for the replica using uuid5 (deterministic)
|
|
614
|
+
// This ensures consistency across runs in the same replica
|
|
616
615
|
const oldId = baseRun.id;
|
|
617
|
-
const newId =
|
|
616
|
+
const newId = uuidv5(`${oldId}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
618
617
|
// Remap trace_id
|
|
619
618
|
let newTraceId;
|
|
620
619
|
if (baseRun.trace_id) {
|
|
621
|
-
newTraceId =
|
|
620
|
+
newTraceId = uuidv5(`${baseRun.trace_id}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
622
621
|
}
|
|
623
622
|
else {
|
|
624
623
|
newTraceId = newId;
|
|
@@ -626,7 +625,7 @@ export class RunTree {
|
|
|
626
625
|
// Remap parent_run_id
|
|
627
626
|
let newParentId;
|
|
628
627
|
if (baseRun.parent_run_id) {
|
|
629
|
-
newParentId =
|
|
628
|
+
newParentId = uuidv5(`${baseRun.parent_run_id}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
630
629
|
}
|
|
631
630
|
// Remap dotted_order segments
|
|
632
631
|
let newDottedOrder;
|
|
@@ -635,7 +634,7 @@ export class RunTree {
|
|
|
635
634
|
const remappedSegs = segs.map((seg) => {
|
|
636
635
|
// Extract the UUID from the segment (last TIMESTAMP_LENGTH characters)
|
|
637
636
|
const segId = seg.slice(-TIMESTAMP_LENGTH);
|
|
638
|
-
const remappedId =
|
|
637
|
+
const remappedId = uuidv5(`${segId}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
639
638
|
// Replace the UUID part while keeping the timestamp prefix
|
|
640
639
|
return seg.slice(0, -TIMESTAMP_LENGTH) + remappedId;
|
|
641
640
|
});
|
package/dist/utils/_uuid.cjs
CHANGED
|
@@ -4,10 +4,8 @@ exports.assertUuid = assertUuid;
|
|
|
4
4
|
exports.uuid7FromTime = uuid7FromTime;
|
|
5
5
|
exports.getUuidVersion = getUuidVersion;
|
|
6
6
|
exports.warnIfNotUuidV7 = warnIfNotUuidV7;
|
|
7
|
-
exports.uuid7Deterministic = uuid7Deterministic;
|
|
8
7
|
// Relaxed UUID validation regex (allows any valid UUID format including nil UUIDs)
|
|
9
8
|
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10
|
-
const crypto_1 = require("crypto");
|
|
11
9
|
const uuid_1 = require("uuid");
|
|
12
10
|
const warn_js_1 = require("./warn.cjs");
|
|
13
11
|
let UUID7_WARNING_EMITTED = false;
|
|
@@ -66,88 +64,3 @@ function warnIfNotUuidV7(uuidStr, _idType) {
|
|
|
66
64
|
`Future versions will require UUID v7.`);
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Convert a UUID string to its 16-byte representation.
|
|
71
|
-
* @param uuidStr - The UUID string (with or without dashes)
|
|
72
|
-
* @returns A Buffer containing the 16 bytes of the UUID
|
|
73
|
-
*/
|
|
74
|
-
function uuidToBytes(uuidStr) {
|
|
75
|
-
const hex = uuidStr.replace(/-/g, "");
|
|
76
|
-
return Buffer.from(hex, "hex");
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Convert 16 bytes to a UUID string.
|
|
80
|
-
* @param bytes - A Buffer containing 16 bytes
|
|
81
|
-
* @returns A UUID string in standard format
|
|
82
|
-
*/
|
|
83
|
-
function bytesToUuid(bytes) {
|
|
84
|
-
const hex = bytes.toString("hex");
|
|
85
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Generate a deterministic UUID v7 derived from an original UUID and a key.
|
|
89
|
-
*
|
|
90
|
-
* This function creates a new UUID that:
|
|
91
|
-
* - Preserves the timestamp from the original UUID if it's UUID v7
|
|
92
|
-
* - Uses current time if the original is not UUID v7
|
|
93
|
-
* - Uses deterministic "random" bits derived from hashing the original + key
|
|
94
|
-
* - Is valid UUID v7 format
|
|
95
|
-
*
|
|
96
|
-
* This is used for creating replica IDs that maintain time-ordering properties
|
|
97
|
-
* while being deterministic across distributed systems.
|
|
98
|
-
*
|
|
99
|
-
* @param originalId - The source UUID string (ideally UUID v7 to preserve timestamp)
|
|
100
|
-
* @param key - A string key used for deterministic derivation (e.g., project name)
|
|
101
|
-
* @returns A new UUID v7 string with preserved timestamp (if original is v7) and
|
|
102
|
-
* deterministic random bits
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```typescript
|
|
106
|
-
* const original = uuidv7();
|
|
107
|
-
* const replicaId = uuid7Deterministic(original, "replica-project");
|
|
108
|
-
* // Same inputs always produce same output
|
|
109
|
-
* assert(uuid7Deterministic(original, "replica-project") === replicaId);
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
function uuid7Deterministic(originalId, key) {
|
|
113
|
-
// Generate deterministic bytes from hash of original + key
|
|
114
|
-
const hashInput = `${originalId}:${key}`;
|
|
115
|
-
const h = (0, crypto_1.createHash)("sha256").update(hashInput).digest();
|
|
116
|
-
// Build new UUID7:
|
|
117
|
-
// UUID7 structure (RFC 9562):
|
|
118
|
-
// [0-5] 48 bits: unix_ts_ms (timestamp in milliseconds)
|
|
119
|
-
// [6] 4 bits: version (0111 = 7) + 4 bits rand_a
|
|
120
|
-
// [7] 8 bits: rand_a (continued)
|
|
121
|
-
// [8] 2 bits: variant (10) + 6 bits rand_b
|
|
122
|
-
// [9-15] 56 bits: rand_b (continued)
|
|
123
|
-
const b = Buffer.alloc(16);
|
|
124
|
-
// Check if original is UUID v7 - if so, preserve its timestamp
|
|
125
|
-
// If not, use current time to ensure the derived UUID has a valid timestamp
|
|
126
|
-
const version = getUuidVersion(originalId);
|
|
127
|
-
if (version === 7) {
|
|
128
|
-
// Preserve timestamp from original UUID7 (bytes 0-5)
|
|
129
|
-
const originalBytes = uuidToBytes(originalId);
|
|
130
|
-
originalBytes.copy(b, 0, 0, 6);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
// Generate fresh timestamp for non-UUID7 inputs
|
|
134
|
-
// This matches the uuid npm package's v7 implementation:
|
|
135
|
-
// https://github.com/uuidjs/uuid/blob/main/src/v7.ts
|
|
136
|
-
const msecs = Date.now();
|
|
137
|
-
b[0] = (msecs / 0x10000000000) & 0xff;
|
|
138
|
-
b[1] = (msecs / 0x100000000) & 0xff;
|
|
139
|
-
b[2] = (msecs / 0x1000000) & 0xff;
|
|
140
|
-
b[3] = (msecs / 0x10000) & 0xff;
|
|
141
|
-
b[4] = (msecs / 0x100) & 0xff;
|
|
142
|
-
b[5] = msecs & 0xff;
|
|
143
|
-
}
|
|
144
|
-
// Set version 7 (0111) in high nibble + 4 bits from hash
|
|
145
|
-
b[6] = 0x70 | (h[0] & 0x0f);
|
|
146
|
-
// rand_a continued (8 bits from hash)
|
|
147
|
-
b[7] = h[1];
|
|
148
|
-
// Set variant (10) in high 2 bits + 6 bits from hash
|
|
149
|
-
b[8] = 0x80 | (h[2] & 0x3f);
|
|
150
|
-
// rand_b (56 bits = 7 bytes from hash)
|
|
151
|
-
h.copy(b, 9, 3, 10);
|
|
152
|
-
return bytesToUuid(b);
|
|
153
|
-
}
|
package/dist/utils/_uuid.d.ts
CHANGED
|
@@ -19,29 +19,3 @@ export declare function getUuidVersion(uuidStr: string): number | null;
|
|
|
19
19
|
* @param idType - The type of ID (e.g., "run_id", "trace_id") for the warning message
|
|
20
20
|
*/
|
|
21
21
|
export declare function warnIfNotUuidV7(uuidStr: string, _idType: string): void;
|
|
22
|
-
/**
|
|
23
|
-
* Generate a deterministic UUID v7 derived from an original UUID and a key.
|
|
24
|
-
*
|
|
25
|
-
* This function creates a new UUID that:
|
|
26
|
-
* - Preserves the timestamp from the original UUID if it's UUID v7
|
|
27
|
-
* - Uses current time if the original is not UUID v7
|
|
28
|
-
* - Uses deterministic "random" bits derived from hashing the original + key
|
|
29
|
-
* - Is valid UUID v7 format
|
|
30
|
-
*
|
|
31
|
-
* This is used for creating replica IDs that maintain time-ordering properties
|
|
32
|
-
* while being deterministic across distributed systems.
|
|
33
|
-
*
|
|
34
|
-
* @param originalId - The source UUID string (ideally UUID v7 to preserve timestamp)
|
|
35
|
-
* @param key - A string key used for deterministic derivation (e.g., project name)
|
|
36
|
-
* @returns A new UUID v7 string with preserved timestamp (if original is v7) and
|
|
37
|
-
* deterministic random bits
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* const original = uuidv7();
|
|
42
|
-
* const replicaId = uuid7Deterministic(original, "replica-project");
|
|
43
|
-
* // Same inputs always produce same output
|
|
44
|
-
* assert(uuid7Deterministic(original, "replica-project") === replicaId);
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare function uuid7Deterministic(originalId: string, key: string): string;
|