langwatch 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{add-LBBS4I3H.js → add-RGWB3264.js} +35 -28
- package/dist/add-RGWB3264.js.map +1 -0
- package/dist/{add-RD3ZKFAT.mjs → add-WLUMK5VQ.mjs} +23 -16
- package/dist/add-WLUMK5VQ.mjs.map +1 -0
- package/dist/chunk-4ILMGMAP.mjs +155 -0
- package/dist/chunk-4ILMGMAP.mjs.map +1 -0
- package/dist/chunk-4TF2O2TH.js +207 -0
- package/dist/chunk-4TF2O2TH.js.map +1 -0
- package/dist/chunk-5N5BUR2Z.js +636 -0
- package/dist/chunk-5N5BUR2Z.js.map +1 -0
- package/dist/chunk-AZELEDOV.js +155 -0
- package/dist/chunk-AZELEDOV.js.map +1 -0
- package/dist/{chunk-YN4436PK.mjs → chunk-CU3443HD.mjs} +14 -9
- package/dist/{chunk-2JU376G7.js → chunk-D2CSG4SJ.js} +4 -4
- package/dist/chunk-D2CSG4SJ.js.map +1 -0
- package/dist/chunk-DEVJ7BPE.js +63 -0
- package/dist/chunk-DEVJ7BPE.js.map +1 -0
- package/dist/chunk-DISMHYXC.js +184 -0
- package/dist/chunk-DISMHYXC.js.map +1 -0
- package/dist/{chunk-E7UE2MPD.mjs → chunk-ECUXLXFT.mjs} +2 -2
- package/dist/chunk-EJWJXTPU.mjs +626 -0
- package/dist/chunk-EJWJXTPU.mjs.map +1 -0
- package/dist/chunk-FQSWUK5N.mjs +63 -0
- package/dist/chunk-FQSWUK5N.mjs.map +1 -0
- package/dist/{chunk-3GKPQB4R.mjs → chunk-HUI45ULC.mjs} +4 -4
- package/dist/chunk-HUI45ULC.mjs.map +1 -0
- package/dist/chunk-IZ2U3ABC.mjs +636 -0
- package/dist/chunk-IZ2U3ABC.mjs.map +1 -0
- package/dist/{chunk-HJU67C7H.js → chunk-K64Y6YUG.js} +10 -10
- package/dist/{chunk-HJU67C7H.js.map → chunk-K64Y6YUG.js.map} +1 -1
- package/dist/chunk-M4VUHTT2.js +626 -0
- package/dist/chunk-M4VUHTT2.js.map +1 -0
- package/dist/{chunk-PR3JDWC3.mjs → chunk-N2V6J3U2.mjs} +28 -3
- package/dist/chunk-N2V6J3U2.mjs.map +1 -0
- package/dist/{chunk-FJLK5CFL.js → chunk-OXBO24RB.js} +13 -8
- package/dist/chunk-OXBO24RB.js.map +1 -0
- package/dist/{chunk-SMXXAVMB.js → chunk-SGNJDRCT.js} +2 -2
- package/dist/chunk-SGNJDRCT.js.map +1 -0
- package/dist/{chunk-W5ZEP3CI.mjs → chunk-SYMZPWZE.mjs} +2 -2
- package/dist/chunk-SYMZPWZE.mjs.map +1 -0
- package/dist/{chunk-KGDAENGD.js → chunk-YH5TIVK2.js} +28 -3
- package/dist/chunk-YH5TIVK2.js.map +1 -0
- package/dist/chunk-YNQ44U6D.mjs +184 -0
- package/dist/chunk-YNQ44U6D.mjs.map +1 -0
- package/dist/chunk-ZJZ3MIWE.mjs +207 -0
- package/dist/chunk-ZJZ3MIWE.mjs.map +1 -0
- package/dist/cli/index.js +8 -8
- package/dist/cli/index.mjs +8 -8
- package/dist/{create-G5MTGOOH.js → create-7K2CC4KQ.js} +11 -11
- package/dist/{create-G5MTGOOH.js.map → create-7K2CC4KQ.js.map} +1 -1
- package/dist/{create-QUZYBMQB.mjs → create-MK7NEGCM.mjs} +8 -8
- package/dist/implementation-C4lvooSg.d.mts +576 -0
- package/dist/implementation-CzemP9jY.d.ts +576 -0
- package/dist/index-DTEZr0Jn.d.mts +34 -0
- package/dist/index-DTEZr0Jn.d.ts +34 -0
- package/dist/index.d.mts +121 -47
- package/dist/index.d.ts +121 -47
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -23
- package/dist/index.mjs.map +1 -1
- package/dist/init-GDKJICSS.js +16 -0
- package/dist/{init-XU2JFY6N.js.map → init-GDKJICSS.js.map} +1 -1
- package/dist/{init-H67RW22E.mjs → init-RINSTP4L.mjs} +5 -5
- package/dist/{list-ZXFLAF52.js → list-DBUK47MA.js} +30 -17
- package/dist/list-DBUK47MA.js.map +1 -0
- package/dist/{list-7NPSX2E4.mjs → list-ZOMRKOBV.mjs} +29 -16
- package/dist/list-ZOMRKOBV.mjs.map +1 -0
- package/dist/{login-76NQIHKR.js → login-A7LEPNBR.js} +8 -4
- package/dist/login-A7LEPNBR.js.map +1 -0
- package/dist/{login-EK4WVOI2.mjs → login-ULPHWIAX.mjs} +8 -4
- package/dist/login-ULPHWIAX.mjs.map +1 -0
- package/dist/observability-sdk/index.d.mts +134 -0
- package/dist/observability-sdk/index.d.ts +134 -0
- package/dist/observability-sdk/index.js +42 -0
- package/dist/observability-sdk/index.js.map +1 -0
- package/dist/observability-sdk/index.mjs +42 -0
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +69 -0
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +69 -0
- package/dist/observability-sdk/instrumentation/langchain/index.js +518 -0
- package/dist/observability-sdk/instrumentation/langchain/index.js.map +1 -0
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +518 -0
- package/dist/observability-sdk/instrumentation/langchain/index.mjs.map +1 -0
- package/dist/observability-sdk/setup/node/index.d.mts +368 -0
- package/dist/observability-sdk/setup/node/index.d.ts +368 -0
- package/dist/observability-sdk/setup/node/index.js +279 -0
- package/dist/observability-sdk/setup/node/index.js.map +1 -0
- package/dist/observability-sdk/setup/node/index.mjs +279 -0
- package/dist/observability-sdk/setup/node/index.mjs.map +1 -0
- package/dist/{remove-XBNGIVMR.js → remove-ODTJLFWR.js} +19 -15
- package/dist/remove-ODTJLFWR.js.map +1 -0
- package/dist/{remove-SDJYEPAY.mjs → remove-RAJBGHQQ.mjs} +12 -8
- package/dist/remove-RAJBGHQQ.mjs.map +1 -0
- package/dist/{sync-ST2IWXSB.mjs → sync-2IXPWN64.mjs} +40 -33
- package/dist/sync-2IXPWN64.mjs.map +1 -0
- package/dist/{sync-EISKGPTL.js → sync-PBOL5ODF.js} +53 -46
- package/dist/sync-PBOL5ODF.js.map +1 -0
- package/dist/{prompt-D-jpMrLS.d.mts → types-1q5wIYP5.d.mts} +628 -14
- package/dist/{prompt-D-jpMrLS.d.ts → types-C9k5gGhU.d.ts} +628 -14
- package/dist/types-DRiQaKFG.d.mts +254 -0
- package/dist/types-DRiQaKFG.d.ts +254 -0
- package/dist/types-Dmazk5Bk.d.mts +44 -0
- package/dist/types-Dmazk5Bk.d.ts +44 -0
- package/package.json +39 -39
- package/dist/add-LBBS4I3H.js.map +0 -1
- package/dist/add-RD3ZKFAT.mjs.map +0 -1
- package/dist/chunk-2JU376G7.js.map +0 -1
- package/dist/chunk-2ODBGSBI.js +0 -4
- package/dist/chunk-2ODBGSBI.js.map +0 -1
- package/dist/chunk-3GKPQB4R.mjs.map +0 -1
- package/dist/chunk-52GXX3MA.js +0 -426
- package/dist/chunk-52GXX3MA.js.map +0 -1
- package/dist/chunk-5NC5ILKA.js +0 -94
- package/dist/chunk-5NC5ILKA.js.map +0 -1
- package/dist/chunk-AAROJADR.mjs +0 -49
- package/dist/chunk-AAROJADR.mjs.map +0 -1
- package/dist/chunk-DTEKFQ4U.js +0 -159
- package/dist/chunk-DTEKFQ4U.js.map +0 -1
- package/dist/chunk-F63YKTXA.mjs +0 -47
- package/dist/chunk-F63YKTXA.mjs.map +0 -1
- package/dist/chunk-FJLK5CFL.js.map +0 -1
- package/dist/chunk-GJSEBQXF.mjs +0 -392
- package/dist/chunk-GJSEBQXF.mjs.map +0 -1
- package/dist/chunk-IGHXIIIK.js +0 -49
- package/dist/chunk-IGHXIIIK.js.map +0 -1
- package/dist/chunk-J7ICRUU4.mjs +0 -426
- package/dist/chunk-J7ICRUU4.mjs.map +0 -1
- package/dist/chunk-KGDAENGD.js.map +0 -1
- package/dist/chunk-LD74LVRU.js +0 -47
- package/dist/chunk-LD74LVRU.js.map +0 -1
- package/dist/chunk-PCQVQ7SB.js +0 -45
- package/dist/chunk-PCQVQ7SB.js.map +0 -1
- package/dist/chunk-PR3JDWC3.mjs.map +0 -1
- package/dist/chunk-PWZBLTHR.js +0 -118
- package/dist/chunk-PWZBLTHR.js.map +0 -1
- package/dist/chunk-QEWDG5QE.mjs +0 -45
- package/dist/chunk-QEWDG5QE.mjs.map +0 -1
- package/dist/chunk-SMXXAVMB.js.map +0 -1
- package/dist/chunk-STV4ZVNA.mjs +0 -118
- package/dist/chunk-STV4ZVNA.mjs.map +0 -1
- package/dist/chunk-T5AZMMVS.mjs +0 -94
- package/dist/chunk-T5AZMMVS.mjs.map +0 -1
- package/dist/chunk-UU33HCCZ.mjs +0 -159
- package/dist/chunk-UU33HCCZ.mjs.map +0 -1
- package/dist/chunk-VGHLQXKB.js +0 -392
- package/dist/chunk-VGHLQXKB.js.map +0 -1
- package/dist/chunk-W5ZEP3CI.mjs.map +0 -1
- package/dist/chunk-Y666BJA5.mjs +0 -4
- package/dist/chunk-YN4436PK.mjs.map +0 -1
- package/dist/client-B2HqIKg6.d.ts +0 -51
- package/dist/client-XyCqclCi.d.mts +0 -51
- package/dist/client-browser.d.mts +0 -8
- package/dist/client-browser.d.ts +0 -8
- package/dist/client-browser.js +0 -88
- package/dist/client-browser.js.map +0 -1
- package/dist/client-browser.mjs +0 -88
- package/dist/client-browser.mjs.map +0 -1
- package/dist/client-node.d.mts +0 -8
- package/dist/client-node.d.ts +0 -8
- package/dist/client-node.js +0 -95
- package/dist/client-node.js.map +0 -1
- package/dist/client-node.mjs +0 -95
- package/dist/client-node.mjs.map +0 -1
- package/dist/evaluation/index.d.mts +0 -897
- package/dist/evaluation/index.d.ts +0 -897
- package/dist/evaluation/index.js +0 -14
- package/dist/evaluation/index.js.map +0 -1
- package/dist/evaluation/index.mjs +0 -14
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +0 -64
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +0 -64
- package/dist/init-XU2JFY6N.js +0 -16
- package/dist/list-7NPSX2E4.mjs.map +0 -1
- package/dist/list-ZXFLAF52.js.map +0 -1
- package/dist/login-76NQIHKR.js.map +0 -1
- package/dist/login-EK4WVOI2.mjs.map +0 -1
- package/dist/observability/index.d.mts +0 -260
- package/dist/observability/index.d.ts +0 -260
- package/dist/observability/index.js +0 -21
- package/dist/observability/index.js.map +0 -1
- package/dist/observability/index.mjs +0 -21
- package/dist/observability/index.mjs.map +0 -1
- package/dist/observability/instrumentation/langchain/index.d.mts +0 -40
- package/dist/observability/instrumentation/langchain/index.d.ts +0 -40
- package/dist/observability/instrumentation/langchain/index.js +0 -668
- package/dist/observability/instrumentation/langchain/index.js.map +0 -1
- package/dist/observability/instrumentation/langchain/index.mjs +0 -668
- package/dist/observability/instrumentation/langchain/index.mjs.map +0 -1
- package/dist/prompt/index.d.mts +0 -10
- package/dist/prompt/index.d.ts +0 -10
- package/dist/prompt/index.js +0 -22
- package/dist/prompt/index.js.map +0 -1
- package/dist/prompt/index.mjs +0 -22
- package/dist/prompt/index.mjs.map +0 -1
- package/dist/record-evaluation-CmxMXa-3.d.mts +0 -25
- package/dist/record-evaluation-CmxMXa-3.d.ts +0 -25
- package/dist/remove-SDJYEPAY.mjs.map +0 -1
- package/dist/remove-XBNGIVMR.js.map +0 -1
- package/dist/sync-EISKGPTL.js.map +0 -1
- package/dist/sync-ST2IWXSB.mjs.map +0 -1
- package/dist/trace-CqaKo0kZ.d.ts +0 -622
- package/dist/trace-DtVc5GhF.d.mts +0 -622
- /package/dist/{chunk-Y666BJA5.mjs.map → chunk-CU3443HD.mjs.map} +0 -0
- /package/dist/{chunk-E7UE2MPD.mjs.map → chunk-ECUXLXFT.mjs.map} +0 -0
- /package/dist/{create-QUZYBMQB.mjs.map → create-MK7NEGCM.mjs.map} +0 -0
- /package/dist/{init-H67RW22E.mjs.map → init-RINSTP4L.mjs.map} +0 -0
- /package/dist/{evaluation → observability-sdk}/index.mjs.map +0 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLangWatchTracer
|
|
3
|
+
} from "./chunk-EJWJXTPU.mjs";
|
|
4
|
+
import {
|
|
5
|
+
LANGWATCH_SDK_NAME_CLIENT,
|
|
6
|
+
LANGWATCH_SDK_VERSION
|
|
7
|
+
} from "./chunk-FQSWUK5N.mjs";
|
|
8
|
+
import {
|
|
9
|
+
shouldCaptureInput,
|
|
10
|
+
shouldCaptureOutput
|
|
11
|
+
} from "./chunk-YNQ44U6D.mjs";
|
|
12
|
+
import {
|
|
13
|
+
PromptConverter
|
|
14
|
+
} from "./chunk-SYMZPWZE.mjs";
|
|
15
|
+
import {
|
|
16
|
+
__spreadProps,
|
|
17
|
+
__spreadValues
|
|
18
|
+
} from "./chunk-CU3443HD.mjs";
|
|
19
|
+
|
|
20
|
+
// src/client-sdk/services/prompts/prompt.ts
|
|
21
|
+
import { Liquid } from "liquidjs";
|
|
22
|
+
|
|
23
|
+
// src/client-sdk/services/prompts/tracing/prompt-tracing.decorator.ts
|
|
24
|
+
var PromptTracingDecorator = class {
|
|
25
|
+
constructor(target) {
|
|
26
|
+
this.target = target;
|
|
27
|
+
}
|
|
28
|
+
traceCompilation(span, variables, compileFn) {
|
|
29
|
+
var _a;
|
|
30
|
+
span.setType("prompt");
|
|
31
|
+
if (shouldCaptureInput()) {
|
|
32
|
+
span.setInput(this.target.raw);
|
|
33
|
+
if (variables) {
|
|
34
|
+
span.setAttribute(
|
|
35
|
+
"langwatch.prompt.variables",
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
type: "json",
|
|
38
|
+
value: variables
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const result = compileFn();
|
|
44
|
+
span.setAttributes({
|
|
45
|
+
"langwatch.prompt.id": result.id,
|
|
46
|
+
"langwatch.prompt.handle": (_a = result.handle) != null ? _a : "",
|
|
47
|
+
"langwatch.prompt.version.id": result.versionId,
|
|
48
|
+
"langwatch.prompt.version.number": result.version
|
|
49
|
+
});
|
|
50
|
+
if (shouldCaptureOutput()) {
|
|
51
|
+
span.setOutput(result.raw);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
compile(span, variables = {}) {
|
|
56
|
+
return this.traceCompilation(
|
|
57
|
+
span,
|
|
58
|
+
variables,
|
|
59
|
+
() => this.target.compile(variables)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
compileStrict(span, variables) {
|
|
63
|
+
return this.traceCompilation(
|
|
64
|
+
span,
|
|
65
|
+
variables,
|
|
66
|
+
() => this.target.compileStrict(variables)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/client-sdk/services/prompts/tracing/prompt-service-tracing.decorator.ts
|
|
72
|
+
var PromptServiceTracingDecorator = class {
|
|
73
|
+
constructor(target) {
|
|
74
|
+
this.target = target;
|
|
75
|
+
}
|
|
76
|
+
async get(span, id, options) {
|
|
77
|
+
var _a;
|
|
78
|
+
span.setType("prompt");
|
|
79
|
+
span.setAttribute("langwatch.prompt.id", id);
|
|
80
|
+
const result = await this.target.get(id, options);
|
|
81
|
+
if (result) {
|
|
82
|
+
span.setAttributes({
|
|
83
|
+
"langwatch.prompt.id": result.id,
|
|
84
|
+
"langwatch.prompt.handle": (_a = result.handle) != null ? _a : "",
|
|
85
|
+
"langwatch.prompt.version.id": result.versionId,
|
|
86
|
+
"langwatch.prompt.version.number": result.version
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (result && shouldCaptureOutput()) {
|
|
90
|
+
span.setOutput("json", result.raw);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
async create(span, params) {
|
|
95
|
+
var _a;
|
|
96
|
+
span.setType("prompt");
|
|
97
|
+
if (shouldCaptureInput()) {
|
|
98
|
+
span.setInput(params);
|
|
99
|
+
}
|
|
100
|
+
const result = await this.target.create(params);
|
|
101
|
+
span.setAttribute("langwatch.prompt.id", result.id);
|
|
102
|
+
span.setAttribute("langwatch.prompt.handle", (_a = result.handle) != null ? _a : "");
|
|
103
|
+
span.setAttribute("langwatch.prompt.scope", result.scope);
|
|
104
|
+
span.setAttribute("langwatch.prompt.version.id", result.versionId);
|
|
105
|
+
span.setAttribute("langwatch.prompt.version.number", result.version);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
async update(span, id, params) {
|
|
109
|
+
var _a;
|
|
110
|
+
if (shouldCaptureInput()) {
|
|
111
|
+
span.setInput(params);
|
|
112
|
+
}
|
|
113
|
+
const result = await this.target.update(id, params);
|
|
114
|
+
span.setType("prompt");
|
|
115
|
+
span.setAttribute("langwatch.prompt.id", id);
|
|
116
|
+
span.setAttribute("langwatch.prompt.handle", (_a = result.handle) != null ? _a : "");
|
|
117
|
+
span.setAttribute("langwatch.prompt.scope", result.scope);
|
|
118
|
+
span.setAttribute("langwatch.prompt.version.id", result.versionId);
|
|
119
|
+
span.setAttribute("langwatch.prompt.version.number", result.version);
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
async delete(span, id) {
|
|
123
|
+
const result = await this.target.delete(id);
|
|
124
|
+
span.setType("prompt");
|
|
125
|
+
span.setAttribute("langwatch.prompt.id", id);
|
|
126
|
+
span.setAttribute("langwatch.prompt.deleted", "true");
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
async upsert(span, handle, config) {
|
|
130
|
+
if (shouldCaptureInput()) {
|
|
131
|
+
span.setInput(config);
|
|
132
|
+
}
|
|
133
|
+
const result = await this.target.upsert(handle, config);
|
|
134
|
+
span.setType("prompt");
|
|
135
|
+
span.setAttribute("langwatch.prompt.handle", handle);
|
|
136
|
+
span.setAttribute("langwatch.prompt.created", result.created.toString());
|
|
137
|
+
span.setAttribute("langwatch.prompt.id", result.prompt.id);
|
|
138
|
+
span.setAttribute("langwatch.prompt.version.id", result.prompt.versionId);
|
|
139
|
+
span.setAttribute("langwatch.prompt.version.number", result.prompt.version);
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
async sync(span, params) {
|
|
143
|
+
if (shouldCaptureInput()) {
|
|
144
|
+
span.setInput(params);
|
|
145
|
+
}
|
|
146
|
+
const result = await this.target.sync(params);
|
|
147
|
+
span.setType("prompt");
|
|
148
|
+
span.setAttribute("langwatch.prompt.name", params.name);
|
|
149
|
+
span.setAttribute("langwatch.prompt.sync.action", result.action);
|
|
150
|
+
if (result.conflictInfo) {
|
|
151
|
+
span.setAttribute("langwatch.prompt.sync.has_conflict", "true");
|
|
152
|
+
span.setAttribute("langwatch.prompt.sync.local_version", result.conflictInfo.localVersion.toString());
|
|
153
|
+
span.setAttribute("langwatch.prompt.sync.remote_version", result.conflictInfo.remoteVersion.toString());
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/client-sdk/services/prompts/tracing/tracer.ts
|
|
160
|
+
var tracer = getLangWatchTracer(`${LANGWATCH_SDK_NAME_CLIENT}.prompts`, LANGWATCH_SDK_VERSION);
|
|
161
|
+
|
|
162
|
+
// src/client-sdk/tracing/create-tracing-proxy.ts
|
|
163
|
+
import { SpanKind } from "@opentelemetry/api";
|
|
164
|
+
function createTracingProxy(target, tracer2, DecoratorClass) {
|
|
165
|
+
const decorator = DecoratorClass ? new DecoratorClass(target) : null;
|
|
166
|
+
return new Proxy(target, {
|
|
167
|
+
get(target2, prop, receiver) {
|
|
168
|
+
const value = Reflect.get(target2, prop, receiver);
|
|
169
|
+
if (typeof value !== "function") {
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
if (typeof prop === "string" && !prop.startsWith("_") && // Skip private methods
|
|
173
|
+
!isGetterOrSetter(target2, prop) && // Skip actual getters/setters
|
|
174
|
+
!isBuiltInMethod(prop)) {
|
|
175
|
+
return (...args) => {
|
|
176
|
+
const spanName = `${target2.constructor.name}.${prop}`;
|
|
177
|
+
return tracer2.withActiveSpan(spanName, {
|
|
178
|
+
kind: SpanKind.CLIENT,
|
|
179
|
+
attributes: {
|
|
180
|
+
"code.function": prop,
|
|
181
|
+
"code.namespace": target2.constructor.name
|
|
182
|
+
}
|
|
183
|
+
}, (span) => {
|
|
184
|
+
if (decorator && prop in decorator) {
|
|
185
|
+
const decoratorMethod = decorator[prop];
|
|
186
|
+
if (typeof decoratorMethod === "function") {
|
|
187
|
+
return decoratorMethod.apply(decorator, [span, ...args]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return value.apply(target2, args);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return typeof value === "function" ? value.bind(target2) : value;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
var isGetterOrSetter = (target, prop) => {
|
|
199
|
+
var _a;
|
|
200
|
+
let descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
201
|
+
if (!descriptor) {
|
|
202
|
+
const prototype = Object.getPrototypeOf(target);
|
|
203
|
+
if (prototype) {
|
|
204
|
+
descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return !!((_a = descriptor == null ? void 0 : descriptor.get) != null ? _a : descriptor == null ? void 0 : descriptor.set);
|
|
208
|
+
};
|
|
209
|
+
var isBuiltInMethod = (prop) => {
|
|
210
|
+
if (typeof prop !== "string") {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
const builtInMethods = [
|
|
214
|
+
"toString",
|
|
215
|
+
"valueOf",
|
|
216
|
+
"toJSON",
|
|
217
|
+
"toLocaleString",
|
|
218
|
+
"hasOwnProperty",
|
|
219
|
+
"isPrototypeOf",
|
|
220
|
+
"propertyIsEnumerable",
|
|
221
|
+
"constructor"
|
|
222
|
+
];
|
|
223
|
+
return builtInMethods.includes(prop);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/client-sdk/services/prompts/prompt.ts
|
|
227
|
+
var PromptCompilationError = class extends Error {
|
|
228
|
+
constructor(message, template, originalError) {
|
|
229
|
+
super(message);
|
|
230
|
+
this.template = template;
|
|
231
|
+
this.originalError = originalError;
|
|
232
|
+
this.name = "PromptCompilationError";
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var liquid = new Liquid({
|
|
236
|
+
strictFilters: true
|
|
237
|
+
});
|
|
238
|
+
var Prompt = class {
|
|
239
|
+
constructor(promptData) {
|
|
240
|
+
this.promptData = promptData;
|
|
241
|
+
this.id = promptData.id;
|
|
242
|
+
this.handle = promptData.handle;
|
|
243
|
+
this.scope = promptData.scope;
|
|
244
|
+
this.name = promptData.name;
|
|
245
|
+
this.updatedAt = promptData.updatedAt;
|
|
246
|
+
this.version = promptData.version;
|
|
247
|
+
this.versionId = promptData.versionId;
|
|
248
|
+
this.versionCreatedAt = promptData.versionCreatedAt;
|
|
249
|
+
this.model = promptData.model;
|
|
250
|
+
this.prompt = promptData.prompt;
|
|
251
|
+
this.messages = promptData.messages;
|
|
252
|
+
this.response_format = promptData.response_format;
|
|
253
|
+
return createTracingProxy(this, tracer, PromptTracingDecorator);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get the raw prompt data from the API
|
|
257
|
+
*/
|
|
258
|
+
get raw() {
|
|
259
|
+
return this.promptData;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Compile the prompt template with provided variables (lenient - missing variables become empty)
|
|
263
|
+
* @param variables - Object containing variable values for template compilation
|
|
264
|
+
* @returns CompiledPrompt instance with compiled content
|
|
265
|
+
*/
|
|
266
|
+
_compile(variables, strict) {
|
|
267
|
+
try {
|
|
268
|
+
const compiledPrompt = this.prompt ? liquid.parseAndRenderSync(this.prompt, variables, {
|
|
269
|
+
strictVariables: strict
|
|
270
|
+
}) : "";
|
|
271
|
+
const compiledMessages = (this.messages || []).map((message) => __spreadProps(__spreadValues({}, message), {
|
|
272
|
+
content: message.content ? liquid.parseAndRenderSync(message.content, variables, {
|
|
273
|
+
strictVariables: strict
|
|
274
|
+
}) : message.content
|
|
275
|
+
}));
|
|
276
|
+
const compiledData = __spreadProps(__spreadValues({}, this), {
|
|
277
|
+
prompt: compiledPrompt,
|
|
278
|
+
messages: compiledMessages
|
|
279
|
+
});
|
|
280
|
+
return new CompiledPrompt(compiledData, this);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
const templateStr = this.prompt || JSON.stringify(this.messages);
|
|
283
|
+
throw new PromptCompilationError(
|
|
284
|
+
`Failed to compile prompt template: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
285
|
+
templateStr,
|
|
286
|
+
error
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
compile(variables = {}) {
|
|
291
|
+
return this._compile(variables, false);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Compile with validation - throws error if required variables are missing
|
|
295
|
+
* @param variables - Template variables
|
|
296
|
+
* @returns CompiledPrompt instance with compiled content
|
|
297
|
+
*/
|
|
298
|
+
compileStrict(variables) {
|
|
299
|
+
return this._compile(variables, true);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var CompiledPrompt = class extends Prompt {
|
|
303
|
+
constructor(compiledData, original) {
|
|
304
|
+
super(compiledData);
|
|
305
|
+
this.original = original;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/client-sdk/services/prompts/service.ts
|
|
310
|
+
var PromptsError = class extends Error {
|
|
311
|
+
constructor(message, operation, originalError) {
|
|
312
|
+
super(message);
|
|
313
|
+
this.operation = operation;
|
|
314
|
+
this.originalError = originalError;
|
|
315
|
+
this.name = "PromptsError";
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var PromptsService = class {
|
|
319
|
+
constructor(config) {
|
|
320
|
+
this.config = config;
|
|
321
|
+
return createTracingProxy(
|
|
322
|
+
this,
|
|
323
|
+
tracer,
|
|
324
|
+
PromptServiceTracingDecorator
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Handles API errors by throwing a PromptsError with operation context.
|
|
329
|
+
* @param operation Description of the operation being performed.
|
|
330
|
+
* @param error The error object returned from the API client.
|
|
331
|
+
* @throws {PromptsError}
|
|
332
|
+
*/
|
|
333
|
+
handleApiError(operation, error) {
|
|
334
|
+
var _a, _b;
|
|
335
|
+
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";
|
|
336
|
+
throw new PromptsError(
|
|
337
|
+
`Failed to ${operation}: ${errorMessage}`,
|
|
338
|
+
operation,
|
|
339
|
+
error
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Fetches all prompts from the API.
|
|
344
|
+
* @returns Array of Prompt instances.
|
|
345
|
+
* @throws {PromptsError} If the API call fails.
|
|
346
|
+
*/
|
|
347
|
+
async getAll() {
|
|
348
|
+
const { data, error } = await this.config.langwatchApiClient.GET("/api/prompts");
|
|
349
|
+
if (error) this.handleApiError("fetch all prompts", error);
|
|
350
|
+
return data.map((promptData) => new Prompt(promptData));
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Fetches a single prompt by its ID.
|
|
354
|
+
* @param id The prompt's unique identifier.
|
|
355
|
+
* @returns The Prompt instance.
|
|
356
|
+
* @throws {PromptsError} If the API call fails.
|
|
357
|
+
*/
|
|
358
|
+
async get(id, options) {
|
|
359
|
+
const { data, error } = await this.config.langwatchApiClient.GET("/api/prompts/{id}", {
|
|
360
|
+
params: { path: { id } },
|
|
361
|
+
query: {
|
|
362
|
+
version: options == null ? void 0 : options.version
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
if (error) {
|
|
366
|
+
this.handleApiError(`fetch prompt with ID "${id}"`, error);
|
|
367
|
+
}
|
|
368
|
+
return new Prompt(data);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Validates if a prompt exists.
|
|
372
|
+
* @param id The prompt's unique identifier.
|
|
373
|
+
* @returns True if prompt exists, false otherwise.
|
|
374
|
+
* @throws {PromptsError} If the API call fails (not 404).
|
|
375
|
+
*/
|
|
376
|
+
async exists(id) {
|
|
377
|
+
var _a;
|
|
378
|
+
try {
|
|
379
|
+
await this.get(id);
|
|
380
|
+
return true;
|
|
381
|
+
} catch (error) {
|
|
382
|
+
if (error instanceof PromptsError && ((_a = error.originalError) == null ? void 0 : _a.statusCode) === 404) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Creates a new prompt.
|
|
390
|
+
* @param params The prompt creation payload, matching the OpenAPI schema.
|
|
391
|
+
* @returns The created Prompt instance.
|
|
392
|
+
* @throws {PromptsError} If the API call fails.
|
|
393
|
+
*/
|
|
394
|
+
async create(params) {
|
|
395
|
+
const { data, error } = await this.config.langwatchApiClient.POST("/api/prompts", {
|
|
396
|
+
body: params
|
|
397
|
+
});
|
|
398
|
+
if (error) this.handleApiError("create prompt", error);
|
|
399
|
+
return new Prompt(data);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Updates an existing prompt.
|
|
403
|
+
* @param id The prompt's unique identifier.
|
|
404
|
+
* @param params The update payload, matching the OpenAPI schema.
|
|
405
|
+
* @returns The updated Prompt instance.
|
|
406
|
+
* @throws {PromptsError} If the API call fails.
|
|
407
|
+
* @remarks
|
|
408
|
+
* The API does not return the updated prompt directly, so this method fetches it after updating.
|
|
409
|
+
*/
|
|
410
|
+
async update(id, params) {
|
|
411
|
+
const { error } = await this.config.langwatchApiClient.PUT("/api/prompts/{id}", {
|
|
412
|
+
params: { path: { id } },
|
|
413
|
+
body: params
|
|
414
|
+
});
|
|
415
|
+
if (error) this.handleApiError(`update prompt with ID "${id}"`, error);
|
|
416
|
+
const updatedPrompt = await this.get(id);
|
|
417
|
+
if (!updatedPrompt) {
|
|
418
|
+
throw new PromptsError(
|
|
419
|
+
"Prompt not found after update",
|
|
420
|
+
"update prompt",
|
|
421
|
+
null
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
return updatedPrompt;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Deletes a prompt by its ID.
|
|
428
|
+
* @param id The prompt's unique identifier.
|
|
429
|
+
* @throws {PromptsError} If the API call fails.
|
|
430
|
+
*/
|
|
431
|
+
async delete(id) {
|
|
432
|
+
const { data, error } = await this.config.langwatchApiClient.DELETE("/api/prompts/{id}", {
|
|
433
|
+
params: { path: { id } }
|
|
434
|
+
});
|
|
435
|
+
if (error) this.handleApiError(`delete prompt with ID "${id}"`, error);
|
|
436
|
+
return data;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Fetches all versions for a given prompt.
|
|
440
|
+
* @param id The prompt's unique identifier.
|
|
441
|
+
* @throws {PromptsError} If the API call fails.
|
|
442
|
+
*/
|
|
443
|
+
async getVersions(id) {
|
|
444
|
+
var _a;
|
|
445
|
+
const { data, error } = await this.config.langwatchApiClient.GET(
|
|
446
|
+
"/api/prompts/{id}/versions",
|
|
447
|
+
{
|
|
448
|
+
params: { path: { id } }
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
if (error)
|
|
452
|
+
this.handleApiError(`fetch versions for prompt with ID "${id}"`, error);
|
|
453
|
+
const prompts = {};
|
|
454
|
+
const dataTypeCorrected = data;
|
|
455
|
+
for (const version of dataTypeCorrected) {
|
|
456
|
+
prompts[version.id] = new Prompt({
|
|
457
|
+
id: version.configId,
|
|
458
|
+
handle: version.handle,
|
|
459
|
+
scope: version.scope,
|
|
460
|
+
messages: version.configData.messages,
|
|
461
|
+
model: version.configData.model,
|
|
462
|
+
prompt: version.configData.prompt,
|
|
463
|
+
response_format: null,
|
|
464
|
+
name: `Prompt ${version.configId}@${version.id}`,
|
|
465
|
+
updatedAt: version.createdAt,
|
|
466
|
+
version: (_a = version.configData.version) != null ? _a : 0,
|
|
467
|
+
versionCreatedAt: version.createdAt,
|
|
468
|
+
versionId: version.id
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
return prompts;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Creates a new version for a given prompt.
|
|
475
|
+
* @param id The prompt's unique identifier.
|
|
476
|
+
* @param params The version creation payload, matching the OpenAPI schema.
|
|
477
|
+
* @returns The updated Prompt instance.
|
|
478
|
+
* @throws {PromptsError} If the API call fails.
|
|
479
|
+
* @remarks
|
|
480
|
+
* The API does not return the updated prompt directly, so this method fetches it after creation.
|
|
481
|
+
*/
|
|
482
|
+
async createVersion(id, params) {
|
|
483
|
+
const { error } = await this.config.langwatchApiClient.POST("/api/prompts/{id}/versions", {
|
|
484
|
+
params: { path: { id } },
|
|
485
|
+
body: params
|
|
486
|
+
});
|
|
487
|
+
if (error)
|
|
488
|
+
this.handleApiError(`create version for prompt with ID "${id}"`, error);
|
|
489
|
+
const updatedPrompt = await this.get(id);
|
|
490
|
+
if (!updatedPrompt) {
|
|
491
|
+
throw new PromptsError(
|
|
492
|
+
"Prompt not found after version creation",
|
|
493
|
+
"create version",
|
|
494
|
+
null
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
return updatedPrompt;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.
|
|
501
|
+
* @param handle The prompt's handle/identifier.
|
|
502
|
+
* @param config Local prompt configuration.
|
|
503
|
+
* @returns Object with created flag and the prompt instance.
|
|
504
|
+
* @throws {PromptsError} If the API call fails.
|
|
505
|
+
*/
|
|
506
|
+
async upsert(handle, config) {
|
|
507
|
+
var _a, _b;
|
|
508
|
+
let prompt = await this.get(handle);
|
|
509
|
+
let created = false;
|
|
510
|
+
if (!prompt) {
|
|
511
|
+
prompt = await this.create({ handle });
|
|
512
|
+
created = true;
|
|
513
|
+
}
|
|
514
|
+
const versionData = {
|
|
515
|
+
configData: {
|
|
516
|
+
version: 1,
|
|
517
|
+
model: config.model,
|
|
518
|
+
prompt: PromptConverter.extractSystemPrompt(config.messages),
|
|
519
|
+
messages: PromptConverter.filterNonSystemMessages(config.messages),
|
|
520
|
+
temperature: (_a = config.modelParameters) == null ? void 0 : _a.temperature,
|
|
521
|
+
max_tokens: (_b = config.modelParameters) == null ? void 0 : _b.max_tokens,
|
|
522
|
+
inputs: [{ identifier: "input", type: "str" }],
|
|
523
|
+
outputs: [{ identifier: "output", type: "str" }]
|
|
524
|
+
},
|
|
525
|
+
commitMessage: `Updated via CLI sync`,
|
|
526
|
+
projectId: "placeholder",
|
|
527
|
+
// Will be overridden by the API
|
|
528
|
+
configId: prompt.id,
|
|
529
|
+
schemaVersion: "1.0",
|
|
530
|
+
version: 1
|
|
531
|
+
// Will be auto-incremented by the API
|
|
532
|
+
};
|
|
533
|
+
const updatedPrompt = await this.createVersion(prompt.id, versionData);
|
|
534
|
+
return {
|
|
535
|
+
created,
|
|
536
|
+
prompt: updatedPrompt
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Sync a prompt with local content, handling conflicts and version management
|
|
541
|
+
*/
|
|
542
|
+
async sync(params) {
|
|
543
|
+
var _a, _b;
|
|
544
|
+
try {
|
|
545
|
+
const response = await this.config.langwatchApiClient.POST("/api/prompts/{id}/sync", {
|
|
546
|
+
params: { path: { id: params.name } },
|
|
547
|
+
body: {
|
|
548
|
+
configData: params.configData,
|
|
549
|
+
localVersion: params.localVersion,
|
|
550
|
+
commitMessage: params.commitMessage
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
if (response.error) {
|
|
554
|
+
const errorMessage = (_b = (_a = response.error) == null ? void 0 : _a.error) != null ? _b : JSON.stringify(response.error);
|
|
555
|
+
throw new Error(`Failed to sync prompt: ${errorMessage}`);
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
action: response.data.action,
|
|
559
|
+
prompt: response.data.prompt,
|
|
560
|
+
conflictInfo: response.data.conflictInfo
|
|
561
|
+
};
|
|
562
|
+
} catch (error) {
|
|
563
|
+
const message = error instanceof Error ? error.message : "Unknown error occurred";
|
|
564
|
+
throw new PromptsError(message, "sync", error);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
// src/client-sdk/services/prompts/facade.ts
|
|
570
|
+
var PromptsFacade = class {
|
|
571
|
+
constructor(config) {
|
|
572
|
+
this.config = config;
|
|
573
|
+
this.service = new PromptsService(config);
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Creates a new prompt.
|
|
577
|
+
* @param data The prompt creation payload.
|
|
578
|
+
* @returns The created Prompt instance.
|
|
579
|
+
* @throws {PromptsError} If the API call fails.
|
|
580
|
+
*/
|
|
581
|
+
async create(data) {
|
|
582
|
+
return this.service.create(data);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Retrieves a prompt by handle or ID.
|
|
586
|
+
* @param handleOrId The prompt's handle or unique identifier.
|
|
587
|
+
* @param options Optional parameters for the request.
|
|
588
|
+
* @returns The Prompt instance or null if not found.
|
|
589
|
+
* @throws {PromptsError} If the API call fails.
|
|
590
|
+
*/
|
|
591
|
+
async get(handleOrId, options) {
|
|
592
|
+
return this.service.get(handleOrId, options);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Retrieves all prompts.
|
|
596
|
+
* @returns Array of Prompt instances.
|
|
597
|
+
* @throws {PromptsError} If the API call fails.
|
|
598
|
+
*/
|
|
599
|
+
async getAll() {
|
|
600
|
+
return this.service.getAll();
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Updates an existing prompt.
|
|
604
|
+
* @param handleOrId The prompt's handle or unique identifier.
|
|
605
|
+
* @param newData The update payload.
|
|
606
|
+
* @returns The updated Prompt instance.
|
|
607
|
+
* @throws {PromptsError} If the API call fails.
|
|
608
|
+
*/
|
|
609
|
+
async update(handleOrId, newData) {
|
|
610
|
+
return this.service.update(handleOrId, newData);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Deletes a prompt by handle or ID.
|
|
614
|
+
* @param handleOrId The prompt's handle or unique identifier.
|
|
615
|
+
* @throws {PromptsError} If the API call fails.
|
|
616
|
+
*/
|
|
617
|
+
async delete(handleOrId) {
|
|
618
|
+
return this.service.delete(handleOrId);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Syncs a prompt with the server.
|
|
622
|
+
* @param params The sync parameters.
|
|
623
|
+
* @returns The sync result.
|
|
624
|
+
* @throws {PromptsError} If the API call fails.
|
|
625
|
+
*/
|
|
626
|
+
async sync(params) {
|
|
627
|
+
return this.service.sync(params);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
export {
|
|
632
|
+
createTracingProxy,
|
|
633
|
+
PromptsError,
|
|
634
|
+
PromptsFacade
|
|
635
|
+
};
|
|
636
|
+
//# sourceMappingURL=chunk-IZ2U3ABC.mjs.map
|