langwatch 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{add-4WXEWG5H.js → add-CGTO6GC2.js} +28 -32
- package/dist/add-CGTO6GC2.js.map +1 -0
- package/dist/{add-D2WVVKIP.mjs → add-XCI65PVN.mjs} +14 -18
- package/dist/add-XCI65PVN.mjs.map +1 -0
- package/dist/{chunk-P4SQTYGN.js → chunk-2GYC6KEA.js} +32 -32
- package/dist/{chunk-P4SQTYGN.js.map → chunk-2GYC6KEA.js.map} +1 -1
- package/dist/{chunk-CAZONSXV.js → chunk-36XAYVMC.js} +186 -76
- package/dist/chunk-36XAYVMC.js.map +1 -0
- package/dist/{chunk-ZIULPOMQ.mjs → chunk-3P4ROGZJ.mjs} +4 -4
- package/dist/{chunk-DLJO7AK5.mjs → chunk-AD7QRYIJ.mjs} +2 -2
- package/dist/{chunk-DISMHYXC.js → chunk-CKIZDPIJ.js} +24 -22
- package/dist/chunk-CKIZDPIJ.js.map +1 -0
- package/dist/{chunk-7OZKH5K2.js → chunk-DZH6SY3Z.js} +10 -10
- package/dist/{chunk-7OZKH5K2.js.map → chunk-DZH6SY3Z.js.map} +1 -1
- package/dist/{chunk-N2V6J3U2.mjs → chunk-FEL5FLHA.mjs} +2 -2
- package/dist/{chunk-H5PON53W.mjs → chunk-GAFUPYJ3.mjs} +334 -143
- package/dist/chunk-GAFUPYJ3.mjs.map +1 -0
- package/dist/{chunk-SVXNUWZI.js → chunk-HVW45GST.js} +345 -154
- package/dist/chunk-HVW45GST.js.map +1 -0
- package/dist/{chunk-YNQ44U6D.mjs → chunk-I2SOBPAF.mjs} +23 -21
- package/dist/chunk-I2SOBPAF.mjs.map +1 -0
- package/dist/{chunk-ECOC36EA.js → chunk-J7B7BNDN.js} +11 -11
- package/dist/{chunk-ECOC36EA.js.map → chunk-J7B7BNDN.js.map} +1 -1
- package/dist/{chunk-QZGTM76F.mjs → chunk-JPWKINZP.mjs} +2 -2
- package/dist/{chunk-OXBO24RB.js → chunk-OHM7JUMR.js} +15 -2
- package/dist/chunk-OHM7JUMR.js.map +1 -0
- package/dist/chunk-PYVDTUA6.mjs +352 -0
- package/dist/chunk-PYVDTUA6.mjs.map +1 -0
- package/dist/{chunk-YH5TIVK2.js → chunk-SNDTNU3T.js} +2 -2
- package/dist/{chunk-YH5TIVK2.js.map → chunk-SNDTNU3T.js.map} +1 -1
- package/dist/{chunk-CU3443HD.mjs → chunk-URTD2WOC.mjs} +14 -1
- package/dist/{chunk-YKFTFYKK.mjs → chunk-WOBPYIKO.mjs} +2 -2
- package/dist/chunk-WOBPYIKO.mjs.map +1 -0
- package/dist/{chunk-QCYYSMCU.js → chunk-Z3NTWVVA.js} +2 -2
- package/dist/chunk-Z3NTWVVA.js.map +1 -0
- package/dist/cli/index.js +8 -8
- package/dist/cli/index.mjs +8 -8
- package/dist/{create-OQEMO4MU.mjs → create-LXQB4EFB.mjs} +4 -5
- package/dist/{create-OQEMO4MU.mjs.map → create-LXQB4EFB.mjs.map} +1 -1
- package/dist/{create-4LG4N2A4.js → create-S5RDGF3H.js} +9 -10
- package/dist/create-S5RDGF3H.js.map +1 -0
- package/dist/{implementation-BIlL6-SW.d.ts → implementation-DsHp9FYU.d.ts} +1 -1
- package/dist/{implementation-fAgqv8OM.d.mts → implementation-nE9dgTwc.d.mts} +1 -1
- package/dist/{index-DTEZr0Jn.d.mts → index-D7rKIGrO.d.mts} +12 -12
- package/dist/{index-DTEZr0Jn.d.ts → index-D7rKIGrO.d.ts} +12 -12
- package/dist/index.d.mts +256 -11
- package/dist/index.d.ts +256 -11
- package/dist/index.js +135 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -10
- package/dist/index.mjs.map +1 -1
- package/dist/{init-MQXXHCNT.mjs → init-T4YDPHBA.mjs} +4 -5
- package/dist/{init-MQXXHCNT.mjs.map → init-T4YDPHBA.mjs.map} +1 -1
- package/dist/init-UADBKUJU.js +15 -0
- package/dist/init-UADBKUJU.js.map +1 -0
- package/dist/{list-GIAXAAH5.js → list-GRKVAGJS.js} +14 -15
- package/dist/list-GRKVAGJS.js.map +1 -0
- package/dist/{list-PFWV7IU6.mjs → list-XHXVFN24.mjs} +13 -14
- package/dist/list-XHXVFN24.mjs.map +1 -0
- package/dist/{login-3STX2FAO.js → login-4GWM5I6F.js} +4 -4
- package/dist/{login-3STX2FAO.js.map → login-4GWM5I6F.js.map} +1 -1
- package/dist/{login-BYLXS23I.mjs → login-EKE7SFN3.mjs} +3 -3
- package/dist/observability-sdk/index.d.mts +4 -3
- package/dist/observability-sdk/index.d.ts +4 -3
- package/dist/observability-sdk/index.js +7 -7
- package/dist/observability-sdk/index.mjs +6 -6
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +2 -1
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +2 -1
- package/dist/observability-sdk/instrumentation/langchain/index.js +19 -19
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +3 -3
- package/dist/observability-sdk/setup/node/index.d.mts +1 -1
- package/dist/observability-sdk/setup/node/index.d.ts +1 -1
- package/dist/observability-sdk/setup/node/index.js +15 -15
- package/dist/observability-sdk/setup/node/index.mjs +4 -4
- package/dist/{remove-U3PILQDV.js → remove-7EXB2Z6R.js} +17 -18
- package/dist/remove-7EXB2Z6R.js.map +1 -0
- package/dist/{remove-FTF3EBYV.mjs → remove-W44FQ5MF.mjs} +9 -10
- package/dist/{remove-FTF3EBYV.mjs.map → remove-W44FQ5MF.mjs.map} +1 -1
- package/dist/{sync-T3T22GVZ.js → sync-V7WRMNJV.js} +31 -35
- package/dist/sync-V7WRMNJV.js.map +1 -0
- package/dist/{sync-FOW7DHAH.mjs → sync-XGFABFAW.mjs} +16 -20
- package/dist/sync-XGFABFAW.mjs.map +1 -0
- package/dist/{types-DyUmlaDx.d.ts → types-B9772cUR.d.ts} +98 -29
- package/dist/{types-jrEEZt9d.d.mts → types-DbPAi4US.d.mts} +98 -29
- package/package.json +4 -3
- package/dist/add-4WXEWG5H.js.map +0 -1
- package/dist/add-D2WVVKIP.mjs.map +0 -1
- package/dist/chunk-CAZONSXV.js.map +0 -1
- package/dist/chunk-CKVDNVFL.mjs +0 -242
- package/dist/chunk-CKVDNVFL.mjs.map +0 -1
- package/dist/chunk-DISMHYXC.js.map +0 -1
- package/dist/chunk-DSIQSULK.js +0 -152
- package/dist/chunk-DSIQSULK.js.map +0 -1
- package/dist/chunk-H5PON53W.mjs.map +0 -1
- package/dist/chunk-OXBO24RB.js.map +0 -1
- package/dist/chunk-QCYYSMCU.js.map +0 -1
- package/dist/chunk-R6FBJN7K.js +0 -115
- package/dist/chunk-R6FBJN7K.js.map +0 -1
- package/dist/chunk-SVXNUWZI.js.map +0 -1
- package/dist/chunk-V5M3HUBV.mjs +0 -115
- package/dist/chunk-V5M3HUBV.mjs.map +0 -1
- package/dist/chunk-YEGQXDTE.mjs +0 -152
- package/dist/chunk-YEGQXDTE.mjs.map +0 -1
- package/dist/chunk-YKFTFYKK.mjs.map +0 -1
- package/dist/chunk-YNQ44U6D.mjs.map +0 -1
- package/dist/create-4LG4N2A4.js.map +0 -1
- package/dist/init-EKNL2SQE.js +0 -16
- package/dist/init-EKNL2SQE.js.map +0 -1
- package/dist/list-GIAXAAH5.js.map +0 -1
- package/dist/list-PFWV7IU6.mjs.map +0 -1
- package/dist/remove-U3PILQDV.js.map +0 -1
- package/dist/sync-FOW7DHAH.mjs.map +0 -1
- package/dist/sync-T3T22GVZ.js.map +0 -1
- /package/dist/{chunk-ZIULPOMQ.mjs.map → chunk-3P4ROGZJ.mjs.map} +0 -0
- /package/dist/{chunk-DLJO7AK5.mjs.map → chunk-AD7QRYIJ.mjs.map} +0 -0
- /package/dist/{chunk-N2V6J3U2.mjs.map → chunk-FEL5FLHA.mjs.map} +0 -0
- /package/dist/{chunk-QZGTM76F.mjs.map → chunk-JPWKINZP.mjs.map} +0 -0
- /package/dist/{chunk-CU3443HD.mjs.map → chunk-URTD2WOC.mjs.map} +0 -0
- /package/dist/{login-BYLXS23I.mjs.map → login-EKE7SFN3.mjs.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { L as Logger, C as ConsoleLogger, N as NoOpLogger } from './index-
|
|
2
|
-
export { F as FilterableBatchSpanProcessor, L as LangWatchExporter, S as SpanProcessingExcludeRule, g as getLangWatchLogger, d as getLangWatchTracer } from './implementation-
|
|
1
|
+
import { L as Logger, C as ConsoleLogger, N as NoOpLogger } from './index-D7rKIGrO.js';
|
|
2
|
+
export { F as FilterableBatchSpanProcessor, L as LangWatchExporter, S as SpanProcessingExcludeRule, g as getLangWatchLogger, d as getLangWatchTracer } from './implementation-DsHp9FYU.js';
|
|
3
3
|
export { l as attributes } from './types-DRiQaKFG.js';
|
|
4
|
-
import { p as paths, P as PromptResponse, g as Prompt } from './types-
|
|
4
|
+
import { p as paths, P as PromptResponse, g as CreatePromptBody, U as UpdatePromptBody, h as PromptData, i as Prompt } from './types-B9772cUR.js';
|
|
5
5
|
import openApiCreateClient from 'openapi-fetch';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
import '@opentelemetry/sdk-trace-base';
|
|
7
8
|
import '@opentelemetry/exporter-trace-otlp-http';
|
|
8
9
|
import '@opentelemetry/api-logs';
|
|
@@ -10,16 +11,20 @@ import '@opentelemetry/api';
|
|
|
10
11
|
import '@opentelemetry/semantic-conventions';
|
|
11
12
|
import '@opentelemetry/semantic-conventions/incubating';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new LangWatch API client.
|
|
16
|
+
* @param apiKey - The API key to use for authentication. Defaults to LANGWATCH_API_KEY environment variable.
|
|
17
|
+
* @param endpoint - The endpoint to use for the API client. Defaults to LANGWATCH_ENDPOINT environment variable or internal DEFAULT_ENDPOINT.
|
|
18
|
+
* @returns A new LangWatch API client.
|
|
19
|
+
*/
|
|
20
|
+
declare const createLangWatchApiClient: (apiKey?: string, endpoint?: string) => openApiCreateClient.Client<paths, `${string}/${string}`>;
|
|
21
|
+
type LangwatchApiClient = ReturnType<typeof createLangWatchApiClient>;
|
|
14
22
|
|
|
15
23
|
interface InternalConfig {
|
|
16
24
|
langwatchApiClient: LangwatchApiClient;
|
|
17
25
|
logger: Logger;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
type CreatePromptBody = NonNullable<paths["/api/prompts"]["post"]["requestBody"]>["content"]["application/json"];
|
|
21
|
-
type UpdatePromptBody = NonNullable<paths["/api/prompts/{id}"]["put"]["requestBody"]>["content"]["application/json"];
|
|
22
|
-
|
|
23
28
|
type SyncAction = "created" | "updated" | "conflict" | "up_to_date";
|
|
24
29
|
type ConfigData = NonNullable<paths["/api/prompts/{id}/sync"]["post"]["requestBody"]>["content"]["application/json"]["configData"];
|
|
25
30
|
interface SyncResult {
|
|
@@ -32,15 +37,255 @@ interface SyncResult {
|
|
|
32
37
|
remoteConfigData: ConfigData;
|
|
33
38
|
};
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Service for managing prompt resources via the Langwatch API.
|
|
42
|
+
* Constructor creates a proxy that wraps the service and traces all methods.
|
|
43
|
+
*
|
|
44
|
+
* Responsibilities:
|
|
45
|
+
* - CRUD operations for prompts
|
|
46
|
+
* - Creating prompt versions
|
|
47
|
+
* - Error handling with contextual information
|
|
48
|
+
*
|
|
49
|
+
* All methods return raw PromptResponse data from the API.
|
|
50
|
+
*/
|
|
51
|
+
declare class PromptsApiService {
|
|
52
|
+
private readonly apiClient;
|
|
53
|
+
constructor(config?: Pick<InternalConfig, "langwatchApiClient">);
|
|
54
|
+
/**
|
|
55
|
+
* Handles API errors by throwing a PromptsError with operation context.
|
|
56
|
+
* @param operation Description of the operation being performed.
|
|
57
|
+
* @param error The error object returned from the API client.
|
|
58
|
+
* @throws {PromptsError}
|
|
59
|
+
*/
|
|
60
|
+
private handleApiError;
|
|
61
|
+
/**
|
|
62
|
+
* Fetches all prompts from the API.
|
|
63
|
+
* @returns Array of raw PromptResponse data.
|
|
64
|
+
* @throws {PromptsError} If the API call fails.
|
|
65
|
+
*/
|
|
66
|
+
getAll(): Promise<PromptResponse[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Fetches a single prompt by its ID.
|
|
69
|
+
* @param id The prompt's unique identifier.
|
|
70
|
+
* @returns Raw PromptResponse data.
|
|
71
|
+
* @throws {PromptsError} If the API call fails.
|
|
72
|
+
*/
|
|
73
|
+
get: (id: string, options?: {
|
|
74
|
+
version?: string;
|
|
75
|
+
}) => Promise<PromptResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Validates if a prompt exists.
|
|
78
|
+
* @param id The prompt's unique identifier.
|
|
79
|
+
* @returns True if prompt exists, false otherwise.
|
|
80
|
+
* @throws {PromptsError} If the API call fails (not 404).
|
|
81
|
+
*/
|
|
82
|
+
exists(id: string): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new prompt.
|
|
85
|
+
* @param params The prompt creation payload, matching the OpenAPI schema.
|
|
86
|
+
* @returns Raw PromptResponse data of the created prompt.
|
|
87
|
+
* @throws {PromptsError} If the API call fails.
|
|
88
|
+
*/
|
|
89
|
+
create(params: CreatePromptBody): Promise<PromptResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Updates an existing prompt.
|
|
92
|
+
* @param id The prompt's unique identifier.
|
|
93
|
+
* @param params The update payload, matching the OpenAPI schema.
|
|
94
|
+
* @returns Raw PromptResponse data of the updated prompt.
|
|
95
|
+
* @throws {PromptsError} If the API call fails.
|
|
96
|
+
*/
|
|
97
|
+
update(id: string, params: UpdatePromptBody): Promise<PromptResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* Deletes a prompt by its ID.
|
|
100
|
+
* @param id The prompt's unique identifier.
|
|
101
|
+
* @throws {PromptsError} If the API call fails.
|
|
102
|
+
*/
|
|
103
|
+
delete(id: string): Promise<{
|
|
104
|
+
success: boolean;
|
|
105
|
+
}>;
|
|
106
|
+
/**
|
|
107
|
+
* Fetches all versions for a given prompt.
|
|
108
|
+
* @param id The prompt's unique identifier.
|
|
109
|
+
* @returns Array of raw PromptResponse data for each version.
|
|
110
|
+
* @throws {PromptsError} If the API call fails.
|
|
111
|
+
*/
|
|
112
|
+
getVersions(id: string): Promise<PromptResponse[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Upserts a prompt with local configuration - creates if doesn't exist, updates version if exists.
|
|
115
|
+
* @param handle The prompt's handle/identifier.
|
|
116
|
+
* @param config Local prompt configuration.
|
|
117
|
+
* @returns Object with created flag and raw PromptResponse data.
|
|
118
|
+
* @throws {PromptsError} If the API call fails.
|
|
119
|
+
*/
|
|
120
|
+
upsert(handle: string, config: {
|
|
121
|
+
model: string;
|
|
122
|
+
modelParameters?: {
|
|
123
|
+
temperature?: number;
|
|
124
|
+
max_tokens?: number;
|
|
125
|
+
};
|
|
126
|
+
messages: Array<{
|
|
127
|
+
role: "system" | "user" | "assistant";
|
|
128
|
+
content: string;
|
|
129
|
+
}>;
|
|
130
|
+
}): Promise<{
|
|
131
|
+
created: boolean;
|
|
132
|
+
prompt: PromptResponse;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* Sync a prompt with local content, handling conflicts and version management
|
|
136
|
+
*/
|
|
137
|
+
sync(params: {
|
|
138
|
+
name: string;
|
|
139
|
+
configData: ConfigData;
|
|
140
|
+
localVersion?: number;
|
|
141
|
+
commitMessage?: string;
|
|
142
|
+
}): Promise<SyncResult>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
type PromptDependency = string | {
|
|
146
|
+
version?: string;
|
|
147
|
+
file?: string;
|
|
148
|
+
};
|
|
149
|
+
type PromptsConfig = {
|
|
150
|
+
prompts: Record<string, PromptDependency>;
|
|
151
|
+
};
|
|
152
|
+
declare const localPromptConfigSchema: z.ZodObject<{
|
|
153
|
+
model: z.ZodString;
|
|
154
|
+
modelParameters: z.ZodOptional<z.ZodObject<{
|
|
155
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
156
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
157
|
+
}, z.core.$loose>>;
|
|
158
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
159
|
+
role: z.ZodEnum<{
|
|
160
|
+
system: "system";
|
|
161
|
+
user: "user";
|
|
162
|
+
assistant: "assistant";
|
|
163
|
+
}>;
|
|
164
|
+
content: z.ZodString;
|
|
165
|
+
}, z.core.$loose>>;
|
|
166
|
+
}, z.core.$loose>;
|
|
167
|
+
type LocalPromptConfig = z.infer<typeof localPromptConfigSchema>;
|
|
168
|
+
type MaterializedPrompt = {
|
|
169
|
+
id: string;
|
|
170
|
+
name: string;
|
|
171
|
+
version: number;
|
|
172
|
+
versionId: string;
|
|
173
|
+
model: string;
|
|
174
|
+
messages: Array<{
|
|
175
|
+
role: "system" | "user" | "assistant";
|
|
176
|
+
content: string;
|
|
177
|
+
}>;
|
|
178
|
+
prompt: string;
|
|
179
|
+
temperature?: number;
|
|
180
|
+
maxTokens?: number;
|
|
181
|
+
inputs?: any;
|
|
182
|
+
outputs?: any;
|
|
183
|
+
updatedAt: string;
|
|
184
|
+
};
|
|
185
|
+
type PromptsLockEntry = {
|
|
186
|
+
version: number;
|
|
187
|
+
versionId: string;
|
|
188
|
+
materialized: string;
|
|
189
|
+
};
|
|
190
|
+
type PromptsLock = {
|
|
191
|
+
lockfileVersion: number;
|
|
192
|
+
prompts: Record<string, PromptsLockEntry>;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
declare class FileManager {
|
|
196
|
+
private static readonly PROMPTS_CONFIG_FILE;
|
|
197
|
+
private static readonly PROMPTS_LOCK_FILE;
|
|
198
|
+
private static readonly PROMPTS_DIR;
|
|
199
|
+
private static readonly MATERIALIZED_DIR;
|
|
200
|
+
static getPromptsConfigPath(): string;
|
|
201
|
+
static getPromptsLockPath(): string;
|
|
202
|
+
static getPromptsDir(): string;
|
|
203
|
+
static getMaterializedDir(): string;
|
|
204
|
+
static ensureDirectories(): void;
|
|
205
|
+
static loadPromptsConfig(): PromptsConfig;
|
|
206
|
+
static savePromptsConfig(config: PromptsConfig): void;
|
|
207
|
+
static initializePromptsConfig(): {
|
|
208
|
+
created: boolean;
|
|
209
|
+
path: string;
|
|
210
|
+
};
|
|
211
|
+
static loadPromptsLock: () => PromptsLock;
|
|
212
|
+
static savePromptsLock(lock: PromptsLock): void;
|
|
213
|
+
static initializePromptsLock(): {
|
|
214
|
+
created: boolean;
|
|
215
|
+
path: string;
|
|
216
|
+
};
|
|
217
|
+
static loadLocalPrompt: (filePath: string) => LocalPromptConfig;
|
|
218
|
+
static saveMaterializedPrompt(name: string, prompt: MaterializedPrompt): string;
|
|
219
|
+
static getLocalPromptFiles: () => string[];
|
|
220
|
+
static promptNameFromPath(filePath: string): string;
|
|
221
|
+
static cleanupOrphanedMaterializedFiles(currentDependencies: Set<string>): string[];
|
|
222
|
+
static updateLockEntry(lock: PromptsLock, name: string, prompt: MaterializedPrompt, materializedPath: string): void;
|
|
223
|
+
static removeFromLock(lock: PromptsLock, names: string[]): void;
|
|
224
|
+
static addToGitignore(entry: string): {
|
|
225
|
+
added: boolean;
|
|
226
|
+
existed: boolean;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
interface LocalPromptsServiceConfig {
|
|
231
|
+
fileManager?: typeof FileManager;
|
|
232
|
+
logger?: Logger;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Service for retrieving prompts from local filesystem sources.
|
|
236
|
+
*
|
|
237
|
+
* Searches for prompts in the following priority order:
|
|
238
|
+
* 1. Explicit file mapping in prompts.json config
|
|
239
|
+
* 2. Materialized path from prompts-lock.json
|
|
240
|
+
* 3. Direct file scanning in prompts directory
|
|
241
|
+
*/
|
|
242
|
+
declare class LocalPromptsService {
|
|
243
|
+
private readonly fileManager;
|
|
244
|
+
private readonly logger;
|
|
245
|
+
constructor(config?: LocalPromptsServiceConfig);
|
|
246
|
+
/**
|
|
247
|
+
* Retrieves a prompt using the configured search strategy.
|
|
248
|
+
* Tries each source in priority order until found or all sources exhausted.
|
|
249
|
+
*/
|
|
250
|
+
get(handleOrId: string): Promise<PromptData | null>;
|
|
251
|
+
/**
|
|
252
|
+
* Searches for prompt using explicit file mapping in prompts.json.
|
|
253
|
+
* Looks for dependencies with a 'file' property pointing to a specific path.
|
|
254
|
+
*/
|
|
255
|
+
private getFromConfig;
|
|
256
|
+
/**
|
|
257
|
+
* Searches for prompt using materialized path from lock file.
|
|
258
|
+
* Lock file contains resolved paths for prompts that have been synced/materialized.
|
|
259
|
+
*/
|
|
260
|
+
private getFromLockFile;
|
|
261
|
+
/**
|
|
262
|
+
* Searches for prompt by scanning all .prompt.yaml files in prompts directory.
|
|
263
|
+
* Extracts prompt name from file path and matches against the requested handle.
|
|
264
|
+
* This is the fallback method when explicit mappings don't exist.
|
|
265
|
+
*/
|
|
266
|
+
private getFromLocalFiles;
|
|
267
|
+
/**
|
|
268
|
+
* Get dependency from config
|
|
269
|
+
*/
|
|
270
|
+
private getDependencyFromConfig;
|
|
271
|
+
/**
|
|
272
|
+
* Converts LocalPromptConfig to PromptData format
|
|
273
|
+
*/
|
|
274
|
+
private convertToPromptData;
|
|
275
|
+
}
|
|
35
276
|
|
|
277
|
+
interface PromptsFacadeDependencies {
|
|
278
|
+
promptsApiService: PromptsApiService;
|
|
279
|
+
localPromptsService: LocalPromptsService;
|
|
280
|
+
}
|
|
36
281
|
/**
|
|
37
282
|
* Facade for prompt operations in the LangWatch SDK.
|
|
38
283
|
* Provides a simplified interface for common prompt management tasks.
|
|
39
284
|
*/
|
|
40
285
|
declare class PromptsFacade {
|
|
41
|
-
private readonly
|
|
42
|
-
private readonly
|
|
43
|
-
constructor(config: InternalConfig);
|
|
286
|
+
private readonly promptsApiService;
|
|
287
|
+
private readonly localPromptsService;
|
|
288
|
+
constructor(config: InternalConfig & PromptsFacadeDependencies);
|
|
44
289
|
/**
|
|
45
290
|
* Creates a new prompt.
|
|
46
291
|
* @param data The prompt creation payload.
|
|
@@ -115,10 +360,10 @@ interface LangWatchConstructorOptions {
|
|
|
115
360
|
declare class LangWatch {
|
|
116
361
|
#private;
|
|
117
362
|
private readonly config;
|
|
118
|
-
private readonly tracer;
|
|
119
363
|
readonly prompts: PromptsFacade;
|
|
120
364
|
readonly traces: TracesFacade;
|
|
121
365
|
constructor(options?: LangWatchConstructorOptions);
|
|
366
|
+
get apiClient(): LangwatchApiClient;
|
|
122
367
|
}
|
|
123
368
|
|
|
124
369
|
declare const logger: {
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,153 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var _chunkDSIQSULKjs = require('./chunk-DSIQSULK.js');
|
|
4
|
-
require('./chunk-SVXNUWZI.js');
|
|
5
3
|
|
|
6
4
|
|
|
7
|
-
var _chunkYH5TIVK2js = require('./chunk-YH5TIVK2.js');
|
|
8
5
|
|
|
9
6
|
|
|
10
|
-
var
|
|
7
|
+
var _chunkHVW45GSTjs = require('./chunk-HVW45GST.js');
|
|
11
8
|
|
|
12
9
|
|
|
10
|
+
var _chunkSNDTNU3Tjs = require('./chunk-SNDTNU3T.js');
|
|
13
11
|
|
|
14
|
-
var _chunkP4SQTYGNjs = require('./chunk-P4SQTYGN.js');
|
|
15
|
-
require('./chunk-QCYYSMCU.js');
|
|
16
12
|
|
|
13
|
+
var _chunkJ7B7BNDNjs = require('./chunk-J7B7BNDN.js');
|
|
17
14
|
|
|
18
15
|
|
|
19
16
|
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
var _chunk2GYC6KEAjs = require('./chunk-2GYC6KEA.js');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var _chunkZ3NTWVVAjs = require('./chunk-Z3NTWVVA.js');
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var _chunkCKIZDPIJjs = require('./chunk-CKIZDPIJ.js');
|
|
28
|
+
require('./chunk-36XAYVMC.js');
|
|
29
|
+
require('./chunk-AZHZ4NB4.js');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
var _chunkOHM7JUMRjs = require('./chunk-OHM7JUMR.js');
|
|
37
|
+
|
|
38
|
+
// src/client-sdk/services/traces/types.ts
|
|
39
|
+
var TracesError = class extends Error {
|
|
40
|
+
constructor(message, operation, originalError) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.operation = operation;
|
|
43
|
+
this.originalError = originalError;
|
|
44
|
+
this.name = "TracesError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/client-sdk/services/traces/tracing/tracer.ts
|
|
49
|
+
var tracer = _chunkJ7B7BNDNjs.getLangWatchTracer.call(void 0, `${_chunkZ3NTWVVAjs.LANGWATCH_SDK_NAME_CLIENT}.traces`, _chunkZ3NTWVVAjs.LANGWATCH_SDK_VERSION);
|
|
50
|
+
|
|
51
|
+
// src/client-sdk/services/traces/service.ts
|
|
52
|
+
var TracesService = class {
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config = config;
|
|
55
|
+
return _chunkHVW45GSTjs.createTracingProxy.call(void 0,
|
|
56
|
+
this,
|
|
57
|
+
tracer
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Handles API errors by throwing a TracesError with operation context.
|
|
62
|
+
* @param operation Description of the operation being performed.
|
|
63
|
+
* @param error The error object returned from the API client.
|
|
64
|
+
* @throws {TracesError}
|
|
65
|
+
*/
|
|
66
|
+
handleApiError(operation, error) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
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";
|
|
69
|
+
throw new TracesError(
|
|
70
|
+
`Failed to ${operation}: ${errorMessage}`,
|
|
71
|
+
operation,
|
|
72
|
+
error
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves a trace by its ID.
|
|
77
|
+
* @param traceId The trace's unique identifier.
|
|
78
|
+
* @param params Optional parameters for the request.
|
|
79
|
+
* @returns The trace response object.
|
|
80
|
+
* @throws {TracesError} If the API call fails.
|
|
81
|
+
*/
|
|
82
|
+
async get(traceId, params) {
|
|
83
|
+
const { data, error } = await this.config.langwatchApiClient.GET("/api/trace/{id}", {
|
|
84
|
+
params: {
|
|
85
|
+
path: {
|
|
86
|
+
id: traceId
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
query: params
|
|
90
|
+
});
|
|
91
|
+
if (error) {
|
|
92
|
+
this.handleApiError("get trace", error);
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/client-sdk/services/traces/facade.ts
|
|
99
|
+
var _service;
|
|
100
|
+
var TracesFacade = class {
|
|
101
|
+
constructor(config) {
|
|
102
|
+
_chunkOHM7JUMRjs.__privateAdd.call(void 0, this, _service);
|
|
103
|
+
_chunkOHM7JUMRjs.__privateSet.call(void 0, this, _service, new TracesService(config));
|
|
104
|
+
}
|
|
105
|
+
async get(traceId, params) {
|
|
106
|
+
return _chunkOHM7JUMRjs.__privateGet.call(void 0, this, _service).get(traceId, params);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
_service = new WeakMap();
|
|
110
|
+
|
|
111
|
+
// src/client-sdk/index.ts
|
|
112
|
+
var _LangWatch_instances, createInternalConfig_fn;
|
|
113
|
+
var LangWatch = class {
|
|
114
|
+
constructor(options = {}) {
|
|
115
|
+
_chunkOHM7JUMRjs.__privateAdd.call(void 0, this, _LangWatch_instances);
|
|
116
|
+
var _a, _b, _c, _d;
|
|
117
|
+
const apiKey = (_b = (_a = options.apiKey) != null ? _a : process.env.LANGWATCH_API_KEY) != null ? _b : "";
|
|
118
|
+
const endpoint = (_d = (_c = options.endpoint) != null ? _c : process.env.LANGWATCH_ENDPOINT) != null ? _d : _chunkZ3NTWVVAjs.DEFAULT_ENDPOINT;
|
|
119
|
+
this.config = _chunkOHM7JUMRjs.__privateMethod.call(void 0, this, _LangWatch_instances, createInternalConfig_fn).call(this, {
|
|
120
|
+
apiKey,
|
|
121
|
+
endpoint,
|
|
122
|
+
options: options.options
|
|
123
|
+
});
|
|
124
|
+
this.prompts = new (0, _chunkHVW45GSTjs.PromptsFacade)(_chunkOHM7JUMRjs.__spreadValues.call(void 0, {
|
|
125
|
+
promptsApiService: new (0, _chunkHVW45GSTjs.PromptsApiService)(this.config),
|
|
126
|
+
localPromptsService: new (0, _chunkHVW45GSTjs.LocalPromptsService)()
|
|
127
|
+
}, this.config));
|
|
128
|
+
this.traces = new TracesFacade(this.config);
|
|
129
|
+
}
|
|
130
|
+
get apiClient() {
|
|
131
|
+
return this.config.langwatchApiClient;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
_LangWatch_instances = new WeakSet();
|
|
135
|
+
createInternalConfig_fn = function({
|
|
136
|
+
apiKey,
|
|
137
|
+
endpoint,
|
|
138
|
+
options
|
|
139
|
+
}) {
|
|
140
|
+
var _a;
|
|
141
|
+
return {
|
|
142
|
+
logger: (_a = options == null ? void 0 : options.logger) != null ? _a : new (0, _chunkCKIZDPIJjs.NoOpLogger)(),
|
|
143
|
+
langwatchApiClient: _chunkHVW45GSTjs.createLangWatchApiClient.call(void 0, apiKey, endpoint)
|
|
144
|
+
};
|
|
145
|
+
};
|
|
23
146
|
|
|
24
147
|
// src/index.ts
|
|
25
148
|
var logger = {
|
|
26
|
-
ConsoleLogger:
|
|
27
|
-
NoOpLogger:
|
|
149
|
+
ConsoleLogger: _chunkCKIZDPIJjs.ConsoleLogger,
|
|
150
|
+
NoOpLogger: _chunkCKIZDPIJjs.NoOpLogger
|
|
28
151
|
};
|
|
29
152
|
|
|
30
153
|
|
|
@@ -34,5 +157,5 @@ var logger = {
|
|
|
34
157
|
|
|
35
158
|
|
|
36
159
|
|
|
37
|
-
exports.FilterableBatchSpanProcessor =
|
|
160
|
+
exports.FilterableBatchSpanProcessor = _chunkSNDTNU3Tjs.FilterableBatchSpanProcessor; exports.LangWatch = LangWatch; exports.LangWatchExporter = _chunk2GYC6KEAjs.LangWatchTraceExporter; exports.attributes = _chunkCKIZDPIJjs.attributes_exports; exports.getLangWatchLogger = _chunk2GYC6KEAjs.getLangWatchLogger; exports.getLangWatchTracer = _chunkJ7B7BNDNjs.getLangWatchTracer; exports.logger = logger;
|
|
38
161
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/index.js","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/index.js","../src/client-sdk/services/traces/types.ts","../src/client-sdk/services/traces/tracing/tracer.ts","../src/client-sdk/services/traces/service.ts","../src/client-sdk/services/traces/facade.ts","../src/client-sdk/index.ts","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACA;ACvBO,IAAM,YAAA,EAAN,MAAA,QAA0B,MAAM;AAAA,EACrC,WAAA,CACE,OAAA,EACgB,SAAA,EACA,aAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHG,IAAA,IAAA,CAAA,UAAA,EAAA,SAAA;AACA,IAAA,IAAA,CAAA,cAAA,EAAA,aAAA;AAGhB,IAAA,IAAA,CAAK,KAAA,EAAO,aAAA;AAAA,EACd;AACF,CAAA;ADuBA;AACA;AE5CO,IAAM,OAAA,EAAS,iDAAA,CAAmB,EAAA;AF8CR;AACA;AGnCN;AAGW,EAAA;AACpB,IAAA;AAKP,IAAA;AACL,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ0C,EAAA;AApC5C,IAAA;AAsCa,IAAA;AAGC,IAAA;AACmB,MAAA;AAC3B,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAY6B,EAAA;AACH,IAAA;AACd,MAAA;AACA,QAAA;AACA,UAAA;AACN,QAAA;AACF,MAAA;AACO,MAAA;AACR,IAAA;AAEU,IAAA;AACW,MAAA;AACtB,IAAA;AAEO,IAAA;AACT,EAAA;AACF;AHsBiC;AACA;AIjGjC;AAI0B;AAGY,EAAA;AAF3B,IAAA;AAGS,IAAA;AAClB,EAAA;AAE+E,EAAA;AACjE,IAAA;AACd,EAAA;AACF;AATW;AJwGsB;AACA;AK9GjC;AAgBuB;AAMkC,EAAA;AANlD,IAAA;AAhBP,IAAA;AAuBmB,IAAA;AACE,IAAA;AAEH,IAAA;AACZ,MAAA;AACA,MAAA;AACiB,MAAA;AACnB,IAAA;AAEmB,IAAA;AACM,MAAA;AACE,MAAA;AAE1B,IAAA;AACiB,IAAA;AACpB,EAAA;AAEoC,EAAA;AACf,IAAA;AACrB,EAAA;AAgBF;AA1CO;AA4BgB;AACnB,EAAA;AACA,EAAA;AACA,EAAA;AAKiB;AApDrB,EAAA;AAqDW,EAAA;AACG,IAAA;AACY,IAAA;AACtB,EAAA;AACF;ALwF+B;AACA;AMnIX;AACpB,EAAA;AACA,EAAA;AACF;ANqIiC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/index.js","sourcesContent":[null,"import type { paths } from \"@/internal/generated/openapi/api-client\";\n\nexport interface GetTraceParams {\n includeSpans?: boolean;\n}\n\nexport type GetTraceResponse = NonNullable<\n paths[\"/api/trace/{id}\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n>;\n\n/**\n * Custom error class for Traces API operations.\n * Provides context about the failed operation and the original error.\n */\nexport class TracesError extends Error {\n constructor(\n message: string,\n public readonly operation: string,\n public readonly originalError?: any,\n ) {\n super(message);\n this.name = \"TracesError\";\n }\n}\n","import { LANGWATCH_SDK_NAME_CLIENT, LANGWATCH_SDK_VERSION } from \"@/internal/constants\";\nimport { getLangWatchTracer } from \"@/observability-sdk/tracer\";\n\nexport const tracer = getLangWatchTracer(`${LANGWATCH_SDK_NAME_CLIENT}.traces`, LANGWATCH_SDK_VERSION);\n","import { createTracingProxy } from \"@/client-sdk/tracing/create-tracing-proxy\";\nimport { type InternalConfig } from \"@/client-sdk/types\";\nimport { type GetTraceParams, TracesError, type GetTraceResponse } from \"./types\";\nimport { tracer } from \"./tracing\";\n\n/**\n * Service for managing trace resources via the Langwatch API.\n * Constructor creates a proxy that wraps the service and traces all methods.\n *\n * Responsibilities:\n * - Retrieving trace data\n * - Error handling with contextual information\n *\n * All methods return trace response objects directly.\n */\nexport class TracesService {\n private config: InternalConfig;\n\n constructor(config: InternalConfig) {\n this.config = config;\n\n /**\n * Wraps the service in a tracing proxy via the decorator.\n */\n return createTracingProxy(\n this as TracesService,\n tracer,\n );\n }\n\n /**\n * Handles API errors by throwing a TracesError 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 {TracesError}\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 TracesError(\n `Failed to ${operation}: ${errorMessage}`,\n operation,\n error,\n );\n }\n\n /**\n * Retrieves a trace by its ID.\n * @param traceId The trace's unique identifier.\n * @param params Optional parameters for the request.\n * @returns The trace response object.\n * @throws {TracesError} If the API call fails.\n */\n async get(\n traceId: string,\n params?: GetTraceParams,\n ): Promise<GetTraceResponse> {\n const { data, error } = await this.config.langwatchApiClient.GET(\"/api/trace/{id}\", {\n params: {\n path: {\n id: traceId,\n },\n },\n query: params,\n });\n\n if (error) {\n this.handleApiError(\"get trace\", error);\n }\n\n return data;\n }\n}\n","import { type InternalConfig } from \"../../types\";\nimport { TracesService } from \"./service\";\nimport { type GetTraceParams, type GetTraceResponse } from \"./types\";\n\nexport class TracesFacade {\n readonly #service: TracesService;\n\n constructor(config: InternalConfig) {\n this.#service = new TracesService(config);\n }\n\n async get(traceId: string, params?: GetTraceParams): Promise<GetTraceResponse> {\n return this.#service.get(traceId, params);\n }\n}\n","import { PromptsFacade, PromptsApiService } from \"./services/prompts\";\nimport { LocalPromptsService } from \"./services/prompts/local-prompts.service\";\nimport { type InternalConfig } from \"./types\";\nimport { createLangWatchApiClient, type LangwatchApiClient } from \"../internal/api/client\";\nimport { type Logger, NoOpLogger } from \"../logger\";\nimport { TracesFacade } from \"./services/traces/facade\";\nimport { DEFAULT_ENDPOINT } from \"@/internal/constants\";\n\nexport interface LangWatchConstructorOptions {\n apiKey?: string;\n endpoint?: string;\n options?: {\n logger?: Logger;\n };\n}\n\nexport class LangWatch {\n private readonly config: InternalConfig;\n\n readonly prompts: PromptsFacade;\n readonly traces: TracesFacade;\n\n constructor(options: LangWatchConstructorOptions = {}) {\n const apiKey = options.apiKey ?? process.env.LANGWATCH_API_KEY ?? \"\";\n const endpoint = options.endpoint ?? process.env.LANGWATCH_ENDPOINT ?? DEFAULT_ENDPOINT;\n\n this.config = this.#createInternalConfig({\n apiKey,\n endpoint,\n options: options.options,\n });\n\n this.prompts = new PromptsFacade({\n promptsApiService: new PromptsApiService(this.config),\n localPromptsService: new LocalPromptsService(),\n ...this.config,\n });\n this.traces = new TracesFacade(this.config);\n }\n\n get apiClient(): LangwatchApiClient {\n return this.config.langwatchApiClient;\n }\n\n #createInternalConfig({\n apiKey,\n endpoint,\n options,\n }: {\n apiKey: string;\n endpoint: string;\n options?: LangWatchConstructorOptions[\"options\"];\n }): InternalConfig {\n return {\n logger: options?.logger ?? new NoOpLogger(),\n langwatchApiClient: createLangWatchApiClient(apiKey, endpoint),\n };\n }\n}\n","import { ConsoleLogger, NoOpLogger } from \"./logger\";\n\nexport {\n getLangWatchTracer,\n getLangWatchLogger,\n attributes,\n} from \"./observability-sdk\";\n\nexport {\n FilterableBatchSpanProcessor,\n type SpanProcessingExcludeRule,\n} from \"./observability-sdk/processors\";\nexport { LangWatchExporter } from \"./observability-sdk/exporters\";\nexport { LangWatch } from \"./client-sdk\";\n\nexport const logger = {\n ConsoleLogger,\n NoOpLogger,\n};\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,148 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
LocalPromptsService,
|
|
3
|
+
PromptsApiService,
|
|
4
|
+
PromptsFacade,
|
|
5
|
+
createLangWatchApiClient,
|
|
6
|
+
createTracingProxy
|
|
7
|
+
} from "./chunk-GAFUPYJ3.mjs";
|
|
5
8
|
import {
|
|
6
9
|
FilterableBatchSpanProcessor
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-FEL5FLHA.mjs";
|
|
8
11
|
import {
|
|
9
12
|
getLangWatchTracer
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-JPWKINZP.mjs";
|
|
11
14
|
import {
|
|
12
15
|
LangWatchTraceExporter,
|
|
13
16
|
getLangWatchLogger
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import
|
|
17
|
+
} from "./chunk-3P4ROGZJ.mjs";
|
|
18
|
+
import {
|
|
19
|
+
DEFAULT_ENDPOINT,
|
|
20
|
+
LANGWATCH_SDK_NAME_CLIENT,
|
|
21
|
+
LANGWATCH_SDK_VERSION
|
|
22
|
+
} from "./chunk-WOBPYIKO.mjs";
|
|
16
23
|
import {
|
|
17
24
|
ConsoleLogger,
|
|
18
25
|
NoOpLogger,
|
|
19
26
|
attributes_exports
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
27
|
+
} from "./chunk-I2SOBPAF.mjs";
|
|
28
|
+
import "./chunk-PYVDTUA6.mjs";
|
|
29
|
+
import "./chunk-BTBSMJTY.mjs";
|
|
30
|
+
import {
|
|
31
|
+
__privateAdd,
|
|
32
|
+
__privateGet,
|
|
33
|
+
__privateMethod,
|
|
34
|
+
__privateSet,
|
|
35
|
+
__spreadValues
|
|
36
|
+
} from "./chunk-URTD2WOC.mjs";
|
|
37
|
+
|
|
38
|
+
// src/client-sdk/services/traces/types.ts
|
|
39
|
+
var TracesError = class extends Error {
|
|
40
|
+
constructor(message, operation, originalError) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.operation = operation;
|
|
43
|
+
this.originalError = originalError;
|
|
44
|
+
this.name = "TracesError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/client-sdk/services/traces/tracing/tracer.ts
|
|
49
|
+
var tracer = getLangWatchTracer(`${LANGWATCH_SDK_NAME_CLIENT}.traces`, LANGWATCH_SDK_VERSION);
|
|
50
|
+
|
|
51
|
+
// src/client-sdk/services/traces/service.ts
|
|
52
|
+
var TracesService = class {
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config = config;
|
|
55
|
+
return createTracingProxy(
|
|
56
|
+
this,
|
|
57
|
+
tracer
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Handles API errors by throwing a TracesError with operation context.
|
|
62
|
+
* @param operation Description of the operation being performed.
|
|
63
|
+
* @param error The error object returned from the API client.
|
|
64
|
+
* @throws {TracesError}
|
|
65
|
+
*/
|
|
66
|
+
handleApiError(operation, error) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
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";
|
|
69
|
+
throw new TracesError(
|
|
70
|
+
`Failed to ${operation}: ${errorMessage}`,
|
|
71
|
+
operation,
|
|
72
|
+
error
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves a trace by its ID.
|
|
77
|
+
* @param traceId The trace's unique identifier.
|
|
78
|
+
* @param params Optional parameters for the request.
|
|
79
|
+
* @returns The trace response object.
|
|
80
|
+
* @throws {TracesError} If the API call fails.
|
|
81
|
+
*/
|
|
82
|
+
async get(traceId, params) {
|
|
83
|
+
const { data, error } = await this.config.langwatchApiClient.GET("/api/trace/{id}", {
|
|
84
|
+
params: {
|
|
85
|
+
path: {
|
|
86
|
+
id: traceId
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
query: params
|
|
90
|
+
});
|
|
91
|
+
if (error) {
|
|
92
|
+
this.handleApiError("get trace", error);
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/client-sdk/services/traces/facade.ts
|
|
99
|
+
var _service;
|
|
100
|
+
var TracesFacade = class {
|
|
101
|
+
constructor(config) {
|
|
102
|
+
__privateAdd(this, _service);
|
|
103
|
+
__privateSet(this, _service, new TracesService(config));
|
|
104
|
+
}
|
|
105
|
+
async get(traceId, params) {
|
|
106
|
+
return __privateGet(this, _service).get(traceId, params);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
_service = new WeakMap();
|
|
110
|
+
|
|
111
|
+
// src/client-sdk/index.ts
|
|
112
|
+
var _LangWatch_instances, createInternalConfig_fn;
|
|
113
|
+
var LangWatch = class {
|
|
114
|
+
constructor(options = {}) {
|
|
115
|
+
__privateAdd(this, _LangWatch_instances);
|
|
116
|
+
var _a, _b, _c, _d;
|
|
117
|
+
const apiKey = (_b = (_a = options.apiKey) != null ? _a : process.env.LANGWATCH_API_KEY) != null ? _b : "";
|
|
118
|
+
const endpoint = (_d = (_c = options.endpoint) != null ? _c : process.env.LANGWATCH_ENDPOINT) != null ? _d : DEFAULT_ENDPOINT;
|
|
119
|
+
this.config = __privateMethod(this, _LangWatch_instances, createInternalConfig_fn).call(this, {
|
|
120
|
+
apiKey,
|
|
121
|
+
endpoint,
|
|
122
|
+
options: options.options
|
|
123
|
+
});
|
|
124
|
+
this.prompts = new PromptsFacade(__spreadValues({
|
|
125
|
+
promptsApiService: new PromptsApiService(this.config),
|
|
126
|
+
localPromptsService: new LocalPromptsService()
|
|
127
|
+
}, this.config));
|
|
128
|
+
this.traces = new TracesFacade(this.config);
|
|
129
|
+
}
|
|
130
|
+
get apiClient() {
|
|
131
|
+
return this.config.langwatchApiClient;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
_LangWatch_instances = new WeakSet();
|
|
135
|
+
createInternalConfig_fn = function({
|
|
136
|
+
apiKey,
|
|
137
|
+
endpoint,
|
|
138
|
+
options
|
|
139
|
+
}) {
|
|
140
|
+
var _a;
|
|
141
|
+
return {
|
|
142
|
+
logger: (_a = options == null ? void 0 : options.logger) != null ? _a : new NoOpLogger(),
|
|
143
|
+
langwatchApiClient: createLangWatchApiClient(apiKey, endpoint)
|
|
144
|
+
};
|
|
145
|
+
};
|
|
23
146
|
|
|
24
147
|
// src/index.ts
|
|
25
148
|
var logger = {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ConsoleLogger, NoOpLogger } from \"./logger\";\n\nexport {\n getLangWatchTracer,\n getLangWatchLogger,\n attributes,\n} from \"./observability-sdk\";\n\nexport {\n FilterableBatchSpanProcessor,\n type SpanProcessingExcludeRule,\n} from \"./observability-sdk/processors\";\nexport { LangWatchExporter } from \"./observability-sdk/exporters\";\nexport { LangWatch } from \"./client-sdk\";\n\nexport const logger = {\n ConsoleLogger,\n NoOpLogger,\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/client-sdk/services/traces/types.ts","../src/client-sdk/services/traces/tracing/tracer.ts","../src/client-sdk/services/traces/service.ts","../src/client-sdk/services/traces/facade.ts","../src/client-sdk/index.ts","../src/index.ts"],"sourcesContent":["import type { paths } from \"@/internal/generated/openapi/api-client\";\n\nexport interface GetTraceParams {\n includeSpans?: boolean;\n}\n\nexport type GetTraceResponse = NonNullable<\n paths[\"/api/trace/{id}\"][\"get\"][\"responses\"][\"200\"][\"content\"][\"application/json\"]\n>;\n\n/**\n * Custom error class for Traces API operations.\n * Provides context about the failed operation and the original error.\n */\nexport class TracesError extends Error {\n constructor(\n message: string,\n public readonly operation: string,\n public readonly originalError?: any,\n ) {\n super(message);\n this.name = \"TracesError\";\n }\n}\n","import { LANGWATCH_SDK_NAME_CLIENT, LANGWATCH_SDK_VERSION } from \"@/internal/constants\";\nimport { getLangWatchTracer } from \"@/observability-sdk/tracer\";\n\nexport const tracer = getLangWatchTracer(`${LANGWATCH_SDK_NAME_CLIENT}.traces`, LANGWATCH_SDK_VERSION);\n","import { createTracingProxy } from \"@/client-sdk/tracing/create-tracing-proxy\";\nimport { type InternalConfig } from \"@/client-sdk/types\";\nimport { type GetTraceParams, TracesError, type GetTraceResponse } from \"./types\";\nimport { tracer } from \"./tracing\";\n\n/**\n * Service for managing trace resources via the Langwatch API.\n * Constructor creates a proxy that wraps the service and traces all methods.\n *\n * Responsibilities:\n * - Retrieving trace data\n * - Error handling with contextual information\n *\n * All methods return trace response objects directly.\n */\nexport class TracesService {\n private config: InternalConfig;\n\n constructor(config: InternalConfig) {\n this.config = config;\n\n /**\n * Wraps the service in a tracing proxy via the decorator.\n */\n return createTracingProxy(\n this as TracesService,\n tracer,\n );\n }\n\n /**\n * Handles API errors by throwing a TracesError 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 {TracesError}\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 TracesError(\n `Failed to ${operation}: ${errorMessage}`,\n operation,\n error,\n );\n }\n\n /**\n * Retrieves a trace by its ID.\n * @param traceId The trace's unique identifier.\n * @param params Optional parameters for the request.\n * @returns The trace response object.\n * @throws {TracesError} If the API call fails.\n */\n async get(\n traceId: string,\n params?: GetTraceParams,\n ): Promise<GetTraceResponse> {\n const { data, error } = await this.config.langwatchApiClient.GET(\"/api/trace/{id}\", {\n params: {\n path: {\n id: traceId,\n },\n },\n query: params,\n });\n\n if (error) {\n this.handleApiError(\"get trace\", error);\n }\n\n return data;\n }\n}\n","import { type InternalConfig } from \"../../types\";\nimport { TracesService } from \"./service\";\nimport { type GetTraceParams, type GetTraceResponse } from \"./types\";\n\nexport class TracesFacade {\n readonly #service: TracesService;\n\n constructor(config: InternalConfig) {\n this.#service = new TracesService(config);\n }\n\n async get(traceId: string, params?: GetTraceParams): Promise<GetTraceResponse> {\n return this.#service.get(traceId, params);\n }\n}\n","import { PromptsFacade, PromptsApiService } from \"./services/prompts\";\nimport { LocalPromptsService } from \"./services/prompts/local-prompts.service\";\nimport { type InternalConfig } from \"./types\";\nimport { createLangWatchApiClient, type LangwatchApiClient } from \"../internal/api/client\";\nimport { type Logger, NoOpLogger } from \"../logger\";\nimport { TracesFacade } from \"./services/traces/facade\";\nimport { DEFAULT_ENDPOINT } from \"@/internal/constants\";\n\nexport interface LangWatchConstructorOptions {\n apiKey?: string;\n endpoint?: string;\n options?: {\n logger?: Logger;\n };\n}\n\nexport class LangWatch {\n private readonly config: InternalConfig;\n\n readonly prompts: PromptsFacade;\n readonly traces: TracesFacade;\n\n constructor(options: LangWatchConstructorOptions = {}) {\n const apiKey = options.apiKey ?? process.env.LANGWATCH_API_KEY ?? \"\";\n const endpoint = options.endpoint ?? process.env.LANGWATCH_ENDPOINT ?? DEFAULT_ENDPOINT;\n\n this.config = this.#createInternalConfig({\n apiKey,\n endpoint,\n options: options.options,\n });\n\n this.prompts = new PromptsFacade({\n promptsApiService: new PromptsApiService(this.config),\n localPromptsService: new LocalPromptsService(),\n ...this.config,\n });\n this.traces = new TracesFacade(this.config);\n }\n\n get apiClient(): LangwatchApiClient {\n return this.config.langwatchApiClient;\n }\n\n #createInternalConfig({\n apiKey,\n endpoint,\n options,\n }: {\n apiKey: string;\n endpoint: string;\n options?: LangWatchConstructorOptions[\"options\"];\n }): InternalConfig {\n return {\n logger: options?.logger ?? new NoOpLogger(),\n langwatchApiClient: createLangWatchApiClient(apiKey, endpoint),\n };\n }\n}\n","import { ConsoleLogger, NoOpLogger } from \"./logger\";\n\nexport {\n getLangWatchTracer,\n getLangWatchLogger,\n attributes,\n} from \"./observability-sdk\";\n\nexport {\n FilterableBatchSpanProcessor,\n type SpanProcessingExcludeRule,\n} from \"./observability-sdk/processors\";\nexport { LangWatchExporter } from \"./observability-sdk/exporters\";\nexport { LangWatch } from \"./client-sdk\";\n\nexport const logger = {\n ConsoleLogger,\n NoOpLogger,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YACE,SACgB,WACA,eAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACpBO,IAAM,SAAS,mBAAmB,GAAG,yBAAyB,WAAW,qBAAqB;;;ACY9F,IAAM,gBAAN,MAAoB;AAAA,EAGzB,YAAY,QAAwB;AAClC,SAAK,SAAS;AAKd,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,eAAe,WAAmB,OAAmB;AApC/D;AAqCI,UAAM,eACJ,OAAO,UAAU,WACb,SACA,0CAAO,UAAP,YAAgB,+BAAO,YAAvB,YAAkC;AACxC,UAAM,IAAI;AAAA,MACR,aAAa,SAAS,KAAK,YAAY;AAAA,MACvC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,IACJ,SACA,QAC2B;AAC3B,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,KAAK,OAAO,mBAAmB,IAAI,mBAAmB;AAAA,MAClF,QAAQ;AAAA,QACN,MAAM;AAAA,UACJ,IAAI;AAAA,QACN;AAAA,MACF;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AAED,QAAI,OAAO;AACT,WAAK,eAAe,aAAa,KAAK;AAAA,IACxC;AAEA,WAAO;AAAA,EACT;AACF;;;AC1EA;AAIO,IAAM,eAAN,MAAmB;AAAA,EAGxB,YAAY,QAAwB;AAFpC,uBAAS;AAGP,uBAAK,UAAW,IAAI,cAAc,MAAM;AAAA,EAC1C;AAAA,EAEA,MAAM,IAAI,SAAiB,QAAoD;AAC7E,WAAO,mBAAK,UAAS,IAAI,SAAS,MAAM;AAAA,EAC1C;AACF;AATW;;;ACLX;AAgBO,IAAM,YAAN,MAAgB;AAAA,EAMrB,YAAY,UAAuC,CAAC,GAAG;AANlD;AAhBP;AAuBI,UAAM,UAAS,mBAAQ,WAAR,YAAkB,QAAQ,IAAI,sBAA9B,YAAmD;AAClE,UAAM,YAAW,mBAAQ,aAAR,YAAoB,QAAQ,IAAI,uBAAhC,YAAsD;AAEvE,SAAK,SAAS,sBAAK,+CAAL,WAA2B;AAAA,MACvC;AAAA,MACA;AAAA,MACA,SAAS,QAAQ;AAAA,IACnB;AAEA,SAAK,UAAU,IAAI,cAAc;AAAA,MAC/B,mBAAmB,IAAI,kBAAkB,KAAK,MAAM;AAAA,MACpD,qBAAqB,IAAI,oBAAoB;AAAA,OAC1C,KAAK,OACT;AACD,SAAK,SAAS,IAAI,aAAa,KAAK,MAAM;AAAA,EAC5C;AAAA,EAEA,IAAI,YAAgC;AAClC,WAAO,KAAK,OAAO;AAAA,EACrB;AAgBF;AA1CO;AA4BL,0BAAqB,SAAC;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAImB;AApDrB;AAqDI,SAAO;AAAA,IACL,SAAQ,wCAAS,WAAT,YAAmB,IAAI,WAAW;AAAA,IAC1C,oBAAoB,yBAAyB,QAAQ,QAAQ;AAAA,EAC/D;AACF;;;AC1CK,IAAM,SAAS;AAAA,EACpB;AAAA,EACA;AACF;","names":[]}
|