dsh-agent-enhancer 0.3.3 → 0.3.4
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.en.md +2 -2
- package/README.md +2 -2
- package/lib/client/context/right-tab.d.ts.map +1 -1
- package/lib/client/locales.d.ts +3 -1
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client.js +5 -1
- package/lib/client.js.map +1 -1
- package/lib/host/auto-route/session-hook.d.ts.map +1 -1
- package/lib/host/context-compact.d.ts +27 -8
- package/lib/host/context-compact.d.ts.map +1 -1
- package/lib/host/index.d.ts +3 -6
- package/lib/host/index.d.ts.map +1 -1
- package/lib/identity.d.ts +1 -1
- package/lib/index.js +132 -117
- package/lib/index.js.map +4 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-hook.d.ts","sourceRoot":"","sources":["../../../src/host/auto-route/session-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AA4PvD,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,gBAAgB,CAAA;CAAE,GACrD,IAAI,
|
|
1
|
+
{"version":3,"file":"session-hook.d.ts","sourceRoot":"","sources":["../../../src/host/auto-route/session-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AA4PvD,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,gBAAgB,CAAA;CAAE,GACrD,IAAI,CAwHN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { CompactionResult } from '@deepseek-ai/dsh-compaction';
|
|
2
3
|
import type { Session } from '@deepseek-ai/dsh-session';
|
|
3
4
|
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
4
5
|
import type { EnhancerSettings } from '../config.ts';
|
|
@@ -7,7 +8,7 @@ export interface ContextCompactRequest {
|
|
|
7
8
|
}
|
|
8
9
|
export interface ContextCompactResult {
|
|
9
10
|
readonly sessionId: SessionId;
|
|
10
|
-
/** Official
|
|
11
|
+
/** Official manual compaction returned a replacement summary. */
|
|
11
12
|
readonly status: 'compacted' | 'noop';
|
|
12
13
|
readonly shadowedCount: number;
|
|
13
14
|
readonly shadowedTokens: number;
|
|
@@ -16,7 +17,7 @@ export interface CompactRouteOverride {
|
|
|
16
17
|
readonly provider: string;
|
|
17
18
|
readonly model: string;
|
|
18
19
|
}
|
|
19
|
-
/** Minimal face of `@deepseek-ai/dsh-commands` used
|
|
20
|
+
/** Minimal face of `@deepseek-ai/dsh-commands` used as `/compact` fallback. */
|
|
20
21
|
export interface CompactCommandRuntime {
|
|
21
22
|
execute(agent: unknown, line: string, attachments: readonly unknown[], signal: AbortSignal): Promise<{
|
|
22
23
|
readonly result: {
|
|
@@ -25,18 +26,36 @@ export interface CompactCommandRuntime {
|
|
|
25
26
|
};
|
|
26
27
|
} | undefined>;
|
|
27
28
|
}
|
|
28
|
-
/**
|
|
29
|
+
/** Official `ctx.compaction.compactNow` — same seam chat `/compact` calls. */
|
|
30
|
+
export interface CompactEngineRuntime {
|
|
31
|
+
compactNow(agent: CompactManualAgent, signal: AbortSignal, sourceCommandId?: string): Promise<CompactionResult | null>;
|
|
32
|
+
}
|
|
33
|
+
/** Agent shape required by manual compaction (`runMaintenance` + idle gate). */
|
|
34
|
+
export interface CompactManualAgent {
|
|
35
|
+
readonly status?: unknown;
|
|
36
|
+
readonly options?: {
|
|
37
|
+
provider?: string;
|
|
38
|
+
model?: string;
|
|
39
|
+
};
|
|
40
|
+
readonly session?: unknown;
|
|
41
|
+
runMaintenance?<T>(task: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Kept for settings / Auto mapping tests. Live compact follows the official
|
|
45
|
+
* summarizer route (requestHeader / agent.options) — do not force a plugin seat.
|
|
46
|
+
*/
|
|
29
47
|
export declare function resolveCompactRouteOverride(ctx: Context, settings: EnhancerSettings, session: Session, signal: AbortSignal): Promise<CompactRouteOverride | undefined>;
|
|
30
48
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
49
|
+
* Same backend as chat `/compact`: prefer `ctx.compaction.compactNow`, fall back
|
|
50
|
+
* to `commands.execute('/compact')`. Do not mutate agent.options or wrap
|
|
51
|
+
* purpose=compaction streams with a plugin-forced route — Auto remapping in
|
|
52
|
+
* session-hook is enough for the sentinel seat.
|
|
34
53
|
*/
|
|
35
54
|
export declare function compactContextNow(options: {
|
|
55
|
+
readonly compaction: CompactEngineRuntime | undefined;
|
|
36
56
|
readonly commands: CompactCommandRuntime | undefined;
|
|
37
|
-
readonly agent:
|
|
57
|
+
readonly agent: CompactManualAgent;
|
|
38
58
|
readonly sessionId: SessionId;
|
|
39
59
|
readonly signal: AbortSignal;
|
|
40
|
-
readonly route?: CompactRouteOverride;
|
|
41
60
|
}): Promise<ContextCompactResult>;
|
|
42
61
|
//# sourceMappingURL=context-compact.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-compact.d.ts","sourceRoot":"","sources":["../../src/host/context-compact.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"context-compact.d.ts","sourceRoot":"","sources":["../../src/host/context-compact.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,O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BAAkB;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACxD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B,cAAc,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CAC1E;AA4ED;;;GAGG;AACH,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAkB3C;AA0FD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,QAAQ,CAAC,UAAU,EAAE,oBAAoB,GAAG,SAAS,CAAA;IACrD,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,GAAG,SAAS,CAAA;IACpD,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;IAClC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6ChC"}
|
package/lib/host/index.d.ts
CHANGED
|
@@ -4,15 +4,13 @@ import type { ModelCatalog } from '@deepseek-ai/dsh-api-session-controller/types
|
|
|
4
4
|
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
5
5
|
import { CheckpointRollbackService } from './checkpoint/service.ts';
|
|
6
6
|
import type { CheckpointCutRequest, CheckpointRollbackRequest, CheckpointSummariesRequest } from './checkpoint/service.ts';
|
|
7
|
-
import type {
|
|
8
|
-
import type { CompactRouteOverride, ContextCompactRequest, ContextCompactResult } from './context-compact.ts';
|
|
7
|
+
import type { CompactCommandRuntime, ContextCompactRequest, ContextCompactResult } from './context-compact.ts';
|
|
9
8
|
import type { ContextInspectRequest, ContextInspectResult } from './context-inspect.ts';
|
|
10
9
|
import { AuxiliaryModels } from './model.ts';
|
|
11
10
|
import type { ProviderBalances, ProviderBalancesRequest, UsageRange, UsageSummary, UsageSummaryReader } from './usage/types.ts';
|
|
12
11
|
import type { RpcPayload } from './rpc.ts';
|
|
13
12
|
import type { AuxiliaryResult } from './types.ts';
|
|
14
13
|
import type { ApplyUpdateResult, UpdateCheckResult } from './update/types.ts';
|
|
15
|
-
import type { CompactCommandRuntime } from './context-compact.ts';
|
|
16
14
|
export declare const name = "agent-enhancer";
|
|
17
15
|
export declare const inject: string[];
|
|
18
16
|
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
@@ -87,10 +85,9 @@ export declare const hostContribution: {
|
|
|
87
85
|
};
|
|
88
86
|
export declare class AgentEnhancerService extends TypertRemoteService {
|
|
89
87
|
private readonly models;
|
|
90
|
-
private readonly compactRoute;
|
|
91
88
|
private readonly usage;
|
|
92
89
|
private readonly balances;
|
|
93
|
-
constructor(ctx: Context, models: AuxiliaryModels,
|
|
90
|
+
constructor(ctx: Context, models: AuxiliaryModels, usage?: UsageSummaryReader, balances?: {
|
|
94
91
|
get(force?: boolean, locale?: string): Promise<ProviderBalances>;
|
|
95
92
|
});
|
|
96
93
|
private assertOwner;
|
|
@@ -98,7 +95,7 @@ export declare class AgentEnhancerService extends TypertRemoteService {
|
|
|
98
95
|
/** Same Desktop catalog the official model selector uses (`llm` registry). */
|
|
99
96
|
listCatalog(): Promise<ModelCatalog>;
|
|
100
97
|
inspectContext(request: ContextInspectRequest, signal: AbortSignal): Promise<ContextInspectResult>;
|
|
101
|
-
/** Trigger
|
|
98
|
+
/** Trigger official idle compaction (same seam as chat `/compact`). */
|
|
102
99
|
compactContext(request: ContextCompactRequest, signal: AbortSignal): Promise<ContextCompactResult>;
|
|
103
100
|
/** Read-only version probe — same gate policy as `listCatalog` (settings-safe). */
|
|
104
101
|
checkUpdate(): Promise<UpdateCheckResult>;
|
package/lib/host/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AACjF,OAAO,EAAe,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAcnF,OAAO,EAA2B,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAC5F,OAAO,KAAK,EACV,oBAAoB,EACpB,yBAAyB,EACzB,0BAA0B,EAC3B,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AACjF,OAAO,EAAe,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAcnF,OAAO,EAA2B,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAC5F,OAAO,KAAK,EACV,oBAAoB,EACpB,yBAAyB,EACzB,0BAA0B,EAC3B,MAAM,yBAAyB,CAAA;AAQhC,OAAO,KAAK,EACV,qBAAqB,EAErB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAEvF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAgB5C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;CACF;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAG/F"}
|
package/lib/identity.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Canonical package / plugin identity after the Composer → Agent rename. */
|
|
2
2
|
export declare const PACKAGE_NAME = "dsh-agent-enhancer";
|
|
3
3
|
export declare const PLUGIN_ID = "agent-enhancer";
|
|
4
|
-
export declare const PACKAGE_VERSION = "0.3.
|
|
4
|
+
export declare const PACKAGE_VERSION = "0.3.4";
|
|
5
5
|
/** Pre-0.2.0 identity — keep reading markers and plugin-data written under these names. */
|
|
6
6
|
export declare const LEGACY_PACKAGE_NAME = "dsh-composer-enhancer";
|
|
7
7
|
export declare const LEGACY_PLUGIN_ID = "composer-enhancer";
|
package/lib/index.js
CHANGED
|
@@ -160,7 +160,7 @@ var AuxiliaryError = class extends Error {
|
|
|
160
160
|
// src/identity.ts
|
|
161
161
|
var PACKAGE_NAME = "dsh-agent-enhancer";
|
|
162
162
|
var PLUGIN_ID = "agent-enhancer";
|
|
163
|
-
var PACKAGE_VERSION = "0.3.
|
|
163
|
+
var PACKAGE_VERSION = "0.3.4";
|
|
164
164
|
var LEGACY_PACKAGE_NAME = "dsh-composer-enhancer";
|
|
165
165
|
var ROLLBACK_PREFIX = `${PACKAGE_NAME}:rollback:`;
|
|
166
166
|
var UNDO_PREFIX = `${PACKAGE_NAME}:undo:`;
|
|
@@ -2761,6 +2761,9 @@ var CheckpointStore = class {
|
|
|
2761
2761
|
}
|
|
2762
2762
|
};
|
|
2763
2763
|
|
|
2764
|
+
// src/host/context-compact.ts
|
|
2765
|
+
import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
|
|
2766
|
+
|
|
2764
2767
|
// src/host/auto-route/classifier.ts
|
|
2765
2768
|
import { BlockAssembler } from "@deepseek-ai/dsh-llm";
|
|
2766
2769
|
|
|
@@ -3143,88 +3146,35 @@ async function resolveAutoRoute(options) {
|
|
|
3143
3146
|
}
|
|
3144
3147
|
|
|
3145
3148
|
// src/host/context-compact.ts
|
|
3146
|
-
function
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
}
|
|
3164
|
-
const fallback = ctx.agentDefaultModel.currentSelection();
|
|
3165
|
-
if (isAutoModel(fallback) || !modelExists(fallback.provider, fallback.model)) return void 0;
|
|
3166
|
-
return tierRouteFromSelection(fallback, override.reasoningEffort);
|
|
3167
|
-
}
|
|
3168
|
-
async function resolveAutoRouteForCompact(ctx, settings, session, feature, signal) {
|
|
3169
|
-
const override = auxiliaryModelOf(settings, "compact");
|
|
3170
|
-
const map = autoRouteMapOf(settings);
|
|
3171
|
-
const classify = settings.autoClassifierEnabled ? createClassifier(ctx.llm, map.classifier) : void 0;
|
|
3172
|
-
const hint = sessionTurnHint(session);
|
|
3173
|
-
const mapped = await resolveAutoRoute({
|
|
3174
|
-
text: hint?.text ?? "",
|
|
3175
|
-
feature,
|
|
3176
|
-
toolHeavy: hint?.toolHeavy,
|
|
3177
|
-
map,
|
|
3178
|
-
classifierEnabled: settings.autoClassifierEnabled,
|
|
3179
|
-
classify,
|
|
3180
|
-
isAvailable: modelExists,
|
|
3181
|
-
fallback: fallbackFromSession(ctx, session, override),
|
|
3182
|
-
signal
|
|
3183
|
-
});
|
|
3184
|
-
if (feature === "session") {
|
|
3185
|
-
setSessionResolvedRouteForSession(session, {
|
|
3186
|
-
provider: mapped.provider,
|
|
3187
|
-
model: mapped.model,
|
|
3188
|
-
reasoningEffort: mapped.reasoningEffort
|
|
3189
|
-
});
|
|
3190
|
-
}
|
|
3191
|
-
return { provider: mapped.provider, model: mapped.model };
|
|
3192
|
-
}
|
|
3193
|
-
async function resolveCompactRouteOverride(ctx, settings, session, signal) {
|
|
3194
|
-
signal.throwIfAborted();
|
|
3195
|
-
const override = auxiliaryModelOf(settings, "compact");
|
|
3196
|
-
if (isAutoModel(override)) {
|
|
3197
|
-
return resolveAutoRouteForCompact(ctx, settings, session, "compact", signal);
|
|
3198
|
-
}
|
|
3199
|
-
if (!isFollowSessionModel(override)) {
|
|
3200
|
-
return { provider: override.provider, model: override.model };
|
|
3201
|
-
}
|
|
3202
|
-
const selection = sessionModelSelection(ctx, session);
|
|
3203
|
-
if (isAutoModel(selection)) {
|
|
3204
|
-
const cached = getSessionResolvedRouteForSession(session);
|
|
3205
|
-
if (cached !== void 0) {
|
|
3206
|
-
return { provider: cached.provider, model: cached.model };
|
|
3149
|
+
function mapManualCompactionCode(code) {
|
|
3150
|
+
switch (code) {
|
|
3151
|
+
case "busy":
|
|
3152
|
+
return "COMPACT_BUSY";
|
|
3153
|
+
case "cancelled":
|
|
3154
|
+
return "COMPACT_FAILED";
|
|
3155
|
+
case "changed":
|
|
3156
|
+
return "COMPACT_CHANGED";
|
|
3157
|
+
case "summary":
|
|
3158
|
+
return "COMPACT_SUMMARY";
|
|
3159
|
+
case "commit":
|
|
3160
|
+
return "COMPACT_FAILED";
|
|
3161
|
+
case "persistence":
|
|
3162
|
+
return "COMPACT_FAILED";
|
|
3163
|
+
default: {
|
|
3164
|
+
const _exhaustive = code;
|
|
3165
|
+
return _exhaustive;
|
|
3207
3166
|
}
|
|
3208
|
-
return resolveAutoRouteForCompact(ctx, settings, session, "session", signal);
|
|
3209
3167
|
}
|
|
3210
|
-
return void 0;
|
|
3211
3168
|
}
|
|
3212
|
-
function
|
|
3213
|
-
if (
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
options.provider = route.provider;
|
|
3218
|
-
options.model = route.model;
|
|
3219
|
-
return () => {
|
|
3220
|
-
;
|
|
3221
|
-
options.provider = previous.provider;
|
|
3222
|
-
options.model = previous.model;
|
|
3223
|
-
};
|
|
3169
|
+
function isManualCompactionError(error) {
|
|
3170
|
+
if (error instanceof ManualCompactionError) return true;
|
|
3171
|
+
if (typeof error !== "object" || error === null) return false;
|
|
3172
|
+
const candidate = error;
|
|
3173
|
+
return candidate.name === "ManualCompactionError" && typeof candidate.code === "string";
|
|
3224
3174
|
}
|
|
3225
3175
|
function mapCompactErrorText(text3) {
|
|
3226
3176
|
const lower = text3.toLowerCase();
|
|
3227
|
-
if (lower.includes("busy") || lower.includes("active") || text3.includes("\u5FD9\u788C")) {
|
|
3177
|
+
if (lower.includes("busy") || lower.includes("active") || text3.includes("\u5FD9\u788C") || text3.includes("\u4E0D\u53EF\u7528\u56E0\u4E3A")) {
|
|
3228
3178
|
return "COMPACT_BUSY";
|
|
3229
3179
|
}
|
|
3230
3180
|
if (lower.includes("summary") || text3.includes("\u6458\u8981")) {
|
|
@@ -3236,6 +3186,9 @@ function mapCompactErrorText(text3) {
|
|
|
3236
3186
|
if (lower.includes("not available") || text3.includes("\u672A\u63D0\u4F9B") || text3.includes("\u4E0D\u53EF\u7528")) {
|
|
3237
3187
|
return "COMPACT_UNAVAILABLE";
|
|
3238
3188
|
}
|
|
3189
|
+
if (lower.includes("cancelled") || text3.includes("\u5DF2\u53D6\u6D88")) {
|
|
3190
|
+
return "COMPACT_FAILED";
|
|
3191
|
+
}
|
|
3239
3192
|
return "COMPACT_FAILED";
|
|
3240
3193
|
}
|
|
3241
3194
|
function parseCompactSuccess(sessionId, text3) {
|
|
@@ -3257,20 +3210,48 @@ function parseCompactSuccess(sessionId, text3) {
|
|
|
3257
3210
|
shadowedTokens: tokenMatch ? Number(tokenMatch[1]) : 0
|
|
3258
3211
|
};
|
|
3259
3212
|
}
|
|
3213
|
+
function resultFromEngine(sessionId, result) {
|
|
3214
|
+
if (result === null) {
|
|
3215
|
+
return {
|
|
3216
|
+
sessionId,
|
|
3217
|
+
status: "noop",
|
|
3218
|
+
shadowedCount: 0,
|
|
3219
|
+
shadowedTokens: 0
|
|
3220
|
+
};
|
|
3221
|
+
}
|
|
3222
|
+
return {
|
|
3223
|
+
sessionId,
|
|
3224
|
+
status: "compacted",
|
|
3225
|
+
shadowedCount: result.shadowedSeqs.length,
|
|
3226
|
+
shadowedTokens: result.shadowedTokenCount
|
|
3227
|
+
};
|
|
3228
|
+
}
|
|
3260
3229
|
async function compactContextNow(options) {
|
|
3261
3230
|
options.signal.throwIfAborted();
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
}
|
|
3265
|
-
if (options.agent === null || typeof options.agent !== "object") {
|
|
3231
|
+
const agent = options.agent;
|
|
3232
|
+
if (agent === null || typeof agent !== "object") {
|
|
3266
3233
|
throw new AuxiliaryError("SESSION_CHANGED");
|
|
3267
3234
|
}
|
|
3268
|
-
const agent = options.agent;
|
|
3269
3235
|
if (agent.status !== void 0 && agent.status !== "idle") {
|
|
3270
3236
|
throw new AuxiliaryError("COMPACT_BUSY");
|
|
3271
3237
|
}
|
|
3272
|
-
const
|
|
3238
|
+
const canCompactNow = options.compaction !== void 0 && typeof options.compaction.compactNow === "function" && typeof agent.runMaintenance === "function";
|
|
3273
3239
|
try {
|
|
3240
|
+
if (canCompactNow && options.compaction !== void 0) {
|
|
3241
|
+
try {
|
|
3242
|
+
const result = await options.compaction.compactNow(agent, options.signal);
|
|
3243
|
+
return resultFromEngine(options.sessionId, result);
|
|
3244
|
+
} catch (error) {
|
|
3245
|
+
if (options.signal.aborted) throw error;
|
|
3246
|
+
if (isManualCompactionError(error)) {
|
|
3247
|
+
throw new AuxiliaryError(mapManualCompactionCode(error.code));
|
|
3248
|
+
}
|
|
3249
|
+
throw error;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
if (options.commands === void 0 || typeof options.commands.execute !== "function") {
|
|
3253
|
+
throw new AuxiliaryError("COMPACT_UNAVAILABLE");
|
|
3254
|
+
}
|
|
3274
3255
|
const execution = await options.commands.execute(agent, "/compact", [], options.signal);
|
|
3275
3256
|
if (execution === void 0) throw new AuxiliaryError("COMPACT_UNAVAILABLE");
|
|
3276
3257
|
if (execution.result.kind === "error") {
|
|
@@ -3280,9 +3261,10 @@ async function compactContextNow(options) {
|
|
|
3280
3261
|
} catch (error) {
|
|
3281
3262
|
if (options.signal.aborted) throw error;
|
|
3282
3263
|
if (error instanceof AuxiliaryError) throw error;
|
|
3264
|
+
if (isManualCompactionError(error)) {
|
|
3265
|
+
throw new AuxiliaryError(mapManualCompactionCode(error.code));
|
|
3266
|
+
}
|
|
3283
3267
|
throw new AuxiliaryError("COMPACT_FAILED");
|
|
3284
|
-
} finally {
|
|
3285
|
-
restore?.();
|
|
3286
3268
|
}
|
|
3287
3269
|
}
|
|
3288
3270
|
|
|
@@ -3726,43 +3708,77 @@ function installAutoSessionRoute(ctx, options) {
|
|
|
3726
3708
|
});
|
|
3727
3709
|
ctx.effect(() => {
|
|
3728
3710
|
const llm = ctx.llm;
|
|
3729
|
-
|
|
3730
|
-
|
|
3711
|
+
if (typeof llm.prepareCall !== "function") return () => {
|
|
3712
|
+
};
|
|
3713
|
+
const innerPrepare = llm.prepareCall.bind(llm);
|
|
3714
|
+
const innerStream = typeof llm.stream === "function" ? llm.stream.bind(llm) : void 0;
|
|
3715
|
+
const remapAuto = async (config, signal, agent, feature = "session") => {
|
|
3716
|
+
const settings = options.settings();
|
|
3717
|
+
const map = autoRouteMapOf(settings);
|
|
3718
|
+
const note = (agent === void 0 ? void 0 : notes.get(agent)) ?? loggedTurn(asAgent(agent));
|
|
3719
|
+
const classify = settings.autoClassifierEnabled ? createClassifier({ prepareCall: innerPrepare }, map.classifier) : void 0;
|
|
3720
|
+
const mapped = await resolveAutoRoute({
|
|
3721
|
+
text: note?.text ?? "",
|
|
3722
|
+
feature,
|
|
3723
|
+
toolHeavy: note?.toolHeavy ?? false,
|
|
3724
|
+
map,
|
|
3725
|
+
classifierEnabled: settings.autoClassifierEnabled,
|
|
3726
|
+
classify,
|
|
3727
|
+
isAvailable: (provider, model) => provider !== "" && model !== "" && !isAutoModel({ provider, model }),
|
|
3728
|
+
signal,
|
|
3729
|
+
fallback: fallbackRoute(ctx, asAgent(agent))
|
|
3730
|
+
});
|
|
3731
|
+
if (agent !== void 0 && feature === "session") setSessionResolvedRoute(agent, mapped);
|
|
3732
|
+
return mapped;
|
|
3733
|
+
};
|
|
3734
|
+
const wrappedPrepare = async (config, signal, configure) => {
|
|
3731
3735
|
const agent = activeAgent(ctx);
|
|
3732
3736
|
const keyProbe = agent ?? config;
|
|
3733
3737
|
const depth = resolving.get(keyProbe) ?? 0;
|
|
3734
3738
|
if (depth > 0 || !shouldRemapAuto(config, asAgent(agent))) {
|
|
3735
|
-
return
|
|
3739
|
+
return innerPrepare(config, signal, configure);
|
|
3736
3740
|
}
|
|
3737
3741
|
const key = agent ?? config;
|
|
3738
3742
|
resolving.set(key, (resolving.get(key) ?? 0) + 1);
|
|
3739
3743
|
try {
|
|
3740
|
-
const
|
|
3741
|
-
|
|
3742
|
-
const note = (agent === void 0 ? void 0 : notes.get(agent)) ?? loggedTurn(asAgent(agent));
|
|
3743
|
-
const classify = settings.autoClassifierEnabled ? createClassifier({ prepareCall: inner }, map.classifier) : void 0;
|
|
3744
|
-
const mapped = await resolveAutoRoute({
|
|
3745
|
-
text: note?.text ?? "",
|
|
3746
|
-
feature: "session",
|
|
3747
|
-
toolHeavy: note?.toolHeavy ?? false,
|
|
3748
|
-
map,
|
|
3749
|
-
classifierEnabled: settings.autoClassifierEnabled,
|
|
3750
|
-
classify,
|
|
3751
|
-
isAvailable: (provider, model) => provider !== "" && model !== "" && !isAutoModel({ provider, model }),
|
|
3752
|
-
signal,
|
|
3753
|
-
fallback: fallbackRoute(ctx, asAgent(agent))
|
|
3754
|
-
});
|
|
3755
|
-
if (agent !== void 0) setSessionResolvedRoute(agent, mapped);
|
|
3756
|
-
return await inner(routeConfig(config, mapped), signal, configure);
|
|
3744
|
+
const mapped = await remapAuto(config, signal, agent);
|
|
3745
|
+
return await innerPrepare(routeConfig(config, mapped), signal, configure);
|
|
3757
3746
|
} finally {
|
|
3758
3747
|
const nextDepth = (resolving.get(key) ?? 1) - 1;
|
|
3759
3748
|
if (nextDepth <= 0) resolving.delete(key);
|
|
3760
3749
|
else resolving.set(key, nextDepth);
|
|
3761
3750
|
}
|
|
3762
3751
|
};
|
|
3763
|
-
llm.prepareCall =
|
|
3752
|
+
llm.prepareCall = wrappedPrepare;
|
|
3753
|
+
let wrappedStream;
|
|
3754
|
+
if (innerStream !== void 0) {
|
|
3755
|
+
wrappedStream = (options2) => {
|
|
3756
|
+
const agent = activeAgent(ctx);
|
|
3757
|
+
if (!shouldRemapAuto(options2, asAgent(agent))) return innerStream(options2);
|
|
3758
|
+
const keyProbe = agent ?? options2;
|
|
3759
|
+
const depth = resolving.get(keyProbe) ?? 0;
|
|
3760
|
+
if (depth > 0) return innerStream(options2);
|
|
3761
|
+
return (async function* remappedAutoStream() {
|
|
3762
|
+
const key = agent ?? options2;
|
|
3763
|
+
resolving.set(key, (resolving.get(key) ?? 0) + 1);
|
|
3764
|
+
try {
|
|
3765
|
+
const mapped = await remapAuto(options2, options2.signal, agent, "session");
|
|
3766
|
+
const routed = routeConfig(options2, mapped);
|
|
3767
|
+
yield* innerStream({ ...options2, ...routed });
|
|
3768
|
+
} finally {
|
|
3769
|
+
const nextDepth = (resolving.get(key) ?? 1) - 1;
|
|
3770
|
+
if (nextDepth <= 0) resolving.delete(key);
|
|
3771
|
+
else resolving.set(key, nextDepth);
|
|
3772
|
+
}
|
|
3773
|
+
})();
|
|
3774
|
+
};
|
|
3775
|
+
llm.stream = wrappedStream;
|
|
3776
|
+
}
|
|
3764
3777
|
return () => {
|
|
3765
|
-
if (llm.prepareCall ===
|
|
3778
|
+
if (llm.prepareCall === wrappedPrepare) llm.prepareCall = innerPrepare;
|
|
3779
|
+
if (wrappedStream !== void 0 && llm.stream === wrappedStream && innerStream !== void 0) {
|
|
3780
|
+
llm.stream = innerStream;
|
|
3781
|
+
}
|
|
3766
3782
|
};
|
|
3767
3783
|
});
|
|
3768
3784
|
}
|
|
@@ -5881,7 +5897,7 @@ var inject = [
|
|
|
5881
5897
|
"tokenMeter",
|
|
5882
5898
|
"typert",
|
|
5883
5899
|
"typertGateway",
|
|
5884
|
-
//
|
|
5900
|
+
// Chat `/compact` → compaction.compactNow; commands kept as fallback.
|
|
5885
5901
|
"commands"
|
|
5886
5902
|
];
|
|
5887
5903
|
var Config = z5.object({
|
|
@@ -5922,7 +5938,7 @@ var hostContribution = {
|
|
|
5922
5938
|
invocations: [...remoteInfo.descriptors, ...checkpointRemoteInfo.descriptors]
|
|
5923
5939
|
};
|
|
5924
5940
|
var AgentEnhancerService = class extends TypertRemoteService {
|
|
5925
|
-
constructor(ctx, models,
|
|
5941
|
+
constructor(ctx, models, usage = {
|
|
5926
5942
|
async summarize(range) {
|
|
5927
5943
|
return summarizeUsage([], range, Date.now());
|
|
5928
5944
|
}
|
|
@@ -5936,12 +5952,10 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
5936
5952
|
}) {
|
|
5937
5953
|
super(ctx, "agentEnhancer");
|
|
5938
5954
|
this.models = models;
|
|
5939
|
-
this.compactRoute = compactRoute;
|
|
5940
5955
|
this.usage = usage;
|
|
5941
5956
|
this.balances = balances;
|
|
5942
5957
|
}
|
|
5943
5958
|
models;
|
|
5944
|
-
compactRoute;
|
|
5945
5959
|
usage;
|
|
5946
5960
|
balances;
|
|
5947
5961
|
assertOwner() {
|
|
@@ -5991,7 +6005,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
5991
6005
|
throw new RemoteError("agent-enhancer/failed", "Context inspect failed", { code: "MODEL_FAILED" });
|
|
5992
6006
|
}
|
|
5993
6007
|
}
|
|
5994
|
-
/** Trigger
|
|
6008
|
+
/** Trigger official idle compaction (same seam as chat `/compact`). */
|
|
5995
6009
|
async compactContext(request, signal) {
|
|
5996
6010
|
this.assertOwner();
|
|
5997
6011
|
signal.throwIfAborted();
|
|
@@ -6003,16 +6017,18 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
6003
6017
|
}
|
|
6004
6018
|
try {
|
|
6005
6019
|
return await withUsageSource("compact", async () => compactContextNow({
|
|
6006
|
-
|
|
6020
|
+
compaction: softService2(this.ctx, "compaction", "compactNow"),
|
|
6021
|
+
commands: softService2(this.ctx, "commands", "execute") ?? this.ctx.commands,
|
|
6007
6022
|
agent,
|
|
6008
6023
|
sessionId: request.sessionId,
|
|
6009
|
-
signal
|
|
6010
|
-
route: await this.compactRoute(agent.session, signal)
|
|
6024
|
+
signal
|
|
6011
6025
|
}));
|
|
6012
6026
|
} catch (error) {
|
|
6013
6027
|
if (signal.aborted) throw error;
|
|
6014
6028
|
const code = error instanceof AuxiliaryError ? error.code : "COMPACT_FAILED";
|
|
6015
|
-
|
|
6029
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
6030
|
+
this.ctx.logger.warn(`agent-enhancer compact failed (${code}): ${detail}`);
|
|
6031
|
+
throw new RemoteError("agent-enhancer/failed", detail || "Context compaction failed", { code });
|
|
6016
6032
|
}
|
|
6017
6033
|
}
|
|
6018
6034
|
/** Read-only version probe — same gate policy as `listCatalog` (settings-safe). */
|
|
@@ -6146,7 +6162,6 @@ function apply(ctx, config) {
|
|
|
6146
6162
|
new AgentEnhancerService(
|
|
6147
6163
|
ctx,
|
|
6148
6164
|
models,
|
|
6149
|
-
(session, signal) => resolveCompactRouteOverride(ctx, settings(), session, signal),
|
|
6150
6165
|
{
|
|
6151
6166
|
async summarize(range) {
|
|
6152
6167
|
const stored = await usage.listCalls();
|