langwatch 0.5.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{add-4WXEWG5H.js → add-5QV3TEWC.js} +28 -32
- package/dist/add-5QV3TEWC.js.map +1 -0
- package/dist/{add-D2WVVKIP.mjs → add-HWFRMAQX.mjs} +14 -18
- package/dist/add-HWFRMAQX.mjs.map +1 -0
- package/dist/{chunk-CAZONSXV.js → chunk-36XAYVMC.js} +186 -76
- package/dist/chunk-36XAYVMC.js.map +1 -0
- package/dist/{chunk-QCYYSMCU.js → chunk-5HAVK64Q.js} +2 -2
- package/dist/chunk-5HAVK64Q.js.map +1 -0
- package/dist/{chunk-ZIULPOMQ.mjs → chunk-7MG7DGPP.mjs} +4 -4
- package/dist/{chunk-YKFTFYKK.mjs → chunk-7VHZNB2S.mjs} +2 -2
- package/dist/chunk-7VHZNB2S.mjs.map +1 -0
- package/dist/{chunk-DLJO7AK5.mjs → chunk-AD7QRYIJ.mjs} +2 -2
- package/dist/{chunk-DISMHYXC.js → chunk-CKIZDPIJ.js} +24 -22
- package/dist/chunk-CKIZDPIJ.js.map +1 -0
- package/dist/{chunk-SVXNUWZI.js → chunk-D7UAKYVI.js} +345 -154
- package/dist/chunk-D7UAKYVI.js.map +1 -0
- package/dist/{chunk-7OZKH5K2.js → chunk-DZH6SY3Z.js} +10 -10
- package/dist/{chunk-7OZKH5K2.js.map → chunk-DZH6SY3Z.js.map} +1 -1
- package/dist/{chunk-H5PON53W.mjs → chunk-EPGKOTSN.mjs} +334 -143
- package/dist/chunk-EPGKOTSN.mjs.map +1 -0
- package/dist/{chunk-N2V6J3U2.mjs → chunk-FEL5FLHA.mjs} +2 -2
- package/dist/{chunk-YNQ44U6D.mjs → chunk-I2SOBPAF.mjs} +23 -21
- package/dist/chunk-I2SOBPAF.mjs.map +1 -0
- package/dist/{chunk-P4SQTYGN.js → chunk-J55AV2YW.js} +32 -32
- package/dist/{chunk-P4SQTYGN.js.map → chunk-J55AV2YW.js.map} +1 -1
- package/dist/{chunk-OXBO24RB.js → chunk-OHM7JUMR.js} +15 -2
- package/dist/chunk-OHM7JUMR.js.map +1 -0
- package/dist/chunk-PYVDTUA6.mjs +352 -0
- package/dist/chunk-PYVDTUA6.mjs.map +1 -0
- package/dist/{chunk-YH5TIVK2.js → chunk-SNDTNU3T.js} +2 -2
- package/dist/{chunk-YH5TIVK2.js.map → chunk-SNDTNU3T.js.map} +1 -1
- package/dist/{chunk-QZGTM76F.mjs → chunk-UNMZPS55.mjs} +7 -3
- package/dist/chunk-UNMZPS55.mjs.map +1 -0
- package/dist/{chunk-CU3443HD.mjs → chunk-URTD2WOC.mjs} +14 -1
- package/dist/{chunk-ECOC36EA.js → chunk-VMZUN4EF.js} +16 -12
- package/dist/chunk-VMZUN4EF.js.map +1 -0
- package/dist/cli/index.js +8 -8
- package/dist/cli/index.mjs +8 -8
- package/dist/{create-OQEMO4MU.mjs → create-LXQB4EFB.mjs} +4 -5
- package/dist/{create-OQEMO4MU.mjs.map → create-LXQB4EFB.mjs.map} +1 -1
- package/dist/{create-4LG4N2A4.js → create-S5RDGF3H.js} +9 -10
- package/dist/create-S5RDGF3H.js.map +1 -0
- package/dist/{implementation-BIlL6-SW.d.ts → implementation-DsHp9FYU.d.ts} +1 -1
- package/dist/{implementation-fAgqv8OM.d.mts → implementation-nE9dgTwc.d.mts} +1 -1
- package/dist/{index-DTEZr0Jn.d.mts → index-D7rKIGrO.d.mts} +12 -12
- package/dist/{index-DTEZr0Jn.d.ts → index-D7rKIGrO.d.ts} +12 -12
- package/dist/index.d.mts +256 -11
- package/dist/index.d.ts +256 -11
- package/dist/index.js +135 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +133 -10
- package/dist/index.mjs.map +1 -1
- package/dist/{init-MQXXHCNT.mjs → init-T4YDPHBA.mjs} +4 -5
- package/dist/{init-MQXXHCNT.mjs.map → init-T4YDPHBA.mjs.map} +1 -1
- package/dist/init-UADBKUJU.js +15 -0
- package/dist/init-UADBKUJU.js.map +1 -0
- package/dist/{list-PFWV7IU6.mjs → list-BQXECLEM.mjs} +13 -14
- package/dist/list-BQXECLEM.mjs.map +1 -0
- package/dist/{list-GIAXAAH5.js → list-HSCIBC4Z.js} +14 -15
- package/dist/list-HSCIBC4Z.js.map +1 -0
- package/dist/{login-BYLXS23I.mjs → login-3IM3PYSJ.mjs} +3 -3
- package/dist/{login-3STX2FAO.js → login-EUDCIJRM.js} +4 -4
- package/dist/{login-3STX2FAO.js.map → login-EUDCIJRM.js.map} +1 -1
- package/dist/observability-sdk/index.d.mts +4 -3
- package/dist/observability-sdk/index.d.ts +4 -3
- package/dist/observability-sdk/index.js +7 -7
- package/dist/observability-sdk/index.mjs +6 -6
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +2 -1
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +2 -1
- package/dist/observability-sdk/instrumentation/langchain/index.js +19 -19
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +3 -3
- package/dist/observability-sdk/setup/node/index.d.mts +1 -1
- package/dist/observability-sdk/setup/node/index.d.ts +1 -1
- package/dist/observability-sdk/setup/node/index.js +15 -15
- package/dist/observability-sdk/setup/node/index.mjs +4 -4
- package/dist/{remove-FTF3EBYV.mjs → remove-IVFQAHNT.mjs} +9 -10
- package/dist/{remove-FTF3EBYV.mjs.map → remove-IVFQAHNT.mjs.map} +1 -1
- package/dist/{remove-U3PILQDV.js → remove-VDQ4M6JF.js} +17 -18
- package/dist/remove-VDQ4M6JF.js.map +1 -0
- package/dist/{sync-FOW7DHAH.mjs → sync-2MVHHWCX.mjs} +16 -20
- package/dist/sync-2MVHHWCX.mjs.map +1 -0
- package/dist/{sync-T3T22GVZ.js → sync-KUMBMGJS.js} +31 -35
- package/dist/sync-KUMBMGJS.js.map +1 -0
- package/dist/{types-DyUmlaDx.d.ts → types-B9772cUR.d.ts} +98 -29
- package/dist/{types-jrEEZt9d.d.mts → types-DbPAi4US.d.mts} +98 -29
- package/package.json +16 -11
- package/dist/add-4WXEWG5H.js.map +0 -1
- package/dist/add-D2WVVKIP.mjs.map +0 -1
- package/dist/chunk-CAZONSXV.js.map +0 -1
- package/dist/chunk-CKVDNVFL.mjs +0 -242
- package/dist/chunk-CKVDNVFL.mjs.map +0 -1
- package/dist/chunk-DISMHYXC.js.map +0 -1
- package/dist/chunk-DSIQSULK.js +0 -152
- package/dist/chunk-DSIQSULK.js.map +0 -1
- package/dist/chunk-ECOC36EA.js.map +0 -1
- package/dist/chunk-H5PON53W.mjs.map +0 -1
- package/dist/chunk-OXBO24RB.js.map +0 -1
- package/dist/chunk-QCYYSMCU.js.map +0 -1
- package/dist/chunk-QZGTM76F.mjs.map +0 -1
- package/dist/chunk-R6FBJN7K.js +0 -115
- package/dist/chunk-R6FBJN7K.js.map +0 -1
- package/dist/chunk-SVXNUWZI.js.map +0 -1
- package/dist/chunk-V5M3HUBV.mjs +0 -115
- package/dist/chunk-V5M3HUBV.mjs.map +0 -1
- package/dist/chunk-YEGQXDTE.mjs +0 -152
- package/dist/chunk-YEGQXDTE.mjs.map +0 -1
- package/dist/chunk-YKFTFYKK.mjs.map +0 -1
- package/dist/chunk-YNQ44U6D.mjs.map +0 -1
- package/dist/create-4LG4N2A4.js.map +0 -1
- package/dist/init-EKNL2SQE.js +0 -16
- package/dist/init-EKNL2SQE.js.map +0 -1
- package/dist/list-GIAXAAH5.js.map +0 -1
- package/dist/list-PFWV7IU6.mjs.map +0 -1
- package/dist/remove-U3PILQDV.js.map +0 -1
- package/dist/sync-FOW7DHAH.mjs.map +0 -1
- package/dist/sync-T3T22GVZ.js.map +0 -1
- /package/dist/{chunk-ZIULPOMQ.mjs.map → chunk-7MG7DGPP.mjs.map} +0 -0
- /package/dist/{chunk-DLJO7AK5.mjs.map → chunk-AD7QRYIJ.mjs.map} +0 -0
- /package/dist/{chunk-N2V6J3U2.mjs.map → chunk-FEL5FLHA.mjs.map} +0 -0
- /package/dist/{chunk-CU3443HD.mjs.map → chunk-URTD2WOC.mjs.map} +0 -0
- /package/dist/{login-BYLXS23I.mjs.map → login-3IM3PYSJ.mjs.map} +0 -0
package/dist/index.d.mts
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.mjs';
|
|
2
|
+
export { F as FilterableBatchSpanProcessor, L as LangWatchExporter, S as SpanProcessingExcludeRule, g as getLangWatchLogger, d as getLangWatchTracer } from './implementation-nE9dgTwc.mjs';
|
|
3
3
|
export { l as attributes } from './types-DRiQaKFG.mjs';
|
|
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-DbPAi4US.mjs';
|
|
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.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: {
|