@mate-academy/prompt-client 1.0.0 → 2.0.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 +120 -69
- package/dist/LLMPromptClient.constants.d.ts +2 -0
- package/dist/LLMPromptClient.constants.js +3 -1
- package/dist/LLMPromptClient.errors.d.ts +5 -0
- package/dist/LLMPromptClient.errors.js +10 -1
- package/dist/LLMPromptClient.typedefs.d.ts +88 -3
- package/dist/LLMPromptClient.typedefs.js +8 -1
- package/dist/PromptManagement.typedefs.d.ts +6 -5
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/providers/InMemory/InMemory.factory.js +1 -8
- package/dist/providers/InMemory/InMemory.typedefs.d.ts +9 -13
- package/dist/providers/InMemory/InMemoryPrompt.client.d.ts +14 -2
- package/dist/providers/InMemory/InMemoryPrompt.client.js +113 -0
- package/dist/providers/Langfuse/Langfuse.factory.js +7 -9
- package/dist/providers/Langfuse/Langfuse.helpers.d.ts +8 -1
- package/dist/providers/Langfuse/Langfuse.helpers.js +27 -11
- package/dist/providers/Langfuse/Langfuse.typedefs.d.ts +0 -2
- package/dist/providers/Langfuse/LangfusePrompt.client.d.ts +18 -5
- package/dist/providers/Langfuse/LangfusePrompt.client.js +169 -18
- package/dist/providers/Langfuse/LangfusePrompt.d.ts +13 -2
- package/dist/providers/Langfuse/LangfusePrompt.js +19 -1
- package/dist/utilities/index.d.ts +0 -1
- package/dist/utilities/index.js +0 -1
- package/package.json +3 -4
- package/dist/LLMTracer.errors.d.ts +0 -4
- package/dist/LLMTracer.errors.js +0 -11
- package/dist/LLMTracer.typedefs.d.ts +0 -45
- package/dist/LLMTracer.typedefs.js +0 -2
- package/dist/providers/InMemory/InMemoryTracer.client.d.ts +0 -15
- package/dist/providers/InMemory/InMemoryTracer.client.js +0 -63
- package/dist/providers/Langfuse/LangfuseTracer.client.d.ts +0 -13
- package/dist/providers/Langfuse/LangfuseTracer.client.js +0 -49
- package/dist/utilities/usageDetails/index.d.ts +0 -1
- package/dist/utilities/usageDetails/index.js +0 -17
- package/dist/utilities/usageDetails/usageDetails.helpers.d.ts +0 -17
- package/dist/utilities/usageDetails/usageDetails.helpers.js +0 -33
package/README.md
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# @mate-academy/prompt-client
|
|
2
2
|
|
|
3
|
-
Provider-agnostic LLM prompt management
|
|
4
|
-
|
|
5
|
-
caching, fallbacks
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
Provider-agnostic LLM **prompt management** client. Consumers code against
|
|
4
|
+
one stable interface — `LLMPromptClient` (fetch + compile text and chat
|
|
5
|
+
prompts, caching, fallbacks, a codegen-facing prompt catalog) — and pick a
|
|
6
|
+
provider from `PromptManagementProviders`. The provider can be swapped
|
|
7
|
+
without touching call sites.
|
|
8
8
|
|
|
9
9
|
Providers:
|
|
10
10
|
|
|
11
|
-
- **`Langfuse`** — the real provider
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
- **`Langfuse`** — the real provider, built on `@langfuse/client` v5.
|
|
12
|
+
- **`InMemory`** — a deterministic test double: seedable text and chat
|
|
13
|
+
prompts. Use it in unit/integration tests instead of hand-rolled mocks.
|
|
14
|
+
|
|
15
|
+
Tracing moved out of this package. `@mate-academy/llm-tracer` now hosts the
|
|
16
|
+
Langfuse tracer surface (traces, generations, usage/cost details); this
|
|
17
|
+
package stays prompts-only.
|
|
16
18
|
|
|
17
19
|
## Install
|
|
18
20
|
|
|
@@ -20,6 +22,28 @@ Providers:
|
|
|
20
22
|
npm install @mate-academy/prompt-client
|
|
21
23
|
```
|
|
22
24
|
|
|
25
|
+
## Migrating from 1.x
|
|
26
|
+
|
|
27
|
+
2.0.0 is a breaking release: the entire tracer surface was removed from this
|
|
28
|
+
package and moved to `@mate-academy/llm-tracer`. Update imports as follows:
|
|
29
|
+
|
|
30
|
+
| Removed from `prompt-client` | New home |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `LLMTracer`, `LLMTrace`, `LLMGeneration` | `@mate-academy/llm-tracer` |
|
|
33
|
+
| `LLMTraceOptions`, `LLMTraceUpdateOptions` | `@mate-academy/llm-tracer` |
|
|
34
|
+
| `LLMGenerationOptions`, `LLMGenerationEndOptions` | `@mate-academy/llm-tracer` |
|
|
35
|
+
| `LLMTracerError` | `@mate-academy/llm-tracer` |
|
|
36
|
+
| `InMemoryTracer`, `InMemoryRecordedTrace`, `InMemoryRecordedGeneration` | `@mate-academy/llm-tracer` |
|
|
37
|
+
| `usageToUsageDetails`, `costToCostDetails`, `LLMUsageInput`, `LLMCostInput` | `@mate-academy/llm-tracer` |
|
|
38
|
+
| `PromptManagementBundle.tracer` / `.flush()` | `@mate-academy/llm-tracer`'s own bundle |
|
|
39
|
+
| `LangfuseProviderOptions.flushAt` / `.flushIntervalMs` | `@mate-academy/llm-tracer`'s own provider options |
|
|
40
|
+
|
|
41
|
+
`getPrompt(name, options?)` itself is unchanged and byte-identical to 1.x —
|
|
42
|
+
only the surrounding bundle shape and the SDK underneath changed. Existing
|
|
43
|
+
1.x consumers (`api/src/gateways/PromptManagement/`,
|
|
44
|
+
`api/src/modules/salesQa/`, `serverless/services/sdrChatbot`) are unaffected
|
|
45
|
+
and keep running on the published 1.x line until they migrate.
|
|
46
|
+
|
|
23
47
|
## Quick start
|
|
24
48
|
|
|
25
49
|
```typescript
|
|
@@ -48,13 +72,12 @@ const instructions = prompt.compile({ leadName: 'Maria' });
|
|
|
48
72
|
|
|
49
73
|
| Member | Purpose |
|
|
50
74
|
|---|---|
|
|
51
|
-
| `promptClient` | `LLMPromptClient` — `getPrompt
|
|
52
|
-
| `
|
|
53
|
-
| `flush()` | Flush pending trace/generation events without shutting down |
|
|
54
|
-
| `shutdown()` | Flush and stop the underlying client (whole bundle) |
|
|
75
|
+
| `promptClient` | `LLMPromptClient` — `getPrompt`, `getChatPrompt`, `listPrompts`, `getPromptRecord`, `shutdown()` |
|
|
76
|
+
| `shutdown()` | Stop the underlying provider client |
|
|
55
77
|
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
There is no `flush()` on this bundle — a prompts-only client buffers
|
|
79
|
+
nothing. `promptClient.shutdown()` and `bundle.shutdown()` stop the same
|
|
80
|
+
shared client; prefer `bundle.shutdown()`.
|
|
58
81
|
|
|
59
82
|
## Prompts
|
|
60
83
|
|
|
@@ -77,50 +100,67 @@ Error model (only when NO `fallback` is provided):
|
|
|
77
100
|
|
|
78
101
|
- `LLMPromptNotFoundError` — the prompt does not exist (safe to use as an
|
|
79
102
|
existence probe).
|
|
80
|
-
- `LLMPromptFetchError` — infrastructure failure (network/HTTP) or a
|
|
81
|
-
prompt
|
|
103
|
+
- `LLMPromptFetchError` — infrastructure failure (network/HTTP) or a
|
|
104
|
+
wrong-shape prompt (a chat prompt fetched via `getPrompt`, or vice versa).
|
|
105
|
+
Both extend `LLMPromptError` and carry `promptName` + `cause`.
|
|
82
106
|
|
|
83
107
|
With `fallback` set, `getPrompt` never rejects: on any failure it resolves to
|
|
84
108
|
the fallback text with `version: 0` and `isFallback: true`, and the logger
|
|
85
109
|
receives a warning.
|
|
86
110
|
|
|
87
|
-
|
|
111
|
+
### Chat prompts
|
|
112
|
+
|
|
113
|
+
`getChatPrompt` is the additive counterpart of `getPrompt` for role-tagged
|
|
114
|
+
message prompts:
|
|
88
115
|
|
|
89
116
|
```typescript
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
input: inboundMessage,
|
|
117
|
+
const prompt = await promptClient.getChatPrompt('chatAgent.conversation', {
|
|
118
|
+
label: 'production',
|
|
119
|
+
fallback: [
|
|
120
|
+
{ role: LLMPromptMessageRoles.System, content: 'You are a helpful agent.' },
|
|
121
|
+
],
|
|
96
122
|
});
|
|
97
123
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
prompt.messages; // LLMPromptMessage[] — { role, content }
|
|
125
|
+
prompt.compile({ leadName: 'Maria' }); // substitutes {{var}} in each message's content
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Fallback is an `LLMPromptMessage[]` instead of a string, with the same
|
|
129
|
+
never-throw / `version: 0` / `isFallback: true` semantics as `getPrompt`.
|
|
130
|
+
Langfuse placeholder entries and messages with an unrecognized role are
|
|
131
|
+
silently skipped from `messages`/`compile()`, with a warning logged so the
|
|
132
|
+
gap is visible without breaking the call.
|
|
104
133
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
134
|
+
### Catalog (for codegen)
|
|
135
|
+
|
|
136
|
+
`listPrompts` and `getPromptRecord` expose the raw prompt catalog for
|
|
137
|
+
Langfuse-prompt codegen (the gateway's `generateSnapshot`):
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const { promptNames, page, totalPages } = await promptClient.listPrompts({
|
|
141
|
+
label: 'production',
|
|
142
|
+
page: 1, // default 1
|
|
143
|
+
pageSize: 100, // default 100
|
|
109
144
|
});
|
|
110
145
|
|
|
111
|
-
|
|
146
|
+
const record = await promptClient.getPromptRecord('chatAgent.instructions', {
|
|
147
|
+
label: 'production',
|
|
148
|
+
});
|
|
149
|
+
// record.type === LLMPromptTypes.Text | LLMPromptTypes.Chat
|
|
112
150
|
```
|
|
113
151
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
152
|
+
Both methods are uncached and never fall back — they **throw** on failure
|
|
153
|
+
(`LLMPromptListError` for `listPrompts`, `LLMPromptNotFoundError` /
|
|
154
|
+
`LLMPromptFetchError` for `getPromptRecord`) so a codegen run can fail loudly
|
|
155
|
+
in CI and fall back to the last-committed snapshot artifact instead of
|
|
156
|
+
silently baking in stale or partial data.
|
|
117
157
|
|
|
118
158
|
## Usage in a long-lived server (api)
|
|
119
159
|
|
|
120
160
|
A process can talk to several Langfuse projects. A project is a **runtime
|
|
121
161
|
argument, never baked into the client**: build one bundle per project (one
|
|
122
162
|
shared client each), memoize them behind a registry keyed by your own project
|
|
123
|
-
enum, and pass the project at the call site.
|
|
163
|
+
enum, and pass the project at the call site. Stop every live bundle on
|
|
124
164
|
SIGTERM.
|
|
125
165
|
|
|
126
166
|
```typescript
|
|
@@ -147,15 +187,15 @@ const getPromptManagement = (
|
|
|
147
187
|
};
|
|
148
188
|
|
|
149
189
|
// at a call site — pick the project you need:
|
|
150
|
-
const { promptClient
|
|
190
|
+
const { promptClient } = getPromptManagement(LangfuseProject.SalesQA);
|
|
151
191
|
|
|
152
192
|
// in graceful shutdown:
|
|
153
193
|
await Promise.all([...bundles.values()].map((bundle) => bundle.shutdown()));
|
|
154
194
|
```
|
|
155
195
|
|
|
156
|
-
Memoizing per project is correctness, not caching: each bundle owns a live
|
|
157
|
-
client
|
|
158
|
-
|
|
196
|
+
Memoizing per project is correctness, not caching: each bundle owns a live
|
|
197
|
+
SDK client, so the registry's `Map` is the client's lifetime — one client per
|
|
198
|
+
project per process.
|
|
159
199
|
|
|
160
200
|
Typed error handling keeps existing semantics: catch
|
|
161
201
|
`LLMPromptNotFoundError` for "is this conversation scorable?" probes and treat
|
|
@@ -163,10 +203,8 @@ Typed error handling keeps existing semantics: catch
|
|
|
163
203
|
|
|
164
204
|
## Usage in a Lambda
|
|
165
205
|
|
|
166
|
-
Create the bundle at module scope so it stays warm across invocations,
|
|
167
|
-
per-prompt fallbacks so a Langfuse outage can never break a turn
|
|
168
|
-
at the end of every invocation** — buffered trace events are lost when the
|
|
169
|
-
sandbox freezes:
|
|
206
|
+
Create the bundle at module scope so it stays warm across invocations, and
|
|
207
|
+
use per-prompt fallbacks so a Langfuse outage can never break a turn:
|
|
170
208
|
|
|
171
209
|
```typescript
|
|
172
210
|
const promptManagement = createPromptManagement({
|
|
@@ -177,21 +215,16 @@ const promptManagement = createPromptManagement({
|
|
|
177
215
|
secretKey: appConfig.langfuseSecretKey,
|
|
178
216
|
baseUrl: appConfig.langfuseBaseUrl,
|
|
179
217
|
},
|
|
180
|
-
flushAt: 1, // send events immediately; Lambdas have no idle time to batch
|
|
181
218
|
},
|
|
182
219
|
logger,
|
|
183
220
|
});
|
|
184
221
|
|
|
185
222
|
export const handler = async (event: SQSEvent): Promise<void> => {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
// ... run the turn, create trace/generations with sessionId: chatId
|
|
192
|
-
} finally {
|
|
193
|
-
await promptManagement.flush();
|
|
194
|
-
}
|
|
223
|
+
const prompt = await promptManagement.promptClient.getPrompt(
|
|
224
|
+
PromptKey.ChatAgentInstructions,
|
|
225
|
+
{ fallback: FALLBACKS[PromptKey.ChatAgentInstructions] },
|
|
226
|
+
);
|
|
227
|
+
// ... run the turn
|
|
195
228
|
};
|
|
196
229
|
```
|
|
197
230
|
|
|
@@ -204,30 +237,48 @@ const promptManagement = createPromptManagement({
|
|
|
204
237
|
prompts: {
|
|
205
238
|
'chatAgent.instructions': { prompt: 'Reply to {{leadName}}', version: 3 },
|
|
206
239
|
},
|
|
240
|
+
chatPrompts: {
|
|
241
|
+
'chatAgent.conversation': {
|
|
242
|
+
messages: [{ role: LLMPromptMessageRoles.System, content: 'Reply to {{leadName}}' }],
|
|
243
|
+
},
|
|
244
|
+
},
|
|
207
245
|
// GenerateStub: unknown names resolve to `Mock prompt for <name>`
|
|
208
246
|
missingPromptBehavior: InMemoryMissingPromptBehaviors.GenerateStub,
|
|
209
247
|
},
|
|
210
248
|
});
|
|
211
249
|
|
|
212
|
-
// The InMemory bundle is typed with the concrete
|
|
250
|
+
// The InMemory bundle is typed with the concrete class:
|
|
213
251
|
promptManagement.promptClient.setPrompt('closing', { prompt: 'Bye!' });
|
|
214
|
-
promptManagement.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
promptManagement.tracer.reset();
|
|
252
|
+
promptManagement.promptClient.setChatPrompt('closing.chat', {
|
|
253
|
+
messages: [{ role: LLMPromptMessageRoles.System, content: 'Bye!' }],
|
|
254
|
+
});
|
|
218
255
|
```
|
|
219
256
|
|
|
257
|
+
`listPrompts` / `getPromptRecord` on the InMemory client read only the
|
|
258
|
+
seeded prompts (labels default to `['production']`); `missingPromptBehavior`
|
|
259
|
+
never applies to `getPromptRecord` — a missing seed always throws
|
|
260
|
+
`LLMPromptNotFoundError`, since the catalog must report seeded truth for
|
|
261
|
+
codegen tests.
|
|
262
|
+
|
|
220
263
|
## Provider notes (Langfuse)
|
|
221
264
|
|
|
222
265
|
- `label` and `version` are mutually exclusive; when `version` is set the
|
|
223
266
|
label (including the `production` default) is omitted automatically.
|
|
224
267
|
- Fallback prompts have `version: 0` and `isFallback: true` (SDK semantics).
|
|
225
|
-
-
|
|
226
|
-
`
|
|
227
|
-
`
|
|
228
|
-
-
|
|
229
|
-
|
|
230
|
-
|
|
268
|
+
- Built on `@langfuse/client` v5. Error classification is **structural,
|
|
269
|
+
never `instanceof`**: v5's Fern-generated errors never assign a
|
|
270
|
+
distinctive `error.name` (every one reports `'Error'` at runtime), so
|
|
271
|
+
classification duck-types on `error.statusCode` — `404` maps to
|
|
272
|
+
`LLMPromptNotFoundError`, everything else to `LLMPromptFetchError`. This
|
|
273
|
+
survives a duplicate SDK copy in a webpack/serverless bundle, where
|
|
274
|
+
`instanceof` would silently fail.
|
|
275
|
+
- **Behavior change vs 1.x**: a non-404 HTTP error (5xx, 401, 403) on the
|
|
276
|
+
prompt endpoint now correctly classifies as `LLMPromptFetchError` instead
|
|
277
|
+
of falling into the default `LLMPromptNotFoundError` bucket.
|
|
278
|
+
- The SDK's `type: 'text' | 'chat'` option on `prompt.get` is a compile-time
|
|
279
|
+
overload discriminator only — the runtime still returns whatever prompt
|
|
280
|
+
the server has. `getPrompt` therefore still rejects a chat prompt (and
|
|
281
|
+
`getChatPrompt` a text prompt) with `LLMPromptFetchError`.
|
|
231
282
|
- No SDK types leak through the public API; a future SDK swap stays inside
|
|
232
283
|
this package.
|
|
233
284
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_PROMPT_CACHE_TTL_SECONDS = exports.DEFAULT_PROMPT_LABEL = void 0;
|
|
3
|
+
exports.DEFAULT_PROMPT_LIST_PAGE_SIZE = exports.DEFAULT_PROMPT_LIST_PAGE = exports.DEFAULT_PROMPT_CACHE_TTL_SECONDS = exports.DEFAULT_PROMPT_LABEL = void 0;
|
|
4
4
|
exports.DEFAULT_PROMPT_LABEL = 'production';
|
|
5
5
|
exports.DEFAULT_PROMPT_CACHE_TTL_SECONDS = 60;
|
|
6
|
+
exports.DEFAULT_PROMPT_LIST_PAGE = 1;
|
|
7
|
+
exports.DEFAULT_PROMPT_LIST_PAGE_SIZE = 100;
|
|
@@ -9,3 +9,8 @@ export declare class LLMPromptNotFoundError extends LLMPromptError {
|
|
|
9
9
|
export declare class LLMPromptFetchError extends LLMPromptError {
|
|
10
10
|
constructor(promptName: string, cause?: unknown);
|
|
11
11
|
}
|
|
12
|
+
export declare class LLMPromptListError extends Error {
|
|
13
|
+
readonly label: string;
|
|
14
|
+
readonly cause?: unknown | undefined;
|
|
15
|
+
constructor(label: string, cause?: unknown | undefined);
|
|
16
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LLMPromptFetchError = exports.LLMPromptNotFoundError = exports.LLMPromptError = void 0;
|
|
3
|
+
exports.LLMPromptListError = exports.LLMPromptFetchError = exports.LLMPromptNotFoundError = exports.LLMPromptError = void 0;
|
|
4
4
|
class LLMPromptError extends Error {
|
|
5
5
|
constructor(message, promptName, cause) {
|
|
6
6
|
super(message);
|
|
@@ -24,3 +24,12 @@ class LLMPromptFetchError extends LLMPromptError {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
exports.LLMPromptFetchError = LLMPromptFetchError;
|
|
27
|
+
class LLMPromptListError extends Error {
|
|
28
|
+
constructor(label, cause) {
|
|
29
|
+
super(`Failed to list LLM prompts for label: ${label}`);
|
|
30
|
+
this.label = label;
|
|
31
|
+
this.cause = cause;
|
|
32
|
+
this.name = 'LLMPromptListError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.LLMPromptListError = LLMPromptListError;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
export declare enum LLMPromptTypes {
|
|
2
|
-
Text = "text"
|
|
2
|
+
Text = "text",
|
|
3
|
+
Chat = "chat"
|
|
4
|
+
}
|
|
5
|
+
export declare enum LLMPromptMessageRoles {
|
|
6
|
+
System = "system",
|
|
7
|
+
User = "user",
|
|
8
|
+
Assistant = "assistant"
|
|
9
|
+
}
|
|
10
|
+
export interface LLMPromptMessage {
|
|
11
|
+
role: LLMPromptMessageRoles;
|
|
12
|
+
content: string;
|
|
3
13
|
}
|
|
4
14
|
export interface LLMPrompt {
|
|
5
15
|
name: string;
|
|
@@ -10,13 +20,88 @@ export interface LLMPrompt {
|
|
|
10
20
|
isFallback: boolean;
|
|
11
21
|
compile(variables?: Record<string, string>): string;
|
|
12
22
|
}
|
|
13
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A chat-shaped prompt: role-tagged messages instead of a single text
|
|
25
|
+
* template. Returned by `getChatPrompt`, the additive counterpart of
|
|
26
|
+
* `getPrompt` (which stays text-only).
|
|
27
|
+
*/
|
|
28
|
+
export interface LLMChatPrompt {
|
|
29
|
+
name: string;
|
|
30
|
+
version: number;
|
|
31
|
+
type: LLMPromptTypes;
|
|
32
|
+
messages: LLMPromptMessage[];
|
|
33
|
+
config: unknown;
|
|
34
|
+
isFallback: boolean;
|
|
35
|
+
compile(variables?: Record<string, string>): LLMPromptMessage[];
|
|
36
|
+
}
|
|
37
|
+
interface GetPromptCommonOptions {
|
|
38
|
+
cacheTtlSeconds?: number;
|
|
39
|
+
fallback?: string;
|
|
40
|
+
}
|
|
41
|
+
interface GetPromptByVersionOptions extends GetPromptCommonOptions {
|
|
14
42
|
version?: number;
|
|
43
|
+
label?: never;
|
|
44
|
+
}
|
|
45
|
+
interface GetPromptByLabelOptions extends GetPromptCommonOptions {
|
|
46
|
+
version?: never;
|
|
15
47
|
label?: string;
|
|
48
|
+
}
|
|
49
|
+
export type GetPromptOptions = GetPromptByVersionOptions | GetPromptByLabelOptions;
|
|
50
|
+
interface GetChatPromptCommonOptions {
|
|
16
51
|
cacheTtlSeconds?: number;
|
|
17
|
-
fallback?:
|
|
52
|
+
fallback?: LLMPromptMessage[];
|
|
53
|
+
}
|
|
54
|
+
interface GetChatPromptByVersionOptions extends GetChatPromptCommonOptions {
|
|
55
|
+
version?: number;
|
|
56
|
+
label?: never;
|
|
57
|
+
}
|
|
58
|
+
interface GetChatPromptByLabelOptions extends GetChatPromptCommonOptions {
|
|
59
|
+
version?: never;
|
|
60
|
+
label?: string;
|
|
61
|
+
}
|
|
62
|
+
export type GetChatPromptOptions = GetChatPromptByVersionOptions | GetChatPromptByLabelOptions;
|
|
63
|
+
export interface ListPromptsOptions {
|
|
64
|
+
label: string;
|
|
65
|
+
page?: number;
|
|
66
|
+
pageSize?: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One page of the prompt catalog: names only (the Langfuse list endpoint
|
|
70
|
+
* returns metadata without bodies) for codegen to iterate and resolve each
|
|
71
|
+
* name via `getPromptRecord`.
|
|
72
|
+
*/
|
|
73
|
+
export interface LLMPromptCatalogPage {
|
|
74
|
+
promptNames: string[];
|
|
75
|
+
page: number;
|
|
76
|
+
totalPages: number;
|
|
77
|
+
}
|
|
78
|
+
export interface GetPromptRecordOptions {
|
|
79
|
+
label: string;
|
|
80
|
+
}
|
|
81
|
+
interface LLMPromptRecordBase {
|
|
82
|
+
name: string;
|
|
83
|
+
version: number;
|
|
84
|
+
labels: string[];
|
|
85
|
+
config: unknown;
|
|
86
|
+
}
|
|
87
|
+
export interface LLMTextPromptRecord extends LLMPromptRecordBase {
|
|
88
|
+
type: LLMPromptTypes.Text;
|
|
89
|
+
text: string;
|
|
90
|
+
}
|
|
91
|
+
export interface LLMChatPromptRecord extends LLMPromptRecordBase {
|
|
92
|
+
type: LLMPromptTypes.Chat;
|
|
93
|
+
messages: LLMPromptMessage[];
|
|
18
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Uncached, no-fallback raw prompt record — the catalog truth codegen reads
|
|
97
|
+
* to regenerate the typed prompt registry. Never used on the hot path.
|
|
98
|
+
*/
|
|
99
|
+
export type LLMPromptRecord = LLMTextPromptRecord | LLMChatPromptRecord;
|
|
19
100
|
export interface LLMPromptClient {
|
|
20
101
|
getPrompt(name: string, options?: GetPromptOptions): Promise<LLMPrompt>;
|
|
102
|
+
getChatPrompt(name: string, options?: GetChatPromptOptions): Promise<LLMChatPrompt>;
|
|
103
|
+
listPrompts(options: ListPromptsOptions): Promise<LLMPromptCatalogPage>;
|
|
104
|
+
getPromptRecord(name: string, options: GetPromptRecordOptions): Promise<LLMPromptRecord>;
|
|
21
105
|
shutdown(): Promise<void>;
|
|
22
106
|
}
|
|
107
|
+
export {};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LLMPromptTypes = void 0;
|
|
3
|
+
exports.LLMPromptMessageRoles = exports.LLMPromptTypes = void 0;
|
|
4
4
|
var LLMPromptTypes;
|
|
5
5
|
(function (LLMPromptTypes) {
|
|
6
6
|
LLMPromptTypes["Text"] = "text";
|
|
7
|
+
LLMPromptTypes["Chat"] = "chat";
|
|
7
8
|
})(LLMPromptTypes || (exports.LLMPromptTypes = LLMPromptTypes = {}));
|
|
9
|
+
var LLMPromptMessageRoles;
|
|
10
|
+
(function (LLMPromptMessageRoles) {
|
|
11
|
+
LLMPromptMessageRoles["System"] = "system";
|
|
12
|
+
LLMPromptMessageRoles["User"] = "user";
|
|
13
|
+
LLMPromptMessageRoles["Assistant"] = "assistant";
|
|
14
|
+
})(LLMPromptMessageRoles || (exports.LLMPromptMessageRoles = LLMPromptMessageRoles = {}));
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { type LLMPromptClient } from './LLMPromptClient.typedefs';
|
|
2
|
-
import { type LLMTracer } from './LLMTracer.typedefs';
|
|
3
2
|
import { type InMemoryProviderOptions } from './providers/InMemory/InMemory.typedefs';
|
|
4
3
|
import { type InMemoryPromptClient } from './providers/InMemory/InMemoryPrompt.client';
|
|
5
|
-
import { type InMemoryTracer } from './providers/InMemory/InMemoryTracer.client';
|
|
6
4
|
import { type LangfuseProviderOptions } from './providers/Langfuse/Langfuse.typedefs';
|
|
7
5
|
import { type PromptManagementLogger } from './utilities/logger';
|
|
8
6
|
export declare enum PromptManagementProviders {
|
|
@@ -13,15 +11,18 @@ export interface PromptManagementProviderOptionsMap {
|
|
|
13
11
|
[PromptManagementProviders.Langfuse]: LangfuseProviderOptions;
|
|
14
12
|
[PromptManagementProviders.InMemory]: InMemoryProviderOptions;
|
|
15
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* A prompts-only bundle: one `LLMPromptClient` plus a single `shutdown`
|
|
16
|
+
* that stops the underlying provider client. No tracer, no `flush` — a
|
|
17
|
+
* prompts-only client buffers nothing (see `@mate-academy/llm-tracer` for
|
|
18
|
+
* tracing).
|
|
19
|
+
*/
|
|
16
20
|
export interface PromptManagementBundle {
|
|
17
21
|
promptClient: LLMPromptClient;
|
|
18
|
-
tracer: LLMTracer;
|
|
19
|
-
flush(): Promise<void>;
|
|
20
22
|
shutdown(): Promise<void>;
|
|
21
23
|
}
|
|
22
24
|
export interface InMemoryPromptManagementBundle extends PromptManagementBundle {
|
|
23
25
|
promptClient: InMemoryPromptClient;
|
|
24
|
-
tracer: InMemoryTracer;
|
|
25
26
|
}
|
|
26
27
|
export interface PromptManagementBundles {
|
|
27
28
|
[PromptManagementProviders.Langfuse]: PromptManagementBundle;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
export * from './LLMPromptClient.typedefs';
|
|
2
2
|
export * from './LLMPromptClient.constants';
|
|
3
3
|
export * from './LLMPromptClient.errors';
|
|
4
|
-
export * from './LLMTracer.typedefs';
|
|
5
|
-
export * from './LLMTracer.errors';
|
|
6
4
|
export * from './PromptManagement.typedefs';
|
|
7
5
|
export * from './PromptManagement.factory';
|
|
8
6
|
export * from './providers/Langfuse/Langfuse.typedefs';
|
|
9
7
|
export * from './providers/InMemory/InMemory.typedefs';
|
|
10
8
|
export * from './providers/InMemory/InMemoryPrompt.client';
|
|
11
|
-
export * from './providers/InMemory/InMemoryTracer.client';
|
|
12
9
|
export * from './utilities/logger';
|
|
13
10
|
export * from './utilities/template';
|
|
14
|
-
export * from './utilities/usageDetails';
|
package/dist/index.js
CHANGED
|
@@ -17,14 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./LLMPromptClient.typedefs"), exports);
|
|
18
18
|
__exportStar(require("./LLMPromptClient.constants"), exports);
|
|
19
19
|
__exportStar(require("./LLMPromptClient.errors"), exports);
|
|
20
|
-
__exportStar(require("./LLMTracer.typedefs"), exports);
|
|
21
|
-
__exportStar(require("./LLMTracer.errors"), exports);
|
|
22
20
|
__exportStar(require("./PromptManagement.typedefs"), exports);
|
|
23
21
|
__exportStar(require("./PromptManagement.factory"), exports);
|
|
24
22
|
__exportStar(require("./providers/Langfuse/Langfuse.typedefs"), exports);
|
|
25
23
|
__exportStar(require("./providers/InMemory/InMemory.typedefs"), exports);
|
|
26
24
|
__exportStar(require("./providers/InMemory/InMemoryPrompt.client"), exports);
|
|
27
|
-
__exportStar(require("./providers/InMemory/InMemoryTracer.client"), exports);
|
|
28
25
|
__exportStar(require("./utilities/logger"), exports);
|
|
29
26
|
__exportStar(require("./utilities/template"), exports);
|
|
30
|
-
__exportStar(require("./utilities/usageDetails"), exports);
|
|
@@ -2,18 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createInMemoryPromptManagement = void 0;
|
|
4
4
|
const InMemoryPrompt_client_1 = require("../../providers/InMemory/InMemoryPrompt.client");
|
|
5
|
-
const InMemoryTracer_client_1 = require("../../providers/InMemory/InMemoryTracer.client");
|
|
6
5
|
const createInMemoryPromptManagement = (options, _logger) => {
|
|
7
6
|
const promptClient = new InMemoryPrompt_client_1.InMemoryPromptClient(options);
|
|
8
|
-
const tracer = new InMemoryTracer_client_1.InMemoryTracer();
|
|
9
7
|
return {
|
|
10
8
|
promptClient,
|
|
11
|
-
|
|
12
|
-
flush: () => tracer.flush(),
|
|
13
|
-
shutdown: async () => {
|
|
14
|
-
await promptClient.shutdown();
|
|
15
|
-
await tracer.shutdown();
|
|
16
|
-
},
|
|
9
|
+
shutdown: () => promptClient.shutdown(),
|
|
17
10
|
};
|
|
18
11
|
};
|
|
19
12
|
exports.createInMemoryPromptManagement = createInMemoryPromptManagement;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type LLMPromptMessage } from '../../LLMPromptClient.typedefs';
|
|
2
2
|
export declare enum InMemoryMissingPromptBehaviors {
|
|
3
3
|
Throw = "Throw",
|
|
4
4
|
GenerateStub = "GenerateStub"
|
|
@@ -7,20 +7,16 @@ export interface InMemorySeedPrompt {
|
|
|
7
7
|
prompt: string;
|
|
8
8
|
version?: number;
|
|
9
9
|
config?: unknown;
|
|
10
|
+
labels?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface InMemorySeedChatPrompt {
|
|
13
|
+
messages: LLMPromptMessage[];
|
|
14
|
+
version?: number;
|
|
15
|
+
config?: unknown;
|
|
16
|
+
labels?: string[];
|
|
10
17
|
}
|
|
11
18
|
export interface InMemoryProviderOptions {
|
|
12
19
|
prompts?: Record<string, InMemorySeedPrompt>;
|
|
20
|
+
chatPrompts?: Record<string, InMemorySeedChatPrompt>;
|
|
13
21
|
missingPromptBehavior?: InMemoryMissingPromptBehaviors;
|
|
14
22
|
}
|
|
15
|
-
export interface InMemoryRecordedTrace {
|
|
16
|
-
id: string;
|
|
17
|
-
options: LLMTraceOptions;
|
|
18
|
-
updates: LLMTraceUpdateOptions[];
|
|
19
|
-
}
|
|
20
|
-
export interface InMemoryRecordedGeneration {
|
|
21
|
-
id: string;
|
|
22
|
-
traceId: string;
|
|
23
|
-
options: LLMGenerationOptions;
|
|
24
|
-
endOptions: LLMGenerationEndOptions | null;
|
|
25
|
-
isEnded: boolean;
|
|
26
|
-
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { type GetPromptOptions, type LLMPrompt, type LLMPromptClient } from '../../LLMPromptClient.typedefs';
|
|
2
|
-
import { type InMemoryProviderOptions, type InMemorySeedPrompt } from '../../providers/InMemory/InMemory.typedefs';
|
|
1
|
+
import { type GetChatPromptOptions, type GetPromptOptions, type GetPromptRecordOptions, type LLMChatPrompt, type LLMPrompt, type LLMPromptCatalogPage, type LLMPromptClient, type LLMPromptRecord, type ListPromptsOptions } from '../../LLMPromptClient.typedefs';
|
|
2
|
+
import { type InMemoryProviderOptions, type InMemorySeedChatPrompt, type InMemorySeedPrompt } from '../../providers/InMemory/InMemory.typedefs';
|
|
3
3
|
export declare class InMemoryPromptClient implements LLMPromptClient {
|
|
4
4
|
private readonly prompts;
|
|
5
|
+
private readonly chatPrompts;
|
|
5
6
|
private readonly missingPromptBehavior;
|
|
6
7
|
constructor(options: InMemoryProviderOptions);
|
|
7
8
|
getPrompt(name: string, options?: GetPromptOptions): Promise<LLMPrompt>;
|
|
9
|
+
getChatPrompt(name: string, options?: GetChatPromptOptions): Promise<LLMChatPrompt>;
|
|
10
|
+
listPrompts(options: ListPromptsOptions): Promise<LLMPromptCatalogPage>;
|
|
11
|
+
getPromptRecord(name: string, options: GetPromptRecordOptions): Promise<LLMPromptRecord>;
|
|
8
12
|
shutdown(): Promise<void>;
|
|
9
13
|
setPrompt(name: string, seedPrompt: InMemorySeedPrompt): void;
|
|
14
|
+
setChatPrompt(name: string, seedChatPrompt: InMemorySeedChatPrompt): void;
|
|
10
15
|
clear(): void;
|
|
11
16
|
private buildPrompt;
|
|
12
17
|
private buildFallbackPrompt;
|
|
18
|
+
private buildChatPrompt;
|
|
19
|
+
private buildFallbackChatPrompt;
|
|
20
|
+
private compileMessages;
|
|
21
|
+
private collectMatchingNames;
|
|
22
|
+
private matchesLabel;
|
|
23
|
+
private buildTextPromptRecord;
|
|
24
|
+
private buildChatPromptRecord;
|
|
13
25
|
}
|