langwatch 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{add-4WXEWG5H.js → add-CGTO6GC2.js} +28 -32
- package/dist/add-CGTO6GC2.js.map +1 -0
- package/dist/{add-D2WVVKIP.mjs → add-XCI65PVN.mjs} +14 -18
- package/dist/add-XCI65PVN.mjs.map +1 -0
- package/dist/{chunk-P4SQTYGN.js → chunk-2GYC6KEA.js} +32 -32
- package/dist/{chunk-P4SQTYGN.js.map → chunk-2GYC6KEA.js.map} +1 -1
- package/dist/{chunk-CAZONSXV.js → chunk-36XAYVMC.js} +186 -76
- package/dist/chunk-36XAYVMC.js.map +1 -0
- package/dist/{chunk-ZIULPOMQ.mjs → chunk-3P4ROGZJ.mjs} +4 -4
- package/dist/{chunk-DLJO7AK5.mjs → chunk-AD7QRYIJ.mjs} +2 -2
- package/dist/{chunk-DISMHYXC.js → chunk-CKIZDPIJ.js} +24 -22
- package/dist/chunk-CKIZDPIJ.js.map +1 -0
- package/dist/{chunk-7OZKH5K2.js → chunk-DZH6SY3Z.js} +10 -10
- package/dist/{chunk-7OZKH5K2.js.map → chunk-DZH6SY3Z.js.map} +1 -1
- package/dist/{chunk-N2V6J3U2.mjs → chunk-FEL5FLHA.mjs} +2 -2
- package/dist/{chunk-H5PON53W.mjs → chunk-GAFUPYJ3.mjs} +334 -143
- package/dist/chunk-GAFUPYJ3.mjs.map +1 -0
- package/dist/{chunk-SVXNUWZI.js → chunk-HVW45GST.js} +345 -154
- package/dist/chunk-HVW45GST.js.map +1 -0
- package/dist/{chunk-YNQ44U6D.mjs → chunk-I2SOBPAF.mjs} +23 -21
- package/dist/chunk-I2SOBPAF.mjs.map +1 -0
- package/dist/{chunk-ECOC36EA.js → chunk-J7B7BNDN.js} +11 -11
- package/dist/{chunk-ECOC36EA.js.map → chunk-J7B7BNDN.js.map} +1 -1
- package/dist/{chunk-QZGTM76F.mjs → chunk-JPWKINZP.mjs} +2 -2
- package/dist/{chunk-OXBO24RB.js → chunk-OHM7JUMR.js} +15 -2
- package/dist/chunk-OHM7JUMR.js.map +1 -0
- package/dist/chunk-PYVDTUA6.mjs +352 -0
- package/dist/chunk-PYVDTUA6.mjs.map +1 -0
- package/dist/{chunk-YH5TIVK2.js → chunk-SNDTNU3T.js} +2 -2
- package/dist/{chunk-YH5TIVK2.js.map → chunk-SNDTNU3T.js.map} +1 -1
- package/dist/{chunk-CU3443HD.mjs → chunk-URTD2WOC.mjs} +14 -1
- package/dist/{chunk-YKFTFYKK.mjs → chunk-WOBPYIKO.mjs} +2 -2
- package/dist/chunk-WOBPYIKO.mjs.map +1 -0
- package/dist/{chunk-QCYYSMCU.js → chunk-Z3NTWVVA.js} +2 -2
- package/dist/chunk-Z3NTWVVA.js.map +1 -0
- package/dist/cli/index.js +8 -8
- package/dist/cli/index.mjs +8 -8
- package/dist/{create-OQEMO4MU.mjs → create-LXQB4EFB.mjs} +4 -5
- package/dist/{create-OQEMO4MU.mjs.map → create-LXQB4EFB.mjs.map} +1 -1
- package/dist/{create-4LG4N2A4.js → create-S5RDGF3H.js} +9 -10
- package/dist/create-S5RDGF3H.js.map +1 -0
- package/dist/{implementation-BIlL6-SW.d.ts → implementation-DsHp9FYU.d.ts} +1 -1
- package/dist/{implementation-fAgqv8OM.d.mts → implementation-nE9dgTwc.d.mts} +1 -1
- package/dist/{index-DTEZr0Jn.d.mts → index-D7rKIGrO.d.mts} +12 -12
- package/dist/{index-DTEZr0Jn.d.ts → index-D7rKIGrO.d.ts} +12 -12
- package/dist/index.d.mts +256 -11
- package/dist/index.d.ts +256 -11
- package/dist/index.js +135 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -10
- package/dist/index.mjs.map +1 -1
- package/dist/{init-MQXXHCNT.mjs → init-T4YDPHBA.mjs} +4 -5
- package/dist/{init-MQXXHCNT.mjs.map → init-T4YDPHBA.mjs.map} +1 -1
- package/dist/init-UADBKUJU.js +15 -0
- package/dist/init-UADBKUJU.js.map +1 -0
- package/dist/{list-GIAXAAH5.js → list-GRKVAGJS.js} +14 -15
- package/dist/list-GRKVAGJS.js.map +1 -0
- package/dist/{list-PFWV7IU6.mjs → list-XHXVFN24.mjs} +13 -14
- package/dist/list-XHXVFN24.mjs.map +1 -0
- package/dist/{login-3STX2FAO.js → login-4GWM5I6F.js} +4 -4
- package/dist/{login-3STX2FAO.js.map → login-4GWM5I6F.js.map} +1 -1
- package/dist/{login-BYLXS23I.mjs → login-EKE7SFN3.mjs} +3 -3
- package/dist/observability-sdk/index.d.mts +4 -3
- package/dist/observability-sdk/index.d.ts +4 -3
- package/dist/observability-sdk/index.js +7 -7
- package/dist/observability-sdk/index.mjs +6 -6
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +2 -1
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +2 -1
- package/dist/observability-sdk/instrumentation/langchain/index.js +19 -19
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +3 -3
- package/dist/observability-sdk/setup/node/index.d.mts +1 -1
- package/dist/observability-sdk/setup/node/index.d.ts +1 -1
- package/dist/observability-sdk/setup/node/index.js +15 -15
- package/dist/observability-sdk/setup/node/index.mjs +4 -4
- package/dist/{remove-U3PILQDV.js → remove-7EXB2Z6R.js} +17 -18
- package/dist/remove-7EXB2Z6R.js.map +1 -0
- package/dist/{remove-FTF3EBYV.mjs → remove-W44FQ5MF.mjs} +9 -10
- package/dist/{remove-FTF3EBYV.mjs.map → remove-W44FQ5MF.mjs.map} +1 -1
- package/dist/{sync-T3T22GVZ.js → sync-V7WRMNJV.js} +31 -35
- package/dist/sync-V7WRMNJV.js.map +1 -0
- package/dist/{sync-FOW7DHAH.mjs → sync-XGFABFAW.mjs} +16 -20
- package/dist/sync-XGFABFAW.mjs.map +1 -0
- package/dist/{types-DyUmlaDx.d.ts → types-B9772cUR.d.ts} +98 -29
- package/dist/{types-jrEEZt9d.d.mts → types-DbPAi4US.d.mts} +98 -29
- package/package.json +4 -3
- package/dist/add-4WXEWG5H.js.map +0 -1
- package/dist/add-D2WVVKIP.mjs.map +0 -1
- package/dist/chunk-CAZONSXV.js.map +0 -1
- package/dist/chunk-CKVDNVFL.mjs +0 -242
- package/dist/chunk-CKVDNVFL.mjs.map +0 -1
- package/dist/chunk-DISMHYXC.js.map +0 -1
- package/dist/chunk-DSIQSULK.js +0 -152
- package/dist/chunk-DSIQSULK.js.map +0 -1
- package/dist/chunk-H5PON53W.mjs.map +0 -1
- package/dist/chunk-OXBO24RB.js.map +0 -1
- package/dist/chunk-QCYYSMCU.js.map +0 -1
- package/dist/chunk-R6FBJN7K.js +0 -115
- package/dist/chunk-R6FBJN7K.js.map +0 -1
- package/dist/chunk-SVXNUWZI.js.map +0 -1
- package/dist/chunk-V5M3HUBV.mjs +0 -115
- package/dist/chunk-V5M3HUBV.mjs.map +0 -1
- package/dist/chunk-YEGQXDTE.mjs +0 -152
- package/dist/chunk-YEGQXDTE.mjs.map +0 -1
- package/dist/chunk-YKFTFYKK.mjs.map +0 -1
- package/dist/chunk-YNQ44U6D.mjs.map +0 -1
- package/dist/create-4LG4N2A4.js.map +0 -1
- package/dist/init-EKNL2SQE.js +0 -16
- package/dist/init-EKNL2SQE.js.map +0 -1
- package/dist/list-GIAXAAH5.js.map +0 -1
- package/dist/list-PFWV7IU6.mjs.map +0 -1
- package/dist/remove-U3PILQDV.js.map +0 -1
- package/dist/sync-FOW7DHAH.mjs.map +0 -1
- package/dist/sync-T3T22GVZ.js.map +0 -1
- /package/dist/{chunk-ZIULPOMQ.mjs.map → chunk-3P4ROGZJ.mjs.map} +0 -0
- /package/dist/{chunk-DLJO7AK5.mjs.map → chunk-AD7QRYIJ.mjs.map} +0 -0
- /package/dist/{chunk-N2V6J3U2.mjs.map → chunk-FEL5FLHA.mjs.map} +0 -0
- /package/dist/{chunk-QZGTM76F.mjs.map → chunk-JPWKINZP.mjs.map} +0 -0
- /package/dist/{chunk-CU3443HD.mjs.map → chunk-URTD2WOC.mjs.map} +0 -0
- /package/dist/{login-BYLXS23I.mjs.map → login-EKE7SFN3.mjs.map} +0 -0
package/dist/chunk-R6FBJN7K.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/cli/utils/promptConverter.ts
|
|
2
|
-
var PromptConverter = class {
|
|
3
|
-
/**
|
|
4
|
-
* Converts a Prompt instance from the API service to the MaterializedPrompt format
|
|
5
|
-
* used for saving to the .materialized directory.
|
|
6
|
-
*/
|
|
7
|
-
static fromApiToMaterialized(prompt) {
|
|
8
|
-
return {
|
|
9
|
-
id: prompt.id,
|
|
10
|
-
name: prompt.name,
|
|
11
|
-
version: prompt.version,
|
|
12
|
-
versionId: prompt.versionId,
|
|
13
|
-
model: prompt.model,
|
|
14
|
-
messages: prompt.messages,
|
|
15
|
-
prompt: prompt.prompt,
|
|
16
|
-
temperature: prompt.temperature,
|
|
17
|
-
maxTokens: prompt.maxTokens,
|
|
18
|
-
inputs: prompt.inputs,
|
|
19
|
-
outputs: prompt.outputs,
|
|
20
|
-
updatedAt: prompt.updatedAt
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Converts a MaterializedPrompt to the YAML content structure
|
|
25
|
-
* for saving to .prompt.yaml files.
|
|
26
|
-
*/
|
|
27
|
-
static fromMaterializedToYaml(prompt) {
|
|
28
|
-
const result = {
|
|
29
|
-
model: prompt.model,
|
|
30
|
-
messages: prompt.messages
|
|
31
|
-
};
|
|
32
|
-
if (prompt.temperature !== void 0 || prompt.maxTokens !== void 0) {
|
|
33
|
-
result.modelParameters = {};
|
|
34
|
-
if (prompt.temperature !== void 0) {
|
|
35
|
-
result.modelParameters.temperature = prompt.temperature;
|
|
36
|
-
}
|
|
37
|
-
if (prompt.maxTokens !== void 0) {
|
|
38
|
-
result.modelParameters.maxTokens = prompt.maxTokens;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Converts a LocalPromptConfig (loaded from YAML) to the format
|
|
45
|
-
* expected by the API service for upserting.
|
|
46
|
-
*/
|
|
47
|
-
static fromLocalToApiFormat(config) {
|
|
48
|
-
return {
|
|
49
|
-
model: config.model,
|
|
50
|
-
modelParameters: config.modelParameters,
|
|
51
|
-
messages: config.messages
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extracts the system prompt from messages array.
|
|
56
|
-
* Used when converting to API format that separates system prompt from messages.
|
|
57
|
-
*/
|
|
58
|
-
static extractSystemPrompt(messages) {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
return (_b = (_a = messages.find((m) => m.role === "system")) == null ? void 0 : _a.content) != null ? _b : "";
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Filters out system messages from the messages array.
|
|
64
|
-
* Used when converting to API format that handles system prompt separately.
|
|
65
|
-
*/
|
|
66
|
-
static filterNonSystemMessages(messages) {
|
|
67
|
-
return messages.filter((m) => m.role !== "system");
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Converts version specification strings to actual version constraints.
|
|
71
|
-
* Handles npm-style version specs like "latest", "5", "^5", etc.
|
|
72
|
-
*/
|
|
73
|
-
static parseVersionSpec(versionSpec) {
|
|
74
|
-
if (versionSpec === "latest") {
|
|
75
|
-
return { type: "latest", value: "latest" };
|
|
76
|
-
}
|
|
77
|
-
if (/^\d+$/.test(versionSpec)) {
|
|
78
|
-
return { type: "exact", value: versionSpec };
|
|
79
|
-
}
|
|
80
|
-
return { type: "tag", value: versionSpec };
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Validates that a YAML config can be safely converted to API format.
|
|
84
|
-
* Returns validation errors if any, or null if valid.
|
|
85
|
-
*/
|
|
86
|
-
static validateForApiConversion(config) {
|
|
87
|
-
var _a;
|
|
88
|
-
const errors = [];
|
|
89
|
-
if (!((_a = config.model) == null ? void 0 : _a.trim())) {
|
|
90
|
-
errors.push("Model is required and cannot be empty");
|
|
91
|
-
}
|
|
92
|
-
if (!config.messages || config.messages.length === 0) {
|
|
93
|
-
errors.push("At least one message is required");
|
|
94
|
-
}
|
|
95
|
-
if (config.messages) {
|
|
96
|
-
config.messages.forEach((message, index) => {
|
|
97
|
-
var _a2;
|
|
98
|
-
if (!["system", "user", "assistant"].includes(message.role)) {
|
|
99
|
-
errors.push(
|
|
100
|
-
`Message ${index}: role must be 'system', 'user', or 'assistant'`
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
if (!((_a2 = message.content) == null ? void 0 : _a2.trim())) {
|
|
104
|
-
errors.push(`Message ${index}: content cannot be empty`);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return errors;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
exports.PromptConverter = PromptConverter;
|
|
115
|
-
//# sourceMappingURL=chunk-R6FBJN7K.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-R6FBJN7K.js","../src/cli/utils/promptConverter.ts"],"names":["_a"],"mappings":"AAAA;ACYO,IAAM,gBAAA,EAAN,MAAsB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK3B,OAAO,qBAAA,CAAsB,MAAA,EAAoC;AAC/D,IAAA,OAAO;AAAA,MACL,EAAA,EAAI,MAAA,CAAO,EAAA;AAAA,MACX,IAAA,EAAM,MAAA,CAAO,IAAA;AAAA,MACb,OAAA,EAAS,MAAA,CAAO,OAAA;AAAA,MAChB,SAAA,EAAW,MAAA,CAAO,SAAA;AAAA,MAClB,KAAA,EAAO,MAAA,CAAO,KAAA;AAAA,MACd,QAAA,EAAU,MAAA,CAAO,QAAA;AAAA,MACjB,MAAA,EAAQ,MAAA,CAAO,MAAA;AAAA,MAC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AO,IAAA,CAAK,uCAAuC,CAAA;AAAA,IACrD;AAEA,IAAA,GAAA,CAAI,CAAC,MAAA,CAAO,SAAA,GAAY,MAAA,CAAO,QAAA,CAAS,OAAA,IAAW,CAAA,EAAG;AACpD,MAAA,MAAA,CAAO,IAAA,CAAK,kCAAkC,CAAA;AAAA,IAChD;AAEA,IAAA,GAAA,CAAI,MAAA,CAAO,QAAA,EAAU;AACnB,MAAA,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,CAAC,OAAA,EAAS,KAAA,EAAA,GAAU;AAzJlD,QAAA,IAAAA,GAAAA;AA0JQ,QAAA,GAAA,CAAI,CAAC,CAAC,QAAA,EAAU,MAAA,EAAQ,WAAW,CAAA,CAAE,QAAA,CAAS,OAAA,CAAQ,IAAI,CAAA,EAAG;AAC3D,UAAA,MAAA,CAAO,IAAA;AAAA,YACL,CAAA,QAAA,EAAW,KAAK,CAAA,+CAAA;AAAA,UAClB,CAAA;AAAA,QACF;AACA,QAAA,GAAA,CAAI,CAAA,CAAA,CAACA,IAAAA,EAAA,OAAA,CAAQ,OAAA,EAAA,GAAR,KAAA,EAAA,KAAA,EAAA,EAAAA,GAAAA,CAAiB,IAAA,CAAA,CAAA,CAAA,EAAQ;AAC5B,UAAA,MAAA,CAAO,IAAA,CAAK,CAAA,QAAA,EAAW,KAAK,CAAA,yBAAA,CAA2B,CAAA;AAAA,QACzD;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AACF,CAAA;ADzDA;AACA;AACE;AACF,0CAAC","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-R6FBJN7K.js","sourcesContent":[null,"import type { Prompt } from \"@/client-sdk/services/prompts/prompt\";\nimport type { LocalPromptConfig, MaterializedPrompt } from \"../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 temperature: prompt.temperature,\n maxTokens: prompt.maxTokens,\n inputs: prompt.inputs,\n outputs: prompt.outputs,\n updatedAt: prompt.updatedAt,\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 modelParameters?: {\n temperature?: number;\n maxTokens?: number;\n };\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>;\n } {\n const result: any = {\n model: prompt.model,\n messages: prompt.messages,\n };\n\n // Add modelParameters if temperature or maxTokens exist\n if (prompt.temperature !== undefined || prompt.maxTokens !== undefined) {\n result.modelParameters = {};\n if (prompt.temperature !== undefined) {\n result.modelParameters.temperature = prompt.temperature;\n }\n if (prompt.maxTokens !== undefined) {\n result.modelParameters.maxTokens = prompt.maxTokens;\n }\n }\n\n return result;\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(\n messages: Array<{ role: string; content: string }>,\n ): 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(\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>,\n ): Array<{ role: \"user\" | \"assistant\"; content: string }> {\n return messages.filter((m) => m.role !== \"system\") as Array<{\n role: \"user\" | \"assistant\";\n content: string;\n }>;\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(\n `Message ${index}: role must be 'system', 'user', or 'assistant'`,\n );\n }\n if (!message.content?.trim()) {\n errors.push(`Message ${index}: content cannot be empty`);\n }\n });\n }\n\n return errors;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-SVXNUWZI.js","../src/client-sdk/services/prompts/prompt.ts","../src/client-sdk/services/prompts/tracing/prompt-tracing.decorator.ts","../src/client-sdk/services/prompts/tracing/prompt-service-tracing.decorator.ts","../src/client-sdk/services/prompts/tracing/tracer.ts","../src/client-sdk/tracing/create-tracing-proxy.ts","../src/client-sdk/services/prompts/service.ts","../src/client-sdk/services/prompts/facade.ts"],"names":["target"],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACA;ACnBA,oCAAuB;ADqBvB;AACA;AEdO,IAAM,uBAAA,EAAN,MAA6B;AAAA,EAClC,WAAA,CAA6B,MAAA,EAAgB;AAAhB,IAAA,IAAA,CAAA,OAAA,EAAA,MAAA;AAAA,EAAiB;AAAA,EAEtC,gBAAA,CACN,IAAA,EACA,SAAA,EACA,SAAA,EACgB;AAfpB,IAAA,IAAA,EAAA;AAgBI,IAAA,IAAA,CAAK,OAAA,CAAQ,QAAQ,CAAA;AAErB,IAAA,GAAA,CAAI,iDAAA,CAAmB,EAAG;AACxB,MAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,MAAA,CAAO,GAAG,CAAA;AAE7B,MAAA,GAAA,CAAI,SAAA,EAAW;AACb,QAAA,IAAA,CAAK,YAAA;AAAA,UACH,4BAAA;AAAA,UACA,IAAA,CAAK,SAAA,CAAU;AAAA,YACb,IAAA,EAAM,MAAA;AAAA,YACN,KAAA,EAAO;AAAA,UACT,CAAC;AAAA,QACH,CAAA;AAAA,MACF;AAAA,IACF;AAEA,IAAA,MAAM,OAAA,EAAS,SAAA,CAAU,CAAA;AAEzB,IAAA,IAAA,CAAK,aAAA,CAAc;AAAA,MACjB,qBAAA,EAAuB,MAAA,CAAO,EAAA;AAAA,MAC9B,yBAAA,EAAA,CAA2B,GAAA,EAAA,MAAA,CAAO,MAAA,EAAA,GAAP,KAAA,EAAA,GAAA,EAAiB,EAAA;AAAA,MAC5C,6BAAA,EAA+B,MAAA,CAAO,SAAA;AAAA,MACtC,iCAAA,EAAmC,MAAA,CAAO;AAAA,IAC5C,CAAC,CAAA;AAED,IAAA,GAAA,CAAI,kD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,UAAA;AACF,QAAA;AACF,MAAA;AAEoB,MAAA;AAEhB,QAAA;AACc,QAAA;AAClB,MAAA;AAEO,MAAA;AACiB,QAAA;AACA,QAAA;AACC,QAAA;AACzB,MAAA;AACc,IAAA;AAEZ,MAAA;AACqB,MAAA;AACzB,IAAA;AACF,EAAA;AACF;AN4MiC;AACA;AOnfN;AAIW,EAAA;AACpB,IAAA;AACK,IAAA;AACrB,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQsD,EAAA;AACzB,IAAA;AAC7B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAY0B,EAAA;AACA,IAAA;AAC1B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOkC,EAAA;AACL,IAAA;AAC7B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASiC,EAAA;AACJ,IAAA;AAC7B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOgE,EAAA;AACnC,IAAA;AAC7B,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAawB,EAAA;AACG,IAAA;AAC3B,EAAA;AACF;APoeiC;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-SVXNUWZI.js","sourcesContent":[null,"import { Liquid } from \"liquidjs\";\nimport type { paths } from \"@/internal/generated/openapi/api-client\";\nimport { PromptTracingDecorator, tracer } from \"./tracing\";\nimport { createTracingProxy } from \"@/client-sdk/tracing/create-tracing-proxy\";\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\n/**\n * The Prompt class provides a standardized interface for working with prompt objects\n * within the SDK, ensuring consistent structure and behavior regardless of the underlying\n * client implementation. This abstraction enables the SDK to maintain control over prompt\n * handling, enforce type safety, and facilitate future enhancements without exposing\n * internal details or requiring changes from client code.\n */\nexport class Prompt implements PromptResponse {\n // === Identification ===\n public readonly id!: PromptResponse[\"id\"];\n public readonly handle!: PromptResponse[\"handle\"];\n public readonly name!: PromptResponse[\"name\"];\n public readonly scope!: PromptResponse[\"scope\"];\n\n // === Ownership & Organization ===\n public readonly projectId!: PromptResponse[\"projectId\"];\n public readonly organizationId!: PromptResponse[\"organizationId\"];\n public readonly authorId: PromptResponse[\"authorId\"];\n\n // === Timestamps ===\n public readonly createdAt!: PromptResponse[\"createdAt\"];\n public readonly updatedAt!: PromptResponse[\"updatedAt\"];\n\n // === Versioning ===\n public readonly version!: PromptResponse[\"version\"];\n public readonly versionId!: PromptResponse[\"versionId\"];\n\n // === Model Configuration ===\n public readonly model!: PromptResponse[\"model\"];\n public readonly temperature: PromptResponse[\"temperature\"];\n public readonly maxTokens: PromptResponse[\"maxTokens\"];\n public readonly responseFormat: PromptResponse[\"responseFormat\"];\n\n // === Prompt Content ===\n public readonly prompt!: PromptResponse[\"prompt\"];\n public readonly messages!: PromptResponse[\"messages\"];\n public readonly inputs!: PromptResponse[\"inputs\"];\n public readonly outputs!: PromptResponse[\"outputs\"];\n\n constructor(readonly raw: PromptResponse) {\n Object.assign(this, raw);\n\n // Return a proxy that wraps specific methods for tracing\n return createTracingProxy(this as Prompt, tracer, PromptTracingDecorator);\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\nexport /**\n * Represents a compiled prompt that extends Prompt with reference to the original template\n */\nclass CompiledPrompt extends Prompt {\n constructor(\n compiledData: PromptResponse,\n public readonly original: Prompt,\n ) {\n super(compiledData);\n }\n}\n","import { type Prompt, type TemplateVariables, type CompiledPrompt } from \"../prompt\";\nimport { shouldCaptureInput, shouldCaptureOutput } from \"@/observability-sdk\";\nimport type { LangWatchSpan } from \"@/observability-sdk\";\n\n/**\n * Class that decorates the target prompt,\n * adding tracing to specific methods.\n */\nexport class PromptTracingDecorator {\n constructor(private readonly target: Prompt) {}\n\n private traceCompilation(\n span: LangWatchSpan,\n variables: TemplateVariables,\n compileFn: () => CompiledPrompt\n ): CompiledPrompt {\n span.setType(\"prompt\");\n\n if (shouldCaptureInput()) {\n span.setInput(this.target.raw);\n\n if (variables) {\n span.setAttribute(\n 'langwatch.prompt.variables',\n JSON.stringify({\n type: \"json\",\n value: variables,\n }),\n );\n }\n }\n\n const result = compileFn();\n\n span.setAttributes({\n 'langwatch.prompt.id': result.id,\n 'langwatch.prompt.handle': result.handle ?? '',\n 'langwatch.prompt.version.id': result.versionId,\n 'langwatch.prompt.version.number': result.version,\n });\n\n if (shouldCaptureOutput()) {\n span.setOutput({\n ...result,\n raw: void 0, // TODO(afr): Figure out a better way to do this.\n });\n }\n\n return result;\n }\n\n compile(span: LangWatchSpan, variables: TemplateVariables = {}): CompiledPrompt {\n return this.traceCompilation(\n span,\n variables,\n () => this.target.compile(variables),\n );\n }\n\n compileStrict(span: LangWatchSpan, variables: TemplateVariables): CompiledPrompt {\n return this.traceCompilation(\n span,\n variables,\n () => this.target.compileStrict(variables),\n );\n }\n}\n","import { type PromptsService } from \"../service\";\nimport { type Prompt } from \"../prompt\";\nimport type { LangWatchSpan } from \"@/observability-sdk\";\nimport { shouldCaptureInput, shouldCaptureOutput } from \"@/observability-sdk\";\nimport type { CreatePromptBody, UpdatePromptBody } from \"../types\";\n\n/**\n * Class that decorates the target prompt service,\n * adding tracing to key methods.\n */\nexport class PromptServiceTracingDecorator {\n constructor(private readonly target: PromptsService) {}\n\n async get(\n span: LangWatchSpan,\n id: string,\n options?: { version?: string }\n ): Promise<Prompt> {\n span.setType(\"prompt\");\n span.setAttribute('langwatch.prompt.id', id);\n\n const result = await this.target.get(id, options);\n\n if (result) {\n span.setAttributes({\n 'langwatch.prompt.id': result.id,\n 'langwatch.prompt.handle': result.handle ?? '',\n 'langwatch.prompt.version.id': result.versionId,\n 'langwatch.prompt.version.number': result.version,\n });\n }\n\n if (result && shouldCaptureOutput()) {\n span.setOutput(\"json\", result.raw);\n }\n\n return result;\n }\n\n async create(\n span: LangWatchSpan,\n params: CreatePromptBody\n ): Promise<Prompt> {\n span.setType(\"prompt\");\n\n if (shouldCaptureInput()) {\n span.setInput(params);\n }\n\n const result = await this.target.create(params);\n\n span.setAttribute('langwatch.prompt.id', result.id);\n span.setAttribute('langwatch.prompt.handle', result.handle ?? '');\n span.setAttribute('langwatch.prompt.scope', result.scope);\n span.setAttribute('langwatch.prompt.version.id', result.versionId);\n span.setAttribute('langwatch.prompt.version.number', result.version);\n\n return result;\n }\n\n async update(\n span: LangWatchSpan,\n id: string,\n params: UpdatePromptBody\n ): Promise<Prompt> {\n\n if (shouldCaptureInput()) {\n span.setInput(params);\n }\n\n const result = await this.target.update(id, params);\n\n span.setType(\"prompt\");\n span.setAttribute('langwatch.prompt.id', id);\n span.setAttribute('langwatch.prompt.handle', result.handle ?? '');\n span.setAttribute('langwatch.prompt.scope', result.scope);\n span.setAttribute('langwatch.prompt.version.id', result.versionId);\n span.setAttribute('langwatch.prompt.version.number', result.version);\n\n return result;\n }\n\n async delete(\n span: LangWatchSpan,\n id: string\n ): Promise<{ success: boolean }> {\n const result = await this.target.delete(id);\n\n span.setType(\"prompt\");\n span.setAttribute('langwatch.prompt.id', id);\n span.setAttribute('langwatch.prompt.deleted', 'true');\n\n return result;\n }\n\n async upsert(\n span: LangWatchSpan,\n handle: string,\n config: any\n ): Promise<{ created: boolean; prompt: Prompt }> {\n if (shouldCaptureInput()) {\n span.setInput(config);\n }\n\n const result = await this.target.upsert(handle, config);\n\n span.setType(\"prompt\");\n span.setAttribute('langwatch.prompt.handle', handle);\n span.setAttribute('langwatch.prompt.created', result.created.toString());\n span.setAttribute('langwatch.prompt.id', result.prompt.id);\n span.setAttribute('langwatch.prompt.version.id', result.prompt.versionId);\n span.setAttribute('langwatch.prompt.version.number', result.prompt.version);\n\n return result;\n }\n\n async sync(\n span: LangWatchSpan,\n params: any\n ): Promise<any> {\n if (shouldCaptureInput()) {\n span.setInput(params);\n }\n\n const result = await this.target.sync(params);\n\n span.setType(\"prompt\");\n span.setAttribute('langwatch.prompt.name', params.name);\n span.setAttribute('langwatch.prompt.sync.action', result.action);\n\n if (result.conflictInfo) {\n span.setAttribute('langwatch.prompt.sync.has_conflict', 'true');\n span.setAttribute('langwatch.prompt.sync.local_version', result.conflictInfo.localVersion.toString());\n span.setAttribute('langwatch.prompt.sync.remote_version', result.conflictInfo.remoteVersion.toString());\n }\n\n return result;\n }\n}\n","import { getLangWatchTracer } from \"@/observability-sdk/tracer\";\nimport { LANGWATCH_SDK_NAME_CLIENT, LANGWATCH_SDK_VERSION } from \"@/internal/constants\";\n\nexport const tracer = getLangWatchTracer(`${LANGWATCH_SDK_NAME_CLIENT}.prompts`, LANGWATCH_SDK_VERSION);\n","import { type LangWatchTracer } from \"@/observability-sdk\";\nimport { SpanKind } from \"@opentelemetry/api\";\n\n// Type for decorator methods that receive span as first parameter\ntype DecoratorMethodWithSpan<T extends (...args: any[]) => any> =\n (span: any, ...args: Parameters<T>) => ReturnType<T>;\n\n// Type for decorator class that maps original methods to span-aware versions\n// Only requires methods that are actually implemented in the decorator\ntype DecoratorClass<T> = new (target: T) => Partial<{\n [K in keyof T]: T[K] extends (...args: any[]) => any\n ? DecoratorMethodWithSpan<T[K]>\n : T[K];\n }>;\n\n/**\n * Creates a proxy that always creates spans for public methods.\n * Decorators can access the span as the first parameter to add additional attributes.\n *\n * @param target - The target to wrap\n * @param tracer - The tracer instance to use\n * @param DecoratorClass - Optional decorator class for custom logic\n * @returns A proxy that wraps the target with consistent tracing\n */\nexport function createTracingProxy<\n T extends object,\n D extends DecoratorClass<T> | undefined = undefined\n>(\n target: T,\n tracer: LangWatchTracer,\n DecoratorClass?: D,\n): T {\n const decorator = DecoratorClass ? new DecoratorClass(target) : null;\n\n return new Proxy(target, {\n get(target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver);\n\n // If it's not a function, return as-is\n if (typeof value !== \"function\") {\n return value;\n }\n\n // Only trace public methods\n if (\n typeof prop === \"string\" &&\n !prop.startsWith(\"_\") && // Skip private methods\n !isGetterOrSetter(target, prop) && // Skip actual getters/setters\n !isBuiltInMethod(prop) // Skip built-in methods\n ) {\n return (...args: any[]) => {\n const spanName = `${target.constructor.name}.${prop}`;\n\n return tracer.withActiveSpan(spanName, {\n kind: SpanKind.CLIENT,\n attributes: {\n 'code.function': prop,\n 'code.namespace': target.constructor.name,\n },\n }, (span) => {\n // If decorator has this method, call it with span as first parameter\n if (decorator && prop in decorator) {\n const decoratorMethod = decorator[prop as keyof typeof decorator];\n if (typeof decoratorMethod === \"function\") {\n return decoratorMethod.apply(decorator, [span, ...args]);\n }\n }\n\n // Default: just call the original method\n return value.apply(target, args);\n });\n };\n }\n\n return typeof value === \"function\" ? value.bind(target) : value;\n },\n });\n}\n\n// Helper function to check if a property is a getter or setter\nconst isGetterOrSetter = (target: any, prop: string | symbol): boolean => {\n // First check own properties\n let descriptor = Object.getOwnPropertyDescriptor(target, prop);\n\n // If not found on own properties, check prototype chain\n if (!descriptor) {\n const prototype = Object.getPrototypeOf(target);\n if (prototype) {\n descriptor = Object.getOwnPropertyDescriptor(prototype, prop);\n }\n }\n\n // Return true if it's a getter or setter\n return !!(descriptor?.get ?? descriptor?.set);\n};\n\n// Helper function to check if a method is a built-in method that should not be traced\nconst isBuiltInMethod = (prop: string | symbol): boolean => {\n if (typeof prop !== \"string\") {\n return false;\n }\n\n // List of built-in methods that should not be traced\n const builtInMethods = [\n 'toString',\n 'valueOf',\n 'toJSON',\n 'toLocaleString',\n 'hasOwnProperty',\n 'isPrototypeOf',\n 'propertyIsEnumerable',\n 'constructor'\n ];\n\n return builtInMethods.includes(prop);\n};\n","import type { paths } from \"@/internal/generated/openapi/api-client\";\nimport { Prompt, type PromptResponse } from \"./prompt\";\nimport { PromptConverter } from \"@/cli/utils/promptConverter\";\nimport { PromptServiceTracingDecorator, tracer } from \"./tracing\";\nimport { createTracingProxy } from \"@/client-sdk/tracing/create-tracing-proxy\";\nimport { type InternalConfig } from \"@/client-sdk/types\";\nimport { type CreatePromptBody, type UpdatePromptBody } from \"./types\";\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\n/**\n * Service for managing prompt resources via the Langwatch API.\n * Constructor creates a proxy that wraps the service and traces all methods.\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 PromptsService {\n private config: InternalConfig;\n\n constructor(config: InternalConfig) {\n this.config = config;\n\n /**\n * Wraps the service in a tracing proxy via the decorator.\n */\n return createTracingProxy(\n this as PromptsService,\n tracer,\n PromptServiceTracingDecorator,\n );\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 } =\n await this.config.langwatchApiClient.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.\n * @throws {PromptsError} If the API call fails.\n */\n async get(id: string, options?: { version?: string }): Promise<Prompt> {\n const { data, error } = await this.config.langwatchApiClient.GET(\n \"/api/prompts/{id}\",\n {\n params: { path: { id } },\n query: {\n version: options?.version,\n },\n },\n );\n\n if (error) {\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 await this.get(id);\n return true;\n } catch (error) {\n if (\n error instanceof PromptsError &&\n error.originalError?.statusCode === 404\n ) {\n return false;\n }\n\n throw error;\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.config.langwatchApiClient.POST(\n \"/api/prompts\",\n {\n body: params,\n },\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, data: updatedPrompt } =\n await this.config.langwatchApiClient.PUT(\"/api/prompts/{id}\", {\n params: { path: { id } },\n body: params,\n });\n if (error) this.handleApiError(`update prompt with ID \"${id}\"`, error);\n return new Prompt(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<{ success: boolean }> {\n const { data, error } = await this.config.langwatchApiClient.DELETE(\n \"/api/prompts/{id}\",\n {\n params: { path: { id } },\n },\n );\n if (error) this.handleApiError(`delete prompt with ID \"${id}\"`, error);\n\n return data;\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<Prompt[]> {\n const { data, error } = await this.config.langwatchApiClient.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 return data.map((version) => new Prompt(version));\n }\n\n /**\n * Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.\n * @param handle The prompt's handle/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 handle: 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 const payload: CreatePromptBody = {\n handle,\n model: config.model,\n prompt: PromptConverter.extractSystemPrompt(config.messages),\n messages: PromptConverter.filterNonSystemMessages(config.messages),\n temperature: config.modelParameters?.temperature,\n maxTokens: config.modelParameters?.max_tokens,\n inputs: [{ identifier: \"input\", type: \"str\" as const }],\n outputs: [{ identifier: \"output\", type: \"str\" as const }],\n commitMessage: `Updated via CLI sync`,\n schemaVersion: \"1.0\",\n };\n\n // Creating a prompt with the same handle will fail, so we try to update instead\n try {\n const prompt = await this.create(payload);\n return {\n created: true,\n prompt,\n };\n } catch {\n const prompt = await this.update(handle, payload as UpdatePromptBody);\n\n return {\n created: false,\n prompt,\n };\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.config.langwatchApiClient.POST(\n \"/api/prompts/{id}/sync\",\n {\n params: { path: { id: params.name } },\n body: {\n configData: params.configData,\n localVersion: params.localVersion,\n commitMessage: params.commitMessage,\n },\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,\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","import { PromptsService, type SyncResult } from \"./service\";\nimport type { Prompt } from \"./prompt\";\nimport type { CreatePromptBody, UpdatePromptBody } from \"./types\";\nimport { type InternalConfig } from \"@/client-sdk/types\";\n\n/**\n * Facade for prompt operations in the LangWatch SDK.\n * Provides a simplified interface for common prompt management tasks.\n */\nexport class PromptsFacade {\n private readonly service: PromptsService;\n private readonly config: InternalConfig;\n\n constructor(config: InternalConfig) {\n this.config = config;\n this.service = new PromptsService(config);\n }\n\n /**\n * Creates a new prompt.\n * @param data The prompt creation payload.\n * @returns The created Prompt instance.\n * @throws {PromptsError} If the API call fails.\n */\n async create(data: CreatePromptBody): Promise<Prompt> {\n return this.service.create(data);\n }\n\n /**\n * Retrieves a prompt by handle or ID.\n * @param handleOrId The prompt's handle or unique identifier.\n * @param options Optional parameters for the request.\n * @returns The Prompt instance or null if not found.\n * @throws {PromptsError} If the API call fails.\n */\n async get(\n handleOrId: string,\n options?: { version?: string },\n ): Promise<Prompt | null> {\n return this.service.get(handleOrId, options);\n }\n\n /**\n * Retrieves all prompts.\n * @returns Array of Prompt instances.\n * @throws {PromptsError} If the API call fails.\n */\n async getAll(): Promise<Prompt[]> {\n return this.service.getAll();\n }\n\n /**\n * Updates an existing prompt.\n * @param handleOrId The prompt's handle or unique identifier.\n * @param newData The update payload.\n * @returns The updated Prompt instance.\n * @throws {PromptsError} If the API call fails.\n */\n async update(handleOrId: string, newData: UpdatePromptBody): Promise<Prompt> {\n return this.service.update(handleOrId, newData);\n }\n\n /**\n * Deletes a prompt by handle or ID.\n * @param handleOrId The prompt's handle or unique identifier.\n * @throws {PromptsError} If the API call fails.\n */\n async delete(handleOrId: string): Promise<{ success: boolean }> {\n return this.service.delete(handleOrId);\n }\n\n /**\n * Syncs a prompt with the server.\n * @param params The sync parameters.\n * @returns The sync result.\n * @throws {PromptsError} If the API call fails.\n */\n async sync(params: {\n name: string;\n configData: any;\n localVersion?: number;\n commitMessage?: string;\n }): Promise<SyncResult> {\n return this.service.sync(params);\n }\n}\n"]}
|
package/dist/chunk-V5M3HUBV.mjs
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// src/cli/utils/promptConverter.ts
|
|
2
|
-
var PromptConverter = class {
|
|
3
|
-
/**
|
|
4
|
-
* Converts a Prompt instance from the API service to the MaterializedPrompt format
|
|
5
|
-
* used for saving to the .materialized directory.
|
|
6
|
-
*/
|
|
7
|
-
static fromApiToMaterialized(prompt) {
|
|
8
|
-
return {
|
|
9
|
-
id: prompt.id,
|
|
10
|
-
name: prompt.name,
|
|
11
|
-
version: prompt.version,
|
|
12
|
-
versionId: prompt.versionId,
|
|
13
|
-
model: prompt.model,
|
|
14
|
-
messages: prompt.messages,
|
|
15
|
-
prompt: prompt.prompt,
|
|
16
|
-
temperature: prompt.temperature,
|
|
17
|
-
maxTokens: prompt.maxTokens,
|
|
18
|
-
inputs: prompt.inputs,
|
|
19
|
-
outputs: prompt.outputs,
|
|
20
|
-
updatedAt: prompt.updatedAt
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Converts a MaterializedPrompt to the YAML content structure
|
|
25
|
-
* for saving to .prompt.yaml files.
|
|
26
|
-
*/
|
|
27
|
-
static fromMaterializedToYaml(prompt) {
|
|
28
|
-
const result = {
|
|
29
|
-
model: prompt.model,
|
|
30
|
-
messages: prompt.messages
|
|
31
|
-
};
|
|
32
|
-
if (prompt.temperature !== void 0 || prompt.maxTokens !== void 0) {
|
|
33
|
-
result.modelParameters = {};
|
|
34
|
-
if (prompt.temperature !== void 0) {
|
|
35
|
-
result.modelParameters.temperature = prompt.temperature;
|
|
36
|
-
}
|
|
37
|
-
if (prompt.maxTokens !== void 0) {
|
|
38
|
-
result.modelParameters.maxTokens = prompt.maxTokens;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Converts a LocalPromptConfig (loaded from YAML) to the format
|
|
45
|
-
* expected by the API service for upserting.
|
|
46
|
-
*/
|
|
47
|
-
static fromLocalToApiFormat(config) {
|
|
48
|
-
return {
|
|
49
|
-
model: config.model,
|
|
50
|
-
modelParameters: config.modelParameters,
|
|
51
|
-
messages: config.messages
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extracts the system prompt from messages array.
|
|
56
|
-
* Used when converting to API format that separates system prompt from messages.
|
|
57
|
-
*/
|
|
58
|
-
static extractSystemPrompt(messages) {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
return (_b = (_a = messages.find((m) => m.role === "system")) == null ? void 0 : _a.content) != null ? _b : "";
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Filters out system messages from the messages array.
|
|
64
|
-
* Used when converting to API format that handles system prompt separately.
|
|
65
|
-
*/
|
|
66
|
-
static filterNonSystemMessages(messages) {
|
|
67
|
-
return messages.filter((m) => m.role !== "system");
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Converts version specification strings to actual version constraints.
|
|
71
|
-
* Handles npm-style version specs like "latest", "5", "^5", etc.
|
|
72
|
-
*/
|
|
73
|
-
static parseVersionSpec(versionSpec) {
|
|
74
|
-
if (versionSpec === "latest") {
|
|
75
|
-
return { type: "latest", value: "latest" };
|
|
76
|
-
}
|
|
77
|
-
if (/^\d+$/.test(versionSpec)) {
|
|
78
|
-
return { type: "exact", value: versionSpec };
|
|
79
|
-
}
|
|
80
|
-
return { type: "tag", value: versionSpec };
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Validates that a YAML config can be safely converted to API format.
|
|
84
|
-
* Returns validation errors if any, or null if valid.
|
|
85
|
-
*/
|
|
86
|
-
static validateForApiConversion(config) {
|
|
87
|
-
var _a;
|
|
88
|
-
const errors = [];
|
|
89
|
-
if (!((_a = config.model) == null ? void 0 : _a.trim())) {
|
|
90
|
-
errors.push("Model is required and cannot be empty");
|
|
91
|
-
}
|
|
92
|
-
if (!config.messages || config.messages.length === 0) {
|
|
93
|
-
errors.push("At least one message is required");
|
|
94
|
-
}
|
|
95
|
-
if (config.messages) {
|
|
96
|
-
config.messages.forEach((message, index) => {
|
|
97
|
-
var _a2;
|
|
98
|
-
if (!["system", "user", "assistant"].includes(message.role)) {
|
|
99
|
-
errors.push(
|
|
100
|
-
`Message ${index}: role must be 'system', 'user', or 'assistant'`
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
if (!((_a2 = message.content) == null ? void 0 : _a2.trim())) {
|
|
104
|
-
errors.push(`Message ${index}: content cannot be empty`);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return errors;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export {
|
|
113
|
-
PromptConverter
|
|
114
|
-
};
|
|
115
|
-
//# sourceMappingURL=chunk-V5M3HUBV.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/utils/promptConverter.ts"],"sourcesContent":["import type { Prompt } from \"@/client-sdk/services/prompts/prompt\";\nimport type { LocalPromptConfig, MaterializedPrompt } from \"../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 temperature: prompt.temperature,\n maxTokens: prompt.maxTokens,\n inputs: prompt.inputs,\n outputs: prompt.outputs,\n updatedAt: prompt.updatedAt,\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 modelParameters?: {\n temperature?: number;\n maxTokens?: number;\n };\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>;\n } {\n const result: any = {\n model: prompt.model,\n messages: prompt.messages,\n };\n\n // Add modelParameters if temperature or maxTokens exist\n if (prompt.temperature !== undefined || prompt.maxTokens !== undefined) {\n result.modelParameters = {};\n if (prompt.temperature !== undefined) {\n result.modelParameters.temperature = prompt.temperature;\n }\n if (prompt.maxTokens !== undefined) {\n result.modelParameters.maxTokens = prompt.maxTokens;\n }\n }\n\n return result;\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(\n messages: Array<{ role: string; content: string }>,\n ): 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(\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>,\n ): Array<{ role: \"user\" | \"assistant\"; content: string }> {\n return messages.filter((m) => m.role !== \"system\") as Array<{\n role: \"user\" | \"assistant\";\n content: string;\n }>;\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(\n `Message ${index}: role must be 'system', 'user', or 'assistant'`,\n );\n }\n if (!message.content?.trim()) {\n errors.push(`Message ${index}: content cannot be empty`);\n }\n });\n }\n\n return errors;\n }\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,aAAa,OAAO;AAAA,MACpB,WAAW,OAAO;AAAA,MAClB,QAAQ,OAAO;AAAA,MACf,SAAS,OAAO;AAAA,MAChB,WAAW,OAAO;AAAA,IACpB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,uBAAuB,QAU5B;AACA,UAAM,SAAc;AAAA,MAClB,OAAO,OAAO;AAAA,MACd,UAAU,OAAO;AAAA,IACn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AG;AACpD,aAAO,KAAK,kCAAkC;AAAA,IAChD;AAEA,QAAI,OAAO,UAAU;AACnB,aAAO,SAAS,QAAQ,CAAC,SAAS,UAAU;AAzJlD,YAAAA;AA0JQ,YAAI,CAAC,CAAC,UAAU,QAAQ,WAAW,EAAE,SAAS,QAAQ,IAAI,GAAG;AAC3D,iBAAO;AAAA,YACL,WAAW,KAAK;AAAA,UAClB;AAAA,QACF;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-YEGQXDTE.mjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PromptsFacade,
|
|
3
|
-
createTracingProxy
|
|
4
|
-
} from "./chunk-H5PON53W.mjs";
|
|
5
|
-
import {
|
|
6
|
-
getLangWatchTracer
|
|
7
|
-
} from "./chunk-QZGTM76F.mjs";
|
|
8
|
-
import {
|
|
9
|
-
DEFAULT_ENDPOINT,
|
|
10
|
-
LANGWATCH_SDK_LANGUAGE,
|
|
11
|
-
LANGWATCH_SDK_NAME_CLIENT,
|
|
12
|
-
LANGWATCH_SDK_NAME_OBSERVABILITY,
|
|
13
|
-
LANGWATCH_SDK_RUNTIME,
|
|
14
|
-
LANGWATCH_SDK_VERSION,
|
|
15
|
-
version
|
|
16
|
-
} from "./chunk-YKFTFYKK.mjs";
|
|
17
|
-
import {
|
|
18
|
-
NoOpLogger
|
|
19
|
-
} from "./chunk-YNQ44U6D.mjs";
|
|
20
|
-
import {
|
|
21
|
-
__privateAdd,
|
|
22
|
-
__privateGet,
|
|
23
|
-
__privateMethod,
|
|
24
|
-
__privateSet,
|
|
25
|
-
__spreadProps,
|
|
26
|
-
__spreadValues
|
|
27
|
-
} from "./chunk-CU3443HD.mjs";
|
|
28
|
-
|
|
29
|
-
// src/internal/api/client.ts
|
|
30
|
-
import openApiCreateClient from "openapi-fetch";
|
|
31
|
-
function createLangWatchApiClient(apiKey, endpoint) {
|
|
32
|
-
return openApiCreateClient({
|
|
33
|
-
baseUrl: endpoint,
|
|
34
|
-
headers: __spreadProps(__spreadValues({}, apiKey ? { authorization: `Bearer ${apiKey}`, "x-auth-token": apiKey } : {}), {
|
|
35
|
-
"content-type": "application/json",
|
|
36
|
-
"user-agent": `langwatch-sdk-node/${version}`,
|
|
37
|
-
"x-langwatch-sdk-name": LANGWATCH_SDK_NAME_OBSERVABILITY,
|
|
38
|
-
"x-langwatch-sdk-language": LANGWATCH_SDK_LANGUAGE,
|
|
39
|
-
"x-langwatch-sdk-version": LANGWATCH_SDK_VERSION,
|
|
40
|
-
"x-langwatch-sdk-platform": LANGWATCH_SDK_RUNTIME()
|
|
41
|
-
})
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/client-sdk/services/traces/types.ts
|
|
46
|
-
var TracesError = class extends Error {
|
|
47
|
-
constructor(message, operation, originalError) {
|
|
48
|
-
super(message);
|
|
49
|
-
this.operation = operation;
|
|
50
|
-
this.originalError = originalError;
|
|
51
|
-
this.name = "TracesError";
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/client-sdk/services/traces/tracing/tracer.ts
|
|
56
|
-
var tracer = getLangWatchTracer(`${LANGWATCH_SDK_NAME_CLIENT}.traces`, LANGWATCH_SDK_VERSION);
|
|
57
|
-
|
|
58
|
-
// src/client-sdk/services/traces/service.ts
|
|
59
|
-
var TracesService = class {
|
|
60
|
-
constructor(config) {
|
|
61
|
-
this.config = config;
|
|
62
|
-
return createTracingProxy(
|
|
63
|
-
this,
|
|
64
|
-
tracer
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Handles API errors by throwing a TracesError with operation context.
|
|
69
|
-
* @param operation Description of the operation being performed.
|
|
70
|
-
* @param error The error object returned from the API client.
|
|
71
|
-
* @throws {TracesError}
|
|
72
|
-
*/
|
|
73
|
-
handleApiError(operation, error) {
|
|
74
|
-
var _a, _b;
|
|
75
|
-
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";
|
|
76
|
-
throw new TracesError(
|
|
77
|
-
`Failed to ${operation}: ${errorMessage}`,
|
|
78
|
-
operation,
|
|
79
|
-
error
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Retrieves a trace by its ID.
|
|
84
|
-
* @param traceId The trace's unique identifier.
|
|
85
|
-
* @param params Optional parameters for the request.
|
|
86
|
-
* @returns The trace response object.
|
|
87
|
-
* @throws {TracesError} If the API call fails.
|
|
88
|
-
*/
|
|
89
|
-
async get(traceId, params) {
|
|
90
|
-
const { data, error } = await this.config.langwatchApiClient.GET("/api/trace/{id}", {
|
|
91
|
-
params: {
|
|
92
|
-
path: {
|
|
93
|
-
id: traceId
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
query: params
|
|
97
|
-
});
|
|
98
|
-
if (error) {
|
|
99
|
-
this.handleApiError("get trace", error);
|
|
100
|
-
}
|
|
101
|
-
return data;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// src/client-sdk/services/traces/facade.ts
|
|
106
|
-
var _service;
|
|
107
|
-
var TracesFacade = class {
|
|
108
|
-
constructor(config) {
|
|
109
|
-
__privateAdd(this, _service);
|
|
110
|
-
__privateSet(this, _service, new TracesService(config));
|
|
111
|
-
}
|
|
112
|
-
async get(traceId, params) {
|
|
113
|
-
return __privateGet(this, _service).get(traceId, params);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
_service = new WeakMap();
|
|
117
|
-
|
|
118
|
-
// src/client-sdk/index.ts
|
|
119
|
-
var _LangWatch_instances, createInternalConfig_fn;
|
|
120
|
-
var LangWatch = class {
|
|
121
|
-
constructor(options = {}) {
|
|
122
|
-
__privateAdd(this, _LangWatch_instances);
|
|
123
|
-
this.tracer = getLangWatchTracer(LANGWATCH_SDK_NAME_CLIENT, LANGWATCH_SDK_VERSION);
|
|
124
|
-
var _a, _b, _c, _d;
|
|
125
|
-
const apiKey = (_b = (_a = options.apiKey) != null ? _a : process.env.LANGWATCH_API_KEY) != null ? _b : "";
|
|
126
|
-
const endpoint = (_d = (_c = options.endpoint) != null ? _c : process.env.LANGWATCH_ENDPOINT) != null ? _d : DEFAULT_ENDPOINT;
|
|
127
|
-
this.config = __privateMethod(this, _LangWatch_instances, createInternalConfig_fn).call(this, {
|
|
128
|
-
apiKey,
|
|
129
|
-
endpoint,
|
|
130
|
-
options: options.options
|
|
131
|
-
});
|
|
132
|
-
this.prompts = new PromptsFacade(this.config);
|
|
133
|
-
this.traces = new TracesFacade(this.config);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
_LangWatch_instances = new WeakSet();
|
|
137
|
-
createInternalConfig_fn = function({
|
|
138
|
-
apiKey,
|
|
139
|
-
endpoint,
|
|
140
|
-
options
|
|
141
|
-
}) {
|
|
142
|
-
var _a;
|
|
143
|
-
return {
|
|
144
|
-
logger: (_a = options == null ? void 0 : options.logger) != null ? _a : new NoOpLogger(),
|
|
145
|
-
langwatchApiClient: createLangWatchApiClient(apiKey, endpoint)
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export {
|
|
150
|
-
LangWatch
|
|
151
|
-
};
|
|
152
|
-
//# sourceMappingURL=chunk-YEGQXDTE.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/api/client.ts","../src/client-sdk/services/traces/types.ts","../src/client-sdk/services/traces/tracing/tracer.ts","../src/client-sdk/services/traces/service.ts","../src/client-sdk/services/traces/facade.ts","../src/client-sdk/index.ts"],"sourcesContent":["import openApiCreateClient from \"openapi-fetch\";\nimport type { paths } from \"../generated/openapi/api-client\";\nimport { version } from \"../../../package.json\";\nimport {\n LANGWATCH_SDK_LANGUAGE,\n LANGWATCH_SDK_NAME_OBSERVABILITY,\n LANGWATCH_SDK_RUNTIME,\n LANGWATCH_SDK_VERSION,\n} from \"../constants\";\n\nexport type LangwatchApiClient = ReturnType<typeof openApiCreateClient<paths>>;\n\nexport function createLangWatchApiClient(\n apiKey?: string,\n endpoint?: string\n): LangwatchApiClient {\n return openApiCreateClient<paths>({\n baseUrl: endpoint,\n headers: {\n ...(apiKey ? { authorization: `Bearer ${apiKey}`, 'x-auth-token': apiKey } : {}),\n \"content-type\": \"application/json\",\n \"user-agent\": `langwatch-sdk-node/${version}`,\n \"x-langwatch-sdk-name\": LANGWATCH_SDK_NAME_OBSERVABILITY,\n \"x-langwatch-sdk-language\": LANGWATCH_SDK_LANGUAGE,\n \"x-langwatch-sdk-version\": LANGWATCH_SDK_VERSION,\n \"x-langwatch-sdk-platform\": LANGWATCH_SDK_RUNTIME(),\n },\n });\n}\n","import type { paths } from \"@/internal/generated/openapi/api-client\";\n\nexport interface GetTraceParams {\n includeSpans?: boolean;\n}\n\nexport type GetTraceResponse = NonNullable<\n paths[\"/api/trace/{id}\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n>;\n\n/**\n * Custom error class for Traces API operations.\n * Provides context about the failed operation and the original error.\n */\nexport class TracesError extends Error {\n constructor(\n message: string,\n public readonly operation: string,\n public readonly originalError?: any,\n ) {\n super(message);\n this.name = \"TracesError\";\n }\n}\n","import { LANGWATCH_SDK_NAME_CLIENT, LANGWATCH_SDK_VERSION } from \"@/internal/constants\";\nimport { getLangWatchTracer } from \"@/observability-sdk/tracer\";\n\nexport const tracer = getLangWatchTracer(`${LANGWATCH_SDK_NAME_CLIENT}.traces`, LANGWATCH_SDK_VERSION);\n","import { createTracingProxy } from \"@/client-sdk/tracing/create-tracing-proxy\";\nimport { type InternalConfig } from \"@/client-sdk/types\";\nimport { type GetTraceParams, TracesError, type GetTraceResponse } from \"./types\";\nimport { tracer } from \"./tracing\";\n\n/**\n * Service for managing trace resources via the Langwatch API.\n * Constructor creates a proxy that wraps the service and traces all methods.\n *\n * Responsibilities:\n * - Retrieving trace data\n * - Error handling with contextual information\n *\n * All methods return trace response objects directly.\n */\nexport class TracesService {\n private config: InternalConfig;\n\n constructor(config: InternalConfig) {\n this.config = config;\n\n /**\n * Wraps the service in a tracing proxy via the decorator.\n */\n return createTracingProxy(\n this as TracesService,\n tracer,\n );\n }\n\n /**\n * Handles API errors by throwing a TracesError 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 {TracesError}\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 TracesError(\n `Failed to ${operation}: ${errorMessage}`,\n operation,\n error,\n );\n }\n\n /**\n * Retrieves a trace by its ID.\n * @param traceId The trace's unique identifier.\n * @param params Optional parameters for the request.\n * @returns The trace response object.\n * @throws {TracesError} If the API call fails.\n */\n async get(\n traceId: string,\n params?: GetTraceParams,\n ): Promise<GetTraceResponse> {\n const { data, error } = await this.config.langwatchApiClient.GET(\"/api/trace/{id}\", {\n params: {\n path: {\n id: traceId,\n },\n },\n query: params,\n });\n\n if (error) {\n this.handleApiError(\"get trace\", error);\n }\n\n return data;\n }\n}\n","import { type InternalConfig } from \"../../types\";\nimport { TracesService } from \"./service\";\nimport { type GetTraceParams, type GetTraceResponse } from \"./types\";\n\nexport class TracesFacade {\n readonly #service: TracesService;\n\n constructor(config: InternalConfig) {\n this.#service = new TracesService(config);\n }\n\n async get(traceId: string, params?: GetTraceParams): Promise<GetTraceResponse> {\n return this.#service.get(traceId, params);\n }\n}\n","import { PromptFacade as PromptsFacade } from \"./services/prompts\";\nimport { type InternalConfig } from \"./types\";\nimport { createLangWatchApiClient } from \"../internal/api/client\";\nimport { type Logger, NoOpLogger } from \"../logger\";\nimport { TracesFacade } from \"./services/traces/facade\";\nimport { getLangWatchTracer, type LangWatchTracer } from \"@/observability-sdk\";\nimport { LANGWATCH_SDK_NAME_CLIENT, LANGWATCH_SDK_VERSION, DEFAULT_ENDPOINT } from \"@/internal/constants\";\nexport interface LangWatchConstructorOptions {\n apiKey?: string;\n endpoint?: string;\n options?: {\n logger?: Logger;\n };\n}\n\nexport class LangWatch {\n private readonly config: InternalConfig;\n private readonly tracer: LangWatchTracer = getLangWatchTracer(LANGWATCH_SDK_NAME_CLIENT, LANGWATCH_SDK_VERSION);\n\n readonly prompts: PromptsFacade;\n readonly traces: TracesFacade;\n\n constructor(options: LangWatchConstructorOptions = {}) {\n const apiKey = options.apiKey ?? process.env.LANGWATCH_API_KEY ?? \"\";\n const endpoint = options.endpoint ?? process.env.LANGWATCH_ENDPOINT ?? DEFAULT_ENDPOINT;\n\n this.config = this.#createInternalConfig({\n apiKey,\n endpoint,\n options: options.options,\n });\n\n this.prompts = new PromptsFacade(this.config);\n this.traces = new TracesFacade(this.config);\n }\n\n #createInternalConfig({\n apiKey,\n endpoint,\n options,\n }: {\n apiKey: string;\n endpoint: string;\n options?: LangWatchConstructorOptions[\"options\"];\n }): InternalConfig {\n return {\n logger: options?.logger ?? new NoOpLogger(),\n langwatchApiClient: createLangWatchApiClient(apiKey, endpoint),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,yBAAyB;AAYzB,SAAS,yBACd,QACA,UACoB;AACpB,SAAO,oBAA2B;AAAA,IAChC,SAAS;AAAA,IACT,SAAS,iCACH,SAAS,EAAE,eAAe,UAAU,MAAM,IAAI,gBAAgB,OAAO,IAAI,CAAC,IADvE;AAAA,MAEP,gBAAgB;AAAA,MAChB,cAAc,sBAAsB,OAAO;AAAA,MAC3C,wBAAwB;AAAA,MACxB,4BAA4B;AAAA,MAC5B,2BAA2B;AAAA,MAC3B,4BAA4B,sBAAsB;AAAA,IACpD;AAAA,EACF,CAAC;AACH;;;ACdO,IAAM,cA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B,SAA0B,mBAAmB,2BAA2B,qBAAqB;AAjBhH;AAuBI,UAAM,UAAS,mBAAQ,WAAR,YAAkB,QAAQ,IAAI,sBAA9B,YAAmD;AAClE,UAAM,YAAW,mBAAQ,aAAR,YAAoB,QAAQ,IAAI,uBAAhC,YAAsD;AAEvE,SAAK,SAAS,sBAAK,+CAAL,WAA2B;AAAA,MACvC;AAAA,MACA;AAAA,MACA,SAAS,QAAQ;AAAA,IACnB;AAEA,SAAK,UAAU,IAAI,cAAc,KAAK,MAAM;AAC5C,SAAK,SAAS,IAAI,aAAa,KAAK,MAAM;AAAA,EAC5C;AAgBF;AAnCO;AAqBL,0BAAqB,SAAC;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAImB;AA5CrB;AA6CI,SAAO;AAAA,IACL,SAAQ,wCAAS,WAAT,YAAmB,IAAI,WAAW;AAAA,IAC1C,oBAAoB,yBAAyB,QAAQ,QAAQ;AAAA,EAC/D;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/internal/runtime.ts","../src/internal/constants.ts"],"sourcesContent":["{\n \"name\": \"langwatch\",\n \"version\": \"0.5.1\",\n \"description\": \"LangWatch TypeScript/JavaScript SDK. Interact with the full LangWatch API and use the LangWatch OpenTelemetry SDK to instrument your application. For more information, see https://docs.langwatch.ai/integration/typescript/guide\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/index.mjs\",\n \"types\": \"dist/index.d.ts\",\n \"author\": \"LangWatch\",\n \"license\": \"MIT\",\n \"engines\": {\n \"node\": \">=20\",\n \"pnpm\": \">=8\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"bin\": {\n \"langwatch\": \"./dist/cli/index.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./observability\": {\n \"types\": \"./dist/observability-sdk/index.d.ts\",\n \"require\": \"./dist/observability-sdk/index.js\",\n \"import\": \"./dist/observability-sdk/index.mjs\"\n },\n \"./observability/node\": {\n \"types\": \"./dist/observability-sdk/setup/node/index.d.ts\",\n \"require\": \"./dist/observability-sdk/setup/node/index.js\",\n \"import\": \"./dist/observability-sdk/setup/node/index.mjs\"\n },\n \"./observability/instrumentation/langchain\": {\n \"types\": \"./dist/observability-sdk/instrumentation/langchain/index.d.ts\",\n \"require\": \"./dist/observability-sdk/instrumentation/langchain/index.js\",\n \"import\": \"./dist/observability-sdk/instrumentation/langchain/index.mjs\"\n }\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/langwatch/langwatch.git\",\n \"directory\": \"typescript-sdk\"\n },\n \"scripts\": {\n \"prepare\": \"pnpm run generate:server-types && pnpm run generate:openapi-types\",\n \"cli\": \"node dist/cli/index.js\",\n \"lint\": \"eslint .\",\n \"test\": \"vitest\",\n \"test:e2e\": \"vitest run -c ./vitest.e2e.config.mts\",\n \"prebuild\": \"pnpm i && pnpm run prepare\",\n \"build\": \"tsgo --noEmit && tsup\",\n \"typecheck\": \"tsgo --noEmit\",\n \"prepublish\": \"pnpm run build\",\n \"generate:openapi-types\": \"npx openapi-typescript ../langwatch/src/app/api/openapiLangWatch.json -o ./src/internal/generated/openapi/api-client.ts\",\n \"generate:server-types\": \"./copy-types.sh\"\n },\n \"devDependencies\": {\n \"@eslint/js\": \"^9.32.0\",\n \"@opentelemetry/sdk-node\": \">=0.203.0\",\n \"@opentelemetry/sdk-trace-node\": \"^2.0.1\",\n \"@opentelemetry/sdk-trace-web\": \">=2.0.1\",\n \"@types/debug\": \"^4.1.12\",\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^24.1.0\",\n \"@typescript/native-preview\": \"7.0.0-dev.20250804.1\",\n \"@vercel/otel\": \"^1.13.0\",\n \"@vitest/coverage-v8\": \"3.2.4\",\n \"esbuild\": \"^0.25.8\",\n \"eslint\": \"^9.32.0\",\n \"fets\": \"^0.8.5\",\n \"fishery\": \"^2.3.1\",\n \"msw\": \"^2.10.4\",\n \"nock\": \"^14.0.8\",\n \"openapi-msw\": \"^1.2.0\",\n \"ts-to-zod\": \"3.15.0\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.9.2\",\n \"typescript-eslint\": \"^8.38.0\",\n \"vitest\": \"^3.2.4\",\n \"yaml\": \"^2.8.1\"\n },\n \"dependencies\": {\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/api-logs\": \"0.203.0\",\n \"@opentelemetry/core\": \"^2.0.1\",\n \"@opentelemetry/exporter-logs-otlp-http\": \"0.203.0\",\n \"@opentelemetry/exporter-trace-otlp-http\": \"0.203.0\",\n \"@opentelemetry/instrumentation\": \"0.203.0\",\n \"@opentelemetry/resources\": \"^2.0.1\",\n \"@opentelemetry/sdk-logs\": \"0.203.0\",\n \"@opentelemetry/sdk-metrics\": \"^2.0.1\",\n \"@opentelemetry/sdk-trace-base\": \"^2.0.1\",\n \"@opentelemetry/semantic-conventions\": \"^1.36.0\",\n \"@types/prompts\": \"^2.4.9\",\n \"chalk\": \"^4.1.2\",\n \"commander\": \"^12.0.0\",\n \"dotenv\": \"^16.6.1\",\n \"js-yaml\": \"^4.1.0\",\n \"liquidjs\": \"^10.21.1\",\n \"open\": \"^10.2.0\",\n \"openapi-fetch\": \"^0.14.0\",\n \"ora\": \"^5.4.1\",\n \"prompts\": \"^2.4.2\",\n \"xksuid\": \"^0.0.4\",\n \"zod\": \"^4.0.14\"\n },\n \"peerDependencies\": {\n \"@ai-sdk/openai\": \">=2.0.0 <3.0.0\",\n \"@langchain/core\": \">=0.3.0 <1.0.0\",\n \"@langchain/langgraph\": \">=0.4.0 <1.0.0\",\n \"@langchain/openai\": \">=0.6.0 <1.0.0\",\n \"@opentelemetry/context-async-hooks\": \">=1.19.0 <3.0.0\",\n \"@opentelemetry/context-zone\": \">=1.19.0 <3.0.0\",\n \"@opentelemetry/sdk-node\": \">=0.200.0 <1.0.0\",\n \"@opentelemetry/sdk-trace-web\": \">=1.19.0 <3.0.0\",\n \"langchain\": \">=0.3.0 <1.0.0\"\n }\n}\n","export type JsRuntime = \"node\" | \"deno\" | \"bun\" | \"web\" | \"unknown\";\n\nlet _runtime: JsRuntime | undefined;\n\n/**\n * Gets the cached JavaScript runtime environment.\n * @returns The detected runtime environment\n */\nexport const getRuntime = (): JsRuntime => {\n _runtime ??= detectRuntime();\n return _runtime;\n};\n\n/**\n * Resets the cached runtime. Only used for testing.\n * @internal\n */\nexport const resetRuntimeCache = (): void => {\n _runtime = undefined;\n};\n\n/**\n * Detects the JavaScript runtime environment.\n * @param globals - (Test only) Optionally override the global object for environment simulation. Only used if NODE_ENV === 'test'.\n */\nexport function detectRuntime(globals?: any): JsRuntime {\n let g = globalThis;\n if (globals) {\n if (process.env.NODE_ENV === \"test\") {\n g = globals;\n } else {\n console.warn(\"[LangWatch Observability] overriding detectRuntime is only supported when running in NODE_ENV=test\");\n }\n }\n\n try {\n if (\n \"Deno\" in g &&\n typeof g.Deno === \"object\" &&\n g.Deno &&\n 'version' in g.Deno &&\n typeof g.Deno.version === \"object\"\n ) {\n return \"deno\";\n }\n if (\n \"Bun\" in g &&\n typeof g.Bun === \"object\" &&\n g.Bun &&\n 'version' in g.Bun &&\n typeof g.Bun.version === \"string\"\n ) {\n return \"bun\";\n }\n if (\n \"process\" in g &&\n typeof g.process === \"object\" &&\n g.process &&\n typeof g.process.versions === \"object\" &&\n typeof g.process.versions.node === \"string\"\n ) {\n return \"node\";\n }\n if (\n typeof g.window?.document !== \"undefined\" &&\n g === g.window\n ) {\n return \"web\";\n }\n return \"unknown\";\n } catch (error) {\n console.warn(\"[LangWatch Observability] Failed to detect runtime\", error);\n return \"unknown\";\n }\n}\n","import { version } from \"../../package.json\";\nimport { getRuntime } from \"./runtime\";\n\nexport const LANGWATCH_SDK_RUNTIME = getRuntime;\n\nexport const LANGWATCH_SDK_NAME_OBSERVABILITY = \"langwatch-observability-sdk\";\nexport const LANGWATCH_SDK_NAME_CLIENT = \"langwatch-client-sdk\";\nexport const LANGWATCH_SDK_LANGUAGE = \"typescript\";\nexport const LANGWATCH_SDK_VERSION = version;\n\nexport const DEFAULT_ENDPOINT = \"https://app.langwatch.ai/\";\nexport const DEFAULT_SERVICE_NAME = \"unknown-service.langwatch\";\n\nexport const TRACES_PATH = \"/api/otel/v1/traces\";\nexport const LOGS_PATH = \"/api/otel/v1/logs\";\nexport const METRICS_PATH = \"/api/otel/v1/metrics\";\n"],"mappings":";AAEI,cAAW;;;ACAf,IAAI;AAMG,IAAM,aAAa,MAAiB;AACzC,2CAAa,cAAc;AAC3B,SAAO;AACT;AAcO,SAAS,cAAc,SAA0B;AAzBxD;AA0BE,MAAI,IAAI;AACR,MAAI,SAAS;AACX,QAAI,QAAQ,IAAI,aAAa,QAAQ;AACnC,UAAI;AAAA,IACN,OAAO;AACL,cAAQ,KAAK,oGAAoG;AAAA,IACnH;AAAA,EACF;AAEA,MAAI;AACF,QACE,UAAU,KACV,OAAO,EAAE,SAAS,YAClB,EAAE,QACF,aAAa,EAAE,QACf,OAAO,EAAE,KAAK,YAAY,UAC1B;AACA,aAAO;AAAA,IACT;AACA,QACE,SAAS,KACT,OAAO,EAAE,QAAQ,YACjB,EAAE,OACF,aAAa,EAAE,OACf,OAAO,EAAE,IAAI,YAAY,UACzB;AACA,aAAO;AAAA,IACT;AACA,QACE,aAAa,KACb,OAAO,EAAE,YAAY,YACrB,EAAE,WACF,OAAO,EAAE,QAAQ,aAAa,YAC9B,OAAO,EAAE,QAAQ,SAAS,SAAS,UACnC;AACA,aAAO;AAAA,IACT;AACA,QACE,SAAO,OAAE,WAAF,mBAAU,cAAa,eAC9B,MAAM,EAAE,QACR;AACA,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,KAAK,sDAAsD,KAAK;AACxE,WAAO;AAAA,EACT;AACF;;;ACvEO,IAAM,wBAAwB;AAE9B,IAAM,mCAAmC;AACzC,IAAM,4BAA4B;AAClC,IAAM,yBAAyB;AAC/B,IAAM,wBAAwB;AAE9B,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAE7B,IAAM,cAAc;AACpB,IAAM,YAAY;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logger/index.ts","../src/observability-sdk/semconv/attributes.ts","../src/observability-sdk/features/data-capture/utils.ts","../src/observability-sdk/config.ts"],"sourcesContent":["// Logger utility for SDKs\n//\n// Usage:\n// - If you pass your own Logger implementation, the SDK will use it as-is (no log level filtering or prefixing applied).\n// - If you use ConsoleLogger, you can specify log level and prefix options.\n// - NoOpLogger disables all logging.\n//\n// Example:\n// const logger = new ConsoleLogger({ level: \"warn\", prefix: \"SDK\" });\n// logger.info(\"This will not show\");\n// logger.warn(\"This will show with prefix\");\n//\n// // If you pass your own logger, SDK will not filter logs:\n// const customLogger: Logger = { ... };\n// // SDK uses customLogger as-is\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nconst logLevelOrder: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n} as const;\n\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n}\n\nexport class NoOpLogger implements Logger {\n debug(): void { /* noop */ }\n info(): void { /* noop */ }\n warn(): void { /* noop */ }\n error(): void { /* noop */ }\n}\n\ninterface ConsoleLoggerOptions {\n level: LogLevel;\n prefix?: string;\n}\n\n/**\n * ConsoleLogger applies log level filtering and optional prefixing.\n * If you pass your own Logger, the SDK will not apply log level filtering or prefixing.\n */\nexport class ConsoleLogger implements Logger {\n private level: LogLevel;\n private prefix?: string;\n\n constructor(options: ConsoleLoggerOptions = { level: \"warn\" }) {\n this.level = options.level;\n this.prefix = options.prefix;\n }\n\n private shouldLog(level: LogLevel): boolean {\n return logLevelOrder[level] >= logLevelOrder[this.level];\n }\n\n private format(message: string): string {\n return this.prefix ? `[${this.prefix}] ${message}` : message;\n }\n\n debug(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"debug\")) console.debug(this.format(message), ...args);\n }\n info(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"info\")) console.info(this.format(message), ...args);\n }\n warn(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"warn\")) console.warn(this.format(message), ...args);\n }\n error(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"error\")) console.error(this.format(message), ...args);\n }\n}\n","/*\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 user ID attribute key\n * Used to store the user ID for a span or event\n */\nexport const ATTR_LANGWATCH_USER_ID = \"langwatch.user.id\";\n\n/**\n * LangWatch tags attribute key\n * Used to store tags for a span or event\n */\nexport const ATTR_LANGWATCH_TAGS = \"langwatch.tags\";\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 ID attribute key\n * Used to identify the specific prompt being used\n */\nexport const ATTR_LANGWATCH_PROMPT_HANDLE = \"langwatch.prompt.handle\";\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 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","import { type DataCaptureMode } from \"./types\";\n\n/**\n * Validates a data capture mode.\n */\nexport function validateDataCaptureMode(mode: DataCaptureMode): boolean {\n return [\"none\", \"input\", \"output\", \"all\"].includes(mode);\n}\n","import { type Logger, NoOpLogger } from \"../logger/index.js\";\nimport {\n type DataCaptureMode,\n type DataCaptureContext,\n type DataCaptureOptions,\n} from \"./features/data-capture/types.js\";\nimport { validateDataCaptureMode } from \"./features/data-capture/utils.js\";\n\n/**\n * @module observability/config\n * @description\n * Provides configuration management for the LangWatch Observability SDK, including logger and data capture settings.\n *\n * @remarks\n * This module allows you to initialize, retrieve, and reset the global observability configuration. It also provides utilities for determining data capture behavior based on context and configuration.\n *\n * @see {@link ObservabilityConfig}\n * @see {@link initializeObservabilitySdkConfig}\n * @see {@link getObservabilitySdkConfig}\n * @see {@link resetObservabilitySdkConfig}\n * @see {@link getDataCaptureMode}\n * @see {@link shouldCaptureInput}\n * @see {@link shouldCaptureOutput}\n */\n/**\n * Configuration options for the LangWatch Observability SDK.\n *\n * @property logger - The logger instance to use for SDK logging.\n * @property dataCapture - Configuration for automatic data capture. Can be a string, function, or object.\n *\n * @example\n * ```ts\n * import { ObservabilityConfig, initializeObservabilitySdkConfig } from \"@langwatch/observability\";\n *\n * const config: ObservabilityConfig = {\n * logger: new ConsoleLogger(),\n * dataCapture: \"all\",\n * };\n *\n * initializeObservabilitySdkConfig(config);\n * ```\n */\nexport interface ObservabilityConfig {\n /**\n * The logger to use for the observability SDK.\n *\n * @default NoOpLogger\n */\n logger: Logger;\n\n /**\n * Configuration for automatic data capture.\n *\n * @default \"all\"\n */\n dataCapture?: DataCaptureOptions;\n}\n\n/**\n * The observability SDK config.\n */\nlet observabilitySdkConfig: ObservabilityConfig | null = null;\n\n/**\n * Initializes the global observability SDK configuration.\n *\n * @param config - The configuration object to use.\n *\n * @remarks\n * This function should be called once at application startup, before using any observability features.\n *\n * @warning\n * Calling this function will intentionally overwrite any existing configuration. This is by design to allow re-initialization in dynamic or testing environments. If you call this function multiple times, the most recent configuration will take effect.\n *\n * @example\n * ```ts\n * initializeObservabilitySdkConfig({ logger: new ConsoleLogger() });\n * ```\n */\nexport function initializeObservabilitySdkConfig(config: ObservabilityConfig) {\n observabilitySdkConfig = config;\n}\n\n/**\n * Resets the global observability SDK configuration to its initial state (`null`).\n *\n * @remarks\n * Useful for testing or re-initializing the SDK in dynamic environments.\n *\n * @example\n * ```ts\n * resetObservabilitySdkConfig();\n * ```\n */\nexport function resetObservabilitySdkConfig() {\n observabilitySdkConfig = null;\n}\n\n/**\n * Retrieves the current observability SDK configuration.\n *\n * @param options - Optional settings.\n * @param options.throwOnUninitialized - If true, throws an error if the config is not initialized. Defaults to `false` unless `NODE_ENV` is `development`.\n * @returns The current {@link ObservabilityConfig}.\n *\n * @throws {Error} If the config is uninitialized and `throwOnUninitialized` is true or in development mode.\n *\n * @example\n * ```ts\n * const config = getObservabilitySdkConfig();\n * ```\n */\nexport function getObservabilitySdkConfig(options?: {\n throwOnUninitialized?: boolean;\n}): ObservabilityConfig {\n if (!observabilitySdkConfig) {\n const message =\n \"[LangWatch Observability SDK] Please call setupObservability() before using the Observability SDK\";\n\n if (\n options?.throwOnUninitialized ||\n process.env.NODE_ENV === \"development\"\n ) {\n throw new Error(message);\n }\n\n // Use a default logger that can be configured\n return {\n logger: new NoOpLogger(),\n };\n }\n return observabilitySdkConfig;\n}\n\n/**\n * Gets the logger instance from the current observability SDK configuration.\n *\n * @returns The configured {@link Logger} instance.\n *\n * @example\n * ```ts\n * const logger = getObservabilitySdkLogger();\n * logger.info(\"Observability initialized\");\n * ```\n */\nexport function getObservabilitySdkLogger(): Logger {\n return getObservabilitySdkConfig().logger;\n}\n\n/**\n * Determines the effective data capture mode.\n *\n * @returns The resolved {@link DataCaptureMode} (\"all\", \"input\", or \"output\").\n *\n * @remarks\n * The mode is determined by the configuration, which can be a string, function, or object. Defaults to \"all\" if not specified.\n *\n * @example\n * ```ts\n * const mode = getDataCaptureMode();\n * ```\n */\nexport function getDataCaptureMode(): DataCaptureMode {\n const config = getObservabilitySdkConfig();\n\n if (!config.dataCapture) {\n return \"all\"; // Default: capture both input and output\n }\n\n // Handle different config formats\n if (typeof config.dataCapture === \"string\") {\n const validModes: DataCaptureMode[] = [\"none\", \"input\", \"output\", \"all\"];\n if (validModes.includes(config.dataCapture)) {\n return config.dataCapture;\n }\n\n\n getObservabilitySdkLogger().warn(\n `Invalid data capture mode: ${config.dataCapture}. Using default: \"all\"`,\n );\n\n return \"all\";\n }\n\n if (typeof config.dataCapture === \"object\" && config.dataCapture.mode &&validateDataCaptureMode(config.dataCapture.mode)) {\n return config.dataCapture.mode;\n }\n\n return \"all\"; // Default fallback\n}\n\n/**\n * Determines if input data should be captured.\n *\n * @returns `true` if input should be captured, otherwise `false`.\n *\n * @example\n * ```ts\n * if (shouldCaptureInput()) {\n * // Capture input\n * }\n * ```\n */\nexport function shouldCaptureInput(): boolean {\n const mode = getDataCaptureMode();\n return mode === \"input\" || mode === \"all\";\n}\n\n/**\n * Determines if output data should be captured.\n *\n * @returns `true` if output should be captured, otherwise `false`.\n *\n * @example\n * ```ts\n * if (shouldCaptureOutput()) {\n * // Capture output\n * }\n * ```\n */\nexport function shouldCaptureOutput(): boolean {\n const mode = getDataCaptureMode();\n return mode === \"output\" || mode === \"all\";\n}\n"],"mappings":";;;;;AAkBA,IAAM,gBAA0C;AAAA,EAC9C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AASO,IAAM,aAAN,MAAmC;AAAA,EACxC,QAAc;AAAA,EAAa;AAAA,EAC3B,OAAa;AAAA,EAAa;AAAA,EAC1B,OAAa;AAAA,EAAa;AAAA,EAC1B,QAAc;AAAA,EAAa;AAC7B;AAWO,IAAM,gBAAN,MAAsC;AAAA,EAI3C,YAAY,UAAgC,EAAE,OAAO,OAAO,GAAG;AAC7D,SAAK,QAAQ,QAAQ;AACrB,SAAK,SAAS,QAAQ;AAAA,EACxB;AAAA,EAEQ,UAAU,OAA0B;AAC1C,WAAO,cAAc,KAAK,KAAK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AO;AACT;AAcO,SAAS,qBAA8B;AAC5C,QAAM,OAAO,mBAAmB;AAChC,SAAO,SAAS,WAAW,SAAS;AACtC;AAcO,SAAS,sBAA+B;AAC7C,QAAM,OAAO,mBAAmB;AAChC,SAAO,SAAS,YAAY,SAAS;AACvC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/create-4LG4N2A4.js","../src/cli/commands/create.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B,+BAA4B;AAC5B,+BAA4B;AAC5B;AACA;ACbA,+DAAoB;AACpB,uEAAsB;AACtB,4EAAkB;AAOX,IAAM,cAAA,EAAgB,MAAA,CAC3B,IAAA,EACA,QAAA,EAAA,GACkB;AAClB,EAAA,IAAI;AAEF,IAAA,GAAA,CAAI,CAAC,KAAA,GAAQ,IAAA,CAAK,IAAA,CAAK,EAAA,IAAM,EAAA,EAAI;AAC/B,MAAA,OAAA,CAAQ,KAAA,CAAM,eAAA,CAAM,GAAA,CAAI,oCAAoC,CAAC,CAAA;AAC7D,MAAA,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA;AAAA,IAChB;AAGA,IAAA,0CAAA,CAAY;AAGZ,IAAA,MAAM,uDAAA,CAAyB;AAG/B,IAAA,MAAM,WAAA,EAAkB,IAAA,CAAA,IAAA;AAAA,MACtB,OAAA,CAAQ,GAAA,CAAI,CAAA;AAAA,MACZ,SAAA;AAAA,MACA,CAAA,EAAA;AACF,IAAA;AAEA,IAAA;AACE,MAAA;AAAQ,QAAA;AAER,MAAA;AACA,MAAA;AACF,IAAA;AAGA,IAAA;AACA,IAAA;AACK,MAAA;AACL,IAAA;AAGA,IAAA;AAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWpB,IAAA;AAGH,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAGA,IAAA;AACA,IAAA;AACE,MAAA;AAAS;AACT,MAAA;AACA,MAAA;AAAc;AAChB,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACE,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACF,EAAA;AACF;ADXO;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/create-4LG4N2A4.js","sourcesContent":[null,"import * as fs from \"fs\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport { FileManager } from \"../utils/fileManager\";\nimport { checkApiKey } from \"../utils/apiKey\";\nimport { ensureProjectInitialized } from \"../utils/init\";\n\ntype CreateOptions = Record<string, unknown>;\n\nexport const createCommand = async (\n name: string,\n _options: CreateOptions,\n): Promise<void> => {\n try {\n // Validate prompt name\n if (!name || name.trim() === \"\") {\n console.error(chalk.red(\"Error: Prompt name cannot be empty\"));\n process.exit(1);\n }\n\n // Check API key before doing anything else\n checkApiKey();\n\n // Ensure project is initialized\n await ensureProjectInitialized();\n\n // Check if file already exists\n const promptPath = path.join(\n process.cwd(),\n \"prompts\",\n `${name}.prompt.yaml`,\n );\n\n if (fs.existsSync(promptPath)) {\n console.error(\n chalk.red(`Error: Prompt file already exists at ${promptPath}`),\n );\n process.exit(1);\n }\n\n // Create prompts directory if it doesn't exist\n const promptsDir = path.dirname(promptPath);\n if (!fs.existsSync(promptsDir)) {\n fs.mkdirSync(promptsDir, { recursive: true });\n }\n\n // Default prompt content\n const defaultContent = `model: openai/gpt-5\nmodelParameters:\n temperature: 0.7\nmessages:\n - role: system\n content: You are a helpful assistant.\n - role: user\n content: \"{{input}}\"\n`;\n\n // Write the file\n fs.writeFileSync(promptPath, defaultContent, \"utf8\");\n\n // Add to prompts.json as a file: dependency\n const promptsConfig = FileManager.loadPromptsConfig();\n const relativePath = path.relative(process.cwd(), promptPath);\n promptsConfig.prompts[name] = `file:${relativePath}`;\n FileManager.savePromptsConfig(promptsConfig);\n\n // Update lock file\n const lock = FileManager.loadPromptsLock();\n lock.prompts[name] = {\n version: 0, // Local files start at version 0\n versionId: \"local\",\n materialized: relativePath, // Store the original file path\n };\n FileManager.savePromptsLock(lock);\n\n const displayPath = `./${relativePath}`;\n console.log(\n chalk.green(`✓ Created prompt file: ${chalk.cyan(displayPath)}`),\n );\n console.log(chalk.gray(` Edit this file and then run:`));\n console.log(chalk.cyan(` langwatch prompt sync`));\n } catch (error) {\n console.error(\n chalk.red(\"Unexpected error:\"),\n error instanceof Error ? error.message : error,\n );\n process.exit(1);\n }\n};\n"]}
|