@hashgraphonline/standards-agent-kit 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -0
- package/dist/_virtual/_commonjsHelpers.js +7 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/index.js +8 -0
- package/dist/_virtual/index.js.map +1 -0
- package/dist/_virtual/index10.js +5 -0
- package/dist/_virtual/index10.js.map +1 -0
- package/dist/_virtual/index11.js +5 -0
- package/dist/_virtual/index11.js.map +1 -0
- package/dist/_virtual/index12.js +8 -0
- package/dist/_virtual/index12.js.map +1 -0
- package/dist/_virtual/index13.js +5 -0
- package/dist/_virtual/index13.js.map +1 -0
- package/dist/_virtual/index14.js +5 -0
- package/dist/_virtual/index14.js.map +1 -0
- package/dist/_virtual/index2.js +3 -0
- package/dist/_virtual/index2.js.map +1 -0
- package/dist/_virtual/index3.js +8 -0
- package/dist/_virtual/index3.js.map +1 -0
- package/dist/_virtual/index4.js +8 -0
- package/dist/_virtual/index4.js.map +1 -0
- package/dist/_virtual/index5.js +6 -0
- package/dist/_virtual/index5.js.map +1 -0
- package/dist/_virtual/index6.js +8 -0
- package/dist/_virtual/index6.js.map +1 -0
- package/dist/_virtual/index7.js +5 -0
- package/dist/_virtual/index7.js.map +1 -0
- package/dist/_virtual/index8.js +5 -0
- package/dist/_virtual/index8.js.map +1 -0
- package/dist/_virtual/index9.js +5 -0
- package/dist/_virtual/index9.js.map +1 -0
- package/dist/_virtual/lower-bound.js +5 -0
- package/dist/_virtual/lower-bound.js.map +1 -0
- package/dist/_virtual/priority-queue.js +5 -0
- package/dist/_virtual/priority-queue.js.map +1 -0
- package/dist/_virtual/re.js +5 -0
- package/dist/_virtual/re.js.map +1 -0
- package/dist/_virtual/retry.js +5 -0
- package/dist/_virtual/retry.js.map +1 -0
- package/dist/agents/index.d.ts +0 -0
- package/dist/hcs10/HCS10Client.d.ts +117 -0
- package/dist/hcs10/HCS10Client.js +251 -0
- package/dist/hcs10/HCS10Client.js.map +1 -0
- package/dist/hcs10/index.d.ts +1 -0
- package/dist/hcs10/types.d.ts +35 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.es.js +9747 -11699
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +59 -0
- package/dist/init.js +92 -0
- package/dist/init.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/base.js +98 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/manager.js +419 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/manager.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/promises.js +16 -0
- package/dist/node_modules/@langchain/core/dist/callbacks/promises.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/language_models/base.js +42 -0
- package/dist/node_modules/@langchain/core/dist/language_models/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/load/map_keys.js +16 -0
- package/dist/node_modules/@langchain/core/dist/load/map_keys.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/load/serializable.js +121 -0
- package/dist/node_modules/@langchain/core/dist/load/serializable.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/messages/ai.js +95 -0
- package/dist/node_modules/@langchain/core/dist/messages/ai.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/messages/base.js +112 -0
- package/dist/node_modules/@langchain/core/dist/messages/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/messages/utils.js +30 -0
- package/dist/node_modules/@langchain/core/dist/messages/utils.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/base.js +1277 -0
- package/dist/node_modules/@langchain/core/dist/runnables/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/config.js +83 -0
- package/dist/node_modules/@langchain/core/dist/runnables/config.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/graph.js +106 -0
- package/dist/node_modules/@langchain/core/dist/runnables/graph.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/iter.js +33 -0
- package/dist/node_modules/@langchain/core/dist/runnables/iter.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/utils.js +54 -0
- package/dist/node_modules/@langchain/core/dist/runnables/utils.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/runnables/wrappers.js +20 -0
- package/dist/node_modules/@langchain/core/dist/runnables/wrappers.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/singletons/index.js +34 -0
- package/dist/node_modules/@langchain/core/dist/singletons/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tools.js +69 -0
- package/dist/node_modules/@langchain/core/dist/tools.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/base.js +299 -0
- package/dist/node_modules/@langchain/core/dist/tracers/base.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/console.js +193 -0
- package/dist/node_modules/@langchain/core/dist/tracers/console.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/initialize.js +10 -0
- package/dist/node_modules/@langchain/core/dist/tracers/initialize.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/log_stream.js +284 -0
- package/dist/node_modules/@langchain/core/dist/tracers/log_stream.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/root_listener.js +54 -0
- package/dist/node_modules/@langchain/core/dist/tracers/root_listener.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/tracers/tracer_langchain.js +68 -0
- package/dist/node_modules/@langchain/core/dist/tracers/tracer_langchain.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/async_caller.js +86 -0
- package/dist/node_modules/@langchain/core/dist/utils/async_caller.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/env.js +33 -0
- package/dist/node_modules/@langchain/core/dist/utils/env.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/core.js +218 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/core.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/helpers.js +117 -0
- package/dist/node_modules/@langchain/core/dist/utils/fast-json-patch/helpers.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/json.js +40 -0
- package/dist/node_modules/@langchain/core/dist/utils/json.js.map +1 -0
- package/dist/node_modules/@langchain/core/dist/utils/stream.js +164 -0
- package/dist/node_modules/@langchain/core/dist/utils/stream.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/ansi-styles/index.js +111 -0
- package/dist/node_modules/@langchain/core/node_modules/ansi-styles/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/camelcase/index.js +30 -0
- package/dist/node_modules/@langchain/core/node_modules/camelcase/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/client.js +2002 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/client.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/index.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/singletons/fetch.js +5 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/singletons/fetch.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/_uuid.js +12 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/_uuid.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/async_caller.js +94 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/async_caller.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/env.js +96 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/env.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/error.js +20 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/error.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js +82 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/messages.js +15 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/messages.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/prompts.js +27 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/prompts.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/warn.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/dist/utils/warn.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/native.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/native.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/regex.js +5 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/regex.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/rng.js +10 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/rng.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/stringify.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/v4.js +14 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/v4.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/validate.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/langsmith/node_modules/uuid/dist/esm-browser/validate.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/native.js +7 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/native.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/regex.js +5 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/regex.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/rng.js +11 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/rng.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/stringify.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/v4.js +14 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/v4.js.map +1 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/validate.js +8 -0
- package/dist/node_modules/@langchain/core/node_modules/uuid/dist/esm-browser/validate.js.map +1 -0
- package/dist/node_modules/base64-js/index.js +53 -0
- package/dist/node_modules/base64-js/index.js.map +1 -0
- package/dist/node_modules/decamelize/index.js +12 -0
- package/dist/node_modules/decamelize/index.js.map +1 -0
- package/dist/node_modules/eventemitter3/index.js +112 -0
- package/dist/node_modules/eventemitter3/index.js.map +1 -0
- package/dist/node_modules/js-tiktoken/dist/chunk-Z5MDQTGX.js +117 -0
- package/dist/node_modules/js-tiktoken/dist/chunk-Z5MDQTGX.js.map +1 -0
- package/dist/node_modules/p-finally/index.js +18 -0
- package/dist/node_modules/p-finally/index.js.map +1 -0
- package/dist/node_modules/p-queue/dist/index.js +198 -0
- package/dist/node_modules/p-queue/dist/index.js.map +1 -0
- package/dist/node_modules/p-queue/dist/lower-bound.js +20 -0
- package/dist/node_modules/p-queue/dist/lower-bound.js.map +1 -0
- package/dist/node_modules/p-queue/dist/priority-queue.js +41 -0
- package/dist/node_modules/p-queue/dist/priority-queue.js.map +1 -0
- package/dist/node_modules/p-retry/index.js +63 -0
- package/dist/node_modules/p-retry/index.js.map +1 -0
- package/dist/node_modules/p-timeout/index.js +45 -0
- package/dist/node_modules/p-timeout/index.js.map +1 -0
- package/dist/node_modules/retry/index.js +9 -0
- package/dist/node_modules/retry/index.js.map +1 -0
- package/dist/node_modules/retry/lib/retry.js +59 -0
- package/dist/node_modules/retry/lib/retry.js.map +1 -0
- package/dist/node_modules/retry/lib/retry_operation.js +58 -0
- package/dist/node_modules/retry/lib/retry_operation.js.map +1 -0
- package/dist/node_modules/semver/classes/comparator.js +57 -0
- package/dist/node_modules/semver/classes/comparator.js.map +1 -0
- package/dist/node_modules/semver/classes/range.js +149 -0
- package/dist/node_modules/semver/classes/range.js.map +1 -0
- package/dist/node_modules/semver/classes/semver.js +170 -0
- package/dist/node_modules/semver/classes/semver.js.map +1 -0
- package/dist/node_modules/semver/functions/clean.js +15 -0
- package/dist/node_modules/semver/functions/clean.js.map +1 -0
- package/dist/node_modules/semver/functions/cmp.js +40 -0
- package/dist/node_modules/semver/functions/cmp.js.map +1 -0
- package/dist/node_modules/semver/functions/coerce.js +34 -0
- package/dist/node_modules/semver/functions/coerce.js.map +1 -0
- package/dist/node_modules/semver/functions/compare-build.js +15 -0
- package/dist/node_modules/semver/functions/compare-build.js.map +1 -0
- package/dist/node_modules/semver/functions/compare-loose.js +12 -0
- package/dist/node_modules/semver/functions/compare-loose.js.map +1 -0
- package/dist/node_modules/semver/functions/compare.js +12 -0
- package/dist/node_modules/semver/functions/compare.js.map +1 -0
- package/dist/node_modules/semver/functions/diff.js +25 -0
- package/dist/node_modules/semver/functions/diff.js.map +1 -0
- package/dist/node_modules/semver/functions/eq.js +12 -0
- package/dist/node_modules/semver/functions/eq.js.map +1 -0
- package/dist/node_modules/semver/functions/gt.js +12 -0
- package/dist/node_modules/semver/functions/gt.js.map +1 -0
- package/dist/node_modules/semver/functions/gte.js +12 -0
- package/dist/node_modules/semver/functions/gte.js.map +1 -0
- package/dist/node_modules/semver/functions/inc.js +22 -0
- package/dist/node_modules/semver/functions/inc.js.map +1 -0
- package/dist/node_modules/semver/functions/lt.js +12 -0
- package/dist/node_modules/semver/functions/lt.js.map +1 -0
- package/dist/node_modules/semver/functions/lte.js +12 -0
- package/dist/node_modules/semver/functions/lte.js.map +1 -0
- package/dist/node_modules/semver/functions/major.js +12 -0
- package/dist/node_modules/semver/functions/major.js.map +1 -0
- package/dist/node_modules/semver/functions/minor.js +12 -0
- package/dist/node_modules/semver/functions/minor.js.map +1 -0
- package/dist/node_modules/semver/functions/neq.js +12 -0
- package/dist/node_modules/semver/functions/neq.js.map +1 -0
- package/dist/node_modules/semver/functions/parse.js +22 -0
- package/dist/node_modules/semver/functions/parse.js.map +1 -0
- package/dist/node_modules/semver/functions/patch.js +12 -0
- package/dist/node_modules/semver/functions/patch.js.map +1 -0
- package/dist/node_modules/semver/functions/prerelease.js +15 -0
- package/dist/node_modules/semver/functions/prerelease.js.map +1 -0
- package/dist/node_modules/semver/functions/rcompare.js +12 -0
- package/dist/node_modules/semver/functions/rcompare.js.map +1 -0
- package/dist/node_modules/semver/functions/rsort.js +12 -0
- package/dist/node_modules/semver/functions/rsort.js.map +1 -0
- package/dist/node_modules/semver/functions/satisfies.js +19 -0
- package/dist/node_modules/semver/functions/satisfies.js.map +1 -0
- package/dist/node_modules/semver/functions/sort.js +12 -0
- package/dist/node_modules/semver/functions/sort.js.map +1 -0
- package/dist/node_modules/semver/functions/valid.js +15 -0
- package/dist/node_modules/semver/functions/valid.js.map +1 -0
- package/dist/node_modules/semver/index.js +98 -0
- package/dist/node_modules/semver/index.js.map +1 -0
- package/dist/node_modules/semver/internal/constants.js +29 -0
- package/dist/node_modules/semver/internal/constants.js.map +1 -0
- package/dist/node_modules/semver/internal/debug.js +9 -0
- package/dist/node_modules/semver/internal/debug.js.map +1 -0
- package/dist/node_modules/semver/internal/identifiers.js +17 -0
- package/dist/node_modules/semver/internal/identifiers.js.map +1 -0
- package/dist/node_modules/semver/internal/lrucache.js +33 -0
- package/dist/node_modules/semver/internal/lrucache.js.map +1 -0
- package/dist/node_modules/semver/internal/parse-options.js +11 -0
- package/dist/node_modules/semver/internal/parse-options.js.map +1 -0
- package/dist/node_modules/semver/internal/re.js +33 -0
- package/dist/node_modules/semver/internal/re.js.map +1 -0
- package/dist/node_modules/semver/ranges/gtr.js +12 -0
- package/dist/node_modules/semver/ranges/gtr.js.map +1 -0
- package/dist/node_modules/semver/ranges/intersects.js +12 -0
- package/dist/node_modules/semver/ranges/intersects.js.map +1 -0
- package/dist/node_modules/semver/ranges/ltr.js +12 -0
- package/dist/node_modules/semver/ranges/ltr.js.map +1 -0
- package/dist/node_modules/semver/ranges/max-satisfying.js +23 -0
- package/dist/node_modules/semver/ranges/max-satisfying.js.map +1 -0
- package/dist/node_modules/semver/ranges/min-satisfying.js +23 -0
- package/dist/node_modules/semver/ranges/min-satisfying.js.map +1 -0
- package/dist/node_modules/semver/ranges/min-version.js +43 -0
- package/dist/node_modules/semver/ranges/min-version.js.map +1 -0
- package/dist/node_modules/semver/ranges/outside.js +45 -0
- package/dist/node_modules/semver/ranges/outside.js.map +1 -0
- package/dist/node_modules/semver/ranges/simplify.js +25 -0
- package/dist/node_modules/semver/ranges/simplify.js.map +1 -0
- package/dist/node_modules/semver/ranges/subset.js +95 -0
- package/dist/node_modules/semver/ranges/subset.js.map +1 -0
- package/dist/node_modules/semver/ranges/to-comparators.js +12 -0
- package/dist/node_modules/semver/ranges/to-comparators.js.map +1 -0
- package/dist/node_modules/semver/ranges/valid.js +18 -0
- package/dist/node_modules/semver/ranges/valid.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js +32 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js +22 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js +14 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js +44 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +7 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +17 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js +26 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js +9 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js +8 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js +6 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js +59 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js +11 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +8 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js +10 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js +36 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js +16 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +27 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js +11 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +9 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js +12 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js +30 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js +28 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +50 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +22 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js +21 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js +8 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js +6 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +56 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js +17 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +245 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js +27 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +9 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js +69 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +7 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js +110 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js.map +1 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +26 -0
- package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js.map +1 -0
- package/dist/plugins/BasePlugin.d.ts +28 -0
- package/dist/plugins/BasePlugin.js +19 -0
- package/dist/plugins/BasePlugin.js.map +1 -0
- package/dist/plugins/PluginInterface.d.ts +64 -0
- package/dist/plugins/PluginLoader.d.ts +38 -0
- package/dist/plugins/PluginLoader.js +60 -0
- package/dist/plugins/PluginLoader.js.map +1 -0
- package/dist/plugins/PluginRegistry.d.ts +47 -0
- package/dist/plugins/PluginRegistry.js +71 -0
- package/dist/plugins/PluginRegistry.js.map +1 -0
- package/dist/plugins/__tests__/BasePlugin.test.d.ts +1 -0
- package/dist/plugins/__tests__/PluginLoader.test.d.ts +1 -0
- package/dist/plugins/__tests__/PluginRegistry.test.d.ts +1 -0
- package/dist/plugins/defi/index.d.ts +13 -0
- package/dist/plugins/hedera/HbarPricePlugin.d.ts +45 -0
- package/dist/plugins/hedera/HbarPricePlugin.js +70 -0
- package/dist/plugins/hedera/HbarPricePlugin.js.map +1 -0
- package/dist/plugins/hedera/__tests__/HbarPricePlugin.test.d.ts +1 -0
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/weather/index.d.ts +15 -0
- package/dist/src/agents/index.d.ts +0 -0
- package/dist/src/plugins/hedera/HbarPricePlugin.d.ts +45 -0
- package/dist/src/plugins/index.d.ts +1 -0
- package/dist/src/tools/CheckMessagesTool.d.ts +9 -2
- package/dist/src/utils/state-tools.d.ts +23 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/open-convai-state.d.ts +84 -0
- package/dist/state/open-convai-state.js +132 -0
- package/dist/state/open-convai-state.js.map +1 -0
- package/dist/state/state-types.d.ts +143 -0
- package/dist/tools/AcceptConnectionRequestTool.d.ts +33 -0
- package/dist/tools/AcceptConnectionRequestTool.js +116 -0
- package/dist/tools/AcceptConnectionRequestTool.js.map +1 -0
- package/dist/tools/CheckMessagesTool.d.ts +34 -0
- package/dist/tools/CheckMessagesTool.js +96 -0
- package/dist/tools/CheckMessagesTool.js.map +1 -0
- package/dist/tools/ConnectionMonitorTool.d.ts +96 -0
- package/dist/tools/ConnectionMonitorTool.js +289 -0
- package/dist/tools/ConnectionMonitorTool.js.map +1 -0
- package/dist/tools/ConnectionTool.d.ts +40 -0
- package/dist/tools/ConnectionTool.js +114 -0
- package/dist/tools/ConnectionTool.js.map +1 -0
- package/dist/tools/FindRegistrationsTool.d.ts +27 -0
- package/dist/tools/FindRegistrationsTool.js +64 -0
- package/dist/tools/FindRegistrationsTool.js.map +1 -0
- package/dist/tools/InitiateConnectionTool.d.ts +30 -0
- package/dist/tools/InitiateConnectionTool.js +79 -0
- package/dist/tools/InitiateConnectionTool.js.map +1 -0
- package/dist/tools/ListConnectionsTool.d.ts +33 -0
- package/dist/tools/ListConnectionsTool.js +327 -0
- package/dist/tools/ListConnectionsTool.js.map +1 -0
- package/dist/tools/ListUnapprovedConnectionRequestsTool.d.ts +53 -0
- package/dist/tools/ListUnapprovedConnectionRequestsTool.js +177 -0
- package/dist/tools/ListUnapprovedConnectionRequestsTool.js.map +1 -0
- package/dist/tools/ManageConnectionRequestsTool.d.ts +39 -0
- package/dist/tools/ManageConnectionRequestsTool.js +161 -0
- package/dist/tools/ManageConnectionRequestsTool.js.map +1 -0
- package/dist/tools/RegisterAgentTool.d.ts +188 -0
- package/dist/tools/RegisterAgentTool.js +331 -0
- package/dist/tools/RegisterAgentTool.js.map +1 -0
- package/dist/tools/RetrieveProfileTool.d.ts +34 -0
- package/dist/tools/RetrieveProfileTool.js +53 -0
- package/dist/tools/RetrieveProfileTool.js.map +1 -0
- package/dist/tools/SendMessageToConnectionTool.d.ts +31 -0
- package/dist/tools/SendMessageToConnectionTool.js +74 -0
- package/dist/tools/SendMessageToConnectionTool.js.map +1 -0
- package/dist/tools/SendMessageTool.d.ts +44 -0
- package/dist/tools/SendMessageTool.js +75 -0
- package/dist/tools/SendMessageTool.js.map +1 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/utils/Encryption.d.ts +7 -0
- package/dist/utils/Encryption.js +7 -0
- package/dist/utils/Encryption.js.map +1 -0
- package/dist/utils/HederaClient.d.ts +18 -0
- package/dist/utils/connectionUtils.d.ts +15 -0
- package/dist/utils/connectionUtils.js +64 -0
- package/dist/utils/connectionUtils.js.map +1 -0
- package/dist/utils/state-tools.d.ts +23 -0
- package/dist/utils/state-tools.js +90 -0
- package/dist/utils/state-tools.js.map +1 -0
- package/package.json +20 -10
|
@@ -0,0 +1,2002 @@
|
|
|
1
|
+
import { AsyncCaller as k } from "./utils/async_caller.js";
|
|
2
|
+
import { isLangChainMessage as N, convertLangChainMessageToExample as x } from "./utils/messages.js";
|
|
3
|
+
import { getLangSmithEnvironmentVariable as j, getRuntimeEnvironment as M, getLangChainEnvVarsMetadata as H } from "./utils/env.js";
|
|
4
|
+
import { __version__ as F } from "./index.js";
|
|
5
|
+
import { assertUuid as f } from "./utils/_uuid.js";
|
|
6
|
+
import { warnOnce as J } from "./utils/warn.js";
|
|
7
|
+
import { parsePromptIdentifier as O, isVersionGreaterOrEqual as z } from "./utils/prompts.js";
|
|
8
|
+
import { raiseForStatus as p } from "./utils/error.js";
|
|
9
|
+
import { _getFetchImplementation as u } from "./singletons/fetch.js";
|
|
10
|
+
import { stringify as T } from "./utils/fast-safe-stringify/index.js";
|
|
11
|
+
import R from "../node_modules/uuid/dist/esm-browser/v4.js";
|
|
12
|
+
function D(g) {
|
|
13
|
+
const t = M(), e = H(), a = g.extra ?? {}, i = a.metadata;
|
|
14
|
+
return g.extra = {
|
|
15
|
+
...a,
|
|
16
|
+
runtime: {
|
|
17
|
+
...t,
|
|
18
|
+
...a == null ? void 0 : a.runtime
|
|
19
|
+
},
|
|
20
|
+
metadata: {
|
|
21
|
+
...e,
|
|
22
|
+
...e.revision_id || g.revision_id ? { revision_id: g.revision_id ?? e.revision_id } : {},
|
|
23
|
+
...i
|
|
24
|
+
}
|
|
25
|
+
}, g;
|
|
26
|
+
}
|
|
27
|
+
const q = () => {
|
|
28
|
+
const g = j("TRACING_SAMPLING_RATE");
|
|
29
|
+
if (g === void 0)
|
|
30
|
+
return;
|
|
31
|
+
const t = parseFloat(g);
|
|
32
|
+
if (t < 0 || t > 1)
|
|
33
|
+
throw new Error(`LANGSMITH_TRACING_SAMPLING_RATE must be between 0 and 1 if set. Got: ${t}`);
|
|
34
|
+
return t;
|
|
35
|
+
}, G = (g) => {
|
|
36
|
+
const e = g.replace("http://", "").replace("https://", "").split("/")[0].split(":")[0];
|
|
37
|
+
return e === "localhost" || e === "127.0.0.1" || e === "::1";
|
|
38
|
+
};
|
|
39
|
+
async function Q(g) {
|
|
40
|
+
const t = [];
|
|
41
|
+
for await (const e of g)
|
|
42
|
+
t.push(e);
|
|
43
|
+
return t;
|
|
44
|
+
}
|
|
45
|
+
function I(g) {
|
|
46
|
+
if (g !== void 0)
|
|
47
|
+
return g.trim().replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1");
|
|
48
|
+
}
|
|
49
|
+
const K = async (g) => {
|
|
50
|
+
if ((g == null ? void 0 : g.status) === 429) {
|
|
51
|
+
const t = parseInt(g.headers.get("retry-after") ?? "30", 10) * 1e3;
|
|
52
|
+
if (t > 0)
|
|
53
|
+
return await new Promise((e) => setTimeout(e, t)), !0;
|
|
54
|
+
}
|
|
55
|
+
return !1;
|
|
56
|
+
};
|
|
57
|
+
class Y {
|
|
58
|
+
constructor() {
|
|
59
|
+
Object.defineProperty(this, "items", {
|
|
60
|
+
enumerable: !0,
|
|
61
|
+
configurable: !0,
|
|
62
|
+
writable: !0,
|
|
63
|
+
value: []
|
|
64
|
+
}), Object.defineProperty(this, "sizeBytes", {
|
|
65
|
+
enumerable: !0,
|
|
66
|
+
configurable: !0,
|
|
67
|
+
writable: !0,
|
|
68
|
+
value: 0
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
peek() {
|
|
72
|
+
return this.items[0];
|
|
73
|
+
}
|
|
74
|
+
push(t) {
|
|
75
|
+
let e;
|
|
76
|
+
const a = new Promise((s) => {
|
|
77
|
+
e = s;
|
|
78
|
+
}), i = T(t.item).length;
|
|
79
|
+
return this.items.push({
|
|
80
|
+
action: t.action,
|
|
81
|
+
payload: t.item,
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
83
|
+
itemPromiseResolve: e,
|
|
84
|
+
itemPromise: a,
|
|
85
|
+
size: i
|
|
86
|
+
}), this.sizeBytes += i, a;
|
|
87
|
+
}
|
|
88
|
+
pop(t) {
|
|
89
|
+
var i;
|
|
90
|
+
if (t < 1)
|
|
91
|
+
throw new Error("Number of bytes to pop off may not be less than 1.");
|
|
92
|
+
const e = [];
|
|
93
|
+
let a = 0;
|
|
94
|
+
for (; a + (((i = this.peek()) == null ? void 0 : i.size) ?? 0) < t && this.items.length > 0; ) {
|
|
95
|
+
const s = this.items.shift();
|
|
96
|
+
s && (e.push(s), a += s.size, this.sizeBytes -= s.size);
|
|
97
|
+
}
|
|
98
|
+
if (e.length === 0 && this.items.length > 0) {
|
|
99
|
+
const s = this.items.shift();
|
|
100
|
+
e.push(s), a += s.size, this.sizeBytes -= s.size;
|
|
101
|
+
}
|
|
102
|
+
return [
|
|
103
|
+
e.map((s) => ({ action: s.action, item: s.payload })),
|
|
104
|
+
() => e.forEach((s) => s.itemPromiseResolve())
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const V = 20971520, W = 1e3;
|
|
109
|
+
class A {
|
|
110
|
+
constructor(t = {}) {
|
|
111
|
+
var a;
|
|
112
|
+
Object.defineProperty(this, "apiKey", {
|
|
113
|
+
enumerable: !0,
|
|
114
|
+
configurable: !0,
|
|
115
|
+
writable: !0,
|
|
116
|
+
value: void 0
|
|
117
|
+
}), Object.defineProperty(this, "apiUrl", {
|
|
118
|
+
enumerable: !0,
|
|
119
|
+
configurable: !0,
|
|
120
|
+
writable: !0,
|
|
121
|
+
value: void 0
|
|
122
|
+
}), Object.defineProperty(this, "webUrl", {
|
|
123
|
+
enumerable: !0,
|
|
124
|
+
configurable: !0,
|
|
125
|
+
writable: !0,
|
|
126
|
+
value: void 0
|
|
127
|
+
}), Object.defineProperty(this, "caller", {
|
|
128
|
+
enumerable: !0,
|
|
129
|
+
configurable: !0,
|
|
130
|
+
writable: !0,
|
|
131
|
+
value: void 0
|
|
132
|
+
}), Object.defineProperty(this, "batchIngestCaller", {
|
|
133
|
+
enumerable: !0,
|
|
134
|
+
configurable: !0,
|
|
135
|
+
writable: !0,
|
|
136
|
+
value: void 0
|
|
137
|
+
}), Object.defineProperty(this, "timeout_ms", {
|
|
138
|
+
enumerable: !0,
|
|
139
|
+
configurable: !0,
|
|
140
|
+
writable: !0,
|
|
141
|
+
value: void 0
|
|
142
|
+
}), Object.defineProperty(this, "_tenantId", {
|
|
143
|
+
enumerable: !0,
|
|
144
|
+
configurable: !0,
|
|
145
|
+
writable: !0,
|
|
146
|
+
value: null
|
|
147
|
+
}), Object.defineProperty(this, "hideInputs", {
|
|
148
|
+
enumerable: !0,
|
|
149
|
+
configurable: !0,
|
|
150
|
+
writable: !0,
|
|
151
|
+
value: void 0
|
|
152
|
+
}), Object.defineProperty(this, "hideOutputs", {
|
|
153
|
+
enumerable: !0,
|
|
154
|
+
configurable: !0,
|
|
155
|
+
writable: !0,
|
|
156
|
+
value: void 0
|
|
157
|
+
}), Object.defineProperty(this, "tracingSampleRate", {
|
|
158
|
+
enumerable: !0,
|
|
159
|
+
configurable: !0,
|
|
160
|
+
writable: !0,
|
|
161
|
+
value: void 0
|
|
162
|
+
}), Object.defineProperty(this, "filteredPostUuids", {
|
|
163
|
+
enumerable: !0,
|
|
164
|
+
configurable: !0,
|
|
165
|
+
writable: !0,
|
|
166
|
+
value: /* @__PURE__ */ new Set()
|
|
167
|
+
}), Object.defineProperty(this, "autoBatchTracing", {
|
|
168
|
+
enumerable: !0,
|
|
169
|
+
configurable: !0,
|
|
170
|
+
writable: !0,
|
|
171
|
+
value: !0
|
|
172
|
+
}), Object.defineProperty(this, "autoBatchQueue", {
|
|
173
|
+
enumerable: !0,
|
|
174
|
+
configurable: !0,
|
|
175
|
+
writable: !0,
|
|
176
|
+
value: new Y()
|
|
177
|
+
}), Object.defineProperty(this, "autoBatchTimeout", {
|
|
178
|
+
enumerable: !0,
|
|
179
|
+
configurable: !0,
|
|
180
|
+
writable: !0,
|
|
181
|
+
value: void 0
|
|
182
|
+
}), Object.defineProperty(this, "autoBatchInitialDelayMs", {
|
|
183
|
+
enumerable: !0,
|
|
184
|
+
configurable: !0,
|
|
185
|
+
writable: !0,
|
|
186
|
+
value: 250
|
|
187
|
+
}), Object.defineProperty(this, "autoBatchAggregationDelayMs", {
|
|
188
|
+
enumerable: !0,
|
|
189
|
+
configurable: !0,
|
|
190
|
+
writable: !0,
|
|
191
|
+
value: 50
|
|
192
|
+
}), Object.defineProperty(this, "batchSizeBytesLimit", {
|
|
193
|
+
enumerable: !0,
|
|
194
|
+
configurable: !0,
|
|
195
|
+
writable: !0,
|
|
196
|
+
value: void 0
|
|
197
|
+
}), Object.defineProperty(this, "fetchOptions", {
|
|
198
|
+
enumerable: !0,
|
|
199
|
+
configurable: !0,
|
|
200
|
+
writable: !0,
|
|
201
|
+
value: void 0
|
|
202
|
+
}), Object.defineProperty(this, "settings", {
|
|
203
|
+
enumerable: !0,
|
|
204
|
+
configurable: !0,
|
|
205
|
+
writable: !0,
|
|
206
|
+
value: void 0
|
|
207
|
+
}), Object.defineProperty(this, "blockOnRootRunFinalization", {
|
|
208
|
+
enumerable: !0,
|
|
209
|
+
configurable: !0,
|
|
210
|
+
writable: !0,
|
|
211
|
+
value: !0
|
|
212
|
+
}), Object.defineProperty(this, "_serverInfo", {
|
|
213
|
+
enumerable: !0,
|
|
214
|
+
configurable: !0,
|
|
215
|
+
writable: !0,
|
|
216
|
+
value: void 0
|
|
217
|
+
}), Object.defineProperty(this, "_getServerInfoPromise", {
|
|
218
|
+
enumerable: !0,
|
|
219
|
+
configurable: !0,
|
|
220
|
+
writable: !0,
|
|
221
|
+
value: void 0
|
|
222
|
+
});
|
|
223
|
+
const e = A.getDefaultClientConfig();
|
|
224
|
+
this.tracingSampleRate = q(), this.apiUrl = I(t.apiUrl ?? e.apiUrl) ?? "", this.apiUrl.endsWith("/") && (this.apiUrl = this.apiUrl.slice(0, -1)), this.apiKey = I(t.apiKey ?? e.apiKey), this.webUrl = I(t.webUrl ?? e.webUrl), (a = this.webUrl) != null && a.endsWith("/") && (this.webUrl = this.webUrl.slice(0, -1)), this.timeout_ms = t.timeout_ms ?? 12e3, this.caller = new k(t.callerOptions ?? {}), this.batchIngestCaller = new k({
|
|
225
|
+
...t.callerOptions ?? {},
|
|
226
|
+
onFailedResponseHook: K
|
|
227
|
+
}), this.hideInputs = t.hideInputs ?? t.anonymizer ?? e.hideInputs, this.hideOutputs = t.hideOutputs ?? t.anonymizer ?? e.hideOutputs, this.autoBatchTracing = t.autoBatchTracing ?? this.autoBatchTracing, this.blockOnRootRunFinalization = t.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization, this.batchSizeBytesLimit = t.batchSizeBytesLimit, this.fetchOptions = t.fetchOptions || {};
|
|
228
|
+
}
|
|
229
|
+
static getDefaultClientConfig() {
|
|
230
|
+
const t = j("API_KEY"), e = j("ENDPOINT") ?? "https://api.smith.langchain.com", a = j("HIDE_INPUTS") === "true", i = j("HIDE_OUTPUTS") === "true";
|
|
231
|
+
return {
|
|
232
|
+
apiUrl: e,
|
|
233
|
+
apiKey: t,
|
|
234
|
+
webUrl: void 0,
|
|
235
|
+
hideInputs: a,
|
|
236
|
+
hideOutputs: i
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
getHostUrl() {
|
|
240
|
+
return this.webUrl ? this.webUrl : G(this.apiUrl) ? (this.webUrl = "http://localhost:3000", this.webUrl) : this.apiUrl.includes("/api") && !this.apiUrl.split(".", 1)[0].endsWith("api") ? (this.webUrl = this.apiUrl.replace("/api", ""), this.webUrl) : this.apiUrl.split(".", 1)[0].includes("dev") ? (this.webUrl = "https://dev.smith.langchain.com", this.webUrl) : this.apiUrl.split(".", 1)[0].includes("eu") ? (this.webUrl = "https://eu.smith.langchain.com", this.webUrl) : (this.webUrl = "https://smith.langchain.com", this.webUrl);
|
|
241
|
+
}
|
|
242
|
+
get headers() {
|
|
243
|
+
const t = {
|
|
244
|
+
"User-Agent": `langsmith-js/${F}`
|
|
245
|
+
};
|
|
246
|
+
return this.apiKey && (t["x-api-key"] = `${this.apiKey}`), t;
|
|
247
|
+
}
|
|
248
|
+
processInputs(t) {
|
|
249
|
+
return this.hideInputs === !1 ? t : this.hideInputs === !0 ? {} : typeof this.hideInputs == "function" ? this.hideInputs(t) : t;
|
|
250
|
+
}
|
|
251
|
+
processOutputs(t) {
|
|
252
|
+
return this.hideOutputs === !1 ? t : this.hideOutputs === !0 ? {} : typeof this.hideOutputs == "function" ? this.hideOutputs(t) : t;
|
|
253
|
+
}
|
|
254
|
+
prepareRunCreateOrUpdateInputs(t) {
|
|
255
|
+
const e = { ...t };
|
|
256
|
+
return e.inputs !== void 0 && (e.inputs = this.processInputs(e.inputs)), e.outputs !== void 0 && (e.outputs = this.processOutputs(e.outputs)), e;
|
|
257
|
+
}
|
|
258
|
+
async _getResponse(t, e) {
|
|
259
|
+
const a = (e == null ? void 0 : e.toString()) ?? "", i = `${this.apiUrl}${t}?${a}`, s = await this.caller.call(u(), i, {
|
|
260
|
+
method: "GET",
|
|
261
|
+
headers: this.headers,
|
|
262
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
263
|
+
...this.fetchOptions
|
|
264
|
+
});
|
|
265
|
+
return await p(s, `Failed to fetch ${t}`), s;
|
|
266
|
+
}
|
|
267
|
+
async _get(t, e) {
|
|
268
|
+
return (await this._getResponse(t, e)).json();
|
|
269
|
+
}
|
|
270
|
+
async *_getPaginated(t, e = new URLSearchParams(), a) {
|
|
271
|
+
let i = Number(e.get("offset")) || 0;
|
|
272
|
+
const s = Number(e.get("limit")) || 100;
|
|
273
|
+
for (; ; ) {
|
|
274
|
+
e.set("offset", String(i)), e.set("limit", String(s));
|
|
275
|
+
const r = `${this.apiUrl}${t}?${e}`, o = await this.caller.call(u(), r, {
|
|
276
|
+
method: "GET",
|
|
277
|
+
headers: this.headers,
|
|
278
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
279
|
+
...this.fetchOptions
|
|
280
|
+
});
|
|
281
|
+
await p(o, `Failed to fetch ${t}`);
|
|
282
|
+
const n = a ? a(await o.json()) : await o.json();
|
|
283
|
+
if (n.length === 0 || (yield n, n.length < s))
|
|
284
|
+
break;
|
|
285
|
+
i += n.length;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async *_getCursorPaginatedList(t, e = null, a = "POST", i = "runs") {
|
|
289
|
+
const s = e ? { ...e } : {};
|
|
290
|
+
for (; ; ) {
|
|
291
|
+
const o = await (await this.caller.call(u(), `${this.apiUrl}${t}`, {
|
|
292
|
+
method: a,
|
|
293
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
294
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
295
|
+
...this.fetchOptions,
|
|
296
|
+
body: JSON.stringify(s)
|
|
297
|
+
})).json();
|
|
298
|
+
if (!o || !o[i])
|
|
299
|
+
break;
|
|
300
|
+
yield o[i];
|
|
301
|
+
const n = o.cursors;
|
|
302
|
+
if (!n || !n.next)
|
|
303
|
+
break;
|
|
304
|
+
s.cursor = n.next;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
_filterForSampling(t, e = !1) {
|
|
308
|
+
if (this.tracingSampleRate === void 0)
|
|
309
|
+
return t;
|
|
310
|
+
if (e) {
|
|
311
|
+
const a = [];
|
|
312
|
+
for (const i of t)
|
|
313
|
+
this.filteredPostUuids.has(i.id) ? this.filteredPostUuids.delete(i.id) : a.push(i);
|
|
314
|
+
return a;
|
|
315
|
+
} else {
|
|
316
|
+
const a = [];
|
|
317
|
+
for (const i of t)
|
|
318
|
+
i.id !== i.trace_id && !this.filteredPostUuids.has(i.trace_id) || Math.random() < this.tracingSampleRate ? a.push(i) : this.filteredPostUuids.add(i.id);
|
|
319
|
+
return a;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async _getBatchSizeLimitBytes() {
|
|
323
|
+
var e;
|
|
324
|
+
const t = await this._ensureServerInfo();
|
|
325
|
+
return this.batchSizeBytesLimit ?? ((e = t.batch_ingest_config) == null ? void 0 : e.size_limit_bytes) ?? V;
|
|
326
|
+
}
|
|
327
|
+
async drainAutoBatchQueue() {
|
|
328
|
+
var t;
|
|
329
|
+
for (; this.autoBatchQueue.items.length >= 0; ) {
|
|
330
|
+
const [e, a] = this.autoBatchQueue.pop(await this._getBatchSizeLimitBytes());
|
|
331
|
+
if (!e.length) {
|
|
332
|
+
a();
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
const i = {
|
|
337
|
+
runCreates: e.filter((r) => r.action === "create").map((r) => r.item),
|
|
338
|
+
runUpdates: e.filter((r) => r.action === "update").map((r) => r.item)
|
|
339
|
+
}, s = await this._ensureServerInfo();
|
|
340
|
+
(t = s == null ? void 0 : s.batch_ingest_config) != null && t.use_multipart_endpoint ? await this.multipartIngestRuns(i) : await this.batchIngestRuns(i);
|
|
341
|
+
} finally {
|
|
342
|
+
a();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
async processRunOperation(t, e) {
|
|
347
|
+
const a = this.autoBatchTimeout;
|
|
348
|
+
clearTimeout(this.autoBatchTimeout), this.autoBatchTimeout = void 0, t.action === "create" && (t.item = D(t.item));
|
|
349
|
+
const i = this.autoBatchQueue.push(t), s = await this._getBatchSizeLimitBytes();
|
|
350
|
+
return (e || this.autoBatchQueue.sizeBytes > s) && await this.drainAutoBatchQueue().catch(console.error), this.autoBatchQueue.items.length > 0 && (this.autoBatchTimeout = setTimeout(() => {
|
|
351
|
+
this.autoBatchTimeout = void 0, this.drainAutoBatchQueue().catch(console.error);
|
|
352
|
+
}, a ? this.autoBatchAggregationDelayMs : this.autoBatchInitialDelayMs)), i;
|
|
353
|
+
}
|
|
354
|
+
async _getServerInfo() {
|
|
355
|
+
const t = await u()(`${this.apiUrl}/info`, {
|
|
356
|
+
method: "GET",
|
|
357
|
+
headers: { Accept: "application/json" },
|
|
358
|
+
signal: AbortSignal.timeout(W),
|
|
359
|
+
...this.fetchOptions
|
|
360
|
+
});
|
|
361
|
+
return await p(t, "get server info"), t.json();
|
|
362
|
+
}
|
|
363
|
+
async _ensureServerInfo() {
|
|
364
|
+
return this._getServerInfoPromise === void 0 && (this._getServerInfoPromise = (async () => {
|
|
365
|
+
if (this._serverInfo === void 0)
|
|
366
|
+
try {
|
|
367
|
+
this._serverInfo = await this._getServerInfo();
|
|
368
|
+
} catch {
|
|
369
|
+
console.warn("[WARNING]: LangSmith failed to fetch info on supported operations. Falling back to single calls and default limits.");
|
|
370
|
+
}
|
|
371
|
+
return this._serverInfo ?? {};
|
|
372
|
+
})()), this._getServerInfoPromise.then((t) => (this._serverInfo === void 0 && (this._getServerInfoPromise = void 0), t));
|
|
373
|
+
}
|
|
374
|
+
async _getSettings() {
|
|
375
|
+
return this.settings || (this.settings = this._get("/settings")), await this.settings;
|
|
376
|
+
}
|
|
377
|
+
async createRun(t) {
|
|
378
|
+
if (!this._filterForSampling([t]).length)
|
|
379
|
+
return;
|
|
380
|
+
const e = { ...this.headers, "Content-Type": "application/json" }, a = t.project_name;
|
|
381
|
+
delete t.project_name;
|
|
382
|
+
const i = this.prepareRunCreateOrUpdateInputs({
|
|
383
|
+
session_name: a,
|
|
384
|
+
...t,
|
|
385
|
+
start_time: t.start_time ?? Date.now()
|
|
386
|
+
});
|
|
387
|
+
if (this.autoBatchTracing && i.trace_id !== void 0 && i.dotted_order !== void 0) {
|
|
388
|
+
this.processRunOperation({
|
|
389
|
+
action: "create",
|
|
390
|
+
item: i
|
|
391
|
+
}).catch(console.error);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const s = D(i), r = await this.caller.call(u(), `${this.apiUrl}/runs`, {
|
|
395
|
+
method: "POST",
|
|
396
|
+
headers: e,
|
|
397
|
+
body: T(s),
|
|
398
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
399
|
+
...this.fetchOptions
|
|
400
|
+
});
|
|
401
|
+
await p(r, "create run", !0);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
405
|
+
* @param runs
|
|
406
|
+
*/
|
|
407
|
+
async batchIngestRuns({ runCreates: t, runUpdates: e }) {
|
|
408
|
+
if (t === void 0 && e === void 0)
|
|
409
|
+
return;
|
|
410
|
+
let a = (t == null ? void 0 : t.map((n) => this.prepareRunCreateOrUpdateInputs(n))) ?? [], i = (e == null ? void 0 : e.map((n) => this.prepareRunCreateOrUpdateInputs(n))) ?? [];
|
|
411
|
+
if (a.length > 0 && i.length > 0) {
|
|
412
|
+
const n = a.reduce((l, h) => (h.id && (l[h.id] = h), l), {}), d = [];
|
|
413
|
+
for (const l of i)
|
|
414
|
+
l.id !== void 0 && n[l.id] ? n[l.id] = {
|
|
415
|
+
...n[l.id],
|
|
416
|
+
...l
|
|
417
|
+
} : d.push(l);
|
|
418
|
+
a = Object.values(n), i = d;
|
|
419
|
+
}
|
|
420
|
+
const s = {
|
|
421
|
+
post: this._filterForSampling(a),
|
|
422
|
+
patch: this._filterForSampling(i, !0)
|
|
423
|
+
};
|
|
424
|
+
if (!s.post.length && !s.patch.length)
|
|
425
|
+
return;
|
|
426
|
+
if ((await this._ensureServerInfo()).version === void 0) {
|
|
427
|
+
this.autoBatchTracing = !1;
|
|
428
|
+
for (const n of s.post)
|
|
429
|
+
await this.createRun(n);
|
|
430
|
+
for (const n of s.patch)
|
|
431
|
+
n.id !== void 0 && await this.updateRun(n.id, n);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const o = {
|
|
435
|
+
post: [],
|
|
436
|
+
patch: []
|
|
437
|
+
};
|
|
438
|
+
for (const n of ["post", "patch"]) {
|
|
439
|
+
const d = n, l = s[d].reverse();
|
|
440
|
+
let h = l.pop();
|
|
441
|
+
for (; h !== void 0; )
|
|
442
|
+
o[d].push(h), h = l.pop();
|
|
443
|
+
}
|
|
444
|
+
(o.post.length > 0 || o.patch.length > 0) && await this._postBatchIngestRuns(T(o));
|
|
445
|
+
}
|
|
446
|
+
async _postBatchIngestRuns(t) {
|
|
447
|
+
const e = {
|
|
448
|
+
...this.headers,
|
|
449
|
+
"Content-Type": "application/json",
|
|
450
|
+
Accept: "application/json"
|
|
451
|
+
}, a = await this.batchIngestCaller.call(u(), `${this.apiUrl}/runs/batch`, {
|
|
452
|
+
method: "POST",
|
|
453
|
+
headers: e,
|
|
454
|
+
body: t,
|
|
455
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
456
|
+
...this.fetchOptions
|
|
457
|
+
});
|
|
458
|
+
await p(a, "batch create run", !0);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
462
|
+
* @param runs
|
|
463
|
+
*/
|
|
464
|
+
async multipartIngestRuns({ runCreates: t, runUpdates: e }) {
|
|
465
|
+
if (t === void 0 && e === void 0)
|
|
466
|
+
return;
|
|
467
|
+
const a = {};
|
|
468
|
+
let i = [];
|
|
469
|
+
for (const l of t ?? []) {
|
|
470
|
+
const h = this.prepareRunCreateOrUpdateInputs(l);
|
|
471
|
+
h.id !== void 0 && h.attachments !== void 0 && (a[h.id] = h.attachments), delete h.attachments, i.push(h);
|
|
472
|
+
}
|
|
473
|
+
let s = [];
|
|
474
|
+
for (const l of e ?? [])
|
|
475
|
+
s.push(this.prepareRunCreateOrUpdateInputs(l));
|
|
476
|
+
if (i.find((l) => l.trace_id === void 0 || l.dotted_order === void 0) !== void 0)
|
|
477
|
+
throw new Error('Multipart ingest requires "trace_id" and "dotted_order" to be set when creating a run');
|
|
478
|
+
if (s.find((l) => l.trace_id === void 0 || l.dotted_order === void 0) !== void 0)
|
|
479
|
+
throw new Error('Multipart ingest requires "trace_id" and "dotted_order" to be set when updating a run');
|
|
480
|
+
if (i.length > 0 && s.length > 0) {
|
|
481
|
+
const l = i.reduce((c, _) => (_.id && (c[_.id] = _), c), {}), h = [];
|
|
482
|
+
for (const c of s)
|
|
483
|
+
c.id !== void 0 && l[c.id] ? l[c.id] = {
|
|
484
|
+
...l[c.id],
|
|
485
|
+
...c
|
|
486
|
+
} : h.push(c);
|
|
487
|
+
i = Object.values(l), s = h;
|
|
488
|
+
}
|
|
489
|
+
if (i.length === 0 && s.length === 0)
|
|
490
|
+
return;
|
|
491
|
+
const n = [], d = [];
|
|
492
|
+
for (const [l, h] of [
|
|
493
|
+
["post", i],
|
|
494
|
+
["patch", s]
|
|
495
|
+
])
|
|
496
|
+
for (const c of h) {
|
|
497
|
+
const { inputs: _, outputs: m, events: b, ...w } = c, y = { inputs: _, outputs: m, events: b }, U = T(w);
|
|
498
|
+
d.push({
|
|
499
|
+
name: `${l}.${w.id}`,
|
|
500
|
+
payload: new Blob([U], {
|
|
501
|
+
type: `application/json; length=${U.length}`
|
|
502
|
+
// encoding=gzip
|
|
503
|
+
})
|
|
504
|
+
});
|
|
505
|
+
for (const [S, v] of Object.entries(y)) {
|
|
506
|
+
if (v === void 0)
|
|
507
|
+
continue;
|
|
508
|
+
const E = T(v);
|
|
509
|
+
d.push({
|
|
510
|
+
name: `${l}.${w.id}.${S}`,
|
|
511
|
+
payload: new Blob([E], {
|
|
512
|
+
type: `application/json; length=${E.length}`
|
|
513
|
+
})
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
if (w.id !== void 0) {
|
|
517
|
+
const S = a[w.id];
|
|
518
|
+
if (S) {
|
|
519
|
+
delete a[w.id];
|
|
520
|
+
for (const [v, [E, P]] of Object.entries(S))
|
|
521
|
+
d.push({
|
|
522
|
+
name: `attachment.${w.id}.${v}`,
|
|
523
|
+
payload: new Blob([P], {
|
|
524
|
+
type: `${E}; length=${P.length}`
|
|
525
|
+
})
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
n.push(`trace=${w.trace_id},id=${w.id}`);
|
|
530
|
+
}
|
|
531
|
+
await this._sendMultipartRequest(d, n.join("; "));
|
|
532
|
+
}
|
|
533
|
+
async _sendMultipartRequest(t, e) {
|
|
534
|
+
try {
|
|
535
|
+
const a = new FormData();
|
|
536
|
+
for (const i of t)
|
|
537
|
+
a.append(i.name, i.payload);
|
|
538
|
+
await this.batchIngestCaller.call(u(), `${this.apiUrl}/runs/multipart`, {
|
|
539
|
+
method: "POST",
|
|
540
|
+
headers: {
|
|
541
|
+
...this.headers
|
|
542
|
+
},
|
|
543
|
+
body: a,
|
|
544
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
545
|
+
...this.fetchOptions
|
|
546
|
+
});
|
|
547
|
+
} catch (a) {
|
|
548
|
+
let i = "Failed to multipart ingest runs";
|
|
549
|
+
a instanceof Error ? i += `: ${a.stack || a.message}` : i += `: ${String(a)}`, console.warn(`${i.trim()}
|
|
550
|
+
|
|
551
|
+
Context: ${e}`);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
async updateRun(t, e) {
|
|
555
|
+
f(t), e.inputs && (e.inputs = this.processInputs(e.inputs)), e.outputs && (e.outputs = this.processOutputs(e.outputs));
|
|
556
|
+
const a = { ...e, id: t };
|
|
557
|
+
if (!this._filterForSampling([a], !0).length)
|
|
558
|
+
return;
|
|
559
|
+
if (this.autoBatchTracing && a.trace_id !== void 0 && a.dotted_order !== void 0) {
|
|
560
|
+
if (e.end_time !== void 0 && a.parent_run_id === void 0 && this.blockOnRootRunFinalization) {
|
|
561
|
+
await this.processRunOperation({ action: "update", item: a }, !0);
|
|
562
|
+
return;
|
|
563
|
+
} else
|
|
564
|
+
this.processRunOperation({ action: "update", item: a }).catch(console.error);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const i = { ...this.headers, "Content-Type": "application/json" }, s = await this.caller.call(u(), `${this.apiUrl}/runs/${t}`, {
|
|
568
|
+
method: "PATCH",
|
|
569
|
+
headers: i,
|
|
570
|
+
body: T(e),
|
|
571
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
572
|
+
...this.fetchOptions
|
|
573
|
+
});
|
|
574
|
+
await p(s, "update run", !0);
|
|
575
|
+
}
|
|
576
|
+
async readRun(t, { loadChildRuns: e } = { loadChildRuns: !1 }) {
|
|
577
|
+
f(t);
|
|
578
|
+
let a = await this._get(`/runs/${t}`);
|
|
579
|
+
return e && a.child_run_ids && (a = await this._loadChildRuns(a)), a;
|
|
580
|
+
}
|
|
581
|
+
async getRunUrl({ runId: t, run: e, projectOpts: a }) {
|
|
582
|
+
if (e !== void 0) {
|
|
583
|
+
let i;
|
|
584
|
+
e.session_id ? i = e.session_id : a != null && a.projectName ? i = (await this.readProject({ projectName: a == null ? void 0 : a.projectName })).id : a != null && a.projectId ? i = a == null ? void 0 : a.projectId : i = (await this.readProject({
|
|
585
|
+
projectName: j("PROJECT") || "default"
|
|
586
|
+
})).id;
|
|
587
|
+
const s = await this._getTenantId();
|
|
588
|
+
return `${this.getHostUrl()}/o/${s}/projects/p/${i}/r/${e.id}?poll=true`;
|
|
589
|
+
} else if (t !== void 0) {
|
|
590
|
+
const i = await this.readRun(t);
|
|
591
|
+
if (!i.app_path)
|
|
592
|
+
throw new Error(`Run ${t} has no app_path`);
|
|
593
|
+
return `${this.getHostUrl()}${i.app_path}`;
|
|
594
|
+
} else
|
|
595
|
+
throw new Error("Must provide either runId or run");
|
|
596
|
+
}
|
|
597
|
+
async _loadChildRuns(t) {
|
|
598
|
+
const e = await Q(this.listRuns({ id: t.child_run_ids })), a = {}, i = {};
|
|
599
|
+
e.sort((s, r) => ((s == null ? void 0 : s.dotted_order) ?? "").localeCompare((r == null ? void 0 : r.dotted_order) ?? ""));
|
|
600
|
+
for (const s of e) {
|
|
601
|
+
if (s.parent_run_id === null || s.parent_run_id === void 0)
|
|
602
|
+
throw new Error(`Child run ${s.id} has no parent`);
|
|
603
|
+
s.parent_run_id in a || (a[s.parent_run_id] = []), a[s.parent_run_id].push(s), i[s.id] = s;
|
|
604
|
+
}
|
|
605
|
+
t.child_runs = a[t.id] || [];
|
|
606
|
+
for (const s in a)
|
|
607
|
+
s !== t.id && (i[s].child_runs = a[s]);
|
|
608
|
+
return t;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* List runs from the LangSmith server.
|
|
612
|
+
* @param projectId - The ID of the project to filter by.
|
|
613
|
+
* @param projectName - The name of the project to filter by.
|
|
614
|
+
* @param parentRunId - The ID of the parent run to filter by.
|
|
615
|
+
* @param traceId - The ID of the trace to filter by.
|
|
616
|
+
* @param referenceExampleId - The ID of the reference example to filter by.
|
|
617
|
+
* @param startTime - The start time to filter by.
|
|
618
|
+
* @param isRoot - Indicates whether to only return root runs.
|
|
619
|
+
* @param runType - The run type to filter by.
|
|
620
|
+
* @param error - Indicates whether to filter by error runs.
|
|
621
|
+
* @param id - The ID of the run to filter by.
|
|
622
|
+
* @param query - The query string to filter by.
|
|
623
|
+
* @param filter - The filter string to apply to the run spans.
|
|
624
|
+
* @param traceFilter - The filter string to apply on the root run of the trace.
|
|
625
|
+
* @param limit - The maximum number of runs to retrieve.
|
|
626
|
+
* @returns {AsyncIterable<Run>} - The runs.
|
|
627
|
+
*
|
|
628
|
+
* @example
|
|
629
|
+
* // List all runs in a project
|
|
630
|
+
* const projectRuns = client.listRuns({ projectName: "<your_project>" });
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* // List LLM and Chat runs in the last 24 hours
|
|
634
|
+
* const todaysLLMRuns = client.listRuns({
|
|
635
|
+
* projectName: "<your_project>",
|
|
636
|
+
* start_time: new Date(Date.now() - 24 * 60 * 60 * 1000),
|
|
637
|
+
* run_type: "llm",
|
|
638
|
+
* });
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* // List traces in a project
|
|
642
|
+
* const rootRuns = client.listRuns({
|
|
643
|
+
* projectName: "<your_project>",
|
|
644
|
+
* execution_order: 1,
|
|
645
|
+
* });
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* // List runs without errors
|
|
649
|
+
* const correctRuns = client.listRuns({
|
|
650
|
+
* projectName: "<your_project>",
|
|
651
|
+
* error: false,
|
|
652
|
+
* });
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* // List runs by run ID
|
|
656
|
+
* const runIds = [
|
|
657
|
+
* "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
|
|
658
|
+
* "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
|
|
659
|
+
* ];
|
|
660
|
+
* const selectedRuns = client.listRuns({ run_ids: runIds });
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* // List all "chain" type runs that took more than 10 seconds and had `total_tokens` greater than 5000
|
|
664
|
+
* const chainRuns = client.listRuns({
|
|
665
|
+
* projectName: "<your_project>",
|
|
666
|
+
* filter: 'and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
|
|
667
|
+
* });
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* // List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1
|
|
671
|
+
* const goodExtractorRuns = client.listRuns({
|
|
672
|
+
* projectName: "<your_project>",
|
|
673
|
+
* filter: 'eq(name, "extractor")',
|
|
674
|
+
* traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
|
|
675
|
+
* });
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* // List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0
|
|
679
|
+
* const complexRuns = client.listRuns({
|
|
680
|
+
* projectName: "<your_project>",
|
|
681
|
+
* filter: 'and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
|
|
682
|
+
* });
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* // List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds
|
|
686
|
+
* const taggedRuns = client.listRuns({
|
|
687
|
+
* projectName: "<your_project>",
|
|
688
|
+
* filter: 'and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
|
|
689
|
+
* });
|
|
690
|
+
*/
|
|
691
|
+
async *listRuns(t) {
|
|
692
|
+
const { projectId: e, projectName: a, parentRunId: i, traceId: s, referenceExampleId: r, startTime: o, executionOrder: n, isRoot: d, runType: l, error: h, id: c, query: _, filter: m, traceFilter: b, treeFilter: w, limit: y, select: U } = t;
|
|
693
|
+
let S = [];
|
|
694
|
+
if (e && (S = Array.isArray(e) ? e : [e]), a) {
|
|
695
|
+
const $ = Array.isArray(a) ? a : [a], C = await Promise.all($.map((L) => this.readProject({ projectName: L }).then((B) => B.id)));
|
|
696
|
+
S.push(...C);
|
|
697
|
+
}
|
|
698
|
+
const v = [
|
|
699
|
+
"app_path",
|
|
700
|
+
"child_run_ids",
|
|
701
|
+
"completion_cost",
|
|
702
|
+
"completion_tokens",
|
|
703
|
+
"dotted_order",
|
|
704
|
+
"end_time",
|
|
705
|
+
"error",
|
|
706
|
+
"events",
|
|
707
|
+
"extra",
|
|
708
|
+
"feedback_stats",
|
|
709
|
+
"first_token_time",
|
|
710
|
+
"id",
|
|
711
|
+
"inputs",
|
|
712
|
+
"name",
|
|
713
|
+
"outputs",
|
|
714
|
+
"parent_run_id",
|
|
715
|
+
"parent_run_ids",
|
|
716
|
+
"prompt_cost",
|
|
717
|
+
"prompt_tokens",
|
|
718
|
+
"reference_example_id",
|
|
719
|
+
"run_type",
|
|
720
|
+
"session_id",
|
|
721
|
+
"start_time",
|
|
722
|
+
"status",
|
|
723
|
+
"tags",
|
|
724
|
+
"total_cost",
|
|
725
|
+
"total_tokens",
|
|
726
|
+
"trace_id"
|
|
727
|
+
], E = {
|
|
728
|
+
session: S.length ? S : null,
|
|
729
|
+
run_type: l,
|
|
730
|
+
reference_example: r,
|
|
731
|
+
query: _,
|
|
732
|
+
filter: m,
|
|
733
|
+
trace_filter: b,
|
|
734
|
+
tree_filter: w,
|
|
735
|
+
execution_order: n,
|
|
736
|
+
parent_run: i,
|
|
737
|
+
start_time: o ? o.toISOString() : null,
|
|
738
|
+
error: h,
|
|
739
|
+
id: c,
|
|
740
|
+
limit: y,
|
|
741
|
+
trace: s,
|
|
742
|
+
select: U || v,
|
|
743
|
+
is_root: d
|
|
744
|
+
};
|
|
745
|
+
let P = 0;
|
|
746
|
+
for await (const $ of this._getCursorPaginatedList("/runs/query", E))
|
|
747
|
+
if (y) {
|
|
748
|
+
if (P >= y)
|
|
749
|
+
break;
|
|
750
|
+
if ($.length + P > y) {
|
|
751
|
+
yield* $.slice(0, y - P);
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
P += $.length, yield* $;
|
|
755
|
+
} else
|
|
756
|
+
yield* $;
|
|
757
|
+
}
|
|
758
|
+
async getRunStats({ id: t, trace: e, parentRun: a, runType: i, projectNames: s, projectIds: r, referenceExampleIds: o, startTime: n, endTime: d, error: l, query: h, filter: c, traceFilter: _, treeFilter: m, isRoot: b, dataSourceType: w }) {
|
|
759
|
+
let y = r || [];
|
|
760
|
+
s && (y = [
|
|
761
|
+
...r || [],
|
|
762
|
+
...await Promise.all(s.map((P) => this.readProject({ projectName: P }).then(($) => $.id)))
|
|
763
|
+
]);
|
|
764
|
+
const S = Object.fromEntries(Object.entries({
|
|
765
|
+
id: t,
|
|
766
|
+
trace: e,
|
|
767
|
+
parent_run: a,
|
|
768
|
+
run_type: i,
|
|
769
|
+
session: y,
|
|
770
|
+
reference_example: o,
|
|
771
|
+
start_time: n,
|
|
772
|
+
end_time: d,
|
|
773
|
+
error: l,
|
|
774
|
+
query: h,
|
|
775
|
+
filter: c,
|
|
776
|
+
trace_filter: _,
|
|
777
|
+
tree_filter: m,
|
|
778
|
+
is_root: b,
|
|
779
|
+
data_source_type: w
|
|
780
|
+
}).filter(([P, $]) => $ !== void 0));
|
|
781
|
+
return await (await this.caller.call(u(), `${this.apiUrl}/runs/stats`, {
|
|
782
|
+
method: "POST",
|
|
783
|
+
headers: this.headers,
|
|
784
|
+
body: JSON.stringify(S),
|
|
785
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
786
|
+
...this.fetchOptions
|
|
787
|
+
})).json();
|
|
788
|
+
}
|
|
789
|
+
async shareRun(t, { shareId: e } = {}) {
|
|
790
|
+
const a = {
|
|
791
|
+
run_id: t,
|
|
792
|
+
share_token: e || R()
|
|
793
|
+
};
|
|
794
|
+
f(t);
|
|
795
|
+
const s = await (await this.caller.call(u(), `${this.apiUrl}/runs/${t}/share`, {
|
|
796
|
+
method: "PUT",
|
|
797
|
+
headers: this.headers,
|
|
798
|
+
body: JSON.stringify(a),
|
|
799
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
800
|
+
...this.fetchOptions
|
|
801
|
+
})).json();
|
|
802
|
+
if (s === null || !("share_token" in s))
|
|
803
|
+
throw new Error("Invalid response from server");
|
|
804
|
+
return `${this.getHostUrl()}/public/${s.share_token}/r`;
|
|
805
|
+
}
|
|
806
|
+
async unshareRun(t) {
|
|
807
|
+
f(t);
|
|
808
|
+
const e = await this.caller.call(u(), `${this.apiUrl}/runs/${t}/share`, {
|
|
809
|
+
method: "DELETE",
|
|
810
|
+
headers: this.headers,
|
|
811
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
812
|
+
...this.fetchOptions
|
|
813
|
+
});
|
|
814
|
+
await p(e, "unshare run", !0);
|
|
815
|
+
}
|
|
816
|
+
async readRunSharedLink(t) {
|
|
817
|
+
f(t);
|
|
818
|
+
const a = await (await this.caller.call(u(), `${this.apiUrl}/runs/${t}/share`, {
|
|
819
|
+
method: "GET",
|
|
820
|
+
headers: this.headers,
|
|
821
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
822
|
+
...this.fetchOptions
|
|
823
|
+
})).json();
|
|
824
|
+
if (!(a === null || !("share_token" in a)))
|
|
825
|
+
return `${this.getHostUrl()}/public/${a.share_token}/r`;
|
|
826
|
+
}
|
|
827
|
+
async listSharedRuns(t, { runIds: e } = {}) {
|
|
828
|
+
const a = new URLSearchParams({
|
|
829
|
+
share_token: t
|
|
830
|
+
});
|
|
831
|
+
if (e !== void 0)
|
|
832
|
+
for (const r of e)
|
|
833
|
+
a.append("id", r);
|
|
834
|
+
return f(t), await (await this.caller.call(u(), `${this.apiUrl}/public/${t}/runs${a}`, {
|
|
835
|
+
method: "GET",
|
|
836
|
+
headers: this.headers,
|
|
837
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
838
|
+
...this.fetchOptions
|
|
839
|
+
})).json();
|
|
840
|
+
}
|
|
841
|
+
async readDatasetSharedSchema(t, e) {
|
|
842
|
+
if (!t && !e)
|
|
843
|
+
throw new Error("Either datasetId or datasetName must be given");
|
|
844
|
+
t || (t = (await this.readDataset({ datasetName: e })).id), f(t);
|
|
845
|
+
const i = await (await this.caller.call(u(), `${this.apiUrl}/datasets/${t}/share`, {
|
|
846
|
+
method: "GET",
|
|
847
|
+
headers: this.headers,
|
|
848
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
849
|
+
...this.fetchOptions
|
|
850
|
+
})).json();
|
|
851
|
+
return i.url = `${this.getHostUrl()}/public/${i.share_token}/d`, i;
|
|
852
|
+
}
|
|
853
|
+
async shareDataset(t, e) {
|
|
854
|
+
if (!t && !e)
|
|
855
|
+
throw new Error("Either datasetId or datasetName must be given");
|
|
856
|
+
t || (t = (await this.readDataset({ datasetName: e })).id);
|
|
857
|
+
const a = {
|
|
858
|
+
dataset_id: t
|
|
859
|
+
};
|
|
860
|
+
f(t);
|
|
861
|
+
const s = await (await this.caller.call(u(), `${this.apiUrl}/datasets/${t}/share`, {
|
|
862
|
+
method: "PUT",
|
|
863
|
+
headers: this.headers,
|
|
864
|
+
body: JSON.stringify(a),
|
|
865
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
866
|
+
...this.fetchOptions
|
|
867
|
+
})).json();
|
|
868
|
+
return s.url = `${this.getHostUrl()}/public/${s.share_token}/d`, s;
|
|
869
|
+
}
|
|
870
|
+
async unshareDataset(t) {
|
|
871
|
+
f(t);
|
|
872
|
+
const e = await this.caller.call(u(), `${this.apiUrl}/datasets/${t}/share`, {
|
|
873
|
+
method: "DELETE",
|
|
874
|
+
headers: this.headers,
|
|
875
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
876
|
+
...this.fetchOptions
|
|
877
|
+
});
|
|
878
|
+
await p(e, "unshare dataset", !0);
|
|
879
|
+
}
|
|
880
|
+
async readSharedDataset(t) {
|
|
881
|
+
return f(t), await (await this.caller.call(u(), `${this.apiUrl}/public/${t}/datasets`, {
|
|
882
|
+
method: "GET",
|
|
883
|
+
headers: this.headers,
|
|
884
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
885
|
+
...this.fetchOptions
|
|
886
|
+
})).json();
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Get shared examples.
|
|
890
|
+
*
|
|
891
|
+
* @param {string} shareToken The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.
|
|
892
|
+
* @param {Object} [options] Additional options for listing the examples.
|
|
893
|
+
* @param {string[] | undefined} [options.exampleIds] A list of example IDs to filter by.
|
|
894
|
+
* @returns {Promise<Example[]>} The shared examples.
|
|
895
|
+
*/
|
|
896
|
+
async listSharedExamples(t, e) {
|
|
897
|
+
const a = {};
|
|
898
|
+
e != null && e.exampleIds && (a.id = e.exampleIds);
|
|
899
|
+
const i = new URLSearchParams();
|
|
900
|
+
Object.entries(a).forEach(([o, n]) => {
|
|
901
|
+
Array.isArray(n) ? n.forEach((d) => i.append(o, d)) : i.append(o, n);
|
|
902
|
+
});
|
|
903
|
+
const s = await this.caller.call(u(), `${this.apiUrl}/public/${t}/examples?${i.toString()}`, {
|
|
904
|
+
method: "GET",
|
|
905
|
+
headers: this.headers,
|
|
906
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
907
|
+
...this.fetchOptions
|
|
908
|
+
}), r = await s.json();
|
|
909
|
+
if (!s.ok)
|
|
910
|
+
throw "detail" in r ? new Error(`Failed to list shared examples.
|
|
911
|
+
Status: ${s.status}
|
|
912
|
+
Message: ${r.detail.join(`
|
|
913
|
+
`)}`) : new Error(`Failed to list shared examples: ${s.status} ${s.statusText}`);
|
|
914
|
+
return r.map((o) => ({
|
|
915
|
+
...o,
|
|
916
|
+
_hostUrl: this.getHostUrl()
|
|
917
|
+
}));
|
|
918
|
+
}
|
|
919
|
+
async createProject({ projectName: t, description: e = null, metadata: a = null, upsert: i = !1, projectExtra: s = null, referenceDatasetId: r = null }) {
|
|
920
|
+
const o = i ? "?upsert=true" : "", n = `${this.apiUrl}/sessions${o}`, d = s || {};
|
|
921
|
+
a && (d.metadata = a);
|
|
922
|
+
const l = {
|
|
923
|
+
name: t,
|
|
924
|
+
extra: d,
|
|
925
|
+
description: e
|
|
926
|
+
};
|
|
927
|
+
r !== null && (l.reference_dataset_id = r);
|
|
928
|
+
const h = await this.caller.call(u(), n, {
|
|
929
|
+
method: "POST",
|
|
930
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
931
|
+
body: JSON.stringify(l),
|
|
932
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
933
|
+
...this.fetchOptions
|
|
934
|
+
});
|
|
935
|
+
return await p(h, "create project"), await h.json();
|
|
936
|
+
}
|
|
937
|
+
async updateProject(t, { name: e = null, description: a = null, metadata: i = null, projectExtra: s = null, endTime: r = null }) {
|
|
938
|
+
const o = `${this.apiUrl}/sessions/${t}`;
|
|
939
|
+
let n = s;
|
|
940
|
+
i && (n = { ...n || {}, metadata: i });
|
|
941
|
+
const d = {
|
|
942
|
+
name: e,
|
|
943
|
+
extra: n,
|
|
944
|
+
description: a,
|
|
945
|
+
end_time: r ? new Date(r).toISOString() : null
|
|
946
|
+
}, l = await this.caller.call(u(), o, {
|
|
947
|
+
method: "PATCH",
|
|
948
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
949
|
+
body: JSON.stringify(d),
|
|
950
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
951
|
+
...this.fetchOptions
|
|
952
|
+
});
|
|
953
|
+
return await p(l, "update project"), await l.json();
|
|
954
|
+
}
|
|
955
|
+
async hasProject({ projectId: t, projectName: e }) {
|
|
956
|
+
let a = "/sessions";
|
|
957
|
+
const i = new URLSearchParams();
|
|
958
|
+
if (t !== void 0 && e !== void 0)
|
|
959
|
+
throw new Error("Must provide either projectName or projectId, not both");
|
|
960
|
+
if (t !== void 0)
|
|
961
|
+
f(t), a += `/${t}`;
|
|
962
|
+
else if (e !== void 0)
|
|
963
|
+
i.append("name", e);
|
|
964
|
+
else
|
|
965
|
+
throw new Error("Must provide projectName or projectId");
|
|
966
|
+
const s = await this.caller.call(u(), `${this.apiUrl}${a}?${i}`, {
|
|
967
|
+
method: "GET",
|
|
968
|
+
headers: this.headers,
|
|
969
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
970
|
+
...this.fetchOptions
|
|
971
|
+
});
|
|
972
|
+
try {
|
|
973
|
+
const r = await s.json();
|
|
974
|
+
return s.ok ? Array.isArray(r) ? r.length > 0 : !0 : !1;
|
|
975
|
+
} catch {
|
|
976
|
+
return !1;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
async readProject({ projectId: t, projectName: e, includeStats: a }) {
|
|
980
|
+
let i = "/sessions";
|
|
981
|
+
const s = new URLSearchParams();
|
|
982
|
+
if (t !== void 0 && e !== void 0)
|
|
983
|
+
throw new Error("Must provide either projectName or projectId, not both");
|
|
984
|
+
if (t !== void 0)
|
|
985
|
+
f(t), i += `/${t}`;
|
|
986
|
+
else if (e !== void 0)
|
|
987
|
+
s.append("name", e);
|
|
988
|
+
else
|
|
989
|
+
throw new Error("Must provide projectName or projectId");
|
|
990
|
+
a !== void 0 && s.append("include_stats", a.toString());
|
|
991
|
+
const r = await this._get(i, s);
|
|
992
|
+
let o;
|
|
993
|
+
if (Array.isArray(r)) {
|
|
994
|
+
if (r.length === 0)
|
|
995
|
+
throw new Error(`Project[id=${t}, name=${e}] not found`);
|
|
996
|
+
o = r[0];
|
|
997
|
+
} else
|
|
998
|
+
o = r;
|
|
999
|
+
return o;
|
|
1000
|
+
}
|
|
1001
|
+
async getProjectUrl({ projectId: t, projectName: e }) {
|
|
1002
|
+
if (t === void 0 && e === void 0)
|
|
1003
|
+
throw new Error("Must provide either projectName or projectId");
|
|
1004
|
+
const a = await this.readProject({ projectId: t, projectName: e }), i = await this._getTenantId();
|
|
1005
|
+
return `${this.getHostUrl()}/o/${i}/projects/p/${a.id}`;
|
|
1006
|
+
}
|
|
1007
|
+
async getDatasetUrl({ datasetId: t, datasetName: e }) {
|
|
1008
|
+
if (t === void 0 && e === void 0)
|
|
1009
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
1010
|
+
const a = await this.readDataset({ datasetId: t, datasetName: e }), i = await this._getTenantId();
|
|
1011
|
+
return `${this.getHostUrl()}/o/${i}/datasets/${a.id}`;
|
|
1012
|
+
}
|
|
1013
|
+
async _getTenantId() {
|
|
1014
|
+
if (this._tenantId !== null)
|
|
1015
|
+
return this._tenantId;
|
|
1016
|
+
const t = new URLSearchParams({ limit: "1" });
|
|
1017
|
+
for await (const e of this._getPaginated("/sessions", t))
|
|
1018
|
+
return this._tenantId = e[0].tenant_id, e[0].tenant_id;
|
|
1019
|
+
throw new Error("No projects found to resolve tenant.");
|
|
1020
|
+
}
|
|
1021
|
+
async *listProjects({ projectIds: t, name: e, nameContains: a, referenceDatasetId: i, referenceDatasetName: s, referenceFree: r, metadata: o } = {}) {
|
|
1022
|
+
const n = new URLSearchParams();
|
|
1023
|
+
if (t !== void 0)
|
|
1024
|
+
for (const d of t)
|
|
1025
|
+
n.append("id", d);
|
|
1026
|
+
if (e !== void 0 && n.append("name", e), a !== void 0 && n.append("name_contains", a), i !== void 0)
|
|
1027
|
+
n.append("reference_dataset", i);
|
|
1028
|
+
else if (s !== void 0) {
|
|
1029
|
+
const d = await this.readDataset({
|
|
1030
|
+
datasetName: s
|
|
1031
|
+
});
|
|
1032
|
+
n.append("reference_dataset", d.id);
|
|
1033
|
+
}
|
|
1034
|
+
r !== void 0 && n.append("reference_free", r.toString()), o !== void 0 && n.append("metadata", JSON.stringify(o));
|
|
1035
|
+
for await (const d of this._getPaginated("/sessions", n))
|
|
1036
|
+
yield* d;
|
|
1037
|
+
}
|
|
1038
|
+
async deleteProject({ projectId: t, projectName: e }) {
|
|
1039
|
+
let a;
|
|
1040
|
+
if (t === void 0 && e === void 0)
|
|
1041
|
+
throw new Error("Must provide projectName or projectId");
|
|
1042
|
+
if (t !== void 0 && e !== void 0)
|
|
1043
|
+
throw new Error("Must provide either projectName or projectId, not both");
|
|
1044
|
+
t === void 0 ? a = (await this.readProject({ projectName: e })).id : a = t, f(a);
|
|
1045
|
+
const i = await this.caller.call(u(), `${this.apiUrl}/sessions/${a}`, {
|
|
1046
|
+
method: "DELETE",
|
|
1047
|
+
headers: this.headers,
|
|
1048
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1049
|
+
...this.fetchOptions
|
|
1050
|
+
});
|
|
1051
|
+
await p(i, `delete session ${a} (${e})`, !0);
|
|
1052
|
+
}
|
|
1053
|
+
async uploadCsv({ csvFile: t, fileName: e, inputKeys: a, outputKeys: i, description: s, dataType: r, name: o }) {
|
|
1054
|
+
const n = `${this.apiUrl}/datasets/upload`, d = new FormData();
|
|
1055
|
+
d.append("file", t, e), a.forEach((c) => {
|
|
1056
|
+
d.append("input_keys", c);
|
|
1057
|
+
}), i.forEach((c) => {
|
|
1058
|
+
d.append("output_keys", c);
|
|
1059
|
+
}), s && d.append("description", s), r && d.append("data_type", r), o && d.append("name", o);
|
|
1060
|
+
const l = await this.caller.call(u(), n, {
|
|
1061
|
+
method: "POST",
|
|
1062
|
+
headers: this.headers,
|
|
1063
|
+
body: d,
|
|
1064
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1065
|
+
...this.fetchOptions
|
|
1066
|
+
});
|
|
1067
|
+
return await p(l, "upload CSV"), await l.json();
|
|
1068
|
+
}
|
|
1069
|
+
async createDataset(t, { description: e, dataType: a, inputsSchema: i, outputsSchema: s, metadata: r } = {}) {
|
|
1070
|
+
const o = {
|
|
1071
|
+
name: t,
|
|
1072
|
+
description: e,
|
|
1073
|
+
extra: r ? { metadata: r } : void 0
|
|
1074
|
+
};
|
|
1075
|
+
a && (o.data_type = a), i && (o.inputs_schema_definition = i), s && (o.outputs_schema_definition = s);
|
|
1076
|
+
const n = await this.caller.call(u(), `${this.apiUrl}/datasets`, {
|
|
1077
|
+
method: "POST",
|
|
1078
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1079
|
+
body: JSON.stringify(o),
|
|
1080
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1081
|
+
...this.fetchOptions
|
|
1082
|
+
});
|
|
1083
|
+
return await p(n, "create dataset"), await n.json();
|
|
1084
|
+
}
|
|
1085
|
+
async readDataset({ datasetId: t, datasetName: e }) {
|
|
1086
|
+
let a = "/datasets";
|
|
1087
|
+
const i = new URLSearchParams({ limit: "1" });
|
|
1088
|
+
if (t !== void 0 && e !== void 0)
|
|
1089
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1090
|
+
if (t !== void 0)
|
|
1091
|
+
f(t), a += `/${t}`;
|
|
1092
|
+
else if (e !== void 0)
|
|
1093
|
+
i.append("name", e);
|
|
1094
|
+
else
|
|
1095
|
+
throw new Error("Must provide datasetName or datasetId");
|
|
1096
|
+
const s = await this._get(a, i);
|
|
1097
|
+
let r;
|
|
1098
|
+
if (Array.isArray(s)) {
|
|
1099
|
+
if (s.length === 0)
|
|
1100
|
+
throw new Error(`Dataset[id=${t}, name=${e}] not found`);
|
|
1101
|
+
r = s[0];
|
|
1102
|
+
} else
|
|
1103
|
+
r = s;
|
|
1104
|
+
return r;
|
|
1105
|
+
}
|
|
1106
|
+
async hasDataset({ datasetId: t, datasetName: e }) {
|
|
1107
|
+
try {
|
|
1108
|
+
return await this.readDataset({ datasetId: t, datasetName: e }), !0;
|
|
1109
|
+
} catch (a) {
|
|
1110
|
+
if (
|
|
1111
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
1112
|
+
a instanceof Error && a.message.toLocaleLowerCase().includes("not found")
|
|
1113
|
+
)
|
|
1114
|
+
return !1;
|
|
1115
|
+
throw a;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
async diffDatasetVersions({ datasetId: t, datasetName: e, fromVersion: a, toVersion: i }) {
|
|
1119
|
+
let s = t;
|
|
1120
|
+
if (s === void 0 && e === void 0)
|
|
1121
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
1122
|
+
if (s !== void 0 && e !== void 0)
|
|
1123
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1124
|
+
s === void 0 && (s = (await this.readDataset({ datasetName: e })).id);
|
|
1125
|
+
const r = new URLSearchParams({
|
|
1126
|
+
from_version: typeof a == "string" ? a : a.toISOString(),
|
|
1127
|
+
to_version: typeof i == "string" ? i : i.toISOString()
|
|
1128
|
+
});
|
|
1129
|
+
return await this._get(`/datasets/${s}/versions/diff`, r);
|
|
1130
|
+
}
|
|
1131
|
+
async readDatasetOpenaiFinetuning({ datasetId: t, datasetName: e }) {
|
|
1132
|
+
const a = "/datasets";
|
|
1133
|
+
if (t === void 0) if (e !== void 0)
|
|
1134
|
+
t = (await this.readDataset({ datasetName: e })).id;
|
|
1135
|
+
else
|
|
1136
|
+
throw new Error("Must provide datasetName or datasetId");
|
|
1137
|
+
return (await (await this._getResponse(`${a}/${t}/openai_ft`)).text()).trim().split(`
|
|
1138
|
+
`).map((o) => JSON.parse(o));
|
|
1139
|
+
}
|
|
1140
|
+
async *listDatasets({ limit: t = 100, offset: e = 0, datasetIds: a, datasetName: i, datasetNameContains: s, metadata: r } = {}) {
|
|
1141
|
+
const o = "/datasets", n = new URLSearchParams({
|
|
1142
|
+
limit: t.toString(),
|
|
1143
|
+
offset: e.toString()
|
|
1144
|
+
});
|
|
1145
|
+
if (a !== void 0)
|
|
1146
|
+
for (const d of a)
|
|
1147
|
+
n.append("id", d);
|
|
1148
|
+
i !== void 0 && n.append("name", i), s !== void 0 && n.append("name_contains", s), r !== void 0 && n.append("metadata", JSON.stringify(r));
|
|
1149
|
+
for await (const d of this._getPaginated(o, n))
|
|
1150
|
+
yield* d;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Update a dataset
|
|
1154
|
+
* @param props The dataset details to update
|
|
1155
|
+
* @returns The updated dataset
|
|
1156
|
+
*/
|
|
1157
|
+
async updateDataset(t) {
|
|
1158
|
+
const { datasetId: e, datasetName: a, ...i } = t;
|
|
1159
|
+
if (!e && !a)
|
|
1160
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
1161
|
+
const s = e ?? (await this.readDataset({ datasetName: a })).id;
|
|
1162
|
+
f(s);
|
|
1163
|
+
const r = await this.caller.call(u(), `${this.apiUrl}/datasets/${s}`, {
|
|
1164
|
+
method: "PATCH",
|
|
1165
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1166
|
+
body: JSON.stringify(i),
|
|
1167
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1168
|
+
...this.fetchOptions
|
|
1169
|
+
});
|
|
1170
|
+
return await p(r, "update dataset"), await r.json();
|
|
1171
|
+
}
|
|
1172
|
+
async deleteDataset({ datasetId: t, datasetName: e }) {
|
|
1173
|
+
let a = "/datasets", i = t;
|
|
1174
|
+
if (t !== void 0 && e !== void 0)
|
|
1175
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1176
|
+
if (e !== void 0 && (i = (await this.readDataset({ datasetName: e })).id), i !== void 0)
|
|
1177
|
+
f(i), a += `/${i}`;
|
|
1178
|
+
else
|
|
1179
|
+
throw new Error("Must provide datasetName or datasetId");
|
|
1180
|
+
const s = await this.caller.call(u(), this.apiUrl + a, {
|
|
1181
|
+
method: "DELETE",
|
|
1182
|
+
headers: this.headers,
|
|
1183
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1184
|
+
...this.fetchOptions
|
|
1185
|
+
});
|
|
1186
|
+
await p(s, `delete ${a}`), await s.json();
|
|
1187
|
+
}
|
|
1188
|
+
async indexDataset({ datasetId: t, datasetName: e, tag: a }) {
|
|
1189
|
+
let i = t;
|
|
1190
|
+
if (!i && !e)
|
|
1191
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
1192
|
+
if (i && e)
|
|
1193
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1194
|
+
i || (i = (await this.readDataset({ datasetName: e })).id), f(i);
|
|
1195
|
+
const s = {
|
|
1196
|
+
tag: a
|
|
1197
|
+
}, r = await this.caller.call(u(), `${this.apiUrl}/datasets/${i}/index`, {
|
|
1198
|
+
method: "POST",
|
|
1199
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1200
|
+
body: JSON.stringify(s),
|
|
1201
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1202
|
+
...this.fetchOptions
|
|
1203
|
+
});
|
|
1204
|
+
await p(r, "index dataset"), await r.json();
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Lets you run a similarity search query on a dataset.
|
|
1208
|
+
*
|
|
1209
|
+
* Requires the dataset to be indexed. Please see the `indexDataset` method to set up indexing.
|
|
1210
|
+
*
|
|
1211
|
+
* @param inputs The input on which to run the similarity search. Must have the
|
|
1212
|
+
* same schema as the dataset.
|
|
1213
|
+
*
|
|
1214
|
+
* @param datasetId The dataset to search for similar examples.
|
|
1215
|
+
*
|
|
1216
|
+
* @param limit The maximum number of examples to return. Will return the top `limit` most
|
|
1217
|
+
* similar examples in order of most similar to least similar. If no similar
|
|
1218
|
+
* examples are found, random examples will be returned.
|
|
1219
|
+
*
|
|
1220
|
+
* @param filter A filter string to apply to the search. Only examples will be returned that
|
|
1221
|
+
* match the filter string. Some examples of filters
|
|
1222
|
+
*
|
|
1223
|
+
* - eq(metadata.mykey, "value")
|
|
1224
|
+
* - and(neq(metadata.my.nested.key, "value"), neq(metadata.mykey, "value"))
|
|
1225
|
+
* - or(eq(metadata.mykey, "value"), eq(metadata.mykey, "othervalue"))
|
|
1226
|
+
*
|
|
1227
|
+
* @returns A list of similar examples.
|
|
1228
|
+
*
|
|
1229
|
+
*
|
|
1230
|
+
* @example
|
|
1231
|
+
* dataset_id = "123e4567-e89b-12d3-a456-426614174000"
|
|
1232
|
+
* inputs = {"text": "How many people live in Berlin?"}
|
|
1233
|
+
* limit = 5
|
|
1234
|
+
* examples = await client.similarExamples(inputs, dataset_id, limit)
|
|
1235
|
+
*/
|
|
1236
|
+
async similarExamples(t, e, a, { filter: i } = {}) {
|
|
1237
|
+
const s = {
|
|
1238
|
+
limit: a,
|
|
1239
|
+
inputs: t
|
|
1240
|
+
};
|
|
1241
|
+
i !== void 0 && (s.filter = i), f(e);
|
|
1242
|
+
const r = await this.caller.call(u(), `${this.apiUrl}/datasets/${e}/search`, {
|
|
1243
|
+
method: "POST",
|
|
1244
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1245
|
+
body: JSON.stringify(s),
|
|
1246
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1247
|
+
...this.fetchOptions
|
|
1248
|
+
});
|
|
1249
|
+
return await p(r, "fetch similar examples"), (await r.json()).examples;
|
|
1250
|
+
}
|
|
1251
|
+
async createExample(t, e, { datasetId: a, datasetName: i, createdAt: s, exampleId: r, metadata: o, split: n, sourceRunId: d }) {
|
|
1252
|
+
let l = a;
|
|
1253
|
+
if (l === void 0 && i === void 0)
|
|
1254
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
1255
|
+
if (l !== void 0 && i !== void 0)
|
|
1256
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1257
|
+
l === void 0 && (l = (await this.readDataset({ datasetName: i })).id);
|
|
1258
|
+
const h = s || /* @__PURE__ */ new Date(), c = {
|
|
1259
|
+
dataset_id: l,
|
|
1260
|
+
inputs: t,
|
|
1261
|
+
outputs: e,
|
|
1262
|
+
created_at: h == null ? void 0 : h.toISOString(),
|
|
1263
|
+
id: r,
|
|
1264
|
+
metadata: o,
|
|
1265
|
+
split: n,
|
|
1266
|
+
source_run_id: d
|
|
1267
|
+
}, _ = await this.caller.call(u(), `${this.apiUrl}/examples`, {
|
|
1268
|
+
method: "POST",
|
|
1269
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1270
|
+
body: JSON.stringify(c),
|
|
1271
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1272
|
+
...this.fetchOptions
|
|
1273
|
+
});
|
|
1274
|
+
return await p(_, "create example"), await _.json();
|
|
1275
|
+
}
|
|
1276
|
+
async createExamples(t) {
|
|
1277
|
+
const { inputs: e, outputs: a, metadata: i, sourceRunIds: s, exampleIds: r, datasetId: o, datasetName: n } = t;
|
|
1278
|
+
let d = o;
|
|
1279
|
+
if (d === void 0 && n === void 0)
|
|
1280
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
1281
|
+
if (d !== void 0 && n !== void 0)
|
|
1282
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1283
|
+
d === void 0 && (d = (await this.readDataset({ datasetName: n })).id);
|
|
1284
|
+
const l = e.map((_, m) => ({
|
|
1285
|
+
dataset_id: d,
|
|
1286
|
+
inputs: _,
|
|
1287
|
+
outputs: a ? a[m] : void 0,
|
|
1288
|
+
metadata: i ? i[m] : void 0,
|
|
1289
|
+
split: t.splits ? t.splits[m] : void 0,
|
|
1290
|
+
id: r ? r[m] : void 0,
|
|
1291
|
+
source_run_id: s ? s[m] : void 0
|
|
1292
|
+
})), h = await this.caller.call(u(), `${this.apiUrl}/examples/bulk`, {
|
|
1293
|
+
method: "POST",
|
|
1294
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1295
|
+
body: JSON.stringify(l),
|
|
1296
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1297
|
+
...this.fetchOptions
|
|
1298
|
+
});
|
|
1299
|
+
return await p(h, "create examples"), await h.json();
|
|
1300
|
+
}
|
|
1301
|
+
async createLLMExample(t, e, a) {
|
|
1302
|
+
return this.createExample({ input: t }, { output: e }, a);
|
|
1303
|
+
}
|
|
1304
|
+
async createChatExample(t, e, a) {
|
|
1305
|
+
const i = t.map((r) => N(r) ? x(r) : r), s = N(e) ? x(e) : e;
|
|
1306
|
+
return this.createExample({ input: i }, { output: s }, a);
|
|
1307
|
+
}
|
|
1308
|
+
async readExample(t) {
|
|
1309
|
+
f(t);
|
|
1310
|
+
const e = `/examples/${t}`;
|
|
1311
|
+
return await this._get(e);
|
|
1312
|
+
}
|
|
1313
|
+
async *listExamples({ datasetId: t, datasetName: e, exampleIds: a, asOf: i, splits: s, inlineS3Urls: r, metadata: o, limit: n, offset: d, filter: l } = {}) {
|
|
1314
|
+
let h;
|
|
1315
|
+
if (t !== void 0 && e !== void 0)
|
|
1316
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1317
|
+
if (t !== void 0)
|
|
1318
|
+
h = t;
|
|
1319
|
+
else if (e !== void 0)
|
|
1320
|
+
h = (await this.readDataset({ datasetName: e })).id;
|
|
1321
|
+
else
|
|
1322
|
+
throw new Error("Must provide a datasetName or datasetId");
|
|
1323
|
+
const c = new URLSearchParams({ dataset: h }), _ = i ? typeof i == "string" ? i : i == null ? void 0 : i.toISOString() : void 0;
|
|
1324
|
+
_ && c.append("as_of", _);
|
|
1325
|
+
const m = r ?? !0;
|
|
1326
|
+
if (c.append("inline_s3_urls", m.toString()), a !== void 0)
|
|
1327
|
+
for (const w of a)
|
|
1328
|
+
c.append("id", w);
|
|
1329
|
+
if (s !== void 0)
|
|
1330
|
+
for (const w of s)
|
|
1331
|
+
c.append("splits", w);
|
|
1332
|
+
if (o !== void 0) {
|
|
1333
|
+
const w = JSON.stringify(o);
|
|
1334
|
+
c.append("metadata", w);
|
|
1335
|
+
}
|
|
1336
|
+
n !== void 0 && c.append("limit", n.toString()), d !== void 0 && c.append("offset", d.toString()), l !== void 0 && c.append("filter", l);
|
|
1337
|
+
let b = 0;
|
|
1338
|
+
for await (const w of this._getPaginated("/examples", c)) {
|
|
1339
|
+
for (const y of w)
|
|
1340
|
+
yield y, b++;
|
|
1341
|
+
if (n !== void 0 && b >= n)
|
|
1342
|
+
break;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
async deleteExample(t) {
|
|
1346
|
+
f(t);
|
|
1347
|
+
const e = `/examples/${t}`, a = await this.caller.call(u(), this.apiUrl + e, {
|
|
1348
|
+
method: "DELETE",
|
|
1349
|
+
headers: this.headers,
|
|
1350
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1351
|
+
...this.fetchOptions
|
|
1352
|
+
});
|
|
1353
|
+
await p(a, `delete ${e}`), await a.json();
|
|
1354
|
+
}
|
|
1355
|
+
async updateExample(t, e) {
|
|
1356
|
+
f(t);
|
|
1357
|
+
const a = await this.caller.call(u(), `${this.apiUrl}/examples/${t}`, {
|
|
1358
|
+
method: "PATCH",
|
|
1359
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1360
|
+
body: JSON.stringify(e),
|
|
1361
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1362
|
+
...this.fetchOptions
|
|
1363
|
+
});
|
|
1364
|
+
return await p(a, "update example"), await a.json();
|
|
1365
|
+
}
|
|
1366
|
+
async updateExamples(t) {
|
|
1367
|
+
const e = await this.caller.call(u(), `${this.apiUrl}/examples/bulk`, {
|
|
1368
|
+
method: "PATCH",
|
|
1369
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1370
|
+
body: JSON.stringify(t),
|
|
1371
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1372
|
+
...this.fetchOptions
|
|
1373
|
+
});
|
|
1374
|
+
return await p(e, "update examples"), await e.json();
|
|
1375
|
+
}
|
|
1376
|
+
async listDatasetSplits({ datasetId: t, datasetName: e, asOf: a }) {
|
|
1377
|
+
let i;
|
|
1378
|
+
if (t === void 0 && e === void 0)
|
|
1379
|
+
throw new Error("Must provide dataset name or ID");
|
|
1380
|
+
if (t !== void 0 && e !== void 0)
|
|
1381
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1382
|
+
t === void 0 ? i = (await this.readDataset({ datasetName: e })).id : i = t, f(i);
|
|
1383
|
+
const s = new URLSearchParams(), r = a ? typeof a == "string" ? a : a == null ? void 0 : a.toISOString() : void 0;
|
|
1384
|
+
return r && s.append("as_of", r), await this._get(`/datasets/${i}/splits`, s);
|
|
1385
|
+
}
|
|
1386
|
+
async updateDatasetSplits({ datasetId: t, datasetName: e, splitName: a, exampleIds: i, remove: s = !1 }) {
|
|
1387
|
+
let r;
|
|
1388
|
+
if (t === void 0 && e === void 0)
|
|
1389
|
+
throw new Error("Must provide dataset name or ID");
|
|
1390
|
+
if (t !== void 0 && e !== void 0)
|
|
1391
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
1392
|
+
t === void 0 ? r = (await this.readDataset({ datasetName: e })).id : r = t, f(r);
|
|
1393
|
+
const o = {
|
|
1394
|
+
split_name: a,
|
|
1395
|
+
examples: i.map((d) => (f(d), d)),
|
|
1396
|
+
remove: s
|
|
1397
|
+
}, n = await this.caller.call(u(), `${this.apiUrl}/datasets/${r}/splits`, {
|
|
1398
|
+
method: "PUT",
|
|
1399
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1400
|
+
body: JSON.stringify(o),
|
|
1401
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1402
|
+
...this.fetchOptions
|
|
1403
|
+
});
|
|
1404
|
+
await p(n, "update dataset splits", !0);
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
|
|
1408
|
+
*/
|
|
1409
|
+
async evaluateRun(t, e, { sourceInfo: a, loadChildRuns: i, referenceExample: s } = { loadChildRuns: !1 }) {
|
|
1410
|
+
J("This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.");
|
|
1411
|
+
let r;
|
|
1412
|
+
if (typeof t == "string")
|
|
1413
|
+
r = await this.readRun(t, { loadChildRuns: i });
|
|
1414
|
+
else if (typeof t == "object" && "id" in t)
|
|
1415
|
+
r = t;
|
|
1416
|
+
else
|
|
1417
|
+
throw new Error(`Invalid run type: ${typeof t}`);
|
|
1418
|
+
r.reference_example_id !== null && r.reference_example_id !== void 0 && (s = await this.readExample(r.reference_example_id));
|
|
1419
|
+
const o = await e.evaluateRun(r, s), [n, d] = await this._logEvaluationFeedback(o, r, a);
|
|
1420
|
+
return d[0];
|
|
1421
|
+
}
|
|
1422
|
+
async createFeedback(t, e, { score: a, value: i, correction: s, comment: r, sourceInfo: o, feedbackSourceType: n = "api", sourceRunId: d, feedbackId: l, feedbackConfig: h, projectId: c, comparativeExperimentId: _ }) {
|
|
1423
|
+
var U;
|
|
1424
|
+
if (!t && !c)
|
|
1425
|
+
throw new Error("One of runId or projectId must be provided");
|
|
1426
|
+
if (t && c)
|
|
1427
|
+
throw new Error("Only one of runId or projectId can be provided");
|
|
1428
|
+
const m = {
|
|
1429
|
+
type: n ?? "api",
|
|
1430
|
+
metadata: o ?? {}
|
|
1431
|
+
};
|
|
1432
|
+
d !== void 0 && (m == null ? void 0 : m.metadata) !== void 0 && !m.metadata.__run && (m.metadata.__run = { run_id: d }), (m == null ? void 0 : m.metadata) !== void 0 && ((U = m.metadata.__run) == null ? void 0 : U.run_id) !== void 0 && f(m.metadata.__run.run_id);
|
|
1433
|
+
const b = {
|
|
1434
|
+
id: l ?? R(),
|
|
1435
|
+
run_id: t,
|
|
1436
|
+
key: e,
|
|
1437
|
+
score: a,
|
|
1438
|
+
value: i,
|
|
1439
|
+
correction: s,
|
|
1440
|
+
comment: r,
|
|
1441
|
+
feedback_source: m,
|
|
1442
|
+
comparative_experiment_id: _,
|
|
1443
|
+
feedbackConfig: h,
|
|
1444
|
+
session_id: c
|
|
1445
|
+
}, w = `${this.apiUrl}/feedback`, y = await this.caller.call(u(), w, {
|
|
1446
|
+
method: "POST",
|
|
1447
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1448
|
+
body: JSON.stringify(b),
|
|
1449
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1450
|
+
...this.fetchOptions
|
|
1451
|
+
});
|
|
1452
|
+
return await p(y, "create feedback", !0), b;
|
|
1453
|
+
}
|
|
1454
|
+
async updateFeedback(t, { score: e, value: a, correction: i, comment: s }) {
|
|
1455
|
+
const r = {};
|
|
1456
|
+
e != null && (r.score = e), a != null && (r.value = a), i != null && (r.correction = i), s != null && (r.comment = s), f(t);
|
|
1457
|
+
const o = await this.caller.call(u(), `${this.apiUrl}/feedback/${t}`, {
|
|
1458
|
+
method: "PATCH",
|
|
1459
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1460
|
+
body: JSON.stringify(r),
|
|
1461
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1462
|
+
...this.fetchOptions
|
|
1463
|
+
});
|
|
1464
|
+
await p(o, "update feedback", !0);
|
|
1465
|
+
}
|
|
1466
|
+
async readFeedback(t) {
|
|
1467
|
+
f(t);
|
|
1468
|
+
const e = `/feedback/${t}`;
|
|
1469
|
+
return await this._get(e);
|
|
1470
|
+
}
|
|
1471
|
+
async deleteFeedback(t) {
|
|
1472
|
+
f(t);
|
|
1473
|
+
const e = `/feedback/${t}`, a = await this.caller.call(u(), this.apiUrl + e, {
|
|
1474
|
+
method: "DELETE",
|
|
1475
|
+
headers: this.headers,
|
|
1476
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1477
|
+
...this.fetchOptions
|
|
1478
|
+
});
|
|
1479
|
+
await p(a, `delete ${e}`), await a.json();
|
|
1480
|
+
}
|
|
1481
|
+
async *listFeedback({ runIds: t, feedbackKeys: e, feedbackSourceTypes: a } = {}) {
|
|
1482
|
+
const i = new URLSearchParams();
|
|
1483
|
+
if (t && i.append("run", t.join(",")), e)
|
|
1484
|
+
for (const s of e)
|
|
1485
|
+
i.append("key", s);
|
|
1486
|
+
if (a)
|
|
1487
|
+
for (const s of a)
|
|
1488
|
+
i.append("source", s);
|
|
1489
|
+
for await (const s of this._getPaginated("/feedback", i))
|
|
1490
|
+
yield* s;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Creates a presigned feedback token and URL.
|
|
1494
|
+
*
|
|
1495
|
+
* The token can be used to authorize feedback metrics without
|
|
1496
|
+
* needing an API key. This is useful for giving browser-based
|
|
1497
|
+
* applications the ability to submit feedback without needing
|
|
1498
|
+
* to expose an API key.
|
|
1499
|
+
*
|
|
1500
|
+
* @param runId - The ID of the run.
|
|
1501
|
+
* @param feedbackKey - The feedback key.
|
|
1502
|
+
* @param options - Additional options for the token.
|
|
1503
|
+
* @param options.expiration - The expiration time for the token.
|
|
1504
|
+
*
|
|
1505
|
+
* @returns A promise that resolves to a FeedbackIngestToken.
|
|
1506
|
+
*/
|
|
1507
|
+
async createPresignedFeedbackToken(t, e, { expiration: a, feedbackConfig: i } = {}) {
|
|
1508
|
+
const s = {
|
|
1509
|
+
run_id: t,
|
|
1510
|
+
feedback_key: e,
|
|
1511
|
+
feedback_config: i
|
|
1512
|
+
};
|
|
1513
|
+
return a ? typeof a == "string" ? s.expires_at = a : (a != null && a.hours || a != null && a.minutes || a != null && a.days) && (s.expires_in = a) : s.expires_in = {
|
|
1514
|
+
hours: 3
|
|
1515
|
+
}, await (await this.caller.call(u(), `${this.apiUrl}/feedback/tokens`, {
|
|
1516
|
+
method: "POST",
|
|
1517
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1518
|
+
body: JSON.stringify(s),
|
|
1519
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1520
|
+
...this.fetchOptions
|
|
1521
|
+
})).json();
|
|
1522
|
+
}
|
|
1523
|
+
async createComparativeExperiment({ name: t, experimentIds: e, referenceDatasetId: a, createdAt: i, description: s, metadata: r, id: o }) {
|
|
1524
|
+
var l;
|
|
1525
|
+
if (e.length === 0)
|
|
1526
|
+
throw new Error("At least one experiment is required");
|
|
1527
|
+
if (a || (a = (await this.readProject({
|
|
1528
|
+
projectId: e[0]
|
|
1529
|
+
})).reference_dataset_id), !a == null)
|
|
1530
|
+
throw new Error("A reference dataset is required");
|
|
1531
|
+
const n = {
|
|
1532
|
+
id: o,
|
|
1533
|
+
name: t,
|
|
1534
|
+
experiment_ids: e,
|
|
1535
|
+
reference_dataset_id: a,
|
|
1536
|
+
description: s,
|
|
1537
|
+
created_at: (l = i ?? /* @__PURE__ */ new Date()) == null ? void 0 : l.toISOString(),
|
|
1538
|
+
extra: {}
|
|
1539
|
+
};
|
|
1540
|
+
return r && (n.extra.metadata = r), await (await this.caller.call(u(), `${this.apiUrl}/datasets/comparative`, {
|
|
1541
|
+
method: "POST",
|
|
1542
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1543
|
+
body: JSON.stringify(n),
|
|
1544
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1545
|
+
...this.fetchOptions
|
|
1546
|
+
})).json();
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Retrieves a list of presigned feedback tokens for a given run ID.
|
|
1550
|
+
* @param runId The ID of the run.
|
|
1551
|
+
* @returns An async iterable of FeedbackIngestToken objects.
|
|
1552
|
+
*/
|
|
1553
|
+
async *listPresignedFeedbackTokens(t) {
|
|
1554
|
+
f(t);
|
|
1555
|
+
const e = new URLSearchParams({ run_id: t });
|
|
1556
|
+
for await (const a of this._getPaginated("/feedback/tokens", e))
|
|
1557
|
+
yield* a;
|
|
1558
|
+
}
|
|
1559
|
+
_selectEvalResults(t) {
|
|
1560
|
+
let e;
|
|
1561
|
+
return "results" in t ? e = t.results : e = [t], e;
|
|
1562
|
+
}
|
|
1563
|
+
async _logEvaluationFeedback(t, e, a) {
|
|
1564
|
+
const i = this._selectEvalResults(t), s = [];
|
|
1565
|
+
for (const r of i) {
|
|
1566
|
+
let o = a || {};
|
|
1567
|
+
r.evaluatorInfo && (o = { ...r.evaluatorInfo, ...o });
|
|
1568
|
+
let n = null;
|
|
1569
|
+
r.targetRunId ? n = r.targetRunId : e && (n = e.id), s.push(await this.createFeedback(n, r.key, {
|
|
1570
|
+
score: r.score,
|
|
1571
|
+
value: r.value,
|
|
1572
|
+
comment: r.comment,
|
|
1573
|
+
correction: r.correction,
|
|
1574
|
+
sourceInfo: o,
|
|
1575
|
+
sourceRunId: r.sourceRunId,
|
|
1576
|
+
feedbackConfig: r.feedbackConfig,
|
|
1577
|
+
feedbackSourceType: "model"
|
|
1578
|
+
}));
|
|
1579
|
+
}
|
|
1580
|
+
return [i, s];
|
|
1581
|
+
}
|
|
1582
|
+
async logEvaluationFeedback(t, e, a) {
|
|
1583
|
+
const [i] = await this._logEvaluationFeedback(t, e, a);
|
|
1584
|
+
return i;
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* API for managing annotation queues
|
|
1588
|
+
*/
|
|
1589
|
+
/**
|
|
1590
|
+
* List the annotation queues on the LangSmith API.
|
|
1591
|
+
* @param options - The options for listing annotation queues
|
|
1592
|
+
* @param options.queueIds - The IDs of the queues to filter by
|
|
1593
|
+
* @param options.name - The name of the queue to filter by
|
|
1594
|
+
* @param options.nameContains - The substring that the queue name should contain
|
|
1595
|
+
* @param options.limit - The maximum number of queues to return
|
|
1596
|
+
* @returns An iterator of AnnotationQueue objects
|
|
1597
|
+
*/
|
|
1598
|
+
async *listAnnotationQueues(t = {}) {
|
|
1599
|
+
const { queueIds: e, name: a, nameContains: i, limit: s } = t, r = new URLSearchParams();
|
|
1600
|
+
e && e.forEach((n, d) => {
|
|
1601
|
+
f(n, `queueIds[${d}]`), r.append("ids", n);
|
|
1602
|
+
}), a && r.append("name", a), i && r.append("name_contains", i), r.append("limit", (s !== void 0 ? Math.min(s, 100) : 100).toString());
|
|
1603
|
+
let o = 0;
|
|
1604
|
+
for await (const n of this._getPaginated("/annotation-queues", r))
|
|
1605
|
+
if (yield* n, o++, s !== void 0 && o >= s)
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Create an annotation queue on the LangSmith API.
|
|
1610
|
+
* @param options - The options for creating an annotation queue
|
|
1611
|
+
* @param options.name - The name of the annotation queue
|
|
1612
|
+
* @param options.description - The description of the annotation queue
|
|
1613
|
+
* @param options.queueId - The ID of the annotation queue
|
|
1614
|
+
* @returns The created AnnotationQueue object
|
|
1615
|
+
*/
|
|
1616
|
+
async createAnnotationQueue(t) {
|
|
1617
|
+
const { name: e, description: a, queueId: i } = t, s = {
|
|
1618
|
+
name: e,
|
|
1619
|
+
description: a,
|
|
1620
|
+
id: i || R()
|
|
1621
|
+
}, r = await this.caller.call(u(), `${this.apiUrl}/annotation-queues`, {
|
|
1622
|
+
method: "POST",
|
|
1623
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1624
|
+
body: JSON.stringify(Object.fromEntries(Object.entries(s).filter(([n, d]) => d !== void 0))),
|
|
1625
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1626
|
+
...this.fetchOptions
|
|
1627
|
+
});
|
|
1628
|
+
return await p(r, "create annotation queue"), await r.json();
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Read an annotation queue with the specified queue ID.
|
|
1632
|
+
* @param queueId - The ID of the annotation queue to read
|
|
1633
|
+
* @returns The AnnotationQueue object
|
|
1634
|
+
*/
|
|
1635
|
+
async readAnnotationQueue(t) {
|
|
1636
|
+
const e = await this.listAnnotationQueues({
|
|
1637
|
+
queueIds: [t]
|
|
1638
|
+
}).next();
|
|
1639
|
+
if (e.done)
|
|
1640
|
+
throw new Error(`Annotation queue with ID ${t} not found`);
|
|
1641
|
+
return e.value;
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Update an annotation queue with the specified queue ID.
|
|
1645
|
+
* @param queueId - The ID of the annotation queue to update
|
|
1646
|
+
* @param options - The options for updating the annotation queue
|
|
1647
|
+
* @param options.name - The new name for the annotation queue
|
|
1648
|
+
* @param options.description - The new description for the annotation queue
|
|
1649
|
+
*/
|
|
1650
|
+
async updateAnnotationQueue(t, e) {
|
|
1651
|
+
const { name: a, description: i } = e, s = await this.caller.call(u(), `${this.apiUrl}/annotation-queues/${f(t, "queueId")}`, {
|
|
1652
|
+
method: "PATCH",
|
|
1653
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1654
|
+
body: JSON.stringify({ name: a, description: i }),
|
|
1655
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1656
|
+
...this.fetchOptions
|
|
1657
|
+
});
|
|
1658
|
+
await p(s, "update annotation queue");
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Delete an annotation queue with the specified queue ID.
|
|
1662
|
+
* @param queueId - The ID of the annotation queue to delete
|
|
1663
|
+
*/
|
|
1664
|
+
async deleteAnnotationQueue(t) {
|
|
1665
|
+
const e = await this.caller.call(u(), `${this.apiUrl}/annotation-queues/${f(t, "queueId")}`, {
|
|
1666
|
+
method: "DELETE",
|
|
1667
|
+
headers: { ...this.headers, Accept: "application/json" },
|
|
1668
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1669
|
+
...this.fetchOptions
|
|
1670
|
+
});
|
|
1671
|
+
await p(e, "delete annotation queue");
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Add runs to an annotation queue with the specified queue ID.
|
|
1675
|
+
* @param queueId - The ID of the annotation queue
|
|
1676
|
+
* @param runIds - The IDs of the runs to be added to the annotation queue
|
|
1677
|
+
*/
|
|
1678
|
+
async addRunsToAnnotationQueue(t, e) {
|
|
1679
|
+
const a = await this.caller.call(u(), `${this.apiUrl}/annotation-queues/${f(t, "queueId")}/runs`, {
|
|
1680
|
+
method: "POST",
|
|
1681
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1682
|
+
body: JSON.stringify(e.map((i, s) => f(i, `runIds[${s}]`).toString())),
|
|
1683
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1684
|
+
...this.fetchOptions
|
|
1685
|
+
});
|
|
1686
|
+
await p(a, "add runs to annotation queue");
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Get a run from an annotation queue at the specified index.
|
|
1690
|
+
* @param queueId - The ID of the annotation queue
|
|
1691
|
+
* @param index - The index of the run to retrieve
|
|
1692
|
+
* @returns A Promise that resolves to a RunWithAnnotationQueueInfo object
|
|
1693
|
+
* @throws {Error} If the run is not found at the given index or for other API-related errors
|
|
1694
|
+
*/
|
|
1695
|
+
async getRunFromAnnotationQueue(t, e) {
|
|
1696
|
+
const a = `/annotation-queues/${f(t, "queueId")}/run`, i = await this.caller.call(u(), `${this.apiUrl}${a}/${e}`, {
|
|
1697
|
+
method: "GET",
|
|
1698
|
+
headers: this.headers,
|
|
1699
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1700
|
+
...this.fetchOptions
|
|
1701
|
+
});
|
|
1702
|
+
return await p(i, "get run from annotation queue"), await i.json();
|
|
1703
|
+
}
|
|
1704
|
+
async _currentTenantIsOwner(t) {
|
|
1705
|
+
const e = await this._getSettings();
|
|
1706
|
+
return t == "-" || e.tenant_handle === t;
|
|
1707
|
+
}
|
|
1708
|
+
async _ownerConflictError(t, e) {
|
|
1709
|
+
const a = await this._getSettings();
|
|
1710
|
+
return new Error(`Cannot ${t} for another tenant.
|
|
1711
|
+
|
|
1712
|
+
Current tenant: ${a.tenant_handle}
|
|
1713
|
+
|
|
1714
|
+
Requested tenant: ${e}`);
|
|
1715
|
+
}
|
|
1716
|
+
async _getLatestCommitHash(t) {
|
|
1717
|
+
const e = await this.caller.call(u(), `${this.apiUrl}/commits/${t}/?limit=1&offset=0`, {
|
|
1718
|
+
method: "GET",
|
|
1719
|
+
headers: this.headers,
|
|
1720
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1721
|
+
...this.fetchOptions
|
|
1722
|
+
}), a = await e.json();
|
|
1723
|
+
if (!e.ok) {
|
|
1724
|
+
const i = typeof a.detail == "string" ? a.detail : JSON.stringify(a.detail), s = new Error(`Error ${e.status}: ${e.statusText}
|
|
1725
|
+
${i}`);
|
|
1726
|
+
throw s.statusCode = e.status, s;
|
|
1727
|
+
}
|
|
1728
|
+
if (a.commits.length !== 0)
|
|
1729
|
+
return a.commits[0].commit_hash;
|
|
1730
|
+
}
|
|
1731
|
+
async _likeOrUnlikePrompt(t, e) {
|
|
1732
|
+
const [a, i, s] = O(t), r = await this.caller.call(u(), `${this.apiUrl}/likes/${a}/${i}`, {
|
|
1733
|
+
method: "POST",
|
|
1734
|
+
body: JSON.stringify({ like: e }),
|
|
1735
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1736
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1737
|
+
...this.fetchOptions
|
|
1738
|
+
});
|
|
1739
|
+
return await p(r, `${e ? "like" : "unlike"} prompt`), await r.json();
|
|
1740
|
+
}
|
|
1741
|
+
async _getPromptUrl(t) {
|
|
1742
|
+
const [e, a, i] = O(t);
|
|
1743
|
+
if (await this._currentTenantIsOwner(e)) {
|
|
1744
|
+
const s = await this._getSettings();
|
|
1745
|
+
return i !== "latest" ? `${this.getHostUrl()}/prompts/${a}/${i.substring(0, 8)}?organizationId=${s.id}` : `${this.getHostUrl()}/prompts/${a}?organizationId=${s.id}`;
|
|
1746
|
+
} else
|
|
1747
|
+
return i !== "latest" ? `${this.getHostUrl()}/hub/${e}/${a}/${i.substring(0, 8)}` : `${this.getHostUrl()}/hub/${e}/${a}`;
|
|
1748
|
+
}
|
|
1749
|
+
async promptExists(t) {
|
|
1750
|
+
return !!await this.getPrompt(t);
|
|
1751
|
+
}
|
|
1752
|
+
async likePrompt(t) {
|
|
1753
|
+
return this._likeOrUnlikePrompt(t, !0);
|
|
1754
|
+
}
|
|
1755
|
+
async unlikePrompt(t) {
|
|
1756
|
+
return this._likeOrUnlikePrompt(t, !1);
|
|
1757
|
+
}
|
|
1758
|
+
async *listCommits(t) {
|
|
1759
|
+
for await (const e of this._getPaginated(`/commits/${t}/`, new URLSearchParams(), (a) => a.commits))
|
|
1760
|
+
yield* e;
|
|
1761
|
+
}
|
|
1762
|
+
async *listPrompts(t) {
|
|
1763
|
+
const e = new URLSearchParams();
|
|
1764
|
+
e.append("sort_field", (t == null ? void 0 : t.sortField) ?? "updated_at"), e.append("sort_direction", "desc"), e.append("is_archived", (!!(t != null && t.isArchived)).toString()), (t == null ? void 0 : t.isPublic) !== void 0 && e.append("is_public", t.isPublic.toString()), t != null && t.query && e.append("query", t.query);
|
|
1765
|
+
for await (const a of this._getPaginated("/repos", e, (i) => i.repos))
|
|
1766
|
+
yield* a;
|
|
1767
|
+
}
|
|
1768
|
+
async getPrompt(t) {
|
|
1769
|
+
const [e, a, i] = O(t), s = await this.caller.call(u(), `${this.apiUrl}/repos/${e}/${a}`, {
|
|
1770
|
+
method: "GET",
|
|
1771
|
+
headers: this.headers,
|
|
1772
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1773
|
+
...this.fetchOptions
|
|
1774
|
+
});
|
|
1775
|
+
if (s.status === 404)
|
|
1776
|
+
return null;
|
|
1777
|
+
await p(s, "get prompt");
|
|
1778
|
+
const r = await s.json();
|
|
1779
|
+
return r.repo ? r.repo : null;
|
|
1780
|
+
}
|
|
1781
|
+
async createPrompt(t, e) {
|
|
1782
|
+
const a = await this._getSettings();
|
|
1783
|
+
if (e != null && e.isPublic && !a.tenant_handle)
|
|
1784
|
+
throw new Error(`Cannot create a public prompt without first
|
|
1785
|
+
|
|
1786
|
+
creating a LangChain Hub handle.
|
|
1787
|
+
You can add a handle by creating a public prompt at:
|
|
1788
|
+
|
|
1789
|
+
https://smith.langchain.com/prompts`);
|
|
1790
|
+
const [i, s, r] = O(t);
|
|
1791
|
+
if (!await this._currentTenantIsOwner(i))
|
|
1792
|
+
throw await this._ownerConflictError("create a prompt", i);
|
|
1793
|
+
const o = {
|
|
1794
|
+
repo_handle: s,
|
|
1795
|
+
...(e == null ? void 0 : e.description) && { description: e.description },
|
|
1796
|
+
...(e == null ? void 0 : e.readme) && { readme: e.readme },
|
|
1797
|
+
...(e == null ? void 0 : e.tags) && { tags: e.tags },
|
|
1798
|
+
is_public: !!(e != null && e.isPublic)
|
|
1799
|
+
}, n = await this.caller.call(u(), `${this.apiUrl}/repos/`, {
|
|
1800
|
+
method: "POST",
|
|
1801
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1802
|
+
body: JSON.stringify(o),
|
|
1803
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1804
|
+
...this.fetchOptions
|
|
1805
|
+
});
|
|
1806
|
+
await p(n, "create prompt");
|
|
1807
|
+
const { repo: d } = await n.json();
|
|
1808
|
+
return d;
|
|
1809
|
+
}
|
|
1810
|
+
async createCommit(t, e, a) {
|
|
1811
|
+
if (!await this.promptExists(t))
|
|
1812
|
+
throw new Error("Prompt does not exist, you must create it first.");
|
|
1813
|
+
const [i, s, r] = O(t), o = (a == null ? void 0 : a.parentCommitHash) === "latest" || !(a != null && a.parentCommitHash) ? await this._getLatestCommitHash(`${i}/${s}`) : a == null ? void 0 : a.parentCommitHash, n = {
|
|
1814
|
+
manifest: JSON.parse(JSON.stringify(e)),
|
|
1815
|
+
parent_commit: o
|
|
1816
|
+
}, d = await this.caller.call(u(), `${this.apiUrl}/commits/${i}/${s}`, {
|
|
1817
|
+
method: "POST",
|
|
1818
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1819
|
+
body: JSON.stringify(n),
|
|
1820
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1821
|
+
...this.fetchOptions
|
|
1822
|
+
});
|
|
1823
|
+
await p(d, "create commit");
|
|
1824
|
+
const l = await d.json();
|
|
1825
|
+
return this._getPromptUrl(`${i}/${s}${l.commit_hash ? `:${l.commit_hash}` : ""}`);
|
|
1826
|
+
}
|
|
1827
|
+
async updatePrompt(t, e) {
|
|
1828
|
+
if (!await this.promptExists(t))
|
|
1829
|
+
throw new Error("Prompt does not exist, you must create it first.");
|
|
1830
|
+
const [a, i] = O(t);
|
|
1831
|
+
if (!await this._currentTenantIsOwner(a))
|
|
1832
|
+
throw await this._ownerConflictError("update a prompt", a);
|
|
1833
|
+
const s = {};
|
|
1834
|
+
if ((e == null ? void 0 : e.description) !== void 0 && (s.description = e.description), (e == null ? void 0 : e.readme) !== void 0 && (s.readme = e.readme), (e == null ? void 0 : e.tags) !== void 0 && (s.tags = e.tags), (e == null ? void 0 : e.isPublic) !== void 0 && (s.is_public = e.isPublic), (e == null ? void 0 : e.isArchived) !== void 0 && (s.is_archived = e.isArchived), Object.keys(s).length === 0)
|
|
1835
|
+
throw new Error("No valid update options provided");
|
|
1836
|
+
const r = await this.caller.call(u(), `${this.apiUrl}/repos/${a}/${i}`, {
|
|
1837
|
+
method: "PATCH",
|
|
1838
|
+
body: JSON.stringify(s),
|
|
1839
|
+
headers: {
|
|
1840
|
+
...this.headers,
|
|
1841
|
+
"Content-Type": "application/json"
|
|
1842
|
+
},
|
|
1843
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1844
|
+
...this.fetchOptions
|
|
1845
|
+
});
|
|
1846
|
+
return await p(r, "update prompt"), r.json();
|
|
1847
|
+
}
|
|
1848
|
+
async deletePrompt(t) {
|
|
1849
|
+
if (!await this.promptExists(t))
|
|
1850
|
+
throw new Error("Prompt does not exist, you must create it first.");
|
|
1851
|
+
const [e, a, i] = O(t);
|
|
1852
|
+
if (!await this._currentTenantIsOwner(e))
|
|
1853
|
+
throw await this._ownerConflictError("delete a prompt", e);
|
|
1854
|
+
return await (await this.caller.call(u(), `${this.apiUrl}/repos/${e}/${a}`, {
|
|
1855
|
+
method: "DELETE",
|
|
1856
|
+
headers: this.headers,
|
|
1857
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1858
|
+
...this.fetchOptions
|
|
1859
|
+
})).json();
|
|
1860
|
+
}
|
|
1861
|
+
async pullPromptCommit(t, e) {
|
|
1862
|
+
const [a, i, s] = O(t), r = await this._getServerInfo(), o = z(r.version, "0.5.23");
|
|
1863
|
+
let n = s;
|
|
1864
|
+
if (!o && s === "latest") {
|
|
1865
|
+
const h = await this._getLatestCommitHash(`${a}/${i}`);
|
|
1866
|
+
if (h)
|
|
1867
|
+
n = h;
|
|
1868
|
+
else
|
|
1869
|
+
throw new Error("No commits found");
|
|
1870
|
+
}
|
|
1871
|
+
const d = await this.caller.call(u(), `${this.apiUrl}/commits/${a}/${i}/${n}${e != null && e.includeModel ? "?include_model=true" : ""}`, {
|
|
1872
|
+
method: "GET",
|
|
1873
|
+
headers: this.headers,
|
|
1874
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1875
|
+
...this.fetchOptions
|
|
1876
|
+
});
|
|
1877
|
+
await p(d, "pull prompt commit");
|
|
1878
|
+
const l = await d.json();
|
|
1879
|
+
return {
|
|
1880
|
+
owner: a,
|
|
1881
|
+
repo: i,
|
|
1882
|
+
commit_hash: l.commit_hash,
|
|
1883
|
+
manifest: l.manifest,
|
|
1884
|
+
examples: l.examples
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
|
|
1889
|
+
* Using this method directly returns the JSON string of the prompt rather than a LangChain object.
|
|
1890
|
+
* @private
|
|
1891
|
+
*/
|
|
1892
|
+
async _pullPrompt(t, e) {
|
|
1893
|
+
const a = await this.pullPromptCommit(t, {
|
|
1894
|
+
includeModel: e == null ? void 0 : e.includeModel
|
|
1895
|
+
});
|
|
1896
|
+
return JSON.stringify(a.manifest);
|
|
1897
|
+
}
|
|
1898
|
+
async pushPrompt(t, e) {
|
|
1899
|
+
return await this.promptExists(t) ? e && Object.keys(e).some((i) => i !== "object") && await this.updatePrompt(t, {
|
|
1900
|
+
description: e == null ? void 0 : e.description,
|
|
1901
|
+
readme: e == null ? void 0 : e.readme,
|
|
1902
|
+
tags: e == null ? void 0 : e.tags,
|
|
1903
|
+
isPublic: e == null ? void 0 : e.isPublic
|
|
1904
|
+
}) : await this.createPrompt(t, {
|
|
1905
|
+
description: e == null ? void 0 : e.description,
|
|
1906
|
+
readme: e == null ? void 0 : e.readme,
|
|
1907
|
+
tags: e == null ? void 0 : e.tags,
|
|
1908
|
+
isPublic: e == null ? void 0 : e.isPublic
|
|
1909
|
+
}), e != null && e.object ? await this.createCommit(t, e == null ? void 0 : e.object, {
|
|
1910
|
+
parentCommitHash: e == null ? void 0 : e.parentCommitHash
|
|
1911
|
+
}) : await this._getPromptUrl(t);
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Clone a public dataset to your own langsmith tenant.
|
|
1915
|
+
* This operation is idempotent. If you already have a dataset with the given name,
|
|
1916
|
+
* this function will do nothing.
|
|
1917
|
+
|
|
1918
|
+
* @param {string} tokenOrUrl The token of the public dataset to clone.
|
|
1919
|
+
* @param {Object} [options] Additional options for cloning the dataset.
|
|
1920
|
+
* @param {string} [options.sourceApiUrl] The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.
|
|
1921
|
+
* @param {string} [options.datasetName] The name of the dataset to create in your tenant. Defaults to the name of the public dataset.
|
|
1922
|
+
* @returns {Promise<void>}
|
|
1923
|
+
*/
|
|
1924
|
+
async clonePublicDataset(t, e = {}) {
|
|
1925
|
+
const { sourceApiUrl: a = this.apiUrl, datasetName: i } = e, [s, r] = this.parseTokenOrUrl(t, a), o = new A({
|
|
1926
|
+
apiUrl: s,
|
|
1927
|
+
// Placeholder API key not needed anymore in most cases, but
|
|
1928
|
+
// some private deployments may have API key-based rate limiting
|
|
1929
|
+
// that would cause this to fail if we provide no value.
|
|
1930
|
+
apiKey: "placeholder"
|
|
1931
|
+
}), n = await o.readSharedDataset(r), d = i || n.name;
|
|
1932
|
+
try {
|
|
1933
|
+
if (await this.hasDataset({ datasetId: d })) {
|
|
1934
|
+
console.log(`Dataset ${d} already exists in your tenant. Skipping.`);
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
} catch {
|
|
1938
|
+
}
|
|
1939
|
+
const l = await o.listSharedExamples(r), h = await this.createDataset(d, {
|
|
1940
|
+
description: n.description,
|
|
1941
|
+
dataType: n.data_type || "kv",
|
|
1942
|
+
inputsSchema: n.inputs_schema_definition ?? void 0,
|
|
1943
|
+
outputsSchema: n.outputs_schema_definition ?? void 0
|
|
1944
|
+
});
|
|
1945
|
+
try {
|
|
1946
|
+
await this.createExamples({
|
|
1947
|
+
inputs: l.map((c) => c.inputs),
|
|
1948
|
+
outputs: l.flatMap((c) => c.outputs ? [c.outputs] : []),
|
|
1949
|
+
datasetId: h.id
|
|
1950
|
+
});
|
|
1951
|
+
} catch (c) {
|
|
1952
|
+
throw console.error(`An error occurred while creating dataset ${d}. You should delete it manually.`), c;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
parseTokenOrUrl(t, e, a = 2, i = "dataset") {
|
|
1956
|
+
try {
|
|
1957
|
+
return f(t), [e, t];
|
|
1958
|
+
} catch {
|
|
1959
|
+
}
|
|
1960
|
+
try {
|
|
1961
|
+
const r = new URL(t).pathname.split("/").filter((o) => o !== "");
|
|
1962
|
+
if (r.length >= a) {
|
|
1963
|
+
const o = r[r.length - a];
|
|
1964
|
+
return [e, o];
|
|
1965
|
+
} else
|
|
1966
|
+
throw new Error(`Invalid public ${i} URL: ${t}`);
|
|
1967
|
+
} catch {
|
|
1968
|
+
throw new Error(`Invalid public ${i} URL or token: ${t}`);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
/**
|
|
1972
|
+
* Awaits all pending trace batches. Useful for environments where
|
|
1973
|
+
* you need to be sure that all tracing requests finish before execution ends,
|
|
1974
|
+
* such as serverless environments.
|
|
1975
|
+
*
|
|
1976
|
+
* @example
|
|
1977
|
+
* ```
|
|
1978
|
+
* import { Client } from "langsmith";
|
|
1979
|
+
*
|
|
1980
|
+
* const client = new Client();
|
|
1981
|
+
*
|
|
1982
|
+
* try {
|
|
1983
|
+
* // Tracing happens here
|
|
1984
|
+
* ...
|
|
1985
|
+
* } finally {
|
|
1986
|
+
* await client.awaitPendingTraceBatches();
|
|
1987
|
+
* }
|
|
1988
|
+
* ```
|
|
1989
|
+
*
|
|
1990
|
+
* @returns A promise that resolves once all currently pending traces have sent.
|
|
1991
|
+
*/
|
|
1992
|
+
awaitPendingTraceBatches() {
|
|
1993
|
+
return Promise.all(this.autoBatchQueue.items.map(({ itemPromise: t }) => t));
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
export {
|
|
1997
|
+
A as Client,
|
|
1998
|
+
V as DEFAULT_BATCH_SIZE_LIMIT_BYTES,
|
|
1999
|
+
Y as Queue,
|
|
2000
|
+
D as mergeRuntimeEnvIntoRunCreate
|
|
2001
|
+
};
|
|
2002
|
+
//# sourceMappingURL=client.js.map
|