@wrongstack/core 0.292.0 → 0.293.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/coordination/index.d.ts +1 -1
- package/dist/coordination/index.d.ts.map +1 -1
- package/dist/coordination/index.js +163 -39
- package/dist/coordination/index.js.map +3 -3
- package/dist/coordination/mailbox-http-router.d.ts +38 -0
- package/dist/coordination/mailbox-http-router.d.ts.map +1 -1
- package/dist/coordination/provider-status-tracker.d.ts.map +1 -1
- package/dist/core/fallback-model.d.ts.map +1 -1
- package/dist/core/fallback-profile-manager.d.ts +0 -2
- package/dist/core/fallback-profile-manager.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/defaults/index.js +351 -318
- package/dist/defaults/index.js.map +4 -4
- package/dist/execution/compaction-core.d.ts +3 -0
- package/dist/execution/compaction-core.d.ts.map +1 -1
- package/dist/execution/compactor.d.ts +4 -0
- package/dist/execution/compactor.d.ts.map +1 -1
- package/dist/execution/index.js +141 -50
- package/dist/execution/index.js.map +4 -4
- package/dist/execution/intelligent-compactor.d.ts +5 -1
- package/dist/execution/intelligent-compactor.d.ts.map +1 -1
- package/dist/execution/one-shot-llm.d.ts.map +1 -1
- package/dist/execution/selective-compactor.d.ts +4 -0
- package/dist/execution/selective-compactor.d.ts.map +1 -1
- package/dist/goal/phase-orchestrator.d.ts +4 -0
- package/dist/goal/phase-orchestrator.d.ts.map +1 -1
- package/dist/hooks/runner.d.ts +0 -2
- package/dist/hooks/runner.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +421 -248
- package/dist/index.js.map +4 -4
- package/dist/models/alibaba-token-plan-catalog.d.ts +85 -0
- package/dist/models/alibaba-token-plan-catalog.d.ts.map +1 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +200 -15
- package/dist/models/index.js.map +4 -4
- package/dist/models/llm-selector.d.ts +4 -0
- package/dist/models/llm-selector.d.ts.map +1 -1
- package/dist/models/models-registry.d.ts +8 -0
- package/dist/models/models-registry.d.ts.map +1 -1
- package/dist/security/index.js +0 -23
- package/dist/security/index.js.map +2 -2
- package/dist/security/permission-policy.d.ts +0 -23
- package/dist/security/permission-policy.d.ts.map +1 -1
- package/dist/storage/config-loader.d.ts.map +1 -1
- package/dist/storage/index.js +6 -5
- package/dist/storage/index.js.map +2 -2
- package/dist/tools/index.js +8 -1
- package/dist/tools/index.js.map +2 -2
- package/dist/types/config.d.ts +9 -16
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.js +7 -4
- package/dist/types/index.js.map +2 -2
- package/dist/types/provider.d.ts.map +1 -1
- package/dist/utils/connectivity.d.ts +36 -0
- package/dist/utils/connectivity.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +59 -11
- package/dist/utils/index.js.map +4 -4
- package/dist/utils/merge-models-payload.d.ts +9 -0
- package/dist/utils/merge-models-payload.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Message } from '../types/messages.js';
|
|
2
|
+
import type { Logger } from '../types/logger.js';
|
|
2
3
|
import { estimateMessageTokens } from '../utils/token-estimate.js';
|
|
4
|
+
/** Set the module-level compaction debug logger (called by compactor constructors). */
|
|
5
|
+
export declare function setCompactionDebugLogger(logger: Logger | undefined): void;
|
|
3
6
|
/**
|
|
4
7
|
* Token estimate for a message array (text + tool I/O). Re-exported from the
|
|
5
8
|
* canonical `token-estimate` helper so compactors and the context-pressure
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-core.d.ts","sourceRoot":"","sources":["../../src/execution/compaction-core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"compaction-core.d.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AAM,CAAC,CAAA;CAAE,GAChD,YAAY,CA6Dd;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAuDrE;AAiCD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAS/F;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAczF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Context } from '../core/context.js';
|
|
2
2
|
import type { CompactReport, Compactor } from '../types/compactor.js';
|
|
3
|
+
import type { Logger } from '../types/logger.js';
|
|
3
4
|
export interface CompactorOptions {
|
|
4
5
|
preserveK?: number | undefined;
|
|
5
6
|
eliseThreshold?: number | undefined;
|
|
@@ -17,6 +18,8 @@ export interface CompactorOptions {
|
|
|
17
18
|
* monitor agree on one number. Kept only for backward-compatible call sites.
|
|
18
19
|
*/
|
|
19
20
|
estimator?: (((text: string) => number)) | undefined;
|
|
21
|
+
/** Structured logger. Defaults to noOpLogger (silent). */
|
|
22
|
+
logger?: Logger | undefined;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* Default tools config values shared across CLI and WebUI.
|
|
@@ -31,6 +34,7 @@ export declare class HybridCompactor implements Compactor {
|
|
|
31
34
|
private readonly preserveK;
|
|
32
35
|
private readonly eliseThreshold;
|
|
33
36
|
private readonly smart;
|
|
37
|
+
private readonly logger;
|
|
34
38
|
constructor(opts?: CompactorOptions);
|
|
35
39
|
compact(ctx: Context, opts?: {
|
|
36
40
|
aggressive?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compactor.d.ts","sourceRoot":"","sources":["../../src/execution/compactor.ts"],"names":[],"mapp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GAAG,OAAO,CAAC,aAAa,CAAC,CAmEnG;IAED;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,oBAAoB;CAiD7B"}
|
package/dist/execution/index.js
CHANGED
|
@@ -82,6 +82,50 @@ async function renameWithRetry(from, to) {
|
|
|
82
82
|
throw lastErr;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// src/utils/term.ts
|
|
86
|
+
var hasStdout = () => typeof process !== "undefined" && !!process.stdout;
|
|
87
|
+
function isStdoutTTY() {
|
|
88
|
+
return hasStdout() && Boolean(process.stdout.isTTY);
|
|
89
|
+
}
|
|
90
|
+
var ESCAPE_TERMINATOR = Object.freeze({
|
|
91
|
+
BEL: "\x07",
|
|
92
|
+
// OSC 0 / OSC 2 (title)
|
|
93
|
+
ST: "\x1B\\"
|
|
94
|
+
// DCS / strict OSC
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// src/utils/color.ts
|
|
98
|
+
var isColorTty = () => {
|
|
99
|
+
if (envFlag(process.env.NO_COLOR)) return false;
|
|
100
|
+
if (envFlag(process.env.FORCE_COLOR)) return true;
|
|
101
|
+
return isStdoutTTY();
|
|
102
|
+
};
|
|
103
|
+
function envFlag(value) {
|
|
104
|
+
if (value === void 0) return false;
|
|
105
|
+
if (value.trim() === "") return false;
|
|
106
|
+
return !/^(0|false|no|off)$/i.test(value.trim());
|
|
107
|
+
}
|
|
108
|
+
var COLOR = isColorTty();
|
|
109
|
+
var wrap = (open2, close) => (s) => COLOR ? `\x1B[${open2}m${s}\x1B[${close}m` : s;
|
|
110
|
+
var color = {
|
|
111
|
+
reset: wrap("0", "0"),
|
|
112
|
+
bold: wrap("1", "22"),
|
|
113
|
+
dim: wrap("2", "22"),
|
|
114
|
+
italic: wrap("3", "23"),
|
|
115
|
+
underline: wrap("4", "24"),
|
|
116
|
+
red: wrap("31", "39"),
|
|
117
|
+
green: wrap("32", "39"),
|
|
118
|
+
yellow: wrap("33", "39"),
|
|
119
|
+
blue: wrap("34", "39"),
|
|
120
|
+
magenta: wrap("35", "39"),
|
|
121
|
+
cyan: wrap("36", "39"),
|
|
122
|
+
gray: wrap("90", "39"),
|
|
123
|
+
amber: wrap("38;5;214", "39"),
|
|
124
|
+
pink: wrap("38;5;205", "39"),
|
|
125
|
+
bgRed: wrap("41", "49"),
|
|
126
|
+
bgGreen: wrap("42", "49")
|
|
127
|
+
};
|
|
128
|
+
|
|
85
129
|
// src/types/blocks.ts
|
|
86
130
|
function isTextBlock(b) {
|
|
87
131
|
return b.type === "text";
|
|
@@ -2044,25 +2088,30 @@ var WHITESPACE_COLLAPSE_PATTERN = /\s+/g;
|
|
|
2044
2088
|
function compactionDebugEnabled() {
|
|
2045
2089
|
return process.env["NODE_ENV"] === "development" || process.env["WRONGSTACK_DEBUG"] === "1";
|
|
2046
2090
|
}
|
|
2091
|
+
var _debugLogger;
|
|
2092
|
+
function setCompactionDebugLogger(logger) {
|
|
2093
|
+
_debugLogger = logger;
|
|
2094
|
+
}
|
|
2047
2095
|
function emitCompactionMetrics(event, metrics) {
|
|
2048
2096
|
if (!compactionDebugEnabled()) return;
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2097
|
+
const ctx = {
|
|
2098
|
+
event,
|
|
2099
|
+
messageCount: metrics.messageCount,
|
|
2100
|
+
preserveStart: metrics.preserveStart,
|
|
2101
|
+
fastPathIterations: metrics.fastPathIterations,
|
|
2102
|
+
fastPathInnerIterations: metrics.fastPathInnerIterations,
|
|
2103
|
+
fastPathInnerPerOuter: metrics.fastPathIterations > 0 ? metrics.fastPathInnerIterations / metrics.fastPathIterations : 0,
|
|
2104
|
+
fullPassIterations: metrics.fullPassIterations,
|
|
2105
|
+
fullPassInnerIterations: metrics.fullPassInnerIterations,
|
|
2106
|
+
fullPassInnerPerOuter: metrics.fullPassIterations > 0 ? metrics.fullPassInnerIterations / metrics.fullPassIterations : 0,
|
|
2107
|
+
tokensSaved: metrics.tokensSaved,
|
|
2108
|
+
changed: metrics.changed
|
|
2109
|
+
};
|
|
2110
|
+
if (_debugLogger) {
|
|
2111
|
+
_debugLogger.debug(`compaction: ${event}`, ctx);
|
|
2112
|
+
} else {
|
|
2113
|
+
console.log(JSON.stringify({ level: "debug", ...ctx }));
|
|
2114
|
+
}
|
|
2066
2115
|
}
|
|
2067
2116
|
var estimateMessages = estimateMessageTokens;
|
|
2068
2117
|
function hasTextContent(m) {
|
|
@@ -2094,18 +2143,20 @@ function findPreserveStart(messages, preserveK) {
|
|
|
2094
2143
|
preserveStart--;
|
|
2095
2144
|
}
|
|
2096
2145
|
if (compactionDebugEnabled()) {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2146
|
+
const ctx = {
|
|
2147
|
+
event: "compaction.find_preserve_start.ended",
|
|
2148
|
+
messageCount: messages.length,
|
|
2149
|
+
preserveK,
|
|
2150
|
+
preserveStart,
|
|
2151
|
+
pairRepairIterations,
|
|
2152
|
+
pairRepairInnerIterations,
|
|
2153
|
+
pairRepairInnerPerOuter: pairRepairIterations > 0 ? pairRepairInnerIterations / pairRepairIterations : 0
|
|
2154
|
+
};
|
|
2155
|
+
if (_debugLogger) {
|
|
2156
|
+
_debugLogger.debug("compaction: find_preserve_start.ended", ctx);
|
|
2157
|
+
} else {
|
|
2158
|
+
console.log(JSON.stringify({ level: "debug", ...ctx }));
|
|
2159
|
+
}
|
|
2109
2160
|
}
|
|
2110
2161
|
return preserveStart;
|
|
2111
2162
|
}
|
|
@@ -2220,16 +2271,18 @@ function eliseOldToolResults(messages, opts) {
|
|
|
2220
2271
|
if (compactionDebugEnabled()) {
|
|
2221
2272
|
const ratio = fullPassInnerIterations / fullPassIterations;
|
|
2222
2273
|
if (ratio > 10) {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
})
|
|
2232
|
-
|
|
2274
|
+
const ctx = {
|
|
2275
|
+
event: "compaction.elision.regression",
|
|
2276
|
+
message: `fullPassInnerPerOuter=${ratio.toFixed(2)} exceeds threshold 10 \u2014 possible O(n\xB7m) regression`,
|
|
2277
|
+
messageCount: messages.length,
|
|
2278
|
+
fullPassIterations,
|
|
2279
|
+
fullPassInnerIterations
|
|
2280
|
+
};
|
|
2281
|
+
if (_debugLogger) {
|
|
2282
|
+
_debugLogger.error(`compaction: elision.regression \u2014 ratio ${ratio.toFixed(2)}`, ctx);
|
|
2283
|
+
} else {
|
|
2284
|
+
console.error(JSON.stringify({ level: "error", ...ctx }));
|
|
2285
|
+
}
|
|
2233
2286
|
}
|
|
2234
2287
|
}
|
|
2235
2288
|
}
|
|
@@ -3248,15 +3301,43 @@ function resolveContextWindowPolicy(config = {}, overrideMode) {
|
|
|
3248
3301
|
};
|
|
3249
3302
|
}
|
|
3250
3303
|
|
|
3304
|
+
// src/infrastructure/logger.ts
|
|
3305
|
+
var COLORS = {
|
|
3306
|
+
error: color.red,
|
|
3307
|
+
warn: color.yellow,
|
|
3308
|
+
info: color.cyan,
|
|
3309
|
+
debug: color.gray,
|
|
3310
|
+
trace: color.dim
|
|
3311
|
+
};
|
|
3312
|
+
var noOpLogger = {
|
|
3313
|
+
// 'error' is the quietest level the Logger contract offers; the methods
|
|
3314
|
+
// discard everything regardless, this only matters to level checks.
|
|
3315
|
+
level: "error",
|
|
3316
|
+
error: () => {
|
|
3317
|
+
},
|
|
3318
|
+
warn: () => {
|
|
3319
|
+
},
|
|
3320
|
+
info: () => {
|
|
3321
|
+
},
|
|
3322
|
+
debug: () => {
|
|
3323
|
+
},
|
|
3324
|
+
trace: () => {
|
|
3325
|
+
},
|
|
3326
|
+
child: () => noOpLogger
|
|
3327
|
+
};
|
|
3328
|
+
|
|
3251
3329
|
// src/execution/compactor.ts
|
|
3252
3330
|
var HybridCompactor = class {
|
|
3253
3331
|
preserveK;
|
|
3254
3332
|
eliseThreshold;
|
|
3255
3333
|
smart;
|
|
3334
|
+
logger;
|
|
3256
3335
|
constructor(opts = {}) {
|
|
3257
3336
|
this.preserveK = opts.preserveK ?? 5;
|
|
3258
3337
|
this.eliseThreshold = opts.eliseThreshold ?? 2e3;
|
|
3259
3338
|
this.smart = opts.smart ?? false;
|
|
3339
|
+
this.logger = opts.logger ?? noOpLogger;
|
|
3340
|
+
setCompactionDebugLogger(this.logger);
|
|
3260
3341
|
}
|
|
3261
3342
|
async compact(ctx, opts = {}) {
|
|
3262
3343
|
const beforeTokens = estimateMessages(ctx.messages);
|
|
@@ -3870,7 +3951,8 @@ function extractText2(result) {
|
|
|
3870
3951
|
// src/types/provider.ts
|
|
3871
3952
|
var CONTEXT_OVERFLOW_RE = /context.length|context.window|maximum context|max.*tokens?.*exceeded|prompt is too long|too long|exceeds the context|\btokens\b.*exceed|too many tokens|reduce the length|resulted in \d+ tokens|input.{0,12}too (?:large|long)|context_length_exceeded/i;
|
|
3872
3953
|
var CONTENT_FILTER_RE = /content.(filter|policy|moderation)|safety (system|filter)/i;
|
|
3873
|
-
var QUOTA_EXHAUSTED_RE = /(?:insufficient|exhausted|depleted|exceeded|no|not enough)[-_\s]*(?:quota|credit|balance)|(?:quota|credit|balance)[-_\s]*(?:exhausted|depleted|exceeded|insufficient)|billing[_\s-]*(?:hard[_\s-]*)?limit|payment required|spending limit|plan limit/i;
|
|
3954
|
+
var QUOTA_EXHAUSTED_RE = /(?:insufficient|exhausted|depleted|exceeded|no|not enough)[-_\s]*(?:quota|credit|balance)|(?:quota|credit|balance)[-_\s]*(?:exhausted|depleted|exceeded|insufficient)|billing[_\s-]*(?:hard[_\s-]*)?limit|payment required|spending limit|plan limit|usage[-_\s]*limit[-_\s]*(?:reached|exceeded)/i;
|
|
3955
|
+
var RATE_LIMIT_EXCEEDED_RE = /rate[-_\s]*limit[-_\s]*exceeded/i;
|
|
3874
3956
|
function classifyProviderError(status, body, message) {
|
|
3875
3957
|
const type = body?.type;
|
|
3876
3958
|
const text = [message, body?.message, type, body?.raw].filter(Boolean).join("\n");
|
|
@@ -3878,6 +3960,9 @@ function classifyProviderError(status, body, message) {
|
|
|
3878
3960
|
if (status === 408) return "timeout";
|
|
3879
3961
|
if (status === 599) return "stream_hang";
|
|
3880
3962
|
if (status === 402 || QUOTA_EXHAUSTED_RE.test(text)) return "quota_exhausted";
|
|
3963
|
+
if (status === 429 && body?.message && RATE_LIMIT_EXCEEDED_RE.test(body.message)) {
|
|
3964
|
+
return "quota_exhausted";
|
|
3965
|
+
}
|
|
3881
3966
|
if (type === "rate_limit_error" || status === 429) return "rate_limit";
|
|
3882
3967
|
if (type === "overloaded_error" || status === 529) return "overloaded";
|
|
3883
3968
|
if (status >= 500) return "server";
|
|
@@ -8184,6 +8269,7 @@ var IntelligentCompactor = class {
|
|
|
8184
8269
|
summarizerPrompt;
|
|
8185
8270
|
summarizerModel;
|
|
8186
8271
|
oneShotOrchestrator;
|
|
8272
|
+
logger;
|
|
8187
8273
|
constructor(opts) {
|
|
8188
8274
|
this.provider = opts.provider;
|
|
8189
8275
|
this.warnThreshold = opts.warnThreshold ?? 0.5;
|
|
@@ -8195,6 +8281,8 @@ var IntelligentCompactor = class {
|
|
|
8195
8281
|
this.summarizerPrompt = opts.summarizerPrompt ?? readBundledInstructionText("llm/intelligent-compactor-summarizer.md");
|
|
8196
8282
|
this.summarizerModel = opts.summarizerModel;
|
|
8197
8283
|
this.oneShotOrchestrator = opts.oneShotOrchestrator;
|
|
8284
|
+
this.logger = opts.logger ?? noOpLogger;
|
|
8285
|
+
setCompactionDebugLogger(this.logger);
|
|
8198
8286
|
}
|
|
8199
8287
|
async compact(ctx, opts = {}) {
|
|
8200
8288
|
const beforeTokens = estimateMessages(ctx.messages);
|
|
@@ -12836,11 +12924,13 @@ var LLMSelector = class {
|
|
|
12836
12924
|
systemPrompt;
|
|
12837
12925
|
maxOutputTokens;
|
|
12838
12926
|
oneShotOrchestrator;
|
|
12927
|
+
logger;
|
|
12839
12928
|
constructor(opts) {
|
|
12840
12929
|
this.provider = opts.provider;
|
|
12841
12930
|
this.model = opts.model ?? "unknown";
|
|
12931
|
+
this.logger = opts.logger ?? noOpLogger;
|
|
12842
12932
|
if (this.model === "unknown" && (process.env["NODE_ENV"] === "development" || process.env["WRONGSTACK_DEBUG"] === "1")) {
|
|
12843
|
-
|
|
12933
|
+
this.logger.warn(
|
|
12844
12934
|
"[LLMSelector] model not set \u2014 selector will use the provider default. Set `model` explicitly in LLMSelectorOptions to silence this warning."
|
|
12845
12935
|
);
|
|
12846
12936
|
}
|
|
@@ -12890,14 +12980,9 @@ IMPORTANT: Total conversation (${totalTokens} tokens) exceeds budget (${effectiv
|
|
|
12890
12980
|
}
|
|
12891
12981
|
} catch (err) {
|
|
12892
12982
|
if (err instanceof Error) {
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
event: "llm_selector.call_failed",
|
|
12897
|
-
message: `selector call failed, using recency fallback: ${err.message}`,
|
|
12898
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
12899
|
-
})
|
|
12900
|
-
);
|
|
12983
|
+
this.logger.warn(`selector call failed, using recency fallback: ${err.message}`, {
|
|
12984
|
+
event: "llm_selector.call_failed"
|
|
12985
|
+
});
|
|
12901
12986
|
}
|
|
12902
12987
|
return this.fallbackSelect(messages, effectiveBudget);
|
|
12903
12988
|
} finally {
|
|
@@ -13004,6 +13089,7 @@ var SelectiveCompactor = class {
|
|
|
13004
13089
|
eliseThreshold;
|
|
13005
13090
|
summarizerModel;
|
|
13006
13091
|
summarizerPrompt;
|
|
13092
|
+
logger;
|
|
13007
13093
|
constructor(opts) {
|
|
13008
13094
|
this.provider = opts.provider;
|
|
13009
13095
|
this.selector = opts.selector ?? new LLMSelector({ provider: opts.provider, model: opts.selectorModel, maxOutputTokens: opts.selectorMaxOutputTokens });
|
|
@@ -13014,8 +13100,10 @@ var SelectiveCompactor = class {
|
|
|
13014
13100
|
this.preserveK = opts.preserveK ?? 4;
|
|
13015
13101
|
this.eliseThreshold = opts.eliseThreshold ?? 300;
|
|
13016
13102
|
this.summarizerModel = opts.summarizerModel ?? opts.selectorModel;
|
|
13103
|
+
this.logger = opts.logger ?? noOpLogger;
|
|
13104
|
+
setCompactionDebugLogger(this.logger);
|
|
13017
13105
|
if (this.summarizerModel === void 0 && (process.env["NODE_ENV"] === "development" || process.env["WRONGSTACK_DEBUG"] === "1")) {
|
|
13018
|
-
|
|
13106
|
+
this.logger.warn(
|
|
13019
13107
|
"[SelectiveCompactor] summarizerModel not set \u2014 will fall back to ctx.model at summarize time. Set `summarizerModel` explicitly to silence this warning."
|
|
13020
13108
|
);
|
|
13021
13109
|
}
|
|
@@ -15308,6 +15396,9 @@ var OneShotOrchestrator = class {
|
|
|
15308
15396
|
for (const entry of usableChain) {
|
|
15309
15397
|
if (!evaluateModelCalendar(config.modelAvailabilitySchedule, entry.providerId, entry.model).allowed)
|
|
15310
15398
|
continue;
|
|
15399
|
+
if (tracker && !tracker.isAvailable(entry.providerId, entry.model)) {
|
|
15400
|
+
continue;
|
|
15401
|
+
}
|
|
15311
15402
|
if (entry.providerId === provider.id && entry.model === target.model) continue;
|
|
15312
15403
|
let fbProvider;
|
|
15313
15404
|
try {
|