@mate-academy/prompt-client 1.0.0 → 2.0.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 +127 -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 +170 -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,74 @@ 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`.
|
|
106
|
+
|
|
107
|
+
`LLMPromptListError` (thrown only by `listPrompts`, see [Catalog](#catalog-for-codegen))
|
|
108
|
+
sits outside this hierarchy on purpose: it is **label-scoped**, not
|
|
109
|
+
prompt-scoped, so it extends `Error` directly and carries `label` + `cause`
|
|
110
|
+
instead of `promptName`. A broad `catch (error) { if (error instanceof
|
|
111
|
+
LLMPromptError) ... }` will **not** catch it — handle it explicitly, or match on
|
|
112
|
+
`error.name === 'LLMPromptListError'`.
|
|
82
113
|
|
|
83
114
|
With `fallback` set, `getPrompt` never rejects: on any failure it resolves to
|
|
84
115
|
the fallback text with `version: 0` and `isFallback: true`, and the logger
|
|
85
116
|
receives a warning.
|
|
86
117
|
|
|
87
|
-
|
|
118
|
+
### Chat prompts
|
|
119
|
+
|
|
120
|
+
`getChatPrompt` is the additive counterpart of `getPrompt` for role-tagged
|
|
121
|
+
message prompts:
|
|
88
122
|
|
|
89
123
|
```typescript
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
input: inboundMessage,
|
|
124
|
+
const prompt = await promptClient.getChatPrompt('chatAgent.conversation', {
|
|
125
|
+
label: 'production',
|
|
126
|
+
fallback: [
|
|
127
|
+
{ role: LLMPromptMessageRoles.System, content: 'You are a helpful agent.' },
|
|
128
|
+
],
|
|
96
129
|
});
|
|
97
130
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
input: messages,
|
|
102
|
-
prompt, // links the generation to the Langfuse prompt version
|
|
103
|
-
});
|
|
131
|
+
prompt.messages; // LLMPromptMessage[] — { role, content }
|
|
132
|
+
prompt.compile({ leadName: 'Maria' }); // substitutes {{var}} in each message's content
|
|
133
|
+
```
|
|
104
134
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
135
|
+
Fallback is an `LLMPromptMessage[]` instead of a string, with the same
|
|
136
|
+
never-throw / `version: 0` / `isFallback: true` semantics as `getPrompt`.
|
|
137
|
+
Langfuse placeholder entries and messages with an unrecognized role are
|
|
138
|
+
silently skipped from `messages`/`compile()`, with a warning logged so the
|
|
139
|
+
gap is visible without breaking the call.
|
|
140
|
+
|
|
141
|
+
### Catalog (for codegen)
|
|
142
|
+
|
|
143
|
+
`listPrompts` and `getPromptRecord` expose the raw prompt catalog for
|
|
144
|
+
Langfuse-prompt codegen (the gateway's `generateSnapshot`):
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const { promptNames, page, totalPages } = await promptClient.listPrompts({
|
|
148
|
+
label: 'production',
|
|
149
|
+
page: 1, // default 1
|
|
150
|
+
pageSize: 100, // default 100
|
|
109
151
|
});
|
|
110
152
|
|
|
111
|
-
|
|
153
|
+
const record = await promptClient.getPromptRecord('chatAgent.instructions', {
|
|
154
|
+
label: 'production',
|
|
155
|
+
});
|
|
156
|
+
// record.type === LLMPromptTypes.Text | LLMPromptTypes.Chat
|
|
112
157
|
```
|
|
113
158
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
159
|
+
Both methods are uncached and never fall back — they **throw** on failure
|
|
160
|
+
(`LLMPromptListError` for `listPrompts`, `LLMPromptNotFoundError` /
|
|
161
|
+
`LLMPromptFetchError` for `getPromptRecord`) so a codegen run can fail loudly
|
|
162
|
+
in CI and fall back to the last-committed snapshot artifact instead of
|
|
163
|
+
silently baking in stale or partial data.
|
|
117
164
|
|
|
118
165
|
## Usage in a long-lived server (api)
|
|
119
166
|
|
|
120
167
|
A process can talk to several Langfuse projects. A project is a **runtime
|
|
121
168
|
argument, never baked into the client**: build one bundle per project (one
|
|
122
169
|
shared client each), memoize them behind a registry keyed by your own project
|
|
123
|
-
enum, and pass the project at the call site.
|
|
170
|
+
enum, and pass the project at the call site. Stop every live bundle on
|
|
124
171
|
SIGTERM.
|
|
125
172
|
|
|
126
173
|
```typescript
|
|
@@ -147,15 +194,15 @@ const getPromptManagement = (
|
|
|
147
194
|
};
|
|
148
195
|
|
|
149
196
|
// at a call site — pick the project you need:
|
|
150
|
-
const { promptClient
|
|
197
|
+
const { promptClient } = getPromptManagement(LangfuseProject.SalesQA);
|
|
151
198
|
|
|
152
199
|
// in graceful shutdown:
|
|
153
200
|
await Promise.all([...bundles.values()].map((bundle) => bundle.shutdown()));
|
|
154
201
|
```
|
|
155
202
|
|
|
156
|
-
Memoizing per project is correctness, not caching: each bundle owns a live
|
|
157
|
-
client
|
|
158
|
-
|
|
203
|
+
Memoizing per project is correctness, not caching: each bundle owns a live
|
|
204
|
+
SDK client, so the registry's `Map` is the client's lifetime — one client per
|
|
205
|
+
project per process.
|
|
159
206
|
|
|
160
207
|
Typed error handling keeps existing semantics: catch
|
|
161
208
|
`LLMPromptNotFoundError` for "is this conversation scorable?" probes and treat
|
|
@@ -163,10 +210,8 @@ Typed error handling keeps existing semantics: catch
|
|
|
163
210
|
|
|
164
211
|
## Usage in a Lambda
|
|
165
212
|
|
|
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:
|
|
213
|
+
Create the bundle at module scope so it stays warm across invocations, and
|
|
214
|
+
use per-prompt fallbacks so a Langfuse outage can never break a turn:
|
|
170
215
|
|
|
171
216
|
```typescript
|
|
172
217
|
const promptManagement = createPromptManagement({
|
|
@@ -177,21 +222,16 @@ const promptManagement = createPromptManagement({
|
|
|
177
222
|
secretKey: appConfig.langfuseSecretKey,
|
|
178
223
|
baseUrl: appConfig.langfuseBaseUrl,
|
|
179
224
|
},
|
|
180
|
-
flushAt: 1, // send events immediately; Lambdas have no idle time to batch
|
|
181
225
|
},
|
|
182
226
|
logger,
|
|
183
227
|
});
|
|
184
228
|
|
|
185
229
|
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
|
-
}
|
|
230
|
+
const prompt = await promptManagement.promptClient.getPrompt(
|
|
231
|
+
PromptKey.ChatAgentInstructions,
|
|
232
|
+
{ fallback: FALLBACKS[PromptKey.ChatAgentInstructions] },
|
|
233
|
+
);
|
|
234
|
+
// ... run the turn
|
|
195
235
|
};
|
|
196
236
|
```
|
|
197
237
|
|
|
@@ -204,30 +244,48 @@ const promptManagement = createPromptManagement({
|
|
|
204
244
|
prompts: {
|
|
205
245
|
'chatAgent.instructions': { prompt: 'Reply to {{leadName}}', version: 3 },
|
|
206
246
|
},
|
|
247
|
+
chatPrompts: {
|
|
248
|
+
'chatAgent.conversation': {
|
|
249
|
+
messages: [{ role: LLMPromptMessageRoles.System, content: 'Reply to {{leadName}}' }],
|
|
250
|
+
},
|
|
251
|
+
},
|
|
207
252
|
// GenerateStub: unknown names resolve to `Mock prompt for <name>`
|
|
208
253
|
missingPromptBehavior: InMemoryMissingPromptBehaviors.GenerateStub,
|
|
209
254
|
},
|
|
210
255
|
});
|
|
211
256
|
|
|
212
|
-
// The InMemory bundle is typed with the concrete
|
|
257
|
+
// The InMemory bundle is typed with the concrete class:
|
|
213
258
|
promptManagement.promptClient.setPrompt('closing', { prompt: 'Bye!' });
|
|
214
|
-
promptManagement.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
promptManagement.tracer.reset();
|
|
259
|
+
promptManagement.promptClient.setChatPrompt('closing.chat', {
|
|
260
|
+
messages: [{ role: LLMPromptMessageRoles.System, content: 'Bye!' }],
|
|
261
|
+
});
|
|
218
262
|
```
|
|
219
263
|
|
|
264
|
+
`listPrompts` / `getPromptRecord` on the InMemory client read only the
|
|
265
|
+
seeded prompts (labels default to `['production']`); `missingPromptBehavior`
|
|
266
|
+
never applies to `getPromptRecord` — a missing seed always throws
|
|
267
|
+
`LLMPromptNotFoundError`, since the catalog must report seeded truth for
|
|
268
|
+
codegen tests.
|
|
269
|
+
|
|
220
270
|
## Provider notes (Langfuse)
|
|
221
271
|
|
|
222
272
|
- `label` and `version` are mutually exclusive; when `version` is set the
|
|
223
273
|
label (including the `production` default) is omitted automatically.
|
|
224
274
|
- Fallback prompts have `version: 0` and `isFallback: true` (SDK semantics).
|
|
225
|
-
-
|
|
226
|
-
`
|
|
227
|
-
`
|
|
228
|
-
-
|
|
229
|
-
|
|
230
|
-
|
|
275
|
+
- Built on `@langfuse/client` v5. Error classification is **structural,
|
|
276
|
+
never `instanceof`**: v5's Fern-generated errors never assign a
|
|
277
|
+
distinctive `error.name` (every one reports `'Error'` at runtime), so
|
|
278
|
+
classification duck-types on `error.statusCode` — `404` maps to
|
|
279
|
+
`LLMPromptNotFoundError`, everything else to `LLMPromptFetchError`. This
|
|
280
|
+
survives a duplicate SDK copy in a webpack/serverless bundle, where
|
|
281
|
+
`instanceof` would silently fail.
|
|
282
|
+
- **Behavior change vs 1.x**: a non-404 HTTP error (5xx, 401, 403) on the
|
|
283
|
+
prompt endpoint now correctly classifies as `LLMPromptFetchError` instead
|
|
284
|
+
of falling into the default `LLMPromptNotFoundError` bucket.
|
|
285
|
+
- The SDK's `type: 'text' | 'chat'` option on `prompt.get` is a compile-time
|
|
286
|
+
overload discriminator only — the runtime still returns whatever prompt
|
|
287
|
+
the server has. `getPrompt` therefore still rejects a chat prompt (and
|
|
288
|
+
`getChatPrompt` a text prompt) with `LLMPromptFetchError`.
|
|
231
289
|
- No SDK types leak through the public API; a future SDK swap stays inside
|
|
232
290
|
this package.
|
|
233
291
|
|
|
@@ -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
|
}
|