langwatch 0.4.2 → 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-SV662KZU.js → add-CGTO6GC2.js} +65 -40
- package/dist/add-CGTO6GC2.js.map +1 -0
- package/dist/{add-SMYALCQG.mjs → add-XCI65PVN.mjs} +53 -28
- package/dist/add-XCI65PVN.mjs.map +1 -0
- package/dist/{chunk-NVKMXXNP.js → chunk-2GYC6KEA.js} +32 -32
- package/dist/{chunk-NVKMXXNP.js.map → chunk-2GYC6KEA.js.map} +1 -1
- package/dist/{chunk-P5F63PAW.js → chunk-36XAYVMC.js} +186 -76
- package/dist/chunk-36XAYVMC.js.map +1 -0
- package/dist/{chunk-ENSRDEDA.mjs → chunk-3P4ROGZJ.mjs} +4 -4
- package/dist/{chunk-K4ICRI7W.mjs → chunk-AD7QRYIJ.mjs} +2 -2
- package/dist/{chunk-I5NDMIK5.js → chunk-AZHZ4NB4.js} +1 -1
- package/dist/{chunk-I5NDMIK5.js.map → chunk-AZHZ4NB4.js.map} +1 -1
- package/dist/{chunk-YQVVPMKH.mjs → chunk-BTBSMJTY.mjs} +1 -1
- package/dist/chunk-BTBSMJTY.mjs.map +1 -0
- package/dist/{chunk-DISMHYXC.js → chunk-CKIZDPIJ.js} +24 -22
- package/dist/chunk-CKIZDPIJ.js.map +1 -0
- package/dist/{chunk-ZZLIF3DE.js → chunk-DZH6SY3Z.js} +10 -10
- package/dist/{chunk-ZZLIF3DE.js.map → chunk-DZH6SY3Z.js.map} +1 -1
- package/dist/{chunk-N2V6J3U2.mjs → chunk-FEL5FLHA.mjs} +2 -2
- package/dist/{chunk-5ZKAT4KI.mjs → chunk-GAFUPYJ3.mjs} +336 -162
- package/dist/chunk-GAFUPYJ3.mjs.map +1 -0
- package/dist/{chunk-NFM6RB4R.js → chunk-HVW45GST.js} +347 -173
- 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-ILTCLEIF.js → chunk-J7B7BNDN.js} +17 -17
- package/dist/chunk-J7B7BNDN.js.map +1 -0
- package/dist/{chunk-VILW5FYO.mjs → chunk-JPWKINZP.mjs} +8 -8
- package/dist/{chunk-VILW5FYO.mjs.map → chunk-JPWKINZP.mjs.map} +1 -1
- 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-CAVBDSBT.mjs → chunk-WOBPYIKO.mjs} +2 -2
- package/dist/chunk-WOBPYIKO.mjs.map +1 -0
- package/dist/{chunk-VI5NJ53L.js → chunk-Z3NTWVVA.js} +2 -2
- package/dist/chunk-Z3NTWVVA.js.map +1 -0
- package/dist/cli/index.js +10 -10
- package/dist/cli/index.mjs +9 -9
- package/dist/{create-BHWZP6YD.mjs → create-LXQB4EFB.mjs} +22 -12
- package/dist/create-LXQB4EFB.mjs.map +1 -0
- package/dist/{create-GUY3HZM2.js → create-S5RDGF3H.js} +27 -17
- package/dist/create-S5RDGF3H.js.map +1 -0
- package/dist/{implementation--7B7PUww.d.ts → implementation-DsHp9FYU.d.ts} +1 -1
- package/dist/{implementation-D7LzdQop.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-T4YDPHBA.mjs +15 -0
- package/dist/{init-RDW2F4G3.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-GZGLSJ52.js → list-GRKVAGJS.js} +14 -15
- package/dist/list-GRKVAGJS.js.map +1 -0
- package/dist/{list-32BRZ6RS.mjs → list-XHXVFN24.mjs} +13 -14
- package/dist/list-XHXVFN24.mjs.map +1 -0
- package/dist/{login-IAP4RFUM.js → login-4GWM5I6F.js} +4 -4
- package/dist/{login-IAP4RFUM.js.map → login-4GWM5I6F.js.map} +1 -1
- package/dist/{login-VXLW2OXR.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 +2 -2
- package/dist/observability-sdk/setup/node/index.d.ts +2 -2
- package/dist/observability-sdk/setup/node/index.js +15 -15
- package/dist/observability-sdk/setup/node/index.mjs +4 -4
- package/dist/{remove-N3324KHS.js → remove-7EXB2Z6R.js} +18 -19
- package/dist/remove-7EXB2Z6R.js.map +1 -0
- package/dist/{remove-JUVM6M7G.mjs → remove-W44FQ5MF.mjs} +10 -11
- package/dist/{remove-JUVM6M7G.mjs.map → remove-W44FQ5MF.mjs.map} +1 -1
- package/dist/{sync-E32H3H52.js → sync-V7WRMNJV.js} +41 -40
- package/dist/sync-V7WRMNJV.js.map +1 -0
- package/dist/{sync-B4YK6QYX.mjs → sync-XGFABFAW.mjs} +28 -27
- package/dist/sync-XGFABFAW.mjs.map +1 -0
- package/dist/{types-D6Cs1385.d.ts → types-B9772cUR.d.ts} +146 -27
- package/dist/{types-D61S7yPU.d.mts → types-DbPAi4US.d.mts} +146 -27
- package/package.json +9 -7
- package/dist/add-SMYALCQG.mjs.map +0 -1
- package/dist/add-SV662KZU.js.map +0 -1
- package/dist/chunk-5ZKAT4KI.mjs.map +0 -1
- package/dist/chunk-7ZRAJ52N.mjs +0 -242
- package/dist/chunk-7ZRAJ52N.mjs.map +0 -1
- package/dist/chunk-CAVBDSBT.mjs.map +0 -1
- package/dist/chunk-DISMHYXC.js.map +0 -1
- package/dist/chunk-ILTCLEIF.js.map +0 -1
- package/dist/chunk-LXVDGQA4.mjs +0 -101
- package/dist/chunk-LXVDGQA4.mjs.map +0 -1
- package/dist/chunk-NFM6RB4R.js.map +0 -1
- package/dist/chunk-OXBO24RB.js.map +0 -1
- package/dist/chunk-P5F63PAW.js.map +0 -1
- package/dist/chunk-PUHM465C.js +0 -101
- package/dist/chunk-PUHM465C.js.map +0 -1
- package/dist/chunk-RBZNMZTF.mjs +0 -155
- package/dist/chunk-RBZNMZTF.mjs.map +0 -1
- package/dist/chunk-T7FQHOLK.js +0 -155
- package/dist/chunk-T7FQHOLK.js.map +0 -1
- package/dist/chunk-VI5NJ53L.js.map +0 -1
- package/dist/chunk-YNQ44U6D.mjs.map +0 -1
- package/dist/chunk-YQVVPMKH.mjs.map +0 -1
- package/dist/create-BHWZP6YD.mjs.map +0 -1
- package/dist/create-GUY3HZM2.js.map +0 -1
- package/dist/init-OO2BUJ6V.js +0 -16
- package/dist/init-OO2BUJ6V.js.map +0 -1
- package/dist/init-RDW2F4G3.mjs +0 -16
- package/dist/list-32BRZ6RS.mjs.map +0 -1
- package/dist/list-GZGLSJ52.js.map +0 -1
- package/dist/remove-N3324KHS.js.map +0 -1
- package/dist/sync-B4YK6QYX.mjs.map +0 -1
- package/dist/sync-E32H3H52.js.map +0 -1
- /package/dist/{chunk-ENSRDEDA.mjs.map → chunk-3P4ROGZJ.mjs.map} +0 -0
- /package/dist/{chunk-K4ICRI7W.mjs.map → chunk-AD7QRYIJ.mjs.map} +0 -0
- /package/dist/{chunk-N2V6J3U2.mjs.map → chunk-FEL5FLHA.mjs.map} +0 -0
- /package/dist/{chunk-CU3443HD.mjs.map → chunk-URTD2WOC.mjs.map} +0 -0
- /package/dist/{login-VXLW2OXR.mjs.map → login-EKE7SFN3.mjs.map} +0 -0
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getLangWatchTracer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JPWKINZP.mjs";
|
|
4
4
|
import {
|
|
5
|
+
DEFAULT_ENDPOINT,
|
|
6
|
+
LANGWATCH_SDK_LANGUAGE,
|
|
5
7
|
LANGWATCH_SDK_NAME_CLIENT,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
LANGWATCH_SDK_NAME_OBSERVABILITY,
|
|
9
|
+
LANGWATCH_SDK_RUNTIME,
|
|
10
|
+
LANGWATCH_SDK_VERSION,
|
|
11
|
+
version
|
|
12
|
+
} from "./chunk-WOBPYIKO.mjs";
|
|
8
13
|
import {
|
|
14
|
+
NoOpLogger,
|
|
9
15
|
shouldCaptureInput,
|
|
10
16
|
shouldCaptureOutput
|
|
11
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-I2SOBPAF.mjs";
|
|
12
18
|
import {
|
|
19
|
+
FileManager,
|
|
13
20
|
PromptConverter
|
|
14
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-PYVDTUA6.mjs";
|
|
15
22
|
import {
|
|
23
|
+
__objRest,
|
|
16
24
|
__spreadProps,
|
|
17
25
|
__spreadValues
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
|
|
20
|
-
// src/client-sdk/services/prompts/prompt.ts
|
|
21
|
-
import { Liquid } from "liquidjs";
|
|
26
|
+
} from "./chunk-URTD2WOC.mjs";
|
|
22
27
|
|
|
23
28
|
// src/client-sdk/services/prompts/tracing/prompt-tracing.decorator.ts
|
|
24
29
|
var PromptTracingDecorator = class {
|
|
@@ -29,7 +34,7 @@ var PromptTracingDecorator = class {
|
|
|
29
34
|
var _a;
|
|
30
35
|
span.setType("prompt");
|
|
31
36
|
if (shouldCaptureInput()) {
|
|
32
|
-
span.setInput(this.target
|
|
37
|
+
span.setInput(this.target);
|
|
33
38
|
if (variables) {
|
|
34
39
|
span.setAttribute(
|
|
35
40
|
"langwatch.prompt.variables",
|
|
@@ -90,7 +95,7 @@ var PromptServiceTracingDecorator = class {
|
|
|
90
95
|
});
|
|
91
96
|
}
|
|
92
97
|
if (result && shouldCaptureOutput()) {
|
|
93
|
-
span.setOutput("json", result
|
|
98
|
+
span.setOutput("json", result);
|
|
94
99
|
}
|
|
95
100
|
return result;
|
|
96
101
|
}
|
|
@@ -101,11 +106,13 @@ var PromptServiceTracingDecorator = class {
|
|
|
101
106
|
span.setInput(params);
|
|
102
107
|
}
|
|
103
108
|
const result = await this.target.create(params);
|
|
104
|
-
span.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
span.setAttributes({
|
|
110
|
+
"langwatch.prompt.id": result.id,
|
|
111
|
+
"langwatch.prompt.handle": (_a = result.handle) != null ? _a : void 0,
|
|
112
|
+
"langwatch.prompt.scope": result.scope,
|
|
113
|
+
"langwatch.prompt.version.id": result.versionId,
|
|
114
|
+
"langwatch.prompt.version.number": result.version
|
|
115
|
+
});
|
|
109
116
|
return result;
|
|
110
117
|
}
|
|
111
118
|
async update(span, id, params) {
|
|
@@ -115,11 +122,13 @@ var PromptServiceTracingDecorator = class {
|
|
|
115
122
|
}
|
|
116
123
|
const result = await this.target.update(id, params);
|
|
117
124
|
span.setType("prompt");
|
|
118
|
-
span.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
span.setAttributes({
|
|
126
|
+
"langwatch.prompt.id": id,
|
|
127
|
+
"langwatch.prompt.handle": (_a = result.handle) != null ? _a : void 0,
|
|
128
|
+
"langwatch.prompt.scope": result.scope,
|
|
129
|
+
"langwatch.prompt.version.id": result.versionId,
|
|
130
|
+
"langwatch.prompt.version.number": result.version
|
|
131
|
+
});
|
|
123
132
|
return result;
|
|
124
133
|
}
|
|
125
134
|
async delete(span, id) {
|
|
@@ -135,11 +144,13 @@ var PromptServiceTracingDecorator = class {
|
|
|
135
144
|
}
|
|
136
145
|
const result = await this.target.upsert(handle, config);
|
|
137
146
|
span.setType("prompt");
|
|
138
|
-
span.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
span.setAttributes({
|
|
148
|
+
"langwatch.prompt.handle": handle,
|
|
149
|
+
"langwatch.prompt.created": result.created.toString(),
|
|
150
|
+
"langwatch.prompt.id": result.prompt.id,
|
|
151
|
+
"langwatch.prompt.version.id": result.prompt.versionId,
|
|
152
|
+
"langwatch.prompt.version.number": result.prompt.version
|
|
153
|
+
});
|
|
143
154
|
return result;
|
|
144
155
|
}
|
|
145
156
|
async sync(span, params) {
|
|
@@ -151,9 +162,11 @@ var PromptServiceTracingDecorator = class {
|
|
|
151
162
|
span.setAttribute("langwatch.prompt.name", params.name);
|
|
152
163
|
span.setAttribute("langwatch.prompt.sync.action", result.action);
|
|
153
164
|
if (result.conflictInfo) {
|
|
154
|
-
span.
|
|
155
|
-
|
|
156
|
-
|
|
165
|
+
span.setAttributes({
|
|
166
|
+
"langwatch.prompt.sync.has_conflict": "true",
|
|
167
|
+
"langwatch.prompt.sync.local_version": result.conflictInfo.localVersion.toString(),
|
|
168
|
+
"langwatch.prompt.sync.remote_version": result.conflictInfo.remoteVersion.toString()
|
|
169
|
+
});
|
|
157
170
|
}
|
|
158
171
|
return result;
|
|
159
172
|
}
|
|
@@ -226,79 +239,23 @@ var isBuiltInMethod = (prop) => {
|
|
|
226
239
|
return builtInMethods.includes(prop);
|
|
227
240
|
};
|
|
228
241
|
|
|
229
|
-
// src/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this.promptData = promptData;
|
|
244
|
-
Object.assign(this, promptData);
|
|
245
|
-
return createTracingProxy(this, tracer, PromptTracingDecorator);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Get the raw prompt data from the API
|
|
249
|
-
*/
|
|
250
|
-
get raw() {
|
|
251
|
-
return this.promptData;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Compile the prompt template with provided variables (lenient - missing variables become empty)
|
|
255
|
-
* @param variables - Object containing variable values for template compilation
|
|
256
|
-
* @returns CompiledPrompt instance with compiled content
|
|
257
|
-
*/
|
|
258
|
-
_compile(variables, strict) {
|
|
259
|
-
try {
|
|
260
|
-
const compiledPrompt = this.prompt ? liquid.parseAndRenderSync(this.prompt, variables, {
|
|
261
|
-
strictVariables: strict
|
|
262
|
-
}) : "";
|
|
263
|
-
const compiledMessages = (this.messages || []).map((message) => __spreadProps(__spreadValues({}, message), {
|
|
264
|
-
content: message.content ? liquid.parseAndRenderSync(message.content, variables, {
|
|
265
|
-
strictVariables: strict
|
|
266
|
-
}) : message.content
|
|
267
|
-
}));
|
|
268
|
-
const compiledData = __spreadProps(__spreadValues({}, this), {
|
|
269
|
-
prompt: compiledPrompt,
|
|
270
|
-
messages: compiledMessages
|
|
271
|
-
});
|
|
272
|
-
return new CompiledPrompt(compiledData, this);
|
|
273
|
-
} catch (error) {
|
|
274
|
-
const templateStr = this.prompt || JSON.stringify(this.messages);
|
|
275
|
-
throw new PromptCompilationError(
|
|
276
|
-
`Failed to compile prompt template: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
277
|
-
templateStr,
|
|
278
|
-
error
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
compile(variables = {}) {
|
|
283
|
-
return this._compile(variables, false);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Compile with validation - throws error if required variables are missing
|
|
287
|
-
* @param variables - Template variables
|
|
288
|
-
* @returns CompiledPrompt instance with compiled content
|
|
289
|
-
*/
|
|
290
|
-
compileStrict(variables) {
|
|
291
|
-
return this._compile(variables, true);
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
var CompiledPrompt = class extends Prompt {
|
|
295
|
-
constructor(compiledData, original) {
|
|
296
|
-
super(compiledData);
|
|
297
|
-
this.original = original;
|
|
298
|
-
}
|
|
242
|
+
// src/internal/api/client.ts
|
|
243
|
+
import openApiCreateClient from "openapi-fetch";
|
|
244
|
+
var createLangWatchApiClient = (apiKey = ((_a) => (_a = process.env.LANGWATCH_API_KEY) != null ? _a : "")(), endpoint = ((_b) => (_b = process.env.LANGWATCH_ENDPOINT) != null ? _b : DEFAULT_ENDPOINT)()) => {
|
|
245
|
+
return openApiCreateClient({
|
|
246
|
+
baseUrl: endpoint,
|
|
247
|
+
headers: __spreadProps(__spreadValues({}, apiKey ? { authorization: `Bearer ${apiKey}`, "x-auth-token": apiKey } : {}), {
|
|
248
|
+
"content-type": "application/json",
|
|
249
|
+
"user-agent": `langwatch-sdk-node/${version}`,
|
|
250
|
+
"x-langwatch-sdk-name": LANGWATCH_SDK_NAME_OBSERVABILITY,
|
|
251
|
+
"x-langwatch-sdk-language": LANGWATCH_SDK_LANGUAGE,
|
|
252
|
+
"x-langwatch-sdk-version": LANGWATCH_SDK_VERSION,
|
|
253
|
+
"x-langwatch-sdk-platform": LANGWATCH_SDK_RUNTIME()
|
|
254
|
+
})
|
|
255
|
+
});
|
|
299
256
|
};
|
|
300
257
|
|
|
301
|
-
// src/client-sdk/services/prompts/service.ts
|
|
258
|
+
// src/client-sdk/services/prompts/prompts-api.service.ts
|
|
302
259
|
var PromptsError = class extends Error {
|
|
303
260
|
constructor(message, operation, originalError) {
|
|
304
261
|
super(message);
|
|
@@ -307,9 +264,31 @@ var PromptsError = class extends Error {
|
|
|
307
264
|
this.name = "PromptsError";
|
|
308
265
|
}
|
|
309
266
|
};
|
|
310
|
-
var
|
|
267
|
+
var PromptsApiService = class {
|
|
311
268
|
constructor(config) {
|
|
312
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Fetches a single prompt by its ID.
|
|
271
|
+
* @param id The prompt's unique identifier.
|
|
272
|
+
* @returns Raw PromptResponse data.
|
|
273
|
+
* @throws {PromptsError} If the API call fails.
|
|
274
|
+
*/
|
|
275
|
+
this.get = async (id, options) => {
|
|
276
|
+
const { data, error } = await this.apiClient.GET(
|
|
277
|
+
"/api/prompts/{id}",
|
|
278
|
+
{
|
|
279
|
+
params: { path: { id } },
|
|
280
|
+
query: {
|
|
281
|
+
version: options == null ? void 0 : options.version
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
if (error) {
|
|
286
|
+
this.handleApiError(`fetch prompt with ID "${id}"`, error);
|
|
287
|
+
}
|
|
288
|
+
return data;
|
|
289
|
+
};
|
|
290
|
+
var _a;
|
|
291
|
+
this.apiClient = (_a = config == null ? void 0 : config.langwatchApiClient) != null ? _a : createLangWatchApiClient();
|
|
313
292
|
return createTracingProxy(
|
|
314
293
|
this,
|
|
315
294
|
tracer,
|
|
@@ -333,34 +312,13 @@ var PromptsService = class {
|
|
|
333
312
|
}
|
|
334
313
|
/**
|
|
335
314
|
* Fetches all prompts from the API.
|
|
336
|
-
* @returns Array of
|
|
315
|
+
* @returns Array of raw PromptResponse data.
|
|
337
316
|
* @throws {PromptsError} If the API call fails.
|
|
338
317
|
*/
|
|
339
318
|
async getAll() {
|
|
340
|
-
const { data, error } = await this.
|
|
319
|
+
const { data, error } = await this.apiClient.GET("/api/prompts");
|
|
341
320
|
if (error) this.handleApiError("fetch all prompts", error);
|
|
342
|
-
return data
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Fetches a single prompt by its ID.
|
|
346
|
-
* @param id The prompt's unique identifier.
|
|
347
|
-
* @returns The Prompt instance.
|
|
348
|
-
* @throws {PromptsError} If the API call fails.
|
|
349
|
-
*/
|
|
350
|
-
async get(id, options) {
|
|
351
|
-
const { data, error } = await this.config.langwatchApiClient.GET(
|
|
352
|
-
"/api/prompts/{id}",
|
|
353
|
-
{
|
|
354
|
-
params: { path: { id } },
|
|
355
|
-
query: {
|
|
356
|
-
version: options == null ? void 0 : options.version
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
);
|
|
360
|
-
if (error) {
|
|
361
|
-
this.handleApiError(`fetch prompt with ID "${id}"`, error);
|
|
362
|
-
}
|
|
363
|
-
return new Prompt(data);
|
|
321
|
+
return data;
|
|
364
322
|
}
|
|
365
323
|
/**
|
|
366
324
|
* Validates if a prompt exists.
|
|
@@ -383,45 +341,32 @@ var PromptsService = class {
|
|
|
383
341
|
/**
|
|
384
342
|
* Creates a new prompt.
|
|
385
343
|
* @param params The prompt creation payload, matching the OpenAPI schema.
|
|
386
|
-
* @returns
|
|
344
|
+
* @returns Raw PromptResponse data of the created prompt.
|
|
387
345
|
* @throws {PromptsError} If the API call fails.
|
|
388
346
|
*/
|
|
389
347
|
async create(params) {
|
|
390
|
-
const { data, error } = await this.
|
|
348
|
+
const { data, error } = await this.apiClient.POST(
|
|
391
349
|
"/api/prompts",
|
|
392
350
|
{
|
|
393
351
|
body: params
|
|
394
352
|
}
|
|
395
353
|
);
|
|
396
354
|
if (error) this.handleApiError("create prompt", error);
|
|
397
|
-
return
|
|
355
|
+
return data;
|
|
398
356
|
}
|
|
399
357
|
/**
|
|
400
358
|
* Updates an existing prompt.
|
|
401
359
|
* @param id The prompt's unique identifier.
|
|
402
360
|
* @param params The update payload, matching the OpenAPI schema.
|
|
403
|
-
* @returns
|
|
361
|
+
* @returns Raw PromptResponse data of the updated prompt.
|
|
404
362
|
* @throws {PromptsError} If the API call fails.
|
|
405
|
-
* @remarks
|
|
406
|
-
* The API does not return the updated prompt directly, so this method fetches it after updating.
|
|
407
363
|
*/
|
|
408
364
|
async update(id, params) {
|
|
409
|
-
const { error } = await this.
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
body: params
|
|
414
|
-
}
|
|
415
|
-
);
|
|
365
|
+
const { error, data: updatedPrompt } = await this.apiClient.PUT("/api/prompts/{id}", {
|
|
366
|
+
params: { path: { id } },
|
|
367
|
+
body: params
|
|
368
|
+
});
|
|
416
369
|
if (error) this.handleApiError(`update prompt with ID "${id}"`, error);
|
|
417
|
-
const updatedPrompt = await this.get(id);
|
|
418
|
-
if (!updatedPrompt) {
|
|
419
|
-
throw new PromptsError(
|
|
420
|
-
"Prompt not found after update",
|
|
421
|
-
"update prompt",
|
|
422
|
-
null
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
370
|
return updatedPrompt;
|
|
426
371
|
}
|
|
427
372
|
/**
|
|
@@ -430,7 +375,7 @@ var PromptsService = class {
|
|
|
430
375
|
* @throws {PromptsError} If the API call fails.
|
|
431
376
|
*/
|
|
432
377
|
async delete(id) {
|
|
433
|
-
const { data, error } = await this.
|
|
378
|
+
const { data, error } = await this.apiClient.DELETE(
|
|
434
379
|
"/api/prompts/{id}",
|
|
435
380
|
{
|
|
436
381
|
params: { path: { id } }
|
|
@@ -442,10 +387,11 @@ var PromptsService = class {
|
|
|
442
387
|
/**
|
|
443
388
|
* Fetches all versions for a given prompt.
|
|
444
389
|
* @param id The prompt's unique identifier.
|
|
390
|
+
* @returns Array of raw PromptResponse data for each version.
|
|
445
391
|
* @throws {PromptsError} If the API call fails.
|
|
446
392
|
*/
|
|
447
393
|
async getVersions(id) {
|
|
448
|
-
const { data, error } = await this.
|
|
394
|
+
const { data, error } = await this.apiClient.GET(
|
|
449
395
|
"/api/prompts/{id}/versions",
|
|
450
396
|
{
|
|
451
397
|
params: { path: { id } }
|
|
@@ -453,13 +399,13 @@ var PromptsService = class {
|
|
|
453
399
|
);
|
|
454
400
|
if (error)
|
|
455
401
|
this.handleApiError(`fetch versions for prompt with ID "${id}"`, error);
|
|
456
|
-
return data
|
|
402
|
+
return data;
|
|
457
403
|
}
|
|
458
404
|
/**
|
|
459
405
|
* Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.
|
|
460
406
|
* @param handle The prompt's handle/identifier.
|
|
461
407
|
* @param config Local prompt configuration.
|
|
462
|
-
* @returns Object with created flag and
|
|
408
|
+
* @returns Object with created flag and raw PromptResponse data.
|
|
463
409
|
* @throws {PromptsError} If the API call fails.
|
|
464
410
|
*/
|
|
465
411
|
async upsert(handle, config) {
|
|
@@ -496,7 +442,7 @@ var PromptsService = class {
|
|
|
496
442
|
async sync(params) {
|
|
497
443
|
var _a, _b;
|
|
498
444
|
try {
|
|
499
|
-
const response = await this.
|
|
445
|
+
const response = await this.apiClient.POST(
|
|
500
446
|
"/api/prompts/{id}/sync",
|
|
501
447
|
{
|
|
502
448
|
params: { path: { id: params.name } },
|
|
@@ -523,11 +469,227 @@ var PromptsService = class {
|
|
|
523
469
|
}
|
|
524
470
|
};
|
|
525
471
|
|
|
526
|
-
// src/client-sdk/services/prompts/
|
|
472
|
+
// src/client-sdk/services/prompts/prompt.ts
|
|
473
|
+
import { Liquid } from "liquidjs";
|
|
474
|
+
|
|
475
|
+
// src/client-sdk/services/prompts/schema/prompt.schema.ts
|
|
476
|
+
import { z } from "zod";
|
|
477
|
+
|
|
478
|
+
// src/client-sdk/services/prompts/constants.ts
|
|
479
|
+
var PromptScope = {
|
|
480
|
+
ORGANIZATION: "ORGANIZATION",
|
|
481
|
+
PROJECT: "PROJECT"
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
// src/client-sdk/services/prompts/schema/prompt.schema.ts
|
|
485
|
+
var messageSchema = z.object({
|
|
486
|
+
role: z.enum(["user", "assistant", "system"]),
|
|
487
|
+
content: z.string()
|
|
488
|
+
});
|
|
489
|
+
var responseFormatSchema = z.object({
|
|
490
|
+
type: z.literal("json_schema"),
|
|
491
|
+
json_schema: z.object({
|
|
492
|
+
name: z.string(),
|
|
493
|
+
schema: z.record(z.string(), z.unknown())
|
|
494
|
+
}).nullable()
|
|
495
|
+
}).optional();
|
|
496
|
+
var corePromptDataSchema = z.object({
|
|
497
|
+
model: z.string().min(1, "Model cannot be empty"),
|
|
498
|
+
messages: z.array(messageSchema).min(1, "At least one message is required"),
|
|
499
|
+
prompt: z.string().optional(),
|
|
500
|
+
temperature: z.number().min(0).max(2).optional(),
|
|
501
|
+
maxTokens: z.number().positive().optional(),
|
|
502
|
+
responseFormat: responseFormatSchema
|
|
503
|
+
});
|
|
504
|
+
var promptMetadataSchema = z.object({
|
|
505
|
+
id: z.string().optional(),
|
|
506
|
+
handle: z.string().nullable().optional(),
|
|
507
|
+
version: z.number().min(0).optional(),
|
|
508
|
+
versionId: z.string().optional(),
|
|
509
|
+
scope: z.enum(PromptScope).optional()
|
|
510
|
+
});
|
|
511
|
+
var promptDataSchema = z.object(__spreadValues(__spreadValues({}, corePromptDataSchema.shape), promptMetadataSchema.shape));
|
|
512
|
+
|
|
513
|
+
// src/client-sdk/services/prompts/errors/prompt-compilation.error.ts
|
|
514
|
+
var PromptCompilationError = class extends Error {
|
|
515
|
+
constructor(message, template, originalError) {
|
|
516
|
+
super(message);
|
|
517
|
+
this.template = template;
|
|
518
|
+
this.originalError = originalError;
|
|
519
|
+
this.name = "PromptCompilationError";
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// src/client-sdk/services/prompts/errors/prompt-validation.error.ts
|
|
524
|
+
var PromptValidationError = class extends Error {
|
|
525
|
+
constructor(message, validationErrors) {
|
|
526
|
+
super(message);
|
|
527
|
+
this.validationErrors = validationErrors;
|
|
528
|
+
this.name = "PromptValidationError";
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
// src/client-sdk/services/prompts/prompt.ts
|
|
533
|
+
var liquid = new Liquid({
|
|
534
|
+
strictFilters: true
|
|
535
|
+
});
|
|
536
|
+
var Prompt = class {
|
|
537
|
+
constructor(data) {
|
|
538
|
+
var _a;
|
|
539
|
+
const validationResult = promptDataSchema.strip().safeParse(data);
|
|
540
|
+
if (!validationResult.success) {
|
|
541
|
+
throw new PromptValidationError(
|
|
542
|
+
"Invalid prompt data provided",
|
|
543
|
+
validationResult.error
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
Object.assign(this, validationResult.data);
|
|
547
|
+
(_a = this.prompt) != null ? _a : this.prompt = this.extractSystemPrompt();
|
|
548
|
+
return createTracingProxy(this, tracer, PromptTracingDecorator);
|
|
549
|
+
}
|
|
550
|
+
extractSystemPrompt() {
|
|
551
|
+
var _a, _b;
|
|
552
|
+
return (_b = (_a = this.messages.find((m) => m.role === "system")) == null ? void 0 : _a.content) != null ? _b : "";
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Compile the prompt template with provided variables (lenient - missing variables become empty)
|
|
556
|
+
* @param variables - Object containing variable values for template compilation
|
|
557
|
+
* @returns CompiledPrompt instance with compiled content
|
|
558
|
+
*/
|
|
559
|
+
_compile(variables, strict) {
|
|
560
|
+
var _a;
|
|
561
|
+
try {
|
|
562
|
+
const compiledPrompt = this.prompt ? liquid.parseAndRenderSync(this.prompt, variables, {
|
|
563
|
+
strictVariables: strict
|
|
564
|
+
}) : "";
|
|
565
|
+
const compiledMessages = (this.messages || []).map((message) => __spreadProps(__spreadValues({}, message), {
|
|
566
|
+
content: message.content ? liquid.parseAndRenderSync(message.content, variables, {
|
|
567
|
+
strictVariables: strict
|
|
568
|
+
}) : message.content
|
|
569
|
+
}));
|
|
570
|
+
const compiledData = __spreadProps(__spreadValues({}, this), {
|
|
571
|
+
prompt: compiledPrompt,
|
|
572
|
+
messages: compiledMessages
|
|
573
|
+
});
|
|
574
|
+
return new CompiledPrompt(compiledData, this);
|
|
575
|
+
} catch (error) {
|
|
576
|
+
const templateStr = (_a = this.prompt) != null ? _a : JSON.stringify(this.messages);
|
|
577
|
+
throw new PromptCompilationError(
|
|
578
|
+
`Failed to compile prompt template: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
579
|
+
templateStr,
|
|
580
|
+
error
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
compile(variables = {}) {
|
|
585
|
+
return this._compile(variables, false);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Compile with validation - throws error if required variables are missing
|
|
589
|
+
* @param variables - Template variables
|
|
590
|
+
* @returns CompiledPrompt instance with compiled content
|
|
591
|
+
*/
|
|
592
|
+
compileStrict(variables) {
|
|
593
|
+
return this._compile(variables, true);
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
var CompiledPrompt = class extends Prompt {
|
|
597
|
+
constructor(compiledData, original) {
|
|
598
|
+
super(compiledData);
|
|
599
|
+
this.original = original;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// src/client-sdk/services/prompts/local-prompts.service.ts
|
|
604
|
+
var LocalPromptsService = class {
|
|
605
|
+
constructor(config) {
|
|
606
|
+
var _a, _b;
|
|
607
|
+
this.fileManager = (_a = config == null ? void 0 : config.fileManager) != null ? _a : FileManager;
|
|
608
|
+
this.logger = (_b = config == null ? void 0 : config.logger) != null ? _b : new NoOpLogger();
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Retrieves a prompt using the configured search strategy.
|
|
612
|
+
* Tries each source in priority order until found or all sources exhausted.
|
|
613
|
+
*/
|
|
614
|
+
async get(handleOrId) {
|
|
615
|
+
var _a, _b;
|
|
616
|
+
try {
|
|
617
|
+
const dependency = await this.getDependencyFromConfig(handleOrId);
|
|
618
|
+
if (!dependency) {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
const localPromptConfig = (_b = (_a = await this.getFromConfig(dependency)) != null ? _a : await this.getFromLockFile(handleOrId)) != null ? _b : await this.getFromLocalFiles(handleOrId);
|
|
622
|
+
return localPromptConfig ? this.convertToPromptData(__spreadProps(__spreadValues({}, localPromptConfig), {
|
|
623
|
+
handle: handleOrId
|
|
624
|
+
})) : null;
|
|
625
|
+
} catch (error) {
|
|
626
|
+
this.logger.warn(`Failed to get prompt "${handleOrId}": ${error instanceof Error ? error.message : String(error)}`);
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Searches for prompt using explicit file mapping in prompts.json.
|
|
632
|
+
* Looks for dependencies with a 'file' property pointing to a specific path.
|
|
633
|
+
*/
|
|
634
|
+
async getFromConfig(dependency) {
|
|
635
|
+
if (typeof dependency === "string" && dependency.startsWith("file:")) {
|
|
636
|
+
return this.fileManager.loadLocalPrompt(dependency.slice(5));
|
|
637
|
+
}
|
|
638
|
+
return null;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Searches for prompt using materialized path from lock file.
|
|
642
|
+
* Lock file contains resolved paths for prompts that have been synced/materialized.
|
|
643
|
+
*/
|
|
644
|
+
async getFromLockFile(handleOrId) {
|
|
645
|
+
const lock = this.fileManager.loadPromptsLock();
|
|
646
|
+
const lockEntry = lock.prompts[handleOrId];
|
|
647
|
+
if (lockEntry == null ? void 0 : lockEntry.materialized) {
|
|
648
|
+
return this.fileManager.loadLocalPrompt(lockEntry.materialized);
|
|
649
|
+
}
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Searches for prompt by scanning all .prompt.yaml files in prompts directory.
|
|
654
|
+
* Extracts prompt name from file path and matches against the requested handle.
|
|
655
|
+
* This is the fallback method when explicit mappings don't exist.
|
|
656
|
+
*/
|
|
657
|
+
async getFromLocalFiles(handleOrId) {
|
|
658
|
+
const localFiles = this.fileManager.getLocalPromptFiles();
|
|
659
|
+
for (const filePath of localFiles) {
|
|
660
|
+
const promptName = this.fileManager.promptNameFromPath(filePath);
|
|
661
|
+
if (promptName === handleOrId) {
|
|
662
|
+
return this.fileManager.loadLocalPrompt(filePath);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Get dependency from config
|
|
669
|
+
*/
|
|
670
|
+
async getDependencyFromConfig(handleOrId) {
|
|
671
|
+
const config = this.fileManager.loadPromptsConfig();
|
|
672
|
+
const dependency = config.prompts[handleOrId];
|
|
673
|
+
return dependency != null ? dependency : null;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Converts LocalPromptConfig to PromptData format
|
|
677
|
+
*/
|
|
678
|
+
convertToPromptData(config) {
|
|
679
|
+
const _a = config, { modelParameters } = _a, rest = __objRest(_a, ["modelParameters"]);
|
|
680
|
+
return __spreadValues({
|
|
681
|
+
maxTokens: modelParameters == null ? void 0 : modelParameters.max_tokens,
|
|
682
|
+
temperature: modelParameters == null ? void 0 : modelParameters.temperature
|
|
683
|
+
}, rest);
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// src/client-sdk/services/prompts/prompts.facade.ts
|
|
527
688
|
var PromptsFacade = class {
|
|
528
689
|
constructor(config) {
|
|
529
|
-
|
|
530
|
-
this.
|
|
690
|
+
var _a, _b;
|
|
691
|
+
this.promptsApiService = (_a = config.promptsApiService) != null ? _a : new PromptsApiService(config);
|
|
692
|
+
this.localPromptsService = (_b = config.localPromptsService) != null ? _b : new LocalPromptsService();
|
|
531
693
|
}
|
|
532
694
|
/**
|
|
533
695
|
* Creates a new prompt.
|
|
@@ -536,7 +698,8 @@ var PromptsFacade = class {
|
|
|
536
698
|
* @throws {PromptsError} If the API call fails.
|
|
537
699
|
*/
|
|
538
700
|
async create(data) {
|
|
539
|
-
|
|
701
|
+
const serverPrompt = await this.promptsApiService.create(data);
|
|
702
|
+
return new Prompt(serverPrompt);
|
|
540
703
|
}
|
|
541
704
|
/**
|
|
542
705
|
* Retrieves a prompt by handle or ID.
|
|
@@ -546,7 +709,12 @@ var PromptsFacade = class {
|
|
|
546
709
|
* @throws {PromptsError} If the API call fails.
|
|
547
710
|
*/
|
|
548
711
|
async get(handleOrId, options) {
|
|
549
|
-
|
|
712
|
+
const localPrompt = await this.localPromptsService.get(handleOrId);
|
|
713
|
+
if (localPrompt) {
|
|
714
|
+
return new Prompt(localPrompt);
|
|
715
|
+
}
|
|
716
|
+
const serverPrompt = await this.promptsApiService.get(handleOrId, options);
|
|
717
|
+
return new Prompt(serverPrompt);
|
|
550
718
|
}
|
|
551
719
|
/**
|
|
552
720
|
* Retrieves all prompts.
|
|
@@ -554,7 +722,8 @@ var PromptsFacade = class {
|
|
|
554
722
|
* @throws {PromptsError} If the API call fails.
|
|
555
723
|
*/
|
|
556
724
|
async getAll() {
|
|
557
|
-
|
|
725
|
+
const serverPrompts = await this.promptsApiService.getAll();
|
|
726
|
+
return serverPrompts.map((prompt) => new Prompt(prompt));
|
|
558
727
|
}
|
|
559
728
|
/**
|
|
560
729
|
* Updates an existing prompt.
|
|
@@ -564,7 +733,8 @@ var PromptsFacade = class {
|
|
|
564
733
|
* @throws {PromptsError} If the API call fails.
|
|
565
734
|
*/
|
|
566
735
|
async update(handleOrId, newData) {
|
|
567
|
-
|
|
736
|
+
const serverPrompt = await this.promptsApiService.update(handleOrId, newData);
|
|
737
|
+
return new Prompt(serverPrompt);
|
|
568
738
|
}
|
|
569
739
|
/**
|
|
570
740
|
* Deletes a prompt by handle or ID.
|
|
@@ -572,7 +742,7 @@ var PromptsFacade = class {
|
|
|
572
742
|
* @throws {PromptsError} If the API call fails.
|
|
573
743
|
*/
|
|
574
744
|
async delete(handleOrId) {
|
|
575
|
-
return this.
|
|
745
|
+
return this.promptsApiService.delete(handleOrId);
|
|
576
746
|
}
|
|
577
747
|
/**
|
|
578
748
|
* Syncs a prompt with the server.
|
|
@@ -581,13 +751,17 @@ var PromptsFacade = class {
|
|
|
581
751
|
* @throws {PromptsError} If the API call fails.
|
|
582
752
|
*/
|
|
583
753
|
async sync(params) {
|
|
584
|
-
|
|
754
|
+
const syncResult = await this.promptsApiService.sync(params);
|
|
755
|
+
return syncResult;
|
|
585
756
|
}
|
|
586
757
|
};
|
|
587
758
|
|
|
588
759
|
export {
|
|
589
760
|
createTracingProxy,
|
|
761
|
+
createLangWatchApiClient,
|
|
590
762
|
PromptsError,
|
|
763
|
+
PromptsApiService,
|
|
764
|
+
LocalPromptsService,
|
|
591
765
|
PromptsFacade
|
|
592
766
|
};
|
|
593
|
-
//# sourceMappingURL=chunk-
|
|
767
|
+
//# sourceMappingURL=chunk-GAFUPYJ3.mjs.map
|