langwatch 0.3.0 → 0.3.2

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.
Files changed (134) hide show
  1. package/README.md +5 -2
  2. package/dist/add-LBBS4I3H.js +114 -0
  3. package/dist/add-LBBS4I3H.js.map +1 -0
  4. package/dist/add-RD3ZKFAT.mjs +114 -0
  5. package/dist/add-RD3ZKFAT.mjs.map +1 -0
  6. package/dist/chunk-2JU376G7.js +242 -0
  7. package/dist/chunk-2JU376G7.js.map +1 -0
  8. package/dist/chunk-2ODBGSBI.js +4 -0
  9. package/dist/{chunk-G3AUABT7.js.map → chunk-2ODBGSBI.js.map} +1 -1
  10. package/dist/chunk-3GKPQB4R.mjs +242 -0
  11. package/dist/chunk-3GKPQB4R.mjs.map +1 -0
  12. package/dist/chunk-4NRLVT2U.mjs +35 -0
  13. package/dist/chunk-4NRLVT2U.mjs.map +1 -0
  14. package/dist/{chunk-SVJ7SCGB.js → chunk-52GXX3MA.js} +33 -31
  15. package/dist/chunk-52GXX3MA.js.map +1 -0
  16. package/dist/chunk-5NC5ILKA.js +94 -0
  17. package/dist/chunk-5NC5ILKA.js.map +1 -0
  18. package/dist/chunk-AAROJADR.mjs +49 -0
  19. package/dist/chunk-AAROJADR.mjs.map +1 -0
  20. package/dist/chunk-DHJKJVY7.mjs +20 -0
  21. package/dist/chunk-DHJKJVY7.mjs.map +1 -0
  22. package/dist/{chunk-VJSOCNPA.js → chunk-DTEKFQ4U.js} +6 -28
  23. package/dist/chunk-DTEKFQ4U.js.map +1 -0
  24. package/dist/chunk-E7UE2MPD.mjs +93 -0
  25. package/dist/chunk-E7UE2MPD.mjs.map +1 -0
  26. package/dist/chunk-F6E4XQQU.js +20 -0
  27. package/dist/chunk-F6E4XQQU.js.map +1 -0
  28. package/dist/chunk-FJLK5CFL.js +37 -0
  29. package/dist/chunk-FJLK5CFL.js.map +1 -0
  30. package/dist/{chunk-Z5J5UI5E.mjs → chunk-GJSEBQXF.mjs} +139 -107
  31. package/dist/chunk-GJSEBQXF.mjs.map +1 -0
  32. package/dist/chunk-HA3LI5IK.js +35 -0
  33. package/dist/chunk-HA3LI5IK.js.map +1 -0
  34. package/dist/chunk-HJU67C7H.js +93 -0
  35. package/dist/chunk-HJU67C7H.js.map +1 -0
  36. package/dist/chunk-IGHXIIIK.js +49 -0
  37. package/dist/chunk-IGHXIIIK.js.map +1 -0
  38. package/dist/{chunk-PMBEK6YE.mjs → chunk-J7ICRUU4.mjs} +5 -3
  39. package/dist/{chunk-PMBEK6YE.mjs.map → chunk-J7ICRUU4.mjs.map} +1 -1
  40. package/dist/{chunk-HPC6Z7J4.js → chunk-PWZBLTHR.js} +3 -3
  41. package/dist/{chunk-HPC6Z7J4.js.map → chunk-PWZBLTHR.js.map} +1 -1
  42. package/dist/chunk-SMXXAVMB.js +100 -0
  43. package/dist/chunk-SMXXAVMB.js.map +1 -0
  44. package/dist/{chunk-CSC3CMIT.mjs → chunk-STV4ZVNA.mjs} +2 -2
  45. package/dist/chunk-T5AZMMVS.mjs +94 -0
  46. package/dist/chunk-T5AZMMVS.mjs.map +1 -0
  47. package/dist/{chunk-4BZATFKJ.mjs → chunk-UU33HCCZ.mjs} +4 -26
  48. package/dist/{chunk-4BZATFKJ.mjs.map → chunk-UU33HCCZ.mjs.map} +1 -1
  49. package/dist/{chunk-PTJ6AAI7.js → chunk-VGHLQXKB.js} +138 -106
  50. package/dist/chunk-VGHLQXKB.js.map +1 -0
  51. package/dist/chunk-W5ZEP3CI.mjs +100 -0
  52. package/dist/chunk-W5ZEP3CI.mjs.map +1 -0
  53. package/dist/chunk-Y666BJA5.mjs +4 -0
  54. package/dist/chunk-YN4436PK.mjs +37 -0
  55. package/dist/chunk-YN4436PK.mjs.map +1 -0
  56. package/dist/cli/index.d.mts +1 -0
  57. package/dist/cli/index.d.ts +1 -0
  58. package/dist/cli/index.js +106 -0
  59. package/dist/cli/index.js.map +1 -0
  60. package/dist/cli/index.mjs +106 -0
  61. package/dist/cli/index.mjs.map +1 -0
  62. package/dist/client-browser.js +15 -10
  63. package/dist/client-browser.js.map +1 -1
  64. package/dist/client-browser.mjs +9 -4
  65. package/dist/client-browser.mjs.map +1 -1
  66. package/dist/client-node.js +14 -9
  67. package/dist/client-node.js.map +1 -1
  68. package/dist/client-node.mjs +11 -6
  69. package/dist/client-node.mjs.map +1 -1
  70. package/dist/create-G5MTGOOH.js +70 -0
  71. package/dist/create-G5MTGOOH.js.map +1 -0
  72. package/dist/create-QUZYBMQB.mjs +70 -0
  73. package/dist/create-QUZYBMQB.mjs.map +1 -0
  74. package/dist/evaluation/index.js +5 -4
  75. package/dist/evaluation/index.js.map +1 -1
  76. package/dist/evaluation/index.mjs +4 -3
  77. package/dist/index.d.mts +21 -14
  78. package/dist/index.d.ts +21 -14
  79. package/dist/index.js +10 -7
  80. package/dist/index.js.map +1 -1
  81. package/dist/index.mjs +9 -6
  82. package/dist/init-H67RW22E.mjs +16 -0
  83. package/dist/init-H67RW22E.mjs.map +1 -0
  84. package/dist/init-XU2JFY6N.js +16 -0
  85. package/dist/init-XU2JFY6N.js.map +1 -0
  86. package/dist/list-7NPSX2E4.mjs +136 -0
  87. package/dist/list-7NPSX2E4.mjs.map +1 -0
  88. package/dist/list-ZXFLAF52.js +136 -0
  89. package/dist/list-ZXFLAF52.js.map +1 -0
  90. package/dist/login-76NQIHKR.js +110 -0
  91. package/dist/login-76NQIHKR.js.map +1 -0
  92. package/dist/login-EK4WVOI2.mjs +110 -0
  93. package/dist/login-EK4WVOI2.mjs.map +1 -0
  94. package/dist/observability/index.d.mts +3 -3
  95. package/dist/observability/index.d.ts +3 -3
  96. package/dist/observability/index.js +5 -4
  97. package/dist/observability/index.js.map +1 -1
  98. package/dist/observability/index.mjs +4 -3
  99. package/dist/observability/instrumentation/langchain/index.d.mts +2 -2
  100. package/dist/observability/instrumentation/langchain/index.d.ts +2 -2
  101. package/dist/observability/instrumentation/langchain/index.js +29 -27
  102. package/dist/observability/instrumentation/langchain/index.js.map +1 -1
  103. package/dist/observability/instrumentation/langchain/index.mjs +5 -3
  104. package/dist/observability/instrumentation/langchain/index.mjs.map +1 -1
  105. package/dist/prompt/index.d.mts +2 -2
  106. package/dist/prompt/index.d.ts +2 -2
  107. package/dist/prompt/index.js +8 -4
  108. package/dist/prompt/index.js.map +1 -1
  109. package/dist/prompt/index.mjs +10 -6
  110. package/dist/{prompt-BXJWdbQp.d.mts → prompt-D-jpMrLS.d.mts} +245 -0
  111. package/dist/{prompt-BXJWdbQp.d.ts → prompt-D-jpMrLS.d.ts} +245 -0
  112. package/dist/remove-SDJYEPAY.mjs +106 -0
  113. package/dist/remove-SDJYEPAY.mjs.map +1 -0
  114. package/dist/remove-XBNGIVMR.js +106 -0
  115. package/dist/remove-XBNGIVMR.js.map +1 -0
  116. package/dist/sync-EISKGPTL.js +403 -0
  117. package/dist/sync-EISKGPTL.js.map +1 -0
  118. package/dist/sync-ST2IWXSB.mjs +403 -0
  119. package/dist/sync-ST2IWXSB.mjs.map +1 -0
  120. package/dist/{trace-G2312klE.d.ts → trace-CqaKo0kZ.d.ts} +1 -1
  121. package/dist/{trace-D-bZOuqb.d.mts → trace-DtVc5GhF.d.mts} +1 -1
  122. package/package.json +23 -12
  123. package/dist/chunk-76KNOWLS.js +0 -39
  124. package/dist/chunk-76KNOWLS.js.map +0 -1
  125. package/dist/chunk-G3AUABT7.js +0 -4
  126. package/dist/chunk-OM7VY3XT.mjs +0 -4
  127. package/dist/chunk-PTJ6AAI7.js.map +0 -1
  128. package/dist/chunk-SVJ7SCGB.js.map +0 -1
  129. package/dist/chunk-VJSOCNPA.js.map +0 -1
  130. package/dist/chunk-X62YT4WB.mjs +0 -39
  131. package/dist/chunk-X62YT4WB.mjs.map +0 -1
  132. package/dist/chunk-Z5J5UI5E.mjs.map +0 -1
  133. /package/dist/{chunk-CSC3CMIT.mjs.map → chunk-STV4ZVNA.mjs.map} +0 -0
  134. /package/dist/{chunk-OM7VY3XT.mjs.map → chunk-Y666BJA5.mjs.map} +0 -0
