lemura 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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/adapters/index.d.mts +45 -0
- package/dist/adapters/index.d.ts +45 -0
- package/dist/adapters/index.js +371 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +369 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters-BSkhv5ac.d.ts +208 -0
- package/dist/adapters-BnG0LEYD.d.mts +208 -0
- package/dist/context/index.d.mts +143 -0
- package/dist/context/index.d.ts +143 -0
- package/dist/context/index.js +321 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +314 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +1375 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1348 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger/index.d.mts +19 -0
- package/dist/logger/index.d.ts +19 -0
- package/dist/logger/index.js +67 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/index.mjs +65 -0
- package/dist/logger/index.mjs.map +1 -0
- package/dist/logger-DxvKliuk.d.mts +37 -0
- package/dist/logger-DxvKliuk.d.ts +37 -0
- package/dist/rag/index.d.mts +10 -0
- package/dist/rag/index.d.ts +10 -0
- package/dist/rag/index.js +43 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/rag/index.mjs +41 -0
- package/dist/rag/index.mjs.map +1 -0
- package/dist/rag-La_Bo-J8.d.mts +45 -0
- package/dist/rag-La_Bo-J8.d.ts +45 -0
- package/dist/skills/index.d.mts +15 -0
- package/dist/skills/index.d.ts +15 -0
- package/dist/skills/index.js +40 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/index.mjs +38 -0
- package/dist/skills/index.mjs.map +1 -0
- package/dist/skills-wc8S-OvC.d.mts +14 -0
- package/dist/skills-wc8S-OvC.d.ts +14 -0
- package/dist/storage-BGu4Loao.d.ts +121 -0
- package/dist/storage-DMcliVVj.d.mts +121 -0
- package/dist/tools/index.d.mts +17 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.js +72 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/index.mjs +70 -0
- package/dist/tools/index.mjs.map +1 -0
- package/dist/types/index.d.mts +118 -0
- package/dist/types/index.d.ts +118 -0
- package/dist/types/index.js +84 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +74 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { I as IToolDefinition } from './storage-BGu4Loao.js';
|
|
2
|
+
|
|
3
|
+
interface ContentBlock {
|
|
4
|
+
type: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
imageUrl?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface ToolResult {
|
|
10
|
+
toolCallId: string;
|
|
11
|
+
content: string;
|
|
12
|
+
}
|
|
13
|
+
interface Turn {
|
|
14
|
+
role: 'user' | 'assistant' | 'tool' | 'system';
|
|
15
|
+
content: string | ContentBlock[];
|
|
16
|
+
tokenCount: number;
|
|
17
|
+
turnIndex: number;
|
|
18
|
+
compressed: boolean;
|
|
19
|
+
toolCalls?: ToolCall[];
|
|
20
|
+
toolResults?: ToolResult[];
|
|
21
|
+
}
|
|
22
|
+
interface ContextWindow {
|
|
23
|
+
systemPrompt: string;
|
|
24
|
+
scratchpad: string;
|
|
25
|
+
turns: Turn[];
|
|
26
|
+
tokenCount: number;
|
|
27
|
+
maxTokens: number;
|
|
28
|
+
compressionSummary?: string;
|
|
29
|
+
metadata: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
interface IContextStrategy {
|
|
32
|
+
name: string;
|
|
33
|
+
priority: number;
|
|
34
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
35
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Represents a single message in the provider format */
|
|
39
|
+
interface NormalizedMessage {
|
|
40
|
+
/** The role of the message sender */
|
|
41
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
42
|
+
/** The text or multimodal content of the message */
|
|
43
|
+
content: string | ContentBlock[];
|
|
44
|
+
/** Name of the tool, required if role is 'tool' */
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Tool calls made by the assistant, present if role is 'assistant' */
|
|
47
|
+
toolCalls?: ToolCall[];
|
|
48
|
+
}
|
|
49
|
+
/** A request strictly normalized for the provider */
|
|
50
|
+
interface CompletionRequest {
|
|
51
|
+
/** Model ID to use */
|
|
52
|
+
model: string;
|
|
53
|
+
/** The array of messages to send to the provider */
|
|
54
|
+
messages: NormalizedMessage[];
|
|
55
|
+
/** Optional array of tool definitions */
|
|
56
|
+
tools?: IToolDefinition[];
|
|
57
|
+
/** Maximum number of tokens to generate */
|
|
58
|
+
maxTokens?: number;
|
|
59
|
+
/** Generation temperature */
|
|
60
|
+
temperature?: number;
|
|
61
|
+
/** Optional array of sequences that will stop generation */
|
|
62
|
+
stopSequences?: string[];
|
|
63
|
+
/** Whether to stream the response back */
|
|
64
|
+
stream?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Tracking of model token usage */
|
|
67
|
+
interface TokenUsage {
|
|
68
|
+
/** Tokens in the prompt */
|
|
69
|
+
promptTokens: number;
|
|
70
|
+
/** Tokens in the completion */
|
|
71
|
+
completionTokens: number;
|
|
72
|
+
/** Total tokens used */
|
|
73
|
+
totalTokens: number;
|
|
74
|
+
}
|
|
75
|
+
/** Structure of a tool call requested by the model */
|
|
76
|
+
interface ToolCall {
|
|
77
|
+
/** Unique ID for the tool call */
|
|
78
|
+
id: string;
|
|
79
|
+
/** Name of the tool to be invoked */
|
|
80
|
+
name: string;
|
|
81
|
+
/** JSON string of arguments to pass to the tool */
|
|
82
|
+
arguments: string;
|
|
83
|
+
}
|
|
84
|
+
/** Standard response from a non-streaming completion */
|
|
85
|
+
interface CompletionResponse {
|
|
86
|
+
/** The text content generated */
|
|
87
|
+
content: string;
|
|
88
|
+
/** Optional tool calls requested */
|
|
89
|
+
toolCalls?: ToolCall[];
|
|
90
|
+
/** The reason generation stopped */
|
|
91
|
+
finishReason: 'stop' | 'tool_call' | 'max_tokens' | 'error';
|
|
92
|
+
/** Token usage statistics */
|
|
93
|
+
usage: TokenUsage;
|
|
94
|
+
/** The unparsed provider response for debugging */
|
|
95
|
+
rawResponse?: unknown;
|
|
96
|
+
}
|
|
97
|
+
/** Structure of a yielded chunk during a streaming completion */
|
|
98
|
+
interface CompletionChunk {
|
|
99
|
+
/** The newly generated text delta */
|
|
100
|
+
delta: string;
|
|
101
|
+
/** Partial tool call delta if generating a tool call */
|
|
102
|
+
toolCallDelta?: Partial<ToolCall>;
|
|
103
|
+
/** True if this is the final chunk */
|
|
104
|
+
finished: boolean;
|
|
105
|
+
/** The reason generation stopped, typically present only on the final chunk */
|
|
106
|
+
finishReason?: CompletionResponse['finishReason'];
|
|
107
|
+
}
|
|
108
|
+
interface TranscriptionRequest {
|
|
109
|
+
audioBase64: string;
|
|
110
|
+
mimeType: string;
|
|
111
|
+
language?: string;
|
|
112
|
+
}
|
|
113
|
+
interface TranscriptionResponse {
|
|
114
|
+
transcript: string;
|
|
115
|
+
confidence: number;
|
|
116
|
+
language: string;
|
|
117
|
+
}
|
|
118
|
+
interface SynthesisRequest {
|
|
119
|
+
text: string;
|
|
120
|
+
voiceId: string;
|
|
121
|
+
format: 'mp3' | 'wav' | 'pcm';
|
|
122
|
+
}
|
|
123
|
+
interface AudioChunk {
|
|
124
|
+
audioBase64: string;
|
|
125
|
+
}
|
|
126
|
+
interface VisionRequest {
|
|
127
|
+
imageBase64: string;
|
|
128
|
+
prompt?: string;
|
|
129
|
+
}
|
|
130
|
+
interface VisionResponse {
|
|
131
|
+
description: string;
|
|
132
|
+
objects: string[];
|
|
133
|
+
}
|
|
134
|
+
interface ImageGenRequest {
|
|
135
|
+
prompt: string;
|
|
136
|
+
dimensions: string;
|
|
137
|
+
}
|
|
138
|
+
interface ImageGenResponse {
|
|
139
|
+
imageUrl: string;
|
|
140
|
+
revisedPrompt?: string;
|
|
141
|
+
}
|
|
142
|
+
/** Basic info about the model's capabilities */
|
|
143
|
+
interface ModelInfo {
|
|
144
|
+
/** Does it support vision? */
|
|
145
|
+
supportsVision: boolean;
|
|
146
|
+
/** Does it support tools? */
|
|
147
|
+
supportsTools: boolean;
|
|
148
|
+
/** Maximum context window size */
|
|
149
|
+
contextWindow: number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Interface that all provider adapters must implement.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* class MyAdapter implements IProviderAdapter {
|
|
156
|
+
* readonly name = 'custom';
|
|
157
|
+
* readonly version = '1.0.0';
|
|
158
|
+
* async complete(request) { ... }
|
|
159
|
+
* ...
|
|
160
|
+
* }
|
|
161
|
+
*/
|
|
162
|
+
interface IProviderAdapter {
|
|
163
|
+
/** The name of the adapter implementation */
|
|
164
|
+
readonly name: string;
|
|
165
|
+
/** The version of the adapter implementation */
|
|
166
|
+
readonly version: string;
|
|
167
|
+
/**
|
|
168
|
+
* Generates a single completion response.
|
|
169
|
+
*
|
|
170
|
+
* @param request - Normalized completion request parameters
|
|
171
|
+
* @returns A promise resolving to the normalized completion response
|
|
172
|
+
* @throws {LemuraAdapterError} When the API fails or capabilities are missing
|
|
173
|
+
*/
|
|
174
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* Streams a completion response back in chunks.
|
|
177
|
+
*
|
|
178
|
+
* @param request - Normalized completion request parameters
|
|
179
|
+
* @returns An async iterable yielding completion chunks
|
|
180
|
+
* @throws {LemuraAdapterError} When the API fails
|
|
181
|
+
*/
|
|
182
|
+
stream(request: CompletionRequest): AsyncIterable<CompletionChunk>;
|
|
183
|
+
transcribe(request: TranscriptionRequest): Promise<TranscriptionResponse>;
|
|
184
|
+
synthesize(request: SynthesisRequest): AsyncIterable<AudioChunk>;
|
|
185
|
+
describeImage(request: VisionRequest): Promise<VisionResponse>;
|
|
186
|
+
generateImage(request: ImageGenRequest): Promise<ImageGenResponse>;
|
|
187
|
+
/**
|
|
188
|
+
* Estimates token count for standard text.
|
|
189
|
+
*
|
|
190
|
+
* @param text - The string to measure
|
|
191
|
+
* @returns The estimated number of tokens
|
|
192
|
+
*/
|
|
193
|
+
estimateTokens(text: string): number;
|
|
194
|
+
/**
|
|
195
|
+
* Gets details about the underlying model's capabilities.
|
|
196
|
+
*
|
|
197
|
+
* @returns An object describing model features
|
|
198
|
+
*/
|
|
199
|
+
getModelInfo(): ModelInfo;
|
|
200
|
+
/**
|
|
201
|
+
* Verify whether the adapter is healthy and reachable.
|
|
202
|
+
*
|
|
203
|
+
* @returns A promise resolving to true if healthy, false otherwise
|
|
204
|
+
*/
|
|
205
|
+
healthCheck(): Promise<boolean>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type { AudioChunk as A, ContextWindow as C, IContextStrategy as I, ModelInfo as M, NormalizedMessage as N, SynthesisRequest as S, Turn as T, VisionRequest as V, ContentBlock as a, CompletionChunk as b, CompletionRequest as c, CompletionResponse as d, IProviderAdapter as e, ImageGenRequest as f, ImageGenResponse as g, TokenUsage as h, ToolCall as i, ToolResult as j, TranscriptionRequest as k, TranscriptionResponse as l, VisionResponse as m };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { I as IToolDefinition } from './storage-DMcliVVj.mjs';
|
|
2
|
+
|
|
3
|
+
interface ContentBlock {
|
|
4
|
+
type: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
imageUrl?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface ToolResult {
|
|
10
|
+
toolCallId: string;
|
|
11
|
+
content: string;
|
|
12
|
+
}
|
|
13
|
+
interface Turn {
|
|
14
|
+
role: 'user' | 'assistant' | 'tool' | 'system';
|
|
15
|
+
content: string | ContentBlock[];
|
|
16
|
+
tokenCount: number;
|
|
17
|
+
turnIndex: number;
|
|
18
|
+
compressed: boolean;
|
|
19
|
+
toolCalls?: ToolCall[];
|
|
20
|
+
toolResults?: ToolResult[];
|
|
21
|
+
}
|
|
22
|
+
interface ContextWindow {
|
|
23
|
+
systemPrompt: string;
|
|
24
|
+
scratchpad: string;
|
|
25
|
+
turns: Turn[];
|
|
26
|
+
tokenCount: number;
|
|
27
|
+
maxTokens: number;
|
|
28
|
+
compressionSummary?: string;
|
|
29
|
+
metadata: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
interface IContextStrategy {
|
|
32
|
+
name: string;
|
|
33
|
+
priority: number;
|
|
34
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
35
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Represents a single message in the provider format */
|
|
39
|
+
interface NormalizedMessage {
|
|
40
|
+
/** The role of the message sender */
|
|
41
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
42
|
+
/** The text or multimodal content of the message */
|
|
43
|
+
content: string | ContentBlock[];
|
|
44
|
+
/** Name of the tool, required if role is 'tool' */
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Tool calls made by the assistant, present if role is 'assistant' */
|
|
47
|
+
toolCalls?: ToolCall[];
|
|
48
|
+
}
|
|
49
|
+
/** A request strictly normalized for the provider */
|
|
50
|
+
interface CompletionRequest {
|
|
51
|
+
/** Model ID to use */
|
|
52
|
+
model: string;
|
|
53
|
+
/** The array of messages to send to the provider */
|
|
54
|
+
messages: NormalizedMessage[];
|
|
55
|
+
/** Optional array of tool definitions */
|
|
56
|
+
tools?: IToolDefinition[];
|
|
57
|
+
/** Maximum number of tokens to generate */
|
|
58
|
+
maxTokens?: number;
|
|
59
|
+
/** Generation temperature */
|
|
60
|
+
temperature?: number;
|
|
61
|
+
/** Optional array of sequences that will stop generation */
|
|
62
|
+
stopSequences?: string[];
|
|
63
|
+
/** Whether to stream the response back */
|
|
64
|
+
stream?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Tracking of model token usage */
|
|
67
|
+
interface TokenUsage {
|
|
68
|
+
/** Tokens in the prompt */
|
|
69
|
+
promptTokens: number;
|
|
70
|
+
/** Tokens in the completion */
|
|
71
|
+
completionTokens: number;
|
|
72
|
+
/** Total tokens used */
|
|
73
|
+
totalTokens: number;
|
|
74
|
+
}
|
|
75
|
+
/** Structure of a tool call requested by the model */
|
|
76
|
+
interface ToolCall {
|
|
77
|
+
/** Unique ID for the tool call */
|
|
78
|
+
id: string;
|
|
79
|
+
/** Name of the tool to be invoked */
|
|
80
|
+
name: string;
|
|
81
|
+
/** JSON string of arguments to pass to the tool */
|
|
82
|
+
arguments: string;
|
|
83
|
+
}
|
|
84
|
+
/** Standard response from a non-streaming completion */
|
|
85
|
+
interface CompletionResponse {
|
|
86
|
+
/** The text content generated */
|
|
87
|
+
content: string;
|
|
88
|
+
/** Optional tool calls requested */
|
|
89
|
+
toolCalls?: ToolCall[];
|
|
90
|
+
/** The reason generation stopped */
|
|
91
|
+
finishReason: 'stop' | 'tool_call' | 'max_tokens' | 'error';
|
|
92
|
+
/** Token usage statistics */
|
|
93
|
+
usage: TokenUsage;
|
|
94
|
+
/** The unparsed provider response for debugging */
|
|
95
|
+
rawResponse?: unknown;
|
|
96
|
+
}
|
|
97
|
+
/** Structure of a yielded chunk during a streaming completion */
|
|
98
|
+
interface CompletionChunk {
|
|
99
|
+
/** The newly generated text delta */
|
|
100
|
+
delta: string;
|
|
101
|
+
/** Partial tool call delta if generating a tool call */
|
|
102
|
+
toolCallDelta?: Partial<ToolCall>;
|
|
103
|
+
/** True if this is the final chunk */
|
|
104
|
+
finished: boolean;
|
|
105
|
+
/** The reason generation stopped, typically present only on the final chunk */
|
|
106
|
+
finishReason?: CompletionResponse['finishReason'];
|
|
107
|
+
}
|
|
108
|
+
interface TranscriptionRequest {
|
|
109
|
+
audioBase64: string;
|
|
110
|
+
mimeType: string;
|
|
111
|
+
language?: string;
|
|
112
|
+
}
|
|
113
|
+
interface TranscriptionResponse {
|
|
114
|
+
transcript: string;
|
|
115
|
+
confidence: number;
|
|
116
|
+
language: string;
|
|
117
|
+
}
|
|
118
|
+
interface SynthesisRequest {
|
|
119
|
+
text: string;
|
|
120
|
+
voiceId: string;
|
|
121
|
+
format: 'mp3' | 'wav' | 'pcm';
|
|
122
|
+
}
|
|
123
|
+
interface AudioChunk {
|
|
124
|
+
audioBase64: string;
|
|
125
|
+
}
|
|
126
|
+
interface VisionRequest {
|
|
127
|
+
imageBase64: string;
|
|
128
|
+
prompt?: string;
|
|
129
|
+
}
|
|
130
|
+
interface VisionResponse {
|
|
131
|
+
description: string;
|
|
132
|
+
objects: string[];
|
|
133
|
+
}
|
|
134
|
+
interface ImageGenRequest {
|
|
135
|
+
prompt: string;
|
|
136
|
+
dimensions: string;
|
|
137
|
+
}
|
|
138
|
+
interface ImageGenResponse {
|
|
139
|
+
imageUrl: string;
|
|
140
|
+
revisedPrompt?: string;
|
|
141
|
+
}
|
|
142
|
+
/** Basic info about the model's capabilities */
|
|
143
|
+
interface ModelInfo {
|
|
144
|
+
/** Does it support vision? */
|
|
145
|
+
supportsVision: boolean;
|
|
146
|
+
/** Does it support tools? */
|
|
147
|
+
supportsTools: boolean;
|
|
148
|
+
/** Maximum context window size */
|
|
149
|
+
contextWindow: number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Interface that all provider adapters must implement.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* class MyAdapter implements IProviderAdapter {
|
|
156
|
+
* readonly name = 'custom';
|
|
157
|
+
* readonly version = '1.0.0';
|
|
158
|
+
* async complete(request) { ... }
|
|
159
|
+
* ...
|
|
160
|
+
* }
|
|
161
|
+
*/
|
|
162
|
+
interface IProviderAdapter {
|
|
163
|
+
/** The name of the adapter implementation */
|
|
164
|
+
readonly name: string;
|
|
165
|
+
/** The version of the adapter implementation */
|
|
166
|
+
readonly version: string;
|
|
167
|
+
/**
|
|
168
|
+
* Generates a single completion response.
|
|
169
|
+
*
|
|
170
|
+
* @param request - Normalized completion request parameters
|
|
171
|
+
* @returns A promise resolving to the normalized completion response
|
|
172
|
+
* @throws {LemuraAdapterError} When the API fails or capabilities are missing
|
|
173
|
+
*/
|
|
174
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* Streams a completion response back in chunks.
|
|
177
|
+
*
|
|
178
|
+
* @param request - Normalized completion request parameters
|
|
179
|
+
* @returns An async iterable yielding completion chunks
|
|
180
|
+
* @throws {LemuraAdapterError} When the API fails
|
|
181
|
+
*/
|
|
182
|
+
stream(request: CompletionRequest): AsyncIterable<CompletionChunk>;
|
|
183
|
+
transcribe(request: TranscriptionRequest): Promise<TranscriptionResponse>;
|
|
184
|
+
synthesize(request: SynthesisRequest): AsyncIterable<AudioChunk>;
|
|
185
|
+
describeImage(request: VisionRequest): Promise<VisionResponse>;
|
|
186
|
+
generateImage(request: ImageGenRequest): Promise<ImageGenResponse>;
|
|
187
|
+
/**
|
|
188
|
+
* Estimates token count for standard text.
|
|
189
|
+
*
|
|
190
|
+
* @param text - The string to measure
|
|
191
|
+
* @returns The estimated number of tokens
|
|
192
|
+
*/
|
|
193
|
+
estimateTokens(text: string): number;
|
|
194
|
+
/**
|
|
195
|
+
* Gets details about the underlying model's capabilities.
|
|
196
|
+
*
|
|
197
|
+
* @returns An object describing model features
|
|
198
|
+
*/
|
|
199
|
+
getModelInfo(): ModelInfo;
|
|
200
|
+
/**
|
|
201
|
+
* Verify whether the adapter is healthy and reachable.
|
|
202
|
+
*
|
|
203
|
+
* @returns A promise resolving to true if healthy, false otherwise
|
|
204
|
+
*/
|
|
205
|
+
healthCheck(): Promise<boolean>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type { AudioChunk as A, ContextWindow as C, IContextStrategy as I, ModelInfo as M, NormalizedMessage as N, SynthesisRequest as S, Turn as T, VisionRequest as V, ContentBlock as a, CompletionChunk as b, CompletionRequest as c, CompletionResponse as d, IProviderAdapter as e, ImageGenRequest as f, ImageGenResponse as g, TokenUsage as h, ToolCall as i, ToolResult as j, TranscriptionRequest as k, TranscriptionResponse as l, VisionResponse as m };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { I as IContextStrategy, C as ContextWindow, e as IProviderAdapter } from '../adapters-BnG0LEYD.mjs';
|
|
2
|
+
import { a as IStorageAdapter } from '../storage-DMcliVVj.mjs';
|
|
3
|
+
export { b as STMRegistryConfig, c as ShortTermMemoryRegistry } from '../storage-DMcliVVj.mjs';
|
|
4
|
+
import '../rag-La_Bo-J8.mjs';
|
|
5
|
+
import '../logger-DxvKliuk.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Orchestrates a stack of IContextStrategy implementations to keep the
|
|
9
|
+
* token count within the maxTokens limit.
|
|
10
|
+
*/
|
|
11
|
+
declare class ContextManager {
|
|
12
|
+
private strategies;
|
|
13
|
+
/**
|
|
14
|
+
* Registers a new compression or pre-turn strategy and sorts the stack by priority.
|
|
15
|
+
*
|
|
16
|
+
* @param strategy - The strategy implementation to register
|
|
17
|
+
*/
|
|
18
|
+
registerStrategy(strategy: IContextStrategy): void;
|
|
19
|
+
/**
|
|
20
|
+
* Applies all registered strategies that return true for `shouldApply()`
|
|
21
|
+
* until the context token count is safely below the maximum budget.
|
|
22
|
+
*
|
|
23
|
+
* @param context - The context window to prepare
|
|
24
|
+
* @param safetyMargin - Modifier applied to maxTokens (default: 0.95 -> 95%)
|
|
25
|
+
* @returns A new ContextWindow object potentially compressed
|
|
26
|
+
* @throws {LemuraContextOverflowError} If the context is still over maxTokens after all strategies
|
|
27
|
+
*/
|
|
28
|
+
prepare(context: ContextWindow, safetyMargin?: number): Promise<ContextWindow>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface SandwichCompressionConfig {
|
|
32
|
+
preserveFirst: number;
|
|
33
|
+
preserveLast: number;
|
|
34
|
+
triggerThreshold: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sandwich compression preserves the beginning and end of the conversation,
|
|
38
|
+
* replacing the middle with a generated summary.
|
|
39
|
+
*/
|
|
40
|
+
declare class SandwichCompressionStrategy implements IContextStrategy {
|
|
41
|
+
private adapter;
|
|
42
|
+
private config;
|
|
43
|
+
readonly name = "sandwich_compression";
|
|
44
|
+
readonly priority = 20;
|
|
45
|
+
constructor(adapter: IProviderAdapter, config: SandwichCompressionConfig);
|
|
46
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
47
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
48
|
+
/**
|
|
49
|
+
* Applies sandwich compression specifically to a Short Term Memory item's content.
|
|
50
|
+
* Implements a 3-layer pipeline: Pre-Layer (encoding), Core Layer (dense summary), Post-Layer (refinement cues).
|
|
51
|
+
*
|
|
52
|
+
* @param content - The heavy text content to compress
|
|
53
|
+
* @param instructions - Guiding instructions for the core layer summary
|
|
54
|
+
* @returns The three-layer sandwich result
|
|
55
|
+
*/
|
|
56
|
+
compressMemoryItem(content: string, instructions?: string): Promise<{
|
|
57
|
+
preLayer: string;
|
|
58
|
+
coreLayer: string;
|
|
59
|
+
postLayer: string;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* ScratchpadStrategy manages the thinking process separate from the turn history.
|
|
65
|
+
* It is primarily a marker/pre-turn strategy that ensures scratchpad gets tokenized properly
|
|
66
|
+
* but is not compressed.
|
|
67
|
+
*/
|
|
68
|
+
declare class ScratchpadStrategy implements IContextStrategy {
|
|
69
|
+
readonly name = "scratchpad_strategy";
|
|
70
|
+
readonly priority = 10;
|
|
71
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
72
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
73
|
+
}
|
|
74
|
+
interface HistoryCompressionConfig {
|
|
75
|
+
windowSize: number;
|
|
76
|
+
triggerAtPercent: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Operates on a rolling window of the oldest N turns and summarizes them.
|
|
80
|
+
*/
|
|
81
|
+
declare class HistoryCompressionStrategy implements IContextStrategy {
|
|
82
|
+
private adapter;
|
|
83
|
+
private config;
|
|
84
|
+
readonly name = "history_compression";
|
|
85
|
+
readonly priority = 30;
|
|
86
|
+
constructor(adapter: IProviderAdapter, config: HistoryCompressionConfig);
|
|
87
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
88
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* An in-memory implementation of IStorageAdapter for holding Short Term Memory.
|
|
93
|
+
* Ideal for testing or single-process lightweight usage.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const storage = new InMemoryStorageAdapter();
|
|
97
|
+
* const id = await storage.set(undefined, 'my content', { type: 'text' });
|
|
98
|
+
* const retrieved = await storage.get(id);
|
|
99
|
+
*/
|
|
100
|
+
declare class InMemoryStorageAdapter implements IStorageAdapter {
|
|
101
|
+
private store;
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves stored content by ID.
|
|
104
|
+
*
|
|
105
|
+
* @param id - The identifier of the stored item
|
|
106
|
+
* @returns The stored content or undefined if not found
|
|
107
|
+
*/
|
|
108
|
+
get(id: string): Promise<any | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the full item including metadata.
|
|
111
|
+
*
|
|
112
|
+
* @param id - The identifier of the stored item
|
|
113
|
+
* @returns The complete item with content and metadata
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
getFull(id: string): Promise<{
|
|
117
|
+
content: any;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
} | undefined>;
|
|
120
|
+
/**
|
|
121
|
+
* Stores content, generating an ID if none is provided.
|
|
122
|
+
*
|
|
123
|
+
* @param id - Optional provided ID. If omitted, a UUID is generated.
|
|
124
|
+
* @param content - The content to store
|
|
125
|
+
* @param metadata - Optional metadata
|
|
126
|
+
* @returns The ID under which the content is stored
|
|
127
|
+
*/
|
|
128
|
+
set(id: string | undefined, content: any, metadata?: Record<string, unknown>): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Deletes the content for the given ID.
|
|
131
|
+
*
|
|
132
|
+
* @param id - The identifier of the item to delete
|
|
133
|
+
*/
|
|
134
|
+
delete(id: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Synchronous health check, always true for in-memory.
|
|
137
|
+
*
|
|
138
|
+
* @returns true
|
|
139
|
+
*/
|
|
140
|
+
healthCheck(): Promise<boolean>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { ContextManager, type HistoryCompressionConfig, HistoryCompressionStrategy, InMemoryStorageAdapter, type SandwichCompressionConfig, SandwichCompressionStrategy, ScratchpadStrategy };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { I as IContextStrategy, C as ContextWindow, e as IProviderAdapter } from '../adapters-BSkhv5ac.js';
|
|
2
|
+
import { a as IStorageAdapter } from '../storage-BGu4Loao.js';
|
|
3
|
+
export { b as STMRegistryConfig, c as ShortTermMemoryRegistry } from '../storage-BGu4Loao.js';
|
|
4
|
+
import '../rag-La_Bo-J8.js';
|
|
5
|
+
import '../logger-DxvKliuk.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Orchestrates a stack of IContextStrategy implementations to keep the
|
|
9
|
+
* token count within the maxTokens limit.
|
|
10
|
+
*/
|
|
11
|
+
declare class ContextManager {
|
|
12
|
+
private strategies;
|
|
13
|
+
/**
|
|
14
|
+
* Registers a new compression or pre-turn strategy and sorts the stack by priority.
|
|
15
|
+
*
|
|
16
|
+
* @param strategy - The strategy implementation to register
|
|
17
|
+
*/
|
|
18
|
+
registerStrategy(strategy: IContextStrategy): void;
|
|
19
|
+
/**
|
|
20
|
+
* Applies all registered strategies that return true for `shouldApply()`
|
|
21
|
+
* until the context token count is safely below the maximum budget.
|
|
22
|
+
*
|
|
23
|
+
* @param context - The context window to prepare
|
|
24
|
+
* @param safetyMargin - Modifier applied to maxTokens (default: 0.95 -> 95%)
|
|
25
|
+
* @returns A new ContextWindow object potentially compressed
|
|
26
|
+
* @throws {LemuraContextOverflowError} If the context is still over maxTokens after all strategies
|
|
27
|
+
*/
|
|
28
|
+
prepare(context: ContextWindow, safetyMargin?: number): Promise<ContextWindow>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface SandwichCompressionConfig {
|
|
32
|
+
preserveFirst: number;
|
|
33
|
+
preserveLast: number;
|
|
34
|
+
triggerThreshold: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sandwich compression preserves the beginning and end of the conversation,
|
|
38
|
+
* replacing the middle with a generated summary.
|
|
39
|
+
*/
|
|
40
|
+
declare class SandwichCompressionStrategy implements IContextStrategy {
|
|
41
|
+
private adapter;
|
|
42
|
+
private config;
|
|
43
|
+
readonly name = "sandwich_compression";
|
|
44
|
+
readonly priority = 20;
|
|
45
|
+
constructor(adapter: IProviderAdapter, config: SandwichCompressionConfig);
|
|
46
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
47
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
48
|
+
/**
|
|
49
|
+
* Applies sandwich compression specifically to a Short Term Memory item's content.
|
|
50
|
+
* Implements a 3-layer pipeline: Pre-Layer (encoding), Core Layer (dense summary), Post-Layer (refinement cues).
|
|
51
|
+
*
|
|
52
|
+
* @param content - The heavy text content to compress
|
|
53
|
+
* @param instructions - Guiding instructions for the core layer summary
|
|
54
|
+
* @returns The three-layer sandwich result
|
|
55
|
+
*/
|
|
56
|
+
compressMemoryItem(content: string, instructions?: string): Promise<{
|
|
57
|
+
preLayer: string;
|
|
58
|
+
coreLayer: string;
|
|
59
|
+
postLayer: string;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* ScratchpadStrategy manages the thinking process separate from the turn history.
|
|
65
|
+
* It is primarily a marker/pre-turn strategy that ensures scratchpad gets tokenized properly
|
|
66
|
+
* but is not compressed.
|
|
67
|
+
*/
|
|
68
|
+
declare class ScratchpadStrategy implements IContextStrategy {
|
|
69
|
+
readonly name = "scratchpad_strategy";
|
|
70
|
+
readonly priority = 10;
|
|
71
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
72
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
73
|
+
}
|
|
74
|
+
interface HistoryCompressionConfig {
|
|
75
|
+
windowSize: number;
|
|
76
|
+
triggerAtPercent: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Operates on a rolling window of the oldest N turns and summarizes them.
|
|
80
|
+
*/
|
|
81
|
+
declare class HistoryCompressionStrategy implements IContextStrategy {
|
|
82
|
+
private adapter;
|
|
83
|
+
private config;
|
|
84
|
+
readonly name = "history_compression";
|
|
85
|
+
readonly priority = 30;
|
|
86
|
+
constructor(adapter: IProviderAdapter, config: HistoryCompressionConfig);
|
|
87
|
+
shouldApply(ctx: ContextWindow): boolean;
|
|
88
|
+
apply(ctx: ContextWindow): Promise<ContextWindow>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* An in-memory implementation of IStorageAdapter for holding Short Term Memory.
|
|
93
|
+
* Ideal for testing or single-process lightweight usage.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const storage = new InMemoryStorageAdapter();
|
|
97
|
+
* const id = await storage.set(undefined, 'my content', { type: 'text' });
|
|
98
|
+
* const retrieved = await storage.get(id);
|
|
99
|
+
*/
|
|
100
|
+
declare class InMemoryStorageAdapter implements IStorageAdapter {
|
|
101
|
+
private store;
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves stored content by ID.
|
|
104
|
+
*
|
|
105
|
+
* @param id - The identifier of the stored item
|
|
106
|
+
* @returns The stored content or undefined if not found
|
|
107
|
+
*/
|
|
108
|
+
get(id: string): Promise<any | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the full item including metadata.
|
|
111
|
+
*
|
|
112
|
+
* @param id - The identifier of the stored item
|
|
113
|
+
* @returns The complete item with content and metadata
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
getFull(id: string): Promise<{
|
|
117
|
+
content: any;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
} | undefined>;
|
|
120
|
+
/**
|
|
121
|
+
* Stores content, generating an ID if none is provided.
|
|
122
|
+
*
|
|
123
|
+
* @param id - Optional provided ID. If omitted, a UUID is generated.
|
|
124
|
+
* @param content - The content to store
|
|
125
|
+
* @param metadata - Optional metadata
|
|
126
|
+
* @returns The ID under which the content is stored
|
|
127
|
+
*/
|
|
128
|
+
set(id: string | undefined, content: any, metadata?: Record<string, unknown>): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Deletes the content for the given ID.
|
|
131
|
+
*
|
|
132
|
+
* @param id - The identifier of the item to delete
|
|
133
|
+
*/
|
|
134
|
+
delete(id: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Synchronous health check, always true for in-memory.
|
|
137
|
+
*
|
|
138
|
+
* @returns true
|
|
139
|
+
*/
|
|
140
|
+
healthCheck(): Promise<boolean>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { ContextManager, type HistoryCompressionConfig, HistoryCompressionStrategy, InMemoryStorageAdapter, type SandwichCompressionConfig, SandwichCompressionStrategy, ScratchpadStrategy };
|