@lmnr-ai/lmnr 0.4.39 → 0.4.40

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/cli.js CHANGED
@@ -36,7 +36,7 @@ var require_package = __commonJS({
36
36
  "package.json"(exports2, module2) {
37
37
  module2.exports = {
38
38
  name: "@lmnr-ai/lmnr",
39
- version: "0.4.39",
39
+ version: "0.4.40",
40
40
  description: "TypeScript SDK for Laminar AI",
41
41
  main: "dist/index.js",
42
42
  types: "dist/index.d.ts",
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.39\",\n \"description\": \"TypeScript SDK for Laminar AI\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup src/index.ts src/cli.ts --format esm,cjs --dts --external puppeteer --external puppeteer-core --external playwright\",\n \"test\": \"tsx --test test/*.test.ts\"\n },\n \"files\": [\n \"dist\",\n \"assets\"\n ],\n \"bin\": {\n \"lmnr\": \"./dist/cli.js\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/lmnr-ai/lmnr-ts.git\"\n },\n \"keywords\": [\n \"laminar\",\n \"lmnr\",\n \"sdk\",\n \"lmnr.ai\"\n ],\n \"author\": \"founders@lmnr.ai\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/lmnr-ai/lmnr-ts/issues\"\n },\n \"homepage\": \"https://github.com/lmnr-ai/lmnr-ts#README\",\n \"devDependencies\": {\n \"@anthropic-ai/sdk\": \"^0.33.1\",\n \"@aws-sdk/client-bedrock-runtime\": \"^3.716.0\",\n \"@azure/openai\": \"^2.0.0\",\n \"@browserbasehq/stagehand\": \"^1.10.1\",\n \"@google-cloud/aiplatform\": \"^3.34.0\",\n \"@google-cloud/vertexai\": \"^1.9.2\",\n \"@langchain/core\": \"^0.3.26\",\n \"@pinecone-database/pinecone\": \"^4.0.0\",\n \"@qdrant/js-client-rest\": \"^1.12.0\",\n \"@types/argparse\": \"^2.0.17\",\n \"@types/cli-progress\": \"^3.11.6\",\n \"@types/node\": \"^22.10.2\",\n \"@types/semver\": \"^7.5.8\",\n \"@types/uuid\": \"^10.0.0\",\n \"bufferutil\": \"^4.0.8\",\n \"chromadb\": \"^1.9.4\",\n \"cohere-ai\": \"^7.15.0\",\n \"langchain\": \"^0.3.8\",\n \"llamaindex\": \"^0.8.30\",\n \"openai\": \"^4.80.1\",\n \"playwright\": \"^1.50.0\",\n \"tsup\": \"^8.3.5\",\n \"tsx\": \"^4.19.2\",\n \"typescript\": \"^5.7.2\"\n },\n \"dependencies\": {\n \"@grpc/grpc-js\": \"^1.12.5\",\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/core\": \"^1.30.0\",\n \"@opentelemetry/exporter-trace-otlp-grpc\": \"^0.57.0\",\n \"@opentelemetry/exporter-trace-otlp-proto\": \"^0.57.0\",\n \"@opentelemetry/instrumentation\": \"^0.57.0\",\n \"@opentelemetry/otlp-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/otlp-grpc-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/sdk-node\": \"^0.57.0\",\n \"@opentelemetry/sdk-trace-base\": \"^1.30.0\",\n \"@opentelemetry/sdk-trace-node\": \"^1.30.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.28.0\",\n \"@traceloop/ai-semantic-conventions\": \"^0.11.6\",\n \"@traceloop/instrumentation-anthropic\": \"^0.11.6\",\n \"@traceloop/instrumentation-azure\": \"^0.11.6\",\n \"@traceloop/instrumentation-bedrock\": \"^0.11.6\",\n \"@traceloop/instrumentation-chromadb\": \"^0.11.6\",\n \"@traceloop/instrumentation-cohere\": \"^0.11.6\",\n \"@traceloop/instrumentation-langchain\": \"^0.11.6\",\n \"@traceloop/instrumentation-llamaindex\": \"^0.11.6\",\n \"@traceloop/instrumentation-openai\": \"^0.11.6\",\n \"@traceloop/instrumentation-pinecone\": \"^0.11.6\",\n \"@traceloop/instrumentation-qdrant\": \"^0.11.6\",\n \"@traceloop/instrumentation-vertexai\": \"^0.11.6\",\n \"argparse\": \"^2.0.1\",\n \"cli-progress\": \"^3.12.0\",\n \"esbuild\": \"^0.24.2\",\n \"glob\": \"^11.0.0\",\n \"uuid\": \"^11.0.3\"\n }\n}\n","#!/usr/bin/env node\n\nimport { ArgumentParser } from \"argparse\";\nimport * as esbuild from \"esbuild\";\nimport * as glob from \"glob\";\nimport { context, trace, propagation } from \"@opentelemetry/api\";\n\nconst pjson = require('../package.json');\n\nexport function loadModule({\n filename,\n moduleText,\n}: {\n filename: string;\n moduleText: string;\n}) {\n // TODO: Figure out how to remove all ts-ignores\n // TODO: Cleanup by setting the original values of _evaluation and _set_global_evaluation back\n // @ts-ignore\n globalThis._evaluation = undefined; // @ts-ignore\n globalThis._set_global_evaluation = true; // @ts-ignore\n\n // it needs \"require\" to be passed in\n new Function(\"require\", moduleText)(require);\n\n // Return the modified _evals global variable\n // @ts-ignore\n return globalThis._evaluation;\n}\n\nasync function cli() {\n const [, , ...args] = process.argv;\n\n // Use argparse, which is the port of the python library\n const parser = new ArgumentParser({\n prog: \"lmnr\",\n description: \"CLI for Laminar. Use `lmnr <subcommand> --help` for more information.\",\n });\n\n parser.add_argument(\"-v\", \"--version\", { action: \"version\", version: pjson.version });\n\n const subparsers = parser.add_subparsers({\n title: \"subcommands\",\n dest: \"subcommand\",\n });\n\n const parserEval = subparsers.add_parser(\"eval\", {\n description: \"Run an evaluation\",\n help: \"Run an evaluation\",\n });\n\n parserEval.add_argument(\"file\", {\n help: \"A file containing the evaluation to run. If no file is provided, \" +\n \"the evaluation will run all `*.eval.ts|js` files in the `evals` directory.\",\n nargs: \"?\",\n });\n\n parserEval.add_argument(\"--fail-on-error\", {\n help: \"Fail on error. If specified, will fail if encounters a file that cannot be run\",\n action: \"store_true\",\n });\n\n parserEval.set_defaults({\n func: async (args: any) => {\n const files = args.file\n ? [args.file]\n : glob.sync('evals/**/*.eval.{ts,js}')\n\n files.sort();\n\n if (files.length === 0) {\n console.error(\"No evaluation files found. Please provide a file or \" +\n \"ensure there are files in the `evals` directory.\");\n process.exit(1);\n }\n\n if (!args.file) {\n console.log(`Located ${files.length} evaluation files in evals/`);\n }\n\n for (const file of files) {\n console.log(`Loading ${file}...`);\n // TODO: Add various optimizations, e.g. minify, pure, tree shaking, etc.\n const buildOptions = {\n entryPoints: [file],\n outfile: `tmp_out_${file}.js`,\n write: false, // will be loaded in memory as a temp file\n platform: \"node\" as esbuild.Platform,\n bundle: true,\n external: [\"node_modules/*\"],\n };\n\n const result = await esbuild.build(buildOptions);\n\n if (!result.outputFiles) {\n console.error(\"Error when building: No output files found\");\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n const outputFileText = result.outputFiles[0].text;\n\n const evaluation = loadModule({\n filename: args.file,\n moduleText: outputFileText,\n });\n\n // @ts-ignore\n if (!evaluation?.run) {\n console.error(`Evaluation ${file} does not properly call evaluate()`);\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n // @ts-ignore\n await evaluation.run();\n\n // FIXME: Now every evaluation file creates a new tracer provider.\n // Attempt to re-initialize it in the same process breaks it.\n // For now, we disable all APIs after running each file, but ideally\n // we should keep a global tracer provider that is initialized once\n // here in the CLI.\n context.disable();\n trace.disable();\n propagation.disable();\n }\n }\n });\n\n parser.set_defaults({\n func: async (args: any) => {\n parser.print_help();\n process.exit(0);\n }\n });\n\n const parsed = parser.parse_args(args);\n await parsed.func(parsed);\n}\n\ncli();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,iBAAAA,UAAAC,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,OAAS;AAAA,M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["exports","module","args"]}
1
+ {"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.40\",\n \"description\": \"TypeScript SDK for Laminar AI\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup src/index.ts src/cli.ts --format esm,cjs --dts --external puppeteer --external puppeteer-core --external playwright\",\n \"test\": \"tsx --test test/*.test.ts\"\n },\n \"files\": [\n \"dist\",\n \"assets\"\n ],\n \"bin\": {\n \"lmnr\": \"./dist/cli.js\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/lmnr-ai/lmnr-ts.git\"\n },\n \"keywords\": [\n \"laminar\",\n \"lmnr\",\n \"sdk\",\n \"lmnr.ai\"\n ],\n \"author\": \"founders@lmnr.ai\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/lmnr-ai/lmnr-ts/issues\"\n },\n \"homepage\": \"https://github.com/lmnr-ai/lmnr-ts#README\",\n \"devDependencies\": {\n \"@anthropic-ai/sdk\": \"^0.33.1\",\n \"@aws-sdk/client-bedrock-runtime\": \"^3.716.0\",\n \"@azure/openai\": \"^2.0.0\",\n \"@browserbasehq/stagehand\": \"^1.10.1\",\n \"@google-cloud/aiplatform\": \"^3.34.0\",\n \"@google-cloud/vertexai\": \"^1.9.2\",\n \"@langchain/core\": \"^0.3.26\",\n \"@pinecone-database/pinecone\": \"^4.0.0\",\n \"@qdrant/js-client-rest\": \"^1.12.0\",\n \"@types/argparse\": \"^2.0.17\",\n \"@types/cli-progress\": \"^3.11.6\",\n \"@types/node\": \"^22.10.2\",\n \"@types/semver\": \"^7.5.8\",\n \"@types/uuid\": \"^10.0.0\",\n \"bufferutil\": \"^4.0.8\",\n \"chromadb\": \"^1.9.4\",\n \"cohere-ai\": \"^7.15.0\",\n \"langchain\": \"^0.3.8\",\n \"llamaindex\": \"^0.8.30\",\n \"openai\": \"^4.80.1\",\n \"playwright\": \"^1.50.0\",\n \"tsup\": \"^8.3.5\",\n \"tsx\": \"^4.19.2\",\n \"typescript\": \"^5.7.2\"\n },\n \"dependencies\": {\n \"@grpc/grpc-js\": \"^1.12.5\",\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/core\": \"^1.30.0\",\n \"@opentelemetry/exporter-trace-otlp-grpc\": \"^0.57.0\",\n \"@opentelemetry/exporter-trace-otlp-proto\": \"^0.57.0\",\n \"@opentelemetry/instrumentation\": \"^0.57.0\",\n \"@opentelemetry/otlp-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/otlp-grpc-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/sdk-node\": \"^0.57.0\",\n \"@opentelemetry/sdk-trace-base\": \"^1.30.0\",\n \"@opentelemetry/sdk-trace-node\": \"^1.30.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.28.0\",\n \"@traceloop/ai-semantic-conventions\": \"^0.11.6\",\n \"@traceloop/instrumentation-anthropic\": \"^0.11.6\",\n \"@traceloop/instrumentation-azure\": \"^0.11.6\",\n \"@traceloop/instrumentation-bedrock\": \"^0.11.6\",\n \"@traceloop/instrumentation-chromadb\": \"^0.11.6\",\n \"@traceloop/instrumentation-cohere\": \"^0.11.6\",\n \"@traceloop/instrumentation-langchain\": \"^0.11.6\",\n \"@traceloop/instrumentation-llamaindex\": \"^0.11.6\",\n \"@traceloop/instrumentation-openai\": \"^0.11.6\",\n \"@traceloop/instrumentation-pinecone\": \"^0.11.6\",\n \"@traceloop/instrumentation-qdrant\": \"^0.11.6\",\n \"@traceloop/instrumentation-vertexai\": \"^0.11.6\",\n \"argparse\": \"^2.0.1\",\n \"cli-progress\": \"^3.12.0\",\n \"esbuild\": \"^0.24.2\",\n \"glob\": \"^11.0.0\",\n \"uuid\": \"^11.0.3\"\n }\n}\n","#!/usr/bin/env node\n\nimport { ArgumentParser } from \"argparse\";\nimport * as esbuild from \"esbuild\";\nimport * as glob from \"glob\";\nimport { context, trace, propagation } from \"@opentelemetry/api\";\n\nconst pjson = require('../package.json');\n\nexport function loadModule({\n filename,\n moduleText,\n}: {\n filename: string;\n moduleText: string;\n}) {\n // TODO: Figure out how to remove all ts-ignores\n // TODO: Cleanup by setting the original values of _evaluation and _set_global_evaluation back\n // @ts-ignore\n globalThis._evaluation = undefined; // @ts-ignore\n globalThis._set_global_evaluation = true; // @ts-ignore\n\n // it needs \"require\" to be passed in\n new Function(\"require\", moduleText)(require);\n\n // Return the modified _evals global variable\n // @ts-ignore\n return globalThis._evaluation;\n}\n\nasync function cli() {\n const [, , ...args] = process.argv;\n\n // Use argparse, which is the port of the python library\n const parser = new ArgumentParser({\n prog: \"lmnr\",\n description: \"CLI for Laminar. Use `lmnr <subcommand> --help` for more information.\",\n });\n\n parser.add_argument(\"-v\", \"--version\", { action: \"version\", version: pjson.version });\n\n const subparsers = parser.add_subparsers({\n title: \"subcommands\",\n dest: \"subcommand\",\n });\n\n const parserEval = subparsers.add_parser(\"eval\", {\n description: \"Run an evaluation\",\n help: \"Run an evaluation\",\n });\n\n parserEval.add_argument(\"file\", {\n help: \"A file containing the evaluation to run. If no file is provided, \" +\n \"the evaluation will run all `*.eval.ts|js` files in the `evals` directory.\",\n nargs: \"?\",\n });\n\n parserEval.add_argument(\"--fail-on-error\", {\n help: \"Fail on error. If specified, will fail if encounters a file that cannot be run\",\n action: \"store_true\",\n });\n\n parserEval.set_defaults({\n func: async (args: any) => {\n const files = args.file\n ? [args.file]\n : glob.sync('evals/**/*.eval.{ts,js}')\n\n files.sort();\n\n if (files.length === 0) {\n console.error(\"No evaluation files found. Please provide a file or \" +\n \"ensure there are files in the `evals` directory.\");\n process.exit(1);\n }\n\n if (!args.file) {\n console.log(`Located ${files.length} evaluation files in evals/`);\n }\n\n for (const file of files) {\n console.log(`Loading ${file}...`);\n // TODO: Add various optimizations, e.g. minify, pure, tree shaking, etc.\n const buildOptions = {\n entryPoints: [file],\n outfile: `tmp_out_${file}.js`,\n write: false, // will be loaded in memory as a temp file\n platform: \"node\" as esbuild.Platform,\n bundle: true,\n external: [\"node_modules/*\"],\n };\n\n const result = await esbuild.build(buildOptions);\n\n if (!result.outputFiles) {\n console.error(\"Error when building: No output files found\");\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n const outputFileText = result.outputFiles[0].text;\n\n const evaluation = loadModule({\n filename: args.file,\n moduleText: outputFileText,\n });\n\n // @ts-ignore\n if (!evaluation?.run) {\n console.error(`Evaluation ${file} does not properly call evaluate()`);\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n // @ts-ignore\n await evaluation.run();\n\n // FIXME: Now every evaluation file creates a new tracer provider.\n // Attempt to re-initialize it in the same process breaks it.\n // For now, we disable all APIs after running each file, but ideally\n // we should keep a global tracer provider that is initialized once\n // here in the CLI.\n context.disable();\n trace.disable();\n propagation.disable();\n }\n }\n });\n\n parser.set_defaults({\n func: async (args: any) => {\n parser.print_help();\n process.exit(0);\n }\n });\n\n const parsed = parser.parse_args(args);\n await parsed.func(parsed);\n}\n\ncli();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,iBAAAA,UAAAC,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,OAAS;AAAA,MACT,SAAW;AAAA,QACT,OAAS;AAAA,QACT,MAAQ;AAAA,MACV;AAAA,MACA,OAAS;AAAA,QACP;AAAA,QACA;AAAA,MACF;AAAA,MACA,KAAO;AAAA,QACL,MAAQ;AAAA,MACV;AAAA,MACA,YAAc;AAAA,QACZ,MAAQ;AAAA,QACR,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,QAAU;AAAA,MACV,SAAW;AAAA,MACX,MAAQ;AAAA,QACN,KAAO;AAAA,M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AAAA,UACP,UAAU;AAAA,UACV,QAAQ;AAAA,UACR,UAAU,CAAC,gBAAgB;AAAA,QAC7B;AAEA,cAAM,SAAS,MAAc,cAAM,YAAY;AAE/C,YAAI,CAAC,OAAO,aAAa;AACvB,kBAAQ,MAAM,4CAA4C;AAC1D,cAAIA,MAAK,eAAe;AACtB,oBAAQ,KAAK,CAAC;AAAA,UAChB;AACA;AAAA,QACF;AAEA,cAAM,iBAAiB,OAAO,YAAY,CAAC,EAAE;AAE7C,cAAM,aAAa,WAAW;AAAA,UAC5B,UAAUA,MAAK;AAAA,UACf,YAAY;AAAA,QACd,CAAC;AAGD,YAAI,CAAC,YAAY,KAAK;AACpB,kBAAQ,MAAM,cAAc,IAAI,oCAAoC;AACpE,cAAIA,MAAK,eAAe;AACtB,oBAAQ,KAAK,CAAC;AAAA,UAChB;AACA;AAAA,QACF;AAGA,cAAM,WAAW,IAAI;AAOrB,2BAAQ,QAAQ;AAChB,yBAAM,QAAQ;AACd,+BAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,aAAa;AAAA,IAClB,MAAM,OAAOA,UAAc;AACzB,aAAO,WAAW;AAClB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,CAAC;AAED,QAAM,SAAS,OAAO,WAAW,IAAI;AACrC,QAAM,OAAO,KAAK,MAAM;AAC1B;AAEA,IAAI;","names":["exports","module","args"]}
package/dist/cli.mjs CHANGED
@@ -15,7 +15,7 @@ var require_package = __commonJS({
15
15
  "package.json"(exports, module) {
16
16
  module.exports = {
17
17
  name: "@lmnr-ai/lmnr",
18
- version: "0.4.39",
18
+ version: "0.4.40",
19
19
  description: "TypeScript SDK for Laminar AI",
20
20
  main: "dist/index.js",
21
21
  types: "dist/index.d.ts",
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.39\",\n \"description\": \"TypeScript SDK for Laminar AI\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup src/index.ts src/cli.ts --format esm,cjs --dts --external puppeteer --external puppeteer-core --external playwright\",\n \"test\": \"tsx --test test/*.test.ts\"\n },\n \"files\": [\n \"dist\",\n \"assets\"\n ],\n \"bin\": {\n \"lmnr\": \"./dist/cli.js\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/lmnr-ai/lmnr-ts.git\"\n },\n \"keywords\": [\n \"laminar\",\n \"lmnr\",\n \"sdk\",\n \"lmnr.ai\"\n ],\n \"author\": \"founders@lmnr.ai\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/lmnr-ai/lmnr-ts/issues\"\n },\n \"homepage\": \"https://github.com/lmnr-ai/lmnr-ts#README\",\n \"devDependencies\": {\n \"@anthropic-ai/sdk\": \"^0.33.1\",\n \"@aws-sdk/client-bedrock-runtime\": \"^3.716.0\",\n \"@azure/openai\": \"^2.0.0\",\n \"@browserbasehq/stagehand\": \"^1.10.1\",\n \"@google-cloud/aiplatform\": \"^3.34.0\",\n \"@google-cloud/vertexai\": \"^1.9.2\",\n \"@langchain/core\": \"^0.3.26\",\n \"@pinecone-database/pinecone\": \"^4.0.0\",\n \"@qdrant/js-client-rest\": \"^1.12.0\",\n \"@types/argparse\": \"^2.0.17\",\n \"@types/cli-progress\": \"^3.11.6\",\n \"@types/node\": \"^22.10.2\",\n \"@types/semver\": \"^7.5.8\",\n \"@types/uuid\": \"^10.0.0\",\n \"bufferutil\": \"^4.0.8\",\n \"chromadb\": \"^1.9.4\",\n \"cohere-ai\": \"^7.15.0\",\n \"langchain\": \"^0.3.8\",\n \"llamaindex\": \"^0.8.30\",\n \"openai\": \"^4.80.1\",\n \"playwright\": \"^1.50.0\",\n \"tsup\": \"^8.3.5\",\n \"tsx\": \"^4.19.2\",\n \"typescript\": \"^5.7.2\"\n },\n \"dependencies\": {\n \"@grpc/grpc-js\": \"^1.12.5\",\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/core\": \"^1.30.0\",\n \"@opentelemetry/exporter-trace-otlp-grpc\": \"^0.57.0\",\n \"@opentelemetry/exporter-trace-otlp-proto\": \"^0.57.0\",\n \"@opentelemetry/instrumentation\": \"^0.57.0\",\n \"@opentelemetry/otlp-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/otlp-grpc-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/sdk-node\": \"^0.57.0\",\n \"@opentelemetry/sdk-trace-base\": \"^1.30.0\",\n \"@opentelemetry/sdk-trace-node\": \"^1.30.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.28.0\",\n \"@traceloop/ai-semantic-conventions\": \"^0.11.6\",\n \"@traceloop/instrumentation-anthropic\": \"^0.11.6\",\n \"@traceloop/instrumentation-azure\": \"^0.11.6\",\n \"@traceloop/instrumentation-bedrock\": \"^0.11.6\",\n \"@traceloop/instrumentation-chromadb\": \"^0.11.6\",\n \"@traceloop/instrumentation-cohere\": \"^0.11.6\",\n \"@traceloop/instrumentation-langchain\": \"^0.11.6\",\n \"@traceloop/instrumentation-llamaindex\": \"^0.11.6\",\n \"@traceloop/instrumentation-openai\": \"^0.11.6\",\n \"@traceloop/instrumentation-pinecone\": \"^0.11.6\",\n \"@traceloop/instrumentation-qdrant\": \"^0.11.6\",\n \"@traceloop/instrumentation-vertexai\": \"^0.11.6\",\n \"argparse\": \"^2.0.1\",\n \"cli-progress\": \"^3.12.0\",\n \"esbuild\": \"^0.24.2\",\n \"glob\": \"^11.0.0\",\n \"uuid\": \"^11.0.3\"\n }\n}\n","#!/usr/bin/env node\n\nimport { ArgumentParser } from \"argparse\";\nimport * as esbuild from \"esbuild\";\nimport * as glob from \"glob\";\nimport { context, trace, propagation } from \"@opentelemetry/api\";\n\nconst pjson = require('../package.json');\n\nexport function loadModule({\n filename,\n moduleText,\n}: {\n filename: string;\n moduleText: string;\n}) {\n // TODO: Figure out how to remove all ts-ignores\n // TODO: Cleanup by setting the original values of _evaluation and _set_global_evaluation back\n // @ts-ignore\n globalThis._evaluation = undefined; // @ts-ignore\n globalThis._set_global_evaluation = true; // @ts-ignore\n\n // it needs \"require\" to be passed in\n new Function(\"require\", moduleText)(require);\n\n // Return the modified _evals global variable\n // @ts-ignore\n return globalThis._evaluation;\n}\n\nasync function cli() {\n const [, , ...args] = process.argv;\n\n // Use argparse, which is the port of the python library\n const parser = new ArgumentParser({\n prog: \"lmnr\",\n description: \"CLI for Laminar. Use `lmnr <subcommand> --help` for more information.\",\n });\n\n parser.add_argument(\"-v\", \"--version\", { action: \"version\", version: pjson.version });\n\n const subparsers = parser.add_subparsers({\n title: \"subcommands\",\n dest: \"subcommand\",\n });\n\n const parserEval = subparsers.add_parser(\"eval\", {\n description: \"Run an evaluation\",\n help: \"Run an evaluation\",\n });\n\n parserEval.add_argument(\"file\", {\n help: \"A file containing the evaluation to run. If no file is provided, \" +\n \"the evaluation will run all `*.eval.ts|js` files in the `evals` directory.\",\n nargs: \"?\",\n });\n\n parserEval.add_argument(\"--fail-on-error\", {\n help: \"Fail on error. If specified, will fail if encounters a file that cannot be run\",\n action: \"store_true\",\n });\n\n parserEval.set_defaults({\n func: async (args: any) => {\n const files = args.file\n ? [args.file]\n : glob.sync('evals/**/*.eval.{ts,js}')\n\n files.sort();\n\n if (files.length === 0) {\n console.error(\"No evaluation files found. Please provide a file or \" +\n \"ensure there are files in the `evals` directory.\");\n process.exit(1);\n }\n\n if (!args.file) {\n console.log(`Located ${files.length} evaluation files in evals/`);\n }\n\n for (const file of files) {\n console.log(`Loading ${file}...`);\n // TODO: Add various optimizations, e.g. minify, pure, tree shaking, etc.\n const buildOptions = {\n entryPoints: [file],\n outfile: `tmp_out_${file}.js`,\n write: false, // will be loaded in memory as a temp file\n platform: \"node\" as esbuild.Platform,\n bundle: true,\n external: [\"node_modules/*\"],\n };\n\n const result = await esbuild.build(buildOptions);\n\n if (!result.outputFiles) {\n console.error(\"Error when building: No output files found\");\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n const outputFileText = result.outputFiles[0].text;\n\n const evaluation = loadModule({\n filename: args.file,\n moduleText: outputFileText,\n });\n\n // @ts-ignore\n if (!evaluation?.run) {\n console.error(`Evaluation ${file} does not properly call evaluate()`);\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n // @ts-ignore\n await evaluation.run();\n\n // FIXME: Now every evaluation file creates a new tracer provider.\n // Attempt to re-initialize it in the same process breaks it.\n // For now, we disable all APIs after running each file, but ideally\n // we should keep a global tracer provider that is initialized once\n // here in the CLI.\n context.disable();\n trace.disable();\n propagation.disable();\n }\n }\n });\n\n parser.set_defaults({\n func: async (args: any) => {\n parser.print_help();\n process.exit(0);\n }\n });\n\n const parsed = parser.parse_args(args);\n await parsed.func(parsed);\n}\n\ncli();\n"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,OAAS;AAAA,MACT,SAAW;AAAA,QACT,OAAS;AAAA,QACT,MAAQ;AAAA,MACV;AAAA,MACA,OAAS;AAAA,QACP;AAAA,QACA;AAAA,MACF;AAAA,MACA,KAAO;AAAA,QACL,MAAQ;AAAA,MACV;AAAA,MACA,YAAc;AAAA,QACZ,MAAQ;AAAA,QACR,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,QAAU;AAAA,MACV,SAAW;AAAA,MACX,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,MACZ,iBAAmB;AAAA,QACjB,qBAAqB;AAAA,QACrB,mCAAmC;AAAA,QACnC,iBAAiB;AAAA,QACjB,4BAA4B;AAAA,QAC5B,4BAA4B;AAAA,QAC5B,0BAA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,MAAM,4CAA4C;AAC1D,cAAIA,MAAK,eAAe;AACtB,oBAAQ,KAAK,CAAC;AAAA,UAChB;AACA;AAAA,QACF;AAEA,cAAM,iBAAiB,OAAO,YAAY,CAAC,EAAE;AAE7C,cAAM,aAAa,WAAW;AAAA,UAC5B,UAAUA,MAAK;AAAA,UACf,YAAY;AAAA,QACd,CAAC;AAGD,YAAI,CAAC,YAAY,KAAK;AACpB,kBAAQ,MAAM,cAAc,IAAI,oCAAoC;AACpE,cAAIA,MAAK,eAAe;AACtB,oBAAQ,KAAK,CAAC;AAAA,UAChB;AACA;AAAA,QACF;AAGA,cAAM,WAAW,IAAI;AAOrB,gBAAQ,QAAQ;AAChB,cAAM,QAAQ;AACd,oBAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,aAAa;AAAA,IAClB,MAAM,OAAOA,UAAc;AACzB,aAAO,WAAW;AAClB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,CAAC;AAED,QAAM,SAAS,OAAO,WAAW,IAAI;AACrC,QAAM,OAAO,KAAK,MAAM;AAC1B;AAEA,IAAI;","names":["args"]}
1
+ {"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.40\",\n \"description\": \"TypeScript SDK for Laminar AI\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup src/index.ts src/cli.ts --format esm,cjs --dts --external puppeteer --external puppeteer-core --external playwright\",\n \"test\": \"tsx --test test/*.test.ts\"\n },\n \"files\": [\n \"dist\",\n \"assets\"\n ],\n \"bin\": {\n \"lmnr\": \"./dist/cli.js\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/lmnr-ai/lmnr-ts.git\"\n },\n \"keywords\": [\n \"laminar\",\n \"lmnr\",\n \"sdk\",\n \"lmnr.ai\"\n ],\n \"author\": \"founders@lmnr.ai\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/lmnr-ai/lmnr-ts/issues\"\n },\n \"homepage\": \"https://github.com/lmnr-ai/lmnr-ts#README\",\n \"devDependencies\": {\n \"@anthropic-ai/sdk\": \"^0.33.1\",\n \"@aws-sdk/client-bedrock-runtime\": \"^3.716.0\",\n \"@azure/openai\": \"^2.0.0\",\n \"@browserbasehq/stagehand\": \"^1.10.1\",\n \"@google-cloud/aiplatform\": \"^3.34.0\",\n \"@google-cloud/vertexai\": \"^1.9.2\",\n \"@langchain/core\": \"^0.3.26\",\n \"@pinecone-database/pinecone\": \"^4.0.0\",\n \"@qdrant/js-client-rest\": \"^1.12.0\",\n \"@types/argparse\": \"^2.0.17\",\n \"@types/cli-progress\": \"^3.11.6\",\n \"@types/node\": \"^22.10.2\",\n \"@types/semver\": \"^7.5.8\",\n \"@types/uuid\": \"^10.0.0\",\n \"bufferutil\": \"^4.0.8\",\n \"chromadb\": \"^1.9.4\",\n \"cohere-ai\": \"^7.15.0\",\n \"langchain\": \"^0.3.8\",\n \"llamaindex\": \"^0.8.30\",\n \"openai\": \"^4.80.1\",\n \"playwright\": \"^1.50.0\",\n \"tsup\": \"^8.3.5\",\n \"tsx\": \"^4.19.2\",\n \"typescript\": \"^5.7.2\"\n },\n \"dependencies\": {\n \"@grpc/grpc-js\": \"^1.12.5\",\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/core\": \"^1.30.0\",\n \"@opentelemetry/exporter-trace-otlp-grpc\": \"^0.57.0\",\n \"@opentelemetry/exporter-trace-otlp-proto\": \"^0.57.0\",\n \"@opentelemetry/instrumentation\": \"^0.57.0\",\n \"@opentelemetry/otlp-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/otlp-grpc-exporter-base\": \"^0.57.0\",\n \"@opentelemetry/sdk-node\": \"^0.57.0\",\n \"@opentelemetry/sdk-trace-base\": \"^1.30.0\",\n \"@opentelemetry/sdk-trace-node\": \"^1.30.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.28.0\",\n \"@traceloop/ai-semantic-conventions\": \"^0.11.6\",\n \"@traceloop/instrumentation-anthropic\": \"^0.11.6\",\n \"@traceloop/instrumentation-azure\": \"^0.11.6\",\n \"@traceloop/instrumentation-bedrock\": \"^0.11.6\",\n \"@traceloop/instrumentation-chromadb\": \"^0.11.6\",\n \"@traceloop/instrumentation-cohere\": \"^0.11.6\",\n \"@traceloop/instrumentation-langchain\": \"^0.11.6\",\n \"@traceloop/instrumentation-llamaindex\": \"^0.11.6\",\n \"@traceloop/instrumentation-openai\": \"^0.11.6\",\n \"@traceloop/instrumentation-pinecone\": \"^0.11.6\",\n \"@traceloop/instrumentation-qdrant\": \"^0.11.6\",\n \"@traceloop/instrumentation-vertexai\": \"^0.11.6\",\n \"argparse\": \"^2.0.1\",\n \"cli-progress\": \"^3.12.0\",\n \"esbuild\": \"^0.24.2\",\n \"glob\": \"^11.0.0\",\n \"uuid\": \"^11.0.3\"\n }\n}\n","#!/usr/bin/env node\n\nimport { ArgumentParser } from \"argparse\";\nimport * as esbuild from \"esbuild\";\nimport * as glob from \"glob\";\nimport { context, trace, propagation } from \"@opentelemetry/api\";\n\nconst pjson = require('../package.json');\n\nexport function loadModule({\n filename,\n moduleText,\n}: {\n filename: string;\n moduleText: string;\n}) {\n // TODO: Figure out how to remove all ts-ignores\n // TODO: Cleanup by setting the original values of _evaluation and _set_global_evaluation back\n // @ts-ignore\n globalThis._evaluation = undefined; // @ts-ignore\n globalThis._set_global_evaluation = true; // @ts-ignore\n\n // it needs \"require\" to be passed in\n new Function(\"require\", moduleText)(require);\n\n // Return the modified _evals global variable\n // @ts-ignore\n return globalThis._evaluation;\n}\n\nasync function cli() {\n const [, , ...args] = process.argv;\n\n // Use argparse, which is the port of the python library\n const parser = new ArgumentParser({\n prog: \"lmnr\",\n description: \"CLI for Laminar. Use `lmnr <subcommand> --help` for more information.\",\n });\n\n parser.add_argument(\"-v\", \"--version\", { action: \"version\", version: pjson.version });\n\n const subparsers = parser.add_subparsers({\n title: \"subcommands\",\n dest: \"subcommand\",\n });\n\n const parserEval = subparsers.add_parser(\"eval\", {\n description: \"Run an evaluation\",\n help: \"Run an evaluation\",\n });\n\n parserEval.add_argument(\"file\", {\n help: \"A file containing the evaluation to run. If no file is provided, \" +\n \"the evaluation will run all `*.eval.ts|js` files in the `evals` directory.\",\n nargs: \"?\",\n });\n\n parserEval.add_argument(\"--fail-on-error\", {\n help: \"Fail on error. If specified, will fail if encounters a file that cannot be run\",\n action: \"store_true\",\n });\n\n parserEval.set_defaults({\n func: async (args: any) => {\n const files = args.file\n ? [args.file]\n : glob.sync('evals/**/*.eval.{ts,js}')\n\n files.sort();\n\n if (files.length === 0) {\n console.error(\"No evaluation files found. Please provide a file or \" +\n \"ensure there are files in the `evals` directory.\");\n process.exit(1);\n }\n\n if (!args.file) {\n console.log(`Located ${files.length} evaluation files in evals/`);\n }\n\n for (const file of files) {\n console.log(`Loading ${file}...`);\n // TODO: Add various optimizations, e.g. minify, pure, tree shaking, etc.\n const buildOptions = {\n entryPoints: [file],\n outfile: `tmp_out_${file}.js`,\n write: false, // will be loaded in memory as a temp file\n platform: \"node\" as esbuild.Platform,\n bundle: true,\n external: [\"node_modules/*\"],\n };\n\n const result = await esbuild.build(buildOptions);\n\n if (!result.outputFiles) {\n console.error(\"Error when building: No output files found\");\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n const outputFileText = result.outputFiles[0].text;\n\n const evaluation = loadModule({\n filename: args.file,\n moduleText: outputFileText,\n });\n\n // @ts-ignore\n if (!evaluation?.run) {\n console.error(`Evaluation ${file} does not properly call evaluate()`);\n if (args.fail_on_error) {\n process.exit(1);\n }\n continue;\n }\n\n // @ts-ignore\n await evaluation.run();\n\n // FIXME: Now every evaluation file creates a new tracer provider.\n // Attempt to re-initialize it in the same process breaks it.\n // For now, we disable all APIs after running each file, but ideally\n // we should keep a global tracer provider that is initialized once\n // here in the CLI.\n context.disable();\n trace.disable();\n propagation.disable();\n }\n }\n });\n\n parser.set_defaults({\n func: async (args: any) => {\n parser.print_help();\n process.exit(0);\n }\n });\n\n const parsed = parser.parse_args(args);\n await parsed.func(parsed);\n}\n\ncli();\n"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,OAAS;AAAA,MACT,SAAW;AAAA,QACT,OAAS;AAAA,QACT,MAAQ;AAAA,MACV;AAAA,MACA,OAAS;AAAA,QACP;AAAA,QACA;AAAA,MACF;AAAA,MACA,KAAO;AAAA,QACL,MAAQ;AAAA,MACV;AAAA,MACA,YAAc;AAAA,QACZ,MAAQ;AAAA,QACR,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,QAAU;AAAA,MACV,SAAW;AAAA,MACX,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,MACZ,iBAAmB;AAAA,QACjB,qBAAqB;AAAA,QACrB,mCAAmC;AAAA,QACnC,iBAAiB;AAAA,QACjB,4BAA4B;AAAA,QAC5B,4BAA4B;AAAA,QAC5B,0BAA0B;AAAA,QAC1B,mBAAmB;AAAA,QACnB,+BAA+B;AAAA,QAC/B,0BAA0B;AAAA,QAC1B,mBAAmB;AAAA,QACnB,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,iBAAiB;AAAA,QACjB,eAAe;AAAA,QACf,YAAc;AAAA,QACd,UAAY;AAAA,QACZ,aAAa;AAAA,QACb,WAAa;AAAA,QACb,YAAc;AAAA,QACd,QAAU;AAAA,QACV,YAAc;AAAA,QACd,MAAQ;AAAA,QACR,KAAO;AAAA,QACP,YAAc;AAAA,MAChB;AAAA,MACA,cAAgB;AAAA,QACd,iBAAiB;AAAA,QACjB,sBAAsB;AAAA,QACtB,uBAAuB;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ChB,cAAM,QAAQ;AACd,oBAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,aAAa;AAAA,IAClB,MAAM,OAAOA,UAAc;AACzB,aAAO,WAAW;AAClB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,CAAC;AAED,QAAM,SAAS,OAAO,WAAW,IAAI;AACrC,QAAM,OAAO,KAAK,MAAM;AAC1B;AAEA,IAAI;","names":["args"]}
package/dist/index.d.mts CHANGED
@@ -91,25 +91,29 @@ interface InitializeOptions {
91
91
  * Defaults to OpenTelemetry SDK defaults.
92
92
  */
93
93
  contextManager?: ContextManager;
94
+ /**
95
+ * The modules to instrument. Optional. Suggested to use, if you don't see
96
+ * the autoinstrumentation working.
97
+ */
94
98
  instrumentModules?: {
95
- openAI?: typeof openai.OpenAI;
96
- anthropic?: typeof anthropic;
97
- azureOpenAI?: typeof azure;
98
- cohere?: typeof cohere;
99
- bedrock?: typeof bedrock;
100
- google_vertexai?: typeof vertexAI;
101
- google_aiplatform?: typeof aiplatform;
102
- pinecone?: typeof pinecone;
99
+ openAI?: typeof openai.OpenAI | any;
100
+ anthropic?: typeof anthropic | any;
101
+ azureOpenAI?: typeof azure | any;
102
+ cohere?: typeof cohere | any;
103
+ bedrock?: typeof bedrock | any;
104
+ google_vertexai?: typeof vertexAI | any;
105
+ google_aiplatform?: typeof aiplatform | any;
106
+ pinecone?: typeof pinecone | any;
103
107
  langchain?: {
104
- chainsModule?: typeof ChainsModule;
105
- agentsModule?: typeof AgentsModule;
106
- toolsModule?: typeof ToolsModule;
107
- runnablesModule?: typeof RunnableModule;
108
- vectorStoreModule?: typeof VectorStoreModule;
108
+ chainsModule?: typeof ChainsModule | any;
109
+ agentsModule?: typeof AgentsModule | any;
110
+ toolsModule?: typeof ToolsModule | any;
111
+ runnablesModule?: typeof RunnableModule | any;
112
+ vectorStoreModule?: typeof VectorStoreModule | any;
109
113
  };
110
- llamaIndex?: typeof llamaindex;
111
- chromadb?: typeof chromadb;
112
- qdrant?: typeof qdrant;
114
+ llamaIndex?: typeof llamaindex | any;
115
+ chromadb?: typeof chromadb | any;
116
+ qdrant?: typeof qdrant | any;
113
117
  };
114
118
  /**
115
119
  * Whether to silence the initialization message. Optional.
@@ -769,6 +773,9 @@ interface ObserveOptions {
769
773
  traceType?: TraceType;
770
774
  spanType?: 'DEFAULT' | 'LLM' | 'TOOL';
771
775
  traceId?: string;
776
+ input?: unknown;
777
+ ignoreInput?: boolean;
778
+ ignoreOutput?: boolean;
772
779
  }
773
780
  /**
774
781
  * The main decorator entrypoint for Laminar. This is used to wrap
@@ -782,6 +789,10 @@ interface ObserveOptions {
782
789
  * @param spanType - Type of the span. 'DEFAULT' is used if not specified. If the type is 'LLM',
783
790
  * you must manually specify some attributes. See {@link Laminar.setSpanAttributes} for more
784
791
  * information.
792
+ * @param input - Force override the input for the span. If not specified, the input will be the
793
+ * arguments passed to the function.
794
+ * @param ignoreInput - Whether to ignore the input altogether.
795
+ * @param ignoreOutput - Whether to ignore the output altogether.
785
796
  * @returns Returns the result of the wrapped function.
786
797
  * @throws Exception - Re-throws the exception if the wrapped function throws an exception.
787
798
  *
@@ -793,7 +804,7 @@ interface ObserveOptions {
793
804
  * // Your code here
794
805
  * });
795
806
  */
796
- declare function observe<A extends unknown[], F extends (...args: A) => ReturnType<F>>({ name, sessionId, traceType, spanType, traceId, }: ObserveOptions, fn: F, ...args: A): Promise<ReturnType<F>>;
807
+ declare function observe<A extends unknown[], F extends (...args: A) => ReturnType<F>>({ name, sessionId, traceType, spanType, traceId, input, ignoreInput, ignoreOutput, }: ObserveOptions, fn: F, ...args: A): Promise<ReturnType<F>>;
797
808
  /**
798
809
  * Sets the labels for any spans inside the function. This is useful for adding
799
810
  * labels to the spans created in the auto-instrumentations. Returns the result
package/dist/index.d.ts CHANGED
@@ -91,25 +91,29 @@ interface InitializeOptions {
91
91
  * Defaults to OpenTelemetry SDK defaults.
92
92
  */
93
93
  contextManager?: ContextManager;
94
+ /**
95
+ * The modules to instrument. Optional. Suggested to use, if you don't see
96
+ * the autoinstrumentation working.
97
+ */
94
98
  instrumentModules?: {
95
- openAI?: typeof openai.OpenAI;
96
- anthropic?: typeof anthropic;
97
- azureOpenAI?: typeof azure;
98
- cohere?: typeof cohere;
99
- bedrock?: typeof bedrock;
100
- google_vertexai?: typeof vertexAI;
101
- google_aiplatform?: typeof aiplatform;
102
- pinecone?: typeof pinecone;
99
+ openAI?: typeof openai.OpenAI | any;
100
+ anthropic?: typeof anthropic | any;
101
+ azureOpenAI?: typeof azure | any;
102
+ cohere?: typeof cohere | any;
103
+ bedrock?: typeof bedrock | any;
104
+ google_vertexai?: typeof vertexAI | any;
105
+ google_aiplatform?: typeof aiplatform | any;
106
+ pinecone?: typeof pinecone | any;
103
107
  langchain?: {
104
- chainsModule?: typeof ChainsModule;
105
- agentsModule?: typeof AgentsModule;
106
- toolsModule?: typeof ToolsModule;
107
- runnablesModule?: typeof RunnableModule;
108
- vectorStoreModule?: typeof VectorStoreModule;
108
+ chainsModule?: typeof ChainsModule | any;
109
+ agentsModule?: typeof AgentsModule | any;
110
+ toolsModule?: typeof ToolsModule | any;
111
+ runnablesModule?: typeof RunnableModule | any;
112
+ vectorStoreModule?: typeof VectorStoreModule | any;
109
113
  };
110
- llamaIndex?: typeof llamaindex;
111
- chromadb?: typeof chromadb;
112
- qdrant?: typeof qdrant;
114
+ llamaIndex?: typeof llamaindex | any;
115
+ chromadb?: typeof chromadb | any;
116
+ qdrant?: typeof qdrant | any;
113
117
  };
114
118
  /**
115
119
  * Whether to silence the initialization message. Optional.
@@ -769,6 +773,9 @@ interface ObserveOptions {
769
773
  traceType?: TraceType;
770
774
  spanType?: 'DEFAULT' | 'LLM' | 'TOOL';
771
775
  traceId?: string;
776
+ input?: unknown;
777
+ ignoreInput?: boolean;
778
+ ignoreOutput?: boolean;
772
779
  }
773
780
  /**
774
781
  * The main decorator entrypoint for Laminar. This is used to wrap
@@ -782,6 +789,10 @@ interface ObserveOptions {
782
789
  * @param spanType - Type of the span. 'DEFAULT' is used if not specified. If the type is 'LLM',
783
790
  * you must manually specify some attributes. See {@link Laminar.setSpanAttributes} for more
784
791
  * information.
792
+ * @param input - Force override the input for the span. If not specified, the input will be the
793
+ * arguments passed to the function.
794
+ * @param ignoreInput - Whether to ignore the input altogether.
795
+ * @param ignoreOutput - Whether to ignore the output altogether.
785
796
  * @returns Returns the result of the wrapped function.
786
797
  * @throws Exception - Re-throws the exception if the wrapped function throws an exception.
787
798
  *
@@ -793,7 +804,7 @@ interface ObserveOptions {
793
804
  * // Your code here
794
805
  * });
795
806
  */
796
- declare function observe<A extends unknown[], F extends (...args: A) => ReturnType<F>>({ name, sessionId, traceType, spanType, traceId, }: ObserveOptions, fn: F, ...args: A): Promise<ReturnType<F>>;
807
+ declare function observe<A extends unknown[], F extends (...args: A) => ReturnType<F>>({ name, sessionId, traceType, spanType, traceId, input, ignoreInput, ignoreOutput, }: ObserveOptions, fn: F, ...args: A): Promise<ReturnType<F>>;
797
808
  /**
798
809
  * Sets the labels for any spans inside the function. This is useful for adding
799
810
  * labels to the spans created in the auto-instrumentations. Returns the result
package/dist/index.js CHANGED
@@ -115,6 +115,7 @@ var SPAN_INPUT = "lmnr.span.input";
115
115
  var SPAN_OUTPUT = "lmnr.span.output";
116
116
  var SPAN_TYPE = "lmnr.span.type";
117
117
  var SPAN_PATH = "lmnr.span.path";
118
+ var SPAN_IDS_PATH = "lmnr.span.ids_path";
118
119
  var SPAN_INSTRUMENTATION_SOURCE = "lmnr.span.instrumentation_source";
119
120
  var SPAN_SDK_VERSION = "lmnr.span.sdk_version";
120
121
  var SPAN_LANGUAGE_VERSION = "lmnr.span.language_version";
@@ -160,16 +161,100 @@ var initBrowserTracing = () => {
160
161
  };
161
162
 
162
163
  // src/version.ts
163
- var SDK_VERSION = "0.4.39";
164
+ var SDK_VERSION = "0.4.40";
164
165
  var getLangVersion = () => {
165
166
  if (process?.versions?.node) {
166
167
  return `node@${process.versions.node}`;
167
168
  }
168
169
  };
169
170
 
171
+ // src/utils.ts
172
+ var import_uuid = require("uuid");
173
+ var isStringUUID = (id) => {
174
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(id);
175
+ };
176
+ var newUUID = () => {
177
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
178
+ return crypto.randomUUID();
179
+ } else {
180
+ return (0, import_uuid.v4)();
181
+ }
182
+ };
183
+ var otelSpanIdToUUID = (spanId) => {
184
+ let id = spanId.toLowerCase();
185
+ if (id.startsWith("0x")) {
186
+ id = id.slice(2);
187
+ }
188
+ if (id.length !== 16) {
189
+ console.warn(`Span ID ${spanId} is not 16 hex chars long. This is not a valid OpenTelemetry span ID.`);
190
+ }
191
+ if (!/^[0-9a-f]+$/.test(id)) {
192
+ console.error(`Span ID ${spanId} is not a valid hex string. Generating a random UUID instead.`);
193
+ return newUUID();
194
+ }
195
+ return id.padStart(32, "0").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
196
+ };
197
+ var otelTraceIdToUUID = (traceId) => {
198
+ let id = traceId.toLowerCase();
199
+ if (id.startsWith("0x")) {
200
+ id = id.slice(2);
201
+ }
202
+ if (id.length !== 32) {
203
+ console.warn(`Trace ID ${traceId} is not 32 hex chars long. This is not a valid OpenTelemetry trace ID.`);
204
+ }
205
+ if (!/^[0-9a-f]+$/.test(id)) {
206
+ console.error(`Trace ID ${traceId} is not a valid hex string. Generating a random UUID instead.`);
207
+ return newUUID();
208
+ }
209
+ return id.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
210
+ };
211
+ var uuidToOtelTraceId = (uuid) => {
212
+ return uuid.replace(/-/g, "");
213
+ };
214
+ var Semaphore = class {
215
+ constructor(value = 1) {
216
+ /**
217
+ * List of promises that will be resolved when a permit becomes available.
218
+ */
219
+ this._waiters = [];
220
+ if (value < 0) {
221
+ throw new Error("Semaphore value must be >= 0");
222
+ }
223
+ this._value = value;
224
+ this._waiters = [];
225
+ }
226
+ async acquire() {
227
+ if (this._value > 0) {
228
+ this._value--;
229
+ return;
230
+ }
231
+ return new Promise((resolve) => {
232
+ this._waiters.push(resolve);
233
+ });
234
+ }
235
+ release() {
236
+ if (this._waiters.length > 0) {
237
+ const resolve = this._waiters.shift();
238
+ resolve?.();
239
+ } else {
240
+ this._value++;
241
+ }
242
+ }
243
+ // Python-like context manager functionality
244
+ async using(fn) {
245
+ try {
246
+ await this.acquire();
247
+ return await fn();
248
+ } finally {
249
+ this.release();
250
+ }
251
+ }
252
+ };
253
+
170
254
  // src/sdk/tracing/index.ts
171
255
  var _spanProcessor;
172
256
  var _spanIdToPath = /* @__PURE__ */ new Map();
257
+ var _spanIdLists = /* @__PURE__ */ new Map();
173
258
  var openAIInstrumentation;
174
259
  var anthropicInstrumentation;
175
260
  var azureOpenAIInstrumentation;
@@ -351,10 +436,15 @@ var startTracing = (options) => {
351
436
  _spanProcessor.onStart = (span, parentContext) => {
352
437
  const contextSpanPath = getSpanPath(parentContext ?? import_api2.context.active());
353
438
  const parentSpanPath = contextSpanPath ?? (span.parentSpanId !== void 0 ? _spanIdToPath.get(span.parentSpanId) : void 0);
439
+ const spanId = span.spanContext().spanId;
440
+ const parentSpanIdsPath = span.parentSpanId ? _spanIdLists.get(span.parentSpanId) ?? [] : [];
354
441
  const spanPath = parentSpanPath ? [...parentSpanPath, span.name] : [span.name];
442
+ const spanIdUuid = otelSpanIdToUUID(spanId);
443
+ const spanIdsPath = parentSpanIdsPath ? [...parentSpanIdsPath, spanIdUuid] : [spanIdUuid];
444
+ span.setAttribute(SPAN_IDS_PATH, spanIdsPath);
445
+ _spanIdLists.set(spanId, spanIdsPath);
355
446
  span.setAttribute(SPAN_PATH, spanPath);
356
447
  import_api2.context.active().setValue(SPAN_PATH_KEY, spanPath);
357
- const spanId = span.spanContext().spanId;
358
448
  _spanIdToPath.set(spanId, spanPath);
359
449
  span.setAttribute(SPAN_INSTRUMENTATION_SOURCE, "javascript");
360
450
  span.setAttribute(SPAN_SDK_VERSION, SDK_VERSION);
@@ -479,95 +569,13 @@ var logLevelToOtelLogLevel = (logLevel) => {
479
569
  // src/sdk/tracing/decorators.ts
480
570
  var import_api4 = require("@opentelemetry/api");
481
571
  var import_core2 = require("@opentelemetry/core");
482
-
483
- // src/utils.ts
484
- var import_uuid = require("uuid");
485
- var isStringUUID = (id) => {
486
- return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(id);
487
- };
488
- var newUUID = () => {
489
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
490
- return crypto.randomUUID();
491
- } else {
492
- return (0, import_uuid.v4)();
493
- }
494
- };
495
- var otelSpanIdToUUID = (spanId) => {
496
- let id = spanId.toLowerCase();
497
- if (id.startsWith("0x")) {
498
- id = id.slice(2);
499
- }
500
- if (id.length !== 16) {
501
- console.warn(`Span ID ${spanId} is not 16 hex chars long. This is not a valid OpenTelemetry span ID.`);
502
- }
503
- if (!/^[0-9a-f]+$/.test(id)) {
504
- console.error(`Span ID ${spanId} is not a valid hex string. Generating a random UUID instead.`);
505
- return newUUID();
506
- }
507
- return id.padStart(32, "0").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
508
- };
509
- var otelTraceIdToUUID = (traceId) => {
510
- let id = traceId.toLowerCase();
511
- if (id.startsWith("0x")) {
512
- id = id.slice(2);
513
- }
514
- if (id.length !== 32) {
515
- console.warn(`Trace ID ${traceId} is not 32 hex chars long. This is not a valid OpenTelemetry trace ID.`);
516
- }
517
- if (!/^[0-9a-f]+$/.test(id)) {
518
- console.error(`Trace ID ${traceId} is not a valid hex string. Generating a random UUID instead.`);
519
- return newUUID();
520
- }
521
- return id.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
522
- };
523
- var uuidToOtelTraceId = (uuid) => {
524
- return uuid.replace(/-/g, "");
525
- };
526
- var Semaphore = class {
527
- constructor(value = 1) {
528
- /**
529
- * List of promises that will be resolved when a permit becomes available.
530
- */
531
- this._waiters = [];
532
- if (value < 0) {
533
- throw new Error("Semaphore value must be >= 0");
534
- }
535
- this._value = value;
536
- this._waiters = [];
537
- }
538
- async acquire() {
539
- if (this._value > 0) {
540
- this._value--;
541
- return;
542
- }
543
- return new Promise((resolve) => {
544
- this._waiters.push(resolve);
545
- });
546
- }
547
- release() {
548
- if (this._waiters.length > 0) {
549
- const resolve = this._waiters.shift();
550
- resolve?.();
551
- } else {
552
- this._value++;
553
- }
554
- }
555
- // Python-like context manager functionality
556
- async using(fn) {
557
- try {
558
- await this.acquire();
559
- return await fn();
560
- } finally {
561
- this.release();
562
- }
563
- }
564
- };
565
-
566
- // src/sdk/tracing/decorators.ts
567
572
  var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
568
- function withEntity({
573
+ function observeBase({
569
574
  name,
570
575
  associationProperties,
576
+ input,
577
+ ignoreInput,
578
+ ignoreOutput,
571
579
  inputParameters,
572
580
  suppressTracing: shouldSuppressTracing,
573
581
  traceId
@@ -606,18 +614,23 @@ function withEntity({
606
614
  if (traceId && isStringUUID(traceId)) {
607
615
  span.setAttribute(OVERRIDE_PARENT_SPAN, true);
608
616
  }
609
- if (shouldSendTraces()) {
617
+ if (shouldSendTraces() && !ignoreInput) {
610
618
  try {
611
- const input = inputParameters ?? args;
612
- if (input.length === 1 && typeof input[0] === "object" && !(input[0] instanceof Map)) {
619
+ const spanInput = inputParameters ?? args;
620
+ if (input !== void 0) {
613
621
  span.setAttribute(
614
622
  SPAN_INPUT,
615
- serialize(input[0])
623
+ serialize(input)
624
+ );
625
+ } else if (spanInput.length === 1 && typeof spanInput[0] === "object" && !(spanInput[0] instanceof Map)) {
626
+ span.setAttribute(
627
+ SPAN_INPUT,
628
+ serialize(spanInput[0])
616
629
  );
617
630
  } else {
618
631
  span.setAttribute(
619
632
  SPAN_INPUT,
620
- serialize(input.length > 0 ? input : {})
633
+ serialize(spanInput.length > 0 ? spanInput : {})
621
634
  );
622
635
  }
623
636
  } catch (error) {
@@ -640,7 +653,7 @@ function withEntity({
640
653
  if (res instanceof Promise) {
641
654
  return res.then((resolvedRes) => {
642
655
  try {
643
- if (shouldSendTraces()) {
656
+ if (shouldSendTraces() && !ignoreOutput) {
644
657
  span.setAttribute(
645
658
  SPAN_OUTPUT,
646
659
  serialize(resolvedRes)
@@ -659,7 +672,7 @@ function withEntity({
659
672
  });
660
673
  }
661
674
  try {
662
- if (shouldSendTraces()) {
675
+ if (shouldSendTraces() && !ignoreOutput) {
663
676
  span.setAttribute(
664
677
  SPAN_OUTPUT,
665
678
  serialize(res)
@@ -675,25 +688,29 @@ function withEntity({
675
688
  )
676
689
  );
677
690
  }
678
- function cleanInput(input) {
679
- if (input instanceof Map) {
680
- return Array.from(input.entries());
681
- } else if (Array.isArray(input)) {
682
- return input.map((value) => cleanInput(value));
683
- } else if (!input) {
684
- return input;
685
- } else if (typeof input === "object") {
691
+ var normalizePayload = (payload, seen) => {
692
+ if (payload instanceof Map) {
693
+ return Array.from(payload.entries());
694
+ } else if (Array.isArray(payload)) {
695
+ return payload.map((value) => normalizePayload(value, seen));
696
+ } else if (!payload) {
697
+ return payload;
698
+ } else if (typeof payload === "object") {
699
+ if (seen.has(payload)) {
700
+ return "[Circular reference]";
701
+ }
702
+ seen.add(payload);
686
703
  const output = {};
687
- Object.entries(input).forEach(([key, value]) => {
688
- output[key] = cleanInput(value);
704
+ Object.entries(payload).forEach(([key, value]) => {
705
+ output[key] = normalizePayload(value, seen);
689
706
  });
690
707
  return output;
691
708
  }
692
- return input;
693
- }
694
- function serialize(input) {
695
- return JSON.stringify(cleanInput(input));
696
- }
709
+ return payload;
710
+ };
711
+ var serialize = (payload) => {
712
+ return JSON.stringify(normalizePayload(payload, /* @__PURE__ */ new WeakSet()));
713
+ };
697
714
 
698
715
  // src/laminar.ts
699
716
  var import_grpc_js = require("@grpc/grpc-js");
@@ -1621,7 +1638,10 @@ async function observe({
1621
1638
  sessionId,
1622
1639
  traceType,
1623
1640
  spanType,
1624
- traceId
1641
+ traceId,
1642
+ input,
1643
+ ignoreInput,
1644
+ ignoreOutput
1625
1645
  }, fn, ...args) {
1626
1646
  if (fn === void 0 || typeof fn !== "function") {
1627
1647
  throw new Error("Invalid `observe` usage. Second argument `fn` must be a function.");
@@ -1636,10 +1656,13 @@ async function observe({
1636
1656
  if (spanType) {
1637
1657
  associationProperties = { ...associationProperties, "span_type": spanType };
1638
1658
  }
1639
- return await withEntity({
1659
+ return await observeBase({
1640
1660
  name: name ?? fn.name,
1641
1661
  associationProperties,
1642
- traceId
1662
+ traceId,
1663
+ input,
1664
+ ignoreInput,
1665
+ ignoreOutput
1643
1666
  }, fn, void 0, ...args);
1644
1667
  }
1645
1668
  function withLabels(labels, fn, ...args) {