@@ -1,41 +1,14 @@
1
1
  import {
2
- canAutomaticallyCaptureInput,
3
- canAutomaticallyCaptureOutput,
2
+ PromptConverter
3
+ } from "./chunk-W5ZEP3CI.mjs";
4
+ import {
4
5
  getApiKey,
5
6
  getEndpoint
6
7
  } from "./chunk-QEWDG5QE.mjs";
7
8
  import {
8
- getLangWatchTracer
9
- } from "./chunk-PMBEK6YE.mjs";
10
- import {
11
- ATTR_LANGWATCH_PROMPT_ID,
12
- ATTR_LANGWATCH_PROMPT_VARIABLES,
13
- ATTR_LANGWATCH_PROMPT_VERSION_ID,
14
- ATTR_LANGWATCH_PROMPT_VERSION_NUMBER,
15
9
  __spreadProps,
16
10
  __spreadValues
17
- } from "./chunk-4BZATFKJ.mjs";
18
-
19
- // src/internal/api/client.ts
20
- import openApiCreateClient from "openapi-fetch";
21
- import { z } from "zod";
22
- var configSchema = z.object({
23
- apiKey: z.string().min(1, "API key is required"),
24
- endpoint: z.string().url("Endpoint must be a valid URL")
25
- });
26
- function createLangWatchApiClient(apiKey, endpoint) {
27
- const config = configSchema.parse({
28
- apiKey: apiKey != null ? apiKey : getApiKey(),
29
- endpoint: endpoint != null ? endpoint : getEndpoint()
30
- });
31
- return openApiCreateClient({
32
- baseUrl: config.endpoint,
33
- headers: {
34
- "X-Auth-Token": config.apiKey,
35
- "Content-Type": "application/json"
36
- }
37
- });
38
- }
11
+ } from "./chunk-YN4436PK.mjs";
39
12
 
40
13
  // src/prompt/prompt.ts
41
14
  import { Liquid } from "liquidjs";
