langsmith 0.0.1-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.
Files changed (50) hide show
  1. package/README.md +262 -0
  2. package/client.cjs +1 -0
  3. package/client.d.ts +1 -0
  4. package/client.js +1 -0
  5. package/dist/cli/docker-compose.ngrok.yaml +17 -0
  6. package/dist/cli/docker-compose.yaml +43 -0
  7. package/dist/cli/main.cjs +278 -0
  8. package/dist/cli/main.d.ts +1 -0
  9. package/dist/cli/main.js +252 -0
  10. package/dist/cli/main.ts +292 -0
  11. package/dist/client.cjs +588 -0
  12. package/dist/client.d.ts +130 -0
  13. package/dist/client.js +561 -0
  14. package/dist/evaluation/evaluator.cjs +2 -0
  15. package/dist/evaluation/evaluator.d.ts +12 -0
  16. package/dist/evaluation/evaluator.js +1 -0
  17. package/dist/evaluation/index.cjs +5 -0
  18. package/dist/evaluation/index.d.ts +2 -0
  19. package/dist/evaluation/index.js +1 -0
  20. package/dist/evaluation/string_evaluator.cjs +66 -0
  21. package/dist/evaluation/string_evaluator.d.ts +30 -0
  22. package/dist/evaluation/string_evaluator.js +62 -0
  23. package/dist/index.cjs +7 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.js +2 -0
  26. package/dist/run_trees.cjs +232 -0
  27. package/dist/run_trees.d.ts +47 -0
  28. package/dist/run_trees.js +205 -0
  29. package/dist/schemas.cjs +2 -0
  30. package/dist/schemas.d.ts +117 -0
  31. package/dist/schemas.js +1 -0
  32. package/dist/utils/async_caller.cjs +111 -0
  33. package/dist/utils/async_caller.d.ts +37 -0
  34. package/dist/utils/async_caller.js +104 -0
  35. package/dist/utils/env.cjs +80 -0
  36. package/dist/utils/env.d.ts +22 -0
  37. package/dist/utils/env.js +68 -0
  38. package/evaluation.cjs +1 -0
  39. package/evaluation.d.ts +1 -0
  40. package/evaluation.js +1 -0
  41. package/index.cjs +1 -0
  42. package/index.d.ts +1 -0
  43. package/index.js +1 -0
  44. package/package.json +121 -0
  45. package/run_trees.cjs +1 -0
  46. package/run_trees.d.ts +1 -0
  47. package/run_trees.js +1 -0
  48. package/schemas.cjs +1 -0
  49. package/schemas.d.ts +1 -0
  50. package/schemas.js +1 -0
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,117 @@
1
+ export interface TracerSession {
2
+ tenant_id: string;
3
+ id: string;
4
+ start_time: number;
5
+ name?: string;
6
+ mode?: string;
7
+ }
8
+ export interface TracerSessionResult extends TracerSession {
9
+ run_count?: number;
10
+ latency_p50?: number;
11
+ latency_p99?: number;
12
+ total_tokens?: number;
13
+ prompt_tokens?: number;
14
+ completion_tokens?: number;
15
+ last_run_start_time?: number;
16
+ feedback_stats?: Record<string, unknown>;
17
+ reference_dataset_ids?: string[];
18
+ run_facets?: KVMap[];
19
+ }
20
+ export type KVMap = Record<string, any>;
21
+ export type RunType = "llm" | "chain" | "tool";
22
+ export type ScoreType = number | boolean | null;
23
+ export type ValueType = number | boolean | string | object | null;
24
+ export interface BaseExample {
25
+ dataset_id: string;
26
+ inputs: KVMap;
27
+ outputs?: KVMap;
28
+ }
29
+ export interface BaseRun {
30
+ id?: string;
31
+ name: string;
32
+ serialized?: object;
33
+ inputs: KVMap;
34
+ run_type: RunType;
35
+ start_time?: number;
36
+ end_time?: number;
37
+ extra?: KVMap;
38
+ error?: string;
39
+ execution_order?: number;
40
+ outputs?: KVMap;
41
+ reference_example_id?: string;
42
+ parent_run_id?: string;
43
+ events?: KVMap[];
44
+ tags?: string[];
45
+ }
46
+ export interface Run extends BaseRun {
47
+ id: string;
48
+ session_id?: string;
49
+ execution_order: number;
50
+ start_time: number;
51
+ child_run_ids?: string[];
52
+ feedback_stats?: KVMap;
53
+ child_runs?: Run[];
54
+ }
55
+ export interface RunCreate extends BaseRun {
56
+ child_runs?: this[];
57
+ session_name?: string;
58
+ }
59
+ export interface RunUpdate {
60
+ end_time?: number;
61
+ error?: string;
62
+ outputs?: KVMap;
63
+ parent_run_id?: string;
64
+ reference_example_id?: string;
65
+ }
66
+ export interface ExampleCreate extends BaseExample {
67
+ id?: string;
68
+ created_at: string;
69
+ }
70
+ export interface Example extends BaseExample {
71
+ id: string;
72
+ created_at: string;
73
+ modified_at: string;
74
+ runs: Run[];
75
+ }
76
+ export interface ExampleUpdate {
77
+ dataset_id?: string;
78
+ inputs?: KVMap;
79
+ outputs?: KVMap;
80
+ }
81
+ export interface BaseDataset {
82
+ name: string;
83
+ description: string;
84
+ tenant_id: string;
85
+ }
86
+ export interface Dataset extends BaseDataset {
87
+ id: string;
88
+ created_at: string;
89
+ modified_at: string;
90
+ }
91
+ export interface FeedbackSourceBase {
92
+ type: string;
93
+ metadata?: KVMap;
94
+ }
95
+ export interface APIFeedbackSource extends FeedbackSourceBase {
96
+ type: "api";
97
+ }
98
+ export interface ModelFeedbackSource extends FeedbackSourceBase {
99
+ type: "model";
100
+ }
101
+ export interface FeedbackBase {
102
+ created_at: string;
103
+ modified_at: string;
104
+ run_id: string;
105
+ key: string;
106
+ score: ScoreType;
107
+ value: ValueType;
108
+ comment: string | null;
109
+ correction: string | object | null;
110
+ feedback_source: APIFeedbackSource | ModelFeedbackSource | KVMap | null;
111
+ }
112
+ export interface FeedbackCreate extends FeedbackBase {
113
+ id: string;
114
+ }
115
+ export interface Feedback extends FeedbackBase {
116
+ id: string;
117
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AsyncCaller = void 0;
7
+ const p_retry_1 = __importDefault(require("p-retry"));
8
+ const p_queue_1 = __importDefault(require("p-queue"));
9
+ const STATUS_NO_RETRY = [
10
+ 400,
11
+ 401,
12
+ 403,
13
+ 404,
14
+ 405,
15
+ 406,
16
+ 407,
17
+ 408,
18
+ 409, // Conflict
19
+ ];
20
+ /**
21
+ * A class that can be used to make async calls with concurrency and retry logic.
22
+ *
23
+ * This is useful for making calls to any kind of "expensive" external resource,
24
+ * be it because it's rate-limited, subject to network issues, etc.
25
+ *
26
+ * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
27
+ * to `Infinity`. This means that by default, all calls will be made in parallel.
28
+ *
29
+ * Retries are limited by the `maxRetries` parameter, which defaults to 6. This
30
+ * means that by default, each call will be retried up to 6 times, with an
31
+ * exponential backoff between each attempt.
32
+ */
33
+ class AsyncCaller {
34
+ constructor(params) {
35
+ Object.defineProperty(this, "maxConcurrency", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ Object.defineProperty(this, "maxRetries", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: void 0
46
+ });
47
+ Object.defineProperty(this, "queue", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ this.maxConcurrency = params.maxConcurrency ?? Infinity;
54
+ this.maxRetries = params.maxRetries ?? 6;
55
+ const PQueue = "default" in p_queue_1.default ? p_queue_1.default.default : p_queue_1.default;
56
+ this.queue = new PQueue({ concurrency: this.maxConcurrency });
57
+ }
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ call(callable, ...args) {
60
+ return this.queue.add(() => (0, p_retry_1.default)(() => callable(...args).catch((error) => {
61
+ // eslint-disable-next-line no-instanceof/no-instanceof
62
+ if (error instanceof Error) {
63
+ throw error;
64
+ }
65
+ else {
66
+ throw new Error(error);
67
+ }
68
+ }), {
69
+ onFailedAttempt(error) {
70
+ if (error.message.startsWith("Cancel") ||
71
+ error.message.startsWith("TimeoutError") ||
72
+ error.message.startsWith("AbortError")) {
73
+ throw error;
74
+ }
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ if (error?.code === "ECONNABORTED") {
77
+ throw error;
78
+ }
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ const status = error?.response?.status;
81
+ if (status && STATUS_NO_RETRY.includes(+status)) {
82
+ throw error;
83
+ }
84
+ },
85
+ retries: this.maxRetries,
86
+ randomize: true,
87
+ // If needed we can change some of the defaults here,
88
+ // but they're quite sensible.
89
+ }), { throwOnTimeout: true });
90
+ }
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ callWithOptions(options, callable, ...args) {
93
+ // Note this doesn't cancel the underlying request,
94
+ // when available prefer to use the signal option of the underlying call
95
+ if (options.signal) {
96
+ return Promise.race([
97
+ this.call(callable, ...args),
98
+ new Promise((_, reject) => {
99
+ options.signal?.addEventListener("abort", () => {
100
+ reject(new Error("AbortError"));
101
+ });
102
+ }),
103
+ ]);
104
+ }
105
+ return this.call(callable, ...args);
106
+ }
107
+ fetch(...args) {
108
+ return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
109
+ }
110
+ }
111
+ exports.AsyncCaller = AsyncCaller;
@@ -0,0 +1,37 @@
1
+ export interface AsyncCallerParams {
2
+ /**
3
+ * The maximum number of concurrent calls that can be made.
4
+ * Defaults to `Infinity`, which means no limit.
5
+ */
6
+ maxConcurrency?: number;
7
+ /**
8
+ * The maximum number of retries that can be made for a single call,
9
+ * with an exponential backoff between each attempt. Defaults to 6.
10
+ */
11
+ maxRetries?: number;
12
+ }
13
+ export interface AsyncCallerCallOptions {
14
+ signal?: AbortSignal;
15
+ }
16
+ /**
17
+ * A class that can be used to make async calls with concurrency and retry logic.
18
+ *
19
+ * This is useful for making calls to any kind of "expensive" external resource,
20
+ * be it because it's rate-limited, subject to network issues, etc.
21
+ *
22
+ * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
23
+ * to `Infinity`. This means that by default, all calls will be made in parallel.
24
+ *
25
+ * Retries are limited by the `maxRetries` parameter, which defaults to 6. This
26
+ * means that by default, each call will be retried up to 6 times, with an
27
+ * exponential backoff between each attempt.
28
+ */
29
+ export declare class AsyncCaller {
30
+ protected maxConcurrency: AsyncCallerParams["maxConcurrency"];
31
+ protected maxRetries: AsyncCallerParams["maxRetries"];
32
+ private queue;
33
+ constructor(params: AsyncCallerParams);
34
+ call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
35
+ callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
36
+ fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
37
+ }
@@ -0,0 +1,104 @@
1
+ import pRetry from "p-retry";
2
+ import PQueueMod from "p-queue";
3
+ const STATUS_NO_RETRY = [
4
+ 400,
5
+ 401,
6
+ 403,
7
+ 404,
8
+ 405,
9
+ 406,
10
+ 407,
11
+ 408,
12
+ 409, // Conflict
13
+ ];
14
+ /**
15
+ * A class that can be used to make async calls with concurrency and retry logic.
16
+ *
17
+ * This is useful for making calls to any kind of "expensive" external resource,
18
+ * be it because it's rate-limited, subject to network issues, etc.
19
+ *
20
+ * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
21
+ * to `Infinity`. This means that by default, all calls will be made in parallel.
22
+ *
23
+ * Retries are limited by the `maxRetries` parameter, which defaults to 6. This
24
+ * means that by default, each call will be retried up to 6 times, with an
25
+ * exponential backoff between each attempt.
26
+ */
27
+ export class AsyncCaller {
28
+ constructor(params) {
29
+ Object.defineProperty(this, "maxConcurrency", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ Object.defineProperty(this, "maxRetries", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ Object.defineProperty(this, "queue", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: void 0
46
+ });
47
+ this.maxConcurrency = params.maxConcurrency ?? Infinity;
48
+ this.maxRetries = params.maxRetries ?? 6;
49
+ const PQueue = "default" in PQueueMod ? PQueueMod.default : PQueueMod;
50
+ this.queue = new PQueue({ concurrency: this.maxConcurrency });
51
+ }
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ call(callable, ...args) {
54
+ return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
55
+ // eslint-disable-next-line no-instanceof/no-instanceof
56
+ if (error instanceof Error) {
57
+ throw error;
58
+ }
59
+ else {
60
+ throw new Error(error);
61
+ }
62
+ }), {
63
+ onFailedAttempt(error) {
64
+ if (error.message.startsWith("Cancel") ||
65
+ error.message.startsWith("TimeoutError") ||
66
+ error.message.startsWith("AbortError")) {
67
+ throw error;
68
+ }
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ if (error?.code === "ECONNABORTED") {
71
+ throw error;
72
+ }
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ const status = error?.response?.status;
75
+ if (status && STATUS_NO_RETRY.includes(+status)) {
76
+ throw error;
77
+ }
78
+ },
79
+ retries: this.maxRetries,
80
+ randomize: true,
81
+ // If needed we can change some of the defaults here,
82
+ // but they're quite sensible.
83
+ }), { throwOnTimeout: true });
84
+ }
85
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+ callWithOptions(options, callable, ...args) {
87
+ // Note this doesn't cancel the underlying request,
88
+ // when available prefer to use the signal option of the underlying call
89
+ if (options.signal) {
90
+ return Promise.race([
91
+ this.call(callable, ...args),
92
+ new Promise((_, reject) => {
93
+ options.signal?.addEventListener("abort", () => {
94
+ reject(new Error("AbortError"));
95
+ });
96
+ }),
97
+ ]);
98
+ }
99
+ return this.call(callable, ...args);
100
+ }
101
+ fetch(...args) {
102
+ return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
103
+ }
104
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setEnvironmentVariable = exports.getEnvironmentVariable = exports.getRuntimeEnvironment = exports.getEnv = exports.isNode = exports.isDeno = exports.isJsDom = exports.isWebWorker = exports.isBrowser = void 0;
4
+ const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
5
+ exports.isBrowser = isBrowser;
6
+ const isWebWorker = () => typeof globalThis === "object" &&
7
+ globalThis.constructor &&
8
+ globalThis.constructor.name === "DedicatedWorkerGlobalScope";
9
+ exports.isWebWorker = isWebWorker;
10
+ const isJsDom = () => (typeof window !== "undefined" && window.name === "nodejs") ||
11
+ (typeof navigator !== "undefined" &&
12
+ (navigator.userAgent.includes("Node.js") ||
13
+ navigator.userAgent.includes("jsdom")));
14
+ exports.isJsDom = isJsDom;
15
+ // Supabase Edge Function provides a `Deno` global object
16
+ // without `version` property
17
+ const isDeno = () => typeof Deno !== "undefined";
18
+ exports.isDeno = isDeno;
19
+ // Mark not-as-node if in Supabase Edge Function
20
+ const isNode = () => typeof process !== "undefined" &&
21
+ typeof process.versions !== "undefined" &&
22
+ typeof process.versions.node !== "undefined" &&
23
+ !(0, exports.isDeno)();
24
+ exports.isNode = isNode;
25
+ const getEnv = () => {
26
+ let env;
27
+ if ((0, exports.isBrowser)()) {
28
+ env = "browser";
29
+ }
30
+ else if ((0, exports.isNode)()) {
31
+ env = "node";
32
+ }
33
+ else if ((0, exports.isWebWorker)()) {
34
+ env = "webworker";
35
+ }
36
+ else if ((0, exports.isJsDom)()) {
37
+ env = "jsdom";
38
+ }
39
+ else if ((0, exports.isDeno)()) {
40
+ env = "deno";
41
+ }
42
+ else {
43
+ env = "other";
44
+ }
45
+ return env;
46
+ };
47
+ exports.getEnv = getEnv;
48
+ let runtimeEnvironment;
49
+ async function getRuntimeEnvironment() {
50
+ if (runtimeEnvironment === undefined) {
51
+ const env = (0, exports.getEnv)();
52
+ runtimeEnvironment = {
53
+ library: "langsmith",
54
+ runtime: env,
55
+ };
56
+ }
57
+ return runtimeEnvironment;
58
+ }
59
+ exports.getRuntimeEnvironment = getRuntimeEnvironment;
60
+ function getEnvironmentVariable(name) {
61
+ // Certain Deno setups will throw an error if you try to access environment variables
62
+ // https://github.com/hwchase17/langchainjs/issues/1412
63
+ try {
64
+ return typeof process !== "undefined"
65
+ ? // eslint-disable-next-line no-process-env
66
+ process.env?.[name]
67
+ : undefined;
68
+ }
69
+ catch (e) {
70
+ return undefined;
71
+ }
72
+ }
73
+ exports.getEnvironmentVariable = getEnvironmentVariable;
74
+ function setEnvironmentVariable(name, value) {
75
+ if (typeof process !== "undefined") {
76
+ // eslint-disable-next-line no-process-env
77
+ process.env[name] = value;
78
+ }
79
+ }
80
+ exports.setEnvironmentVariable = setEnvironmentVariable;
@@ -0,0 +1,22 @@
1
+ declare global {
2
+ const Deno: {
3
+ version: {
4
+ deno: string;
5
+ };
6
+ } | undefined;
7
+ }
8
+ export declare const isBrowser: () => boolean;
9
+ export declare const isWebWorker: () => boolean;
10
+ export declare const isJsDom: () => boolean;
11
+ export declare const isDeno: () => boolean;
12
+ export declare const isNode: () => boolean;
13
+ export declare const getEnv: () => string;
14
+ export type RuntimeEnvironment = {
15
+ library: string;
16
+ libraryVersion?: string;
17
+ runtime: string;
18
+ runtimeVersion?: string;
19
+ };
20
+ export declare function getRuntimeEnvironment(): Promise<RuntimeEnvironment>;
21
+ export declare function getEnvironmentVariable(name: string): string | undefined;
22
+ export declare function setEnvironmentVariable(name: string, value: string): void;
@@ -0,0 +1,68 @@
1
+ export const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
2
+ export const isWebWorker = () => typeof globalThis === "object" &&
3
+ globalThis.constructor &&
4
+ globalThis.constructor.name === "DedicatedWorkerGlobalScope";
5
+ export const isJsDom = () => (typeof window !== "undefined" && window.name === "nodejs") ||
6
+ (typeof navigator !== "undefined" &&
7
+ (navigator.userAgent.includes("Node.js") ||
8
+ navigator.userAgent.includes("jsdom")));
9
+ // Supabase Edge Function provides a `Deno` global object
10
+ // without `version` property
11
+ export const isDeno = () => typeof Deno !== "undefined";
12
+ // Mark not-as-node if in Supabase Edge Function
13
+ export const isNode = () => typeof process !== "undefined" &&
14
+ typeof process.versions !== "undefined" &&
15
+ typeof process.versions.node !== "undefined" &&
16
+ !isDeno();
17
+ export const getEnv = () => {
18
+ let env;
19
+ if (isBrowser()) {
20
+ env = "browser";
21
+ }
22
+ else if (isNode()) {
23
+ env = "node";
24
+ }
25
+ else if (isWebWorker()) {
26
+ env = "webworker";
27
+ }
28
+ else if (isJsDom()) {
29
+ env = "jsdom";
30
+ }
31
+ else if (isDeno()) {
32
+ env = "deno";
33
+ }
34
+ else {
35
+ env = "other";
36
+ }
37
+ return env;
38
+ };
39
+ let runtimeEnvironment;
40
+ export async function getRuntimeEnvironment() {
41
+ if (runtimeEnvironment === undefined) {
42
+ const env = getEnv();
43
+ runtimeEnvironment = {
44
+ library: "langsmith",
45
+ runtime: env,
46
+ };
47
+ }
48
+ return runtimeEnvironment;
49
+ }
50
+ export function getEnvironmentVariable(name) {
51
+ // Certain Deno setups will throw an error if you try to access environment variables
52
+ // https://github.com/hwchase17/langchainjs/issues/1412
53
+ try {
54
+ return typeof process !== "undefined"
55
+ ? // eslint-disable-next-line no-process-env
56
+ process.env?.[name]
57
+ : undefined;
58
+ }
59
+ catch (e) {
60
+ return undefined;
61
+ }
62
+ }
63
+ export function setEnvironmentVariable(name, value) {
64
+ if (typeof process !== "undefined") {
65
+ // eslint-disable-next-line no-process-env
66
+ process.env[name] = value;
67
+ }
68
+ }
package/evaluation.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/evaluation/index.cjs');
@@ -0,0 +1 @@
1
+ export * from './dist/evaluation/index.js'
package/evaluation.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/evaluation/index.js'
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/index.cjs');
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/index.js'
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/index.js'