maka-agent 0.2.0-dev.30.20260912 → 0.2.0-dev.32.20260914
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/THIRD_PARTY_NOTICES.txt +392 -0
- package/dist/acp/maka-acp-agent.js +8 -2
- package/dist/acp/prompt-content.js +225 -0
- package/dist/acp/session-event-mapper.js +103 -0
- package/dist/acp/session-registry.js +654 -17
- package/dist/acp/stdio-server.js +10 -1
- package/dist/cli-core.js +1 -1
- package/dist/pi-transcript-tools.js +3 -2
- package/dist/pi-transcript.js +15 -6
- package/dist/runtime-host-session-channel.js +63 -9
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/agent-graph-schedule.js +15 -4
- package/node_modules/@maka/core/dist/artifacts.js +6 -0
- package/node_modules/@maka/core/dist/attachments.js +7 -2
- package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
- package/node_modules/@maka/core/dist/events.js +21 -0
- package/node_modules/@maka/core/dist/executor-id.js +22 -0
- package/node_modules/@maka/core/dist/external-session.js +18 -0
- package/node_modules/@maka/core/dist/goal.js +44 -2
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -13
- package/node_modules/@maka/core/dist/permission.js +0 -1
- package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
- package/node_modules/@maka/core/dist/runtime-event.js +25 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
- package/node_modules/@maka/core/dist/session-send-projection.js +6 -3
- package/node_modules/@maka/core/dist/session.js +8 -2
- package/node_modules/@maka/core/dist/shell-run-result.js +1 -0
- package/node_modules/@maka/core/dist/shell-run.js +4 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/unified-diff.js +33 -26
- package/node_modules/@maka/core/dist/work-board.js +94 -1
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/eval/dist/fleet-simulation.js +270 -0
- package/node_modules/@maka/eval/dist/fleet-store.js +243 -0
- package/node_modules/@maka/eval/dist/fleet-worker.js +125 -0
- package/node_modules/@maka/eval/dist/fleet.js +329 -0
- package/node_modules/@maka/eval/dist/index.js +3 -0
- package/node_modules/@maka/runtime/dist/agent-run.js +2 -17
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +55 -180
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +43 -26
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +271 -382
- package/node_modules/@maka/runtime/dist/background-task-health-tool.js +104 -0
- package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
- package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
- package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
- package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
- package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
- package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
- package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
- package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
- package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
- package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
- package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
- package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
- package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
- package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
- package/node_modules/@maka/runtime/dist/history-compaction.js +3 -1
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +1 -1
- package/node_modules/@maka/runtime/dist/model-adapter.js +62 -53
- package/node_modules/@maka/runtime/dist/model-history.js +26 -8
- package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +311 -0
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +344 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +7 -1
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +35 -8
- package/node_modules/@maka/runtime/dist/read-page.js +231 -0
- package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
- package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
- package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +7 -1
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +188 -20
- package/node_modules/@maka/runtime/dist/runtime-invocation-route.js +49 -0
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +72 -150
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -3
- package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +106 -64
- package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
- package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +10 -4
- package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +2 -1
- package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
- package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +1 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +26 -4
- package/node_modules/@maka/runtime/dist/subagent-tools.js +7 -0
- package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
- package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
- package/node_modules/@maka/runtime/dist/tool-runtime.js +52 -471
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
- package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
- package/node_modules/@maka/runtime/package.json +5 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +7 -2
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +24 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +42 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +31 -3
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +8 -2
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
- package/node_modules/@maka/runtime-host/dist/server/child-agent-composition.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +3 -30
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +56 -8
- package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +14 -1
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
- package/node_modules/@maka/runtime-host/dist/server/host-session-availability.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +56 -16
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +9 -5
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
- package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +37 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
- package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +450 -234
- package/node_modules/@maka/storage/dist/claude-code-transcript-lineage.js +106 -77
- package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
- package/node_modules/@maka/storage/dist/legacy-run-header.js +2 -2
- package/node_modules/@maka/storage/dist/model-call-usage-sql.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
- package/node_modules/@maka/storage/dist/session-store.js +12 -2
- package/node_modules/@maka/storage/dist/sqlite-long-term-memory-store.js +86 -12
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
- package/node_modules/@maka/storage/dist/work-board-store.js +40 -1
- package/node_modules/balanced-match/LICENSE.md +23 -0
- package/node_modules/balanced-match/README.md +57 -0
- package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
- package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
- package/node_modules/balanced-match/dist/esm/index.js +54 -0
- package/node_modules/balanced-match/dist/esm/package.json +3 -0
- package/node_modules/balanced-match/package.json +68 -0
- package/node_modules/brace-expansion/LICENSE +23 -0
- package/node_modules/brace-expansion/README.md +105 -0
- package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
- package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
- package/node_modules/brace-expansion/dist/esm/index.js +285 -0
- package/node_modules/brace-expansion/dist/esm/package.json +3 -0
- package/node_modules/brace-expansion/package.json +64 -0
- package/node_modules/glob/LICENSE.md +63 -0
- package/node_modules/glob/README.md +1203 -0
- package/node_modules/glob/dist/commonjs/glob.js +248 -0
- package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
- package/node_modules/glob/dist/commonjs/ignore.js +119 -0
- package/node_modules/glob/dist/commonjs/index.js +68 -0
- package/node_modules/glob/dist/commonjs/index.min.js +4 -0
- package/node_modules/glob/dist/commonjs/package.json +3 -0
- package/node_modules/glob/dist/commonjs/pattern.js +223 -0
- package/node_modules/glob/dist/commonjs/processor.js +301 -0
- package/node_modules/glob/dist/commonjs/walker.js +387 -0
- package/node_modules/glob/dist/esm/glob.js +244 -0
- package/node_modules/glob/dist/esm/has-magic.js +23 -0
- package/node_modules/glob/dist/esm/ignore.js +115 -0
- package/node_modules/glob/dist/esm/index.js +55 -0
- package/node_modules/glob/dist/esm/index.min.js +4 -0
- package/node_modules/glob/dist/esm/package.json +3 -0
- package/node_modules/glob/dist/esm/pattern.js +219 -0
- package/node_modules/glob/dist/esm/processor.js +294 -0
- package/node_modules/glob/dist/esm/walker.js +381 -0
- package/node_modules/glob/package.json +98 -0
- package/node_modules/minimatch/LICENSE.md +55 -0
- package/node_modules/minimatch/README.md +528 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
- package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
- package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
- package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
- package/node_modules/minimatch/dist/commonjs/package.json +3 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
- package/node_modules/minimatch/dist/esm/ast.js +841 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
- package/node_modules/minimatch/dist/esm/escape.js +26 -0
- package/node_modules/minimatch/dist/esm/index.js +1114 -0
- package/node_modules/minimatch/dist/esm/package.json +3 -0
- package/node_modules/minimatch/dist/esm/unescape.js +34 -0
- package/node_modules/minimatch/package.json +73 -0
- package/node_modules/minipass/LICENSE.md +55 -0
- package/node_modules/minipass/README.md +825 -0
- package/node_modules/minipass/dist/commonjs/index.js +1038 -0
- package/node_modules/minipass/dist/commonjs/package.json +3 -0
- package/node_modules/minipass/dist/esm/index.js +1020 -0
- package/node_modules/minipass/dist/esm/package.json +3 -0
- package/node_modules/minipass/package.json +77 -0
- package/node_modules/path-scurry/LICENSE.md +55 -0
- package/node_modules/path-scurry/README.md +636 -0
- package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
- package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/dist/esm/index.js +1983 -0
- package/node_modules/path-scurry/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
- package/node_modules/path-scurry/package.json +72 -0
- package/package.json +1 -1
- package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
- package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +0 -115
|
@@ -22,10 +22,9 @@ import { isHistoryCompactContentEvent } from './history-compaction.js';
|
|
|
22
22
|
import { canContinueHistoryCompactCheckpointForModel, canReplayHistoryCompactCheckpointForModel, historyCompactSourceDigest, matchHistoryCompactCheckpointPrefix, projectHistoryCompactCheckpointReplay, } from './history-compact-checkpoint.js';
|
|
23
23
|
import { HistoryCompactSummarizerError, isMalformedHistoryCompactSummaryReason, } from './history-compact-error.js';
|
|
24
24
|
import { createHash } from 'node:crypto';
|
|
25
|
-
import {
|
|
26
|
-
import { archiveToolResultAsTransition, collectStaleToolResultArchiveCandidates, serializedToolResultProjection, } from './tool-result-archive-transition.js';
|
|
25
|
+
import { archiveToolResultAsTransition, collectToolResultArchiveCandidates, serializedToolResultProjection, } from './tool-result-archive-transition.js';
|
|
27
26
|
import { estimateTokens } from './context-budget-helpers.js';
|
|
28
|
-
import {
|
|
27
|
+
import { reduceEffectiveModelProjections, } from './model-projection-transition-ledger.js';
|
|
29
28
|
import { buildRuntimeEventModelReplayPlan, collectToolActivityTurnIds, compatibleProviderReasoningReplayEventIds, } from './model-history.js';
|
|
30
29
|
import { planHistoryCompaction } from './history-compaction.js';
|
|
31
30
|
import { resolveDeclaredContextWindow } from './context-budget-policy.js';
|
|
@@ -98,7 +97,6 @@ export class AiSdkCompaction {
|
|
|
98
97
|
sessionId: this.sessionId,
|
|
99
98
|
archiveToolResult: (candidate) => archive(candidate),
|
|
100
99
|
recordTransition: (transition) => record(transition, turnId),
|
|
101
|
-
loadTransitions: () => this.loadModelProjectionTransitions(),
|
|
102
100
|
now: this.now,
|
|
103
101
|
};
|
|
104
102
|
}
|
|
@@ -287,7 +285,9 @@ export class AiSdkCompaction {
|
|
|
287
285
|
const route = invocation.opening.route;
|
|
288
286
|
return {
|
|
289
287
|
runId: invocation.runId,
|
|
290
|
-
...(route.provenance === 'runtime'
|
|
288
|
+
...(route.provenance === 'runtime' && route.backendKind !== 'plugin-executor'
|
|
289
|
+
? { connectionId: route.llmConnectionId }
|
|
290
|
+
: {}),
|
|
291
291
|
modelId: route.modelId,
|
|
292
292
|
};
|
|
293
293
|
})
|
|
@@ -335,11 +335,11 @@ export class AiSdkCompaction {
|
|
|
335
335
|
*
|
|
336
336
|
* The current Turn's own events go through here on every provider step, for
|
|
337
337
|
* the same reason prior Turns do: what the model sees is the folded ledger,
|
|
338
|
-
* not the raw one.
|
|
339
|
-
*
|
|
338
|
+
* not the raw one. Checkpoint validation and replay pass the same snapshot;
|
|
339
|
+
* standalone callers read one here. Unreadable targets remain withheld.
|
|
340
340
|
*/
|
|
341
|
-
async foldEffectiveModelHistory(events) {
|
|
342
|
-
const loaded = await this.loadModelProjectionTransitions();
|
|
341
|
+
async foldEffectiveModelHistory(events, snapshot) {
|
|
342
|
+
const loaded = snapshot ?? (await this.loadModelProjectionTransitions());
|
|
343
343
|
if (loaded.transitions.length === 0 && loaded.unreadableTargets.size === 0) {
|
|
344
344
|
return [...events];
|
|
345
345
|
}
|
|
@@ -371,39 +371,32 @@ export class AiSdkCompaction {
|
|
|
371
371
|
return historyCompactSourceDigest(covered) === pinned;
|
|
372
372
|
}
|
|
373
373
|
/**
|
|
374
|
-
*
|
|
375
|
-
* commit any new stale-result transition the prune policy calls for.
|
|
374
|
+
* Apply the same bounded-result rule to current and prior events.
|
|
376
375
|
*
|
|
377
376
|
* This is the one seam where raw RuntimeEvents become effective model
|
|
378
377
|
* history: the caller uses the returned events for replay, budgeting and
|
|
379
378
|
* compaction alike, so no later stage can read content a transition removed.
|
|
380
379
|
*/
|
|
381
|
-
async
|
|
380
|
+
async pruneToolResults(runtimeContext, turnId) {
|
|
382
381
|
const policy = this.input.contextBudget;
|
|
383
|
-
|
|
384
|
-
let
|
|
385
|
-
let effective = reduceEffectiveModelProjections(runtimeContext, transitions, loaded.unreadableTargets);
|
|
382
|
+
let loaded = await this.loadModelProjectionTransitions();
|
|
383
|
+
let effective = reduceEffectiveModelProjections(runtimeContext, loaded.transitions, loaded.unreadableTargets);
|
|
386
384
|
if (!policy)
|
|
387
|
-
return {
|
|
388
|
-
let
|
|
389
|
-
let diagnosticPatch;
|
|
385
|
+
return { events: effective.events, projectionSnapshot: loaded };
|
|
386
|
+
let stats;
|
|
390
387
|
// A chain this reader cannot see in full is a chain it must not extend: a
|
|
391
388
|
// successor built on a partly known state would name the wrong predecessor
|
|
392
389
|
// and be permanently inert, losing the content it archived.
|
|
393
390
|
const services = loaded.unreadableTargets.size === 0
|
|
394
391
|
? this.toolResultArchiveTransitionServices(turnId)
|
|
395
392
|
: undefined;
|
|
396
|
-
if (policy.
|
|
393
|
+
if (policy.toolResultPrune?.enabled === true && services) {
|
|
397
394
|
// The decision is taken over EFFECTIVE history, so a result an earlier
|
|
398
395
|
// Turn already replaced is never re-measured — or re-archived — at the
|
|
399
396
|
// size it used to have.
|
|
400
|
-
const candidates =
|
|
401
|
-
const committed = [];
|
|
402
|
-
let archiveFailures = 0;
|
|
403
|
-
let estimatedTokensBefore = 0;
|
|
404
|
-
let estimatedTokensAfter = 0;
|
|
397
|
+
const candidates = collectToolResultArchiveCandidates(effective.events, policy.toolResultPrune, policy.charsPerToken ?? 4);
|
|
405
398
|
for (const candidate of candidates) {
|
|
406
|
-
|
|
399
|
+
await archiveToolResultAsTransition(services, {
|
|
407
400
|
runtimeEventId: candidate.runtimeEventId,
|
|
408
401
|
turnId: candidate.turnId,
|
|
409
402
|
toolCallId: candidate.toolCallId,
|
|
@@ -415,37 +408,41 @@ export class AiSdkCompaction {
|
|
|
415
408
|
reason: candidate.reason,
|
|
416
409
|
result: candidate.result,
|
|
417
410
|
});
|
|
418
|
-
if (!outcome) {
|
|
419
|
-
archiveFailures += 1;
|
|
420
|
-
continue;
|
|
421
|
-
}
|
|
422
|
-
committed.push(outcome.transition);
|
|
423
|
-
estimatedTokensBefore += candidate.originalEstimatedTokens;
|
|
424
|
-
estimatedTokensAfter += estimateTokens(serializedToolResultProjection(outcome.transition.replacement).length, policy.charsPerToken ?? 4);
|
|
425
|
-
}
|
|
426
|
-
if (committed.length > 0) {
|
|
427
|
-
transitions = [...transitions, ...committed];
|
|
428
|
-
effective = reduceEffectiveModelProjections(runtimeContext, transitions, loaded.unreadableTargets);
|
|
429
411
|
}
|
|
430
|
-
if (
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
: {}),
|
|
443
|
-
...(archiveFailures > 0
|
|
444
|
-
? { archiveWriteFailures: archiveFailures, unarchivedToolResults: archiveFailures }
|
|
445
|
-
: {}),
|
|
412
|
+
if (candidates.length > 0) {
|
|
413
|
+
// Writes (including a rival winner or an uncertain commit) cannot tell
|
|
414
|
+
// us what the model sees. Read once after the batch and use this same
|
|
415
|
+
// snapshot for checkpoint validation, replay, and diagnostics.
|
|
416
|
+
loaded = await this.loadModelProjectionTransitions();
|
|
417
|
+
effective = reduceEffectiveModelProjections(runtimeContext, loaded.transitions, loaded.unreadableTargets);
|
|
418
|
+
stats = {
|
|
419
|
+
prunedToolResults: 0,
|
|
420
|
+
prunedToolResultEstimatedTokensBefore: 0,
|
|
421
|
+
prunedToolResultEstimatedTokensAfter: 0,
|
|
422
|
+
archiveWriteFailures: 0,
|
|
446
423
|
};
|
|
424
|
+
for (const candidate of candidates) {
|
|
425
|
+
const applied = effective.applied.find((transition) => transition.target.runtimeEventId === candidate.runtimeEventId);
|
|
426
|
+
if (!applied) {
|
|
427
|
+
stats.archiveWriteFailures++;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
stats.prunedToolResults++;
|
|
431
|
+
stats.prunedToolResultEstimatedTokensBefore += candidate.originalEstimatedTokens;
|
|
432
|
+
stats.prunedToolResultEstimatedTokensAfter += estimateTokens(serializedToolResultProjection(applied.replacement).length, policy.charsPerToken ?? 4);
|
|
433
|
+
}
|
|
447
434
|
}
|
|
448
435
|
}
|
|
436
|
+
return { events: effective.events, projectionSnapshot: loaded, ...(stats ? { stats } : {}) };
|
|
437
|
+
}
|
|
438
|
+
async prepareContextBudgetPolicy(runtimeContext, turnId) {
|
|
439
|
+
const policy = this.input.contextBudget;
|
|
440
|
+
const prepared = await this.pruneToolResults(runtimeContext, turnId);
|
|
441
|
+
const effective = { events: prepared.events };
|
|
442
|
+
if (!policy)
|
|
443
|
+
return { policy, events: effective.events, projectionSnapshot: prepared.projectionSnapshot };
|
|
444
|
+
let nextPolicy = policy;
|
|
445
|
+
let diagnosticPatch = prepared.stats;
|
|
449
446
|
let loadedCheckpoint;
|
|
450
447
|
try {
|
|
451
448
|
loadedCheckpoint = await Promise.resolve(this.input.loadHistoryCompactCheckpoint?.());
|
|
@@ -492,93 +489,10 @@ export class AiSdkCompaction {
|
|
|
492
489
|
return {
|
|
493
490
|
policy: nextPolicy,
|
|
494
491
|
events: effective.events,
|
|
492
|
+
projectionSnapshot: prepared.projectionSnapshot,
|
|
495
493
|
...(diagnosticPatch ? { diagnosticPatch } : {}),
|
|
496
494
|
};
|
|
497
495
|
}
|
|
498
|
-
buildActiveToolResultPruneProjection(turnId, includeNewestStep, onDiagnosticPatch) {
|
|
499
|
-
const policy = this.input.contextBudget?.activeToolResultPrune;
|
|
500
|
-
if (policy?.enabled !== true)
|
|
501
|
-
return undefined;
|
|
502
|
-
const services = this.toolResultArchiveTransitionServices(turnId);
|
|
503
|
-
// No durable ledger, no lossy rewrite. The old per-Turn placeholder map let
|
|
504
|
-
// this run prune content that the NEXT request would have shown again.
|
|
505
|
-
if (!services || !this.input.loadTurnRuntimeEvents)
|
|
506
|
-
return undefined;
|
|
507
|
-
// The current Turn reads the same folded history as every other consumer.
|
|
508
|
-
// Nothing here remembers what this run already archived: the ledger says it,
|
|
509
|
-
// and a step that measures the raw body again would archive it again.
|
|
510
|
-
let effective;
|
|
511
|
-
const loadEffectiveTurnEvents = async () => {
|
|
512
|
-
if (effective)
|
|
513
|
-
return effective;
|
|
514
|
-
const loaded = await this.loadModelProjectionTransitions();
|
|
515
|
-
if (loaded.unreadableTargets.size > 0)
|
|
516
|
-
return undefined;
|
|
517
|
-
let turnEvents;
|
|
518
|
-
try {
|
|
519
|
-
turnEvents = await this.input.loadTurnRuntimeEvents(turnId);
|
|
520
|
-
}
|
|
521
|
-
catch {
|
|
522
|
-
return undefined;
|
|
523
|
-
}
|
|
524
|
-
const reduction = reduceEffectiveModelProjections(turnEvents, loaded.transitions);
|
|
525
|
-
const lastApplied = new Map();
|
|
526
|
-
for (const transition of reduction.applied) {
|
|
527
|
-
lastApplied.set(transition.target.runtimeEventId, transition.transitionId);
|
|
528
|
-
}
|
|
529
|
-
effective = { events: reduction.events, lastApplied };
|
|
530
|
-
return effective;
|
|
531
|
-
};
|
|
532
|
-
const resolveProjection = async (toolCallId) => {
|
|
533
|
-
const current = await loadEffectiveTurnEvents();
|
|
534
|
-
if (!current)
|
|
535
|
-
return undefined;
|
|
536
|
-
const event = current.events.find((candidate) => candidate.partial !== true &&
|
|
537
|
-
candidate.content?.kind === 'function_response' &&
|
|
538
|
-
candidate.content.id === toolCallId);
|
|
539
|
-
if (!event || event.content?.kind !== 'function_response')
|
|
540
|
-
return undefined;
|
|
541
|
-
const projection = baseToolResultProjection(event);
|
|
542
|
-
if (!projection)
|
|
543
|
-
return undefined;
|
|
544
|
-
const previousTransitionId = current.lastApplied.get(event.id);
|
|
545
|
-
return {
|
|
546
|
-
runtimeEventId: event.id,
|
|
547
|
-
turnId: event.turnId,
|
|
548
|
-
toolName: event.content.name,
|
|
549
|
-
projection,
|
|
550
|
-
...(previousTransitionId ? { previousTransitionId } : {}),
|
|
551
|
-
};
|
|
552
|
-
};
|
|
553
|
-
return async (options) => {
|
|
554
|
-
const eligibleToolCallIds = collectPrunableCompletedStepToolCallIds(options.completedSteps, includeNewestStep);
|
|
555
|
-
if (eligibleToolCallIds.size === 0)
|
|
556
|
-
return undefined;
|
|
557
|
-
// Each provider step rebuilds its messages from the durable Turn ledger,
|
|
558
|
-
// so each step must re-fold it too.
|
|
559
|
-
effective = undefined;
|
|
560
|
-
const rewritten = await rewriteActiveToolResultsInMessages({
|
|
561
|
-
messages: options.messages,
|
|
562
|
-
policy,
|
|
563
|
-
stepNumber: options.stepNumber,
|
|
564
|
-
turnId,
|
|
565
|
-
charsPerToken: this.input.contextBudget?.charsPerToken,
|
|
566
|
-
eligibleToolCallIds,
|
|
567
|
-
completedToolCalls: options.completedSteps.flatMap((step, stepNumber) => (step.toolCalls ?? []).map((call) => ({
|
|
568
|
-
toolCallId: call.toolCallId,
|
|
569
|
-
toolName: call.toolName,
|
|
570
|
-
input: call.input,
|
|
571
|
-
stepNumber,
|
|
572
|
-
}))),
|
|
573
|
-
resolveProjection,
|
|
574
|
-
transitions: services,
|
|
575
|
-
});
|
|
576
|
-
if (hasActiveToolResultPruneDiagnosticPatch(rewritten.diagnosticPatch)) {
|
|
577
|
-
onDiagnosticPatch?.(rewritten.diagnosticPatch);
|
|
578
|
-
}
|
|
579
|
-
return rewritten.rewritten > 0 ? { messages: rewritten.messages } : undefined;
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
496
|
/**
|
|
583
497
|
* Mid-turn capacity compaction eligibility (issue #882 PR 1). Explicit
|
|
584
498
|
* opt-in via `historyCompact.midTurn.enabled`; requires the checkpoint
|
|
@@ -907,7 +821,8 @@ export class AiSdkCompaction {
|
|
|
907
821
|
// materializable and replay-admissible. A checkpoint that fails either
|
|
908
822
|
// check must never be persisted because it would poison every later
|
|
909
823
|
// projection.
|
|
910
|
-
const
|
|
824
|
+
const effectiveReplacement = await this.foldEffectiveModelHistory(plan.replacementEvents);
|
|
825
|
+
const replayPlan = buildRuntimeEventModelReplayPlan(effectiveReplacement, {
|
|
911
826
|
toolActivityTurnIds: collectToolActivityTurnIds(orderedEvents),
|
|
912
827
|
});
|
|
913
828
|
if (replayPlan.items.length === 0 ||
|
|
@@ -969,8 +884,9 @@ export class AiSdkCompaction {
|
|
|
969
884
|
*/
|
|
970
885
|
async recoverFromOverflowError(input) {
|
|
971
886
|
const state = input.midTurnState;
|
|
972
|
-
if (
|
|
887
|
+
if (!state || state.compactionAttemptedThisSend || state.omittedImageToolResults.size > 0) {
|
|
973
888
|
return undefined;
|
|
889
|
+
}
|
|
974
890
|
if (this.modelAdapter.classifyError(input.error) !== 'context_overflow')
|
|
975
891
|
return undefined;
|
|
976
892
|
const eligibleImages = collectHistoricalImageToolResults(state.priorContentEvents);
|
|
@@ -1035,41 +951,6 @@ export class AiSdkCompaction {
|
|
|
1035
951
|
return { messages: outcome.replacementMessages };
|
|
1036
952
|
}
|
|
1037
953
|
}
|
|
1038
|
-
// -- moved helpers (defined in ai-sdk-backend, used only by cache write) -------
|
|
1039
|
-
function incrementRecord(counts, key) {
|
|
1040
|
-
counts[key] = (counts[key] ?? 0) + 1;
|
|
1041
|
-
}
|
|
1042
|
-
function mergeCountsInto(target, source) {
|
|
1043
|
-
for (const [key, value] of Object.entries(source ?? {})) {
|
|
1044
|
-
target[key] = (target[key] ?? 0) + value;
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
// -- moved helpers (prepare-step / signature / prune) ------------------------
|
|
1048
|
-
/**
|
|
1049
|
-
* Tool results from the newest completed step have not crossed the provider
|
|
1050
|
-
* boundary yet: projection is invoked immediately before the first request
|
|
1051
|
-
* that could show those results to the model. By default active pruning defers
|
|
1052
|
-
* the newest step and archives only older completed steps, after the model has
|
|
1053
|
-
* had one request in which to consume their exact output.
|
|
1054
|
-
*
|
|
1055
|
-
* `includeNewestStep` widens eligibility to every completed step, including the
|
|
1056
|
-
* newest. The caller sets it when mid-turn capacity compaction is active: the
|
|
1057
|
-
* final-payload verdict may need an oversized newest result pruned to a
|
|
1058
|
-
* placeholder before declaring exhaustion, and capacity/recovery rebuilds
|
|
1059
|
-
* re-materialize raw bodies from the ledger that must be re-archived.
|
|
1060
|
-
*/
|
|
1061
|
-
function collectPrunableCompletedStepToolCallIds(steps, includeNewestStep) {
|
|
1062
|
-
const out = new Set();
|
|
1063
|
-
const prunableSteps = includeNewestStep ? steps : steps.slice(0, -1);
|
|
1064
|
-
for (const step of prunableSteps) {
|
|
1065
|
-
for (const call of step.toolCalls ?? []) {
|
|
1066
|
-
if (typeof call.toolCallId === 'string' && call.toolCallId.length > 0) {
|
|
1067
|
-
out.add(call.toolCallId);
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
return out;
|
|
1072
|
-
}
|
|
1073
954
|
function projectHistoricalImageOmissions(messages, omittedImageToolResults) {
|
|
1074
955
|
if (omittedImageToolResults.size === 0)
|
|
1075
956
|
return undefined;
|
|
@@ -1110,13 +991,6 @@ function stableStringifyForSignature(value) {
|
|
|
1110
991
|
.map((key) => `${JSON.stringify(key)}:${stableStringifyForSignature(object[key])}`)
|
|
1111
992
|
.join(',')}}`;
|
|
1112
993
|
}
|
|
1113
|
-
export function hasActiveToolResultPruneDiagnosticPatch(patch) {
|
|
1114
|
-
return ((patch.activePrunedToolResults ?? 0) > 0 ||
|
|
1115
|
-
(patch.activeSupersededToolResults ?? 0) > 0 ||
|
|
1116
|
-
(patch.activeDuplicateToolResults ?? 0) > 0 ||
|
|
1117
|
-
(patch.activeArchiveFailures ?? 0) > 0 ||
|
|
1118
|
-
(patch.activeEstimatedTokensSaved ?? 0) > 0);
|
|
1119
|
-
}
|
|
1120
994
|
/**
|
|
1121
995
|
* Per-send() state for the mid-turn capacity invariant. The coverage pool is
|
|
1122
996
|
* NOT mirrored here: every trigger reads the current turn's persisted
|
|
@@ -1265,6 +1139,7 @@ function persistedRequestAnchor(events, invocations, modelId, connectionId) {
|
|
|
1265
1139
|
continue;
|
|
1266
1140
|
const route = invocations.find((candidate) => candidate.runId === event?.runId)?.opening.route;
|
|
1267
1141
|
if (route?.provenance !== 'runtime' ||
|
|
1142
|
+
route.backendKind === 'plugin-executor' ||
|
|
1268
1143
|
route.modelId !== modelId ||
|
|
1269
1144
|
route.llmConnectionId !== connectionId) {
|
|
1270
1145
|
return undefined;
|
|
@@ -24,6 +24,31 @@ import { admitProviderReasoningReplayItems, buildRuntimeEventReplayTimeline, for
|
|
|
24
24
|
import { openAiChatReasoningFieldFromProviderOptions } from './openai-chat-reasoning-transport.js';
|
|
25
25
|
import { decodePlaintextResponsesReasoningState, replayPlaintextResponsesProviderOptions, } from './responses-reasoning-state.js';
|
|
26
26
|
import { toolResultOutput } from './tool-result-output.js';
|
|
27
|
+
function isRedactedThinking(providerOptions) {
|
|
28
|
+
const anthropic = providerOptions?.anthropic;
|
|
29
|
+
return (!!anthropic &&
|
|
30
|
+
typeof anthropic === 'object' &&
|
|
31
|
+
!Array.isArray(anthropic) &&
|
|
32
|
+
typeof anthropic.redactedData === 'string');
|
|
33
|
+
}
|
|
34
|
+
function encryptedResponsesReasoning(providerOptions) {
|
|
35
|
+
const openai = providerOptions?.openai;
|
|
36
|
+
if (!openai || typeof openai !== 'object' || Array.isArray(openai))
|
|
37
|
+
return undefined;
|
|
38
|
+
const { itemId, reasoningEncryptedContent } = openai;
|
|
39
|
+
return typeof itemId === 'string' &&
|
|
40
|
+
itemId.length > 0 &&
|
|
41
|
+
typeof reasoningEncryptedContent === 'string' &&
|
|
42
|
+
reasoningEncryptedContent.length > 0
|
|
43
|
+
? { itemId, reasoningEncryptedContent }
|
|
44
|
+
: undefined;
|
|
45
|
+
}
|
|
46
|
+
export function hasFinalizedReasoning(part) {
|
|
47
|
+
return (!!part.signature ||
|
|
48
|
+
isRedactedThinking(part.providerOptions) ||
|
|
49
|
+
decodePlaintextResponsesReasoningState(part.providerOptions).kind === 'valid' ||
|
|
50
|
+
encryptedResponsesReasoning(part.providerOptions) !== undefined);
|
|
51
|
+
}
|
|
27
52
|
function isImageToolResult(value) {
|
|
28
53
|
if (!value || typeof value !== 'object')
|
|
29
54
|
return false;
|
|
@@ -167,11 +192,7 @@ export class AiSdkMessageProjection {
|
|
|
167
192
|
}
|
|
168
193
|
: undefined;
|
|
169
194
|
}
|
|
170
|
-
|
|
171
|
-
if (anthropic &&
|
|
172
|
-
typeof anthropic === 'object' &&
|
|
173
|
-
!Array.isArray(anthropic) &&
|
|
174
|
-
typeof anthropic.redactedData === 'string') {
|
|
195
|
+
if (isRedactedThinking(item.providerOptions)) {
|
|
175
196
|
return replaySupport.signedThinking
|
|
176
197
|
? {
|
|
177
198
|
part: {
|
|
@@ -218,26 +239,17 @@ export class AiSdkMessageProjection {
|
|
|
218
239
|
return { part: { type: 'reasoning', text: item.text } };
|
|
219
240
|
}
|
|
220
241
|
if (replaySupport.responsesReasoning === 'encrypted-content') {
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
part: {
|
|
230
|
-
type: 'reasoning',
|
|
231
|
-
text: item.text,
|
|
232
|
-
providerOptions: {
|
|
233
|
-
openai: {
|
|
234
|
-
itemId,
|
|
235
|
-
reasoningEncryptedContent,
|
|
236
|
-
},
|
|
237
|
-
},
|
|
242
|
+
const encrypted = encryptedResponsesReasoning(item.providerOptions);
|
|
243
|
+
if (encrypted) {
|
|
244
|
+
return {
|
|
245
|
+
part: {
|
|
246
|
+
type: 'reasoning',
|
|
247
|
+
text: item.text,
|
|
248
|
+
providerOptions: {
|
|
249
|
+
openai: encrypted,
|
|
238
250
|
},
|
|
239
|
-
}
|
|
240
|
-
}
|
|
251
|
+
},
|
|
252
|
+
};
|
|
241
253
|
}
|
|
242
254
|
}
|
|
243
255
|
if (!replaySupport.unsignedThinking)
|
|
@@ -444,18 +456,23 @@ export class AiSdkMessageProjection {
|
|
|
444
456
|
}
|
|
445
457
|
async materializeRuntimeReplayItem(budget, item) {
|
|
446
458
|
if (item.role === 'user') {
|
|
459
|
+
// Both ordinary and steered replay materialize image attachments through
|
|
460
|
+
// the same path the original request used — a steering replay that kept
|
|
461
|
+
// only the envelope text would hand a recovery turn references without
|
|
462
|
+
// the native images the first request received.
|
|
463
|
+
const content = await this.appendImageParts(budget, item.content, item.attachments, item.steering ? `steering:${item.steering.eventId}` : `runtime-event:${item.eventId}`);
|
|
447
464
|
if (item.steering) {
|
|
448
465
|
// Already envelope-wrapped by the plan; carry the structured identity
|
|
449
466
|
// so injection dedupe recognizes the replayed message.
|
|
450
467
|
return {
|
|
451
468
|
role: 'user',
|
|
452
|
-
content
|
|
469
|
+
content,
|
|
453
470
|
providerOptions: steeringProviderOptions(item.steering.eventId),
|
|
454
471
|
};
|
|
455
472
|
}
|
|
456
473
|
return {
|
|
457
474
|
role: 'user',
|
|
458
|
-
content
|
|
475
|
+
content,
|
|
459
476
|
};
|
|
460
477
|
}
|
|
461
478
|
return {
|