agents 0.10.0 → 0.10.1
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/client.d.ts +1 -1
- package/dist/compaction-helpers-BPE1_ziA.js.map +1 -1
- package/dist/compaction-helpers-BdQbZiML.d.ts +441 -0
- package/dist/experimental/memory/session/index.d.ts +61 -268
- package/dist/experimental/memory/session/index.js +238 -34
- package/dist/experimental/memory/session/index.js.map +1 -1
- package/dist/experimental/memory/utils/index.d.ts +3 -4
- package/dist/experimental/memory/utils/index.js.map +1 -1
- package/dist/{index-BPkkIqMn.d.ts → index-D2lfljd3.d.ts} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -9
- package/dist/mcp/index.js.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/package.json +2 -2
- package/dist/compaction-helpers-CHNQeyRm.d.ts +0 -139
package/dist/react.d.ts
CHANGED
package/dist/workflows.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"durable objects"
|
|
10
10
|
],
|
|
11
11
|
"type": "module",
|
|
12
|
-
"version": "0.10.
|
|
12
|
+
"version": "0.10.1",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
15
15
|
"directory": "packages/agents",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@ai-sdk/openai": "^3.0.0",
|
|
56
56
|
"@ai-sdk/react": "^3.0.0",
|
|
57
|
-
"@cloudflare/ai-chat": "^0.4.
|
|
57
|
+
"@cloudflare/ai-chat": "^0.4.1",
|
|
58
58
|
"@cloudflare/codemode": "^0.3.4",
|
|
59
59
|
"@x402/core": "^2.0.0",
|
|
60
60
|
"@x402/evm": "^2.0.0",
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { UIMessage } from "ai";
|
|
2
|
-
|
|
3
|
-
//#region src/experimental/memory/utils/compaction-helpers.d.ts
|
|
4
|
-
/** Prefix for all compaction messages (overlays and summaries) */
|
|
5
|
-
declare const COMPACTION_PREFIX = "compaction_";
|
|
6
|
-
/** Check if a message is a compaction message */
|
|
7
|
-
declare function isCompactionMessage(msg: UIMessage): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Align a boundary index forward to avoid splitting tool call/result groups.
|
|
10
|
-
* If the boundary falls between an assistant message with tool calls and its
|
|
11
|
-
* tool results, move it forward past the results.
|
|
12
|
-
*/
|
|
13
|
-
declare function alignBoundaryForward(
|
|
14
|
-
messages: UIMessage[],
|
|
15
|
-
idx: number
|
|
16
|
-
): number;
|
|
17
|
-
/**
|
|
18
|
-
* Align a boundary index backward to avoid splitting tool call/result groups.
|
|
19
|
-
* If the boundary falls in the middle of tool results, move it backward to
|
|
20
|
-
* include the assistant message that made the calls.
|
|
21
|
-
*/
|
|
22
|
-
declare function alignBoundaryBackward(
|
|
23
|
-
messages: UIMessage[],
|
|
24
|
-
idx: number
|
|
25
|
-
): number;
|
|
26
|
-
/**
|
|
27
|
-
* Find the compression end boundary using a token budget for the tail.
|
|
28
|
-
* Walks backward from the end, accumulating tokens until budget is reached.
|
|
29
|
-
* Returns the index where compression should stop (everything from this
|
|
30
|
-
* index onward is protected).
|
|
31
|
-
*
|
|
32
|
-
* @param messages All messages
|
|
33
|
-
* @param headEnd Index where the protected head ends (compression starts here)
|
|
34
|
-
* @param tailTokenBudget Maximum tokens to keep in the tail
|
|
35
|
-
* @param minTailMessages Minimum messages to protect in the tail (fallback)
|
|
36
|
-
*/
|
|
37
|
-
declare function findTailCutByTokens(
|
|
38
|
-
messages: UIMessage[],
|
|
39
|
-
headEnd: number,
|
|
40
|
-
tailTokenBudget?: number,
|
|
41
|
-
minTailMessages?: number
|
|
42
|
-
): number;
|
|
43
|
-
/**
|
|
44
|
-
* Fix orphaned tool call/result pairs after compaction.
|
|
45
|
-
*
|
|
46
|
-
* Two failure modes:
|
|
47
|
-
* 1. Tool result references a call_id whose assistant tool_call was removed
|
|
48
|
-
* → Remove the orphaned result
|
|
49
|
-
* 2. Assistant has tool_calls whose results were dropped
|
|
50
|
-
* → Add stub results so the API doesn't error
|
|
51
|
-
*
|
|
52
|
-
* @param messages Messages after compaction
|
|
53
|
-
* @returns Sanitized messages with no orphaned pairs
|
|
54
|
-
*/
|
|
55
|
-
declare function sanitizeToolPairs(messages: UIMessage[]): UIMessage[];
|
|
56
|
-
/**
|
|
57
|
-
* Compute a summary token budget based on the content being compressed.
|
|
58
|
-
* 20% of the compressed content, clamped to 2K-8K tokens.
|
|
59
|
-
*/
|
|
60
|
-
declare function computeSummaryBudget(messages: UIMessage[]): number;
|
|
61
|
-
/**
|
|
62
|
-
* Build a prompt for LLM summarization of compressed messages.
|
|
63
|
-
*
|
|
64
|
-
* @param messages Messages to summarize
|
|
65
|
-
* @param previousSummary Previous summary for iterative updates (or null for first compaction)
|
|
66
|
-
* @param budget Target token count for the summary
|
|
67
|
-
*/
|
|
68
|
-
declare function buildSummaryPrompt(
|
|
69
|
-
messages: UIMessage[],
|
|
70
|
-
previousSummary: string | null,
|
|
71
|
-
budget: number
|
|
72
|
-
): string;
|
|
73
|
-
/**
|
|
74
|
-
* Result of a compaction function — describes the overlay to store.
|
|
75
|
-
*/
|
|
76
|
-
interface CompactResult {
|
|
77
|
-
/** First message ID in the compacted range */
|
|
78
|
-
fromMessageId: string;
|
|
79
|
-
/** Last message ID in the compacted range */
|
|
80
|
-
toMessageId: string;
|
|
81
|
-
/** Summary text to store as the overlay */
|
|
82
|
-
summary: string;
|
|
83
|
-
}
|
|
84
|
-
interface CompactOptions {
|
|
85
|
-
/**
|
|
86
|
-
* Function to call the LLM for summarization.
|
|
87
|
-
* Takes a user prompt string, returns the LLM's text response.
|
|
88
|
-
*/
|
|
89
|
-
summarize: (prompt: string) => Promise<string>;
|
|
90
|
-
/** Number of head messages to protect (default: 2) */
|
|
91
|
-
protectHead?: number;
|
|
92
|
-
/** Token budget for tail protection (default: 20000) */
|
|
93
|
-
tailTokenBudget?: number;
|
|
94
|
-
/** Minimum tail messages to protect (default: 2) */
|
|
95
|
-
minTailMessages?: number;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Reference compaction implementation.
|
|
99
|
-
*
|
|
100
|
-
* Implements the full hermes-style compaction algorithm:
|
|
101
|
-
* 1. Protect head messages (first N)
|
|
102
|
-
* 2. Protect tail by token budget (walk backward)
|
|
103
|
-
* 3. Align boundaries to tool call groups
|
|
104
|
-
* 4. Summarize middle section with LLM (structured format)
|
|
105
|
-
* 5. Sanitize orphaned tool pairs
|
|
106
|
-
* 6. Iterative summary updates on subsequent compactions
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* import { createCompactFunction } from "agents/experimental/memory/utils";
|
|
111
|
-
*
|
|
112
|
-
* const session = new Session(provider, {
|
|
113
|
-
* compaction: {
|
|
114
|
-
* tokenThreshold: 100000,
|
|
115
|
-
* fn: createCompactFunction({
|
|
116
|
-
* summarize: (prompt) => generateText({ model, prompt }).then(r => r.text)
|
|
117
|
-
* })
|
|
118
|
-
* }
|
|
119
|
-
* });
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
declare function createCompactFunction(
|
|
123
|
-
opts: CompactOptions
|
|
124
|
-
): (messages: UIMessage[]) => Promise<CompactResult | null>;
|
|
125
|
-
//#endregion
|
|
126
|
-
export {
|
|
127
|
-
alignBoundaryForward as a,
|
|
128
|
-
createCompactFunction as c,
|
|
129
|
-
sanitizeToolPairs as d,
|
|
130
|
-
alignBoundaryBackward as i,
|
|
131
|
-
findTailCutByTokens as l,
|
|
132
|
-
CompactOptions as n,
|
|
133
|
-
buildSummaryPrompt as o,
|
|
134
|
-
CompactResult as r,
|
|
135
|
-
computeSummaryBudget as s,
|
|
136
|
-
COMPACTION_PREFIX as t,
|
|
137
|
-
isCompactionMessage as u
|
|
138
|
-
};
|
|
139
|
-
//# sourceMappingURL=compaction-helpers-CHNQeyRm.d.ts.map
|