langwatch 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{add-LBBS4I3H.js → add-RGWB3264.js} +35 -28
- package/dist/add-RGWB3264.js.map +1 -0
- package/dist/{add-RD3ZKFAT.mjs → add-WLUMK5VQ.mjs} +23 -16
- package/dist/add-WLUMK5VQ.mjs.map +1 -0
- package/dist/chunk-4ILMGMAP.mjs +155 -0
- package/dist/chunk-4ILMGMAP.mjs.map +1 -0
- package/dist/chunk-4TF2O2TH.js +207 -0
- package/dist/chunk-4TF2O2TH.js.map +1 -0
- package/dist/chunk-5N5BUR2Z.js +636 -0
- package/dist/chunk-5N5BUR2Z.js.map +1 -0
- package/dist/chunk-AZELEDOV.js +155 -0
- package/dist/chunk-AZELEDOV.js.map +1 -0
- package/dist/{chunk-YN4436PK.mjs → chunk-CU3443HD.mjs} +14 -9
- package/dist/{chunk-2JU376G7.js → chunk-D2CSG4SJ.js} +4 -4
- package/dist/chunk-D2CSG4SJ.js.map +1 -0
- package/dist/chunk-DEVJ7BPE.js +63 -0
- package/dist/chunk-DEVJ7BPE.js.map +1 -0
- package/dist/chunk-DISMHYXC.js +184 -0
- package/dist/chunk-DISMHYXC.js.map +1 -0
- package/dist/{chunk-E7UE2MPD.mjs → chunk-ECUXLXFT.mjs} +2 -2
- package/dist/chunk-EJWJXTPU.mjs +626 -0
- package/dist/chunk-EJWJXTPU.mjs.map +1 -0
- package/dist/chunk-FQSWUK5N.mjs +63 -0
- package/dist/chunk-FQSWUK5N.mjs.map +1 -0
- package/dist/{chunk-3GKPQB4R.mjs → chunk-HUI45ULC.mjs} +4 -4
- package/dist/chunk-HUI45ULC.mjs.map +1 -0
- package/dist/chunk-IZ2U3ABC.mjs +636 -0
- package/dist/chunk-IZ2U3ABC.mjs.map +1 -0
- package/dist/{chunk-HJU67C7H.js → chunk-K64Y6YUG.js} +10 -10
- package/dist/{chunk-HJU67C7H.js.map → chunk-K64Y6YUG.js.map} +1 -1
- package/dist/chunk-M4VUHTT2.js +626 -0
- package/dist/chunk-M4VUHTT2.js.map +1 -0
- package/dist/{chunk-PR3JDWC3.mjs → chunk-N2V6J3U2.mjs} +28 -3
- package/dist/chunk-N2V6J3U2.mjs.map +1 -0
- package/dist/{chunk-FJLK5CFL.js → chunk-OXBO24RB.js} +13 -8
- package/dist/chunk-OXBO24RB.js.map +1 -0
- package/dist/{chunk-SMXXAVMB.js → chunk-SGNJDRCT.js} +2 -2
- package/dist/chunk-SGNJDRCT.js.map +1 -0
- package/dist/{chunk-W5ZEP3CI.mjs → chunk-SYMZPWZE.mjs} +2 -2
- package/dist/chunk-SYMZPWZE.mjs.map +1 -0
- package/dist/{chunk-KGDAENGD.js → chunk-YH5TIVK2.js} +28 -3
- package/dist/chunk-YH5TIVK2.js.map +1 -0
- package/dist/chunk-YNQ44U6D.mjs +184 -0
- package/dist/chunk-YNQ44U6D.mjs.map +1 -0
- package/dist/chunk-ZJZ3MIWE.mjs +207 -0
- package/dist/chunk-ZJZ3MIWE.mjs.map +1 -0
- package/dist/cli/index.js +8 -8
- package/dist/cli/index.mjs +8 -8
- package/dist/{create-G5MTGOOH.js → create-7K2CC4KQ.js} +11 -11
- package/dist/{create-G5MTGOOH.js.map → create-7K2CC4KQ.js.map} +1 -1
- package/dist/{create-QUZYBMQB.mjs → create-MK7NEGCM.mjs} +8 -8
- package/dist/implementation-C4lvooSg.d.mts +576 -0
- package/dist/implementation-CzemP9jY.d.ts +576 -0
- package/dist/index-DTEZr0Jn.d.mts +34 -0
- package/dist/index-DTEZr0Jn.d.ts +34 -0
- package/dist/index.d.mts +121 -47
- package/dist/index.d.ts +121 -47
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -23
- package/dist/index.mjs.map +1 -1
- package/dist/init-GDKJICSS.js +16 -0
- package/dist/{init-XU2JFY6N.js.map → init-GDKJICSS.js.map} +1 -1
- package/dist/{init-H67RW22E.mjs → init-RINSTP4L.mjs} +5 -5
- package/dist/{list-ZXFLAF52.js → list-DBUK47MA.js} +30 -17
- package/dist/list-DBUK47MA.js.map +1 -0
- package/dist/{list-7NPSX2E4.mjs → list-ZOMRKOBV.mjs} +29 -16
- package/dist/list-ZOMRKOBV.mjs.map +1 -0
- package/dist/{login-76NQIHKR.js → login-A7LEPNBR.js} +8 -4
- package/dist/login-A7LEPNBR.js.map +1 -0
- package/dist/{login-EK4WVOI2.mjs → login-ULPHWIAX.mjs} +8 -4
- package/dist/login-ULPHWIAX.mjs.map +1 -0
- package/dist/observability-sdk/index.d.mts +134 -0
- package/dist/observability-sdk/index.d.ts +134 -0
- package/dist/observability-sdk/index.js +42 -0
- package/dist/observability-sdk/index.js.map +1 -0
- package/dist/observability-sdk/index.mjs +42 -0
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +69 -0
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +69 -0
- package/dist/observability-sdk/instrumentation/langchain/index.js +518 -0
- package/dist/observability-sdk/instrumentation/langchain/index.js.map +1 -0
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +518 -0
- package/dist/observability-sdk/instrumentation/langchain/index.mjs.map +1 -0
- package/dist/observability-sdk/setup/node/index.d.mts +368 -0
- package/dist/observability-sdk/setup/node/index.d.ts +368 -0
- package/dist/observability-sdk/setup/node/index.js +279 -0
- package/dist/observability-sdk/setup/node/index.js.map +1 -0
- package/dist/observability-sdk/setup/node/index.mjs +279 -0
- package/dist/observability-sdk/setup/node/index.mjs.map +1 -0
- package/dist/{remove-XBNGIVMR.js → remove-ODTJLFWR.js} +19 -15
- package/dist/remove-ODTJLFWR.js.map +1 -0
- package/dist/{remove-SDJYEPAY.mjs → remove-RAJBGHQQ.mjs} +12 -8
- package/dist/remove-RAJBGHQQ.mjs.map +1 -0
- package/dist/{sync-ST2IWXSB.mjs → sync-2IXPWN64.mjs} +40 -33
- package/dist/sync-2IXPWN64.mjs.map +1 -0
- package/dist/{sync-EISKGPTL.js → sync-PBOL5ODF.js} +53 -46
- package/dist/sync-PBOL5ODF.js.map +1 -0
- package/dist/{prompt-D-jpMrLS.d.mts → types-1q5wIYP5.d.mts} +628 -14
- package/dist/{prompt-D-jpMrLS.d.ts → types-C9k5gGhU.d.ts} +628 -14
- package/dist/types-DRiQaKFG.d.mts +254 -0
- package/dist/types-DRiQaKFG.d.ts +254 -0
- package/dist/types-Dmazk5Bk.d.mts +44 -0
- package/dist/types-Dmazk5Bk.d.ts +44 -0
- package/package.json +39 -39
- package/dist/add-LBBS4I3H.js.map +0 -1
- package/dist/add-RD3ZKFAT.mjs.map +0 -1
- package/dist/chunk-2JU376G7.js.map +0 -1
- package/dist/chunk-2ODBGSBI.js +0 -4
- package/dist/chunk-2ODBGSBI.js.map +0 -1
- package/dist/chunk-3GKPQB4R.mjs.map +0 -1
- package/dist/chunk-52GXX3MA.js +0 -426
- package/dist/chunk-52GXX3MA.js.map +0 -1
- package/dist/chunk-5NC5ILKA.js +0 -94
- package/dist/chunk-5NC5ILKA.js.map +0 -1
- package/dist/chunk-AAROJADR.mjs +0 -49
- package/dist/chunk-AAROJADR.mjs.map +0 -1
- package/dist/chunk-DTEKFQ4U.js +0 -159
- package/dist/chunk-DTEKFQ4U.js.map +0 -1
- package/dist/chunk-F63YKTXA.mjs +0 -47
- package/dist/chunk-F63YKTXA.mjs.map +0 -1
- package/dist/chunk-FJLK5CFL.js.map +0 -1
- package/dist/chunk-GJSEBQXF.mjs +0 -392
- package/dist/chunk-GJSEBQXF.mjs.map +0 -1
- package/dist/chunk-IGHXIIIK.js +0 -49
- package/dist/chunk-IGHXIIIK.js.map +0 -1
- package/dist/chunk-J7ICRUU4.mjs +0 -426
- package/dist/chunk-J7ICRUU4.mjs.map +0 -1
- package/dist/chunk-KGDAENGD.js.map +0 -1
- package/dist/chunk-LD74LVRU.js +0 -47
- package/dist/chunk-LD74LVRU.js.map +0 -1
- package/dist/chunk-PCQVQ7SB.js +0 -45
- package/dist/chunk-PCQVQ7SB.js.map +0 -1
- package/dist/chunk-PR3JDWC3.mjs.map +0 -1
- package/dist/chunk-PWZBLTHR.js +0 -118
- package/dist/chunk-PWZBLTHR.js.map +0 -1
- package/dist/chunk-QEWDG5QE.mjs +0 -45
- package/dist/chunk-QEWDG5QE.mjs.map +0 -1
- package/dist/chunk-SMXXAVMB.js.map +0 -1
- package/dist/chunk-STV4ZVNA.mjs +0 -118
- package/dist/chunk-STV4ZVNA.mjs.map +0 -1
- package/dist/chunk-T5AZMMVS.mjs +0 -94
- package/dist/chunk-T5AZMMVS.mjs.map +0 -1
- package/dist/chunk-UU33HCCZ.mjs +0 -159
- package/dist/chunk-UU33HCCZ.mjs.map +0 -1
- package/dist/chunk-VGHLQXKB.js +0 -392
- package/dist/chunk-VGHLQXKB.js.map +0 -1
- package/dist/chunk-W5ZEP3CI.mjs.map +0 -1
- package/dist/chunk-Y666BJA5.mjs +0 -4
- package/dist/chunk-YN4436PK.mjs.map +0 -1
- package/dist/client-B2HqIKg6.d.ts +0 -51
- package/dist/client-XyCqclCi.d.mts +0 -51
- package/dist/client-browser.d.mts +0 -8
- package/dist/client-browser.d.ts +0 -8
- package/dist/client-browser.js +0 -88
- package/dist/client-browser.js.map +0 -1
- package/dist/client-browser.mjs +0 -88
- package/dist/client-browser.mjs.map +0 -1
- package/dist/client-node.d.mts +0 -8
- package/dist/client-node.d.ts +0 -8
- package/dist/client-node.js +0 -95
- package/dist/client-node.js.map +0 -1
- package/dist/client-node.mjs +0 -95
- package/dist/client-node.mjs.map +0 -1
- package/dist/evaluation/index.d.mts +0 -897
- package/dist/evaluation/index.d.ts +0 -897
- package/dist/evaluation/index.js +0 -14
- package/dist/evaluation/index.js.map +0 -1
- package/dist/evaluation/index.mjs +0 -14
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +0 -64
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +0 -64
- package/dist/init-XU2JFY6N.js +0 -16
- package/dist/list-7NPSX2E4.mjs.map +0 -1
- package/dist/list-ZXFLAF52.js.map +0 -1
- package/dist/login-76NQIHKR.js.map +0 -1
- package/dist/login-EK4WVOI2.mjs.map +0 -1
- package/dist/observability/index.d.mts +0 -260
- package/dist/observability/index.d.ts +0 -260
- package/dist/observability/index.js +0 -21
- package/dist/observability/index.js.map +0 -1
- package/dist/observability/index.mjs +0 -21
- package/dist/observability/index.mjs.map +0 -1
- package/dist/observability/instrumentation/langchain/index.d.mts +0 -40
- package/dist/observability/instrumentation/langchain/index.d.ts +0 -40
- package/dist/observability/instrumentation/langchain/index.js +0 -668
- package/dist/observability/instrumentation/langchain/index.js.map +0 -1
- package/dist/observability/instrumentation/langchain/index.mjs +0 -668
- package/dist/observability/instrumentation/langchain/index.mjs.map +0 -1
- package/dist/prompt/index.d.mts +0 -10
- package/dist/prompt/index.d.ts +0 -10
- package/dist/prompt/index.js +0 -22
- package/dist/prompt/index.js.map +0 -1
- package/dist/prompt/index.mjs +0 -22
- package/dist/prompt/index.mjs.map +0 -1
- package/dist/record-evaluation-CmxMXa-3.d.mts +0 -25
- package/dist/record-evaluation-CmxMXa-3.d.ts +0 -25
- package/dist/remove-SDJYEPAY.mjs.map +0 -1
- package/dist/remove-XBNGIVMR.js.map +0 -1
- package/dist/sync-EISKGPTL.js.map +0 -1
- package/dist/sync-ST2IWXSB.mjs.map +0 -1
- package/dist/trace-CqaKo0kZ.d.ts +0 -622
- package/dist/trace-DtVc5GhF.d.mts +0 -622
- /package/dist/{chunk-Y666BJA5.mjs.map → chunk-CU3443HD.mjs.map} +0 -0
- /package/dist/{chunk-E7UE2MPD.mjs.map → chunk-ECUXLXFT.mjs.map} +0 -0
- /package/dist/{create-QUZYBMQB.mjs.map → create-MK7NEGCM.mjs.map} +0 -0
- /package/dist/{init-H67RW22E.mjs.map → init-RINSTP4L.mjs.map} +0 -0
- /package/dist/{evaluation → observability-sdk}/index.mjs.map +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/observability/semconv/attributes.ts","../src/observability/semconv/events.ts","../src/observability/semconv/index.ts","../src/observability/semconv/values.ts"],"sourcesContent":["/*\n This file contains the semantic conventions for attributes either owned by LangWatch, or\n which are no yet part of the OpenTelemetry semantic conventions for Gen AI.\n\n Any that are not yet part of the OpenTelemetry semantic conventions for Gen AI are\n marked with an UNSTABLE_ prefix.\n*/\n\n/**\n * LangWatch input data attribute key\n * Used to store the input data for a span or event\n */\nexport const ATTR_LANGWATCH_INPUT = \"langwatch.input\";\n\n/**\n * LangWatch output data attribute key\n * Used to store the output data for a span or event\n */\nexport const ATTR_LANGWATCH_OUTPUT = \"langwatch.output\";\n\n/**\n * LangWatch span type attribute key\n * Used to identify the type of span being traced\n */\nexport const ATTR_LANGWATCH_SPAN_TYPE = \"langwatch.span.type\";\n\n/**\n * LangWatch RAG contexts attribute key\n * Used to store retrieval-augmented generation contexts\n */\nexport const ATTR_LANGWATCH_RAG_CONTEXTS = \"langwatch.contexts\";\n\n/**\n * LangWatch metrics attribute key\n * Used to store custom metrics data\n */\nexport const ATTR_LANGWATCH_METRICS = \"langwatch.metrics\";\n\n/**\n * LangWatch SDK version attribute key\n * Used to track the version of the LangWatch SDK being used\n */\nexport const ATTR_LANGWATCH_SDK_VERSION = \"langwatch.sdk.version\";\n\n/**\n * LangWatch SDK name attribute key\n * Used to identify the LangWatch SDK implementation\n */\nexport const ATTR_LANGWATCH_SDK_NAME = \"langwatch.sdk.name\";\n\n/**\n * LangWatch SDK language attribute key\n * Used to identify the programming language of the SDK\n */\nexport const ATTR_LANGWATCH_SDK_LANGUAGE = \"langwatch.sdk.language\";\n\n/**\n * LangWatch timestamps attribute key\n * Used to store timing information for events\n */\nexport const ATTR_LANGWATCH_TIMESTAMPS = \"langwatch.timestamps\";\n\n/**\n * LangWatch custom evaluation attribute key\n * Used to store custom evaluation data\n */\nexport const ATTR_LANGWATCH_EVALUATION_CUSTOM = \"langwatch.evaluation.custom\";\n\n/**\n * LangWatch parameters attribute key\n * Used to store parameter data for operations\n */\nexport const ATTR_LANGWATCH_PARAMS = \"langwatch.params\";\n\n/**\n * LangWatch customer ID attribute key\n * Used to identify the customer associated with the trace\n */\nexport const ATTR_LANGWATCH_CUSTOMER_ID = \"langwatch.customer.id\";\n\n/**\n * LangWatch thread ID attribute key\n * Used to group related operations within a conversation thread\n */\nexport const ATTR_LANGWATCH_THREAD_ID = \"langwatch.thread.id\";\n\n/**\n * LangWatch streaming attribute key\n * Used to indicate if the operation involves streaming\n */\nexport const ATTR_LANGWATCH_STREAMING = \"langwatch.gen_ai.streaming\";\n\n/**\n * LangWatch prompt ID attribute key\n * Used to identify the specific prompt being used\n */\nexport const ATTR_LANGWATCH_PROMPT_ID = \"langwatch.prompt.id\";\n\n/**\n * LangWatch prompt version ID attribute key\n * Used to identify the specific version of a prompt\n */\nexport const ATTR_LANGWATCH_PROMPT_VERSION_ID = \"langwatch.prompt.version.id\";\n\n/**\n * LangWatch prompt variables attribute key\n * Used to store variables used in prompt templates\n */\nexport const ATTR_LANGWATCH_PROMPT_VARIABLES = \"langwatch.prompt.variables\";\n\n/**\n * LangWatch prompt selected ID attribute key\n * Used to identify which prompt was selected from a set\n */\nexport const ATTR_LANGWATCH_PROMPT_SELECTED_ID = \"langwatch.prompt.selected.id\";\n\n/**\n * LangWatch prompt version number attribute key\n * Used to track the version number of a prompt\n */\nexport const ATTR_LANGWATCH_PROMPT_VERSION_NUMBER =\n \"langwatch.prompt.version.number\";\n\n/**\n * LangWatch gen AI log event imposter attribute key\n * Used to identify imposter events in log records\n */\nexport const ATTR_LANGWATCH_GEN_AI_LOG_EVENT_IMPOSTER =\n \"langwatch.gen_ai.log_event.imposter\";\n\n/**\n * LangWatch gen AI log event body attribute key\n * Used to store the body content of log events\n */\nexport const ATTR_LANGWATCH_GEN_AI_LOG_EVENT_BODY =\n \"langwatch.gen_ai.log_event.body\";\n\n/**\n * LangWatch LangChain tags attribute key\n * Used to store tags associated with LangChain operations\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_TAGS = \"langwatch.langchain.tags\";\n\n/**\n * LangWatch LangChain event name attribute key\n * Used to identify the specific LangChain event type\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_EVENT_NAME = \"langwatch.langchain.event_name\";\n\n/**\n * LangWatch LangChain run ID attribute key\n * Used to identify a specific LangChain run\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_RUN_ID = \"langwatch.langchain.run.id\";\n\n/**\n * LangWatch LangChain run tags attribute key\n * Used to store tags associated with a LangChain run\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_RUN_TAGS = \"langwatch.langchain.run.tags\";\n\n/**\n * LangWatch LangChain run type attribute key\n * Used to identify the type of LangChain run\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_RUN_TYPE = \"langwatch.langchain.run.type\";\n\n/**\n * LangWatch LangChain run metadata attribute key\n * Used to store metadata associated with a LangChain run\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_RUN_METADATA = \"langwatch.langchain.run.metadata\";\n\n/**\n * LangWatch LangChain run extra parameters attribute key\n * Used to store additional parameters for a LangChain run\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_RUN_EXTRA_PARAMS = \"langwatch.langchain.run.extra_params\";\n\n/**\n * LangWatch LangChain run parent ID attribute key\n * Used to identify the parent run in a hierarchical structure\n */\nexport const ATTR_LANGWATCH_LANGCHAIN_RUN_PARENT_ID =\n \"langwatch.langchain.run.parent.id\";\n","/*\n This file contains the values for the OpenTelemetry semantic conventions for GenAI log\n record event names.\n\n 👉 https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-events/\n*/\n\n/**\n * GenAI system message event name\n * Used for log records representing system messages in AI conversations\n */\nexport const LOG_EVNT_GEN_AI_SYSTEM_MESSAGE = \"gen.ai.system_message\";\n\n/**\n * GenAI user message event name\n * Used for log records representing user messages in AI conversations\n */\nexport const LOG_EVNT_GEN_AI_USER_MESSAGE = \"gen.ai.user_message\";\n\n/**\n * GenAI assistant message event name\n * Used for log records representing assistant responses in AI conversations\n */\nexport const LOG_EVNT_GEN_AI_ASSISTANT_MESSAGE = \"gen.ai.assistant_message\";\n\n/**\n * GenAI tool message event name\n * Used for log records representing tool calls or responses in AI conversations\n */\nexport const LOG_EVNT_GEN_AI_TOOL_MESSAGE = \"gen.ai.tool_message\";\n\n/**\n * GenAI choice event name\n * Used for log records representing choices made by AI models\n */\nexport const LOG_EVNT_GEN_AI_CHOICE = \"gen.ai.choice\";\n\n/**\n * LangWatch LangChain callback event name\n * Used for log records representing LangChain callback events\n */\nexport const EVNT_LANGWATCH_LANGCHAIN_CALLBACK = \"langwatch.langchain.callback\";\n","/**\n * Semantic conventions module for LangWatch observability\n *\n * This module exports all semantic convention constants used for:\n * - Attributes: Key-value pairs for span and event metadata\n * - Values: Predefined values for semantic convention attributes\n * - Events: Event names for log records and traces\n *\n * @see {@link ./attributes} for attribute constants\n * @see {@link ./values} for value constants\n * @see {@link ./events} for event constants\n */\n\nexport * from \"./attributes\";\nexport * from \"./values\";\nexport * from \"./events\";\n","/*\n This file contains the values for the OpenTelemetry semantic conventions for Gen AI,\n some of which are still in development and therefor currently considered to be\n experimental.\n\n 👉 https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-events/\n*/\n\n/**\n * Anthropic AI system identifier\n * Used to identify Anthropic's Claude models\n */\nexport const VAL_GEN_AI_SYSTEM_ANTHROPIC = \"anthropic\";\n\n/**\n * AWS Bedrock system identifier\n * Used to identify AWS Bedrock AI services\n */\nexport const VAL_GEN_AI_SYSTEM_AWS_BEDROCK = \"aws.bedrock\";\n\n/**\n * Azure AI Inference system identifier\n * Used to identify Azure AI Inference services\n */\nexport const VAL_GEN_AI_SYSTEM_AZURE_AI_INFERENCE = \"azure.ai.inference\";\n\n/**\n * Azure AI OpenAI system identifier\n * Used to identify Azure OpenAI services\n */\nexport const VAL_GEN_AI_SYSTEM_AZURE_AI_OPENAI = \"azure.ai.openai\";\n\n/**\n * Cohere system identifier\n * Used to identify Cohere AI models\n */\nexport const VAL_GEN_AI_SYSTEM_COHERE = \"cohere\";\n\n/**\n * DeepSeek system identifier\n * Used to identify DeepSeek AI models\n */\nexport const VAL_GEN_AI_SYSTEM_DEEPSEEK = \"deepseek\";\n\n/**\n * GCP Gemini system identifier\n * Used to identify Google Cloud Gemini models\n */\nexport const VAL_GEN_AI_SYSTEM_GCP_GEMINI = \"gcp.gemini\";\n\n/**\n * GCP Gen AI system identifier\n * Used to identify Google Cloud Generative AI services\n */\nexport const VAL_GEN_AI_SYSTEM_GCP_GEN_AI = \"gcp.gen_ai\";\n\n/**\n * GCP Vertex AI system identifier\n * Used to identify Google Cloud Vertex AI services\n */\nexport const VAL_GEN_AI_SYSTEM_GCP_VERTEX_AI = \"gcp.vertex_ai\";\n\n/**\n * Groq system identifier\n * Used to identify Groq AI models\n */\nexport const VAL_GEN_AI_SYSTEM_GROQ = \"groq\";\n\n/**\n * IBM WatsonX AI system identifier\n * Used to identify IBM WatsonX AI services\n */\nexport const VAL_GEN_AI_SYSTEM_IBM_WATSONX_AI = \"ibm.watsonx.ai\";\n\n/**\n * Mistral AI system identifier\n * Used to identify Mistral AI models\n */\nexport const VAL_GEN_AI_SYSTEM_MISTRAL_AI = \"mistral_ai\";\n\n/**\n * OpenAI system identifier\n * Used to identify OpenAI models and services\n */\nexport const VAL_GEN_AI_SYSTEM_OPENAI = \"openai\";\n\n/**\n * Perplexity system identifier\n * Used to identify Perplexity AI models\n */\nexport const VAL_GEN_AI_SYSTEM_PERPLEXITY = \"perplexity\";\n\n/**\n * XAI system identifier\n * Used to identify XAI models and services\n */\nexport const VAL_GEN_AI_SYSTEM_XAI = \"xai\";\n\n/**\n * Content filter finish reason\n * Used when generation stops due to content filtering\n */\nexport const VAL_GEN_AI_FINISH_REASON_CONTENT_FILTER = \"content_filter\";\n\n/**\n * Error finish reason\n * Used when generation stops due to an error\n */\nexport const VAL_GEN_AI_FINISH_REASON_ERROR = \"error\";\n\n/**\n * Length finish reason\n * Used when generation stops due to length limits\n */\nexport const VAL_GEN_AI_FINISH_REASON_LENGTH = \"length\";\n\n/**\n * Stop finish reason\n * Used when generation stops due to stop tokens\n */\nexport const VAL_GEN_AI_FINISH_REASON_STOP = \"stop\";\n\n/**\n * Tool calls finish reason\n * Used when generation stops due to tool calls\n */\nexport const VAL_GEN_AI_FINISH_REASON_TOOL_CALLS = \"tool_calls\";\n\n/**\n * Union type of all supported GenAI system identifiers\n * Used for type safety when working with system identification\n */\nexport type VAL_GEN_AI_SYSTEMS =\n | typeof VAL_GEN_AI_SYSTEM_ANTHROPIC\n | typeof VAL_GEN_AI_SYSTEM_AWS_BEDROCK\n | typeof VAL_GEN_AI_SYSTEM_AZURE_AI_INFERENCE\n | typeof VAL_GEN_AI_SYSTEM_AZURE_AI_OPENAI\n | typeof VAL_GEN_AI_SYSTEM_COHERE\n | typeof VAL_GEN_AI_SYSTEM_DEEPSEEK\n | typeof VAL_GEN_AI_SYSTEM_GCP_GEMINI\n | typeof VAL_GEN_AI_SYSTEM_GCP_GEN_AI\n | typeof VAL_GEN_AI_SYSTEM_GCP_VERTEX_AI\n | typeof VAL_GEN_AI_SYSTEM_GROQ\n | typeof VAL_GEN_AI_SYSTEM_IBM_WATSONX_AI\n | typeof VAL_GEN_AI_SYSTEM_MISTRAL_AI\n | typeof VAL_GEN_AI_SYSTEM_OPENAI\n | typeof VAL_GEN_AI_SYSTEM_PERPLEXITY\n | typeof VAL_GEN_AI_SYSTEM_XAI;\n\n/**\n * Union type of all supported GenAI finish reasons\n * Used for type safety when working with generation completion reasons\n */\nexport type VAL_GEN_AI_FINISH_REASONS =\n | typeof VAL_GEN_AI_FINISH_REASON_CONTENT_FILTER\n | typeof VAL_GEN_AI_FINISH_REASON_ERROR\n | typeof VAL_GEN_AI_FINISH_REASON_LENGTH\n | typeof VAL_GEN_AI_FINISH_REASON_STOP\n | typeof VAL_GEN_AI_FINISH_REASON_TOOL_CALLS;\n"],"mappings":";;;;;AAYO,IAAM,uBAAuB;AAM7B,IAAM,wBAAwB;A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AMrC,IAAM,kCAAkC;AAMxC,IAAM,yBAAyB;AAM/B,IAAM,mCAAmC;AAMzC,IAAM,+BAA+B;AAMrC,IAAM,2BAA2B;AAMjC,IAAM,+BAA+B;AAMrC,IAAM,wBAAwB;AAM9B,IAAM,0CAA0C;AAMhD,IAAM,iCAAiC;AAMvC,IAAM,kCAAkC;AAMxC,IAAM,gCAAgC;AAMtC,IAAM,sCAAsC;","names":[]}
|
package/dist/chunk-VGHLQXKB.js
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
-
|
|
3
|
-
var _chunkSMXXAVMBjs = require('./chunk-SMXXAVMB.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkPCQVQ7SBjs = require('./chunk-PCQVQ7SB.js');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _chunkFJLK5CFLjs = require('./chunk-FJLK5CFL.js');
|
|
12
|
-
|
|
13
|
-
// src/prompt/prompt.ts
|
|
14
|
-
var _liquidjs = require('liquidjs');
|
|
15
|
-
var PromptCompilationError = class extends Error {
|
|
16
|
-
constructor(message, template, originalError) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.template = template;
|
|
19
|
-
this.originalError = originalError;
|
|
20
|
-
this.name = "PromptCompilationError";
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var liquid = new (0, _liquidjs.Liquid)({
|
|
24
|
-
strictFilters: true
|
|
25
|
-
});
|
|
26
|
-
var Prompt = class {
|
|
27
|
-
constructor(promptData) {
|
|
28
|
-
this.id = promptData.id;
|
|
29
|
-
this.handle = promptData.handle;
|
|
30
|
-
this.scope = promptData.scope;
|
|
31
|
-
this.name = promptData.name;
|
|
32
|
-
this.updatedAt = promptData.updatedAt;
|
|
33
|
-
this.version = promptData.version;
|
|
34
|
-
this.versionId = promptData.versionId;
|
|
35
|
-
this.versionCreatedAt = promptData.versionCreatedAt;
|
|
36
|
-
this.model = promptData.model;
|
|
37
|
-
this.prompt = promptData.prompt;
|
|
38
|
-
this.messages = promptData.messages;
|
|
39
|
-
this.response_format = promptData.response_format;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get the raw prompt data from the API
|
|
43
|
-
*/
|
|
44
|
-
get raw() {
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Compile the prompt template with provided variables (lenient - missing variables become empty)
|
|
49
|
-
* @param variables - Object containing variable values for template compilation
|
|
50
|
-
* @returns CompiledPrompt instance with compiled content
|
|
51
|
-
*/
|
|
52
|
-
_compile(variables, strict) {
|
|
53
|
-
try {
|
|
54
|
-
const compiledPrompt = this.prompt ? liquid.parseAndRenderSync(this.prompt, variables, {
|
|
55
|
-
strictVariables: strict
|
|
56
|
-
}) : "";
|
|
57
|
-
const compiledMessages = (this.messages || []).map((message) => _chunkFJLK5CFLjs.__spreadProps.call(void 0, _chunkFJLK5CFLjs.__spreadValues.call(void 0, {}, message), {
|
|
58
|
-
content: message.content ? liquid.parseAndRenderSync(message.content, variables, {
|
|
59
|
-
strictVariables: strict
|
|
60
|
-
}) : message.content
|
|
61
|
-
}));
|
|
62
|
-
const compiledData = _chunkFJLK5CFLjs.__spreadProps.call(void 0, _chunkFJLK5CFLjs.__spreadValues.call(void 0, {}, this), {
|
|
63
|
-
prompt: compiledPrompt,
|
|
64
|
-
messages: compiledMessages
|
|
65
|
-
});
|
|
66
|
-
return new CompiledPrompt(compiledData, this);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
const templateStr = this.prompt || JSON.stringify(this.messages);
|
|
69
|
-
throw new PromptCompilationError(
|
|
70
|
-
`Failed to compile prompt template: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
71
|
-
templateStr,
|
|
72
|
-
error
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
compile(variables = {}) {
|
|
77
|
-
return this._compile(variables, false);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Compile with validation - throws error if required variables are missing
|
|
81
|
-
* @param variables - Template variables
|
|
82
|
-
* @returns CompiledPrompt instance with compiled content
|
|
83
|
-
*/
|
|
84
|
-
compileStrict(variables) {
|
|
85
|
-
return this._compile(variables, true);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
var CompiledPrompt = class extends Prompt {
|
|
89
|
-
constructor(compiledData, original) {
|
|
90
|
-
super(compiledData);
|
|
91
|
-
this.original = original;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// src/internal/api/client.ts
|
|
96
|
-
var _openapifetch = require('openapi-fetch'); var _openapifetch2 = _interopRequireDefault(_openapifetch);
|
|
97
|
-
var _zod = require('zod');
|
|
98
|
-
var configSchema = _zod.z.object({
|
|
99
|
-
apiKey: _zod.z.string().min(1, "API key is required"),
|
|
100
|
-
endpoint: _zod.z.string().url("Endpoint must be a valid URL")
|
|
101
|
-
});
|
|
102
|
-
function createLangWatchApiClient(apiKey, endpoint) {
|
|
103
|
-
const config = configSchema.parse({
|
|
104
|
-
apiKey: apiKey != null ? apiKey : _chunkPCQVQ7SBjs.getApiKey.call(void 0, ),
|
|
105
|
-
endpoint: endpoint != null ? endpoint : _chunkPCQVQ7SBjs.getEndpoint.call(void 0, )
|
|
106
|
-
});
|
|
107
|
-
return _openapifetch2.default.call(void 0, {
|
|
108
|
-
baseUrl: config.endpoint,
|
|
109
|
-
headers: {
|
|
110
|
-
"X-Auth-Token": config.apiKey,
|
|
111
|
-
"Content-Type": "application/json"
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/prompt/service.ts
|
|
117
|
-
var PromptsError = class extends Error {
|
|
118
|
-
constructor(message, operation, originalError) {
|
|
119
|
-
super(message);
|
|
120
|
-
this.operation = operation;
|
|
121
|
-
this.originalError = originalError;
|
|
122
|
-
this.name = "PromptsError";
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
var _PromptService = class _PromptService {
|
|
126
|
-
constructor(opts) {
|
|
127
|
-
var _a;
|
|
128
|
-
this.client = (_a = opts == null ? void 0 : opts.client) != null ? _a : createLangWatchApiClient();
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Gets the singleton instance of PromptService.
|
|
132
|
-
* Creates the instance lazily on first access.
|
|
133
|
-
*/
|
|
134
|
-
static getInstance() {
|
|
135
|
-
if (!_PromptService.instance) {
|
|
136
|
-
_PromptService.instance = new _PromptService();
|
|
137
|
-
}
|
|
138
|
-
return _PromptService.instance;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Resets the singleton instance. Primarily used for testing.
|
|
142
|
-
*/
|
|
143
|
-
static resetInstance() {
|
|
144
|
-
_PromptService.instance = null;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Handles API errors by throwing a PromptsError with operation context.
|
|
148
|
-
* @param operation Description of the operation being performed.
|
|
149
|
-
* @param error The error object returned from the API client.
|
|
150
|
-
* @throws {PromptsError}
|
|
151
|
-
*/
|
|
152
|
-
handleApiError(operation, error) {
|
|
153
|
-
var _a, _b;
|
|
154
|
-
const errorMessage = typeof error === "string" ? error : (_b = (_a = error == null ? void 0 : error.error) != null ? _a : error == null ? void 0 : error.message) != null ? _b : "Unknown error occurred";
|
|
155
|
-
throw new PromptsError(
|
|
156
|
-
`Failed to ${operation}: ${errorMessage}`,
|
|
157
|
-
operation,
|
|
158
|
-
error
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Fetches all prompts from the API.
|
|
163
|
-
* @returns Array of Prompt instances.
|
|
164
|
-
* @throws {PromptsError} If the API call fails.
|
|
165
|
-
*/
|
|
166
|
-
async getAll() {
|
|
167
|
-
const { data, error } = await this.client.GET("/api/prompts");
|
|
168
|
-
if (error) this.handleApiError("fetch all prompts", error);
|
|
169
|
-
return data.map((promptData) => new Prompt(promptData));
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Fetches a single prompt by its ID.
|
|
173
|
-
* @param id The prompt's unique identifier.
|
|
174
|
-
* @returns The Prompt instance or null if not found.
|
|
175
|
-
* @throws {PromptsError} If the API call fails.
|
|
176
|
-
*/
|
|
177
|
-
async get(id) {
|
|
178
|
-
const { data, error } = await this.client.GET("/api/prompts/{id}", {
|
|
179
|
-
params: { path: { id } }
|
|
180
|
-
});
|
|
181
|
-
if (error) {
|
|
182
|
-
if (error.toString().includes("404")) {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
this.handleApiError(`fetch prompt with ID "${id}"`, error);
|
|
186
|
-
}
|
|
187
|
-
return new Prompt(data);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Validates if a prompt exists.
|
|
191
|
-
* @param id The prompt's unique identifier.
|
|
192
|
-
* @returns True if prompt exists, false otherwise.
|
|
193
|
-
* @throws {PromptsError} If the API call fails (not 404).
|
|
194
|
-
*/
|
|
195
|
-
async exists(id) {
|
|
196
|
-
try {
|
|
197
|
-
const prompt = await this.get(id);
|
|
198
|
-
return prompt !== null;
|
|
199
|
-
} catch (error) {
|
|
200
|
-
throw error;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Creates a new prompt.
|
|
205
|
-
* @param params The prompt creation payload, matching the OpenAPI schema.
|
|
206
|
-
* @returns The created Prompt instance.
|
|
207
|
-
* @throws {PromptsError} If the API call fails.
|
|
208
|
-
*/
|
|
209
|
-
async create(params) {
|
|
210
|
-
const { data, error } = await this.client.POST("/api/prompts", {
|
|
211
|
-
body: params
|
|
212
|
-
});
|
|
213
|
-
if (error) this.handleApiError("create prompt", error);
|
|
214
|
-
return new Prompt(data);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Updates an existing prompt.
|
|
218
|
-
* @param id The prompt's unique identifier.
|
|
219
|
-
* @param params The update payload, matching the OpenAPI schema.
|
|
220
|
-
* @returns The updated Prompt instance.
|
|
221
|
-
* @throws {PromptsError} If the API call fails.
|
|
222
|
-
* @remarks
|
|
223
|
-
* The API does not return the updated prompt directly, so this method fetches it after updating.
|
|
224
|
-
*/
|
|
225
|
-
async update(id, params) {
|
|
226
|
-
const { error } = await this.client.PUT("/api/prompts/{id}", {
|
|
227
|
-
params: { path: { id } },
|
|
228
|
-
body: params
|
|
229
|
-
});
|
|
230
|
-
if (error) this.handleApiError(`update prompt with ID "${id}"`, error);
|
|
231
|
-
const updatedPrompt = await this.get(id);
|
|
232
|
-
if (!updatedPrompt) {
|
|
233
|
-
throw new PromptsError(
|
|
234
|
-
"Prompt not found after update",
|
|
235
|
-
"update prompt",
|
|
236
|
-
null
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
return updatedPrompt;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Deletes a prompt by its ID.
|
|
243
|
-
* @param id The prompt's unique identifier.
|
|
244
|
-
* @throws {PromptsError} If the API call fails.
|
|
245
|
-
*/
|
|
246
|
-
async delete(id) {
|
|
247
|
-
const { error } = await this.client.DELETE("/api/prompts/{id}", {
|
|
248
|
-
params: { path: { id } }
|
|
249
|
-
});
|
|
250
|
-
if (error) this.handleApiError(`delete prompt with ID "${id}"`, error);
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Fetches all versions for a given prompt.
|
|
254
|
-
* @param id The prompt's unique identifier.
|
|
255
|
-
* @throws {PromptsError} If the API call fails.
|
|
256
|
-
*/
|
|
257
|
-
async getVersions(id) {
|
|
258
|
-
var _a;
|
|
259
|
-
const { data, error } = await this.client.GET(
|
|
260
|
-
"/api/prompts/{id}/versions",
|
|
261
|
-
{
|
|
262
|
-
params: { path: { id } }
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
if (error)
|
|
266
|
-
this.handleApiError(`fetch versions for prompt with ID "${id}"`, error);
|
|
267
|
-
const prompts = {};
|
|
268
|
-
const dataTypeCorrected = data;
|
|
269
|
-
for (const version of dataTypeCorrected) {
|
|
270
|
-
prompts[version.id] = new Prompt({
|
|
271
|
-
id: version.configId,
|
|
272
|
-
handle: version.handle,
|
|
273
|
-
scope: version.scope,
|
|
274
|
-
messages: version.configData.messages,
|
|
275
|
-
model: version.configData.model,
|
|
276
|
-
prompt: version.configData.prompt,
|
|
277
|
-
response_format: null,
|
|
278
|
-
name: `Prompt ${version.configId}@${version.id}`,
|
|
279
|
-
updatedAt: version.createdAt,
|
|
280
|
-
version: (_a = version.configData.version) != null ? _a : 0,
|
|
281
|
-
versionCreatedAt: version.createdAt,
|
|
282
|
-
versionId: version.id
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return prompts;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Creates a new version for a given prompt.
|
|
289
|
-
* @param id The prompt's unique identifier.
|
|
290
|
-
* @param params The version creation payload, matching the OpenAPI schema.
|
|
291
|
-
* @returns The updated Prompt instance.
|
|
292
|
-
* @throws {PromptsError} If the API call fails.
|
|
293
|
-
* @remarks
|
|
294
|
-
* The API does not return the updated prompt directly, so this method fetches it after creation.
|
|
295
|
-
*/
|
|
296
|
-
async createVersion(id, params) {
|
|
297
|
-
const { error } = await this.client.POST("/api/prompts/{id}/versions", {
|
|
298
|
-
params: { path: { id } },
|
|
299
|
-
body: params
|
|
300
|
-
});
|
|
301
|
-
if (error)
|
|
302
|
-
this.handleApiError(`create version for prompt with ID "${id}"`, error);
|
|
303
|
-
const updatedPrompt = await this.get(id);
|
|
304
|
-
if (!updatedPrompt) {
|
|
305
|
-
throw new PromptsError(
|
|
306
|
-
"Prompt not found after version creation",
|
|
307
|
-
"create version",
|
|
308
|
-
null
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
return updatedPrompt;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.
|
|
315
|
-
* @param name The prompt's name/identifier.
|
|
316
|
-
* @param config Local prompt configuration.
|
|
317
|
-
* @returns Object with created flag and the prompt instance.
|
|
318
|
-
* @throws {PromptsError} If the API call fails.
|
|
319
|
-
*/
|
|
320
|
-
async upsert(name, config) {
|
|
321
|
-
var _a, _b;
|
|
322
|
-
let prompt = await this.get(name);
|
|
323
|
-
let created = false;
|
|
324
|
-
if (!prompt) {
|
|
325
|
-
prompt = await this.create({ name });
|
|
326
|
-
created = true;
|
|
327
|
-
}
|
|
328
|
-
const versionData = {
|
|
329
|
-
configData: {
|
|
330
|
-
version: 1,
|
|
331
|
-
model: config.model,
|
|
332
|
-
prompt: _chunkSMXXAVMBjs.PromptConverter.extractSystemPrompt(config.messages),
|
|
333
|
-
messages: _chunkSMXXAVMBjs.PromptConverter.filterNonSystemMessages(config.messages),
|
|
334
|
-
temperature: (_a = config.modelParameters) == null ? void 0 : _a.temperature,
|
|
335
|
-
max_tokens: (_b = config.modelParameters) == null ? void 0 : _b.max_tokens,
|
|
336
|
-
inputs: [{ identifier: "input", type: "str" }],
|
|
337
|
-
outputs: [{ identifier: "output", type: "str" }]
|
|
338
|
-
},
|
|
339
|
-
commitMessage: `Updated via CLI sync`,
|
|
340
|
-
projectId: "placeholder",
|
|
341
|
-
// Will be overridden by the API
|
|
342
|
-
configId: prompt.id,
|
|
343
|
-
schemaVersion: "1.0",
|
|
344
|
-
version: 1
|
|
345
|
-
// Will be auto-incremented by the API
|
|
346
|
-
};
|
|
347
|
-
const updatedPrompt = await this.createVersion(prompt.id, versionData);
|
|
348
|
-
return {
|
|
349
|
-
created,
|
|
350
|
-
prompt: updatedPrompt
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Sync a prompt with local content, handling conflicts and version management
|
|
355
|
-
*/
|
|
356
|
-
async sync(params) {
|
|
357
|
-
var _a, _b;
|
|
358
|
-
try {
|
|
359
|
-
const response = await this.client.POST("/api/prompts/{id}/sync", {
|
|
360
|
-
params: { path: { id: params.name } },
|
|
361
|
-
body: {
|
|
362
|
-
configData: params.configData,
|
|
363
|
-
localVersion: params.localVersion,
|
|
364
|
-
commitMessage: params.commitMessage
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
if (response.error) {
|
|
368
|
-
const errorMessage = (_b = (_a = response.error) == null ? void 0 : _a.error) != null ? _b : JSON.stringify(response.error);
|
|
369
|
-
throw new Error(`Failed to sync prompt: ${errorMessage}`);
|
|
370
|
-
}
|
|
371
|
-
return {
|
|
372
|
-
action: response.data.action,
|
|
373
|
-
prompt: response.data.prompt,
|
|
374
|
-
conflictInfo: response.data.conflictInfo
|
|
375
|
-
};
|
|
376
|
-
} catch (error) {
|
|
377
|
-
const message = error instanceof Error ? error.message : "Unknown error occurred";
|
|
378
|
-
throw new PromptsError(message, "sync", error);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
_PromptService.instance = null;
|
|
383
|
-
var PromptService = _PromptService;
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
exports.PromptCompilationError = PromptCompilationError; exports.Prompt = Prompt; exports.CompiledPrompt = CompiledPrompt; exports.PromptsError = PromptsError; exports.PromptService = PromptService;
|
|
392
|
-
//# sourceMappingURL=chunk-VGHLQXKB.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-VGHLQXKB.js","../src/prompt/prompt.ts","../src/internal/api/client.ts","../src/prompt/service.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACA;ACZA,oCAAuB;AAiBhB,IAAM,uBAAA,EAAN,MAAA,QAAqC,MAAM;AAAA,EAChD,WAAA,CACE,OAAA,EACg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A;AACE,QAAA;AAC1D,MAAA;AACe,MAAA;AACJ,MAAA;AAAA;AACM,MAAA;AACF,MAAA;AACN,MAAA;AAAA;AACX,IAAA;AAEqE,IAAA;AAE9D,IAAA;AACL,MAAA;AACQ,MAAA;AACV,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAUwB,EAAA;AAtV1B,IAAA;AAuVQ,IAAA;AACgE,MAAA;AAC5B,QAAA;AAC9B,QAAA;AACe,UAAA;AACE,UAAA;AACC,UAAA;AACxB,QAAA;AACD,MAAA;AAEmB,MAAA;AAES,QAAA;AAC6B,QAAA;AAC1D,MAAA;AAEO,MAAA;AACiB,QAAA;AACA,QAAA;AACM,QAAA;AAC9B,MAAA;AACc,IAAA;AAE6B,MAAA;AACE,MAAA;AAC/C,IAAA;AACF,EAAA;AACF;AA5SkD;AAF3C;AH2TgG;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-VGHLQXKB.js","sourcesContent":[null,"import { Liquid } from \"liquidjs\";\nimport type { paths } from \"../internal/generated/openapi/api-client\";\n\n// Extract the prompt response type from OpenAPI schema\nexport type PromptResponse = NonNullable<\n paths[\"/api/prompts/{id}\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n>;\n\n// Type for template variables - supporting common data types\nexport type TemplateVariables = Record<\n string,\n string | number | boolean | object | null\n>;\n\n/**\n * Error class for template compilation issues\n */\nexport class PromptCompilationError extends Error {\n constructor(\n message: string,\n public readonly template: string,\n public readonly originalError?: any,\n ) {\n super(message);\n this.name = \"PromptCompilationError\";\n }\n}\n\n// Global Liquid instance - shared across all prompts for efficiency\nconst liquid = new Liquid({\n strictFilters: true,\n});\n\nexport class Prompt implements PromptResponse {\n public readonly id!: string;\n public readonly handle!: string | null;\n public readonly scope!: \"ORGANIZATION\" | \"PROJECT\";\n public readonly name!: string;\n public readonly updatedAt!: string;\n public readonly version!: number;\n public readonly versionId!: string;\n public readonly versionCreatedAt!: string;\n public readonly model!: string;\n public readonly prompt!: string;\n public readonly messages!: PromptResponse[\"messages\"];\n public readonly response_format!: PromptResponse[\"response_format\"];\n\n constructor(promptData: PromptResponse) {\n this.id = promptData.id;\n this.handle = promptData.handle;\n this.scope = promptData.scope;\n this.name = promptData.name;\n this.updatedAt = promptData.updatedAt;\n this.version = promptData.version;\n this.versionId = promptData.versionId;\n this.versionCreatedAt = promptData.versionCreatedAt;\n this.model = promptData.model;\n this.prompt = promptData.prompt;\n this.messages = promptData.messages;\n this.response_format = promptData.response_format;\n }\n\n /**\n * Get the raw prompt data from the API\n */\n get raw(): PromptResponse {\n return this;\n }\n\n /**\n * Compile the prompt template with provided variables (lenient - missing variables become empty)\n * @param variables - Object containing variable values for template compilation\n * @returns CompiledPrompt instance with compiled content\n */\n private _compile(\n variables: TemplateVariables,\n strict: boolean,\n ): CompiledPrompt {\n try {\n // Compile main prompt\n const compiledPrompt = this.prompt\n ? liquid.parseAndRenderSync(this.prompt, variables, {\n strictVariables: strict,\n })\n : \"\";\n\n // Compile messages\n const compiledMessages = (this.messages || []).map((message) => ({\n ...message,\n content: message.content\n ? liquid.parseAndRenderSync(message.content, variables, {\n strictVariables: strict,\n })\n : message.content,\n }));\n\n // Create new prompt data with compiled content\n const compiledData: PromptResponse = {\n ...this,\n prompt: compiledPrompt,\n messages: compiledMessages,\n };\n\n return new CompiledPrompt(compiledData, this);\n } catch (error) {\n const templateStr = this.prompt || JSON.stringify(this.messages);\n throw new PromptCompilationError(\n `Failed to compile prompt template: ${\n error instanceof Error ? error.message : \"Unknown error\"\n }`,\n templateStr,\n error,\n );\n }\n }\n\n compile(variables: TemplateVariables = {}): CompiledPrompt {\n return this._compile(variables, false);\n }\n\n /**\n * Compile with validation - throws error if required variables are missing\n * @param variables - Template variables\n * @returns CompiledPrompt instance with compiled content\n */\n compileStrict(variables: TemplateVariables): CompiledPrompt {\n return this._compile(variables, true);\n }\n}\n\n/**\n * Represents a compiled prompt that extends Prompt with reference to the original template\n */\nexport class CompiledPrompt extends Prompt {\n constructor(\n compiledData: PromptResponse,\n public readonly original: Prompt,\n ) {\n super(compiledData);\n }\n}\n","import openApiCreateClient from \"openapi-fetch\";\nimport type { paths } from \"../generated/openapi/api-client\";\nimport { z } from \"zod\";\nimport { getApiKey, getEndpoint } from \"../../client\";\n\n// Define the client type explicitly to avoid naming issues\nexport type LangwatchApiClient = ReturnType<typeof openApiCreateClient<paths>>;\n\nconst configSchema = z.object({\n apiKey: z.string().min(1, \"API key is required\"),\n endpoint: z.string().url(\"Endpoint must be a valid URL\"),\n});\n\nexport function createLangWatchApiClient(apiKey?: string | undefined, endpoint?: string | undefined ): LangwatchApiClient {\n // This will error if the config is invalid\n const config = configSchema.parse({\n apiKey: apiKey ?? getApiKey(),\n endpoint: endpoint ?? getEndpoint(),\n });\n\n return openApiCreateClient<paths>({\n baseUrl: config.endpoint,\n headers: {\n \"X-Auth-Token\": config.apiKey,\n \"Content-Type\": \"application/json\",\n },\n });\n}\n\n\n","import {\n createLangWatchApiClient,\n type LangwatchApiClient,\n} from \"../internal/api/client\";\nimport type { paths } from \"../internal/generated/openapi/api-client\";\nimport { Prompt, type PromptResponse } from \"./prompt\";\nimport { PromptConverter } from \"./converter\";\n\n// Extract types directly from OpenAPI schema for strong type safety.\ntype CreatePromptBody = NonNullable<\n paths[\"/api/prompts\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\ntype UpdatePromptBody = NonNullable<\n paths[\"/api/prompts/{id}\"][\"put\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\ntype CreateVersionBody = NonNullable<\n paths[\"/api/prompts/{id}/versions\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\ntype SyncBody = NonNullable<\n paths[\"/api/prompts/{id}/sync\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\n/**\n * Custom error class for Prompts API operations.\n * Provides context about the failed operation and the original error.\n */\nexport class PromptsError extends Error {\n constructor(\n message: string,\n public readonly operation: string,\n public readonly originalError?: any,\n ) {\n super(message);\n this.name = \"PromptsError\";\n }\n}\n\nexport type SyncAction = \"created\" | \"updated\" | \"conflict\" | \"up_to_date\";\n\nexport type ConfigData = NonNullable<\n paths[\"/api/prompts/{id}/sync\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"][\"configData\"];\n\nexport interface SyncResult {\n action: SyncAction;\n prompt?: PromptResponse;\n conflictInfo?: {\n localVersion: number;\n remoteVersion: number;\n differences: string[];\n remoteConfigData: ConfigData;\n };\n}\n\ninterface PromptServiceOptions {\n client?: LangwatchApiClient;\n}\n\n/**\n * Service for managing prompt resources via the Langwatch API.\n *\n * Responsibilities:\n * - CRUD operations for prompts\n * - Creating prompt versions\n * - Error handling with contextual information\n *\n * All methods return Prompt instances, which encapsulate prompt data and template logic.\n */\nexport class PromptService {\n private client: LangwatchApiClient;\n private static instance: PromptService | null = null;\n\n constructor(opts?: PromptServiceOptions) {\n this.client = opts?.client ?? createLangWatchApiClient();\n }\n\n /**\n * Gets the singleton instance of PromptService.\n * Creates the instance lazily on first access.\n */\n public static getInstance(): PromptService {\n if (!PromptService.instance) {\n PromptService.instance = new PromptService();\n }\n return PromptService.instance;\n }\n\n /**\n * Resets the singleton instance. Primarily used for testing.\n */\n public static resetInstance(): void {\n PromptService.instance = null;\n }\n\n /**\n * Handles API errors by throwing a PromptsError with operation context.\n * @param operation Description of the operation being performed.\n * @param error The error object returned from the API client.\n * @throws {PromptsError}\n */\n private handleApiError(operation: string, error: any): never {\n const errorMessage =\n typeof error === \"string\"\n ? error\n : error?.error ?? error?.message ?? \"Unknown error occurred\";\n throw new PromptsError(\n `Failed to ${operation}: ${errorMessage}`,\n operation,\n error,\n );\n }\n\n /**\n * Fetches all prompts from the API.\n * @returns Array of Prompt instances.\n * @throws {PromptsError} If the API call fails.\n */\n async getAll(): Promise<Prompt[]> {\n const { data, error } = await this.client.GET(\"/api/prompts\");\n if (error) this.handleApiError(\"fetch all prompts\", error);\n return data.map((promptData) => new Prompt(promptData));\n }\n\n /**\n * Fetches a single prompt by its ID.\n * @param id The prompt's unique identifier.\n * @returns The Prompt instance or null if not found.\n * @throws {PromptsError} If the API call fails.\n */\n async get(id: string): Promise<Prompt | null> {\n const { data, error } = await this.client.GET(\"/api/prompts/{id}\", {\n params: { path: { id } },\n });\n if (error) {\n if (error.toString().includes(\"404\")) {\n return null;\n }\n this.handleApiError(`fetch prompt with ID \"${id}\"`, error);\n }\n return new Prompt(data);\n }\n\n /**\n * Validates if a prompt exists.\n * @param id The prompt's unique identifier.\n * @returns True if prompt exists, false otherwise.\n * @throws {PromptsError} If the API call fails (not 404).\n */\n async exists(id: string): Promise<boolean> {\n try {\n const prompt = await this.get(id);\n return prompt !== null;\n } catch (error) {\n throw error; // Re-throw non-404 errors\n }\n }\n\n /**\n * Creates a new prompt.\n * @param params The prompt creation payload, matching the OpenAPI schema.\n * @returns The created Prompt instance.\n * @throws {PromptsError} If the API call fails.\n */\n async create(params: CreatePromptBody): Promise<Prompt> {\n const { data, error } = await this.client.POST(\"/api/prompts\", {\n body: params,\n });\n if (error) this.handleApiError(\"create prompt\", error);\n return new Prompt(data);\n }\n\n /**\n * Updates an existing prompt.\n * @param id The prompt's unique identifier.\n * @param params The update payload, matching the OpenAPI schema.\n * @returns The updated Prompt instance.\n * @throws {PromptsError} If the API call fails.\n * @remarks\n * The API does not return the updated prompt directly, so this method fetches it after updating.\n */\n async update(id: string, params: UpdatePromptBody): Promise<Prompt> {\n const { error } = await this.client.PUT(\"/api/prompts/{id}\", {\n params: { path: { id } },\n body: params,\n });\n if (error) this.handleApiError(`update prompt with ID \"${id}\"`, error);\n // TODO: This is a workaround to get the updated prompt. It would be better to return the updated prompt directly.\n const updatedPrompt = await this.get(id);\n if (!updatedPrompt) {\n throw new PromptsError(\n \"Prompt not found after update\",\n \"update prompt\",\n null,\n );\n }\n return updatedPrompt;\n }\n\n /**\n * Deletes a prompt by its ID.\n * @param id The prompt's unique identifier.\n * @throws {PromptsError} If the API call fails.\n */\n async delete(id: string): Promise<void> {\n const { error } = await this.client.DELETE(\"/api/prompts/{id}\", {\n params: { path: { id } },\n });\n if (error) this.handleApiError(`delete prompt with ID \"${id}\"`, error);\n }\n\n /**\n * Fetches all versions for a given prompt.\n * @param id The prompt's unique identifier.\n * @throws {PromptsError} If the API call fails.\n */\n async getVersions(id: string): Promise<Record<string, Prompt>> {\n const { data, error } = await this.client.GET(\n \"/api/prompts/{id}/versions\",\n {\n params: { path: { id } },\n },\n );\n if (error)\n this.handleApiError(`fetch versions for prompt with ID \"${id}\"`, error);\n\n const prompts: Record<string, Prompt> = {};\n const dataTypeCorrected = data as unknown as NonNullable<\n paths[\"/api/prompts/{id}/versions\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >[];\n\n for (const version of dataTypeCorrected) {\n prompts[version.id] = new Prompt({\n id: version.configId,\n handle: version.handle,\n scope: version.scope,\n messages: version.configData.messages,\n model: version.configData.model,\n prompt: version.configData.prompt,\n response_format: null,\n name: `Prompt ${version.configId}@${version.id}`,\n updatedAt: version.createdAt,\n version: version.configData.version ?? 0,\n versionCreatedAt: version.createdAt,\n versionId: version.id,\n });\n }\n\n return prompts;\n }\n\n /**\n * Creates a new version for a given prompt.\n * @param id The prompt's unique identifier.\n * @param params The version creation payload, matching the OpenAPI schema.\n * @returns The updated Prompt instance.\n * @throws {PromptsError} If the API call fails.\n * @remarks\n * The API does not return the updated prompt directly, so this method fetches it after creation.\n */\n async createVersion(id: string, params: CreateVersionBody): Promise<Prompt> {\n const { error } = await this.client.POST(\"/api/prompts/{id}/versions\", {\n params: { path: { id } },\n body: params,\n });\n if (error)\n this.handleApiError(`create version for prompt with ID \"${id}\"`, error);\n // TODO: This is a workaround to get the updated prompt. It would be better to return the updated prompt directly.\n const updatedPrompt = await this.get(id);\n if (!updatedPrompt) {\n throw new PromptsError(\n \"Prompt not found after version creation\",\n \"create version\",\n null,\n );\n }\n return updatedPrompt;\n }\n\n /**\n * Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.\n * @param name The prompt's name/identifier.\n * @param config Local prompt configuration.\n * @returns Object with created flag and the prompt instance.\n * @throws {PromptsError} If the API call fails.\n */\n async upsert(\n name: string,\n config: {\n model: string;\n modelParameters?: {\n temperature?: number;\n max_tokens?: number;\n };\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>;\n },\n ): Promise<{ created: boolean; prompt: Prompt }> {\n let prompt = await this.get(name);\n let created = false;\n\n if (!prompt) {\n prompt = await this.create({ name });\n created = true;\n }\n\n // Create a new version with the updated config using the converter\n const versionData = {\n configData: {\n version: 1,\n model: config.model,\n prompt: PromptConverter.extractSystemPrompt(config.messages),\n messages: PromptConverter.filterNonSystemMessages(config.messages),\n temperature: config.modelParameters?.temperature,\n max_tokens: config.modelParameters?.max_tokens,\n inputs: [{ identifier: \"input\", type: \"str\" as const }],\n outputs: [{ identifier: \"output\", type: \"str\" as const }],\n },\n commitMessage: `Updated via CLI sync`,\n projectId: \"placeholder\", // Will be overridden by the API\n configId: prompt.id,\n schemaVersion: \"1.0\" as const,\n version: 1, // Will be auto-incremented by the API\n } as any; // Type assertion to bypass strict typing for now\n\n const updatedPrompt = await this.createVersion(prompt.id, versionData);\n\n return {\n created,\n prompt: updatedPrompt,\n };\n }\n\n /**\n * Sync a prompt with local content, handling conflicts and version management\n */\n async sync(params: {\n name: string;\n configData: ConfigData;\n localVersion?: number;\n commitMessage?: string;\n }): Promise<SyncResult> {\n try {\n const response = await this.client.POST(\"/api/prompts/{id}/sync\", {\n params: { path: { id: params.name } },\n body: {\n configData: params.configData,\n localVersion: params.localVersion,\n commitMessage: params.commitMessage,\n },\n });\n\n if (response.error) {\n const errorMessage =\n response.error?.error ?? JSON.stringify(response.error);\n throw new Error(`Failed to sync prompt: ${errorMessage}`);\n }\n\n return {\n action: response.data.action as SyncAction,\n prompt: response.data.prompt as PromptResponse,\n conflictInfo: response.data.conflictInfo,\n };\n } catch (error) {\n const message =\n error instanceof Error ? error.message : \"Unknown error occurred\";\n throw new PromptsError(message, \"sync\", error);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/prompt/converter.ts"],"sourcesContent":["import type { Prompt } from \"./prompt\";\nimport type { LocalPromptConfig, MaterializedPrompt } from \"../cli/types\";\n\n/**\n * Converter utility for transforming between YAML prompt format and API service format.\n *\n * The YAML format follows the GitHub .prompt.yaml file format standard,\n * while the API format is our internal prompt service schema tied to the database.\n *\n * This separation allows us to maintain and evolve both formats independently\n * while keeping the conversion logic centralized and well-tested.\n */\nexport class PromptConverter {\n /**\n * Converts a Prompt instance from the API service to the MaterializedPrompt format\n * used for saving to the .materialized directory.\n */\n static fromApiToMaterialized(prompt: Prompt): MaterializedPrompt {\n return {\n id: prompt.id,\n name: prompt.name,\n version: prompt.version,\n versionId: prompt.versionId,\n model: prompt.model,\n messages: prompt.messages,\n prompt: prompt.prompt,\n updatedAt: prompt.updatedAt,\n versionCreatedAt: prompt.versionCreatedAt,\n };\n }\n\n /**\n * Converts a MaterializedPrompt to the YAML content structure\n * for saving to .prompt.yaml files.\n */\n static fromMaterializedToYaml(prompt: MaterializedPrompt): {\n model: string;\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>;\n } {\n return {\n model: prompt.model,\n messages: prompt.messages,\n };\n }\n\n /**\n * Converts a LocalPromptConfig (loaded from YAML) to the format\n * expected by the API service for upserting.\n */\n static fromLocalToApiFormat(config: LocalPromptConfig): {\n model: string;\n modelParameters?: {\n temperature?: number;\n max_tokens?: number;\n };\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>;\n } {\n return {\n model: config.model,\n modelParameters: config.modelParameters,\n messages: config.messages,\n };\n }\n\n /**\n * Extracts the system prompt from messages array.\n * Used when converting to API format that separates system prompt from messages.\n */\n static extractSystemPrompt(messages: Array<{ role: string; content: string }>): string {\n return messages.find(m => m.role === \"system\")?.content || \"\";\n }\n\n /**\n * Filters out system messages from the messages array.\n * Used when converting to API format that handles system prompt separately.\n */\n static filterNonSystemMessages(messages: Array<{ role: string; content: string }>) {\n return messages.filter(m => m.role !== \"system\");\n }\n\n /**\n * Converts version specification strings to actual version constraints.\n * Handles npm-style version specs like \"latest\", \"5\", \"^5\", etc.\n */\n static parseVersionSpec(versionSpec: string): {\n type: \"latest\" | \"exact\" | \"tag\";\n value: string;\n } {\n if (versionSpec === \"latest\") {\n return { type: \"latest\", value: \"latest\" };\n }\n\n // For now, treat everything else as tags until we implement proper semver\n if (/^\\d+$/.test(versionSpec)) {\n return { type: \"exact\", value: versionSpec };\n }\n\n // Handle prefixes like ^, ~, etc. as tags for now\n return { type: \"tag\", value: versionSpec };\n }\n\n /**\n * Validates that a YAML config can be safely converted to API format.\n * Returns validation errors if any, or null if valid.\n */\n static validateForApiConversion(config: LocalPromptConfig): string[] {\n const errors: string[] = [];\n\n if (!config.model?.trim()) {\n errors.push(\"Model is required and cannot be empty\");\n }\n\n if (!config.messages || config.messages.length === 0) {\n errors.push(\"At least one message is required\");\n }\n\n if (config.messages) {\n config.messages.forEach((message, index) => {\n if (![\"system\", \"user\", \"assistant\"].includes(message.role)) {\n errors.push(`Message ${index}: role must be 'system', 'user', or 'assistant'`);\n }\n if (!message.content?.trim()) {\n errors.push(`Message ${index}: content cannot be empty`);\n }\n });\n }\n\n return errors;\n }\n}"],"mappings":";AAYO,IAAM,kBAAN,MAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK3B,OAAO,sBAAsB,QAAoC;AAC/D,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,MACX,MAAM,OAAO;AAAA,MACb,SAAS,OAAO;AAAA,MAChB,WAAW,OAAO;AAAA,MAClB,OAAO,OAAO;AAAA,MACd,UAAU,OAAO;AAAA,MACjB,QAAQ,OAAO;AAAA,MACf,WAAW,OAAO;AAAA,MAClB,kBAAkB,OAAO;AAAA,IAC3B;AAAA,EACF;AAAA;AAAA;AAAA;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,WAAW,EAAE,SAAS,QAAQ,IAAI,GAAG;AAC3D,iBAAO,KAAK,WAAW,KAAK,iDAAiD;AAAA,QAC/E;AACA,YAAI,GAACA,MAAA,QAAQ,YAAR,gBAAAA,IAAiB,SAAQ;AAC5B,iBAAO,KAAK,WAAW,KAAK,2BAA2B;AAAA,QACzD;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":["_a"]}
|
package/dist/chunk-Y666BJA5.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
2
|
-
import { Attributes } from '@opentelemetry/api';
|
|
3
|
-
import { S as SpanProcessingExcludeRule } from './filterable-batch-span-processor-zO5kcjBY.js';
|
|
4
|
-
|
|
5
|
-
interface SetupOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The API key to use for the LangWatch API.
|
|
8
|
-
*/
|
|
9
|
-
apiKey?: string;
|
|
10
|
-
/**
|
|
11
|
-
* The endpoint to use for the LangWatch API.
|
|
12
|
-
*/
|
|
13
|
-
endpoint?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The span processors to use for the OpenTelemetry SDK.
|
|
16
|
-
*
|
|
17
|
-
* If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has
|
|
18
|
-
* been initialized.
|
|
19
|
-
*/
|
|
20
|
-
otelSpanProcessors?: SpanProcessor[];
|
|
21
|
-
/**
|
|
22
|
-
* The span processing exclude rules to use for the OpenTelemetry SDK.
|
|
23
|
-
*
|
|
24
|
-
* If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has
|
|
25
|
-
* been initialized.
|
|
26
|
-
*
|
|
27
|
-
* If you are using the `otelSpanProcessors` option, then these will be ignored.
|
|
28
|
-
*/
|
|
29
|
-
otelSpanProcessingExcludeRules?: SpanProcessingExcludeRule[];
|
|
30
|
-
/**
|
|
31
|
-
* Whether to skip the automatic setup of the OpenTelemetry SDK. If this is set, then
|
|
32
|
-
* the LangWatch SDK will not attempt to setup the OpenTelemetry SDK. You will need to
|
|
33
|
-
* setup the OpenTelemetry yourself, and ensure that a SpanProcessor is added to the
|
|
34
|
-
* OpenTelemetry SDK that will send traces to the LangWatch API.
|
|
35
|
-
*/
|
|
36
|
-
skipOpenTelemetrySetup?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Whether to disable the automatic capture of input.
|
|
39
|
-
*/
|
|
40
|
-
disableAutomaticInputCapture?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Whether to disable the automatic capture of output.
|
|
43
|
-
*/
|
|
44
|
-
disableAutomaticOutputCapture?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* The base attributes to use for the OpenTelemetry SDK.
|
|
47
|
-
*/
|
|
48
|
-
baseAttributes?: Attributes;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type { SetupOptions as S };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
2
|
-
import { Attributes } from '@opentelemetry/api';
|
|
3
|
-
import { S as SpanProcessingExcludeRule } from './filterable-batch-span-processor-zO5kcjBY.mjs';
|
|
4
|
-
|
|
5
|
-
interface SetupOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The API key to use for the LangWatch API.
|
|
8
|
-
*/
|
|
9
|
-
apiKey?: string;
|
|
10
|
-
/**
|
|
11
|
-
* The endpoint to use for the LangWatch API.
|
|
12
|
-
*/
|
|
13
|
-
endpoint?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The span processors to use for the OpenTelemetry SDK.
|
|
16
|
-
*
|
|
17
|
-
* If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has
|
|
18
|
-
* been initialized.
|
|
19
|
-
*/
|
|
20
|
-
otelSpanProcessors?: SpanProcessor[];
|
|
21
|
-
/**
|
|
22
|
-
* The span processing exclude rules to use for the OpenTelemetry SDK.
|
|
23
|
-
*
|
|
24
|
-
* If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has
|
|
25
|
-
* been initialized.
|
|
26
|
-
*
|
|
27
|
-
* If you are using the `otelSpanProcessors` option, then these will be ignored.
|
|
28
|
-
*/
|
|
29
|
-
otelSpanProcessingExcludeRules?: SpanProcessingExcludeRule[];
|
|
30
|
-
/**
|
|
31
|
-
* Whether to skip the automatic setup of the OpenTelemetry SDK. If this is set, then
|
|
32
|
-
* the LangWatch SDK will not attempt to setup the OpenTelemetry SDK. You will need to
|
|
33
|
-
* setup the OpenTelemetry yourself, and ensure that a SpanProcessor is added to the
|
|
34
|
-
* OpenTelemetry SDK that will send traces to the LangWatch API.
|
|
35
|
-
*/
|
|
36
|
-
skipOpenTelemetrySetup?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Whether to disable the automatic capture of input.
|
|
39
|
-
*/
|
|
40
|
-
disableAutomaticInputCapture?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Whether to disable the automatic capture of output.
|
|
43
|
-
*/
|
|
44
|
-
disableAutomaticOutputCapture?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* The base attributes to use for the OpenTelemetry SDK.
|
|
47
|
-
*/
|
|
48
|
-
baseAttributes?: Attributes;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type { SetupOptions as S };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { S as SetupOptions } from './client-XyCqclCi.mjs';
|
|
2
|
-
import '@opentelemetry/sdk-trace-base';
|
|
3
|
-
import '@opentelemetry/api';
|
|
4
|
-
import './filterable-batch-span-processor-zO5kcjBY.mjs';
|
|
5
|
-
|
|
6
|
-
declare function setupLangWatch(options?: SetupOptions): Promise<void>;
|
|
7
|
-
|
|
8
|
-
export { setupLangWatch };
|
package/dist/client-browser.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { S as SetupOptions } from './client-B2HqIKg6.js';
|
|
2
|
-
import '@opentelemetry/sdk-trace-base';
|
|
3
|
-
import '@opentelemetry/api';
|
|
4
|
-
import './filterable-batch-span-processor-zO5kcjBY.js';
|
|
5
|
-
|
|
6
|
-
declare function setupLangWatch(options?: SetupOptions): Promise<void>;
|
|
7
|
-
|
|
8
|
-
export { setupLangWatch };
|