langwatch 0.5.1 → 0.7.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/README.md +19 -0
- package/dist/{add-4WXEWG5H.js → add-5QV3TEWC.js} +28 -32
- package/dist/add-5QV3TEWC.js.map +1 -0
- package/dist/{add-D2WVVKIP.mjs → add-HWFRMAQX.mjs} +14 -18
- package/dist/add-HWFRMAQX.mjs.map +1 -0
- package/dist/{chunk-CAZONSXV.js → chunk-36XAYVMC.js} +186 -76
- package/dist/chunk-36XAYVMC.js.map +1 -0
- package/dist/{chunk-QCYYSMCU.js → chunk-5HAVK64Q.js} +2 -2
- package/dist/chunk-5HAVK64Q.js.map +1 -0
- package/dist/{chunk-ZIULPOMQ.mjs → chunk-7MG7DGPP.mjs} +4 -4
- package/dist/{chunk-YKFTFYKK.mjs → chunk-7VHZNB2S.mjs} +2 -2
- package/dist/chunk-7VHZNB2S.mjs.map +1 -0
- 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-SVXNUWZI.js → chunk-D7UAKYVI.js} +345 -154
- package/dist/chunk-D7UAKYVI.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-H5PON53W.mjs → chunk-EPGKOTSN.mjs} +334 -143
- package/dist/chunk-EPGKOTSN.mjs.map +1 -0
- package/dist/{chunk-N2V6J3U2.mjs → chunk-FEL5FLHA.mjs} +2 -2
- package/dist/{chunk-YNQ44U6D.mjs → chunk-I2SOBPAF.mjs} +23 -21
- package/dist/chunk-I2SOBPAF.mjs.map +1 -0
- package/dist/{chunk-P4SQTYGN.js → chunk-J55AV2YW.js} +32 -32
- package/dist/{chunk-P4SQTYGN.js.map → chunk-J55AV2YW.js.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-QZGTM76F.mjs → chunk-UNMZPS55.mjs} +7 -3
- package/dist/chunk-UNMZPS55.mjs.map +1 -0
- package/dist/{chunk-CU3443HD.mjs → chunk-URTD2WOC.mjs} +14 -1
- package/dist/{chunk-ECOC36EA.js → chunk-VMZUN4EF.js} +16 -12
- package/dist/chunk-VMZUN4EF.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-PFWV7IU6.mjs → list-BQXECLEM.mjs} +13 -14
- package/dist/list-BQXECLEM.mjs.map +1 -0
- package/dist/{list-GIAXAAH5.js → list-HSCIBC4Z.js} +14 -15
- package/dist/list-HSCIBC4Z.js.map +1 -0
- package/dist/{login-BYLXS23I.mjs → login-3IM3PYSJ.mjs} +3 -3
- package/dist/{login-3STX2FAO.js → login-EUDCIJRM.js} +4 -4
- package/dist/{login-3STX2FAO.js.map → login-EUDCIJRM.js.map} +1 -1
- 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-FTF3EBYV.mjs → remove-IVFQAHNT.mjs} +9 -10
- package/dist/{remove-FTF3EBYV.mjs.map → remove-IVFQAHNT.mjs.map} +1 -1
- package/dist/{remove-U3PILQDV.js → remove-VDQ4M6JF.js} +17 -18
- package/dist/remove-VDQ4M6JF.js.map +1 -0
- package/dist/{sync-FOW7DHAH.mjs → sync-2MVHHWCX.mjs} +16 -20
- package/dist/sync-2MVHHWCX.mjs.map +1 -0
- package/dist/{sync-T3T22GVZ.js → sync-KUMBMGJS.js} +31 -35
- package/dist/sync-KUMBMGJS.js.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 +16 -11
- 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-ECOC36EA.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-QZGTM76F.mjs.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-7MG7DGPP.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-CU3443HD.mjs.map → chunk-URTD2WOC.mjs.map} +0 -0
- /package/dist/{login-BYLXS23I.mjs.map → login-3IM3PYSJ.mjs.map} +0 -0
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getLangWatchTracer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UNMZPS55.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-7VHZNB2S.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,73 +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.raw = raw;
|
|
244
|
-
Object.assign(this, raw);
|
|
245
|
-
return createTracingProxy(this, tracer, PromptTracingDecorator);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Compile the prompt template with provided variables (lenient - missing variables become empty)
|
|
249
|
-
* @param variables - Object containing variable values for template compilation
|
|
250
|
-
* @returns CompiledPrompt instance with compiled content
|
|
251
|
-
*/
|
|
252
|
-
_compile(variables, strict) {
|
|
253
|
-
try {
|
|
254
|
-
const compiledPrompt = this.prompt ? liquid.parseAndRenderSync(this.prompt, variables, {
|
|
255
|
-
strictVariables: strict
|
|
256
|
-
}) : "";
|
|
257
|
-
const compiledMessages = (this.messages || []).map((message) => __spreadProps(__spreadValues({}, message), {
|
|
258
|
-
content: message.content ? liquid.parseAndRenderSync(message.content, variables, {
|
|
259
|
-
strictVariables: strict
|
|
260
|
-
}) : message.content
|
|
261
|
-
}));
|
|
262
|
-
const compiledData = __spreadProps(__spreadValues({}, this), {
|
|
263
|
-
prompt: compiledPrompt,
|
|
264
|
-
messages: compiledMessages
|
|
265
|
-
});
|
|
266
|
-
return new CompiledPrompt(compiledData, this);
|
|
267
|
-
} catch (error) {
|
|
268
|
-
const templateStr = this.prompt || JSON.stringify(this.messages);
|
|
269
|
-
throw new PromptCompilationError(
|
|
270
|
-
`Failed to compile prompt template: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
271
|
-
templateStr,
|
|
272
|
-
error
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
compile(variables = {}) {
|
|
277
|
-
return this._compile(variables, false);
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Compile with validation - throws error if required variables are missing
|
|
281
|
-
* @param variables - Template variables
|
|
282
|
-
* @returns CompiledPrompt instance with compiled content
|
|
283
|
-
*/
|
|
284
|
-
compileStrict(variables) {
|
|
285
|
-
return this._compile(variables, true);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
var CompiledPrompt = class extends Prompt {
|
|
289
|
-
constructor(compiledData, original) {
|
|
290
|
-
super(compiledData);
|
|
291
|
-
this.original = original;
|
|
292
|
-
}
|
|
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
|
+
});
|
|
293
256
|
};
|
|
294
257
|
|
|
295
|
-
// src/client-sdk/services/prompts/service.ts
|
|
258
|
+
// src/client-sdk/services/prompts/prompts-api.service.ts
|
|
296
259
|
var PromptsError = class extends Error {
|
|
297
260
|
constructor(message, operation, originalError) {
|
|
298
261
|
super(message);
|
|
@@ -301,9 +264,31 @@ var PromptsError = class extends Error {
|
|
|
301
264
|
this.name = "PromptsError";
|
|
302
265
|
}
|
|
303
266
|
};
|
|
304
|
-
var
|
|
267
|
+
var PromptsApiService = class {
|
|
305
268
|
constructor(config) {
|
|
306
|
-
|
|
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();
|
|
307
292
|
return createTracingProxy(
|
|
308
293
|
this,
|
|
309
294
|
tracer,
|
|
@@ -327,34 +312,13 @@ var PromptsService = class {
|
|
|
327
312
|
}
|
|
328
313
|
/**
|
|
329
314
|
* Fetches all prompts from the API.
|
|
330
|
-
* @returns Array of
|
|
315
|
+
* @returns Array of raw PromptResponse data.
|
|
331
316
|
* @throws {PromptsError} If the API call fails.
|
|
332
317
|
*/
|
|
333
318
|
async getAll() {
|
|
334
|
-
const { data, error } = await this.
|
|
319
|
+
const { data, error } = await this.apiClient.GET("/api/prompts");
|
|
335
320
|
if (error) this.handleApiError("fetch all prompts", error);
|
|
336
|
-
return data
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Fetches a single prompt by its ID.
|
|
340
|
-
* @param id The prompt's unique identifier.
|
|
341
|
-
* @returns The Prompt instance.
|
|
342
|
-
* @throws {PromptsError} If the API call fails.
|
|
343
|
-
*/
|
|
344
|
-
async get(id, options) {
|
|
345
|
-
const { data, error } = await this.config.langwatchApiClient.GET(
|
|
346
|
-
"/api/prompts/{id}",
|
|
347
|
-
{
|
|
348
|
-
params: { path: { id } },
|
|
349
|
-
query: {
|
|
350
|
-
version: options == null ? void 0 : options.version
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
);
|
|
354
|
-
if (error) {
|
|
355
|
-
this.handleApiError(`fetch prompt with ID "${id}"`, error);
|
|
356
|
-
}
|
|
357
|
-
return new Prompt(data);
|
|
321
|
+
return data;
|
|
358
322
|
}
|
|
359
323
|
/**
|
|
360
324
|
* Validates if a prompt exists.
|
|
@@ -377,35 +341,33 @@ var PromptsService = class {
|
|
|
377
341
|
/**
|
|
378
342
|
* Creates a new prompt.
|
|
379
343
|
* @param params The prompt creation payload, matching the OpenAPI schema.
|
|
380
|
-
* @returns
|
|
344
|
+
* @returns Raw PromptResponse data of the created prompt.
|
|
381
345
|
* @throws {PromptsError} If the API call fails.
|
|
382
346
|
*/
|
|
383
347
|
async create(params) {
|
|
384
|
-
const { data, error } = await this.
|
|
348
|
+
const { data, error } = await this.apiClient.POST(
|
|
385
349
|
"/api/prompts",
|
|
386
350
|
{
|
|
387
351
|
body: params
|
|
388
352
|
}
|
|
389
353
|
);
|
|
390
354
|
if (error) this.handleApiError("create prompt", error);
|
|
391
|
-
return
|
|
355
|
+
return data;
|
|
392
356
|
}
|
|
393
357
|
/**
|
|
394
358
|
* Updates an existing prompt.
|
|
395
359
|
* @param id The prompt's unique identifier.
|
|
396
360
|
* @param params The update payload, matching the OpenAPI schema.
|
|
397
|
-
* @returns
|
|
361
|
+
* @returns Raw PromptResponse data of the updated prompt.
|
|
398
362
|
* @throws {PromptsError} If the API call fails.
|
|
399
|
-
* @remarks
|
|
400
|
-
* The API does not return the updated prompt directly, so this method fetches it after updating.
|
|
401
363
|
*/
|
|
402
364
|
async update(id, params) {
|
|
403
|
-
const { error, data: updatedPrompt } = await this.
|
|
365
|
+
const { error, data: updatedPrompt } = await this.apiClient.PUT("/api/prompts/{id}", {
|
|
404
366
|
params: { path: { id } },
|
|
405
367
|
body: params
|
|
406
368
|
});
|
|
407
369
|
if (error) this.handleApiError(`update prompt with ID "${id}"`, error);
|
|
408
|
-
return
|
|
370
|
+
return updatedPrompt;
|
|
409
371
|
}
|
|
410
372
|
/**
|
|
411
373
|
* Deletes a prompt by its ID.
|
|
@@ -413,7 +375,7 @@ var PromptsService = class {
|
|
|
413
375
|
* @throws {PromptsError} If the API call fails.
|
|
414
376
|
*/
|
|
415
377
|
async delete(id) {
|
|
416
|
-
const { data, error } = await this.
|
|
378
|
+
const { data, error } = await this.apiClient.DELETE(
|
|
417
379
|
"/api/prompts/{id}",
|
|
418
380
|
{
|
|
419
381
|
params: { path: { id } }
|
|
@@ -425,10 +387,11 @@ var PromptsService = class {
|
|
|
425
387
|
/**
|
|
426
388
|
* Fetches all versions for a given prompt.
|
|
427
389
|
* @param id The prompt's unique identifier.
|
|
390
|
+
* @returns Array of raw PromptResponse data for each version.
|
|
428
391
|
* @throws {PromptsError} If the API call fails.
|
|
429
392
|
*/
|
|
430
393
|
async getVersions(id) {
|
|
431
|
-
const { data, error } = await this.
|
|
394
|
+
const { data, error } = await this.apiClient.GET(
|
|
432
395
|
"/api/prompts/{id}/versions",
|
|
433
396
|
{
|
|
434
397
|
params: { path: { id } }
|
|
@@ -436,13 +399,13 @@ var PromptsService = class {
|
|
|
436
399
|
);
|
|
437
400
|
if (error)
|
|
438
401
|
this.handleApiError(`fetch versions for prompt with ID "${id}"`, error);
|
|
439
|
-
return data
|
|
402
|
+
return data;
|
|
440
403
|
}
|
|
441
404
|
/**
|
|
442
405
|
* Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.
|
|
443
406
|
* @param handle The prompt's handle/identifier.
|
|
444
407
|
* @param config Local prompt configuration.
|
|
445
|
-
* @returns Object with created flag and
|
|
408
|
+
* @returns Object with created flag and raw PromptResponse data.
|
|
446
409
|
* @throws {PromptsError} If the API call fails.
|
|
447
410
|
*/
|
|
448
411
|
async upsert(handle, config) {
|
|
@@ -479,7 +442,7 @@ var PromptsService = class {
|
|
|
479
442
|
async sync(params) {
|
|
480
443
|
var _a, _b;
|
|
481
444
|
try {
|
|
482
|
-
const response = await this.
|
|
445
|
+
const response = await this.apiClient.POST(
|
|
483
446
|
"/api/prompts/{id}/sync",
|
|
484
447
|
{
|
|
485
448
|
params: { path: { id: params.name } },
|
|
@@ -506,11 +469,227 @@ var PromptsService = class {
|
|
|
506
469
|
}
|
|
507
470
|
};
|
|
508
471
|
|
|
509
|
-
// 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
|
|
510
688
|
var PromptsFacade = class {
|
|
511
689
|
constructor(config) {
|
|
512
|
-
|
|
513
|
-
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();
|
|
514
693
|
}
|
|
515
694
|
/**
|
|
516
695
|
* Creates a new prompt.
|
|
@@ -519,7 +698,8 @@ var PromptsFacade = class {
|
|
|
519
698
|
* @throws {PromptsError} If the API call fails.
|
|
520
699
|
*/
|
|
521
700
|
async create(data) {
|
|
522
|
-
|
|
701
|
+
const serverPrompt = await this.promptsApiService.create(data);
|
|
702
|
+
return new Prompt(serverPrompt);
|
|
523
703
|
}
|
|
524
704
|
/**
|
|
525
705
|
* Retrieves a prompt by handle or ID.
|
|
@@ -529,7 +709,12 @@ var PromptsFacade = class {
|
|
|
529
709
|
* @throws {PromptsError} If the API call fails.
|
|
530
710
|
*/
|
|
531
711
|
async get(handleOrId, options) {
|
|
532
|
-
|
|
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);
|
|
533
718
|
}
|
|
534
719
|
/**
|
|
535
720
|
* Retrieves all prompts.
|
|
@@ -537,7 +722,8 @@ var PromptsFacade = class {
|
|
|
537
722
|
* @throws {PromptsError} If the API call fails.
|
|
538
723
|
*/
|
|
539
724
|
async getAll() {
|
|
540
|
-
|
|
725
|
+
const serverPrompts = await this.promptsApiService.getAll();
|
|
726
|
+
return serverPrompts.map((prompt) => new Prompt(prompt));
|
|
541
727
|
}
|
|
542
728
|
/**
|
|
543
729
|
* Updates an existing prompt.
|
|
@@ -547,7 +733,8 @@ var PromptsFacade = class {
|
|
|
547
733
|
* @throws {PromptsError} If the API call fails.
|
|
548
734
|
*/
|
|
549
735
|
async update(handleOrId, newData) {
|
|
550
|
-
|
|
736
|
+
const serverPrompt = await this.promptsApiService.update(handleOrId, newData);
|
|
737
|
+
return new Prompt(serverPrompt);
|
|
551
738
|
}
|
|
552
739
|
/**
|
|
553
740
|
* Deletes a prompt by handle or ID.
|
|
@@ -555,7 +742,7 @@ var PromptsFacade = class {
|
|
|
555
742
|
* @throws {PromptsError} If the API call fails.
|
|
556
743
|
*/
|
|
557
744
|
async delete(handleOrId) {
|
|
558
|
-
return this.
|
|
745
|
+
return this.promptsApiService.delete(handleOrId);
|
|
559
746
|
}
|
|
560
747
|
/**
|
|
561
748
|
* Syncs a prompt with the server.
|
|
@@ -564,13 +751,17 @@ var PromptsFacade = class {
|
|
|
564
751
|
* @throws {PromptsError} If the API call fails.
|
|
565
752
|
*/
|
|
566
753
|
async sync(params) {
|
|
567
|
-
|
|
754
|
+
const syncResult = await this.promptsApiService.sync(params);
|
|
755
|
+
return syncResult;
|
|
568
756
|
}
|
|
569
757
|
};
|
|
570
758
|
|
|
571
759
|
export {
|
|
572
760
|
createTracingProxy,
|
|
761
|
+
createLangWatchApiClient,
|
|
573
762
|
PromptsError,
|
|
763
|
+
PromptsApiService,
|
|
764
|
+
LocalPromptsService,
|
|
574
765
|
PromptsFacade
|
|
575
766
|
};
|
|
576
|
-
//# sourceMappingURL=chunk-
|
|
767
|
+
//# sourceMappingURL=chunk-EPGKOTSN.mjs.map
|