anyclaude-sdk 0.6.1 → 0.6.2
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/agent.js +32 -10
- package/dist/types/index.d.ts +10 -0
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -480,7 +480,12 @@ export async function* runAgent(options) {
|
|
|
480
480
|
yield {
|
|
481
481
|
type: 'system',
|
|
482
482
|
subtype: 'compact_boundary',
|
|
483
|
-
compact_metadata: {
|
|
483
|
+
compact_metadata: {
|
|
484
|
+
trigger: 'manual',
|
|
485
|
+
pre_tokens: 0,
|
|
486
|
+
status: 'end',
|
|
487
|
+
post_tokens: Math.round(estimateTokens(history)),
|
|
488
|
+
},
|
|
484
489
|
uuid: uuid(),
|
|
485
490
|
session_id: sessionId,
|
|
486
491
|
};
|
|
@@ -581,21 +586,38 @@ export async function* runAgent(options) {
|
|
|
581
586
|
if (options.autoCompact && autoCompactCount < 3 && history.length > 3) {
|
|
582
587
|
const limit = options.contextLimit ?? (contextWindowFor(resultModel) || 200_000);
|
|
583
588
|
const threshold = (options.compactThreshold ?? 0.8) * limit;
|
|
584
|
-
|
|
589
|
+
const preTokens = estimateTokens(history);
|
|
590
|
+
if (preTokens > threshold) {
|
|
585
591
|
await runHooks('PreCompact', { hook_event_name: 'PreCompact', trigger: 'auto' });
|
|
592
|
+
// Emit a START boundary BEFORE the (possibly slow) summarization so a UI
|
|
593
|
+
// can show a live "compacting…" indicator while the LLM call is in flight.
|
|
594
|
+
yield {
|
|
595
|
+
type: 'system',
|
|
596
|
+
subtype: 'compact_boundary',
|
|
597
|
+
compact_metadata: { trigger: 'auto', pre_tokens: Math.round(preTokens), status: 'start' },
|
|
598
|
+
uuid: uuid(),
|
|
599
|
+
session_id: sessionId,
|
|
600
|
+
};
|
|
586
601
|
const compacted = await summarizeHistory(history, llm, { model, signal });
|
|
587
602
|
if (compacted) {
|
|
588
603
|
history.splice(0, history.length, ...compacted);
|
|
589
604
|
autoCompactCount++;
|
|
590
|
-
yield {
|
|
591
|
-
type: 'system',
|
|
592
|
-
subtype: 'compact_boundary',
|
|
593
|
-
compact_metadata: { trigger: 'auto', pre_tokens: Math.round(threshold) },
|
|
594
|
-
uuid: uuid(),
|
|
595
|
-
session_id: sessionId,
|
|
596
|
-
};
|
|
597
|
-
await runHooks('PostCompact', { hook_event_name: 'PostCompact', trigger: 'auto' });
|
|
598
605
|
}
|
|
606
|
+
// END boundary closes the live indicator either way (compacted or not).
|
|
607
|
+
yield {
|
|
608
|
+
type: 'system',
|
|
609
|
+
subtype: 'compact_boundary',
|
|
610
|
+
compact_metadata: {
|
|
611
|
+
trigger: 'auto',
|
|
612
|
+
pre_tokens: Math.round(preTokens),
|
|
613
|
+
status: 'end',
|
|
614
|
+
post_tokens: Math.round(estimateTokens(history)),
|
|
615
|
+
},
|
|
616
|
+
uuid: uuid(),
|
|
617
|
+
session_id: sessionId,
|
|
618
|
+
};
|
|
619
|
+
if (compacted)
|
|
620
|
+
await runHooks('PostCompact', { hook_event_name: 'PostCompact', trigger: 'auto' });
|
|
599
621
|
}
|
|
600
622
|
}
|
|
601
623
|
let streamedText = '';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -162,7 +162,17 @@ export type SDKCompactBoundaryMessage = {
|
|
|
162
162
|
subtype: 'compact_boundary';
|
|
163
163
|
compact_metadata: {
|
|
164
164
|
trigger: 'manual' | 'auto';
|
|
165
|
+
/** Transcript token estimate when compaction began. */
|
|
165
166
|
pre_tokens: number;
|
|
167
|
+
/**
|
|
168
|
+
* Compaction phase: `'start'` is emitted BEFORE the (possibly slow)
|
|
169
|
+
* summarization so a UI can show a live "compacting…" indicator; `'end'`
|
|
170
|
+
* is emitted after, with `post_tokens` set. Absent ⇒ treat as `'end'`
|
|
171
|
+
* (back-compat: pre-0.6.2 only emitted the post-compaction boundary).
|
|
172
|
+
*/
|
|
173
|
+
status?: 'start' | 'end';
|
|
174
|
+
/** Transcript token estimate after compaction (only on `status: 'end'`). */
|
|
175
|
+
post_tokens?: number;
|
|
166
176
|
};
|
|
167
177
|
uuid: string;
|
|
168
178
|
session_id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anyclaude-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Standalone, browser-compatible SDK providing Claude Code agent capabilities (tools, tool loop, multi-turn, MCP, sub-agents, sessions) against any OpenAI/Anthropic-compatible LLM endpoint. Runs in the browser (WebContainer), Node, and Bun — no backend required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|