langwatch 0.2.0 → 0.3.0-prerelease.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.
- package/LICENSE +7 -0
- package/README.md +268 -1
- package/dist/chunk-4BZATFKJ.mjs +181 -0
- package/dist/chunk-4BZATFKJ.mjs.map +1 -0
- package/dist/chunk-CSC3CMIT.mjs +118 -0
- package/dist/chunk-CSC3CMIT.mjs.map +1 -0
- package/dist/chunk-F63YKTXA.mjs +47 -0
- package/dist/chunk-F63YKTXA.mjs.map +1 -0
- package/dist/chunk-G3AUABT7.js +4 -0
- package/dist/chunk-G3AUABT7.js.map +1 -0
- package/dist/chunk-HPC6Z7J4.js +118 -0
- package/dist/chunk-HPC6Z7J4.js.map +1 -0
- package/dist/chunk-KGDAENGD.js +50 -0
- package/dist/chunk-KGDAENGD.js.map +1 -0
- package/dist/chunk-LD74LVRU.js +47 -0
- package/dist/chunk-LD74LVRU.js.map +1 -0
- package/dist/chunk-OM7VY3XT.mjs +4 -0
- package/dist/chunk-PCQVQ7SB.js +45 -0
- package/dist/chunk-PCQVQ7SB.js.map +1 -0
- package/dist/chunk-PMBEK6YE.mjs +424 -0
- package/dist/chunk-PMBEK6YE.mjs.map +1 -0
- package/dist/chunk-PR3JDWC3.mjs +50 -0
- package/dist/chunk-PR3JDWC3.mjs.map +1 -0
- package/dist/chunk-PTJ6AAI7.js +360 -0
- package/dist/chunk-PTJ6AAI7.js.map +1 -0
- package/dist/chunk-QEWDG5QE.mjs +45 -0
- package/dist/chunk-QEWDG5QE.mjs.map +1 -0
- package/dist/chunk-REUCVT7A.mjs +39 -0
- package/dist/chunk-REUCVT7A.mjs.map +1 -0
- package/dist/chunk-SVJ7SCGB.js +424 -0
- package/dist/chunk-SVJ7SCGB.js.map +1 -0
- package/dist/chunk-VJSOCNPA.js +181 -0
- package/dist/chunk-VJSOCNPA.js.map +1 -0
- package/dist/chunk-WM2GRSRW.js +39 -0
- package/dist/chunk-WM2GRSRW.js.map +1 -0
- package/dist/chunk-Z5J5UI5E.mjs +360 -0
- package/dist/chunk-Z5J5UI5E.mjs.map +1 -0
- package/dist/client-B2HqIKg6.d.ts +51 -0
- package/dist/client-XyCqclCi.d.mts +51 -0
- package/dist/client-browser.d.mts +8 -0
- package/dist/client-browser.d.ts +8 -0
- package/dist/client-browser.js +83 -0
- package/dist/client-browser.js.map +1 -0
- package/dist/client-browser.mjs +83 -0
- package/dist/client-browser.mjs.map +1 -0
- package/dist/client-node.d.mts +8 -0
- package/dist/client-node.d.ts +8 -0
- package/dist/client-node.js +90 -0
- package/dist/client-node.js.map +1 -0
- package/dist/client-node.mjs +90 -0
- package/dist/client-node.mjs.map +1 -0
- package/dist/evaluation/index.d.mts +897 -0
- package/dist/evaluation/index.d.ts +897 -0
- package/dist/evaluation/index.js +13 -0
- package/dist/evaluation/index.js.map +1 -0
- package/dist/evaluation/index.mjs +13 -0
- package/dist/evaluation/index.mjs.map +1 -0
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +64 -0
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +64 -0
- package/dist/index.d.mts +45 -1027
- package/dist/index.d.ts +45 -1027
- package/dist/index.js +11 -27291
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -956
- package/dist/index.mjs.map +1 -1
- package/dist/observability/index.d.mts +260 -0
- package/dist/observability/index.d.ts +260 -0
- package/dist/observability/index.js +20 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/index.mjs +20 -0
- package/dist/observability/index.mjs.map +1 -0
- package/dist/observability/instrumentation/langchain/index.d.mts +40 -0
- package/dist/observability/instrumentation/langchain/index.d.ts +40 -0
- package/dist/observability/instrumentation/langchain/index.js +666 -0
- package/dist/observability/instrumentation/langchain/index.js.map +1 -0
- package/dist/observability/instrumentation/langchain/index.mjs +666 -0
- package/dist/observability/instrumentation/langchain/index.mjs.map +1 -0
- package/dist/prompt/index.d.mts +10 -0
- package/dist/prompt/index.d.ts +10 -0
- package/dist/prompt/index.js +18 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/index.mjs +18 -0
- package/dist/prompt/index.mjs.map +1 -0
- package/dist/prompt-BXJWdbQp.d.mts +1967 -0
- package/dist/prompt-BXJWdbQp.d.ts +1967 -0
- package/dist/record-evaluation-CmxMXa-3.d.mts +25 -0
- package/dist/record-evaluation-CmxMXa-3.d.ts +25 -0
- package/dist/trace-D-bZOuqb.d.mts +622 -0
- package/dist/trace-G2312klE.d.ts +622 -0
- package/package.json +86 -37
- package/.eslintrc.cjs +0 -37
- package/copy-types.sh +0 -17
- package/dist/chunk-LKD2K67J.mjs +0 -717
- package/dist/chunk-LKD2K67J.mjs.map +0 -1
- package/dist/utils-Cv-rUjJ1.d.mts +0 -313
- package/dist/utils-Cv-rUjJ1.d.ts +0 -313
- package/dist/utils.d.mts +0 -2
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -709
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs +0 -11
- package/example/.env.example +0 -12
- package/example/.eslintrc.json +0 -26
- package/example/LICENSE +0 -13
- package/example/README.md +0 -12
- package/example/app/(chat)/chat/[id]/page.tsx +0 -60
- package/example/app/(chat)/layout.tsx +0 -14
- package/example/app/(chat)/page.tsx +0 -27
- package/example/app/actions.ts +0 -156
- package/example/app/globals.css +0 -76
- package/example/app/guardrails/page.tsx +0 -26
- package/example/app/langchain/page.tsx +0 -27
- package/example/app/langchain-rag/page.tsx +0 -28
- package/example/app/late-update/page.tsx +0 -27
- package/example/app/layout.tsx +0 -64
- package/example/app/login/actions.ts +0 -71
- package/example/app/login/page.tsx +0 -18
- package/example/app/manual/page.tsx +0 -27
- package/example/app/new/page.tsx +0 -5
- package/example/app/opengraph-image.png +0 -0
- package/example/app/share/[id]/page.tsx +0 -58
- package/example/app/signup/actions.ts +0 -111
- package/example/app/signup/page.tsx +0 -18
- package/example/app/twitter-image.png +0 -0
- package/example/auth.config.ts +0 -42
- package/example/auth.ts +0 -45
- package/example/components/button-scroll-to-bottom.tsx +0 -36
- package/example/components/chat-history.tsx +0 -49
- package/example/components/chat-list.tsx +0 -52
- package/example/components/chat-message-actions.tsx +0 -40
- package/example/components/chat-message.tsx +0 -80
- package/example/components/chat-panel.tsx +0 -139
- package/example/components/chat-share-dialog.tsx +0 -95
- package/example/components/chat.tsx +0 -84
- package/example/components/clear-history.tsx +0 -75
- package/example/components/empty-screen.tsx +0 -38
- package/example/components/external-link.tsx +0 -29
- package/example/components/footer.tsx +0 -19
- package/example/components/header.tsx +0 -114
- package/example/components/login-button.tsx +0 -42
- package/example/components/login-form.tsx +0 -97
- package/example/components/markdown.tsx +0 -9
- package/example/components/prompt-form.tsx +0 -115
- package/example/components/providers.tsx +0 -17
- package/example/components/sidebar-actions.tsx +0 -125
- package/example/components/sidebar-desktop.tsx +0 -19
- package/example/components/sidebar-footer.tsx +0 -16
- package/example/components/sidebar-item.tsx +0 -124
- package/example/components/sidebar-items.tsx +0 -42
- package/example/components/sidebar-list.tsx +0 -38
- package/example/components/sidebar-mobile.tsx +0 -31
- package/example/components/sidebar-toggle.tsx +0 -24
- package/example/components/sidebar.tsx +0 -21
- package/example/components/signup-form.tsx +0 -95
- package/example/components/stocks/events-skeleton.tsx +0 -31
- package/example/components/stocks/events.tsx +0 -30
- package/example/components/stocks/index.tsx +0 -36
- package/example/components/stocks/message.tsx +0 -134
- package/example/components/stocks/spinner.tsx +0 -16
- package/example/components/stocks/stock-purchase.tsx +0 -146
- package/example/components/stocks/stock-skeleton.tsx +0 -22
- package/example/components/stocks/stock.tsx +0 -210
- package/example/components/stocks/stocks-skeleton.tsx +0 -9
- package/example/components/stocks/stocks.tsx +0 -67
- package/example/components/tailwind-indicator.tsx +0 -14
- package/example/components/theme-toggle.tsx +0 -31
- package/example/components/ui/alert-dialog.tsx +0 -141
- package/example/components/ui/badge.tsx +0 -36
- package/example/components/ui/button.tsx +0 -57
- package/example/components/ui/codeblock.tsx +0 -148
- package/example/components/ui/dialog.tsx +0 -122
- package/example/components/ui/dropdown-menu.tsx +0 -205
- package/example/components/ui/icons.tsx +0 -507
- package/example/components/ui/input.tsx +0 -25
- package/example/components/ui/label.tsx +0 -26
- package/example/components/ui/select.tsx +0 -164
- package/example/components/ui/separator.tsx +0 -31
- package/example/components/ui/sheet.tsx +0 -140
- package/example/components/ui/sonner.tsx +0 -31
- package/example/components/ui/switch.tsx +0 -29
- package/example/components/ui/textarea.tsx +0 -24
- package/example/components/ui/tooltip.tsx +0 -30
- package/example/components/user-menu.tsx +0 -53
- package/example/components.json +0 -17
- package/example/instrumentation.ts +0 -11
- package/example/lib/chat/guardrails.tsx +0 -181
- package/example/lib/chat/langchain-rag.tsx +0 -191
- package/example/lib/chat/langchain.tsx +0 -112
- package/example/lib/chat/late-update.tsx +0 -208
- package/example/lib/chat/manual.tsx +0 -605
- package/example/lib/chat/vercel-ai.tsx +0 -576
- package/example/lib/hooks/use-copy-to-clipboard.tsx +0 -33
- package/example/lib/hooks/use-enter-submit.tsx +0 -23
- package/example/lib/hooks/use-local-storage.ts +0 -24
- package/example/lib/hooks/use-scroll-anchor.tsx +0 -86
- package/example/lib/hooks/use-sidebar.tsx +0 -60
- package/example/lib/hooks/use-streamable-text.ts +0 -25
- package/example/lib/types.ts +0 -41
- package/example/lib/utils.ts +0 -89
- package/example/middleware.ts +0 -8
- package/example/next-env.d.ts +0 -5
- package/example/next.config.js +0 -16
- package/example/package-lock.json +0 -10917
- package/example/package.json +0 -84
- package/example/pnpm-lock.yaml +0 -5712
- package/example/postcss.config.js +0 -6
- package/example/prettier.config.cjs +0 -34
- package/example/public/apple-touch-icon.png +0 -0
- package/example/public/favicon-16x16.png +0 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/next.svg +0 -1
- package/example/public/thirteen.svg +0 -1
- package/example/public/vercel.svg +0 -1
- package/example/tailwind.config.ts +0 -81
- package/example/tsconfig.json +0 -35
- package/src/LangWatchExporter.ts +0 -96
- package/src/evaluations.ts +0 -219
- package/src/index.test.ts +0 -402
- package/src/index.ts +0 -596
- package/src/langchain.ts +0 -557
- package/src/server/types/.gitkeep +0 -0
- package/src/typeUtils.ts +0 -89
- package/src/types.ts +0 -82
- package/src/utils.ts +0 -205
- package/ts-to-zod.config.js +0 -24
- package/tsconfig.json +0 -32
- package/tsup.config.ts +0 -10
- package/vitest.config.ts +0 -8
- /package/dist/{utils.mjs.map → chunk-OM7VY3XT.mjs.map} +0 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkPCQVQ7SBjs = require('./chunk-PCQVQ7SB.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkSVJ7SCGBjs = require('./chunk-SVJ7SCGB.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkVJSOCNPAjs = require('./chunk-VJSOCNPA.js');
|
|
18
|
+
|
|
19
|
+
// src/internal/api/client.ts
|
|
20
|
+
var _openapifetch = require('openapi-fetch'); var _openapifetch2 = _interopRequireDefault(_openapifetch);
|
|
21
|
+
var _zod = require('zod');
|
|
22
|
+
var configSchema = _zod.z.object({
|
|
23
|
+
apiKey: _zod.z.string().min(1, "API key is required"),
|
|
24
|
+
endpoint: _zod.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 : _chunkPCQVQ7SBjs.getApiKey.call(void 0, ),
|
|
29
|
+
endpoint: endpoint != null ? endpoint : _chunkPCQVQ7SBjs.getEndpoint.call(void 0, )
|
|
30
|
+
});
|
|
31
|
+
return _openapifetch2.default.call(void 0, {
|
|
32
|
+
baseUrl: config.endpoint,
|
|
33
|
+
headers: {
|
|
34
|
+
"X-Auth-Token": config.apiKey,
|
|
35
|
+
"Content-Type": "application/json"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/prompt/prompt.ts
|
|
41
|
+
var _liquidjs = require('liquidjs');
|
|
42
|
+
var PromptCompilationError = class extends Error {
|
|
43
|
+
constructor(message, template, originalError) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.template = template;
|
|
46
|
+
this.originalError = originalError;
|
|
47
|
+
this.name = "PromptCompilationError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var liquid = new (0, _liquidjs.Liquid)({
|
|
51
|
+
strictFilters: true
|
|
52
|
+
});
|
|
53
|
+
var Prompt = class {
|
|
54
|
+
constructor(promptData) {
|
|
55
|
+
this.id = promptData.id;
|
|
56
|
+
this.name = promptData.name;
|
|
57
|
+
this.updatedAt = promptData.updatedAt;
|
|
58
|
+
this.version = promptData.version;
|
|
59
|
+
this.versionId = promptData.versionId;
|
|
60
|
+
this.versionCreatedAt = promptData.versionCreatedAt;
|
|
61
|
+
this.model = promptData.model;
|
|
62
|
+
this.prompt = promptData.prompt;
|
|
63
|
+
this.messages = promptData.messages;
|
|
64
|
+
this.response_format = promptData.response_format;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the raw prompt data from the API
|
|
68
|
+
*/
|
|
69
|
+
get raw() {
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Compile the prompt template with provided variables (lenient - missing variables become empty)
|
|
74
|
+
* @param variables - Object containing variable values for template compilation
|
|
75
|
+
* @returns CompiledPrompt instance with compiled content
|
|
76
|
+
*/
|
|
77
|
+
_compile(variables, strict) {
|
|
78
|
+
try {
|
|
79
|
+
const compiledPrompt = this.prompt ? liquid.parseAndRenderSync(this.prompt, variables, {
|
|
80
|
+
strictVariables: strict
|
|
81
|
+
}) : "";
|
|
82
|
+
const compiledMessages = (this.messages || []).map((message) => _chunkVJSOCNPAjs.__spreadProps.call(void 0, _chunkVJSOCNPAjs.__spreadValues.call(void 0, {}, message), {
|
|
83
|
+
content: message.content ? liquid.parseAndRenderSync(message.content, variables, {
|
|
84
|
+
strictVariables: strict
|
|
85
|
+
}) : message.content
|
|
86
|
+
}));
|
|
87
|
+
const compiledData = _chunkVJSOCNPAjs.__spreadProps.call(void 0, _chunkVJSOCNPAjs.__spreadValues.call(void 0, {}, this), {
|
|
88
|
+
prompt: compiledPrompt,
|
|
89
|
+
messages: compiledMessages
|
|
90
|
+
});
|
|
91
|
+
return new CompiledPrompt(compiledData, this);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
const templateStr = this.prompt || JSON.stringify(this.messages);
|
|
94
|
+
throw new PromptCompilationError(
|
|
95
|
+
`Failed to compile prompt template: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
96
|
+
templateStr,
|
|
97
|
+
error
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
compile(variables = {}) {
|
|
102
|
+
return this._compile(variables, false);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Compile with validation - throws error if required variables are missing
|
|
106
|
+
* @param variables - Template variables
|
|
107
|
+
* @returns CompiledPrompt instance with compiled content
|
|
108
|
+
*/
|
|
109
|
+
compileStrict(variables) {
|
|
110
|
+
return this._compile(variables, true);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var CompiledPrompt = class extends Prompt {
|
|
114
|
+
constructor(compiledData, original) {
|
|
115
|
+
super(compiledData);
|
|
116
|
+
this.original = original;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/prompt/service.ts
|
|
121
|
+
var PromptsError = class extends Error {
|
|
122
|
+
constructor(message, operation, originalError) {
|
|
123
|
+
super(message);
|
|
124
|
+
this.operation = operation;
|
|
125
|
+
this.originalError = originalError;
|
|
126
|
+
this.name = "PromptsError";
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var _PromptService = class _PromptService {
|
|
130
|
+
constructor(opts) {
|
|
131
|
+
var _a;
|
|
132
|
+
this.client = (_a = opts == null ? void 0 : opts.client) != null ? _a : createLangWatchApiClient();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets the singleton instance of PromptService.
|
|
136
|
+
* Creates the instance lazily on first access.
|
|
137
|
+
*/
|
|
138
|
+
static getInstance() {
|
|
139
|
+
if (!_PromptService.instance) {
|
|
140
|
+
_PromptService.instance = new _PromptService();
|
|
141
|
+
}
|
|
142
|
+
return _PromptService.instance;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Resets the singleton instance. Primarily used for testing.
|
|
146
|
+
*/
|
|
147
|
+
static resetInstance() {
|
|
148
|
+
_PromptService.instance = null;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Handles API errors by throwing a PromptsError with operation context.
|
|
152
|
+
* @param operation Description of the operation being performed.
|
|
153
|
+
* @param error The error object returned from the API client.
|
|
154
|
+
* @throws {PromptsError}
|
|
155
|
+
*/
|
|
156
|
+
handleApiError(operation, error) {
|
|
157
|
+
var _a, _b;
|
|
158
|
+
const errorMessage = typeof error === "string" ? error : (_b = (_a = error == null ? void 0 : error.error) != null ? _a : error == null ? void 0 : error.message) != null ? _b : "Unknown error occurred";
|
|
159
|
+
throw new PromptsError(
|
|
160
|
+
`Failed to ${operation}: ${errorMessage}`,
|
|
161
|
+
operation,
|
|
162
|
+
error
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Fetches all prompts from the API.
|
|
167
|
+
* @returns Array of Prompt instances.
|
|
168
|
+
* @throws {PromptsError} If the API call fails.
|
|
169
|
+
*/
|
|
170
|
+
async getAll() {
|
|
171
|
+
const { data, error } = await this.client.GET("/api/prompts");
|
|
172
|
+
if (error) this.handleApiError("fetch all prompts", error);
|
|
173
|
+
return data.map((promptData) => new Prompt(promptData));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Fetches a single prompt by its ID.
|
|
177
|
+
* @param id The prompt's unique identifier.
|
|
178
|
+
* @returns The Prompt instance.
|
|
179
|
+
* @throws {PromptsError} If the API call fails.
|
|
180
|
+
*/
|
|
181
|
+
async get(id) {
|
|
182
|
+
const { data, error } = await this.client.GET("/api/prompts/{id}", {
|
|
183
|
+
params: { path: { id } }
|
|
184
|
+
});
|
|
185
|
+
if (error) this.handleApiError(`fetch prompt with ID "${id}"`, error);
|
|
186
|
+
return new Prompt(data);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Creates a new prompt.
|
|
190
|
+
* @param params The prompt creation payload, matching the OpenAPI schema.
|
|
191
|
+
* @returns The created Prompt instance.
|
|
192
|
+
* @throws {PromptsError} If the API call fails.
|
|
193
|
+
*/
|
|
194
|
+
async create(params) {
|
|
195
|
+
const { data, error } = await this.client.POST("/api/prompts", {
|
|
196
|
+
body: params
|
|
197
|
+
});
|
|
198
|
+
if (error) this.handleApiError("create prompt", error);
|
|
199
|
+
return new Prompt(data);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Updates an existing prompt.
|
|
203
|
+
* @param id The prompt's unique identifier.
|
|
204
|
+
* @param params The update payload, matching the OpenAPI schema.
|
|
205
|
+
* @returns The updated Prompt instance.
|
|
206
|
+
* @throws {PromptsError} If the API call fails.
|
|
207
|
+
* @remarks
|
|
208
|
+
* The API does not return the updated prompt directly, so this method fetches it after updating.
|
|
209
|
+
*/
|
|
210
|
+
async update(id, params) {
|
|
211
|
+
const { error } = await this.client.PUT("/api/prompts/{id}", {
|
|
212
|
+
params: { path: { id } },
|
|
213
|
+
body: params
|
|
214
|
+
});
|
|
215
|
+
if (error) this.handleApiError(`update prompt with ID "${id}"`, error);
|
|
216
|
+
return await this.get(id);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Deletes a prompt by its ID.
|
|
220
|
+
* @param id The prompt's unique identifier.
|
|
221
|
+
* @throws {PromptsError} If the API call fails.
|
|
222
|
+
*/
|
|
223
|
+
async delete(id) {
|
|
224
|
+
const { error } = await this.client.DELETE("/api/prompts/{id}", {
|
|
225
|
+
params: { path: { id } }
|
|
226
|
+
});
|
|
227
|
+
if (error) this.handleApiError(`delete prompt with ID "${id}"`, error);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Fetches all versions for a given prompt.
|
|
231
|
+
* @param id The prompt's unique identifier.
|
|
232
|
+
* @throws {PromptsError} If the API call fails.
|
|
233
|
+
*/
|
|
234
|
+
async getVersions(id) {
|
|
235
|
+
var _a;
|
|
236
|
+
const { data, error } = await this.client.GET(
|
|
237
|
+
"/api/prompts/{id}/versions",
|
|
238
|
+
{
|
|
239
|
+
params: { path: { id } }
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
if (error)
|
|
243
|
+
this.handleApiError(`fetch versions for prompt with ID "${id}"`, error);
|
|
244
|
+
const prompts = {};
|
|
245
|
+
const dataTypeCorrected = data;
|
|
246
|
+
for (const version of dataTypeCorrected) {
|
|
247
|
+
prompts[version.id] = new Prompt({
|
|
248
|
+
id: version.configId,
|
|
249
|
+
messages: version.configData.messages,
|
|
250
|
+
model: version.configData.model,
|
|
251
|
+
prompt: version.configData.prompt,
|
|
252
|
+
response_format: null,
|
|
253
|
+
name: `Prompt ${version.configId}@${version.id}`,
|
|
254
|
+
updatedAt: version.createdAt,
|
|
255
|
+
version: (_a = version.configData.version) != null ? _a : 0,
|
|
256
|
+
versionCreatedAt: version.createdAt,
|
|
257
|
+
versionId: version.id
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return prompts;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Creates a new version for a given prompt.
|
|
264
|
+
* @param id The prompt's unique identifier.
|
|
265
|
+
* @param params The version creation payload, matching the OpenAPI schema.
|
|
266
|
+
* @returns The updated Prompt instance.
|
|
267
|
+
* @throws {PromptsError} If the API call fails.
|
|
268
|
+
* @remarks
|
|
269
|
+
* The API does not return the updated prompt directly, so this method fetches it after creation.
|
|
270
|
+
*/
|
|
271
|
+
async createVersion(id, params) {
|
|
272
|
+
const { error } = await this.client.POST("/api/prompts/{id}/versions", {
|
|
273
|
+
params: { path: { id } },
|
|
274
|
+
body: params
|
|
275
|
+
});
|
|
276
|
+
if (error)
|
|
277
|
+
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 = _chunkSVJ7SCGBjs.getLangWatchTracer.call(void 0, "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(_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_ID, id);
|
|
292
|
+
const service = PromptService.getInstance();
|
|
293
|
+
const prompt = await service.get(id);
|
|
294
|
+
if (_chunkPCQVQ7SBjs.canAutomaticallyCaptureOutput.call(void 0, )) {
|
|
295
|
+
span.setOutput(prompt);
|
|
296
|
+
}
|
|
297
|
+
span.setAttributes({
|
|
298
|
+
[_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_ID]: id,
|
|
299
|
+
[_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_VERSION_ID]: prompt.versionId,
|
|
300
|
+
[_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_VERSION_NUMBER]: prompt.version
|
|
301
|
+
});
|
|
302
|
+
if (variables) {
|
|
303
|
+
if (_chunkPCQVQ7SBjs.canAutomaticallyCaptureInput.call(void 0, )) {
|
|
304
|
+
span.setAttribute(
|
|
305
|
+
_chunkVJSOCNPAjs.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(_chunkVJSOCNPAjs.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}`);
|
|
328
|
+
}
|
|
329
|
+
if (_chunkPCQVQ7SBjs.canAutomaticallyCaptureOutput.call(void 0, )) {
|
|
330
|
+
span.setOutput(prompt);
|
|
331
|
+
}
|
|
332
|
+
span.setAttributes({
|
|
333
|
+
[_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_ID]: id,
|
|
334
|
+
[_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_VERSION_ID]: promptVersion.id,
|
|
335
|
+
[_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_VERSION_NUMBER]: promptVersion.version
|
|
336
|
+
});
|
|
337
|
+
if (variables) {
|
|
338
|
+
if (_chunkPCQVQ7SBjs.canAutomaticallyCaptureInput.call(void 0, )) {
|
|
339
|
+
span.setAttribute(
|
|
340
|
+
_chunkVJSOCNPAjs.ATTR_LANGWATCH_PROMPT_VARIABLES,
|
|
341
|
+
JSON.stringify({
|
|
342
|
+
type: "json",
|
|
343
|
+
value: variables
|
|
344
|
+
})
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
return promptVersion.compile(variables);
|
|
348
|
+
}
|
|
349
|
+
return promptVersion;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
exports.PromptCompilationError = PromptCompilationError; exports.Prompt = Prompt; exports.CompiledPrompt = CompiledPrompt; exports.getPrompt = getPrompt; exports.getPromptVersion = getPromptVersion;
|
|
360
|
+
//# sourceMappingURL=chunk-PTJ6AAI7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-PTJ6AAI7.js","../src/internal/api/client.ts","../src/prompt/prompt.ts","../src/prompt/service.ts","../src/prompt/tracer.ts","../src/prompt/get-prompt.ts","../src/prompt/get-prompt-version.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACA;AClBA,yGAAgC;AAEhC,0BAAkB;AAMlB,IAAM,aAAA,EAAe,MAAA,CAAE,MAAA,CAAO;AAAA,EAC5B,MAAA,EAAQ,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAA,EAAG,qBAAqB,CAAA;AAAA,EAC/C,QAAA,EAAU,MAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,8BAA8B;AACzD,CAAC,CAAA;AAEM,SAAS,wBAAA,CAAyB,MAAA,EAA6B,QAAA,EAAoD;AAExH,EAAA,MAAM,OAAA,EAAS,YAAA,CAAa,KAAA,CAAM;AAAA,IAChC,MAAA,EAAQ,OAAA,GAAA,KAAA,EAAA,OAA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C,IAAA;AACd,MAAA;AACvB,IAAA;AAEmB,IAAA;AACsB,MAAA;AACsB,MAAA;AACI,MAAA;AAClE,IAAA;AAEc,IAAA;AACuB,MAAA;AAC7B,QAAA;AACQ,UAAA;AACI,UAAA;AACP,YAAA;AACC,YAAA;AACR,UAAA;AACH,QAAA;AACF,MAAA;AAEsC,MAAA;AACxC,IAAA;AAEO,IAAA;AACR,EAAA;AACH;AN+SuG;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-PTJ6AAI7.js","sourcesContent":[null,"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 { 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 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.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(variables: TemplateVariables, strict: boolean): 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: ${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 {\n createLangWatchApiClient,\n type LangwatchApiClient,\n} from \"../internal/api/client\";\nimport type { paths } from \"../internal/generated/openapi/api-client\";\nimport { Prompt } from \"./prompt\";\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\"];\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\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.\n * @throws {PromptsError} If the API call fails.\n */\n async get(id: string): Promise<Prompt> {\n const { data, error } = await this.client.GET(\"/api/prompts/{id}\", {\n params: { path: { id } },\n });\n if (error) this.handleApiError(`fetch prompt with ID \"${id}\"`, error);\n return new Prompt(data);\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 return await this.get(id);\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(\n id: string,\n ): 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 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 return await this.get(id);\n }\n}\n","import { getLangWatchTracer } from \"../observability/trace\";\n\nexport const tracer = getLangWatchTracer(\"langwatch.prompt\");\n","import { PromptService } from \"./service\";\nimport { CompiledPrompt, Prompt, TemplateVariables } from \"./prompt\";\nimport * as intSemconv from \"../observability/semconv\";\nimport { tracer } from \"./tracer\";\nimport { canAutomaticallyCaptureInput, canAutomaticallyCaptureOutput } from \"../client\";\n\nexport async function getPrompt(id: string, variables: TemplateVariables): Promise<CompiledPrompt>;\nexport async function getPrompt(id: string): Promise<Prompt>;\n\nexport async function getPrompt(id: string, variables?: TemplateVariables): Promise<Prompt | CompiledPrompt> {\n return tracer.withActiveSpan(\"retrieve prompt\", async (span) => {\n span.setType(\"prompt\");\n span.setAttribute(intSemconv.ATTR_LANGWATCH_PROMPT_ID, id);\n\n const service = PromptService.getInstance();\n const prompt = await service.get(id);\n\n if (canAutomaticallyCaptureOutput()) {\n span.setOutput(prompt);\n }\n\n span.setAttributes({\n [intSemconv.ATTR_LANGWATCH_PROMPT_ID]: id,\n [intSemconv.ATTR_LANGWATCH_PROMPT_VERSION_ID]: prompt.versionId,\n [intSemconv.ATTR_LANGWATCH_PROMPT_VERSION_NUMBER]: prompt.version,\n });\n\n if (variables) {\n if (canAutomaticallyCaptureInput()) {\n span.setAttribute(\n intSemconv.ATTR_LANGWATCH_PROMPT_VARIABLES,\n JSON.stringify({\n type: \"json\",\n value: variables,\n }),\n );\n }\n\n return prompt.compile(variables);\n }\n\n return prompt;\n });\n}\n","import { PromptService } from \"./service\";\nimport { CompiledPrompt, Prompt, TemplateVariables } from \"./prompt\";\nimport * as intSemconv from \"../observability/semconv\";\nimport { tracer } from \"./tracer\";\nimport { canAutomaticallyCaptureInput, canAutomaticallyCaptureOutput } from \"../client\";\n\nexport async function getPromptVersion(id: string, versionId: string, variables: TemplateVariables): Promise<CompiledPrompt>;\nexport async function getPromptVersion(id: string, versionId: string): Promise<Prompt>;\n\nexport async function getPromptVersion(id: string, versionId: string, variables?: TemplateVariables): Promise<Prompt | CompiledPrompt> {\n return tracer.withActiveSpan(\"retrieve prompt version\", async (span) => {\n span.setType(\"prompt\");\n span.setAttribute(intSemconv.ATTR_LANGWATCH_PROMPT_ID, id);\n\n const service = PromptService.getInstance();\n const prompt = await service.getVersions(id);\n const promptVersion = prompt[versionId];\n\n if (!promptVersion) {\n throw new Error(`Prompt version ${versionId} not found for prompt ${id}`);\n }\n\n if (canAutomaticallyCaptureOutput()) {\n span.setOutput(prompt);\n }\n\n span.setAttributes({\n [intSemconv.ATTR_LANGWATCH_PROMPT_ID]: id,\n [intSemconv.ATTR_LANGWATCH_PROMPT_VERSION_ID]: promptVersion.id,\n [intSemconv.ATTR_LANGWATCH_PROMPT_VERSION_NUMBER]: promptVersion.version,\n });\n\n if (variables) {\n if (canAutomaticallyCaptureInput()) {\n span.setAttribute(\n intSemconv.ATTR_LANGWATCH_PROMPT_VARIABLES,\n JSON.stringify({\n type: \"json\",\n value: variables,\n }),\n );\n }\n\n return promptVersion.compile(variables);\n }\n\n return promptVersion;\n });\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var _a, _b;
|
|
3
|
+
var config = {
|
|
4
|
+
apiKey: (_a = process.env.LANGWATCH_API_KEY) != null ? _a : "",
|
|
5
|
+
endpoint: (_b = process.env.LANGWATCH_ENDPOINT) != null ? _b : "https://app.langwatch.ai",
|
|
6
|
+
setupCalled: false,
|
|
7
|
+
skipOpenTelemetrySetup: false,
|
|
8
|
+
disableAutomaticInputCapture: false,
|
|
9
|
+
disableAutomaticOutputCapture: false,
|
|
10
|
+
baseAttributes: {}
|
|
11
|
+
};
|
|
12
|
+
function setConfig(options) {
|
|
13
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
14
|
+
config.setupCalled = true;
|
|
15
|
+
config.apiKey = options.apiKey !== void 0 ? options.apiKey : (_a2 = process.env.LANGWATCH_API_KEY) != null ? _a2 : config.apiKey;
|
|
16
|
+
config.endpoint = options.endpoint !== void 0 ? options.endpoint : (_b2 = process.env.LANGWATCH_ENDPOINT) != null ? _b2 : config.endpoint;
|
|
17
|
+
if (config.apiKey === "") {
|
|
18
|
+
console.warn("[langwatch setup] No API key provided. Please set the LANGWATCH_API_KEY environment variable or pass it to the setup function. The SDK will perform no operations.");
|
|
19
|
+
}
|
|
20
|
+
config.skipOpenTelemetrySetup = (_c = options.skipOpenTelemetrySetup) != null ? _c : config.skipOpenTelemetrySetup;
|
|
21
|
+
config.disableAutomaticInputCapture = (_d = options.disableAutomaticInputCapture) != null ? _d : config.disableAutomaticInputCapture;
|
|
22
|
+
config.disableAutomaticOutputCapture = (_e = options.disableAutomaticOutputCapture) != null ? _e : config.disableAutomaticOutputCapture;
|
|
23
|
+
config.baseAttributes = (_f = options.baseAttributes) != null ? _f : config.baseAttributes;
|
|
24
|
+
}
|
|
25
|
+
function getApiKey() {
|
|
26
|
+
return config.apiKey;
|
|
27
|
+
}
|
|
28
|
+
function getEndpoint() {
|
|
29
|
+
return config.endpoint;
|
|
30
|
+
}
|
|
31
|
+
function canAutomaticallyCaptureInput() {
|
|
32
|
+
return !config.disableAutomaticInputCapture;
|
|
33
|
+
}
|
|
34
|
+
function canAutomaticallyCaptureOutput() {
|
|
35
|
+
return !config.disableAutomaticOutputCapture;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
setConfig,
|
|
40
|
+
getApiKey,
|
|
41
|
+
getEndpoint,
|
|
42
|
+
canAutomaticallyCaptureInput,
|
|
43
|
+
canAutomaticallyCaptureOutput
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=chunk-QEWDG5QE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport { SpanProcessingExcludeRule } from \"./observability\";\nimport { Attributes } from \"@opentelemetry/api\";\n\nexport interface SetupOptions {\n /**\n * The API key to use for the LangWatch API.\n */\n apiKey?: string;\n\n /**\n * The endpoint to use for the LangWatch API.\n */\n endpoint?: string;\n\n /**\n * The span processors to use for the OpenTelemetry SDK.\n *\n * If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has\n * been initialized.\n */\n otelSpanProcessors?: SpanProcessor[];\n\n /**\n * The span processing exclude rules to use for the OpenTelemetry SDK.\n *\n * If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has\n * been initialized.\n *\n * If you are using the `otelSpanProcessors` option, then these will be ignored.\n */\n otelSpanProcessingExcludeRules?: SpanProcessingExcludeRule[];\n\n /**\n * Whether to skip the automatic setup of the OpenTelemetry SDK. If this is set, then\n * the LangWatch SDK will not attempt to setup the OpenTelemetry SDK. You will need to\n * setup the OpenTelemetry yourself, and ensure that a SpanProcessor is added to the\n * OpenTelemetry SDK that will send traces to the LangWatch API.\n */\n skipOpenTelemetrySetup?: boolean;\n\n /**\n * Whether to disable the automatic capture of input.\n */\n disableAutomaticInputCapture?: boolean;\n\n /**\n * Whether to disable the automatic capture of output.\n */\n disableAutomaticOutputCapture?: boolean;\n\n /**\n * The base attributes to use for the OpenTelemetry SDK.\n */\n baseAttributes?: Attributes;\n}\n\ninterface InternalConfig {\n apiKey: string;\n endpoint: string;\n setupCalled: boolean;\n skipOpenTelemetrySetup: boolean;\n disableAutomaticInputCapture: boolean;\n disableAutomaticOutputCapture: boolean;\n\n baseAttributes: Attributes;\n}\n\nconst config: InternalConfig = {\n apiKey: process.env.LANGWATCH_API_KEY ?? \"\",\n endpoint: process.env.LANGWATCH_ENDPOINT ?? \"https://app.langwatch.ai\",\n setupCalled: false,\n skipOpenTelemetrySetup: false,\n disableAutomaticInputCapture: false,\n disableAutomaticOutputCapture: false,\n baseAttributes: {},\n};\n\nexport function setConfig(options: SetupOptions) {\n config.setupCalled = true;\n\n config.apiKey = options.apiKey !== void 0\n ? options.apiKey\n : (process.env.LANGWATCH_API_KEY ?? config.apiKey);\n\n config.endpoint = options.endpoint !== void 0\n ? options.endpoint\n : (process.env.LANGWATCH_ENDPOINT ?? config.endpoint);\n\n if (config.apiKey === \"\") {\n console.warn(\"[langwatch setup] No API key provided. Please set the LANGWATCH_API_KEY environment variable or pass it to the setup function. The SDK will perform no operations.\");\n }\n\n config.skipOpenTelemetrySetup = options.skipOpenTelemetrySetup ?? config.skipOpenTelemetrySetup;\n config.disableAutomaticInputCapture = options.disableAutomaticInputCapture ?? config.disableAutomaticInputCapture;\n config.disableAutomaticOutputCapture = options.disableAutomaticOutputCapture ?? config.disableAutomaticOutputCapture;\n\n config.baseAttributes = options.baseAttributes ?? config.baseAttributes;\n}\n\nexport function getApiKey(): string {\n return config.apiKey;\n}\n\nexport function getEndpoint(): string {\n return config.endpoint;\n}\n\nexport function canAutomaticallyCaptureInput(): boolean {\n return !config.disableAutomaticInputCapture;\n}\n\nexport function canAutomaticallyCaptureOutput(): boolean {\n return !config.disableAutomaticOutputCapture;\n}\n\nexport function isSetupCalled(): boolean {\n return config.setupCalled;\n}\n"],"mappings":";AAAA;AAoEA,IAAM,SAAyB;AAAA,EAC7B,SAAQ,aAAQ,IAAI,sBAAZ,YAAiC;AAAA,EACzC,WAAU,aAAQ,IAAI,uBAAZ,YAAkC;AAAA,EAC5C,aAAa;AAAA,EACb,wBAAwB;AAAA,EACxB,8BAA8B;AAAA,EAC9B,+BAA+B;AAAA,EAC/B,gBAAgB,CAAC;AACnB;AAEO,SAAS,UAAU,SAAuB;AA9EjD,MAAAA,KAAAC,KAAA;AA+EE,SAAO,cAAc;AAErB,SAAO,SAAS,QAAQ,WAAW,SAC/B,QAAQ,UACPD,MAAA,QAAQ,IAAI,sBAAZ,OAAAA,MAAiC,OAAO;AAE7C,SAAO,WAAW,QAAQ,aAAa,SACnC,QAAQ,YACPC,MAAA,QAAQ,IAAI,uBAAZ,OAAAA,MAAkC,OAAO;AAE9C,MAAI,OAAO,WAAW,IAAI;AACxB,YAAQ,KAAK,oKAAoK;AAAA,EACnL;AAEA,SAAO,0BAAyB,aAAQ,2BAAR,YAAkC,OAAO;AACzE,SAAO,gCAA+B,aAAQ,iCAAR,YAAwC,OAAO;AACrF,SAAO,iCAAgC,aAAQ,kCAAR,YAAyC,OAAO;AAEvF,SAAO,kBAAiB,aAAQ,mBAAR,YAA0B,OAAO;AAC3D;AAEO,SAAS,YAAoB;AAClC,SAAO,OAAO;AAChB;AAEO,SAAS,cAAsB;AACpC,SAAO,OAAO;AAChB;AAEO,SAAS,+BAAwC;AACtD,SAAO,CAAC,OAAO;AACjB;AAEO,SAAS,gCAAyC;AACvD,SAAO,CAAC,OAAO;AACjB;","names":["_a","_b"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getApiKey,
|
|
3
|
+
getEndpoint
|
|
4
|
+
} from "./chunk-QEWDG5QE.mjs";
|
|
5
|
+
|
|
6
|
+
// package.json
|
|
7
|
+
var version = "0.3.0-prerelease.2";
|
|
8
|
+
|
|
9
|
+
// src/observability/exporters/langwatch-exporter.ts
|
|
10
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
11
|
+
var LangWatchExporter = class extends OTLPTraceExporter {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new LangWatchExporter instance.
|
|
14
|
+
*
|
|
15
|
+
* @param apiKey - Optional API key for LangWatch authentication. If not provided,
|
|
16
|
+
* will use environment variables or fallback configuration.
|
|
17
|
+
* @param endpointURL - Optional custom endpoint URL for LangWatch ingestion.
|
|
18
|
+
* If not provided, will use environment variables or fallback configuration.
|
|
19
|
+
*/
|
|
20
|
+
constructor(apiKey, endpointURL) {
|
|
21
|
+
const setApiKey = apiKey != null ? apiKey : getApiKey();
|
|
22
|
+
const setEndpoint = endpointURL != null ? endpointURL : getEndpoint();
|
|
23
|
+
super({
|
|
24
|
+
headers: {
|
|
25
|
+
"Authorization": `Bearer ${setApiKey}`,
|
|
26
|
+
"X-LangWatch-SDK-Version": version,
|
|
27
|
+
"X-LangWatch-SDK-Language": `typescript-${typeof process !== "undefined" ? "node" : "browser"}`,
|
|
28
|
+
"X-LangWatch-SDK-Name": "langwatch-observability-sdk"
|
|
29
|
+
},
|
|
30
|
+
url: setEndpoint
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
version,
|
|
37
|
+
LangWatchExporter
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-REUCVT7A.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/observability/exporters/langwatch-exporter.ts"],"sourcesContent":["{\n \"name\": \"langwatch\",\n \"version\": \"0.3.0-prerelease.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 \"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/node\": \"^24.1.0\",\n \"@typescript/native-preview\": \"7.0.0-dev.20250804.1\",\n \"@vitest/coverage-v8\": \"3.2.4\",\n \"dotenv\": \"^17.2.1\",\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 \"liquidjs\": \"^10.21.1\",\n \"openapi-fetch\": \"^0.14.0\",\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.66\",\n \"@langchain/openai\": \"^0.6.3\",\n \"@langchain/langgraph\": \"^0.4.2\",\n \"@opentelemetry/context-async-hooks\": \"^2.0.1\",\n \"@opentelemetry/context-zone\": \"^2.0.1\",\n \"@opentelemetry/sdk-node\": \"^0.203.0\",\n \"@opentelemetry/sdk-trace-web\": \"^2.0.1\",\n \"@vercel/otel\": \"^1.13.0\",\n \"langchain\": \"^0.3.30\"\n }\n}\n","import { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-http\";\nimport { version } from \"../../../package.json\";\nimport { getApiKey, getEndpoint } from \"../../client\";\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 API key and endpoint\n *\n * // With environment variables/fallback configuration\n * const exporter = new LangWatchExporter();\n *\n * // With custom API key and endpoint\n * const exporter = new LangWatchExporter('api-key', 'https://custom.langwatch.com');\n * ```\n */\nexport class LangWatchExporter extends OTLPTraceExporter {\n /**\n * Creates a new LangWatchExporter instance.\n *\n * @param apiKey - Optional API key for LangWatch authentication. If not provided,\n * will use environment variables or fallback configuration.\n * @param endpointURL - Optional custom endpoint URL for LangWatch ingestion.\n * If not provided, will use environment variables or fallback configuration.\n */\n constructor(apiKey?: string, endpointURL?: string) {\n const setApiKey = apiKey ?? getApiKey();\n const setEndpoint = endpointURL ?? getEndpoint();\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"],"mappings":";;;;;;AAEE,cAAW;;;ACFb,SAAS,yBAAyB;AA6B3B,IAAM,oBAAN,cAAgC,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvD,YAAY,QAAiB,aAAsB;AACjD,UAAM,YAAY,0BAAU,UAAU;AACtC,UAAM,cAAc,oCAAe,YAAY;AAE/C,UAAM;AAAA,MACJ,SAAS;AAAA,QACP,iBAAiB,UAAU,SAAS;AAAA,QACpC,2BAA2B;AAAA,QAC3B,4BAA4B,cAAc,OAAO,YAAY,cAAc,SAAS,SAAS;AAAA,QAC7F,wBAAwB;AAAA,MAC1B;AAAA,MACA,KAAK;AAAA,IACP,CAAC;AAAA,EACH;AACF;","names":[]}
|