@deepagents/context 0.8.1 → 0.10.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 +125 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +371 -127
- 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;
|
|
@@ -225,6 +261,38 @@ export declare class ContextEngine {
|
|
|
225
261
|
* ```
|
|
226
262
|
*/
|
|
227
263
|
switchBranch(name: string): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* Create a parallel branch from the current position ("by the way").
|
|
266
|
+
*
|
|
267
|
+
* Use this when you want to fork the conversation without leaving
|
|
268
|
+
* the current branch. Common use case: user wants to ask another
|
|
269
|
+
* question while waiting for the model to respond.
|
|
270
|
+
*
|
|
271
|
+
* Unlike rewind(), this method:
|
|
272
|
+
* - Uses the current HEAD (no messageId needed)
|
|
273
|
+
* - Does NOT switch to the new branch
|
|
274
|
+
* - Keeps pending messages intact
|
|
275
|
+
*
|
|
276
|
+
* @returns The new branch info (does not switch to it)
|
|
277
|
+
* @throws Error if no messages exist in the conversation
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* // User asked a question, model is generating...
|
|
282
|
+
* context.set(user('What is the weather?'));
|
|
283
|
+
* await context.save();
|
|
284
|
+
*
|
|
285
|
+
* // User wants to ask something else without waiting
|
|
286
|
+
* const newBranch = await context.btw();
|
|
287
|
+
* // newBranch = { name: 'main-v2', ... }
|
|
288
|
+
*
|
|
289
|
+
* // Later, switch to the new branch and add the question
|
|
290
|
+
* await context.switchBranch(newBranch.name);
|
|
291
|
+
* context.set(user('Also, what time is it?'));
|
|
292
|
+
* await context.save();
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
btw(): Promise<BranchInfo>;
|
|
228
296
|
/**
|
|
229
297
|
* Update metadata for the current chat.
|
|
230
298
|
*
|
|
@@ -248,6 +316,26 @@ export declare class ContextEngine {
|
|
|
248
316
|
* @experimental
|
|
249
317
|
*/
|
|
250
318
|
consolidate(): void;
|
|
319
|
+
/**
|
|
320
|
+
* Inspect the full context state for debugging.
|
|
321
|
+
* Returns a comprehensive JSON-serializable object with all context information.
|
|
322
|
+
*
|
|
323
|
+
* @param options - Inspection options (modelId and renderer required)
|
|
324
|
+
* @returns Complete inspection data including estimates, rendered output, fragments, and graph
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* const inspection = await context.inspect({
|
|
329
|
+
* modelId: 'openai:gpt-4o',
|
|
330
|
+
* renderer: new XmlRenderer(),
|
|
331
|
+
* });
|
|
332
|
+
* console.log(JSON.stringify(inspection, null, 2));
|
|
333
|
+
*
|
|
334
|
+
* // Or write to file for analysis
|
|
335
|
+
* await fs.writeFile('context-debug.json', JSON.stringify(inspection, null, 2));
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
inspect(options: InspectOptions): Promise<InspectResult>;
|
|
251
339
|
}
|
|
252
340
|
export declare function hint(text: string): ContextFragment;
|
|
253
341
|
export declare function fragment(name: string, ...children: ContextFragment[]): ContextFragment;
|
|
@@ -268,12 +356,12 @@ export declare function role(content: string): ContextFragment;
|
|
|
268
356
|
* context.set(user('Hello', { id: 'msg-1' })); // Custom ID
|
|
269
357
|
* ```
|
|
270
358
|
*/
|
|
271
|
-
export declare function user(content: string
|
|
359
|
+
export declare function user(content: string | UIMessage): ContextFragment;
|
|
272
360
|
/**
|
|
273
361
|
* Create an assistant message fragment.
|
|
274
362
|
* Message fragments are separated from regular fragments during resolve().
|
|
275
363
|
*
|
|
276
|
-
* @param
|
|
364
|
+
* @param message - The message content
|
|
277
365
|
* @param options - Optional settings (id)
|
|
278
366
|
*
|
|
279
367
|
* @example
|
|
@@ -282,5 +370,20 @@ export declare function user(content: string, options?: MessageOptions): Context
|
|
|
282
370
|
* context.set(assistant('Hi there!', { id: 'resp-1' })); // Custom ID
|
|
283
371
|
* ```
|
|
284
372
|
*/
|
|
285
|
-
export declare function assistant(
|
|
373
|
+
export declare function assistant(message: UIMessage): ContextFragment;
|
|
374
|
+
export declare function message(content: string | UIMessage): ContextFragment;
|
|
375
|
+
/**
|
|
376
|
+
* Create an assistant message fragment from text content.
|
|
377
|
+
* Convenience wrapper that creates a UIMessage internally.
|
|
378
|
+
*
|
|
379
|
+
* @param content - The message text content
|
|
380
|
+
* @param options - Optional settings (id)
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* context.set(assistantText('Hi there!')); // Auto-generated ID
|
|
385
|
+
* context.set(assistantText('Hi there!', { id: 'resp-1' })); // Custom ID
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
export declare function assistantText(content: string, options?: MessageOptions): ContextFragment;
|
|
286
389
|
//# 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,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,IAAI,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,E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