graphile-llm 0.7.3 → 0.9.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/__tests__/graphile-llm.test.js +87 -71
- package/chat.d.ts +5 -5
- package/chat.js +45 -43
- package/config-cache.d.ts +77 -0
- package/config-cache.js +148 -0
- package/embedder.d.ts +5 -5
- package/embedder.js +11 -17
- package/env.d.ts +31 -0
- package/env.js +52 -0
- package/esm/__tests__/graphile-llm.test.js +87 -71
- package/esm/chat.d.ts +5 -5
- package/esm/chat.js +45 -40
- package/esm/config-cache.d.ts +77 -0
- package/esm/config-cache.js +143 -0
- package/esm/embedder.d.ts +5 -5
- package/esm/embedder.js +11 -17
- package/esm/env.d.ts +31 -0
- package/esm/env.js +49 -0
- package/esm/index.d.ts +14 -5
- package/esm/index.js +11 -5
- package/esm/metering.d.ts +114 -0
- package/esm/metering.js +352 -0
- package/esm/plugins/agent-discovery-plugin.d.ts +29 -0
- package/esm/plugins/agent-discovery-plugin.js +65 -0
- package/esm/plugins/llm-module-plugin.d.ts +11 -2
- package/esm/plugins/llm-module-plugin.js +15 -7
- package/esm/plugins/metering-plugin.d.ts +42 -0
- package/esm/plugins/metering-plugin.js +175 -0
- package/esm/plugins/rag-plugin.js +20 -20
- package/esm/plugins/text-mutation-plugin.d.ts +4 -0
- package/esm/plugins/text-mutation-plugin.js +23 -13
- package/esm/plugins/text-search-plugin.d.ts +4 -0
- package/esm/plugins/text-search-plugin.js +23 -11
- package/esm/preset.d.ts +21 -1
- package/esm/preset.js +33 -6
- package/esm/types.d.ts +86 -10
- package/index.d.ts +14 -5
- package/index.js +25 -8
- package/metering.d.ts +114 -0
- package/metering.js +359 -0
- package/package.json +15 -15
- package/plugins/agent-discovery-plugin.d.ts +29 -0
- package/plugins/agent-discovery-plugin.js +69 -0
- package/plugins/llm-module-plugin.d.ts +11 -2
- package/plugins/llm-module-plugin.js +15 -7
- package/plugins/metering-plugin.d.ts +42 -0
- package/plugins/metering-plugin.js +178 -0
- package/plugins/rag-plugin.js +20 -20
- package/plugins/text-mutation-plugin.d.ts +4 -0
- package/plugins/text-mutation-plugin.js +23 -13
- package/plugins/text-search-plugin.d.ts +4 -0
- package/plugins/text-search-plugin.js +23 -11
- package/preset.d.ts +21 -1
- package/preset.js +33 -6
- package/types.d.ts +86 -10
package/types.d.ts
CHANGED
|
@@ -4,9 +4,18 @@
|
|
|
4
4
|
* Shared type definitions for the LLM plugin.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Result from an embedding call, including real token usage from the provider.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export interface EmbeddingResult {
|
|
10
|
+
/** The vector embedding */
|
|
11
|
+
embedding: number[];
|
|
12
|
+
/** Number of prompt tokens consumed (from provider; 0 if unavailable) */
|
|
13
|
+
promptTokens: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A function that converts text into a vector embedding with token usage.
|
|
17
|
+
*/
|
|
18
|
+
export type EmbedderFunction = (text: string) => Promise<EmbeddingResult>;
|
|
10
19
|
/**
|
|
11
20
|
* Configuration for an embedding provider.
|
|
12
21
|
*/
|
|
@@ -17,8 +26,24 @@ export interface EmbedderConfig {
|
|
|
17
26
|
model?: string;
|
|
18
27
|
/** Base URL for the provider (e.g. 'http://localhost:11434' for Ollama) */
|
|
19
28
|
baseUrl?: string;
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Token usage metadata returned by LLM providers.
|
|
32
|
+
* Maps to the billing schema's inference_log columns.
|
|
33
|
+
*/
|
|
34
|
+
export interface LlmUsage {
|
|
35
|
+
/** Prompt / input tokens consumed */
|
|
36
|
+
input: number;
|
|
37
|
+
/** Completion / output tokens generated (includes reasoning for providers that count it) */
|
|
38
|
+
output: number;
|
|
39
|
+
/** Reasoning tokens (subset of output — not additive) */
|
|
40
|
+
reasoning: number;
|
|
41
|
+
/** Tokens served from prompt cache (zero cost) */
|
|
42
|
+
cacheRead: number;
|
|
43
|
+
/** Tokens written to prompt cache */
|
|
44
|
+
cacheWrite: number;
|
|
45
|
+
/** input + output + cacheRead + cacheWrite */
|
|
46
|
+
totalTokens: number;
|
|
22
47
|
}
|
|
23
48
|
/**
|
|
24
49
|
* A single message in a chat conversation.
|
|
@@ -37,9 +62,17 @@ export interface ChatOptions {
|
|
|
37
62
|
temperature?: number;
|
|
38
63
|
}
|
|
39
64
|
/**
|
|
40
|
-
*
|
|
65
|
+
* Result from a chat completion call, including real token usage.
|
|
41
66
|
*/
|
|
42
|
-
export
|
|
67
|
+
export interface ChatResult {
|
|
68
|
+
content: string;
|
|
69
|
+
usage: LlmUsage;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A function that sends messages to a chat completion provider
|
|
73
|
+
* and returns the response with token usage metadata.
|
|
74
|
+
*/
|
|
75
|
+
export type ChatFunction = (messages: ChatMessage[], options?: ChatOptions) => Promise<ChatResult>;
|
|
43
76
|
/**
|
|
44
77
|
* Configuration for a chat completion provider.
|
|
45
78
|
*/
|
|
@@ -50,8 +83,6 @@ export interface ChatConfig {
|
|
|
50
83
|
model?: string;
|
|
51
84
|
/** Base URL for the provider */
|
|
52
85
|
baseUrl?: string;
|
|
53
|
-
/** API key for providers that require authentication */
|
|
54
|
-
apiKey?: string;
|
|
55
86
|
}
|
|
56
87
|
/**
|
|
57
88
|
* The shape of the `llm_module` data stored in `services_public.api_modules`.
|
|
@@ -74,8 +105,6 @@ export interface LlmModuleData {
|
|
|
74
105
|
chat_model?: string;
|
|
75
106
|
/** Base URL for the chat provider */
|
|
76
107
|
chat_base_url?: string;
|
|
77
|
-
/** API key reference (e.g. 'vault://openai-key' or env var name) */
|
|
78
|
-
api_key_ref?: string;
|
|
79
108
|
/** Rate limit: requests per minute */
|
|
80
109
|
rate_limit_rpm?: number;
|
|
81
110
|
/** Maximum tokens per request */
|
|
@@ -131,6 +160,41 @@ export interface ChunkTableInfo {
|
|
|
131
160
|
/** Text content column on chunks table (the actual chunk text) */
|
|
132
161
|
contentField: string;
|
|
133
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Configuration for billing/metering integration.
|
|
165
|
+
* When provided, embedding and chat calls are wrapped with quota checks
|
|
166
|
+
* and usage recording via the billing_module functions.
|
|
167
|
+
*/
|
|
168
|
+
export interface MeteringConfig {
|
|
169
|
+
/**
|
|
170
|
+
* Meter slug for embedding operations.
|
|
171
|
+
* Must match a slug in the billing_module meters table.
|
|
172
|
+
*
|
|
173
|
+
* @default the embedding model name (e.g. 'text-embedding-3-small')
|
|
174
|
+
* — meter slug = model name, so each model has its own meter
|
|
175
|
+
* in the three-level waterfall (per-model → inference pool → universal).
|
|
176
|
+
*/
|
|
177
|
+
embeddingMeterSlug?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Meter slug for chat completion operations.
|
|
180
|
+
*
|
|
181
|
+
* @default the chat model name (e.g. 'gpt-4o-mini')
|
|
182
|
+
*/
|
|
183
|
+
chatMeterSlug?: string;
|
|
184
|
+
/**
|
|
185
|
+
* Disable metering entirely (e.g. for local dev).
|
|
186
|
+
* When true, billing functions are never called.
|
|
187
|
+
* @default false
|
|
188
|
+
*/
|
|
189
|
+
skipMetering?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Resolve the billing entity_id from pgSettings.
|
|
192
|
+
* The entity_id identifies who gets billed (user, org, etc.).
|
|
193
|
+
*
|
|
194
|
+
* @default reads jwt.claims.user_id
|
|
195
|
+
*/
|
|
196
|
+
resolveEntityId?: (pgSettings: Record<string, string>) => string | null;
|
|
197
|
+
}
|
|
134
198
|
/**
|
|
135
199
|
* Options for the GraphileLlmPreset.
|
|
136
200
|
*/
|
|
@@ -170,4 +234,16 @@ export interface GraphileLlmOptions {
|
|
|
170
234
|
* Individual queries can override these values.
|
|
171
235
|
*/
|
|
172
236
|
ragDefaults?: RagDefaults;
|
|
237
|
+
/**
|
|
238
|
+
* Billing/metering configuration (opt-in).
|
|
239
|
+
* When truthy, loads the LlmMeteringPlugin which wraps the embedder
|
|
240
|
+
* with billing quota checks + usage recording.
|
|
241
|
+
*
|
|
242
|
+
* Set to `true` to enable metering with defaults (entity_id from jwt.claims.user_id).
|
|
243
|
+
* Provide a MeteringConfig object for fine-grained control (custom entity_id, meter slugs).
|
|
244
|
+
* Set to `false` or omit to disable metering entirely.
|
|
245
|
+
*
|
|
246
|
+
* @default undefined (metering disabled)
|
|
247
|
+
*/
|
|
248
|
+
metering?: boolean | MeteringConfig;
|
|
173
249
|
}
|