langsmith 0.5.21 → 0.5.23
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 +327 -10
- package/dist/client.d.ts +90 -1
- package/dist/client.js +330 -13
- package/dist/evaluation/_runner.cjs +1 -4
- package/dist/evaluation/_runner.js +1 -4
- package/dist/experimental/sandbox/client.cjs +102 -427
- package/dist/experimental/sandbox/client.d.ts +68 -159
- package/dist/experimental/sandbox/client.js +104 -429
- package/dist/experimental/sandbox/errors.cjs +1 -2
- package/dist/experimental/sandbox/errors.d.ts +1 -2
- package/dist/experimental/sandbox/errors.js +1 -2
- package/dist/experimental/sandbox/helpers.cjs +8 -98
- package/dist/experimental/sandbox/helpers.d.ts +0 -29
- package/dist/experimental/sandbox/helpers.js +9 -95
- package/dist/experimental/sandbox/index.cjs +6 -1
- package/dist/experimental/sandbox/index.d.ts +7 -2
- package/dist/experimental/sandbox/index.js +6 -1
- package/dist/experimental/sandbox/sandbox.cjs +3 -11
- package/dist/experimental/sandbox/sandbox.d.ts +3 -5
- package/dist/experimental/sandbox/sandbox.js +3 -11
- package/dist/experimental/sandbox/types.d.ts +32 -149
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/schemas.d.ts +54 -0
- package/dist/utils/error.cjs +7 -0
- package/dist/utils/error.d.ts +1 -0
- package/dist/utils/error.js +6 -0
- package/dist/utils/fast-safe-stringify/index.cjs +228 -0
- package/dist/utils/fast-safe-stringify/index.d.ts +33 -0
- package/dist/utils/fast-safe-stringify/index.js +227 -0
- package/dist/utils/prompts.cjs +7 -2
- package/dist/utils/prompts.d.ts +6 -1
- package/dist/utils/prompts.js +6 -1
- package/dist/wrappers/openai_agents.cjs +849 -0
- package/dist/wrappers/openai_agents.d.ts +92 -0
- package/dist/wrappers/openai_agents.js +845 -0
- package/package.json +22 -6
- package/wrappers/openai_agents.cjs +1 -0
- package/wrappers/openai_agents.d.cts +1 -0
- package/wrappers/openai_agents.d.ts +1 -0
- package/wrappers/openai_agents.js +1 -0
package/dist/client.cjs
CHANGED
|
@@ -189,7 +189,19 @@ class AutoBatchQueue {
|
|
|
189
189
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
|
|
190
190
|
itemPromiseResolve = resolve;
|
|
191
191
|
});
|
|
192
|
-
|
|
192
|
+
// By default we compute the exact serialized size here by stringifying
|
|
193
|
+
// the payload. This is expensive: JSON.stringify on large payloads
|
|
194
|
+
// blocks the event loop on the user's hot path.
|
|
195
|
+
//
|
|
196
|
+
// Opting into LANGSMITH_PERF_OPTIMIZATION=true switches to a cheap
|
|
197
|
+
// structural estimate instead. The estimate is only used for soft
|
|
198
|
+
// memory accounting (queue size limit and downstream async caller
|
|
199
|
+
// memory tracking), never for anything correctness-critical -- the
|
|
200
|
+
// real serialization still happens later, off the hot path, when the
|
|
201
|
+
// batch is assembled for sending.
|
|
202
|
+
const size = (0, env_js_1.getLangSmithEnvironmentVariable)("PERF_OPTIMIZATION") === "true"
|
|
203
|
+
? (0, index_js_3.estimateSerializedSize)(item.item)
|
|
204
|
+
: (0, index_js_3.serialize)(item.item, `Serializing run with id: ${item.item.id}`).length;
|
|
193
205
|
// Check if adding this item would exceed the size limit
|
|
194
206
|
// Allow the run if the queue is empty (to support large single traces)
|
|
195
207
|
if (this.sizeBytes + size > this.maxSizeBytes && this.items.length > 0) {
|
|
@@ -317,6 +329,12 @@ class Client {
|
|
|
317
329
|
writable: true,
|
|
318
330
|
value: void 0
|
|
319
331
|
});
|
|
332
|
+
Object.defineProperty(this, "hideMetadata", {
|
|
333
|
+
enumerable: true,
|
|
334
|
+
configurable: true,
|
|
335
|
+
writable: true,
|
|
336
|
+
value: void 0
|
|
337
|
+
});
|
|
320
338
|
Object.defineProperty(this, "omitTracedRuntimeInfo", {
|
|
321
339
|
enumerable: true,
|
|
322
340
|
configurable: true,
|
|
@@ -529,6 +547,7 @@ class Client {
|
|
|
529
547
|
config.hideInputs ?? config.anonymizer ?? defaultConfig.hideInputs;
|
|
530
548
|
this.hideOutputs =
|
|
531
549
|
config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
|
|
550
|
+
this.hideMetadata = config.hideMetadata ?? defaultConfig.hideMetadata;
|
|
532
551
|
this.omitTracedRuntimeInfo = config.omitTracedRuntimeInfo ?? false;
|
|
533
552
|
this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
|
|
534
553
|
this.autoBatchQueue = new AutoBatchQueue(maxMemory);
|
|
@@ -578,12 +597,14 @@ class Client {
|
|
|
578
597
|
const apiUrl = (0, env_js_1.getLangSmithEnvironmentVariable)("ENDPOINT") ?? DEFAULT_API_URL;
|
|
579
598
|
const hideInputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_INPUTS") === "true";
|
|
580
599
|
const hideOutputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_OUTPUTS") === "true";
|
|
600
|
+
const hideMetadata = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_METADATA") === "true";
|
|
581
601
|
return {
|
|
582
602
|
apiUrl: apiUrl,
|
|
583
603
|
apiKey: apiKey,
|
|
584
604
|
webUrl: undefined,
|
|
585
605
|
hideInputs: hideInputs,
|
|
586
606
|
hideOutputs: hideOutputs,
|
|
607
|
+
hideMetadata: hideMetadata,
|
|
587
608
|
};
|
|
588
609
|
}
|
|
589
610
|
getHostUrl() {
|
|
@@ -679,6 +700,18 @@ class Client {
|
|
|
679
700
|
}
|
|
680
701
|
return outputs;
|
|
681
702
|
}
|
|
703
|
+
async processMetadata(metadata) {
|
|
704
|
+
if (this.hideMetadata === false) {
|
|
705
|
+
return metadata;
|
|
706
|
+
}
|
|
707
|
+
if (this.hideMetadata === true) {
|
|
708
|
+
return {};
|
|
709
|
+
}
|
|
710
|
+
if (typeof this.hideMetadata === "function") {
|
|
711
|
+
return this.hideMetadata(metadata);
|
|
712
|
+
}
|
|
713
|
+
return metadata;
|
|
714
|
+
}
|
|
682
715
|
/**
|
|
683
716
|
* Filter content from new_token events to prevent streaming LLM output
|
|
684
717
|
* from being uploaded via events.
|
|
@@ -705,6 +738,12 @@ class Client {
|
|
|
705
738
|
if (runParams.outputs !== undefined) {
|
|
706
739
|
runParams.outputs = await this.processOutputs(runParams.outputs);
|
|
707
740
|
}
|
|
741
|
+
if (runParams.extra != null && "metadata" in runParams.extra) {
|
|
742
|
+
runParams.extra = {
|
|
743
|
+
...runParams.extra,
|
|
744
|
+
metadata: await this.processMetadata(runParams.extra.metadata),
|
|
745
|
+
};
|
|
746
|
+
}
|
|
708
747
|
if (runParams.events !== undefined) {
|
|
709
748
|
runParams.events = this._filterNewTokenEvents(runParams.events);
|
|
710
749
|
}
|
|
@@ -1552,6 +1591,12 @@ class Client {
|
|
|
1552
1591
|
if (run.outputs) {
|
|
1553
1592
|
run.outputs = await this.processOutputs(run.outputs);
|
|
1554
1593
|
}
|
|
1594
|
+
if (run.extra != null && "metadata" in run.extra) {
|
|
1595
|
+
run.extra = {
|
|
1596
|
+
...run.extra,
|
|
1597
|
+
metadata: await this.processMetadata(run.extra.metadata),
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1555
1600
|
if (run.events) {
|
|
1556
1601
|
run.events = this._filterNewTokenEvents(run.events);
|
|
1557
1602
|
}
|
|
@@ -3788,7 +3833,7 @@ class Client {
|
|
|
3788
3833
|
return json.commits[0].commit_hash;
|
|
3789
3834
|
}
|
|
3790
3835
|
async _likeOrUnlikePrompt(promptIdentifier, like) {
|
|
3791
|
-
const [owner, promptName, _] = (0, prompts_js_1.
|
|
3836
|
+
const [owner, promptName, _] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
3792
3837
|
const body = JSON.stringify({ like: like });
|
|
3793
3838
|
const response = await this.caller.call(async () => {
|
|
3794
3839
|
const res = await this._fetch(`${this.apiUrl}/likes/${owner}/${promptName}`, {
|
|
@@ -3807,7 +3852,7 @@ class Client {
|
|
|
3807
3852
|
return response.json();
|
|
3808
3853
|
}
|
|
3809
3854
|
async _getPromptUrl(promptIdentifier) {
|
|
3810
|
-
const [owner, promptName, commitHash] = (0, prompts_js_1.
|
|
3855
|
+
const [owner, promptName, commitHash] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
3811
3856
|
if (!(await this._currentTenantIsOwner(owner))) {
|
|
3812
3857
|
if (commitHash !== "latest") {
|
|
3813
3858
|
return `${this.getHostUrl()}/hub/${owner}/${promptName}/${commitHash.substring(0, 8)}`;
|
|
@@ -3899,7 +3944,7 @@ class Client {
|
|
|
3899
3944
|
* ```
|
|
3900
3945
|
*/
|
|
3901
3946
|
async *listCommits(promptIdentifier) {
|
|
3902
|
-
const [owner, promptName, _] = (0, prompts_js_1.
|
|
3947
|
+
const [owner, promptName, _] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
3903
3948
|
for await (const commits of this._getPaginated(`/commits/${owner}/${promptName}/`, new URLSearchParams(), (res) => res.commits)) {
|
|
3904
3949
|
yield* commits;
|
|
3905
3950
|
}
|
|
@@ -3962,7 +4007,7 @@ class Client {
|
|
|
3962
4007
|
* ```
|
|
3963
4008
|
*/
|
|
3964
4009
|
async getPrompt(promptIdentifier) {
|
|
3965
|
-
const [owner, promptName, _] = (0, prompts_js_1.
|
|
4010
|
+
const [owner, promptName, _] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
3966
4011
|
const response = await this.caller.call(async () => {
|
|
3967
4012
|
const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
|
|
3968
4013
|
method: "GET",
|
|
@@ -4019,7 +4064,7 @@ class Client {
|
|
|
4019
4064
|
You can add a handle by creating a public prompt at:\n
|
|
4020
4065
|
https://smith.langchain.com/prompts`);
|
|
4021
4066
|
}
|
|
4022
|
-
const [owner, promptName, _] = (0, prompts_js_1.
|
|
4067
|
+
const [owner, promptName, _] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
4023
4068
|
if (!(await this._currentTenantIsOwner(owner))) {
|
|
4024
4069
|
throw await this._ownerConflictError("create a prompt", owner);
|
|
4025
4070
|
}
|
|
@@ -4078,7 +4123,7 @@ class Client {
|
|
|
4078
4123
|
if (!(await this.promptExists(promptIdentifier))) {
|
|
4079
4124
|
throw new Error("Prompt does not exist, you must create it first.");
|
|
4080
4125
|
}
|
|
4081
|
-
const [owner, promptName, _] = (0, prompts_js_1.
|
|
4126
|
+
const [owner, promptName, _] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
4082
4127
|
const resolvedParentCommitHash = options?.parentCommitHash === "latest" || !options?.parentCommitHash
|
|
4083
4128
|
? await this._getLatestCommitHash(`${owner}/${promptName}`)
|
|
4084
4129
|
: options?.parentCommitHash;
|
|
@@ -4276,7 +4321,7 @@ class Client {
|
|
|
4276
4321
|
if (!(await this.promptExists(promptIdentifier))) {
|
|
4277
4322
|
throw new Error("Prompt does not exist, you must create it first.");
|
|
4278
4323
|
}
|
|
4279
|
-
const [owner, promptName] = (0, prompts_js_1.
|
|
4324
|
+
const [owner, promptName] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
4280
4325
|
if (!(await this._currentTenantIsOwner(owner))) {
|
|
4281
4326
|
throw await this._ownerConflictError("update a prompt", owner);
|
|
4282
4327
|
}
|
|
@@ -4316,7 +4361,7 @@ class Client {
|
|
|
4316
4361
|
if (!(await this.promptExists(promptIdentifier))) {
|
|
4317
4362
|
throw new Error("Prompt does not exist, you must create it first.");
|
|
4318
4363
|
}
|
|
4319
|
-
const [owner, promptName, _] = (0, prompts_js_1.
|
|
4364
|
+
const [owner, promptName, _] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
4320
4365
|
if (!(await this._currentTenantIsOwner(owner))) {
|
|
4321
4366
|
throw await this._ownerConflictError("delete a prompt", owner);
|
|
4322
4367
|
}
|
|
@@ -4344,7 +4389,7 @@ class Client {
|
|
|
4344
4389
|
* Fetch a prompt commit directly from the API (bypassing cache).
|
|
4345
4390
|
*/
|
|
4346
4391
|
async _fetchPromptFromApi(promptIdentifier, options) {
|
|
4347
|
-
const [owner, promptName, commitHash] = (0, prompts_js_1.
|
|
4392
|
+
const [owner, promptName, commitHash] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
4348
4393
|
const response = await this.caller.call(async () => {
|
|
4349
4394
|
const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
|
|
4350
4395
|
method: "GET",
|
|
@@ -4424,6 +4469,251 @@ class Client {
|
|
|
4424
4469
|
});
|
|
4425
4470
|
return url;
|
|
4426
4471
|
}
|
|
4472
|
+
/**
|
|
4473
|
+
* Check if an agent repo exists.
|
|
4474
|
+
*/
|
|
4475
|
+
async agentExists(identifier) {
|
|
4476
|
+
const [owner, name] = (0, prompts_js_1.parseHubIdentifier)(identifier);
|
|
4477
|
+
return this._repoExists(owner, name);
|
|
4478
|
+
}
|
|
4479
|
+
/**
|
|
4480
|
+
* Check if a skill repo exists.
|
|
4481
|
+
*/
|
|
4482
|
+
async skillExists(identifier) {
|
|
4483
|
+
const [owner, name] = (0, prompts_js_1.parseHubIdentifier)(identifier);
|
|
4484
|
+
return this._repoExists(owner, name);
|
|
4485
|
+
}
|
|
4486
|
+
/**
|
|
4487
|
+
* Pull an agent directory from Hub.
|
|
4488
|
+
* @param identifier The identifier (owner/name[:version]).
|
|
4489
|
+
* @param options.version Commit hash or tag; overrides identifier's version.
|
|
4490
|
+
*/
|
|
4491
|
+
async pullAgent(identifier, options) {
|
|
4492
|
+
return (await this._pullDirectory(identifier, "agent", options?.version));
|
|
4493
|
+
}
|
|
4494
|
+
/**
|
|
4495
|
+
* Pull a skill directory from Hub.
|
|
4496
|
+
*/
|
|
4497
|
+
async pullSkill(identifier, options) {
|
|
4498
|
+
return (await this._pullDirectory(identifier, "skill", options?.version));
|
|
4499
|
+
}
|
|
4500
|
+
/**
|
|
4501
|
+
* Push an agent to Hub. Creates the repo if missing, patches metadata if
|
|
4502
|
+
* provided, then commits the given files.
|
|
4503
|
+
* @returns The URL of the resulting commit.
|
|
4504
|
+
*/
|
|
4505
|
+
async pushAgent(identifier, options) {
|
|
4506
|
+
return this._pushDirectory(identifier, "agent", options);
|
|
4507
|
+
}
|
|
4508
|
+
/**
|
|
4509
|
+
* Push a skill to Hub.
|
|
4510
|
+
*/
|
|
4511
|
+
async pushSkill(identifier, options) {
|
|
4512
|
+
return this._pushDirectory(identifier, "skill", options);
|
|
4513
|
+
}
|
|
4514
|
+
/**
|
|
4515
|
+
* Delete an agent and all its owned child file repos.
|
|
4516
|
+
*/
|
|
4517
|
+
async deleteAgent(identifier) {
|
|
4518
|
+
return this._deleteDirectory(identifier);
|
|
4519
|
+
}
|
|
4520
|
+
/**
|
|
4521
|
+
* Delete a skill and all its owned child file repos.
|
|
4522
|
+
*/
|
|
4523
|
+
async deleteSkill(identifier) {
|
|
4524
|
+
return this._deleteDirectory(identifier);
|
|
4525
|
+
}
|
|
4526
|
+
/**
|
|
4527
|
+
* List agent repos. Yields one at a time, auto-paginating.
|
|
4528
|
+
*/
|
|
4529
|
+
async *listAgents(options) {
|
|
4530
|
+
yield* this._listReposByType("agent", options);
|
|
4531
|
+
}
|
|
4532
|
+
/**
|
|
4533
|
+
* List skill repos. Yields one at a time, auto-paginating.
|
|
4534
|
+
*/
|
|
4535
|
+
async *listSkills(options) {
|
|
4536
|
+
yield* this._listReposByType("skill", options);
|
|
4537
|
+
}
|
|
4538
|
+
async *_listReposByType(repoType, options) {
|
|
4539
|
+
const params = new URLSearchParams();
|
|
4540
|
+
params.append("repo_type", repoType);
|
|
4541
|
+
params.append("is_archived", (!!options?.isArchived).toString());
|
|
4542
|
+
if (options?.isPublic !== undefined) {
|
|
4543
|
+
params.append("is_public", options.isPublic.toString());
|
|
4544
|
+
}
|
|
4545
|
+
if (options?.query) {
|
|
4546
|
+
params.append("query", options.query);
|
|
4547
|
+
}
|
|
4548
|
+
for await (const repos of this._getPaginated("/repos", params, (res) => res.repos)) {
|
|
4549
|
+
yield* repos;
|
|
4550
|
+
}
|
|
4551
|
+
}
|
|
4552
|
+
async _pullDirectory(identifier, repoType, version) {
|
|
4553
|
+
const [owner, name, parsedVersion] = (0, prompts_js_1.parseHubIdentifier)(identifier);
|
|
4554
|
+
const resolvedVersion = version ?? (parsedVersion !== "latest" ? parsedVersion : undefined);
|
|
4555
|
+
const url = new URL(`${this.apiUrl}/v1/platform/hub/repos/${owner}/${name}/directories`);
|
|
4556
|
+
url.searchParams.set("repo_type", repoType);
|
|
4557
|
+
if (resolvedVersion) {
|
|
4558
|
+
url.searchParams.set("commit", resolvedVersion);
|
|
4559
|
+
}
|
|
4560
|
+
const response = await this.caller.call(async () => {
|
|
4561
|
+
const res = await this._fetch(url.toString(), {
|
|
4562
|
+
method: "GET",
|
|
4563
|
+
headers: this._mergedHeaders,
|
|
4564
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
4565
|
+
...this.fetchOptions,
|
|
4566
|
+
});
|
|
4567
|
+
await (0, error_js_1.raiseForStatus)(res, "pull directory");
|
|
4568
|
+
return res;
|
|
4569
|
+
});
|
|
4570
|
+
return (await response.json());
|
|
4571
|
+
}
|
|
4572
|
+
async _pushDirectory(identifier, repoType, options) {
|
|
4573
|
+
if (options.parentCommit !== undefined &&
|
|
4574
|
+
(options.parentCommit.length < 8 || options.parentCommit.length > 64)) {
|
|
4575
|
+
throw new Error("parent_commit must be 8-64 characters");
|
|
4576
|
+
}
|
|
4577
|
+
const [owner, name] = (0, prompts_js_1.parseHubIdentifier)(identifier);
|
|
4578
|
+
if (!(await this._currentTenantIsOwner(owner))) {
|
|
4579
|
+
throw await this._ownerConflictError(`push ${repoType}`, owner);
|
|
4580
|
+
}
|
|
4581
|
+
if (await this._repoExists(owner, name)) {
|
|
4582
|
+
if (options.description !== undefined ||
|
|
4583
|
+
options.readme !== undefined ||
|
|
4584
|
+
options.tags !== undefined ||
|
|
4585
|
+
options.isPublic !== undefined) {
|
|
4586
|
+
await this._updateRepoMetadata(owner, name, options);
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4589
|
+
else {
|
|
4590
|
+
const REPO_HANDLE_PATTERN = /^[a-z][a-z0-9-_]*$/;
|
|
4591
|
+
if (!REPO_HANDLE_PATTERN.test(name)) {
|
|
4592
|
+
throw new Error(`Invalid repo_handle ${JSON.stringify(name)}: must match ${REPO_HANDLE_PATTERN}`);
|
|
4593
|
+
}
|
|
4594
|
+
await this._createRepo(name, repoType, options);
|
|
4595
|
+
}
|
|
4596
|
+
const body = { files: options.files };
|
|
4597
|
+
if (options.parentCommit) {
|
|
4598
|
+
body.parent_commit = options.parentCommit;
|
|
4599
|
+
}
|
|
4600
|
+
const response = await this.caller.call(async () => {
|
|
4601
|
+
const res = await this._fetch(`${this.apiUrl}/v1/platform/hub/repos/${owner}/${name}/directories/commits`, {
|
|
4602
|
+
method: "POST",
|
|
4603
|
+
headers: {
|
|
4604
|
+
...this._mergedHeaders,
|
|
4605
|
+
"Content-Type": "application/json",
|
|
4606
|
+
},
|
|
4607
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
4608
|
+
...this.fetchOptions,
|
|
4609
|
+
body: JSON.stringify(body),
|
|
4610
|
+
});
|
|
4611
|
+
await (0, error_js_1.raiseForStatus)(res, `push ${repoType}`);
|
|
4612
|
+
return res;
|
|
4613
|
+
});
|
|
4614
|
+
const data = (await response.json());
|
|
4615
|
+
const commitHash = data.commit.commit_hash;
|
|
4616
|
+
return `${this.getHostUrl()}/hub/${owner}/${name}:${commitHash.slice(0, 8)}`;
|
|
4617
|
+
}
|
|
4618
|
+
async _deleteDirectory(identifier) {
|
|
4619
|
+
const [owner, name] = (0, prompts_js_1.parseHubIdentifier)(identifier);
|
|
4620
|
+
if (!(await this._currentTenantIsOwner(owner))) {
|
|
4621
|
+
throw await this._ownerConflictError("delete", owner);
|
|
4622
|
+
}
|
|
4623
|
+
await this.caller.call(async () => {
|
|
4624
|
+
const res = await this._fetch(`${this.apiUrl}/v1/platform/hub/repos/${owner}/${name}/directories`, {
|
|
4625
|
+
method: "DELETE",
|
|
4626
|
+
headers: this._mergedHeaders,
|
|
4627
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
4628
|
+
...this.fetchOptions,
|
|
4629
|
+
});
|
|
4630
|
+
await (0, error_js_1.raiseForStatus)(res, "delete directory");
|
|
4631
|
+
return res;
|
|
4632
|
+
});
|
|
4633
|
+
}
|
|
4634
|
+
async _repoExists(owner, name) {
|
|
4635
|
+
try {
|
|
4636
|
+
await this.caller.call(async () => {
|
|
4637
|
+
const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${name}`, {
|
|
4638
|
+
method: "GET",
|
|
4639
|
+
headers: this._mergedHeaders,
|
|
4640
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
4641
|
+
...this.fetchOptions,
|
|
4642
|
+
});
|
|
4643
|
+
await (0, error_js_1.raiseForStatus)(res, "check repo exists");
|
|
4644
|
+
return res;
|
|
4645
|
+
});
|
|
4646
|
+
return true;
|
|
4647
|
+
}
|
|
4648
|
+
catch (e) {
|
|
4649
|
+
if ((0, error_js_1.isLangSmithNotFoundError)(e)) {
|
|
4650
|
+
return false;
|
|
4651
|
+
}
|
|
4652
|
+
throw e;
|
|
4653
|
+
}
|
|
4654
|
+
}
|
|
4655
|
+
async _createRepo(name, repoType, options) {
|
|
4656
|
+
const body = {
|
|
4657
|
+
repo_handle: name,
|
|
4658
|
+
repo_type: repoType,
|
|
4659
|
+
is_public: !!options.isPublic,
|
|
4660
|
+
};
|
|
4661
|
+
if (options.description !== undefined)
|
|
4662
|
+
body.description = options.description;
|
|
4663
|
+
if (options.readme !== undefined)
|
|
4664
|
+
body.readme = options.readme;
|
|
4665
|
+
if (options.tags !== undefined)
|
|
4666
|
+
body.tags = options.tags;
|
|
4667
|
+
try {
|
|
4668
|
+
await this.caller.call(async () => {
|
|
4669
|
+
const res = await this._fetch(`${this.apiUrl}/repos/`, {
|
|
4670
|
+
method: "POST",
|
|
4671
|
+
headers: {
|
|
4672
|
+
...this._mergedHeaders,
|
|
4673
|
+
"Content-Type": "application/json",
|
|
4674
|
+
},
|
|
4675
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
4676
|
+
...this.fetchOptions,
|
|
4677
|
+
body: JSON.stringify(body),
|
|
4678
|
+
});
|
|
4679
|
+
await (0, error_js_1.raiseForStatus)(res, `create ${repoType}`);
|
|
4680
|
+
return res;
|
|
4681
|
+
});
|
|
4682
|
+
}
|
|
4683
|
+
catch (e) {
|
|
4684
|
+
if ((0, error_js_1.isLangSmithConflictError)(e)) {
|
|
4685
|
+
return;
|
|
4686
|
+
}
|
|
4687
|
+
throw e;
|
|
4688
|
+
}
|
|
4689
|
+
}
|
|
4690
|
+
async _updateRepoMetadata(owner, name, options) {
|
|
4691
|
+
const body = {};
|
|
4692
|
+
if (options.description !== undefined)
|
|
4693
|
+
body.description = options.description;
|
|
4694
|
+
if (options.readme !== undefined)
|
|
4695
|
+
body.readme = options.readme;
|
|
4696
|
+
if (options.tags !== undefined)
|
|
4697
|
+
body.tags = options.tags;
|
|
4698
|
+
if (options.isPublic !== undefined)
|
|
4699
|
+
body.is_public = options.isPublic;
|
|
4700
|
+
if (Object.keys(body).length === 0)
|
|
4701
|
+
return;
|
|
4702
|
+
await this.caller.call(async () => {
|
|
4703
|
+
const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${name}`, {
|
|
4704
|
+
method: "PATCH",
|
|
4705
|
+
headers: {
|
|
4706
|
+
...this._mergedHeaders,
|
|
4707
|
+
"Content-Type": "application/json",
|
|
4708
|
+
},
|
|
4709
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
4710
|
+
...this.fetchOptions,
|
|
4711
|
+
body: JSON.stringify(body),
|
|
4712
|
+
});
|
|
4713
|
+
await (0, error_js_1.raiseForStatus)(res, "update repo metadata");
|
|
4714
|
+
return res;
|
|
4715
|
+
});
|
|
4716
|
+
}
|
|
4427
4717
|
/**
|
|
4428
4718
|
* Clone a public dataset to your own langsmith tenant.
|
|
4429
4719
|
* This operation is idempotent. If you already have a dataset with the given name,
|
|
@@ -4563,6 +4853,33 @@ class Client {
|
|
|
4563
4853
|
await (0, otel_js_1.getDefaultOTLPTracerComponents)()?.DEFAULT_LANGSMITH_SPAN_PROCESSOR?.forceFlush();
|
|
4564
4854
|
}
|
|
4565
4855
|
}
|
|
4856
|
+
/**
|
|
4857
|
+
* Returns a string representation of the Client instance.
|
|
4858
|
+
* This method is called when the object is converted to a string
|
|
4859
|
+
* or logged, ensuring sensitive information like API keys is not exposed.
|
|
4860
|
+
*
|
|
4861
|
+
* @returns A string representation of the Client.
|
|
4862
|
+
*/
|
|
4863
|
+
toString() {
|
|
4864
|
+
const params = [`apiUrl=${JSON.stringify(this.apiUrl)}`];
|
|
4865
|
+
if (this.webUrl !== undefined) {
|
|
4866
|
+
params.push(`webUrl=${JSON.stringify(this.webUrl)}`);
|
|
4867
|
+
}
|
|
4868
|
+
if (this.workspaceId !== undefined) {
|
|
4869
|
+
params.push(`workspaceId=${JSON.stringify(this.workspaceId)}`);
|
|
4870
|
+
}
|
|
4871
|
+
return `[LangSmithClient ${params.join(" ")}]`;
|
|
4872
|
+
}
|
|
4873
|
+
/**
|
|
4874
|
+
* Custom inspect method for Node.js.
|
|
4875
|
+
* This method is called when the object is inspected in the Node.js REPL
|
|
4876
|
+
* or with console.log, ensuring sensitive information like API keys is not exposed.
|
|
4877
|
+
*
|
|
4878
|
+
* @returns A string representation of the Client for inspection.
|
|
4879
|
+
*/
|
|
4880
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
4881
|
+
return this.toString();
|
|
4882
|
+
}
|
|
4566
4883
|
}
|
|
4567
4884
|
exports.Client = Client;
|
|
4568
4885
|
Object.defineProperty(Client, "_fallbackDirsCreated", {
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OTELContext } from "./experimental/otel/types.js";
|
|
2
2
|
import { AsyncCallerParams } from "./utils/async_caller.js";
|
|
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, TimeDelta, TracerSession, TracerSessionResult, ValueType, AnnotationQueue, RunWithAnnotationQueueInfo, Attachments, UploadExamplesResponse, UpdateExamplesResponse, DatasetVersion, AnnotationQueueWithDetails, AnnotationQueueRubricItem, FeedbackConfigSchema } from "./schemas.js";
|
|
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, TimeDelta, TracerSession, TracerSessionResult, ValueType, AnnotationQueue, RunWithAnnotationQueueInfo, Attachments, UploadExamplesResponse, UpdateExamplesResponse, DatasetVersion, AnnotationQueueWithDetails, AnnotationQueueRubricItem, FeedbackConfigSchema, AgentContext, SkillContext, Entry } from "./schemas.js";
|
|
4
4
|
import { EvaluationResult, EvaluationResults } from "./evaluation/evaluator.js";
|
|
5
5
|
import { PromptCache } from "./utils/prompt_cache/index.js";
|
|
6
6
|
export interface ClientConfig {
|
|
@@ -12,6 +12,7 @@ export interface ClientConfig {
|
|
|
12
12
|
anonymizer?: (values: KVMap) => KVMap | Promise<KVMap>;
|
|
13
13
|
hideInputs?: boolean | ((inputs: KVMap) => KVMap | Promise<KVMap>);
|
|
14
14
|
hideOutputs?: boolean | ((outputs: KVMap) => KVMap | Promise<KVMap>);
|
|
15
|
+
hideMetadata?: boolean | ((metadata: KVMap) => KVMap | Promise<KVMap>);
|
|
15
16
|
/**
|
|
16
17
|
* Whether to omit runtime information from traced runs.
|
|
17
18
|
* If true, runtime information (SDK version, platform, etc.) and
|
|
@@ -396,6 +397,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
396
397
|
private _tenantId;
|
|
397
398
|
private hideInputs?;
|
|
398
399
|
private hideOutputs?;
|
|
400
|
+
private hideMetadata?;
|
|
399
401
|
private omitTracedRuntimeInfo?;
|
|
400
402
|
private tracingSampleRate?;
|
|
401
403
|
private filteredPostUuids;
|
|
@@ -432,6 +434,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
432
434
|
webUrl?: string;
|
|
433
435
|
hideInputs?: boolean;
|
|
434
436
|
hideOutputs?: boolean;
|
|
437
|
+
hideMetadata?: boolean;
|
|
435
438
|
};
|
|
436
439
|
getHostUrl(): string;
|
|
437
440
|
private get _mergedHeaders();
|
|
@@ -445,6 +448,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
445
448
|
private _getPlatformEndpointPath;
|
|
446
449
|
private processInputs;
|
|
447
450
|
private processOutputs;
|
|
451
|
+
private processMetadata;
|
|
448
452
|
/**
|
|
449
453
|
* Filter content from new_token events to prevent streaming LLM output
|
|
450
454
|
* from being uploaded via events.
|
|
@@ -1302,6 +1306,83 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
1302
1306
|
tags?: string[];
|
|
1303
1307
|
commitDescription?: string;
|
|
1304
1308
|
}): Promise<string>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Check if an agent repo exists.
|
|
1311
|
+
*/
|
|
1312
|
+
agentExists(identifier: string): Promise<boolean>;
|
|
1313
|
+
/**
|
|
1314
|
+
* Check if a skill repo exists.
|
|
1315
|
+
*/
|
|
1316
|
+
skillExists(identifier: string): Promise<boolean>;
|
|
1317
|
+
/**
|
|
1318
|
+
* Pull an agent directory from Hub.
|
|
1319
|
+
* @param identifier The identifier (owner/name[:version]).
|
|
1320
|
+
* @param options.version Commit hash or tag; overrides identifier's version.
|
|
1321
|
+
*/
|
|
1322
|
+
pullAgent(identifier: string, options?: {
|
|
1323
|
+
version?: string;
|
|
1324
|
+
}): Promise<AgentContext>;
|
|
1325
|
+
/**
|
|
1326
|
+
* Pull a skill directory from Hub.
|
|
1327
|
+
*/
|
|
1328
|
+
pullSkill(identifier: string, options?: {
|
|
1329
|
+
version?: string;
|
|
1330
|
+
}): Promise<SkillContext>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Push an agent to Hub. Creates the repo if missing, patches metadata if
|
|
1333
|
+
* provided, then commits the given files.
|
|
1334
|
+
* @returns The URL of the resulting commit.
|
|
1335
|
+
*/
|
|
1336
|
+
pushAgent(identifier: string, options: {
|
|
1337
|
+
files: Record<string, Entry | null>;
|
|
1338
|
+
parentCommit?: string;
|
|
1339
|
+
description?: string;
|
|
1340
|
+
readme?: string;
|
|
1341
|
+
tags?: string[];
|
|
1342
|
+
isPublic?: boolean;
|
|
1343
|
+
}): Promise<string>;
|
|
1344
|
+
/**
|
|
1345
|
+
* Push a skill to Hub.
|
|
1346
|
+
*/
|
|
1347
|
+
pushSkill(identifier: string, options: {
|
|
1348
|
+
files: Record<string, Entry | null>;
|
|
1349
|
+
parentCommit?: string;
|
|
1350
|
+
description?: string;
|
|
1351
|
+
readme?: string;
|
|
1352
|
+
tags?: string[];
|
|
1353
|
+
isPublic?: boolean;
|
|
1354
|
+
}): Promise<string>;
|
|
1355
|
+
/**
|
|
1356
|
+
* Delete an agent and all its owned child file repos.
|
|
1357
|
+
*/
|
|
1358
|
+
deleteAgent(identifier: string): Promise<void>;
|
|
1359
|
+
/**
|
|
1360
|
+
* Delete a skill and all its owned child file repos.
|
|
1361
|
+
*/
|
|
1362
|
+
deleteSkill(identifier: string): Promise<void>;
|
|
1363
|
+
/**
|
|
1364
|
+
* List agent repos. Yields one at a time, auto-paginating.
|
|
1365
|
+
*/
|
|
1366
|
+
listAgents(options?: {
|
|
1367
|
+
isPublic?: boolean;
|
|
1368
|
+
isArchived?: boolean;
|
|
1369
|
+
query?: string;
|
|
1370
|
+
}): AsyncIterableIterator<Prompt>;
|
|
1371
|
+
/**
|
|
1372
|
+
* List skill repos. Yields one at a time, auto-paginating.
|
|
1373
|
+
*/
|
|
1374
|
+
listSkills(options?: {
|
|
1375
|
+
isPublic?: boolean;
|
|
1376
|
+
isArchived?: boolean;
|
|
1377
|
+
query?: string;
|
|
1378
|
+
}): AsyncIterableIterator<Prompt>;
|
|
1379
|
+
private _listReposByType;
|
|
1380
|
+
private _pullDirectory;
|
|
1381
|
+
private _pushDirectory;
|
|
1382
|
+
private _deleteDirectory;
|
|
1383
|
+
private _repoExists;
|
|
1384
|
+
private _createRepo;
|
|
1385
|
+
private _updateRepoMetadata;
|
|
1305
1386
|
/**
|
|
1306
1387
|
* Clone a public dataset to your own langsmith tenant.
|
|
1307
1388
|
* This operation is idempotent. If you already have a dataset with the given name,
|
|
@@ -1345,6 +1426,14 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
1345
1426
|
* @returns A promise that resolves once all currently pending traces have sent.
|
|
1346
1427
|
*/
|
|
1347
1428
|
awaitPendingTraceBatches(): Promise<void>;
|
|
1429
|
+
/**
|
|
1430
|
+
* Returns a string representation of the Client instance.
|
|
1431
|
+
* This method is called when the object is converted to a string
|
|
1432
|
+
* or logged, ensuring sensitive information like API keys is not exposed.
|
|
1433
|
+
*
|
|
1434
|
+
* @returns A string representation of the Client.
|
|
1435
|
+
*/
|
|
1436
|
+
toString(): string;
|
|
1348
1437
|
}
|
|
1349
1438
|
export interface LangSmithTracingClientInterface {
|
|
1350
1439
|
createRun: (run: CreateRunParams) => Promise<void>;
|