@mate-academy/llm-gateway 8.7.0 → 8.8.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 +29 -29
- package/dist/LLMService.typedefs.d.ts +2 -0
- package/dist/LLMService.typedefs.js.map +1 -1
- package/dist/client/LLMClientEngine.d.ts +1 -0
- package/dist/client/LLMClientEngine.js +5 -4
- package/dist/client/LLMClientEngine.js.map +1 -1
- package/dist/client/agentRunner.d.ts +1 -0
- package/dist/client/agentRunner.js +30 -29
- package/dist/client/agentRunner.js.map +1 -1
- package/dist/client/codegen/fetchPromptRecords.js +0 -5
- package/dist/client/codegen/fetchPromptRecords.js.map +1 -1
- package/dist/client/codegen/index.d.ts +0 -1
- package/dist/client/codegen/index.js +0 -1
- package/dist/client/codegen/index.js.map +1 -1
- package/dist/client/codegen/renderSnapshot.constants.d.ts +0 -5
- package/dist/client/codegen/renderSnapshot.constants.js +1 -6
- package/dist/client/codegen/renderSnapshot.constants.js.map +1 -1
- package/dist/client/codegen/renderSnapshot.d.ts +4 -8
- package/dist/client/codegen/renderSnapshot.js +6 -81
- package/dist/client/codegen/renderSnapshot.js.map +1 -1
- package/dist/client/codegen/renderSnapshot.typedefs.d.ts +0 -1
- package/dist/client/createLLMClient.d.ts +5 -5
- package/dist/client/createLLMClient.js +4 -4
- package/dist/client/defineLLMPrompts.d.ts +6 -9
- package/dist/client/defineLLMPrompts.js.map +1 -1
- package/dist/client/llmClient.typedefs.d.ts +15 -14
- package/dist/client/promptRegistry.runtime.js +0 -6
- package/dist/client/promptRegistry.runtime.js.map +1 -1
- package/dist/client/promptSnapshot.typedefs.d.ts +3 -5
- package/dist/client/validationGate.d.ts +4 -8
- package/dist/client/validationGate.js +3 -25
- package/dist/client/validationGate.js.map +1 -1
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.d.ts +1 -7
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.js +0 -6
- package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.js.map +1 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.d.ts +2 -1
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js +13 -37
- package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js.map +1 -1
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js +6 -8
- package/dist/providers/LLMAPI/services/LLMAPIAssistance.service.js.map +1 -1
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.d.ts +1 -0
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js +10 -14
- package/dist/providers/OpenAI/services/OpenAIAssistance.service.js.map +1 -1
- package/dist/services/LLMAssistanceService.abstract.d.ts +2 -0
- package/dist/services/LLMAssistanceService.abstract.js +37 -2
- package/dist/services/LLMAssistanceService.abstract.js.map +1 -1
- package/dist/services/LLMBaseService.abstract.d.ts +2 -2
- package/dist/services/LLMBaseService.abstract.js +11 -3
- package/dist/services/LLMBaseService.abstract.js.map +1 -1
- package/dist/services/agentRounds/LLMAgentRounds.d.ts +5 -8
- package/dist/services/agentRounds/LLMAgentRounds.js +21 -8
- package/dist/services/agentRounds/LLMAgentRounds.js.map +1 -1
- package/dist/services/agentRounds/agentRounds.typedefs.d.ts +18 -10
- package/dist/utilities/llmTracing/llmTracing.typedefs.d.ts +1 -0
- package/dist/utilities/llmTracing/noopLLMTracing.js +3 -0
- package/dist/utilities/llmTracing/noopLLMTracing.js.map +1 -1
- package/package.json +1 -1
- package/dist/client/codegen/extractVariables.d.ts +0 -7
- package/dist/client/codegen/extractVariables.js +0 -21
- package/dist/client/codegen/extractVariables.js.map +0 -1
|
@@ -6,14 +6,10 @@ const promptName_1 = require("../../client/codegen/promptName");
|
|
|
6
6
|
const renderSnapshot_constants_1 = require("../../client/codegen/renderSnapshot.constants");
|
|
7
7
|
/**
|
|
8
8
|
* Renders the full `langfusePrompts.generated.ts` content from fetched prompt
|
|
9
|
-
* records: the `LLMPrompt` enum
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* against the runtime helpers the package exports rather than carrying its own
|
|
14
|
-
* copy of them. A prompt whose enum member is not a valid TS identifier is
|
|
15
|
-
* skipped with a warning rather than emitted — a hostile prompt name can never
|
|
16
|
-
* produce a file that fails the build.
|
|
9
|
+
* records: the `LLMPrompt` enum and the snapshot constant used as the outage
|
|
10
|
+
* fallback. Variable contracts are owned by the application's registry, never
|
|
11
|
+
* inferred from Langfuse. A prompt whose enum member is not a valid TS
|
|
12
|
+
* identifier is skipped with a warning rather than emitted.
|
|
17
13
|
*/
|
|
18
14
|
function renderSnapshotFile(records, options = {}) {
|
|
19
15
|
const renderable = records.filter((record) => isRenderable(record, options));
|
|
@@ -30,10 +26,8 @@ function isRenderable(record, options) {
|
|
|
30
26
|
return false;
|
|
31
27
|
}
|
|
32
28
|
/**
|
|
33
|
-
* Builds the generated file through ts-morph's structural API
|
|
34
|
-
*
|
|
35
|
-
* structures and printed by the TypeScript emitter, so the codegen never
|
|
36
|
-
* hand-assembles TypeScript source out of strings.
|
|
29
|
+
* Builds the generated file through ts-morph's structural API so prompt names
|
|
30
|
+
* and snapshot contents are printed safely instead of hand-assembling source.
|
|
37
31
|
*/
|
|
38
32
|
class SnapshotFileBuilder {
|
|
39
33
|
records;
|
|
@@ -53,9 +47,6 @@ class SnapshotFileBuilder {
|
|
|
53
47
|
build() {
|
|
54
48
|
this.addGatewayImport();
|
|
55
49
|
this.addPromptEnum();
|
|
56
|
-
this.addVariableUnions();
|
|
57
|
-
this.addVariableMap();
|
|
58
|
-
this.addCompilers();
|
|
59
50
|
this.addSnapshotConstant();
|
|
60
51
|
this.sourceFile.formatText({ indentSize: 2, convertTabsToSpaces: true });
|
|
61
52
|
return this.sourceFile.getFullText();
|
|
@@ -65,11 +56,7 @@ class SnapshotFileBuilder {
|
|
|
65
56
|
leadingTrivia: renderSnapshot_constants_1.FILE_HEADER_COMMENT,
|
|
66
57
|
moduleSpecifier: renderSnapshot_constants_1.GATEWAY_MODULE_SPECIFIER,
|
|
67
58
|
namedImports: [
|
|
68
|
-
{ name: renderSnapshot_constants_1.MESSAGES_COMPILER_NAME },
|
|
69
|
-
{ name: renderSnapshot_constants_1.TEXT_COMPILER_NAME },
|
|
70
|
-
{ name: renderSnapshot_constants_1.PROMPT_MESSAGE_TYPE_NAME, isTypeOnly: true },
|
|
71
59
|
{ name: renderSnapshot_constants_1.SNAPSHOT_TYPE_NAME, isTypeOnly: true },
|
|
72
|
-
{ name: renderSnapshot_constants_1.VARIABLE_VALUE_TYPE_NAME, isTypeOnly: true },
|
|
73
60
|
],
|
|
74
61
|
});
|
|
75
62
|
}
|
|
@@ -83,29 +70,6 @@ class SnapshotFileBuilder {
|
|
|
83
70
|
})),
|
|
84
71
|
});
|
|
85
72
|
}
|
|
86
|
-
addVariableUnions() {
|
|
87
|
-
this.sourceFile.addTypeAliases(this.records.map((record) => ({
|
|
88
|
-
name: `${(0, promptName_1.promptNameToEnumMember)(record.name)}Variables`,
|
|
89
|
-
isExported: true,
|
|
90
|
-
type: toVariablesUnion(record),
|
|
91
|
-
})));
|
|
92
|
-
}
|
|
93
|
-
addVariableMap() {
|
|
94
|
-
this.sourceFile.addInterface({
|
|
95
|
-
name: renderSnapshot_constants_1.VARIABLE_MAP_INTERFACE_NAME,
|
|
96
|
-
isExported: true,
|
|
97
|
-
properties: this.records.map((record) => {
|
|
98
|
-
const member = (0, promptName_1.promptNameToEnumMember)(record.name);
|
|
99
|
-
return {
|
|
100
|
-
name: `[${renderSnapshot_constants_1.PROMPT_ENUM_NAME}.${member}]`,
|
|
101
|
-
type: `${member}Variables`,
|
|
102
|
-
};
|
|
103
|
-
}),
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
addCompilers() {
|
|
107
|
-
this.sourceFile.addFunctions(this.records.map((record) => toCompilerStructure(record)));
|
|
108
|
-
}
|
|
109
73
|
addSnapshotConstant() {
|
|
110
74
|
this.sourceFile.addVariableStatement({
|
|
111
75
|
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
@@ -131,51 +95,12 @@ class SnapshotFileBuilder {
|
|
|
131
95
|
});
|
|
132
96
|
}
|
|
133
97
|
}
|
|
134
|
-
function toCompilerStructure(record) {
|
|
135
|
-
const member = (0, promptName_1.promptNameToEnumMember)(record.name);
|
|
136
|
-
const isChatPrompt = record.kind === 'chat';
|
|
137
|
-
const compilerName = isChatPrompt
|
|
138
|
-
? renderSnapshot_constants_1.MESSAGES_COMPILER_NAME
|
|
139
|
-
: renderSnapshot_constants_1.TEXT_COMPILER_NAME;
|
|
140
|
-
return {
|
|
141
|
-
name: `compile${member}`,
|
|
142
|
-
isExported: true,
|
|
143
|
-
parameters: [{
|
|
144
|
-
name: 'variables',
|
|
145
|
-
type: toVariablesParameterType(record),
|
|
146
|
-
}],
|
|
147
|
-
returnType: isChatPrompt ? `${renderSnapshot_constants_1.PROMPT_MESSAGE_TYPE_NAME}[]` : 'string',
|
|
148
|
-
statements: (writer) => {
|
|
149
|
-
writer.write(`return ${compilerName}(`).inlineBlock(() => {
|
|
150
|
-
writer.writeLine(`snapshot: ${renderSnapshot_constants_1.SNAPSHOT_CONSTANT_NAME},`);
|
|
151
|
-
writer.writeLine(`name: ${renderSnapshot_constants_1.PROMPT_ENUM_NAME}.${member},`);
|
|
152
|
-
writer.writeLine('variables,');
|
|
153
|
-
}).write(');');
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function toVariablesUnion(record) {
|
|
158
|
-
if (record.requiredVariables.length === 0) {
|
|
159
|
-
return 'never';
|
|
160
|
-
}
|
|
161
|
-
return record.requiredVariables
|
|
162
|
-
.map((name) => JSON.stringify(name))
|
|
163
|
-
.join(' | ');
|
|
164
|
-
}
|
|
165
|
-
function toVariablesParameterType(record) {
|
|
166
|
-
const member = (0, promptName_1.promptNameToEnumMember)(record.name);
|
|
167
|
-
const strictVariables = record.requiredVariables.length > 0
|
|
168
|
-
? `Record<${member}Variables, ${renderSnapshot_constants_1.VARIABLE_VALUE_TYPE_NAME}>`
|
|
169
|
-
: 'Record<string, never>';
|
|
170
|
-
return `${strictVariables} & Record<string, ${renderSnapshot_constants_1.VARIABLE_VALUE_TYPE_NAME}>`;
|
|
171
|
-
}
|
|
172
98
|
function toSnapshotEntry(record) {
|
|
173
99
|
return {
|
|
174
100
|
name: record.name,
|
|
175
101
|
kind: record.kind,
|
|
176
102
|
version: record.version,
|
|
177
103
|
labels: record.labels,
|
|
178
|
-
requiredVariables: record.requiredVariables,
|
|
179
104
|
fallbackText: record.fallbackText,
|
|
180
105
|
fallbackMessages: record.fallbackMessages,
|
|
181
106
|
config: record.config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderSnapshot.js","sourceRoot":"","sources":["../../../src/client/codegen/renderSnapshot.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"renderSnapshot.js","sourceRoot":"","sources":["../../../src/client/codegen/renderSnapshot.ts"],"names":[],"mappings":";;AA8BA,gDAQC;AAtCD,uCAOkB;AAClB,4DAAqE;AAKrE,wFAQmD;AAEnD;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,OAA8B,EAC9B,UAAiC,EAAE;IAEnC,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7E,MAAM,MAAM,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAE1F,OAAO,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC;AACjD,CAAC;AAED,SAAS,YAAY,CACnB,MAA2B,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,CAAC,SAAS,CAAC,IAAI,2CAAgB,IAAI,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC;YACjE,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,eAAe,CAAC,MAA2B;IAClD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -2,9 +2,9 @@ import { type LLMPromptRegistry } from '../client/defineLLMPrompts';
|
|
|
2
2
|
import { type CreateLLMClientConfig, type LLMClient, type LLMPromptVariableMap } from '../client/llmClient.typedefs';
|
|
3
3
|
/**
|
|
4
4
|
* Builds the v2 gateway client once at the composition root. The client is
|
|
5
|
-
* generic over `typeof registry
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* generic over `typeof registry`, so call sites get code-owned variable types
|
|
6
|
+
* and typed returns from a single binding here. Feature code receives the
|
|
7
|
+
* client via DI and never touches credentials, the prompt client, or the
|
|
8
|
+
* reporter.
|
|
9
9
|
*/
|
|
10
|
-
export declare function createLLMClient<Registry extends LLMPromptRegistry, VariableMap extends Record<keyof Registry, string> = LLMPromptVariableMap<Registry>, ReporterContext extends Record<string, any> =
|
|
10
|
+
export declare function createLLMClient<Registry extends LLMPromptRegistry, VariableMap extends Record<keyof Registry, string> = LLMPromptVariableMap<Registry>, ReporterContext extends Record<string, any> = never>(config: CreateLLMClientConfig<Registry, ReporterContext>): LLMClient<Registry, VariableMap>;
|
|
@@ -6,10 +6,10 @@ const promptRegistry_runtime_1 = require("../client/promptRegistry.runtime");
|
|
|
6
6
|
const llmClient_typedefs_1 = require("../client/llmClient.typedefs");
|
|
7
7
|
/**
|
|
8
8
|
* Builds the v2 gateway client once at the composition root. The client is
|
|
9
|
-
* generic over `typeof registry
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* generic over `typeof registry`, so call sites get code-owned variable types
|
|
10
|
+
* and typed returns from a single binding here. Feature code receives the
|
|
11
|
+
* client via DI and never touches credentials, the prompt client, or the
|
|
12
|
+
* reporter.
|
|
13
13
|
*/
|
|
14
14
|
function createLLMClient(config) {
|
|
15
15
|
const mode = config.mode ?? 'production';
|
|
@@ -12,20 +12,17 @@ export type LLMCapabilityRequirement = keyof Pick<LLMModelCapabilities, 'vision'
|
|
|
12
12
|
* the `generate` return type; `toolSchemas` carry tool name+parameter shapes for
|
|
13
13
|
* typing/capability validation (executable tools are always passed per call);
|
|
14
14
|
* `requires` lists capabilities the resolved model must satisfy; `kind`
|
|
15
|
-
* distinguishes config-only audio prompts; `
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* code-declared source of "what variables code provides", independent of any
|
|
20
|
-
* live prompt (a generated `compile()` signature reflects the prompt's current
|
|
21
|
-
* vars, not the call site's).
|
|
15
|
+
* distinguishes config-only audio prompts; `variables` is the code-owned list
|
|
16
|
+
* of required input names for this prompt. The client derives each call site's
|
|
17
|
+
* `variables` type from this list, independently of the prompt body stored in
|
|
18
|
+
* Langfuse.
|
|
22
19
|
*/
|
|
23
20
|
export interface LLMPromptBinding<Schema extends LLMSchemaInterface = LLMSchemaInterface> {
|
|
24
21
|
schema?: Schema;
|
|
25
22
|
toolSchemas?: Record<string, LLMSchemaInterface>;
|
|
26
23
|
requires?: LLMCapabilityRequirement[];
|
|
27
24
|
kind?: LLMPromptKind | 'transcription' | 'speech';
|
|
28
|
-
|
|
25
|
+
variables?: readonly string[];
|
|
29
26
|
}
|
|
30
27
|
export type LLMPromptRegistry = Record<string, LLMPromptBinding>;
|
|
31
28
|
/**
|
|
@@ -34,4 +31,4 @@ export type LLMPromptRegistry = Record<string, LLMPromptBinding>;
|
|
|
34
31
|
* infer per-prompt variables and return types from `typeof registry` — bind the
|
|
35
32
|
* registry once at the composition root, never via module augmentation.
|
|
36
33
|
*/
|
|
37
|
-
export declare function defineLLMPrompts<Registry extends LLMPromptRegistry>(registry: Registry): Registry;
|
|
34
|
+
export declare function defineLLMPrompts<const Registry extends LLMPromptRegistry>(registry: Registry): Registry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineLLMPrompts.js","sourceRoot":"","sources":["../../src/client/defineLLMPrompts.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"defineLLMPrompts.js","sourceRoot":"","sources":["../../src/client/defineLLMPrompts.ts"],"names":[],"mappings":";;AAkDA,4CAIC;AAVD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC9B,QAAkB;IAElB,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -89,13 +89,11 @@ export interface LLMReportingConfig<Context extends Record<string, any> = Record
|
|
|
89
89
|
buildContext: (scope: LLMReporterContextScope) => Context;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
* What building a provider service for one call needs: the prompt
|
|
93
|
-
*
|
|
94
|
-
* which decides whose credentials the provider is built with.
|
|
92
|
+
* What building a provider service for one call needs: the resolved prompt and
|
|
93
|
+
* the context that decides whose credentials the provider is built with.
|
|
95
94
|
*/
|
|
96
95
|
export interface LLMProviderServiceScope {
|
|
97
96
|
resolved: ResolvedPrompt;
|
|
98
|
-
promptName: string;
|
|
99
97
|
callContext: LLMClientCallContext | undefined;
|
|
100
98
|
}
|
|
101
99
|
/**
|
|
@@ -131,8 +129,9 @@ export type LLMDelegationGate = (args: Record<string, unknown>) => Promise<LLMTo
|
|
|
131
129
|
* so a mapper that drops or mistypes a DWH column fails the build instead of
|
|
132
130
|
* corrupting a dashboard. It is inferred from `reporting` when the call site
|
|
133
131
|
* passes no explicit type arguments; TypeScript has no partial inference, so a
|
|
134
|
-
* call site that spells out `Registry`/`VariableMap` must spell this out too
|
|
135
|
-
*
|
|
132
|
+
* call site that spells out `Registry`/`VariableMap` must spell this out too.
|
|
133
|
+
* The factory defaults it to `never`, so a partially explicit call cannot
|
|
134
|
+
* silently fall back to an unchecked reporter context.
|
|
136
135
|
*/
|
|
137
136
|
export interface CreateLLMClientConfig<Registry extends LLMPromptRegistry, ReporterContext extends Record<string, any> = Record<string, any>> {
|
|
138
137
|
gateway: LLMGateway;
|
|
@@ -161,9 +160,9 @@ export interface LLMClientEngineConfig<Registry extends LLMPromptRegistry> {
|
|
|
161
160
|
normalizeToolResult: LLMToolResultNormalizer | undefined;
|
|
162
161
|
}
|
|
163
162
|
/**
|
|
164
|
-
* The variables a prompt requires.
|
|
165
|
-
*
|
|
166
|
-
*
|
|
163
|
+
* The variables a prompt requires. Required keys come exclusively from the
|
|
164
|
+
* code-owned prompt registry. Extras remain tolerated so callers can migrate a
|
|
165
|
+
* variable in more than one deployment.
|
|
167
166
|
*/
|
|
168
167
|
export type LLMPromptVariables<RequiredKeys extends string> = Record<RequiredKeys, LLMVariableValue> & Record<string, LLMVariableValue>;
|
|
169
168
|
/**
|
|
@@ -229,14 +228,16 @@ export interface LLMPlainMessage {
|
|
|
229
228
|
text: string;
|
|
230
229
|
}
|
|
231
230
|
/**
|
|
232
|
-
* Maps each registry key to the union of variable names
|
|
233
|
-
*
|
|
234
|
-
*
|
|
231
|
+
* Maps each registry key to the union of variable names declared by code. The
|
|
232
|
+
* Langfuse prompt body and generated fallback snapshot do not participate in
|
|
233
|
+
* call-site typing.
|
|
235
234
|
*/
|
|
236
235
|
export type LLMPromptVariableMap<Registry extends LLMPromptRegistry> = {
|
|
237
|
-
[Key in keyof Registry]:
|
|
236
|
+
[Key in keyof Registry]: Registry[Key] extends {
|
|
237
|
+
variables: readonly (infer VariableName extends string)[];
|
|
238
|
+
} ? VariableName : never;
|
|
238
239
|
};
|
|
239
|
-
export interface LLMClient<Registry extends LLMPromptRegistry, VariableMap extends Record<keyof Registry, string>> {
|
|
240
|
+
export interface LLMClient<Registry extends LLMPromptRegistry, VariableMap extends Record<keyof Registry, string> = LLMPromptVariableMap<Registry>> {
|
|
240
241
|
generate<Key extends keyof Registry, Schema extends LLMSchemaInterface = never>(prompt: Key, options: LLMGenerateOptions<Record<VariableMap[Key], LLMVariableValue> & Record<string, LLMVariableValue>, Schema>): Promise<[
|
|
241
242
|
Schema
|
|
242
243
|
] extends [never] ? LLMGenerateResult<Registry[Key]> : InferSchema<Schema>>;
|
|
@@ -106,8 +106,6 @@ class PromptRegistryRuntime {
|
|
|
106
106
|
}
|
|
107
107
|
gateConfig(rawConfig, input) {
|
|
108
108
|
return (0, validationGate_1.runValidationGate)({
|
|
109
|
-
promptText: '',
|
|
110
|
-
providedVariables: [],
|
|
111
109
|
rawConfig,
|
|
112
110
|
requires: input.requires,
|
|
113
111
|
purpose: input.purpose,
|
|
@@ -120,8 +118,6 @@ class PromptRegistryRuntime {
|
|
|
120
118
|
}
|
|
121
119
|
const compiled = this.compileBody(input.kind, fetched.body, input.variables);
|
|
122
120
|
const gate = (0, validationGate_1.runValidationGate)({
|
|
123
|
-
promptText: compiled.text,
|
|
124
|
-
providedVariables: Object.keys(input.variables),
|
|
125
121
|
rawConfig: fetched.config,
|
|
126
122
|
requires: input.requires,
|
|
127
123
|
purpose: input.purpose,
|
|
@@ -148,8 +144,6 @@ class PromptRegistryRuntime {
|
|
|
148
144
|
}
|
|
149
145
|
const compiled = this.compileBody(input.kind, input.kind === 'chat' ? entry.fallbackMessages : entry.fallbackText, input.variables);
|
|
150
146
|
const gate = (0, validationGate_1.runValidationGate)({
|
|
151
|
-
promptText: compiled.text,
|
|
152
|
-
providedVariables: Object.keys(input.variables),
|
|
153
147
|
rawConfig: entry.config,
|
|
154
148
|
requires: input.requires,
|
|
155
149
|
purpose: input.purpose,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptRegistry.runtime.js","sourceRoot":"","sources":["../../src/client/promptRegistry.runtime.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"promptRegistry.runtime.js","sourceRoot":"","sources":["../../src/client/promptRegistry.runtime.ts"],"names":[],"mappings":";;;AA2ZA,gDAEC;AA7ZD,+DAAsF;AAEtF,uDAGgC;AAehC,4DAA4D;AAE5D,MAAM,kBAAkB,GAAoC;IAC1D,QAAQ;IACR,MAAM;IACN,WAAW;CACZ,CAAC;AAEF,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,MAAM,wBAAwB,GAAG,gCAAgC,CAAC;AAgElE;;;;;;GAMG;AACH,MAAa,qBAAqB;IACf,YAAY,CAAqC;IAEjD,QAAQ,CAAoB;IAE5B,YAAY,CAAS;IAErB,eAAe,CAAS;IAExB,MAAM,CAAiC;IAEvC,qBAAqB,CAA2B;IAEzD,oBAAoB,GAAG,KAAK,CAAC;IAErC,YAAY,MAAmC;QAC7C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,yBAAyB,CAAC;QAC3E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC5D,IAAI,CAAC,qBAAqB;cACtB,MAAM,CAAC,qBAAqB,IAAI,sCAAyB,CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QAED,MAAM,OAAO,CAAC,UAAU,CACtB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CA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AC,CAAC,GAAG,CAAC,CAAC,KAA6B,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACpF,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,gBAAgB,CACvB,QAAiC;IAEjC,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACnC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;QACvB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;QACpD,CAAC,CAAC,EAAE,CACP,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAQ,kBAAwC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -35,10 +35,9 @@ export interface LLMPromptConfigSnapshot {
|
|
|
35
35
|
/**
|
|
36
36
|
* One prompt's build-time snapshot, emitted by `npm run langfuse:generate` into
|
|
37
37
|
* the gitignored `langfusePrompts.generated.ts`. It is the outage fallback: the
|
|
38
|
-
* runtime registry serves it whenever a live fetch or
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* check agrees with the typed `compile()` signature.
|
|
38
|
+
* runtime registry serves it whenever a live fetch or config validation fails.
|
|
39
|
+
* Prompt variables are intentionally absent because their contract is owned by
|
|
40
|
+
* application code.
|
|
42
41
|
*
|
|
43
42
|
* `fallbackText` is the body for a `text` prompt; `fallbackMessages` is the
|
|
44
43
|
* role-tagged message list for a `chat` prompt. Exactly one is meaningful per
|
|
@@ -49,7 +48,6 @@ export interface LLMPromptSnapshotEntry {
|
|
|
49
48
|
kind: LLMPromptKind;
|
|
50
49
|
version: number;
|
|
51
50
|
labels: string[];
|
|
52
|
-
requiredVariables: string[];
|
|
53
51
|
fallbackText: string;
|
|
54
52
|
fallbackMessages: LLMPromptMessage[];
|
|
55
53
|
config: LLMPromptConfigSnapshot;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { type LLMModel, type LLMProviders, type LLMPurposes } from '../LLMService.typedefs';
|
|
2
2
|
import { type LLMPromptConfig } from '../client/llmConfig.schema';
|
|
3
3
|
import { type LLMCapabilityRequirement } from '../client/defineLLMPrompts';
|
|
4
|
-
export type GateFailureReason = '
|
|
4
|
+
export type GateFailureReason = 'config-parse' | 'unknown-model' | 'unmet-capabilities';
|
|
5
5
|
export interface GateInput {
|
|
6
|
-
promptText: string;
|
|
7
|
-
providedVariables: string[];
|
|
8
6
|
rawConfig: unknown;
|
|
9
7
|
requires: LLMCapabilityRequirement[];
|
|
10
8
|
purpose: LLMPurposes;
|
|
@@ -19,10 +17,8 @@ export type GateResult = {
|
|
|
19
17
|
detail: string;
|
|
20
18
|
};
|
|
21
19
|
/**
|
|
22
|
-
* The
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* config parse fail fast before the model lookup, and capabilities are checked
|
|
26
|
-
* last because they need the resolved model.
|
|
20
|
+
* The runtime config gate, run on every prompt fetch (live or fallback). Prompt
|
|
21
|
+
* variables are a code-owned compile-time contract; this gate validates only
|
|
22
|
+
* routing configuration and model capabilities.
|
|
27
23
|
*/
|
|
28
24
|
export declare function runValidationGate(input: GateInput): GateResult;
|
|
@@ -3,23 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.runValidationGate = runValidationGate;
|
|
4
4
|
const LLMService_constants_1 = require("../LLMService.constants");
|
|
5
5
|
const llmConfig_schema_1 = require("../client/llmConfig.schema");
|
|
6
|
-
const TEMPLATE_VARIABLE_PATTERN = /{{\s*([\w.]+)\s*}}/g;
|
|
7
6
|
/**
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* config parse fail fast before the model lookup, and capabilities are checked
|
|
12
|
-
* last because they need the resolved model.
|
|
7
|
+
* The runtime config gate, run on every prompt fetch (live or fallback). Prompt
|
|
8
|
+
* variables are a code-owned compile-time contract; this gate validates only
|
|
9
|
+
* routing configuration and model capabilities.
|
|
13
10
|
*/
|
|
14
11
|
function runValidationGate(input) {
|
|
15
|
-
const unresolved = findUnresolvedVariables(input.promptText, input.providedVariables);
|
|
16
|
-
if (unresolved.length > 0) {
|
|
17
|
-
return {
|
|
18
|
-
valid: false,
|
|
19
|
-
reason: 'unresolved-variables',
|
|
20
|
-
detail: `prompt references unprovided variables: ${unresolved.join(', ')}`,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
12
|
const parsed = llmConfig_schema_1.llmPromptConfigSchema.safeParse(input.rawConfig);
|
|
24
13
|
if (!parsed.success) {
|
|
25
14
|
return {
|
|
@@ -50,17 +39,6 @@ function runValidationGate(input) {
|
|
|
50
39
|
}
|
|
51
40
|
return { valid: true, config: parsed.data, model };
|
|
52
41
|
}
|
|
53
|
-
function findUnresolvedVariables(promptText, providedVariables) {
|
|
54
|
-
const provided = new Set(providedVariables);
|
|
55
|
-
const referenced = new Set();
|
|
56
|
-
for (const match of promptText.matchAll(TEMPLATE_VARIABLE_PATTERN)) {
|
|
57
|
-
const variableName = match[1];
|
|
58
|
-
if (!variableName.startsWith('#') && !variableName.startsWith('/')) {
|
|
59
|
-
referenced.add(variableName);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return [...referenced].filter((name) => !provided.has(name));
|
|
63
|
-
}
|
|
64
42
|
function resolveModel(config, purpose) {
|
|
65
43
|
const providerModels = LLMService_constants_1.LLM_SERVICE_MODELS[config.provider];
|
|
66
44
|
const purposeModels = providerModels[purpose];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationGate.js","sourceRoot":"","sources":["../../src/client/validationGate.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"validationGate.js","sourceRoot":"","sources":["../../src/client/validationGate.ts"],"names":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O,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AACrD,CAAC;AAED,SAAS,YAAY,CACnB,MAAuB,EACvB,OAAoB;IAEpB,MAAM,cAAc,GAAG,yCAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAE/B,CAAC;IAEd,OAAO,aAAa,EAAE,CAAC,MAAM,CAAC,KAAmC,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,uBAAuB,CAC9B,KAA6B,EAC7B,QAAoC;IAEpC,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;IAExC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -11,13 +11,7 @@ export declare enum GoogleGenerativeAIModelNames {
|
|
|
11
11
|
}
|
|
12
12
|
export declare enum GoogleGenerativeAIRoles {
|
|
13
13
|
User = "user",
|
|
14
|
-
Model = "model"
|
|
15
|
-
/**
|
|
16
|
-
* Not a role the chat history ever carries — the system instruction lives in
|
|
17
|
-
* the request config. Used only to label it when a traced round renders the
|
|
18
|
-
* conversation it was sent with.
|
|
19
|
-
*/
|
|
20
|
-
System = "system"
|
|
14
|
+
Model = "model"
|
|
21
15
|
}
|
|
22
16
|
export type GoogleGenerativeAIClient = GoogleGenAI;
|
|
23
17
|
export type GoogleGenerativeAIClientOptions = GoogleGenAIOptions;
|
|
@@ -16,11 +16,5 @@ var GoogleGenerativeAIRoles;
|
|
|
16
16
|
(function (GoogleGenerativeAIRoles) {
|
|
17
17
|
GoogleGenerativeAIRoles["User"] = "user";
|
|
18
18
|
GoogleGenerativeAIRoles["Model"] = "model";
|
|
19
|
-
/**
|
|
20
|
-
* Not a role the chat history ever carries — the system instruction lives in
|
|
21
|
-
* the request config. Used only to label it when a traced round renders the
|
|
22
|
-
* conversation it was sent with.
|
|
23
|
-
*/
|
|
24
|
-
GoogleGenerativeAIRoles["System"] = "system";
|
|
25
19
|
})(GoogleGenerativeAIRoles || (exports.GoogleGenerativeAIRoles = GoogleGenerativeAIRoles = {}));
|
|
26
20
|
//# sourceMappingURL=GoogleGenerativeAI.typedefs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleGenerativeAI.typedefs.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.ts"],"names":[],"mappings":";;;AAOA,IAAY,4BASX;AATD,WAAY,4BAA4B;IACtC,qEAAqC,CAAA;IACrC,+EAA+C,CAAA;IAC/C,iEAAiC,CAAA;IACjC,6FAA6D,CAAA;IAC7D,yFAAyD,CAAA;IACzD,iFAAiD,CAAA;IACjD,+FAA+D,CAAA;IAC/D,iFAAiD,CAAA;AACnD,CAAC,EATW,4BAA4B,4CAA5B,4BAA4B,QASvC;AAED,IAAY,
|
|
1
|
+
{"version":3,"file":"GoogleGenerativeAI.typedefs.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.ts"],"names":[],"mappings":";;;AAOA,IAAY,4BASX;AATD,WAAY,4BAA4B;IACtC,qEAAqC,CAAA;IACrC,+EAA+C,CAAA;IAC/C,iEAAiC,CAAA;IACjC,6FAA6D,CAAA;IAC7D,yFAAyD,CAAA;IACzD,iFAAiD,CAAA;IACjD,+FAA+D,CAAA;IAC/D,iFAAiD,CAAA;AACnD,CAAC,EATW,4BAA4B,4CAA5B,4BAA4B,QASvC;AAED,IAAY,uBAGX;AAHD,WAAY,uBAAuB;IACjC,wCAAa,CAAA;IACb,0CAAe,CAAA;AACjB,CAAC,EAHW,uBAAuB,uCAAvB,uBAAuB,QAGlC"}
|
package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.d.ts
CHANGED
|
@@ -38,7 +38,8 @@ export declare class GoogleGenerativeAIAssistanceService<Reporter extends LLMRep
|
|
|
38
38
|
* so the per-round generations add up to the single metrics point the run
|
|
39
39
|
* still writes.
|
|
40
40
|
*/
|
|
41
|
-
private
|
|
41
|
+
private buildUsageMetrics;
|
|
42
|
+
private readonly buildRoundOutcome;
|
|
42
43
|
private extractUsageFromResponse;
|
|
43
44
|
private combineUsage;
|
|
44
45
|
private convertCustomToolsToGoogle;
|