ds4-context-engine 0.3.0-alpha.3 → 0.3.0-alpha.5
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 +7 -5
- package/docs/ARCHITECTURE.md +5 -4
- package/docs/COMPACTION.md +8 -8
- package/docs/CONTEXT_PERSISTENCE_TOOL.md +18 -16
- package/docs/DOGFOODING_0.3.0_ALPHA.md +12 -10
- package/docs/releases/0.3.0-alpha.3.md +5 -3
- package/docs/releases/0.3.0-alpha.4.md +61 -0
- package/docs/releases/0.3.0-alpha.5.md +58 -0
- package/package.json +2 -2
- package/src/extension/commands.ts +4 -0
- package/src/extension/context-persistence-contract.ts +21 -10
- package/src/pi-adapter/compaction-adapter.ts +107 -23
- package/src/pi-adapter/compaction-coordinator.ts +415 -119
- package/src/pi-adapter/summary-generator.ts +49 -17
- package/src/pi-adapter/version.ts +1 -1
|
@@ -50,33 +50,65 @@ function responseStopReason(response: unknown): string | undefined {
|
|
|
50
50
|
return typeof response.stopReason === "string" ? response.stopReason : undefined;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
function responseErrorMessage(response: unknown): string | undefined {
|
|
54
|
+
if (!response || typeof response !== "object" || !("errorMessage" in response)) return undefined;
|
|
55
|
+
return typeof response.errorMessage === "string" ? response.errorMessage : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function providerFailureCategory(value: unknown): string {
|
|
59
|
+
const message = value instanceof Error
|
|
60
|
+
? value.message
|
|
61
|
+
: typeof value === "string"
|
|
62
|
+
? value
|
|
63
|
+
: "";
|
|
64
|
+
if (/abort|cancel/iu.test(message)) return "aborted";
|
|
65
|
+
if (/usage|quota|credit|billing/iu.test(message)) return "usage-limit";
|
|
66
|
+
if (/rate|too many requests|429/iu.test(message)) return "rate-limit";
|
|
67
|
+
if (/(?:context|prompt|input).{0,48}(?:exceed|limit|maximum|too (?:long|large)|tokens?)|tokens?.{0,48}(?:exceed|limit|maximum|too many)|maximum (?:context|input|prompt|length)/iu.test(message)) {
|
|
68
|
+
return "input-limit";
|
|
69
|
+
}
|
|
70
|
+
if (/auth|credential|api.?key|permission|forbidden|401|403/iu.test(message)) return "authentication";
|
|
71
|
+
if (/timeout|network|connection|socket|dns/iu.test(message)) return "transport";
|
|
72
|
+
return "provider-error";
|
|
73
|
+
}
|
|
74
|
+
|
|
53
75
|
export async function generateValidatedSummary(
|
|
54
76
|
input: GenerateValidatedSummaryInput,
|
|
55
77
|
): Promise<GeneratedSummary> {
|
|
56
78
|
const model = input.ctx.model;
|
|
57
79
|
if (!model) throw new Error("Compaction summary generation requires an active model");
|
|
58
80
|
const maxTokens = Math.max(1, Math.min(input.maxSummaryTokens, model.maxTokens ?? input.maxSummaryTokens));
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
let response: Awaited<ReturnType<typeof input.ctx.modelRegistry.complete>>;
|
|
82
|
+
try {
|
|
83
|
+
response = await input.ctx.modelRegistry.complete(
|
|
84
|
+
model,
|
|
85
|
+
{
|
|
86
|
+
messages: [{
|
|
87
|
+
role: "user",
|
|
88
|
+
content: [{ type: "text", text: input.prompt }],
|
|
89
|
+
timestamp: input.now(),
|
|
90
|
+
}],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
maxTokens,
|
|
94
|
+
signal: input.event.signal,
|
|
95
|
+
cacheRetention: "none",
|
|
96
|
+
sessionId: randomUUID(),
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Compaction ${input.stage} request failed (category=${providerFailureCategory(error)})`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
75
104
|
if (input.event.signal.aborted) throw new Error("Compaction summary generation aborted");
|
|
76
105
|
const stopReason = responseStopReason(response);
|
|
77
106
|
if (stopReason === "length") throw new Error("Compaction summary hit the model output limit");
|
|
78
107
|
if (stopReason === "error" || stopReason === "aborted") {
|
|
79
|
-
|
|
108
|
+
const category = stopReason === "aborted"
|
|
109
|
+
? "aborted"
|
|
110
|
+
: providerFailureCategory(responseErrorMessage(response));
|
|
111
|
+
throw new Error(`Compaction ${input.stage} summary stopped with ${stopReason} (category=${category})`);
|
|
80
112
|
}
|
|
81
113
|
if (response.content.some((block) => block.type === "toolCall")) {
|
|
82
114
|
throw new Error("Compaction summarizer attempted to call a tool");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const EXTENSION_VERSION = "0.3.0-alpha.
|
|
1
|
+
export const EXTENSION_VERSION = "0.3.0-alpha.5";
|
|
2
2
|
export const SUPPORTED_PI_VERSION = "0.84.3";
|
|
3
3
|
export const OBSERVER_PLANNER_VERSION = "observer-model-aware-v1";
|
|
4
4
|
export const PLANNER_VERSION = "managed-learned-ranking-v1";
|