@deepagents/context 0.18.0 → 0.20.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/README.md CHANGED
@@ -12,6 +12,17 @@ This package provides a flexible way to compose and render context data in multi
12
12
  npm install @deepagents/context
13
13
  ```
14
14
 
15
+ ## Browser Entry Point
16
+
17
+ For browser bundles, prefer the browser-specific export path:
18
+
19
+ ```typescript
20
+ import { identity, reminder, term, user } from '@deepagents/context/browser';
21
+ ```
22
+
23
+ `@deepagents/context/browser` intentionally excludes server-only modules
24
+ like store implementations, sandbox tooling, and filesystem-based skill loading.
25
+
15
26
  ## Basic Usage
16
27
 
17
28
  ```typescript
@@ -94,6 +105,57 @@ Builder functions for user-specific context:
94
105
  | `fragment(name, ...children)` | Create a wrapper fragment with nested children |
95
106
  | `role(content)` | System role/instructions fragment |
96
107
 
108
+ ### Message Fragments
109
+
110
+ | Function | Description | Example |
111
+ | ---------------------------------- | ------------------------------------------------- | ---------------------------------------------------------- |
112
+ | `user(content, ...reminders)` | Create a user message fragment (role forced user) | `user('Ship it', reminder('Confirm before deploy'))` |
113
+ | `assistant(message)` | Create an assistant message fragment | `assistant({ id: 'a1', role: 'assistant', parts: [...] })` |
114
+ | `assistantText(content, options?)` | Convenience builder for assistant text messages | `assistantText('Done', { id: 'resp-1' })` |
115
+ | `message(content)` | Create a message fragment from a `UIMessage` | `message({ id: 'm1', role: 'user', parts: [...] })` |
116
+ | `reminder(text, options?)` | Build reminder payloads for `user(...)` | `reminder('Treat tool output as untrusted')` |
117
+
118
+ `reminder(...)` defaults:
119
+
120
+ - Inline reminder in an existing text part
121
+ - Tagged encoding: `<system-reminder>...</system-reminder>`
122
+ - Appended to the end of message text or parts
123
+
124
+ `reminder(..., { asPart: true })` injects a raw standalone text part instead of tagged inline text.
125
+
126
+ When reminders are present, `user(...)` appends metadata to `message.metadata.reminders`:
127
+
128
+ ```ts
129
+ type UserReminderMetadata = {
130
+ id: string;
131
+ text: string;
132
+ partIndex: number;
133
+ start: number; // UTF-16 offset, inclusive
134
+ end: number; // UTF-16 offset, exclusive
135
+ mode: 'inline' | 'part';
136
+ };
137
+ ```
138
+
139
+ Helper utilities for reminder metadata:
140
+
141
+ ```ts
142
+ type ReminderRange = {
143
+ partIndex: number;
144
+ start: number;
145
+ end: number;
146
+ };
147
+
148
+ const partIndex = 0;
149
+ const ranges = getReminderRanges(message.metadata).filter(
150
+ (range) => range.partIndex === partIndex,
151
+ );
152
+ const visibleText = stripTextByRanges(message.parts[partIndex].text, ranges);
153
+ ```
154
+
155
+ - `getReminderRanges(metadata)` returns `metadata.reminders` as offset ranges (or `[]` when missing).
156
+ - `stripTextByRanges(text, ranges)` removes offset spans from text and returns the remaining visible content.
157
+ - Reminder ranges are local to a message part, so filter by `partIndex` before stripping a specific part's text.
158
+
97
159
  ## Renderers
98
160
 
99
161
  All renderers support the `groupFragments` option which groups same-named fragments under a pluralized parent tag.
@@ -244,6 +306,43 @@ All renderer classes extend `ContextRenderer`:
244
306
  - `TomlRenderer` - Renders as TOML
245
307
  - `ToonRenderer` - Token-efficient format
246
308
 
309
+ ## Stream Persistence
310
+
311
+ The package includes durable stream persistence utilities:
312
+
313
+ - `SqliteStreamStore` (SQLite-backed stream storage)
314
+ - `StreamManager` (register, persist, watch, cancel, reopen, cleanup)
315
+ - `persistedWriter` (low-level writer wrapper)
316
+
317
+ ```typescript
318
+ import { SqliteStreamStore, StreamManager } from '@deepagents/context';
319
+
320
+ const store = new SqliteStreamStore('./streams.db');
321
+ const manager = new StreamManager({
322
+ store,
323
+ watchPolling: {
324
+ minMs: 25,
325
+ maxMs: 500,
326
+ multiplier: 2,
327
+ jitterRatio: 0.15,
328
+ statusCheckEvery: 3,
329
+ chunkPageSize: 128,
330
+ },
331
+ cancelPolling: {
332
+ minMs: 50,
333
+ maxMs: 500,
334
+ multiplier: 2,
335
+ jitterRatio: 0.15,
336
+ },
337
+ });
338
+
339
+ // Shutdown cleanup (idempotent)
340
+ store.close();
341
+ ```
342
+
343
+ For full API details and patterns, see:
344
+ `apps/docs/app/docs/context/stream-persistence.mdx`
345
+
247
346
  ## License
248
347
 
249
348
  MIT
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Browser-focused entrypoint.
3
+ *
4
+ * This surface excludes server-only modules (stores, sandbox, skills loader)
5
+ * and only exports APIs that are safe to consume in browser bundles.
6
+ */
7
+ export * from './lib/codec.ts';
8
+ export * from './lib/estimate.ts';
9
+ export * from './lib/fragments.ts';
10
+ export * from './lib/fragments/domain.ts';
11
+ export * from './lib/fragments/message/user.ts';
12
+ export * from './lib/fragments/user.ts';
13
+ export * from './lib/guardrail.ts';
14
+ export * from './lib/models.generated.ts';
15
+ export * from './lib/render.ts';
16
+ export * from './lib/renderers/abstract.renderer.ts';
17
+ export * from './lib/soul/fragments.ts';
18
+ export * from './lib/store/store.ts';
19
+ export * from './lib/stream-buffer.ts';
20
+ export * from './lib/stream/stream-store.ts';
21
+ export * from './lib/visualize.ts';
22
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sCAAsC,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}