@deepagents/context 0.8.1 → 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/dist/index.d.ts +93 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +297 -103
- package/dist/index.js.map +4 -4
- package/dist/lib/agent.d.ts +28 -0
- package/dist/lib/agent.d.ts.map +1 -0
- package/dist/lib/codec.d.ts +17 -0
- package/dist/lib/codec.d.ts.map +1 -0
- package/dist/lib/context.d.ts +6 -0
- package/dist/lib/context.d.ts.map +1 -1
- package/dist/lib/estimate.d.ts +15 -2
- package/dist/lib/estimate.d.ts.map +1 -1
- package/dist/lib/store/sqlite.store.d.ts +4 -3
- package/dist/lib/store/sqlite.store.d.ts.map +1 -1
- package/dist/lib/store/store.d.ts +14 -3
- package/dist/lib/store/store.d.ts.map +1 -1
- package/package.json +7 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
+
import { type UIMessage } from 'ai';
|
|
1
2
|
import type { ContextFragment } from './lib/context.ts';
|
|
2
3
|
import { type EstimateResult } from './lib/estimate.ts';
|
|
3
4
|
import type { Models } from './lib/models.generated.ts';
|
|
4
5
|
import { type ContextRenderer } from './lib/renderers/abstract.renderer.ts';
|
|
5
|
-
import { type BranchInfo, type CheckpointInfo, ContextStore } from './lib/store/store.ts';
|
|
6
|
-
export type {
|
|
6
|
+
import { type BranchInfo, type CheckpointInfo, ContextStore, type GraphData, type MessageData } from './lib/store/store.ts';
|
|
7
|
+
export type { FragmentCodec } from './lib/codec.ts';
|
|
7
8
|
export { isMessageFragment } from './lib/context.ts';
|
|
8
|
-
export
|
|
9
|
-
export { SqliteContextStore } from './lib/store/sqlite.store.ts';
|
|
9
|
+
export type { ContextFragment, FragmentType } from './lib/context.ts';
|
|
10
10
|
export { InMemoryContextStore } from './lib/store/memory.store.ts';
|
|
11
|
+
export { SqliteContextStore } from './lib/store/sqlite.store.ts';
|
|
12
|
+
export { ContextStore, type BranchData, type BranchInfo, type ChatData, type ChatInfo, type CheckpointData, type CheckpointInfo, type GraphBranch, type GraphCheckpoint, type GraphData, type GraphNode, type MessageData, type MessageInfo, type SearchOptions, type SearchResult, type StoredChatData, } from './lib/store/store.ts';
|
|
11
13
|
export { visualizeGraph } from './lib/visualize.ts';
|
|
12
|
-
/**
|
|
13
|
-
* Message format compatible with AI SDK's CoreMessage.
|
|
14
|
-
*/
|
|
15
|
-
export interface Message {
|
|
16
|
-
role: 'user' | 'assistant' | 'system';
|
|
17
|
-
content: string;
|
|
18
|
-
}
|
|
19
14
|
/**
|
|
20
15
|
* Result of resolving context - ready for AI SDK consumption.
|
|
21
16
|
*/
|
|
@@ -23,14 +18,14 @@ export interface ResolveResult {
|
|
|
23
18
|
/** Rendered non-message fragments for system prompt */
|
|
24
19
|
systemPrompt: string;
|
|
25
20
|
/** Message fragments decoded to AI SDK format */
|
|
26
|
-
messages:
|
|
21
|
+
messages: unknown[];
|
|
27
22
|
}
|
|
28
23
|
/**
|
|
29
24
|
* Options for resolve().
|
|
30
25
|
*/
|
|
31
26
|
export interface ResolveOptions {
|
|
32
27
|
/** Renderer to use for system prompt (defaults to XmlRenderer) */
|
|
33
|
-
renderer
|
|
28
|
+
renderer: ContextRenderer;
|
|
34
29
|
}
|
|
35
30
|
/**
|
|
36
31
|
* Options for creating a ContextEngine.
|
|
@@ -65,9 +60,45 @@ export interface ChatMeta {
|
|
|
65
60
|
/** Optional custom metadata */
|
|
66
61
|
metadata?: Record<string, unknown>;
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Options for context inspection.
|
|
65
|
+
*/
|
|
66
|
+
export interface InspectOptions {
|
|
67
|
+
/** Model ID for cost estimation (required) */
|
|
68
|
+
modelId: Models;
|
|
69
|
+
/** Renderer for estimation (required) */
|
|
70
|
+
renderer: ContextRenderer;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Result of inspecting context state.
|
|
74
|
+
* Provides a comprehensive JSON-serializable snapshot for debugging.
|
|
75
|
+
*/
|
|
76
|
+
export interface InspectResult {
|
|
77
|
+
/** Token usage and cost estimation */
|
|
78
|
+
estimate: EstimateResult;
|
|
79
|
+
/** Rendered output using the provided renderer */
|
|
80
|
+
rendered: string;
|
|
81
|
+
/** Fragment structure breakdown */
|
|
82
|
+
fragments: {
|
|
83
|
+
/** Non-message fragments (role, hints, etc.) */
|
|
84
|
+
context: ContextFragment[];
|
|
85
|
+
/** Pending messages not yet saved to store */
|
|
86
|
+
pending: ContextFragment[];
|
|
87
|
+
/** Persisted messages from the store */
|
|
88
|
+
persisted: MessageData[];
|
|
89
|
+
};
|
|
90
|
+
/** Conversation graph with branches and checkpoints */
|
|
91
|
+
graph: GraphData;
|
|
92
|
+
/** Inspection metadata */
|
|
93
|
+
meta: {
|
|
94
|
+
chatId: string;
|
|
95
|
+
branch: string;
|
|
96
|
+
timestamp: number;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export { ModelsRegistry, defaultTokenizer, estimate, getModelsRegistry, type EstimateResult, type FragmentEstimate, type ModelCost, type ModelInfo, type Tokenizer, } from './lib/estimate.ts';
|
|
100
|
+
export type { KnownModels, Models } from './lib/models.generated.ts';
|
|
101
|
+
export { MarkdownRenderer, TomlRenderer, ToonRenderer, XmlRenderer, type ContextRenderer, type RendererOptions, } from './lib/renderers/abstract.renderer.ts';
|
|
71
102
|
/**
|
|
72
103
|
* Context engine for managing AI conversation context with graph-based storage.
|
|
73
104
|
*
|
|
@@ -122,7 +153,7 @@ export declare class ContextEngine {
|
|
|
122
153
|
* await generateText({ system: systemPrompt, messages });
|
|
123
154
|
* ```
|
|
124
155
|
*/
|
|
125
|
-
resolve(options
|
|
156
|
+
resolve(options: ResolveOptions): Promise<ResolveResult>;
|
|
126
157
|
/**
|
|
127
158
|
* Save pending messages to the graph.
|
|
128
159
|
*
|
|
@@ -139,11 +170,16 @@ export declare class ContextEngine {
|
|
|
139
170
|
*/
|
|
140
171
|
save(): Promise<void>;
|
|
141
172
|
/**
|
|
142
|
-
* Estimate token count and cost for the
|
|
173
|
+
* Estimate token count and cost for the full context.
|
|
174
|
+
*
|
|
175
|
+
* Includes:
|
|
176
|
+
* - System prompt fragments (role, hints, etc.)
|
|
177
|
+
* - Persisted chat messages (from store)
|
|
178
|
+
* - Pending messages (not yet saved)
|
|
143
179
|
*
|
|
144
180
|
* @param modelId - Model ID (e.g., "openai:gpt-4o", "anthropic:claude-3-5-sonnet")
|
|
145
181
|
* @param options - Optional settings
|
|
146
|
-
* @returns Estimate result with token counts and
|
|
182
|
+
* @returns Estimate result with token counts, costs, and per-fragment breakdown
|
|
147
183
|
*/
|
|
148
184
|
estimate(modelId: Models, options?: {
|
|
149
185
|
renderer?: ContextRenderer;
|
|
@@ -248,6 +284,26 @@ export declare class ContextEngine {
|
|
|
248
284
|
* @experimental
|
|
249
285
|
*/
|
|
250
286
|
consolidate(): void;
|
|
287
|
+
/**
|
|
288
|
+
* Inspect the full context state for debugging.
|
|
289
|
+
* Returns a comprehensive JSON-serializable object with all context information.
|
|
290
|
+
*
|
|
291
|
+
* @param options - Inspection options (modelId and renderer required)
|
|
292
|
+
* @returns Complete inspection data including estimates, rendered output, fragments, and graph
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* const inspection = await context.inspect({
|
|
297
|
+
* modelId: 'openai:gpt-4o',
|
|
298
|
+
* renderer: new XmlRenderer(),
|
|
299
|
+
* });
|
|
300
|
+
* console.log(JSON.stringify(inspection, null, 2));
|
|
301
|
+
*
|
|
302
|
+
* // Or write to file for analysis
|
|
303
|
+
* await fs.writeFile('context-debug.json', JSON.stringify(inspection, null, 2));
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
inspect(options: InspectOptions): Promise<InspectResult>;
|
|
251
307
|
}
|
|
252
308
|
export declare function hint(text: string): ContextFragment;
|
|
253
309
|
export declare function fragment(name: string, ...children: ContextFragment[]): ContextFragment;
|
|
@@ -268,12 +324,12 @@ export declare function role(content: string): ContextFragment;
|
|
|
268
324
|
* context.set(user('Hello', { id: 'msg-1' })); // Custom ID
|
|
269
325
|
* ```
|
|
270
326
|
*/
|
|
271
|
-
export declare function user(content: string
|
|
327
|
+
export declare function user(content: string | UIMessage): ContextFragment;
|
|
272
328
|
/**
|
|
273
329
|
* Create an assistant message fragment.
|
|
274
330
|
* Message fragments are separated from regular fragments during resolve().
|
|
275
331
|
*
|
|
276
|
-
* @param
|
|
332
|
+
* @param message - The message content
|
|
277
333
|
* @param options - Optional settings (id)
|
|
278
334
|
*
|
|
279
335
|
* @example
|
|
@@ -282,5 +338,20 @@ export declare function user(content: string, options?: MessageOptions): Context
|
|
|
282
338
|
* context.set(assistant('Hi there!', { id: 'resp-1' })); // Custom ID
|
|
283
339
|
* ```
|
|
284
340
|
*/
|
|
285
|
-
export declare function assistant(
|
|
341
|
+
export declare function assistant(message: UIMessage): ContextFragment;
|
|
342
|
+
export declare function message(content: string | UIMessage): ContextFragment;
|
|
343
|
+
/**
|
|
344
|
+
* Create an assistant message fragment from text content.
|
|
345
|
+
* Convenience wrapper that creates a UIMessage internally.
|
|
346
|
+
*
|
|
347
|
+
* @param content - The message text content
|
|
348
|
+
* @param options - Optional settings (id)
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* context.set(assistantText('Hi there!')); // Auto-generated ID
|
|
353
|
+
* context.set(assistantText('Hi there!', { id: 'resp-1' })); // Custom ID
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
export declare function assistantText(content: string, options?: MessageOptions): ContextFragment;
|
|
286
357
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,e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