@warmdrift/kgauto 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +229 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.js +1131 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1090 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -0
- package/profiles.json +672 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KG-auto types — shared across adapter, logger, and public API.
|
|
3
|
+
*/
|
|
4
|
+
interface ModelProfile {
|
|
5
|
+
id: string;
|
|
6
|
+
provider: string;
|
|
7
|
+
status: 'current' | 'legacy' | 'preview';
|
|
8
|
+
max_tools: number;
|
|
9
|
+
max_context_tokens: number;
|
|
10
|
+
max_output_tokens: number;
|
|
11
|
+
parallel_tool_calls: boolean;
|
|
12
|
+
output_modes: ('generateText' | 'generateObject')[];
|
|
13
|
+
prompt_rules: string[];
|
|
14
|
+
known_failures: string[];
|
|
15
|
+
strengths: string[];
|
|
16
|
+
weaknesses: string[];
|
|
17
|
+
cost_input_per_1m: number;
|
|
18
|
+
cost_output_per_1m: number;
|
|
19
|
+
step_limit_default: number;
|
|
20
|
+
notes: string;
|
|
21
|
+
}
|
|
22
|
+
interface Message {
|
|
23
|
+
role: string;
|
|
24
|
+
content: string;
|
|
25
|
+
}
|
|
26
|
+
interface ToolDefinition {
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
parameters?: Record<string, unknown>;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
interface AdapterConstraints {
|
|
33
|
+
/** Tool relevance scores (0-1). Higher = more likely to be kept during budgeting. */
|
|
34
|
+
relevanceHints?: Record<string, number>;
|
|
35
|
+
/** Hard word limit injected into system prompt. */
|
|
36
|
+
maxResponseWords?: number;
|
|
37
|
+
/** Whether the caller wants structured JSON output. */
|
|
38
|
+
structuredOutput?: boolean;
|
|
39
|
+
/** Max latency hint (advisory, not enforced by adapter). */
|
|
40
|
+
maxLatencyMs?: number;
|
|
41
|
+
/** Quality floor hint (advisory). */
|
|
42
|
+
qualityFloor?: number;
|
|
43
|
+
/** Caller-provided intent classification (skips heuristic detection). */
|
|
44
|
+
intentHint?: string;
|
|
45
|
+
/** Project identifier for logging. */
|
|
46
|
+
project?: string;
|
|
47
|
+
}
|
|
48
|
+
interface PrepareInput {
|
|
49
|
+
/** Target model profile ID (e.g. "gemini-2.5-flash"). */
|
|
50
|
+
model: string;
|
|
51
|
+
/** Raw system prompt before adaptation. */
|
|
52
|
+
systemPrompt: string;
|
|
53
|
+
/** Conversation messages. */
|
|
54
|
+
messages: Message[];
|
|
55
|
+
/** Available tools — adapter may reduce this set. */
|
|
56
|
+
tools?: ToolDefinition[];
|
|
57
|
+
/** Constraints and hints. */
|
|
58
|
+
constraints?: AdapterConstraints;
|
|
59
|
+
}
|
|
60
|
+
interface ToolPolicy {
|
|
61
|
+
name: string;
|
|
62
|
+
parallelSafe: boolean;
|
|
63
|
+
maxPerResponse: number | null;
|
|
64
|
+
reason: string | null;
|
|
65
|
+
}
|
|
66
|
+
interface PrepareResult {
|
|
67
|
+
requestId: string;
|
|
68
|
+
model: string;
|
|
69
|
+
provider: string;
|
|
70
|
+
systemPrompt: string;
|
|
71
|
+
messages: Message[];
|
|
72
|
+
tools: ToolDefinition[];
|
|
73
|
+
outputStrategy: 'generateText' | 'generateObject';
|
|
74
|
+
promptRulesApplied: string[];
|
|
75
|
+
tokensEstimated: number;
|
|
76
|
+
contextBudget: number;
|
|
77
|
+
toolsOriginalCount: number;
|
|
78
|
+
toolsSelectedCount: number;
|
|
79
|
+
toolPolicies: ToolPolicy[] | null;
|
|
80
|
+
}
|
|
81
|
+
interface LogInput {
|
|
82
|
+
requestId: string;
|
|
83
|
+
model: string;
|
|
84
|
+
provider: string;
|
|
85
|
+
project?: string;
|
|
86
|
+
intent?: string;
|
|
87
|
+
toolsOffered?: number;
|
|
88
|
+
toolsSelected?: number;
|
|
89
|
+
toolsUsed?: number;
|
|
90
|
+
tokensIn: number;
|
|
91
|
+
tokensOut: number;
|
|
92
|
+
latencyMs: number;
|
|
93
|
+
success: boolean;
|
|
94
|
+
emptyResponse?: boolean;
|
|
95
|
+
errorType?: string;
|
|
96
|
+
adapterRulesApplied?: string[];
|
|
97
|
+
mode?: string;
|
|
98
|
+
toolsCalled?: string[];
|
|
99
|
+
}
|
|
100
|
+
interface LogResult {
|
|
101
|
+
logged: boolean;
|
|
102
|
+
requestId: string;
|
|
103
|
+
inputRatio: number | null;
|
|
104
|
+
efficiencyFlag: 'healthy' | 'warning' | 'critical' | null;
|
|
105
|
+
textOnly: boolean | null;
|
|
106
|
+
parallelismWarnings: string[] | null;
|
|
107
|
+
}
|
|
108
|
+
interface KGAutoConfig {
|
|
109
|
+
/** Optional: HTTP endpoint for centralized logging. If omitted, logs to console. */
|
|
110
|
+
logUrl?: string;
|
|
111
|
+
/** Project identifier for logging. Default: "default". */
|
|
112
|
+
project?: string;
|
|
113
|
+
/** Suppress console log output. Default: false. */
|
|
114
|
+
silent?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Request Adapter — transforms raw requests so the target model handles them correctly.
|
|
119
|
+
*
|
|
120
|
+
* Port of gateway/adapter.py. Pure transform, no IO, no state.
|
|
121
|
+
*
|
|
122
|
+
* Three stages applied in order:
|
|
123
|
+
* 1. Unified token budget (tools + system prompt + messages share one context window)
|
|
124
|
+
* 2. Prompt rewriting (composable rules from model profile)
|
|
125
|
+
* 3. Output strategy selection (generateObject vs generateText)
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Prepare a request for a specific model.
|
|
130
|
+
*
|
|
131
|
+
* Pure function. Takes the raw request and returns an adapted request
|
|
132
|
+
* with budgeted tools, rewritten prompt, and output strategy.
|
|
133
|
+
*
|
|
134
|
+
* Throws Error if the system prompt exceeds the model's context budget.
|
|
135
|
+
*/
|
|
136
|
+
declare function prepare(input: PrepareInput): PrepareResult;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Outcome logger — diagnostics for every model call.
|
|
140
|
+
*
|
|
141
|
+
* Three destinations:
|
|
142
|
+
* - console (default): human-readable log line
|
|
143
|
+
* - http: POST to a centralized endpoint (fire-and-forget)
|
|
144
|
+
* - silent: no output (for tests)
|
|
145
|
+
*
|
|
146
|
+
* Every log() call returns instant diagnostics:
|
|
147
|
+
* - efficiency flag (input/output ratio assessment)
|
|
148
|
+
* - text-only detection (tools offered but none used)
|
|
149
|
+
* - parallelism warnings (serial-only tools called multiple times)
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/** Compute all diagnostics for a log entry. */
|
|
153
|
+
declare function computeDiagnostics(input: LogInput): LogResult;
|
|
154
|
+
interface LogDestination {
|
|
155
|
+
write(input: LogInput, result: LogResult): void;
|
|
156
|
+
}
|
|
157
|
+
declare class ConsoleDestination implements LogDestination {
|
|
158
|
+
write(input: LogInput, result: LogResult): void;
|
|
159
|
+
}
|
|
160
|
+
declare class HttpDestination implements LogDestination {
|
|
161
|
+
private url;
|
|
162
|
+
constructor(url: string);
|
|
163
|
+
write(input: LogInput, _result: LogResult): void;
|
|
164
|
+
}
|
|
165
|
+
declare class SilentDestination implements LogDestination {
|
|
166
|
+
write(): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Log an outcome and return instant diagnostics.
|
|
170
|
+
*
|
|
171
|
+
* The diagnostics are computed synchronously. The write to the destination
|
|
172
|
+
* is fire-and-forget (may be async for HTTP, but never blocks the caller).
|
|
173
|
+
*/
|
|
174
|
+
declare function log(input: LogInput, destination: LogDestination): LogResult;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Model profiles — bundled at build time from profiles/models.yaml.
|
|
178
|
+
*
|
|
179
|
+
* Adding a model = adding an entry to profiles.json + npm version bump.
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
/** All loaded model profiles, keyed by model ID. */
|
|
183
|
+
declare const PROFILES: Readonly<Record<string, ModelProfile>>;
|
|
184
|
+
/** Get a single profile by ID. Throws if not found. */
|
|
185
|
+
declare function getProfile(modelId: string): ModelProfile;
|
|
186
|
+
/** Get all profiles with status "current". */
|
|
187
|
+
declare function getCurrentProfiles(): Record<string, ModelProfile>;
|
|
188
|
+
/** Get profiles filtered by provider. */
|
|
189
|
+
declare function getProfilesByProvider(provider: string): Record<string, ModelProfile>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Per-tool execution policies — advises consumers on parallel safety.
|
|
193
|
+
*
|
|
194
|
+
* These tools cause side effects when called concurrently.
|
|
195
|
+
* The adapter advises; the consumer enforces.
|
|
196
|
+
*
|
|
197
|
+
* Source: tt-intelligence production data (61 fixtures, 50+ sessions).
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
/** Tools that must NOT run in parallel. */
|
|
201
|
+
declare const SERIAL_TOOLS: Record<string, string>;
|
|
202
|
+
/** Compute tool policies for a set of tools. Only returns policies for serial-only tools. */
|
|
203
|
+
declare function computeToolPolicies(tools: ToolDefinition[]): ToolPolicy[];
|
|
204
|
+
/** Detect parallelism violations in a list of called tools. */
|
|
205
|
+
declare function detectParallelismWarnings(toolsCalled: string[]): string[];
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Token counting — lightweight estimation for token budgeting.
|
|
209
|
+
*
|
|
210
|
+
* Uses char/4 heuristic by default (within 15% of tiktoken for English).
|
|
211
|
+
* The adapter's 10% safety margin on context budget absorbs the error.
|
|
212
|
+
*
|
|
213
|
+
* For precise counting, callers can inject a custom tokenizer via setTokenizer().
|
|
214
|
+
* Example: setTokenizer(text => tiktoken.encode(text).length)
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Override the default tokenizer with a precise one.
|
|
219
|
+
*
|
|
220
|
+
* Example with js-tiktoken:
|
|
221
|
+
* import { encodingForModel } from 'js-tiktoken';
|
|
222
|
+
* const enc = encodingForModel('gpt-4o');
|
|
223
|
+
* setTokenizer(text => enc.encode(text).length);
|
|
224
|
+
*/
|
|
225
|
+
declare function setTokenizer(fn: (text: string) => number): void;
|
|
226
|
+
/** Count tokens in a string. */
|
|
227
|
+
declare function countTokens(text: string): number;
|
|
228
|
+
|
|
229
|
+
export { type AdapterConstraints, ConsoleDestination, HttpDestination, type KGAutoConfig, type LogDestination, type LogInput, type LogResult, type Message, type ModelProfile, PROFILES, type PrepareInput, type PrepareResult, SERIAL_TOOLS, SilentDestination, type ToolDefinition, type ToolPolicy, computeDiagnostics, computeToolPolicies, countTokens, detectParallelismWarnings, getCurrentProfiles, getProfile, getProfilesByProvider, log, prepare, setTokenizer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KG-auto types — shared across adapter, logger, and public API.
|
|
3
|
+
*/
|
|
4
|
+
interface ModelProfile {
|
|
5
|
+
id: string;
|
|
6
|
+
provider: string;
|
|
7
|
+
status: 'current' | 'legacy' | 'preview';
|
|
8
|
+
max_tools: number;
|
|
9
|
+
max_context_tokens: number;
|
|
10
|
+
max_output_tokens: number;
|
|
11
|
+
parallel_tool_calls: boolean;
|
|
12
|
+
output_modes: ('generateText' | 'generateObject')[];
|
|
13
|
+
prompt_rules: string[];
|
|
14
|
+
known_failures: string[];
|
|
15
|
+
strengths: string[];
|
|
16
|
+
weaknesses: string[];
|
|
17
|
+
cost_input_per_1m: number;
|
|
18
|
+
cost_output_per_1m: number;
|
|
19
|
+
step_limit_default: number;
|
|
20
|
+
notes: string;
|
|
21
|
+
}
|
|
22
|
+
interface Message {
|
|
23
|
+
role: string;
|
|
24
|
+
content: string;
|
|
25
|
+
}
|
|
26
|
+
interface ToolDefinition {
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
parameters?: Record<string, unknown>;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
interface AdapterConstraints {
|
|
33
|
+
/** Tool relevance scores (0-1). Higher = more likely to be kept during budgeting. */
|
|
34
|
+
relevanceHints?: Record<string, number>;
|
|
35
|
+
/** Hard word limit injected into system prompt. */
|
|
36
|
+
maxResponseWords?: number;
|
|
37
|
+
/** Whether the caller wants structured JSON output. */
|
|
38
|
+
structuredOutput?: boolean;
|
|
39
|
+
/** Max latency hint (advisory, not enforced by adapter). */
|
|
40
|
+
maxLatencyMs?: number;
|
|
41
|
+
/** Quality floor hint (advisory). */
|
|
42
|
+
qualityFloor?: number;
|
|
43
|
+
/** Caller-provided intent classification (skips heuristic detection). */
|
|
44
|
+
intentHint?: string;
|
|
45
|
+
/** Project identifier for logging. */
|
|
46
|
+
project?: string;
|
|
47
|
+
}
|
|
48
|
+
interface PrepareInput {
|
|
49
|
+
/** Target model profile ID (e.g. "gemini-2.5-flash"). */
|
|
50
|
+
model: string;
|
|
51
|
+
/** Raw system prompt before adaptation. */
|
|
52
|
+
systemPrompt: string;
|
|
53
|
+
/** Conversation messages. */
|
|
54
|
+
messages: Message[];
|
|
55
|
+
/** Available tools — adapter may reduce this set. */
|
|
56
|
+
tools?: ToolDefinition[];
|
|
57
|
+
/** Constraints and hints. */
|
|
58
|
+
constraints?: AdapterConstraints;
|
|
59
|
+
}
|
|
60
|
+
interface ToolPolicy {
|
|
61
|
+
name: string;
|
|
62
|
+
parallelSafe: boolean;
|
|
63
|
+
maxPerResponse: number | null;
|
|
64
|
+
reason: string | null;
|
|
65
|
+
}
|
|
66
|
+
interface PrepareResult {
|
|
67
|
+
requestId: string;
|
|
68
|
+
model: string;
|
|
69
|
+
provider: string;
|
|
70
|
+
systemPrompt: string;
|
|
71
|
+
messages: Message[];
|
|
72
|
+
tools: ToolDefinition[];
|
|
73
|
+
outputStrategy: 'generateText' | 'generateObject';
|
|
74
|
+
promptRulesApplied: string[];
|
|
75
|
+
tokensEstimated: number;
|
|
76
|
+
contextBudget: number;
|
|
77
|
+
toolsOriginalCount: number;
|
|
78
|
+
toolsSelectedCount: number;
|
|
79
|
+
toolPolicies: ToolPolicy[] | null;
|
|
80
|
+
}
|
|
81
|
+
interface LogInput {
|
|
82
|
+
requestId: string;
|
|
83
|
+
model: string;
|
|
84
|
+
provider: string;
|
|
85
|
+
project?: string;
|
|
86
|
+
intent?: string;
|
|
87
|
+
toolsOffered?: number;
|
|
88
|
+
toolsSelected?: number;
|
|
89
|
+
toolsUsed?: number;
|
|
90
|
+
tokensIn: number;
|
|
91
|
+
tokensOut: number;
|
|
92
|
+
latencyMs: number;
|
|
93
|
+
success: boolean;
|
|
94
|
+
emptyResponse?: boolean;
|
|
95
|
+
errorType?: string;
|
|
96
|
+
adapterRulesApplied?: string[];
|
|
97
|
+
mode?: string;
|
|
98
|
+
toolsCalled?: string[];
|
|
99
|
+
}
|
|
100
|
+
interface LogResult {
|
|
101
|
+
logged: boolean;
|
|
102
|
+
requestId: string;
|
|
103
|
+
inputRatio: number | null;
|
|
104
|
+
efficiencyFlag: 'healthy' | 'warning' | 'critical' | null;
|
|
105
|
+
textOnly: boolean | null;
|
|
106
|
+
parallelismWarnings: string[] | null;
|
|
107
|
+
}
|
|
108
|
+
interface KGAutoConfig {
|
|
109
|
+
/** Optional: HTTP endpoint for centralized logging. If omitted, logs to console. */
|
|
110
|
+
logUrl?: string;
|
|
111
|
+
/** Project identifier for logging. Default: "default". */
|
|
112
|
+
project?: string;
|
|
113
|
+
/** Suppress console log output. Default: false. */
|
|
114
|
+
silent?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Request Adapter — transforms raw requests so the target model handles them correctly.
|
|
119
|
+
*
|
|
120
|
+
* Port of gateway/adapter.py. Pure transform, no IO, no state.
|
|
121
|
+
*
|
|
122
|
+
* Three stages applied in order:
|
|
123
|
+
* 1. Unified token budget (tools + system prompt + messages share one context window)
|
|
124
|
+
* 2. Prompt rewriting (composable rules from model profile)
|
|
125
|
+
* 3. Output strategy selection (generateObject vs generateText)
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Prepare a request for a specific model.
|
|
130
|
+
*
|
|
131
|
+
* Pure function. Takes the raw request and returns an adapted request
|
|
132
|
+
* with budgeted tools, rewritten prompt, and output strategy.
|
|
133
|
+
*
|
|
134
|
+
* Throws Error if the system prompt exceeds the model's context budget.
|
|
135
|
+
*/
|
|
136
|
+
declare function prepare(input: PrepareInput): PrepareResult;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Outcome logger — diagnostics for every model call.
|
|
140
|
+
*
|
|
141
|
+
* Three destinations:
|
|
142
|
+
* - console (default): human-readable log line
|
|
143
|
+
* - http: POST to a centralized endpoint (fire-and-forget)
|
|
144
|
+
* - silent: no output (for tests)
|
|
145
|
+
*
|
|
146
|
+
* Every log() call returns instant diagnostics:
|
|
147
|
+
* - efficiency flag (input/output ratio assessment)
|
|
148
|
+
* - text-only detection (tools offered but none used)
|
|
149
|
+
* - parallelism warnings (serial-only tools called multiple times)
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/** Compute all diagnostics for a log entry. */
|
|
153
|
+
declare function computeDiagnostics(input: LogInput): LogResult;
|
|
154
|
+
interface LogDestination {
|
|
155
|
+
write(input: LogInput, result: LogResult): void;
|
|
156
|
+
}
|
|
157
|
+
declare class ConsoleDestination implements LogDestination {
|
|
158
|
+
write(input: LogInput, result: LogResult): void;
|
|
159
|
+
}
|
|
160
|
+
declare class HttpDestination implements LogDestination {
|
|
161
|
+
private url;
|
|
162
|
+
constructor(url: string);
|
|
163
|
+
write(input: LogInput, _result: LogResult): void;
|
|
164
|
+
}
|
|
165
|
+
declare class SilentDestination implements LogDestination {
|
|
166
|
+
write(): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Log an outcome and return instant diagnostics.
|
|
170
|
+
*
|
|
171
|
+
* The diagnostics are computed synchronously. The write to the destination
|
|
172
|
+
* is fire-and-forget (may be async for HTTP, but never blocks the caller).
|
|
173
|
+
*/
|
|
174
|
+
declare function log(input: LogInput, destination: LogDestination): LogResult;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Model profiles — bundled at build time from profiles/models.yaml.
|
|
178
|
+
*
|
|
179
|
+
* Adding a model = adding an entry to profiles.json + npm version bump.
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
/** All loaded model profiles, keyed by model ID. */
|
|
183
|
+
declare const PROFILES: Readonly<Record<string, ModelProfile>>;
|
|
184
|
+
/** Get a single profile by ID. Throws if not found. */
|
|
185
|
+
declare function getProfile(modelId: string): ModelProfile;
|
|
186
|
+
/** Get all profiles with status "current". */
|
|
187
|
+
declare function getCurrentProfiles(): Record<string, ModelProfile>;
|
|
188
|
+
/** Get profiles filtered by provider. */
|
|
189
|
+
declare function getProfilesByProvider(provider: string): Record<string, ModelProfile>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Per-tool execution policies — advises consumers on parallel safety.
|
|
193
|
+
*
|
|
194
|
+
* These tools cause side effects when called concurrently.
|
|
195
|
+
* The adapter advises; the consumer enforces.
|
|
196
|
+
*
|
|
197
|
+
* Source: tt-intelligence production data (61 fixtures, 50+ sessions).
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
/** Tools that must NOT run in parallel. */
|
|
201
|
+
declare const SERIAL_TOOLS: Record<string, string>;
|
|
202
|
+
/** Compute tool policies for a set of tools. Only returns policies for serial-only tools. */
|
|
203
|
+
declare function computeToolPolicies(tools: ToolDefinition[]): ToolPolicy[];
|
|
204
|
+
/** Detect parallelism violations in a list of called tools. */
|
|
205
|
+
declare function detectParallelismWarnings(toolsCalled: string[]): string[];
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Token counting — lightweight estimation for token budgeting.
|
|
209
|
+
*
|
|
210
|
+
* Uses char/4 heuristic by default (within 15% of tiktoken for English).
|
|
211
|
+
* The adapter's 10% safety margin on context budget absorbs the error.
|
|
212
|
+
*
|
|
213
|
+
* For precise counting, callers can inject a custom tokenizer via setTokenizer().
|
|
214
|
+
* Example: setTokenizer(text => tiktoken.encode(text).length)
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Override the default tokenizer with a precise one.
|
|
219
|
+
*
|
|
220
|
+
* Example with js-tiktoken:
|
|
221
|
+
* import { encodingForModel } from 'js-tiktoken';
|
|
222
|
+
* const enc = encodingForModel('gpt-4o');
|
|
223
|
+
* setTokenizer(text => enc.encode(text).length);
|
|
224
|
+
*/
|
|
225
|
+
declare function setTokenizer(fn: (text: string) => number): void;
|
|
226
|
+
/** Count tokens in a string. */
|
|
227
|
+
declare function countTokens(text: string): number;
|
|
228
|
+
|
|
229
|
+
export { type AdapterConstraints, ConsoleDestination, HttpDestination, type KGAutoConfig, type LogDestination, type LogInput, type LogResult, type Message, type ModelProfile, PROFILES, type PrepareInput, type PrepareResult, SERIAL_TOOLS, SilentDestination, type ToolDefinition, type ToolPolicy, computeDiagnostics, computeToolPolicies, countTokens, detectParallelismWarnings, getCurrentProfiles, getProfile, getProfilesByProvider, log, prepare, setTokenizer };
|