@@ -53,6 +26,8 @@ var liquid = new Liquid({
53
26
  var Prompt = class {
54
27
  constructor(promptData) {
55
28
  this.id = promptData.id;
29
+ this.handle = promptData.handle;
30
+ this.scope = promptData.scope;
56
31
  this.name = promptData.name;
57
32
  this.updatedAt = promptData.updatedAt;
58
33
  this.version = promptData.version;
@@ -117,6 +92,27 @@ var CompiledPrompt = class extends Prompt {
117
92
  }
118
93
  };
119
94
 
95
+ // src/internal/api/client.ts
96
+ import openApiCreateClient from "openapi-fetch";
97
+ import { z } from "zod";
98
+ var configSchema = z.object({
99
+ apiKey: z.string().min(1, "API key is required"),
100
+ endpoint: z.string().url("Endpoint must be a valid URL")
101
+ });
102
+ function createLangWatchApiClient(apiKey, endpoint) {
103
+ const config = configSchema.parse({
104
+ apiKey: apiKey != null ? apiKey : getApiKey(),
105
+ endpoint: endpoint != null ? endpoint : getEndpoint()
106
+ });
107
+ return openApiCreateClient({
108
+ baseUrl: config.endpoint,
109
+ headers: {
110
+ "X-Auth-Token": config.apiKey,
111
+ "Content-Type": "application/json"
112
+ }
113
+ });
114
+ }
115
+
120
116
  // src/prompt/service.ts
121
117
  var PromptsError = class extends Error {
122
118
  constructor(message, operation, originalError) {
@@ -175,16 +171,35 @@ var _PromptService = class _PromptService {
175
171
  /**
176
172
  * Fetches a single prompt by its ID.
177
173
  * @param id The prompt's unique identifier.
178
- * @returns The Prompt instance.
174
+ * @returns The Prompt instance or null if not found.
179
175
  * @throws {PromptsError} If the API call fails.
180
176
  */
181
177
  async get(id) {
182
178
  const { data, error } = await this.client.GET("/api/prompts/{id}", {
183
179
  params: { path: { id } }
184
180
  });
185
- if (error) this.handleApiError(`fetch prompt with ID "${id}"`, error);
181
+ if (error) {
182
+ if (error.toString().includes("404")) {
183
+ return null;
184
+ }
185
+ this.handleApiError(`fetch prompt with ID "${id}"`, error);
186
+ }
186
187
  return new Prompt(data);
187
188
  }
189
+ /**
190
+ * Validates if a prompt exists.
191
+ * @param id The prompt's unique identifier.
192
+ * @returns True if prompt exists, false otherwise.
193
+ * @throws {PromptsError} If the API call fails (not 404).
194
+ */
195
+ async exists(id) {
196
+ try {
197
+ const prompt = await this.get(id);
198
+ return prompt !== null;
199
+ } catch (error) {
200
+ throw error;
201
+ }
202
+ }
188
203
  /**
189
204
  * Creates a new prompt.
190
205
  * @param params The prompt creation payload, matching the OpenAPI schema.
@@ -213,7 +228,15 @@ var _PromptService = class _PromptService {
213
228
  body: params
214
229
  });
215
230
  if (error) this.handleApiError(`update prompt with ID "${id}"`, error);
216
- return await this.get(id);
231
+ const updatedPrompt = await this.get(id);
232
+ if (!updatedPrompt) {
233
+ throw new PromptsError(
234
+ "Prompt not found after update",
235
+ "update prompt",
236
+ null
237
+ );
238
+ }
239
+ return updatedPrompt;
217
240
  }
218
241
  /**
219
242
  * Deletes a prompt by its ID.
@@ -246,6 +269,8 @@ var _PromptService = class _PromptService {
246
269
  for (const version of dataTypeCorrected) {
247
270
  prompts[version.id] = new Prompt({
248
271
  id: version.configId,
272
+ handle: version.handle,
273
+ scope: version.scope,
249
274
  messages: version.configData.messages,
250
275
  model: version.configData.model,
251
276
  prompt: version.configData.prompt,
@@ -275,86 +300,93 @@ var _PromptService = class _PromptService {
275
300
  });
276
301
  if (error)
277
302
  this.handleApiError(`create version for prompt with ID "${id}"`, error);
278
- return await this.get(id);
279
- }
280
- };
281
- _PromptService.instance = null;
282
- var PromptService = _PromptService;
283
-
284
- // src/prompt/tracer.ts
285
- var tracer = getLangWatchTracer("langwatch.prompt");
286
-
287
- // src/prompt/get-prompt.ts
288
- async function getPrompt(id, variables) {
289
- return tracer.withActiveSpan("retrieve prompt", async (span) => {
290
- span.setType("prompt");
291
- span.setAttribute(ATTR_LANGWATCH_PROMPT_ID, id);
292
- const service = PromptService.getInstance();
293
- const prompt = await service.get(id);
294
- if (canAutomaticallyCaptureOutput()) {
295
- span.setOutput(prompt);
296
- }
297
- span.setAttributes({
298
- [ATTR_LANGWATCH_PROMPT_ID]: id,
299
- [ATTR_LANGWATCH_PROMPT_VERSION_ID]: prompt.versionId,
300
- [ATTR_LANGWATCH_PROMPT_VERSION_NUMBER]: prompt.version
301
- });
302
- if (variables) {
303
- if (canAutomaticallyCaptureInput()) {
304
- span.setAttribute(
305
- ATTR_LANGWATCH_PROMPT_VARIABLES,
306
- JSON.stringify({
307
- type: "json",
308
- value: variables
309
- })
310
- );
311
- }
312
- return prompt.compile(variables);
313
- }
314
- return prompt;
315
- });
316
- }
317
-
318
- // src/prompt/get-prompt-version.ts
319
- async function getPromptVersion(id, versionId, variables) {
320
- return tracer.withActiveSpan("retrieve prompt version", async (span) => {
321
- span.setType("prompt");
322
- span.setAttribute(ATTR_LANGWATCH_PROMPT_ID, id);
323
- const service = PromptService.getInstance();
324
- const prompt = await service.getVersions(id);
325
- const promptVersion = prompt[versionId];
326
- if (!promptVersion) {
327
- throw new Error(`Prompt version ${versionId} not found for prompt ${id}`);
303
+ const updatedPrompt = await this.get(id);
304
+ if (!updatedPrompt) {
305
+ throw new PromptsError(
306
+ "Prompt not found after version creation",
307
+ "create version",
308
+ null
309
+ );
328
310
  }
329
- if (canAutomaticallyCaptureOutput()) {
330
- span.setOutput(prompt);
311
+ return updatedPrompt;
312
+ }
313
+ /**
314
+ * Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.
315
+ * @param name The prompt's name/identifier.
316
+ * @param config Local prompt configuration.
317
+ * @returns Object with created flag and the prompt instance.
318
+ * @throws {PromptsError} If the API call fails.
319
+ */
320
+ async upsert(name, config) {
321
+ var _a, _b;
322
+ let prompt = await this.get(name);
323
+ let created = false;
324
+ if (!prompt) {
325
+ prompt = await this.create({ name });
326
+ created = true;
331
327
  }
332
- span.setAttributes({
333
- [ATTR_LANGWATCH_PROMPT_ID]: id,
334
- [ATTR_LANGWATCH_PROMPT_VERSION_ID]: promptVersion.id,
335
- [ATTR_LANGWATCH_PROMPT_VERSION_NUMBER]: promptVersion.version
336
- });
337
- if (variables) {
338
- if (canAutomaticallyCaptureInput()) {
339
- span.setAttribute(
340
- ATTR_LANGWATCH_PROMPT_VARIABLES,
341
- JSON.stringify({
342
- type: "json",
343
- value: variables
344
- })
345
- );
328
+ const versionData = {
329
+ configData: {
330
+ version: 1,
331
+ model: config.model,
332
+ prompt: PromptConverter.extractSystemPrompt(config.messages),
333
+ messages: PromptConverter.filterNonSystemMessages(config.messages),
334
+ temperature: (_a = config.modelParameters) == null ? void 0 : _a.temperature,
335
+ max_tokens: (_b = config.modelParameters) == null ? void 0 : _b.max_tokens,
336
+ inputs: [{ identifier: "input", type: "str" }],
337
+ outputs: [{ identifier: "output", type: "str" }]
338
+ },
339
+ commitMessage: `Updated via CLI sync`,
340
+ projectId: "placeholder",
341
+ // Will be overridden by the API
342
+ configId: prompt.id,
343
+ schemaVersion: "1.0",
344
+ version: 1
345
+ // Will be auto-incremented by the API
346
+ };
347
+ const updatedPrompt = await this.createVersion(prompt.id, versionData);
348
+ return {
349
+ created,
350
+ prompt: updatedPrompt
351
+ };
352
+ }
353
+ /**
354
+ * Sync a prompt with local content, handling conflicts and version management
355
+ */
356
+ async sync(params) {
357
+ var _a, _b;
358
+ try {
359
+ const response = await this.client.POST("/api/prompts/{id}/sync", {
360
+ params: { path: { id: params.name } },
361
+ body: {
362
+ configData: params.configData,
363
+ localVersion: params.localVersion,
364
+ commitMessage: params.commitMessage
365
+ }
366
+ });
367
+ if (response.error) {
368
+ const errorMessage = (_b = (_a = response.error) == null ? void 0 : _a.error) != null ? _b : JSON.stringify(response.error);
369
+ throw new Error(`Failed to sync prompt: ${errorMessage}`);
346
370
  }
347
- return promptVersion.compile(variables);
371
+ return {
372
+ action: response.data.action,
373
+ prompt: response.data.prompt,
374
+ conflictInfo: response.data.conflictInfo
375
+ };
376
+ } catch (error) {
377
+ const message = error instanceof Error ? error.message : "Unknown error occurred";
378
+ throw new PromptsError(message, "sync", error);
348
379
  }
349
- return promptVersion;
350
- });
351
- }
380
+ }
381
+ };
382
+ _PromptService.instance = null;
383
+ var PromptService = _PromptService;
352
384
 
353
385
  export {
354
386
  PromptCompilationError,
355
387
  Prompt,
356
388
  CompiledPrompt,
357
- getPrompt,
358
- getPromptVersion
389
+ PromptsError,
390
+ PromptService
359
391
  };
360
- //# sourceMappingURL=chunk-Z5J5UI5E.mjs.map
392
+ //# sourceMappingURL=chunk-GJSEBQXF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/prompt/prompt.ts","../src/internal/api/client.ts","../src/prompt/service.ts"],"sourcesContent":["import { Liquid } from \"liquidjs\";\nimport type { paths } from \"../internal/generated/openapi/api-client\";\n\n// Extract the prompt response type from OpenAPI schema\nexport type PromptResponse = NonNullable<\n paths[\"/api/prompts/{id}\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n>;\n\n// Type for template variables - supporting common data types\nexport type TemplateVariables = Record<\n string,\n string | number | boolean | object | null\n>;\n\n/**\n * Error class for template compilation issues\n */\nexport class PromptCompilationError extends Error {\n constructor(\n message: string,\n public readonly template: string,\n public readonly originalError?: any,\n ) {\n super(message);\n this.name = \"PromptCompilationError\";\n }\n}\n\n// Global Liquid instance - shared across all prompts for efficiency\nconst liquid = new Liquid({\n strictFilters: true,\n});\n\nexport class Prompt implements PromptResponse {\n public readonly id!: string;\n public readonly handle!: string | null;\n public readonly scope!: \"ORGANIZATION\" | \"PROJECT\";\n public readonly name!: string;\n public readonly updatedAt!: string;\n public readonly version!: number;\n public readonly versionId!: string;\n public readonly versionCreatedAt!: string;\n public readonly model!: string;\n public readonly prompt!: string;\n public readonly messages!: PromptResponse[\"messages\"];\n public readonly response_format!: PromptResponse[\"response_format\"];\n\n constructor(promptData: PromptResponse) {\n this.id = promptData.id;\n this.handle = promptData.handle;\n this.scope = promptData.scope;\n this.name = promptData.name;\n this.updatedAt = promptData.updatedAt;\n this.version = promptData.version;\n this.versionId = promptData.versionId;\n this.versionCreatedAt = promptData.versionCreatedAt;\n this.model = promptData.model;\n this.prompt = promptData.prompt;\n this.messages = promptData.messages;\n this.response_format = promptData.response_format;\n }\n\n /**\n * Get the raw prompt data from the API\n */\n get raw(): PromptResponse {\n return this;\n }\n\n /**\n * Compile the prompt template with provided variables (lenient - missing variables become empty)\n * @param variables - Object containing variable values for template compilation\n * @returns CompiledPrompt instance with compiled content\n */\n private _compile(\n variables: TemplateVariables,\n strict: boolean,\n ): CompiledPrompt {\n try {\n // Compile main prompt\n const compiledPrompt = this.prompt\n ? liquid.parseAndRenderSync(this.prompt, variables, {\n strictVariables: strict,\n })\n : \"\";\n\n // Compile messages\n const compiledMessages = (this.messages || []).map((message) => ({\n ...message,\n content: message.content\n ? liquid.parseAndRenderSync(message.content, variables, {\n strictVariables: strict,\n })\n : message.content,\n }));\n\n // Create new prompt data with compiled content\n const compiledData: PromptResponse = {\n ...this,\n prompt: compiledPrompt,\n messages: compiledMessages,\n };\n\n return new CompiledPrompt(compiledData, this);\n } catch (error) {\n const templateStr = this.prompt || JSON.stringify(this.messages);\n throw new PromptCompilationError(\n `Failed to compile prompt template: ${\n error instanceof Error ? error.message : \"Unknown error\"\n }`,\n templateStr,\n error,\n );\n }\n }\n\n compile(variables: TemplateVariables = {}): CompiledPrompt {\n return this._compile(variables, false);\n }\n\n /**\n * Compile with validation - throws error if required variables are missing\n * @param variables - Template variables\n * @returns CompiledPrompt instance with compiled content\n */\n compileStrict(variables: TemplateVariables): CompiledPrompt {\n return this._compile(variables, true);\n }\n}\n\n/**\n * Represents a compiled prompt that extends Prompt with reference to the original template\n */\nexport class CompiledPrompt extends Prompt {\n constructor(\n compiledData: PromptResponse,\n public readonly original: Prompt,\n ) {\n super(compiledData);\n }\n}\n","import openApiCreateClient from \"openapi-fetch\";\nimport type { paths } from \"../generated/openapi/api-client\";\nimport { z } from \"zod\";\nimport { getApiKey, getEndpoint } from \"../../client\";\n\n// Define the client type explicitly to avoid naming issues\nexport type LangwatchApiClient = ReturnType<typeof openApiCreateClient<paths>>;\n\nconst configSchema = z.object({\n apiKey: z.string().min(1, \"API key is required\"),\n endpoint: z.string().url(\"Endpoint must be a valid URL\"),\n});\n\nexport function createLangWatchApiClient(apiKey?: string | undefined, endpoint?: string | undefined ): LangwatchApiClient {\n // This will error if the config is invalid\n const config = configSchema.parse({\n apiKey: apiKey ?? getApiKey(),\n endpoint: endpoint ?? getEndpoint(),\n });\n\n return openApiCreateClient<paths>({\n baseUrl: config.endpoint,\n headers: {\n \"X-Auth-Token\": config.apiKey,\n \"Content-Type\": \"application/json\",\n },\n });\n}\n\n\n","import {\n createLangWatchApiClient,\n type LangwatchApiClient,\n} from \"../internal/api/client\";\nimport type { paths } from \"../internal/generated/openapi/api-client\";\nimport { Prompt, type PromptResponse } from \"./prompt\";\nimport { PromptConverter } from \"./converter\";\n\n// Extract types directly from OpenAPI schema for strong type safety.\ntype CreatePromptBody = NonNullable<\n paths[\"/api/prompts\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\ntype UpdatePromptBody = NonNullable<\n paths[\"/api/prompts/{id}\"][\"put\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\ntype CreateVersionBody = NonNullable<\n paths[\"/api/prompts/{id}/versions\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\ntype SyncBody = NonNullable<\n paths[\"/api/prompts/{id}/sync\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"];\n\n/**\n * Custom error class for Prompts API operations.\n * Provides context about the failed operation and the original error.\n */\nexport class PromptsError extends Error {\n constructor(\n message: string,\n public readonly operation: string,\n public readonly originalError?: any,\n ) {\n super(message);\n this.name = \"PromptsError\";\n }\n}\n\nexport type SyncAction = \"created\" | \"updated\" | \"conflict\" | \"up_to_date\";\n\nexport type ConfigData = NonNullable<\n paths[\"/api/prompts/{id}/sync\"][\"post\"][\"requestBody\"]\n>[\"content\"][\"application/json\"][\"configData\"];\n\nexport interface SyncResult {\n action: SyncAction;\n prompt?: PromptResponse;\n conflictInfo?: {\n localVersion: number;\n remoteVersion: number;\n differences: string[];\n remoteConfigData: ConfigData;\n };\n}\n\ninterface PromptServiceOptions {\n client?: LangwatchApiClient;\n}\n\n/**\n * Service for managing prompt resources via the Langwatch API.\n *\n * Responsibilities:\n * - CRUD operations for prompts\n * - Creating prompt versions\n * - Error handling with contextual information\n *\n * All methods return Prompt instances, which encapsulate prompt data and template logic.\n */\nexport class PromptService {\n private client: LangwatchApiClient;\n private static instance: PromptService | null = null;\n\n constructor(opts?: PromptServiceOptions) {\n this.client = opts?.client ?? createLangWatchApiClient();\n }\n\n /**\n * Gets the singleton instance of PromptService.\n * Creates the instance lazily on first access.\n */\n public static getInstance(): PromptService {\n if (!PromptService.instance) {\n PromptService.instance = new PromptService();\n }\n return PromptService.instance;\n }\n\n /**\n * Resets the singleton instance. Primarily used for testing.\n */\n public static resetInstance(): void {\n PromptService.instance = null;\n }\n\n /**\n * Handles API errors by throwing a PromptsError with operation context.\n * @param operation Description of the operation being performed.\n * @param error The error object returned from the API client.\n * @throws {PromptsError}\n */\n private handleApiError(operation: string, error: any): never {\n const errorMessage =\n typeof error === \"string\"\n ? error\n : error?.error ?? error?.message ?? \"Unknown error occurred\";\n throw new PromptsError(\n `Failed to ${operation}: ${errorMessage}`,\n operation,\n error,\n );\n }\n\n /**\n * Fetches all prompts from the API.\n * @returns Array of Prompt instances.\n * @throws {PromptsError} If the API call fails.\n */\n async getAll(): Promise<Prompt[]> {\n const { data, error } = await this.client.GET(\"/api/prompts\");\n if (error) this.handleApiError(\"fetch all prompts\", error);\n return data.map((promptData) => new Prompt(promptData));\n }\n\n /**\n * Fetches a single prompt by its ID.\n * @param id The prompt's unique identifier.\n * @returns The Prompt instance or null if not found.\n * @throws {PromptsError} If the API call fails.\n */\n async get(id: string): Promise<Prompt | null> {\n const { data, error } = await this.client.GET(\"/api/prompts/{id}\", {\n params: { path: { id } },\n });\n if (error) {\n if (error.toString().includes(\"404\")) {\n return null;\n }\n this.handleApiError(`fetch prompt with ID \"${id}\"`, error);\n }\n return new Prompt(data);\n }\n\n /**\n * Validates if a prompt exists.\n * @param id The prompt's unique identifier.\n * @returns True if prompt exists, false otherwise.\n * @throws {PromptsError} If the API call fails (not 404).\n */\n async exists(id: string): Promise<boolean> {\n try {\n const prompt = await this.get(id);\n return prompt !== null;\n } catch (error) {\n throw error; // Re-throw non-404 errors\n }\n }\n\n /**\n * Creates a new prompt.\n * @param params The prompt creation payload, matching the OpenAPI schema.\n * @returns The created Prompt instance.\n * @throws {PromptsError} If the API call fails.\n */\n async create(params: CreatePromptBody): Promise<Prompt> {\n const { data, error } = await this.client.POST(\"/api/prompts\", {\n body: params,\n });\n if (error) this.handleApiError(\"create prompt\", error);\n return new Prompt(data);\n }\n\n /**\n * Updates an existing prompt.\n * @param id The prompt's unique identifier.\n * @param params The update payload, matching the OpenAPI schema.\n * @returns The updated Prompt instance.\n * @throws {PromptsError} If the API call fails.\n * @remarks\n * The API does not return the updated prompt directly, so this method fetches it after updating.\n */\n async update(id: string, params: UpdatePromptBody): Promise<Prompt> {\n const { error } = await this.client.PUT(\"/api/prompts/{id}\", {\n params: { path: { id } },\n body: params,\n });\n if (error) this.handleApiError(`update prompt with ID \"${id}\"`, error);\n // TODO: This is a workaround to get the updated prompt. It would be better to return the updated prompt directly.\n const updatedPrompt = await this.get(id);\n if (!updatedPrompt) {\n throw new PromptsError(\n \"Prompt not found after update\",\n \"update prompt\",\n null,\n );\n }\n return updatedPrompt;\n }\n\n /**\n * Deletes a prompt by its ID.\n * @param id The prompt's unique identifier.\n * @throws {PromptsError} If the API call fails.\n */\n async delete(id: string): Promise<void> {\n const { error } = await this.client.DELETE(\"/api/prompts/{id}\", {\n params: { path: { id } },\n });\n if (error) this.handleApiError(`delete prompt with ID \"${id}\"`, error);\n }\n\n /**\n * Fetches all versions for a given prompt.\n * @param id The prompt's unique identifier.\n * @throws {PromptsError} If the API call fails.\n */\n async getVersions(id: string): Promise<Record<string, Prompt>> {\n const { data, error } = await this.client.GET(\n \"/api/prompts/{id}/versions\",\n {\n params: { path: { id } },\n },\n );\n if (error)\n this.handleApiError(`fetch versions for prompt with ID \"${id}\"`, error);\n\n const prompts: Record<string, Prompt> = {};\n const dataTypeCorrected = data as unknown as NonNullable<\n paths[\"/api/prompts/{id}/versions\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n >[];\n\n for (const version of dataTypeCorrected) {\n prompts[version.id] = new Prompt({\n id: version.configId,\n handle: version.handle,\n scope: version.scope,\n messages: version.configData.messages,\n model: version.configData.model,\n prompt: version.configData.prompt,\n response_format: null,\n name: `Prompt ${version.configId}@${version.id}`,\n updatedAt: version.createdAt,\n version: version.configData.version ?? 0,\n versionCreatedAt: version.createdAt,\n versionId: version.id,\n });\n }\n\n return prompts;\n }\n\n /**\n * Creates a new version for a given prompt.\n * @param id The prompt's unique identifier.\n * @param params The version creation payload, matching the OpenAPI schema.\n * @returns The updated Prompt instance.\n * @throws {PromptsError} If the API call fails.\n * @remarks\n * The API does not return the updated prompt directly, so this method fetches it after creation.\n */\n async createVersion(id: string, params: CreateVersionBody): Promise<Prompt> {\n const { error } = await this.client.POST(\"/api/prompts/{id}/versions\", {\n params: { path: { id } },\n body: params,\n });\n if (error)\n this.handleApiError(`create version for prompt with ID \"${id}\"`, error);\n // TODO: This is a workaround to get the updated prompt. It would be better to return the updated prompt directly.\n const updatedPrompt = await this.get(id);\n if (!updatedPrompt) {\n throw new PromptsError(\n \"Prompt not found after version creation\",\n \"create version\",\n null,\n );\n }\n return updatedPrompt;\n }\n\n /**\n * Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.\n * @param name The prompt's name/identifier.\n * @param config Local prompt configuration.\n * @returns Object with created flag and the prompt instance.\n * @throws {PromptsError} If the API call fails.\n */\n async upsert(\n name: string,\n config: {\n model: string;\n modelParameters?: {\n temperature?: number;\n max_tokens?: number;\n };\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>;\n },\n ): Promise<{ created: boolean; prompt: Prompt }> {\n let prompt = await this.get(name);\n let created = false;\n\n if (!prompt) {\n prompt = await this.create({ name });\n created = true;\n }\n\n // Create a new version with the updated config using the converter\n const versionData = {\n configData: {\n version: 1,\n model: config.model,\n prompt: PromptConverter.extractSystemPrompt(config.messages),\n messages: PromptConverter.filterNonSystemMessages(config.messages),\n temperature: config.modelParameters?.temperature,\n max_tokens: config.modelParameters?.max_tokens,\n inputs: [{ identifier: \"input\", type: \"str\" as const }],\n outputs: [{ identifier: \"output\", type: \"str\" as const }],\n },\n commitMessage: `Updated via CLI sync`,\n projectId: \"placeholder\", // Will be overridden by the API\n configId: prompt.id,\n schemaVersion: \"1.0\" as const,\n version: 1, // Will be auto-incremented by the API\n } as any; // Type assertion to bypass strict typing for now\n\n const updatedPrompt = await this.createVersion(prompt.id, versionData);\n\n return {\n created,\n prompt: updatedPrompt,\n };\n }\n\n /**\n * Sync a prompt with local content, handling conflicts and version management\n */\n async sync(params: {\n name: string;\n configData: ConfigData;\n localVersion?: number;\n commitMessage?: string;\n }): Promise<SyncResult> {\n try {\n const response = await this.client.POST(\"/api/prompts/{id}/sync\", {\n params: { path: { id: params.name } },\n body: {\n configData: params.configData,\n localVersion: params.localVersion,\n commitMessage: params.commitMessage,\n },\n });\n\n if (response.error) {\n const errorMessage =\n response.error?.error ?? JSON.stringify(response.error);\n throw new Error(`Failed to sync prompt: ${errorMessage}`);\n }\n\n return {\n action: response.data.action as SyncAction,\n prompt: response.data.prompt as PromptResponse,\n conflictInfo: response.data.conflictInfo,\n };\n } catch (error) {\n const message =\n error instanceof Error ? error.message : \"Unknown error occurred\";\n throw new PromptsError(message, \"sync\", error);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,cAAc;AAiBhB,IAAM,yBAAN,cAAqC,MAAM;AAAA,EAChD,YACE,SACgB,UACA,eAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAGA,IAAM,SAAS,IAAI,OAAO;AAAA,EACxB,eAAe;AACjB,CAAC;AAEM,IAAM,SAAN,MAAuC;AAAA,EAc5C,YAAY,YAA4B;AACtC,SAAK,KAAK,WAAW;AACrB,SAAK,SAAS,WAAW;AACzB,SAAK,QAAQ,WAAW;AACxB,SAAK,OAAO,WAAW;AACvB,SAAK,YAAY,WAAW;AAC5B,SAAK,UAAU,WAAW;AAC1B,SAAK,YAAY,WAAW;AAC5B,SAAK,mBAAmB,WAAW;AACnC,SAAK,QAAQ,WAAW;AACxB,SAAK,SAAS,WAAW;AACzB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AAAA,MACf,SAAS;AAAA;AAAA,IACX;AAEA,UAAM,gBAAgB,MAAM,KAAK,cAAc,OAAO,IAAI,WAAW;AAErE,WAAO;AAAA,MACL;AAAA,MACA,QAAQ;AAAA,IACV;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,QAKa;AAtV1B;AAuVI,QAAI;AACF,YAAM,WAAW,MAAM,KAAK,OAAO,KAAK,0BAA0B;AAAA,QAChE,QAAQ,EAAE,MAAM,EAAE,IAAI,OAAO,KAAK,EAAE;AAAA,QACpC,MAAM;AAAA,UACJ,YAAY,OAAO;AAAA,UACnB,cAAc,OAAO;AAAA,UACrB,eAAe,OAAO;AAAA,QACxB;AAAA,MACF,CAAC;AAED,UAAI,SAAS,OAAO;AAClB,cAAM,gBACJ,oBAAS,UAAT,mBAAgB,UAAhB,YAAyB,KAAK,UAAU,SAAS,KAAK;AACxD,cAAM,IAAI,MAAM,0BAA0B,YAAY,EAAE;AAAA,MAC1D;AAEA,aAAO;AAAA,QACL,QAAQ,SAAS,KAAK;AAAA,QACtB,QAAQ,SAAS,KAAK;AAAA,QACtB,cAAc,SAAS,KAAK;AAAA,MAC9B;AAAA,IACF,SAAS,OAAO;AACd,YAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU;AAC3C,YAAM,IAAI,aAAa,SAAS,QAAQ,KAAK;AAAA,IAC/C;AAAA,EACF;AACF;AA9Sa,eAEI,WAAiC;AAF3C,IAAM,gBAAN;","names":[]}
@@ -0,0 +1,35 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/cli/types.ts
2
+ var _zod = require('zod');
3
+ var localPromptConfigSchema = _zod.z.object({
4
+ model: _zod.z.string().min(1, "Model is required"),
5
+ modelParameters: _zod.z.object({
6
+ temperature: _zod.z.number().optional(),
7
+ max_tokens: _zod.z.number().optional()
8
+ }).loose().optional(),
9
+ messages: _zod.z.array(
10
+ _zod.z.object({
11
+ role: _zod.z.enum(["system", "user", "assistant"]),
12
+ content: _zod.z.string().min(1, "Message content cannot be empty")
13
+ }).loose()
14
+ ).min(1, "At least one message is required")
15
+ }).loose();
16
+ var parsePromptSpec = (spec) => {
17
+ const atIndex = spec.lastIndexOf("@");
18
+ if (atIndex === -1) {
19
+ return { name: spec, version: "latest" };
20
+ }
21
+ const name = spec.slice(0, atIndex);
22
+ const version = spec.slice(atIndex + 1);
23
+ if (!name || !version) {
24
+ throw new Error(
25
+ `Invalid prompt specification: ${spec}. Use format 'name@version' or just 'name'`
26
+ );
27
+ }
28
+ return { name, version };
29
+ };
30
+
31
+
32
+
33
+
34
+ exports.localPromptConfigSchema = localPromptConfigSchema; exports.parsePromptSpec = parsePromptSpec;
35
+ //# sourceMappingURL=chunk-HA3LI5IK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-HA3LI5IK.js","../src/cli/types.ts"],"names":[],"mappings":"AAAA;ACAA,0BAAkB;AAcX,IAAM,wBAAA,EAA0B,MAAA,CACpC,MAAA,CAAO;AAAA,EACN,KAAA,EAAO,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAA,EAAG,mBAAmB,CAAA;AAAA,EAC5C,eAAA,EAAiB,MAAA,CACd,MAAA,CAAO;AAAA,IACN,WAAA,EAAa,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,QAAA,CAAS,CAAA;AAAA,IACjC,UAAA,EAAY,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,QAAA,CAAS;AAAA,EAClC,CAAC,CAAA,CACA,KAAA,CAAM,CAAA,CACN,QAAA,CAAS,CAAA;AAAA,EACZ,QAAA,EAAU,MAAA,CACP,KAAA;AAAA,IACC,MAAA,CACG,MAAA,CAAO;AAAA,MACN,IAAA,EAAM,MAAA,CAAE,IAAA,CAAK,CAAC,QAAA,EAAU,MAAA,EAAQ,WAAW,CAAC,CAAA;AAAA,MAC5C,OAAA,EAAS,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAA,EAAG,iCAAiC;AAAA,IAC9D,CAAC,CAAA,CACA,KAAA,CAAM;AAAA,EACX,CAAA,CACC,GAAA,CAAI,CAAA,EAAG,kCAAkC;AAC9C,CAAC,CAAA,CACA,KAAA,CAAM,CAAA;AAuCF,IAAM,gBAAA,EAAkB,CAC7B,IAAA,EAAA,GACsC;AACtC,EAAA,MAAM,QAAA,EAAU,IAAA,CAAK,WAAA,CAAY,GAAG,CAAA;AACpC,EAAA,GAAA,CAAI,QAAA,IAAY,CAAA,CAAA,EAAI;AAClB,IAAA,OAAO,EAAE,IAAA,EAAM,IAAA,EAAM,OAAA,EAAS,SAAS,CAAA;AAAA,EACzC;AAEA,EAAA,MAAM,KAAA,EAAO,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,OAAO,CAAA;AAClC,EAAA,MAAM,QAAA,EAAU,IAAA,CAAK,KAAA,CAAM,QAAA,EAAU,CAAC,CAAA;AAEtC,EAAA,GAAA,CAAI,CAAC,KAAA,GAAQ,CAAC,OAAA,EAAS;AACrB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,8BAAA,EAAiC,IAAI,CAAA,0CAAA;AAAA,IACvC,CAAA;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,QAAQ,CAAA;AACzB,CAAA;AD/DA;AACA;AACE;AACA;AACF,qGAAC","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-HA3LI5IK.js","sourcesContent":[null,"import { z } from \"zod\";\n\nexport type PromptDependency =\n | string\n | {\n version?: string;\n file?: string;\n };\n\nexport type PromptsConfig = {\n prompts: Record<string, PromptDependency>;\n};\n\n// Zod schema for local prompt config with permissive validation\nexport const localPromptConfigSchema = z\n .object({\n model: z.string().min(1, \"Model is required\"),\n modelParameters: z\n .object({\n temperature: z.number().optional(),\n max_tokens: z.number().optional(),\n })\n .loose()\n .optional(),\n messages: z\n .array(\n z\n .object({\n role: z.enum([\"system\", \"user\", \"assistant\"]),\n content: z.string().min(1, \"Message content cannot be empty\"),\n })\n .loose(),\n )\n .min(1, \"At least one message is required\"),\n })\n .loose();\n\nexport type LocalPromptConfig = z.infer<typeof localPromptConfigSchema>;\n\nexport type MaterializedPrompt = {\n id: string;\n name: string;\n version: number;\n versionId: string;\n model: string;\n messages: Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>;\n prompt: string;\n updatedAt: string;\n versionCreatedAt: string;\n};\n\nexport type SyncResult = {\n fetched: Array<{ name: string; version: number; versionSpec: string }>;\n pushed: Array<{ name: string; version: number }>;\n unchanged: string[];\n cleaned: string[];\n errors: Array<{ name: string; error: string }>;\n};\n\nexport type PromptsLockEntry = {\n version: number;\n versionId: string;\n materialized: string;\n};\n\nexport type PromptsLock = {\n lockfileVersion: number;\n prompts: Record<string, PromptsLockEntry>;\n};\n\n// Parse npm-style version specifications like \"foo@latest\" or \"bar@5\"\nexport const parsePromptSpec = (\n spec: string,\n): { name: string; version: string } => {\n const atIndex = spec.lastIndexOf(\"@\");\n if (atIndex === -1) {\n return { name: spec, version: \"latest\" };\n }\n\n const name = spec.slice(0, atIndex);\n const version = spec.slice(atIndex + 1);\n\n if (!name || !version) {\n throw new Error(\n `Invalid prompt specification: ${spec}. Use format 'name@version' or just 'name'`,\n );\n }\n\n return { name, version };\n};\n"]}
@@ -0,0 +1,93 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+
3
+ var _chunk2JU376G7js = require('./chunk-2JU376G7.js');
4
+
5
+ // src/cli/utils/init.ts
6
+ var _readline = require('readline'); var readline = _interopRequireWildcard(_readline);
7
+ var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
8
+ var promptUser = (question) => {
9
+ const rl = readline.createInterface({
10
+ input: process.stdin,
11
+ output: process.stdout
12
+ });
13
+ return new Promise((resolve) => {
14
+ rl.question(question, (answer) => {
15
+ rl.close();
16
+ resolve(answer.trim().toLowerCase());
17
+ });
18
+ });
19
+ };
20
+ var initializeProject = async () => {
21
+ console.log(_chalk2.default.blue("Initializing LangWatch prompts project..."));
22
+ const configResult = _chunk2JU376G7js.FileManager.initializePromptsConfig();
23
+ if (configResult.created) {
24
+ console.log(_chalk2.default.green(`\u2713 Created ${_chalk2.default.gray("./prompts.json")}`));
25
+ const shouldAddGitignore = await promptUser(
26
+ _chalk2.default.yellow("Add 'prompts/.materialized' to .gitignore? [Y/n]: ")
27
+ );
28
+ if (shouldAddGitignore === "" || shouldAddGitignore === "y" || shouldAddGitignore === "yes") {
29
+ const gitignoreResult = _chunk2JU376G7js.FileManager.addToGitignore("prompts/.materialized");
30
+ if (gitignoreResult.added) {
31
+ if (gitignoreResult.existed) {
32
+ console.log(_chalk2.default.green(`\u2713 Added ${_chalk2.default.gray("prompts/.materialized")} to existing .gitignore`));
33
+ } else {
34
+ console.log(_chalk2.default.green(`\u2713 Created .gitignore with ${_chalk2.default.gray("prompts/.materialized")}`));
35
+ }
36
+ } else {
37
+ console.log(_chalk2.default.gray(`\u2022 ${_chalk2.default.gray("prompts/.materialized")} already in .gitignore`));
38
+ }
39
+ }
40
+ } else {
41
+ console.log(_chalk2.default.gray(`\u2022 prompts.json already exists`));
42
+ }
43
+ const lockResult = _chunk2JU376G7js.FileManager.initializePromptsLock();
44
+ if (lockResult.created) {
45
+ console.log(_chalk2.default.green(`\u2713 Created ${_chalk2.default.gray("./prompts-lock.json")}`));
46
+ } else {
47
+ console.log(_chalk2.default.gray(`\u2022 prompts-lock.json already exists`));
48
+ }
49
+ _chunk2JU376G7js.FileManager.ensureDirectories();
50
+ console.log(_chalk2.default.green(`\u2713 Created ${_chalk2.default.gray("./prompts/")} directory structure`));
51
+ console.log(_chalk2.default.green("\n\u2728 Project initialized! You can now add prompts with:"));
52
+ console.log(_chalk2.default.gray(" langwatch prompt add <name>"));
53
+ };
54
+ var ensureProjectInitialized = async (shouldPromptForGitignore = true) => {
55
+ const configResult = _chunk2JU376G7js.FileManager.initializePromptsConfig();
56
+ let askedAboutGitignore = false;
57
+ if (configResult.created) {
58
+ console.log(_chalk2.default.green(`\u2713 Created ${_chalk2.default.gray("./prompts.json")}`));
59
+ if (shouldPromptForGitignore) {
60
+ askedAboutGitignore = true;
61
+ const shouldAddGitignore = await promptUser(
62
+ _chalk2.default.yellow("Add 'prompts/.materialized' to .gitignore? [Y/n]: ")
63
+ );
64
+ if (shouldAddGitignore === "" || shouldAddGitignore === "y" || shouldAddGitignore === "yes") {
65
+ const gitignoreResult = _chunk2JU376G7js.FileManager.addToGitignore("prompts/.materialized");
66
+ if (gitignoreResult.added) {
67
+ if (gitignoreResult.existed) {
68
+ console.log(_chalk2.default.green(`\u2713 Added ${_chalk2.default.gray("prompts/.materialized")} to existing .gitignore`));
69
+ } else {
70
+ console.log(_chalk2.default.green(`\u2713 Created .gitignore with ${_chalk2.default.gray("prompts/.materialized")}`));
71
+ }
72
+ } else {
73
+ console.log(_chalk2.default.gray(`\u2022 ${_chalk2.default.gray("prompts/.materialized")} already in .gitignore`));
74
+ }
75
+ }
76
+ }
77
+ }
78
+ const lockResult = _chunk2JU376G7js.FileManager.initializePromptsLock();
79
+ if (lockResult.created) {
80
+ console.log(_chalk2.default.green(`\u2713 Created ${_chalk2.default.gray("./prompts-lock.json")}`));
81
+ }
82
+ _chunk2JU376G7js.FileManager.ensureDirectories();
83
+ return {
84
+ configCreated: configResult.created,
85
+ lockCreated: lockResult.created
86
+ };
87
+ };
88
+
89
+
90
+
91
+
92
+ exports.initializeProject = initializeProject; exports.ensureProjectInitialized = ensureProjectInitialized;
93
+ //# sourceMappingURL=chunk-HJU67C7H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources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AAA;AACK,EAAA;AACkD,IAAA;AACzD,EAAA;AAGqD,EAAA;AAC7B,EAAA;AAC0B,IAAA;AAC3C,EAAA;AACuD,IAAA;AAC9D,EAAA;AAG8B,EAAA;AAC+B,EAAA;AAErC,EAAA;AAC+B,EAAA;AACzD;AAE8I;AAEnF,EAAA;AAC/B,EAAA;AAEA,EAAA;AACyC,IAAA;AAGnC,IAAA;AACN,MAAA;AACW,MAAA;AACkC,QAAA;AACnE,MAAA;AAE+D,MAAA;AACV,QAAA;AACxB,QAAA;AACI,UAAA;AACmB,YAAA;AACzC,UAAA;AACgD,YAAA;AACvD,UAAA;AACK,QAAA;AACkC,UAAA;AACzC,QAAA;AACF,MAAA;AACF,IAAA;AACF,EAAA;AAGqD,EAAA;AAC7B,EAAA;AAC0B,IAAA;AAClD,EAAA;AAG8B,EAAA;AAEvB,EAAA;AACuB,IAAA;AACJ,IAAA;AAC1B,EAAA;AACF;ADnB2E;AACA;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-HJU67C7H.js","sourcesContent":[null,"import * as readline from \"readline\";\nimport chalk from \"chalk\";\nimport { FileManager } from \"./fileManager\";\n\nconst promptUser = (question: string): Promise<string> => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n return new Promise((resolve) => {\n rl.question(question, (answer) => {\n rl.close();\n resolve(answer.trim().toLowerCase());\n });\n });\n};\n\nexport const initializeProject = async (): Promise<void> => {\n console.log(chalk.blue(\"Initializing LangWatch prompts project...\"));\n\n // Initialize prompts.json\n const configResult = FileManager.initializePromptsConfig();\n if (configResult.created) {\n console.log(chalk.green(`✓ Created ${chalk.gray(\"./prompts.json\")}`));\n\n // Ask about .gitignore\n const shouldAddGitignore = await promptUser(\n chalk.yellow(\"Add 'prompts/.materialized' to .gitignore? [Y/n]: \")\n );\n\n if (shouldAddGitignore === \"\" || shouldAddGitignore === \"y\" || shouldAddGitignore === \"yes\") {\n const gitignoreResult = FileManager.addToGitignore(\"prompts/.materialized\");\n if (gitignoreResult.added) {\n if (gitignoreResult.existed) {\n console.log(chalk.green(`✓ Added ${chalk.gray(\"prompts/.materialized\")} to existing .gitignore`));\n } else {\n console.log(chalk.green(`✓ Created .gitignore with ${chalk.gray(\"prompts/.materialized\")}`));\n }\n } else {\n console.log(chalk.gray(`• ${chalk.gray(\"prompts/.materialized\")} already in .gitignore`));\n }\n }\n } else {\n console.log(chalk.gray(`• prompts.json already exists`));\n }\n\n // Initialize lock file\n const lockResult = FileManager.initializePromptsLock();\n if (lockResult.created) {\n console.log(chalk.green(`✓ Created ${chalk.gray(\"./prompts-lock.json\")}`));\n } else {\n console.log(chalk.gray(`• prompts-lock.json already exists`));\n }\n\n // Ensure directories exist\n FileManager.ensureDirectories();\n console.log(chalk.green(`✓ Created ${chalk.gray(\"./prompts/\")} directory structure`));\n\n console.log(chalk.green(\"\\n✨ Project initialized! You can now add prompts with:\"));\n console.log(chalk.gray(\" langwatch prompt add <name>\"));\n};\n\nexport const ensureProjectInitialized = async (shouldPromptForGitignore = true): Promise<{ configCreated: boolean; lockCreated: boolean }> => {\n // Initialize prompts.json\n const configResult = FileManager.initializePromptsConfig();\n let askedAboutGitignore = false;\n\n if (configResult.created) {\n console.log(chalk.green(`✓ Created ${chalk.gray(\"./prompts.json\")}`));\n\n // Ask about .gitignore only if we should prompt and haven't asked yet\n if (shouldPromptForGitignore) {\n askedAboutGitignore = true;\n const shouldAddGitignore = await promptUser(\n chalk.yellow(\"Add 'prompts/.materialized' to .gitignore? [Y/n]: \")\n );\n\n if (shouldAddGitignore === \"\" || shouldAddGitignore === \"y\" || shouldAddGitignore === \"yes\") {\n const gitignoreResult = FileManager.addToGitignore(\"prompts/.materialized\");\n if (gitignoreResult.added) {\n if (gitignoreResult.existed) {\n console.log(chalk.green(`✓ Added ${chalk.gray(\"prompts/.materialized\")} to existing .gitignore`));\n } else {\n console.log(chalk.green(`✓ Created .gitignore with ${chalk.gray(\"prompts/.materialized\")}`));\n }\n } else {\n console.log(chalk.gray(`• ${chalk.gray(\"prompts/.materialized\")} already in .gitignore`));\n }\n }\n }\n }\n\n // Initialize lock file\n const lockResult = FileManager.initializePromptsLock();\n if (lockResult.created) {\n console.log(chalk.green(`✓ Created ${chalk.gray(\"./prompts-lock.json\")}`));\n }\n\n // Ensure directories exist\n FileManager.ensureDirectories();\n\n return {\n configCreated: configResult.created,\n lockCreated: lockResult.created\n };\n};"]}
@@ -0,0 +1,49 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkPCQVQ7SBjs = require('./chunk-PCQVQ7SB.js');
5
+
6
+ // package.json
7
+ var version = "0.3.2";
8
+
9
+ // src/observability/exporters/langwatch-exporter.ts
10
+ var _exportertraceotlphttp = require('@opentelemetry/exporter-trace-otlp-http');
11
+ var LangWatchExporter = class extends _exportertraceotlphttp.OTLPTraceExporter {
12
+ /**
13
+ * Creates a new LangWatchExporter instance.
14
+ *
15
+ * @param opts - Optional configuration options for the exporter
16
+ * @param opts.apiKey - Optional API key for LangWatch authentication. If not provided,
17
+ * will use environment variables or fallback configuration.
18
+ * @param opts.endpoint - Optional custom endpoint URL for LangWatch ingestion.
19
+ * If not provided, will use environment variables or fallback configuration.
20
+ * @param opts.includeAllSpans - Deprecated: This option is deprecated and will be removed in a future version
21
+ * @param opts.debug - Deprecated: This option is deprecated and will be removed in a future version
22
+ */
23
+ constructor(opts) {
24
+ var _a, _b;
25
+ const setApiKey = (_a = opts == null ? void 0 : opts.apiKey) != null ? _a : _chunkPCQVQ7SBjs.getApiKey.call(void 0, );
26
+ const setEndpoint = (_b = opts == null ? void 0 : opts.endpoint) != null ? _b : _chunkPCQVQ7SBjs.getEndpoint.call(void 0, );
27
+ if (opts && opts.includeAllSpans !== void 0) {
28
+ console.warn("[LangWatchExporter] The behavior of `includeAllSpans` is deprecated and will be removed in a future version");
29
+ }
30
+ if (opts && opts.debug !== void 0) {
31
+ console.warn("[LangWatchExporter] The behavior of `debug` is deprecated and will be removed in a future version");
32
+ }
33
+ super({
34
+ headers: {
35
+ "Authorization": `Bearer ${setApiKey}`,
36
+ "X-LangWatch-SDK-Version": version,
37
+ "X-LangWatch-SDK-Language": `typescript-${typeof process !== "undefined" ? "node" : "browser"}`,
38
+ "X-LangWatch-SDK-Name": "langwatch-observability-sdk"
39
+ },
40
+ url: setEndpoint
41
+ });
42
+ }
43
+ };
44
+
45
+
46
+
47
+
48
+ exports.version = version; exports.LangWatchExporter = LangWatchExporter;
49
+ //# sourceMappingURL=chunk-IGHXIIIK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-IGHXIIIK.js","../package.json","../src/observability/exporters/langwatch-exporter.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,sDAA4B;AAC5B;AACA;ACHE,IAAA,QAAA,EAAW,OAAA;ADKb;AACA;AERA,gFAAkC;AAkC3B,IAAM,kBAAA,EAAN,MAAA,QAAgC,yCAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYvD,WAAA,CAAY,IAAA,EAAiC;AA9C/C,IAAA,IAAA,EAAA,EAAA,EAAA;AA+CI,IAAA,MAAM,UAAA,EAAA,CAAY,GAAA,EAAA,KAAA,GAAA,KAAA,EAAA,KAAA,EAAA,EAAA,IAAA,CAAM,MAAA,EAAA,GAAN,KAAA,EAAA,GAAA,EAAgB,wCAAA,CAAU;AAC5C,IAAA,MAAM,YAAA,EAAA,CAAc,GAAA,EAAA,KAAA,GAAA,KAAA,EAAA,KAAA,EAAA,EAAA,IAAA,CAAM,QAAA,EAAA,GAAN,KAAA,EAAA,GAAA,EAAkB,0CAAA,CAAY;AAElD,IAAA,GAAA,CAAI,KAAA,GAAQ,IAAA,CAAK,gBAAA,IAAoB,KAAA,CAAA,EAAQ;AAC3C,MAAA,OAAA,CAAQ,IAAA,CAAK,6GAA6G,CAAA;AAAA,IAC5H;AACA,IAAA,GAAA,CAAI,KAAA,GAAQ,IAAA,CAAK,MAAA,IAAU,KAAA,CAAA,EAAQ;AACjC,MAAA,OAAA,CAAQ,IAAA,CAAK,mGAAmG,CAAA;AAAA,IAClH;AAEA,IAAA,KAAA,CAAM;AAAA,MACJ,OAAA,EAAS;AAAA,QACP,eAAA,EAAiB,CAAA,OAAA,EAAU,SAAS,CAAA,CAAA;AACT,QAAA;AACC,QAAA;AACJ,QAAA;AAC1B,MAAA;AACK,MAAA;AACN,IAAA;AACH,EAAA;AACF;AFxB6C;AACA;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-IGHXIIIK.js","sourcesContent":[null,"{\n \"name\": \"langwatch\",\n \"version\": \"0.3.2\",\n \"description\": \"\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/index.mjs\",\n \"types\": \"dist/index.d.ts\",\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"bin\": {\n \"langwatch\": \"./dist/cli/index.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./evaluation\": {\n \"types\": \"./dist/evaluation/index.d.ts\",\n \"require\": \"./dist/evaluation/index.js\",\n \"import\": \"./dist/evaluation/index.mjs\"\n },\n \"./observability\": {\n \"types\": \"./dist/observability/index.d.ts\",\n \"require\": \"./dist/observability/index.js\",\n \"import\": \"./dist/observability/index.mjs\"\n },\n \"./observability/instrumentation/langchain\": {\n \"types\": \"./dist/observability/instrumentation/langchain/index.d.ts\",\n \"require\": \"./dist/observability/instrumentation/langchain/index.js\",\n \"import\": \"./dist/observability/instrumentation/langchain/index.mjs\"\n },\n \"./prompt\": {\n \"types\": \"./dist/prompt/index.d.ts\",\n \"require\": \"./dist/prompt/index.js\",\n \"import\": \"./dist/prompt/index.mjs\"\n },\n \"./node\": {\n \"types\": \"./dist/client-node.d.ts\",\n \"import\": \"./dist/client-node.mjs\",\n \"require\": \"./dist/client-node.js\"\n },\n \"./browser\": {\n \"types\": \"./dist/client-browser.d.ts\",\n \"import\": \"./dist/client-browser.mjs\",\n \"require\": \"./dist/client-browser.js\"\n }\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/langwatch/langwatch.git\",\n \"directory\": \"typescript-sdk\"\n },\n \"scripts\": {\n \"prepare\": \"./copy-types.sh && pnpm run generate:openapi-types\",\n \"test\": \"vitest\",\n \"prebuild\": \"pnpm run prepare\",\n \"build\": \"tsgo --noEmit && tsup\",\n \"prepublish\": \"pnpm run build\",\n \"generate:openapi-types\": \"npx openapi-typescript ../langwatch/src/app/api/openapiLangWatch.json -o ./src/internal/generated/openapi/api-client.ts\"\n },\n \"author\": \"LangWatch\",\n \"license\": \"MIT\",\n \"engines\": {\n \"node\": \">=20\",\n \"pnpm\": \">=8\"\n },\n \"devDependencies\": {\n \"@eslint/js\": \"^9.32.0\",\n \"@types/debug\": \"^4.1.12\",\n \"@types/js-yaml\": \"^4.0.9\",\n \"@types/node\": \"^24.1.0\",\n \"@typescript/native-preview\": \"7.0.0-dev.20250804.1\",\n \"@vercel/otel\": \"^1.13.0\",\n \"@vitest/coverage-v8\": \"3.2.4\",\n \"esbuild\": \"^0.25.8\",\n \"eslint\": \"^9.32.0\",\n \"fets\": \"^0.8.5\",\n \"nock\": \"^14.0.8\",\n \"ts-to-zod\": \"3.15.0\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.9.2\",\n \"typescript-eslint\": \"^8.38.0\",\n \"vitest\": \"^3.2.4\"\n },\n \"dependencies\": {\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/core\": \"^2.0.1\",\n \"@opentelemetry/exporter-trace-otlp-http\": \"^0.203.0\",\n \"@opentelemetry/resources\": \"^2.0.1\",\n \"@opentelemetry/sdk-trace-base\": \"^2.0.1\",\n \"@opentelemetry/semantic-conventions\": \"^1.36.0\",\n \"@types/prompts\": \"^2.4.9\",\n \"chalk\": \"^4.1.2\",\n \"commander\": \"^12.0.0\",\n \"dotenv\": \"^16.6.1\",\n \"js-yaml\": \"^4.1.0\",\n \"liquidjs\": \"^10.21.1\",\n \"open\": \"^10.2.0\",\n \"openapi-fetch\": \"^0.14.0\",\n \"ora\": \"^5.4.1\",\n \"prompts\": \"^2.4.2\",\n \"xksuid\": \"^0.0.4\",\n \"zod\": \"^4.0.14\"\n },\n \"peerDependencies\": {\n \"@ai-sdk/openai\": \">=2.0.0\",\n \"@langchain/core\": \">=0.3.0\",\n \"@langchain/openai\": \">=0.6.0\",\n \"@langchain/langgraph\": \">=0.4.0\",\n \"@opentelemetry/context-async-hooks\": \">=1.19.0\",\n \"@opentelemetry/context-zone\": \">=1.19.0\",\n \"@opentelemetry/sdk-node\": \">=0.200.0\",\n \"@opentelemetry/sdk-trace-web\": \">=1.19.0\",\n \"langchain\": \">=0.3.0\"\n }\n}\n","import { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-http\";\nimport { version } from \"../../../package.json\";\nimport { getApiKey, getEndpoint } from \"../../client\";\n\nexport interface LangWatchExporterOptions {\n endpoint?: string;\n apiKey?: string;\n includeAllSpans?: boolean;\n debug?: boolean;\n}\n\n/**\n * LangWatchExporter extends the OpenTelemetry OTLP HTTP trace exporter\n * to send trace data to LangWatch with proper authentication and metadata headers.\n *\n * This exporter automatically configures:\n * - Authorization headers using the provided API key or environment variables/fallback\n * - SDK version and language identification headers\n * - Proper endpoint configuration for LangWatch ingestion using provided URL or environment variables/fallback\n *\n * @example\n * ```typescript\n * import { LangWatchExporter } from '@langwatch/observability';\n *\n * // Using environment variables/fallback configuration\n * const exporter = new LangWatchExporter();\n *\n * // Using custom options\n * const exporter = new LangWatchExporter({\n * apiKey: 'your-api-key',\n * endpoint: 'https://custom.langwatch.com'\n * });\n * ```\n */\nexport class LangWatchExporter extends OTLPTraceExporter {\n /**\n * Creates a new LangWatchExporter instance.\n *\n * @param opts - Optional configuration options for the exporter\n * @param opts.apiKey - Optional API key for LangWatch authentication. If not provided,\n * will use environment variables or fallback configuration.\n * @param opts.endpoint - Optional custom endpoint URL for LangWatch ingestion.\n * If not provided, will use environment variables or fallback configuration.\n * @param opts.includeAllSpans - Deprecated: This option is deprecated and will be removed in a future version\n * @param opts.debug - Deprecated: This option is deprecated and will be removed in a future version\n */\n constructor(opts?: LangWatchExporterOptions) {\n const setApiKey = opts?.apiKey ?? getApiKey();\n const setEndpoint = opts?.endpoint ?? getEndpoint();\n\n if (opts && opts.includeAllSpans !== void 0) {\n console.warn(\"[LangWatchExporter] The behavior of `includeAllSpans` is deprecated and will be removed in a future version\");\n }\n if (opts && opts.debug !== void 0) {\n console.warn(\"[LangWatchExporter] The behavior of `debug` is deprecated and will be removed in a future version\");\n }\n\n super({\n headers: {\n \"Authorization\": `Bearer ${setApiKey}`,\n \"X-LangWatch-SDK-Version\": version,\n \"X-LangWatch-SDK-Language\": `typescript-${typeof process !== \"undefined\" ? \"node\" : \"browser\"}`,\n \"X-LangWatch-SDK-Name\": \"langwatch-observability-sdk\",\n },\n url: setEndpoint,\n });\n }\n}\n"]}
@@ -15,10 +15,12 @@ import {
15
15
  LOG_EVNT_GEN_AI_CHOICE,
16
16
  LOG_EVNT_GEN_AI_SYSTEM_MESSAGE,
17
17
  LOG_EVNT_GEN_AI_TOOL_MESSAGE,
18
- LOG_EVNT_GEN_AI_USER_MESSAGE,
18
+ LOG_EVNT_GEN_AI_USER_MESSAGE
19
+ } from "./chunk-UU33HCCZ.mjs";
20
+ import {
19
21
  __spreadProps,
20
22
  __spreadValues
21
- } from "./chunk-4BZATFKJ.mjs";
23
+ } from "./chunk-YN4436PK.mjs";
22
24
 
23
25
  // src/observability/trace.ts
24
26
  import {
@@ -421,4 +423,4 @@ export {
421
423
  spanTypes,
422
424
  createLangWatchSpan
423
425
  };
424
- //# sourceMappingURL=chunk-PMBEK6YE.mjs.map
426
+ //# sourceMappingURL=chunk-J7ICRUU4.mjs.map