@mate-academy/llm-gateway 7.5.0 → 8.0.0-canary.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 +164 -0
- package/dist/LLMService.typedefs.d.ts +13 -4
- package/dist/LLMService.typedefs.js.map +1 -1
- package/dist/advanced.d.ts +11 -0
- package/dist/advanced.js +32 -0
- package/dist/advanced.js.map +1 -0
- package/dist/client/codegen/extractVariables.d.ts +7 -0
- package/dist/client/codegen/extractVariables.js +21 -0
- package/dist/client/codegen/extractVariables.js.map +1 -0
- package/dist/client/codegen/fetchPromptRecords.d.ts +14 -0
- package/dist/client/codegen/fetchPromptRecords.js +95 -0
- package/dist/client/codegen/fetchPromptRecords.js.map +1 -0
- package/dist/client/codegen/generateSnapshot.d.ts +18 -0
- package/dist/client/codegen/generateSnapshot.js +32 -0
- package/dist/client/codegen/generateSnapshot.js.map +1 -0
- package/dist/client/codegen/index.d.ts +5 -0
- package/dist/client/codegen/index.js +22 -0
- package/dist/client/codegen/index.js.map +1 -0
- package/dist/client/codegen/promptName.d.ts +8 -0
- package/dist/client/codegen/promptName.js +21 -0
- package/dist/client/codegen/promptName.js.map +1 -0
- package/dist/client/codegen/renderSnapshot.d.ts +25 -0
- package/dist/client/codegen/renderSnapshot.js +157 -0
- package/dist/client/codegen/renderSnapshot.js.map +1 -0
- package/dist/client/createLLMClient.d.ts +44 -0
- package/dist/client/createLLMClient.js +323 -0
- package/dist/client/createLLMClient.js.map +1 -0
- package/dist/client/createLLMClient.typedefs.d.ts +89 -0
- package/dist/client/createLLMClient.typedefs.js +10 -0
- package/dist/client/createLLMClient.typedefs.js.map +1 -0
- package/dist/client/defineLLMPrompts.d.ts +37 -0
- package/dist/client/defineLLMPrompts.js +13 -0
- package/dist/client/defineLLMPrompts.js.map +1 -0
- package/dist/client/errors.d.ts +57 -0
- package/dist/client/errors.js +70 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.js +26 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/llmConfig.schema.d.ts +53 -0
- package/dist/client/llmConfig.schema.js +49 -0
- package/dist/client/llmConfig.schema.js.map +1 -0
- package/dist/client/promptRegistry.runtime.d.ts +111 -0
- package/dist/client/promptRegistry.runtime.js +241 -0
- package/dist/client/promptRegistry.runtime.js.map +1 -0
- package/dist/client/promptSnapshot.typedefs.d.ts +57 -0
- package/dist/client/promptSnapshot.typedefs.js +3 -0
- package/dist/client/promptSnapshot.typedefs.js.map +1 -0
- package/dist/client/traceIO.d.ts +13 -0
- package/dist/client/traceIO.js +44 -0
- package/dist/client/traceIO.js.map +1 -0
- package/dist/client/validationGate.d.ts +28 -0
- package/dist/client/validationGate.js +76 -0
- package/dist/client/validationGate.js.map +1 -0
- package/dist/codegen.d.ts +6 -0
- package/dist/codegen.js +23 -0
- package/dist/codegen.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js +2 -25
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js.map +1 -1
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.d.ts +1 -13
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js +42 -134
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js.map +1 -1
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js +24 -8
- package/dist/providers/LLMAPI/services/LLMAPICompletion.service.js.map +1 -1
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js +3 -27
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js.map +1 -1
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js +50 -17
- package/dist/providers/OpenAICompatible/OpenAICompatibleCompletion.service.js.map +1 -1
- package/dist/services/LLMBaseService.abstract.d.ts +27 -4
- package/dist/services/LLMBaseService.abstract.js +80 -7
- package/dist/services/LLMBaseService.abstract.js.map +1 -1
- package/dist/services/chatState/CompletionsChatState.d.ts +2 -10
- package/dist/services/chatState/CompletionsChatState.js +2 -2
- package/dist/services/chatState/CompletionsChatState.js.map +1 -1
- package/dist/services/chatState/index.d.ts +1 -1
- package/dist/services/chatState/index.js.map +1 -1
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/langfuse/LangfuseTracer.d.ts +46 -0
- package/dist/utilities/langfuse/LangfuseTracer.js +180 -0
- package/dist/utilities/langfuse/LangfuseTracer.js.map +1 -0
- package/dist/utilities/langfuse/createLangfuseTracer.d.ts +32 -0
- package/dist/utilities/langfuse/createLangfuseTracer.js +73 -0
- package/dist/utilities/langfuse/createLangfuseTracer.js.map +1 -0
- package/dist/utilities/langfuse/fallbackMetric.d.ts +21 -0
- package/dist/utilities/langfuse/fallbackMetric.js +24 -0
- package/dist/utilities/langfuse/fallbackMetric.js.map +1 -0
- package/dist/utilities/langfuse/index.d.ts +5 -0
- package/dist/utilities/langfuse/index.js +22 -0
- package/dist/utilities/langfuse/index.js.map +1 -0
- package/dist/utilities/langfuse/langfuse.typedefs.d.ts +57 -0
- package/dist/utilities/langfuse/langfuse.typedefs.js +9 -0
- package/dist/utilities/langfuse/langfuse.typedefs.js.map +1 -0
- package/dist/utilities/langfuse/withLLMTrace.d.ts +12 -0
- package/dist/utilities/langfuse/withLLMTrace.js +21 -0
- package/dist/utilities/langfuse/withLLMTrace.js.map +1 -0
- package/package.json +39 -1
package/README.md
CHANGED
|
@@ -59,6 +59,7 @@ npm install @mate-academy/llm-gateway
|
|
|
59
59
|
## Features
|
|
60
60
|
|
|
61
61
|
- Support for multiple LLM providers (OpenAI, Google Generative AI)
|
|
62
|
+
- **Langfuse Tracing**: Required, env-driven Langfuse observability constructed once per process. Generations, tool observations, usage, and cost are captured automatically at every LLM call; fire-and-forget so a tracing failure never blocks or fails a call. Disabled cleanly via the `LangfuseDisabled` token or absent env.
|
|
62
63
|
- **Structured Output**: Type-safe JSON responses with schema validation
|
|
63
64
|
- **Extensible Schema Architecture**: Driver pattern with provider-specific adapters
|
|
64
65
|
- **LLM Metrics & Reporting**: Comprehensive metrics collection with automatic cost calculation
|
|
@@ -79,6 +80,169 @@ npm install @mate-academy/llm-gateway
|
|
|
79
80
|
|
|
80
81
|
## Usage
|
|
81
82
|
|
|
83
|
+
### Langfuse Tracing
|
|
84
|
+
|
|
85
|
+
Tracing is configured from environment once per process at the composition root
|
|
86
|
+
(the consumer's DI container / serverless core) and injected — feature code never
|
|
87
|
+
touches Langfuse credentials. Construct it with `createLangfuseTracer`, which
|
|
88
|
+
reads the connection config and registers the active tracer. Missing credentials
|
|
89
|
+
or the explicit `LangfuseDisabled` token resolve to a no-op tracer, so nothing
|
|
90
|
+
breaks before rollout.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import {
|
|
94
|
+
createLangfuseTracer,
|
|
95
|
+
LangfuseDisabled,
|
|
96
|
+
withLLMTrace,
|
|
97
|
+
flushLLMTraces,
|
|
98
|
+
} from '@mate-academy/llm-gateway';
|
|
99
|
+
|
|
100
|
+
// Once per process, at the composition root:
|
|
101
|
+
const tracer = createLangfuseTracer(
|
|
102
|
+
process.env.LANGFUSE_PUBLIC_KEY
|
|
103
|
+
? {
|
|
104
|
+
baseUrl: process.env.LANGFUSE_BASE_URL,
|
|
105
|
+
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
|
106
|
+
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
107
|
+
environment: process.env.LANGFUSE_ENVIRONMENT,
|
|
108
|
+
// 'batched' for long-running processes, 'immediate' for Lambda
|
|
109
|
+
exportMode: 'batched',
|
|
110
|
+
}
|
|
111
|
+
: LangfuseDisabled,
|
|
112
|
+
);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Once constructed, every gateway completion / assistance call emits a Langfuse
|
|
116
|
+
`generation` observation (full prompt/completion content, model, params, usage,
|
|
117
|
+
cost) at the same success/error points the metrics reporter already wraps;
|
|
118
|
+
assistance tool loops emit a child `tool` observation per tool call. All of this
|
|
119
|
+
is fire-and-forget — a Langfuse failure never blocks or fails an LLM call.
|
|
120
|
+
|
|
121
|
+
For code outside a traced base class, wrap work in a trace so nested gateway
|
|
122
|
+
calls attach to it automatically:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
await withLLMTrace('my-operation', { feature: 'city-prediction' }, async () => {
|
|
126
|
+
// gateway calls here nest under the trace via OTel context
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Short-lived processes (Lambdas, scripts) must flush before exit, since buffered
|
|
131
|
+
events are lost otherwise:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
await flushLLMTraces(); // alias of the SDK forceFlush; safe no-op when disabled
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The CloudWatch fallback-serving metric (`LangfuseFallbackServed`, namespace
|
|
138
|
+
`LLMGateway`) is exposed via `emitLangfuseFallbackServed`; inject a real emitter
|
|
139
|
+
with `setFallbackMetricEmitter` at the composition root (defaults to a no-op so
|
|
140
|
+
the package carries no AWS dependency).
|
|
141
|
+
|
|
142
|
+
To assert emitted observations in tests, inject an OTel `InMemorySpanExporter`
|
|
143
|
+
via the `spanExporter` config field (export mode defaults to `immediate` when one
|
|
144
|
+
is set, so `flush()` makes spans available synchronously):
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { InMemorySpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
148
|
+
|
|
149
|
+
const exporter = new InMemorySpanExporter();
|
|
150
|
+
const tracer = createLangfuseTracer({ ...config, spanExporter: exporter });
|
|
151
|
+
|
|
152
|
+
await tracer.withTrace('MyUseCase', {}, async () => {
|
|
153
|
+
// ... gateway calls ...
|
|
154
|
+
});
|
|
155
|
+
await tracer.flush();
|
|
156
|
+
|
|
157
|
+
const names = exporter.getFinishedSpans().map((span) => span.name);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### v2 Client (`createLLMClient`)
|
|
161
|
+
|
|
162
|
+
The v2 client is the prompt-name-first call surface. A call site names the
|
|
163
|
+
operation (the Langfuse prompt name); everything else — prompt text, model,
|
|
164
|
+
provider, params, credentials, reporter wiring, tracing, structured output —
|
|
165
|
+
resolves from it inside the package. Build it once at the composition root and
|
|
166
|
+
inject it via DI; feature code never sees configuration or credentials.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import {
|
|
170
|
+
createLLMClient,
|
|
171
|
+
defineLLMPrompts,
|
|
172
|
+
LLMSchema,
|
|
173
|
+
} from '@mate-academy/llm-gateway';
|
|
174
|
+
import { LLMPrompt, langfusePromptSnapshot } from './langfusePrompts.generated';
|
|
175
|
+
|
|
176
|
+
const llmPromptRegistry = defineLLMPrompts({
|
|
177
|
+
[LLMPrompt.CityPredictionPredictCityName]: {
|
|
178
|
+
schema: LLMSchema.object({ cityName: LLMSchema.string().nullable() }),
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const llm = createLLMClient({
|
|
183
|
+
registry: llmPromptRegistry,
|
|
184
|
+
snapshot: langfusePromptSnapshot,
|
|
185
|
+
credentials: async ({ provider, promptName, product }) => providerOptions,
|
|
186
|
+
reporting: { reporter },
|
|
187
|
+
logger,
|
|
188
|
+
context: { product, appEnvironment },
|
|
189
|
+
mode: 'production',
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const { cityName } = await llm.generate(
|
|
193
|
+
LLMPrompt.CityPredictionPredictCityName,
|
|
194
|
+
{ variables: { locationName, countryName }, context: { userId } },
|
|
195
|
+
);
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
- **Typed end to end.** The client is generic over `typeof registry`. Variables
|
|
199
|
+
are typed from the generated snapshot (strict on required names, tolerant of
|
|
200
|
+
extras so a Langfuse edit can never break a build); the return type is the
|
|
201
|
+
bound schema's inferred type, or `string` when no schema is bound.
|
|
202
|
+
- **Single validation gate on every fetch.** Vars subset, `config` zod-parse,
|
|
203
|
+
provider/model in the gateway map, param ceilings, and the resolved model's
|
|
204
|
+
capabilities vs the registry `requires`. Any failure serves the last-known-good
|
|
205
|
+
snapshot and emits the `LangfuseFallbackServed` metric; `LLMConfigError` throws
|
|
206
|
+
only when the live config and the fallback are both unusable.
|
|
207
|
+
- **Errors throw with a taxonomy** (`LLMGatewayError` base + `LLMProviderError`,
|
|
208
|
+
`LLMSchemaValidationError`, `LLMAbortedError`, `LLMConfigError`); validated
|
|
209
|
+
`data` is the return value, never an `'error' in response` union.
|
|
210
|
+
- **Override gating.** `mode: 'production'` rejects per-call `overrides` with
|
|
211
|
+
`LLMConfigError`; only `mode: 'experiment'` (harness/playground/tests) honors
|
|
212
|
+
them.
|
|
213
|
+
- **Chat-type prompts.** A prompt seeded as a Langfuse `chat` prompt binds with
|
|
214
|
+
`kind: 'chat'`. `compile()` produces a role-tagged message array with variables
|
|
215
|
+
substituted across every message; at call time a leading `system` message maps
|
|
216
|
+
to the provider's instructions slot and the final `user` message is the request,
|
|
217
|
+
preserving the message structure the prompt declares (plan §1.2). The validation
|
|
218
|
+
gate checks the variable subset across all message contents.
|
|
219
|
+
- **Per-call schema override.** Pass `schema` in the `generate` options to override
|
|
220
|
+
the registry binding's schema for one call; the return type follows the call-site
|
|
221
|
+
schema. Use it when the output contract is dynamic (e.g. a schema whose shape
|
|
222
|
+
depends on runtime input). A binding may omit `schema` when callers always pass
|
|
223
|
+
one. The schema is the code-owned output contract, honored in every mode.
|
|
224
|
+
- **`describePrompt(name)`.** Read-only accessor returning the
|
|
225
|
+
`{ provider, model, promptVersion, isFallback }` the runtime would serve right
|
|
226
|
+
now (same resolve/cache/fallback path as `generate`, no provider call). Use it
|
|
227
|
+
where analytics events need the resolved model name — keeping it off `generate`'s
|
|
228
|
+
data-only return.
|
|
229
|
+
|
|
230
|
+
#### Prompt snapshot codegen
|
|
231
|
+
|
|
232
|
+
`langfusePrompts.generated.ts` is produced by `npm run langfuse:generate` (root),
|
|
233
|
+
which fetches every labeled prompt and emits the `LLMPrompt` enum, per-prompt
|
|
234
|
+
variable unions, typed `compile()` helpers, and the snapshot used as the outage
|
|
235
|
+
fallback. It is gitignored exactly like GraphQL generated files: regenerated
|
|
236
|
+
locally on demand, in CI before image builds (with a cached-artifact fallback so a
|
|
237
|
+
Langfuse outage never fails a build), and refreshed non-blocking at API pod boot.
|
|
238
|
+
|
|
239
|
+
#### Escape hatch
|
|
240
|
+
|
|
241
|
+
`@mate-academy/llm-gateway/advanced` re-exports `LLMServiceFactory`, the provider
|
|
242
|
+
services, and the model maps for the rare call site needing raw control. It
|
|
243
|
+
bypasses prompt management, the validation gate, and config-in-prompt routing —
|
|
244
|
+
prefer the v2 client.
|
|
245
|
+
|
|
82
246
|
### Logger Interface
|
|
83
247
|
|
|
84
248
|
The package accepts an optional logger that implements the `LLMLoggerInterface` interface. Most logging libraries are compatible (`@mate-academy/logger`, winston, pino, etc.). If no logger is provided, no logging will occur.
|
|
@@ -248,6 +248,11 @@ export type LLMCompletionResult = LLMRequestResult<{
|
|
|
248
248
|
*/
|
|
249
249
|
export type LLMMethodBaseOptions<Reporter extends LLMReporterInterface<any> | undefined> = {
|
|
250
250
|
abortSignal?: AbortSignal;
|
|
251
|
+
/**
|
|
252
|
+
* Per-call Langfuse trace context. The prompt name (PR2) names the generation
|
|
253
|
+
* observation; absent it, the base service falls back to `<service>/<method>`.
|
|
254
|
+
*/
|
|
255
|
+
traceContext?: LLMCallTraceContext;
|
|
251
256
|
} & (Reporter extends LLMReporterInterface<infer R> ? R extends undefined ? {
|
|
252
257
|
reporterContext?: never;
|
|
253
258
|
} : {
|
|
@@ -255,6 +260,14 @@ export type LLMMethodBaseOptions<Reporter extends LLMReporterInterface<any> | un
|
|
|
255
260
|
} : {
|
|
256
261
|
reporterContext?: never;
|
|
257
262
|
});
|
|
263
|
+
/**
|
|
264
|
+
* Per-call trace context threaded into a single gateway call. PR2 supplies the
|
|
265
|
+
* prompt name; PR1 only wires the threading.
|
|
266
|
+
*/
|
|
267
|
+
export type LLMCallTraceContext = {
|
|
268
|
+
promptName?: string;
|
|
269
|
+
metadata?: Record<string, string | number | boolean>;
|
|
270
|
+
};
|
|
258
271
|
/**
|
|
259
272
|
* Options for sending a message to an LLM service.
|
|
260
273
|
* @template Provider - The LLM provider type
|
|
@@ -274,8 +287,6 @@ export type LLMStructuredResult<T = any> = LLMRequestResult<{
|
|
|
274
287
|
text: string;
|
|
275
288
|
data?: T;
|
|
276
289
|
parseError?: string;
|
|
277
|
-
toolIterationsUsed?: number;
|
|
278
|
-
toolIterationsExhausted?: true;
|
|
279
290
|
}>;
|
|
280
291
|
/**
|
|
281
292
|
* Limits for files that can be uploaded to LLM services.
|
|
@@ -390,8 +401,6 @@ export type LLMAssistanceOptions<Provider extends LLMProviders, Reporter extends
|
|
|
390
401
|
*/
|
|
391
402
|
export type LLMAssistanceResult = LLMRequestResult<{
|
|
392
403
|
text: string;
|
|
393
|
-
toolIterationsUsed?: number;
|
|
394
|
-
toolIterationsExhausted?: true;
|
|
395
404
|
}>;
|
|
396
405
|
/**
|
|
397
406
|
* Options for a one-shot prompt in a newly created chat.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LLMService.typedefs.js","sourceRoot":"","sources":["../src/LLMService.typedefs.ts"],"names":[],"mappings":";;;AAkCA;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,yDAAyC,CAAA;IACzC,iCAAiB,CAAA;AACnB,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB;AAoBD;;GAEG;AACH,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,wCAAyB,CAAA;IACzB,8CAA+B,CAAA;IAC/B,8CAA+B,CAAA;AACjC,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAiLD;;GAEG;AACH,IAAY,QAGX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iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,iDAAuB,CAAA;AACzB,CAAC,EAfW,sBAAsB,sCAAtB,sBAAsB,QAejC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape hatch entry point. Re-exports the internal engine — `LLMServiceFactory`,
|
|
3
|
+
* the provider services, and the model maps — for the rare call site that needs
|
|
4
|
+
* raw control the v2 client does not expose. Discouraged: prefer `createLLMClient`
|
|
5
|
+
* + the typed registry. This surface bypasses prompt management, the validation
|
|
6
|
+
* gate, and config-in-prompt routing.
|
|
7
|
+
*/
|
|
8
|
+
export { LLMServiceFactory } from './LLMService.factory';
|
|
9
|
+
export { LLM_SERVICE_FACTORIES, LLM_SERVICE_MODELS, } from './LLMService.constants';
|
|
10
|
+
export * from './providers';
|
|
11
|
+
export * from './services';
|
package/dist/advanced.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.LLM_SERVICE_MODELS = exports.LLM_SERVICE_FACTORIES = exports.LLMServiceFactory = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Escape hatch entry point. Re-exports the internal engine — `LLMServiceFactory`,
|
|
20
|
+
* the provider services, and the model maps — for the rare call site that needs
|
|
21
|
+
* raw control the v2 client does not expose. Discouraged: prefer `createLLMClient`
|
|
22
|
+
* + the typed registry. This surface bypasses prompt management, the validation
|
|
23
|
+
* gate, and config-in-prompt routing.
|
|
24
|
+
*/
|
|
25
|
+
var LLMService_factory_1 = require("./LLMService.factory");
|
|
26
|
+
Object.defineProperty(exports, "LLMServiceFactory", { enumerable: true, get: function () { return LLMService_factory_1.LLMServiceFactory; } });
|
|
27
|
+
var LLMService_constants_1 = require("./LLMService.constants");
|
|
28
|
+
Object.defineProperty(exports, "LLM_SERVICE_FACTORIES", { enumerable: true, get: function () { return LLMService_constants_1.LLM_SERVICE_FACTORIES; } });
|
|
29
|
+
Object.defineProperty(exports, "LLM_SERVICE_MODELS", { enumerable: true, get: function () { return LLMService_constants_1.LLM_SERVICE_MODELS; } });
|
|
30
|
+
__exportStar(require("./providers"), exports);
|
|
31
|
+
__exportStar(require("./services"), exports);
|
|
32
|
+
//# sourceMappingURL=advanced.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.js","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,2DAAyD;AAAhD,uHAAA,iBAAiB,OAAA;AAC1B,+DAGgC;AAF9B,6HAAA,qBAAqB,OAAA;AACrB,0HAAA,kBAAkB,OAAA;AAEpB,8CAA4B;AAC5B,6CAA2B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the plain variable names a prompt references, matching the runtime
|
|
3
|
+
* compile path (only `{{var}}` survives the conditional drop, see plan §1.3).
|
|
4
|
+
* Section/closer tokens (`{{#cond}}`, `{{/cond}}`) are excluded so the generated
|
|
5
|
+
* required-variable set agrees with what the validation gate counts as provided.
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractRequiredVariables(promptText: string): string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractRequiredVariables = extractRequiredVariables;
|
|
4
|
+
const VARIABLE_PATTERN = /{{\s*([\w.]+)\s*}}/g;
|
|
5
|
+
/**
|
|
6
|
+
* Extracts the plain variable names a prompt references, matching the runtime
|
|
7
|
+
* compile path (only `{{var}}` survives the conditional drop, see plan §1.3).
|
|
8
|
+
* Section/closer tokens (`{{#cond}}`, `{{/cond}}`) are excluded so the generated
|
|
9
|
+
* required-variable set agrees with what the validation gate counts as provided.
|
|
10
|
+
*/
|
|
11
|
+
function extractRequiredVariables(promptText) {
|
|
12
|
+
const names = new Set();
|
|
13
|
+
for (const match of promptText.matchAll(VARIABLE_PATTERN)) {
|
|
14
|
+
const token = match[1];
|
|
15
|
+
if (!token.startsWith('#') && !token.startsWith('/')) {
|
|
16
|
+
names.add(token);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return [...names].sort();
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=extractVariables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractVariables.js","sourceRoot":"","sources":["../../../src/client/codegen/extractVariables.ts"],"names":[],"mappings":";;AAQA,4DAYC;AApBD,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAE/C;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,UAAkB;IACzD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAEvB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type LangfuseClient } from '@langfuse/client';
|
|
2
|
+
import { type CodegenPromptRecord } from '../../client/codegen/renderSnapshot';
|
|
3
|
+
export interface FetchPromptRecordsOptions {
|
|
4
|
+
label: string;
|
|
5
|
+
onWarn?: (message: string) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Fetches every prompt that carries the given label from the Langfuse project and
|
|
9
|
+
* shapes it into a codegen record. A prompt whose `config` does not satisfy the
|
|
10
|
+
* gateway schema is skipped with a warning rather than failing the build — the
|
|
11
|
+
* governor (PR3) is the edit-time gate; codegen never crashes on a bad live
|
|
12
|
+
* config so a Langfuse edit can never break a build.
|
|
13
|
+
*/
|
|
14
|
+
export declare function fetchPromptRecords(client: LangfuseClient, options: FetchPromptRecordsOptions): Promise<CodegenPromptRecord[]>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchPromptRecords = fetchPromptRecords;
|
|
4
|
+
const llmConfig_schema_1 = require("../../client/llmConfig.schema");
|
|
5
|
+
const extractVariables_1 = require("../../client/codegen/extractVariables");
|
|
6
|
+
const CHAT_MESSAGE_ROLES = [
|
|
7
|
+
'system',
|
|
8
|
+
'user',
|
|
9
|
+
'assistant',
|
|
10
|
+
];
|
|
11
|
+
const DEFAULT_PAGE_SIZE = 100;
|
|
12
|
+
/**
|
|
13
|
+
* Fetches every prompt that carries the given label from the Langfuse project and
|
|
14
|
+
* shapes it into a codegen record. A prompt whose `config` does not satisfy the
|
|
15
|
+
* gateway schema is skipped with a warning rather than failing the build — the
|
|
16
|
+
* governor (PR3) is the edit-time gate; codegen never crashes on a bad live
|
|
17
|
+
* config so a Langfuse edit can never break a build.
|
|
18
|
+
*/
|
|
19
|
+
async function fetchPromptRecords(client, options) {
|
|
20
|
+
const names = await listPromptNames(client, options.label);
|
|
21
|
+
const records = [];
|
|
22
|
+
for (const name of names) {
|
|
23
|
+
const record = await fetchSingleRecord(client, name, options);
|
|
24
|
+
if (record) {
|
|
25
|
+
records.push(record);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return records;
|
|
29
|
+
}
|
|
30
|
+
async function listPromptNames(client, label) {
|
|
31
|
+
const names = [];
|
|
32
|
+
const collectPage = async (page) => {
|
|
33
|
+
const response = await client.api.prompts.list({
|
|
34
|
+
label,
|
|
35
|
+
page,
|
|
36
|
+
limit: DEFAULT_PAGE_SIZE,
|
|
37
|
+
});
|
|
38
|
+
for (const meta of response.data) {
|
|
39
|
+
names.push(meta.name);
|
|
40
|
+
}
|
|
41
|
+
return response.meta.totalPages;
|
|
42
|
+
};
|
|
43
|
+
const totalPages = await collectPage(1);
|
|
44
|
+
for (let page = 2; page <= totalPages; page += 1) {
|
|
45
|
+
await collectPage(page);
|
|
46
|
+
}
|
|
47
|
+
return names;
|
|
48
|
+
}
|
|
49
|
+
async function fetchSingleRecord(client, name, options) {
|
|
50
|
+
const prompt = await client.api.prompts.get(name, { label: options.label });
|
|
51
|
+
const parsedConfig = llmConfig_schema_1.llmPromptConfigSchema.safeParse(prompt.config);
|
|
52
|
+
if (!parsedConfig.success) {
|
|
53
|
+
options.onWarn?.(`Skipping "${name}": config does not satisfy the gateway schema `
|
|
54
|
+
+ `(${parsedConfig.error.issues.map((issue) => issue.message).join('; ')})`);
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const kind = prompt.type;
|
|
58
|
+
const fallbackText = kind === 'text' ? String(prompt.prompt) : '';
|
|
59
|
+
const fallbackMessages = kind === 'chat' ? toFallbackMessages(prompt.prompt) : [];
|
|
60
|
+
const variableSource = kind === 'chat'
|
|
61
|
+
? fallbackMessages.map((message) => message.content).join('\n')
|
|
62
|
+
: fallbackText;
|
|
63
|
+
return {
|
|
64
|
+
name,
|
|
65
|
+
kind,
|
|
66
|
+
version: prompt.version,
|
|
67
|
+
labels: prompt.labels,
|
|
68
|
+
requiredVariables: (0, extractVariables_1.extractRequiredVariables)(variableSource),
|
|
69
|
+
fallbackText,
|
|
70
|
+
fallbackMessages,
|
|
71
|
+
config: parsedConfig.data,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function toFallbackMessages(promptBody) {
|
|
75
|
+
if (!Array.isArray(promptBody)) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
return promptBody.flatMap((message) => {
|
|
79
|
+
if (!isRecord(message)) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
const role = String(message.role ?? '');
|
|
83
|
+
if (!isKnownRole(role)) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
return [{ role, content: String(message.content ?? '') }];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function isKnownRole(role) {
|
|
90
|
+
return CHAT_MESSAGE_ROLES.includes(role);
|
|
91
|
+
}
|
|
92
|
+
function isRecord(value) {
|
|
93
|
+
return typeof value === 'object' && value !== null;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=fetchPromptRecords.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchPromptRecords.js","sourceRoot":"","sources":["../../../src/client/codegen/fetchPromptRecords.ts"],"names":[],"mappings":";;AA8BA,gDAgBC;AA7CD,gEAAkE;AAMlE,wEAA6E;AAG7E,MAAM,kBAAkB,GAAoC;IAC1D,QAAQ;IACR,MAAM;IACN,WAAW;CACZ,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAO9B;;;;;;GAMG;AACI,KAAK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AgB;QAChB,MAAM,EAAE,YAAY,CAAC,IAAI;KAC1B,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAmB;IAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACpC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACvB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAExC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAQ,kBAAwC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface GenerateSnapshotOptions {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
publicKey: string;
|
|
4
|
+
secretKey: string;
|
|
5
|
+
label: string;
|
|
6
|
+
outputPath: string;
|
|
7
|
+
onLog?: (message: string) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The codegen entry point invoked by `npm run langfuse:generate`. Lists labeled
|
|
11
|
+
* prompts from the project, validates each config, renders the snapshot file, and
|
|
12
|
+
* writes it to `outputPath`. An empty project is valid: it produces an empty but
|
|
13
|
+
* type-correct snapshot. The caller owns the CI cached-artifact fallback (this
|
|
14
|
+
* throws on an unreachable Langfuse host so the caller can fall back).
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateSnapshot(options: GenerateSnapshotOptions): Promise<{
|
|
17
|
+
promptCount: number;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSnapshot = generateSnapshot;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const client_1 = require("@langfuse/client");
|
|
6
|
+
const fetchPromptRecords_1 = require("../../client/codegen/fetchPromptRecords");
|
|
7
|
+
const renderSnapshot_1 = require("../../client/codegen/renderSnapshot");
|
|
8
|
+
/**
|
|
9
|
+
* The codegen entry point invoked by `npm run langfuse:generate`. Lists labeled
|
|
10
|
+
* prompts from the project, validates each config, renders the snapshot file, and
|
|
11
|
+
* writes it to `outputPath`. An empty project is valid: it produces an empty but
|
|
12
|
+
* type-correct snapshot. The caller owns the CI cached-artifact fallback (this
|
|
13
|
+
* throws on an unreachable Langfuse host so the caller can fall back).
|
|
14
|
+
*/
|
|
15
|
+
async function generateSnapshot(options) {
|
|
16
|
+
const log = options.onLog ?? (() => undefined);
|
|
17
|
+
const client = new client_1.LangfuseClient({
|
|
18
|
+
baseUrl: options.baseUrl,
|
|
19
|
+
publicKey: options.publicKey,
|
|
20
|
+
secretKey: options.secretKey,
|
|
21
|
+
});
|
|
22
|
+
log(`Fetching prompts labeled "${options.label}" from ${options.baseUrl}`);
|
|
23
|
+
const records = await (0, fetchPromptRecords_1.fetchPromptRecords)(client, {
|
|
24
|
+
label: options.label,
|
|
25
|
+
onWarn: (message) => log(message),
|
|
26
|
+
});
|
|
27
|
+
const fileContent = (0, renderSnapshot_1.renderSnapshotFile)(records, { onWarn: (message) => log(message) });
|
|
28
|
+
(0, node_fs_1.writeFileSync)(options.outputPath, fileContent, 'utf8');
|
|
29
|
+
log(`Wrote ${records.length} prompt(s) to ${options.outputPath}`);
|
|
30
|
+
return { promptCount: records.length };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=generateSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSnapshot.js","sourceRoot":"","sources":["../../../src/client/codegen/generateSnapshot.ts"],"names":[],"mappings":";;AAqBA,4CAwBC;AA7CD,qCAAwC;AACxC,6CAAkD;AAClD,4EAAyE;AACzE,oEAAqE;AAWrE;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CACpC,OAAgC;IAEhC,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,IAAI,uBAAc,CAAC;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAC;IAEH,GAAG,CAAC,6BAA6B,OAAO,CAAC,KAAK,UAAU,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAE3E,MAAM,OAAO,GAAG,MAAM,IAAA,uCAAkB,EAAC,MAAM,EAAE;QAC/C,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;KAClC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,IAAA,mCAAkB,EAAC,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAEvF,IAAA,uBAAa,EAAC,OAAO,CAAC,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IAEvD,GAAG,CAAC,SAAS,OAAO,CAAC,MAAM,iBAAiB,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAElE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./extractVariables"), exports);
|
|
18
|
+
__exportStar(require("./promptName"), exports);
|
|
19
|
+
__exportStar(require("./renderSnapshot"), exports);
|
|
20
|
+
__exportStar(require("./fetchPromptRecords"), exports);
|
|
21
|
+
__exportStar(require("./generateSnapshot"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/codegen/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,+CAA6B;AAC7B,mDAAiC;AACjC,uDAAqC;AACrC,qDAAmC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Langfuse prompt name (`<feature-slug>/<operation>`, kebab-case with
|
|
3
|
+
* slash-separated virtual folders) into the PascalCase `LLMPrompt` enum member.
|
|
4
|
+
* `city-prediction/predict-city-name` → `CityPredictionPredictCityName`. The
|
|
5
|
+
* underscore subprompt convention (`_sections`) is preserved as a segment so
|
|
6
|
+
* section prompts get distinct members.
|
|
7
|
+
*/
|
|
8
|
+
export declare function promptNameToEnumMember(promptName: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptNameToEnumMember = promptNameToEnumMember;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Langfuse prompt name (`<feature-slug>/<operation>`, kebab-case with
|
|
6
|
+
* slash-separated virtual folders) into the PascalCase `LLMPrompt` enum member.
|
|
7
|
+
* `city-prediction/predict-city-name` → `CityPredictionPredictCityName`. The
|
|
8
|
+
* underscore subprompt convention (`_sections`) is preserved as a segment so
|
|
9
|
+
* section prompts get distinct members.
|
|
10
|
+
*/
|
|
11
|
+
function promptNameToEnumMember(promptName) {
|
|
12
|
+
return promptName
|
|
13
|
+
.split(/[/\-_]/)
|
|
14
|
+
.filter((segment) => segment.length > 0)
|
|
15
|
+
.map(capitalize)
|
|
16
|
+
.join('');
|
|
17
|
+
}
|
|
18
|
+
function capitalize(segment) {
|
|
19
|
+
return segment.charAt(0).toUpperCase() + segment.slice(1);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=promptName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptName.js","sourceRoot":"","sources":["../../../src/client/codegen/promptName.ts"],"names":[],"mappings":";;AAOA,wDAMC;AAbD;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,UAAkB;IACvD,OAAO,UAAU;SACd,KAAK,CAAC,QAAQ,CAAC;SACf,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;SACvC,GAAG,CAAC,UAAU,CAAC;SACf,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,SAAS,UAAU,CAAC,OAAe;IACjC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type LLMPromptConfig } from '../../client/llmConfig.schema';
|
|
2
|
+
import { type LLMPromptKind, type LLMPromptMessage } from '../../client/promptSnapshot.typedefs';
|
|
3
|
+
export interface CodegenPromptRecord {
|
|
4
|
+
name: string;
|
|
5
|
+
kind: LLMPromptKind;
|
|
6
|
+
version: number;
|
|
7
|
+
labels: string[];
|
|
8
|
+
requiredVariables: string[];
|
|
9
|
+
fallbackText: string;
|
|
10
|
+
fallbackMessages: LLMPromptMessage[];
|
|
11
|
+
config: LLMPromptConfig;
|
|
12
|
+
}
|
|
13
|
+
export interface RenderSnapshotOptions {
|
|
14
|
+
onWarn?: (message: string) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Renders the full `langfusePrompts.generated.ts` content from fetched prompt
|
|
18
|
+
* records: the `LLMPrompt` enum, per-prompt required-variable unions, the
|
|
19
|
+
* `LLMPromptVariableMap` the client infers from, typed `compile()` helpers
|
|
20
|
+
* (strict on required vars, tolerant of extras), and the snapshot constant used
|
|
21
|
+
* as the outage fallback. A prompt whose enum member is not a valid TS
|
|
22
|
+
* identifier is skipped with a warning rather than emitted — a hostile prompt
|
|
23
|
+
* name can never produce a file that fails the build.
|
|
24
|
+
*/
|
|
25
|
+
export declare function renderSnapshotFile(records: CodegenPromptRecord[], options?: RenderSnapshotOptions): string;
|