maka-agent 0.2.0-dev.51.20260925 → 0.2.0-dev.53.20260927
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/acp/goal-plan-operations.js +142 -0
- package/dist/acp/goal-plan-routes.js +33 -0
- package/dist/acp/maka-acp-agent.js +41 -1
- package/dist/acp/session-domain-observation.js +185 -0
- package/dist/acp/session-event-mapper.js +1 -1
- package/dist/acp/session-registry.js +417 -9
- package/dist/acp/tool-event-mapper.js +36 -3
- package/dist/activation-command.js +11 -3
- package/dist/pi-tui-mcp-status.js +73 -5
- package/dist/pi-tui-runner.js +1 -1
- package/dist/runtime-host-run-command.js +39 -6
- package/dist/runtime-host-run-mcp.js +161 -0
- package/dist/runtime-host-session-channel.js +4 -0
- package/dist/runtime-host-session-driver.js +22 -2
- package/dist/tui-copy-catalog.js +6 -0
- package/dist/tui-mcp-control.js +11 -2
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/attachments.js +7 -0
- package/node_modules/@maka/core/dist/events.js +11 -0
- package/node_modules/@maka/core/dist/openai-urls.js +51 -0
- package/node_modules/@maka/core/dist/provider-registry.js +11 -2
- package/node_modules/@maka/core/dist/relative-time.js +1 -9
- package/node_modules/@maka/core/dist/turn-origin.js +6 -0
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +1 -5
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +90 -32
- package/node_modules/@maka/runtime/dist/bots/proxied-fetch.js +5 -4
- package/node_modules/@maka/runtime/dist/builtin-tools.js +2 -2
- package/node_modules/@maka/runtime/dist/computer-use-tools.js +136 -100
- package/node_modules/@maka/runtime/dist/context-budget-helpers.js +4 -0
- package/node_modules/@maka/runtime/dist/conversation-copy.js +51 -205
- package/node_modules/@maka/runtime/dist/edit-replace.js +7 -7
- package/node_modules/@maka/runtime/dist/filesystem-executor.js +7 -22
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +17 -28
- package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +7 -4
- package/node_modules/@maka/runtime/dist/format-json.js +39 -0
- package/node_modules/@maka/runtime/dist/glob-search.js +18 -5
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +1 -6
- package/node_modules/@maka/runtime/dist/image-file.js +22 -14
- package/node_modules/@maka/runtime/dist/model-adapter.js +18 -2
- package/node_modules/@maka/runtime/dist/model-factory.js +27 -1
- package/node_modules/@maka/runtime/dist/model-fetcher.js +2 -1
- package/node_modules/@maka/runtime/dist/model-history.js +201 -3
- package/node_modules/@maka/runtime/dist/model-runtime.js +5 -3
- package/node_modules/@maka/runtime/dist/network/abortable-connector.js +55 -0
- package/node_modules/@maka/runtime/dist/network/proxy-dispatcher.js +72 -37
- package/node_modules/@maka/runtime/dist/network/proxy-test.js +1 -1
- package/node_modules/@maka/runtime/dist/network/scoped-fetch-transport.js +7 -2
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -3
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +36 -8
- package/node_modules/@maka/runtime/dist/provider-urls.js +1 -18
- package/node_modules/@maka/runtime/dist/recovery-resolver.js +1 -91
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +44 -0
- package/node_modules/@maka/runtime/dist/scheduled-task-tools.js +27 -2
- package/node_modules/@maka/runtime/dist/session-manager.js +54 -58
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +84 -2
- package/node_modules/@maka/runtime/dist/test-connection.js +2 -2
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +79 -57
- package/node_modules/@maka/runtime/dist/workspace-executor.js +5 -6
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +27 -6
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +4 -1
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +9 -9
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +9 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +14 -1
- package/node_modules/@maka/runtime-host/dist/protocol/scheduled-task.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog-change.js +24 -6
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +28 -6
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +12 -2
- package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +10 -7
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +26 -5
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +20 -16
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +18 -1
- package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +15 -22
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +30 -3
- package/node_modules/@maka/runtime-host/dist/server/interactive-turn-coordinator.js +4 -1
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +4 -2
- package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +7 -6
- package/node_modules/@maka/runtime-host/dist/server/safe-boundary-resume-policy.js +27 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +5 -3
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +23 -5
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +11 -141
- package/node_modules/@maka/runtime-host/dist/server/session-revision-graph-references.js +46 -75
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +18 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +33 -3
- package/node_modules/@maka/runtime-host/dist/transport/framed-byte-stream-transport.js +39 -5
- package/node_modules/@maka/storage/dist/agent-run-store-contract.js +7 -1
- package/node_modules/@maka/storage/dist/artifact-store.js +1 -5
- package/node_modules/@maka/storage/dist/artifact-stores.js +0 -3
- package/node_modules/@maka/storage/dist/atomic-file-write.js +1 -0
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +107 -57
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +227 -19
- package/node_modules/@maka/storage/dist/external-session-importer.js +1 -1
- package/node_modules/@maka/storage/dist/mcp-config-store.js +22 -3
- package/node_modules/@maka/storage/dist/settings-store.js +281 -13
- package/package.json +1 -1
|
@@ -56,6 +56,13 @@ export function isDirectoryReference(value) {
|
|
|
56
56
|
value.path.length <= 4096 &&
|
|
57
57
|
isCanonicalAbsolutePath(value.path));
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Cap for {@link QuoteRef.comment}. A note about a quote carries intent, not
|
|
61
|
+
* content: long prose belongs in the message text, which has its own limit.
|
|
62
|
+
* The single authority for the IPC normalizer, the Runtime Host protocol and
|
|
63
|
+
* the composer's staging cap.
|
|
64
|
+
*/
|
|
65
|
+
export const QUOTE_COMMENT_MAX_LENGTH = 1000;
|
|
59
66
|
const MESSAGE_CONTENT_SHAPE = defineObjectShape()(['text'], ['displayText', 'attachments', 'directoryReferences', 'quotes', 'inlineReferences']);
|
|
60
67
|
/**
|
|
61
68
|
* A Turn message is meaningful when at least one of its four content carriers
|
|
@@ -81,6 +88,7 @@ export function hasMeaningfulMessageContent(content) {
|
|
|
81
88
|
const ATTACHMENT_REF_SHAPE = defineObjectShape()(['kind', 'name', 'mimeType', 'bytes', 'ref'], []);
|
|
82
89
|
const QUOTE_REF_SHAPE = defineObjectShape()(['text'], [
|
|
83
90
|
'label',
|
|
91
|
+
'comment',
|
|
84
92
|
'sourceTurnId',
|
|
85
93
|
'sourceSessionId',
|
|
86
94
|
'sourceSessionName',
|
|
@@ -121,6 +129,7 @@ export function normalizeMessageContent(content) {
|
|
|
121
129
|
quotes: content.quotes.map((quote) => ({
|
|
122
130
|
text: quote.text,
|
|
123
131
|
...(quote.label !== undefined ? { label: quote.label } : {}),
|
|
132
|
+
...(quote.comment !== undefined ? { comment: quote.comment } : {}),
|
|
124
133
|
...(quote.sourceTurnId !== undefined ? { sourceTurnId: quote.sourceTurnId } : {}),
|
|
125
134
|
...(quote.sourceSessionId !== undefined
|
|
126
135
|
? { sourceSessionId: quote.sourceSessionId }
|
|
@@ -244,6 +253,7 @@ export function isQuoteRef(value) {
|
|
|
244
253
|
hasExactShape(record, QUOTE_REF_SHAPE) &&
|
|
245
254
|
typeof record.text === 'string' &&
|
|
246
255
|
(record.label === undefined || typeof record.label === 'string') &&
|
|
256
|
+
(record.comment === undefined || typeof record.comment === 'string') &&
|
|
247
257
|
(record.sourceTurnId === undefined || typeof record.sourceTurnId === 'string') &&
|
|
248
258
|
(!hasSourceMetadata ||
|
|
249
259
|
(typeof record.sourceSessionId === 'string' &&
|
|
@@ -386,6 +396,7 @@ function inlineReferencesEqual(left, right) {
|
|
|
386
396
|
function quoteRefsEqual(left, right) {
|
|
387
397
|
return (left.text === right.text &&
|
|
388
398
|
left.label === right.label &&
|
|
399
|
+
left.comment === right.comment &&
|
|
389
400
|
left.sourceTurnId === right.sourceTurnId &&
|
|
390
401
|
left.sourceSessionId === right.sourceSessionId &&
|
|
391
402
|
left.sourceSessionName === right.sourceSessionName &&
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
/** Shared by request previews, connection probes and SDK base URL resolution. */
|
|
20
|
+
export function openAiChatBaseUrl(baseUrl) {
|
|
21
|
+
return openAiBaseUrl(baseUrl);
|
|
22
|
+
}
|
|
23
|
+
export function openAiChatUrl(baseUrl) {
|
|
24
|
+
return openAiRequestUrl(baseUrl, '/chat/completions');
|
|
25
|
+
}
|
|
26
|
+
export function openAiResponsesBaseUrl(baseUrl) {
|
|
27
|
+
return openAiBaseUrl(baseUrl);
|
|
28
|
+
}
|
|
29
|
+
export function openResponsesUrl(baseUrl) {
|
|
30
|
+
return openAiRequestUrl(baseUrl, '/responses');
|
|
31
|
+
}
|
|
32
|
+
export function openAiBaseUrl(baseUrl) {
|
|
33
|
+
const url = new URL(baseUrl);
|
|
34
|
+
let path = url.pathname.replace(/\/+$/, '');
|
|
35
|
+
// Accept both a base and a full endpoint, including previously duplicated
|
|
36
|
+
// suffixes. Models on one connection may use either OpenAI protocol.
|
|
37
|
+
// Preserve the gateway's prefix; never assume or insert /v1.
|
|
38
|
+
// A terminal OpenAI endpoint is always treated as an endpoint: a gateway
|
|
39
|
+
// mounted at that exact path cannot be distinguished from a full request URL.
|
|
40
|
+
const endpoint = /\/(?:chat\/completions|responses)$/i;
|
|
41
|
+
while (endpoint.test(path)) {
|
|
42
|
+
path = path.replace(endpoint, '').replace(/\/+$/, '');
|
|
43
|
+
}
|
|
44
|
+
url.pathname = path;
|
|
45
|
+
return url.toString();
|
|
46
|
+
}
|
|
47
|
+
function openAiRequestUrl(baseUrl, endpoint) {
|
|
48
|
+
const url = new URL(openAiBaseUrl(baseUrl));
|
|
49
|
+
url.pathname = `${url.pathname.replace(/\/+$/, '')}${endpoint}`;
|
|
50
|
+
return url.toString();
|
|
51
|
+
}
|
|
@@ -671,7 +671,7 @@ const providerRegistry = {
|
|
|
671
671
|
label: 'MiniMax',
|
|
672
672
|
baseUrl: 'https://api.minimax.io/anthropic/v1',
|
|
673
673
|
authKind: 'api_key',
|
|
674
|
-
fallbackModels: ['MiniMax-M3'],
|
|
674
|
+
fallbackModels: ['MiniMax-M3', 'MiniMax-M2.7'],
|
|
675
675
|
status: 'ready',
|
|
676
676
|
runtimeAdapter: { kind: 'anthropic', auth: 'bearer', normalizeBaseUrl: false },
|
|
677
677
|
modelDiscovery: { kind: 'protocol' },
|
|
@@ -684,7 +684,7 @@ const providerRegistry = {
|
|
|
684
684
|
label: 'MiniMax 中国站',
|
|
685
685
|
baseUrl: 'https://api.minimaxi.com/anthropic/v1',
|
|
686
686
|
authKind: 'api_key',
|
|
687
|
-
fallbackModels: ['MiniMax-M3'],
|
|
687
|
+
fallbackModels: ['MiniMax-M3', 'MiniMax-M2.7'],
|
|
688
688
|
status: 'ready',
|
|
689
689
|
runtimeAdapter: { kind: 'anthropic', auth: 'bearer', normalizeBaseUrl: false },
|
|
690
690
|
modelDiscovery: { kind: 'protocol' },
|
|
@@ -1438,5 +1438,14 @@ export function providerMenuLabel(providerType) {
|
|
|
1438
1438
|
export function isRetiredProvider(providerType) {
|
|
1439
1439
|
return providerDefaultsOf(providerType)?.retired === true;
|
|
1440
1440
|
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Whether a request on this provider may carry an output-token limit. The
|
|
1443
|
+
* ChatGPT Codex backend answers `max_output_tokens` with HTTP 400
|
|
1444
|
+
* "Unsupported parameter", so no limit can be honoured there: Runtime must not
|
|
1445
|
+
* send one, and settings must not offer one.
|
|
1446
|
+
*/
|
|
1447
|
+
export function providerAcceptsOutputTokenLimit(providerType) {
|
|
1448
|
+
return providerDefaultsOf(providerType)?.runtimeAdapter.kind !== 'openai-codex';
|
|
1449
|
+
}
|
|
1441
1450
|
export const CATALOG_PROVIDER_TYPES = providerTypesByOrder('catalogOrder');
|
|
1442
1451
|
export const RECOMMENDED_PROVIDER_TYPES = providerTypesByOrder('recommendedOrder');
|
|
@@ -47,14 +47,6 @@ const JUST_NOW = {
|
|
|
47
47
|
'zh-TW': '剛剛',
|
|
48
48
|
en: 'just now',
|
|
49
49
|
};
|
|
50
|
-
// The sidebar column is sized to the scan tokens ("59min"); the spelled-out
|
|
51
|
-
// "just now" is wider than any of them, so the slot gets its own compact en
|
|
52
|
-
// label.
|
|
53
|
-
const SIDEBAR_JUST_NOW = {
|
|
54
|
-
'zh-CN': '刚刚',
|
|
55
|
-
'zh-TW': '剛剛',
|
|
56
|
-
en: 'now',
|
|
57
|
-
};
|
|
58
50
|
/** Future timestamps are treated as age zero and therefore display as just now. */
|
|
59
51
|
function relativeAgeMs(ts, now) {
|
|
60
52
|
return Math.max(0, now - ts);
|
|
@@ -162,7 +154,7 @@ export function formatCompactTimestamp(ts, now, locale) {
|
|
|
162
154
|
export function formatSidebarTimestamp(ts, now, locale) {
|
|
163
155
|
const diffMs = relativeAgeMs(ts, now);
|
|
164
156
|
if (diffMs < JUST_NOW_MS)
|
|
165
|
-
return
|
|
157
|
+
return JUST_NOW[locale];
|
|
166
158
|
const bucket = sidebarTimeBucket(diffMs);
|
|
167
159
|
return `${bucket.value}${bucket.suffix}`;
|
|
168
160
|
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { defineObjectShape, hasExactShape, isRecord } from './record-schema.js';
|
|
20
20
|
const SCHEDULED_TASK_ORIGIN_SHAPE = defineObjectShape()(['kind', 'scheduledTaskId'], []);
|
|
21
|
+
const CLOUD_ACTIVATION_ORIGIN_SHAPE = defineObjectShape()(['kind', 'activationId'], []);
|
|
21
22
|
const LEGACY_AUTOMATION_ORIGIN_SHAPE = defineObjectShape()(['kind', 'automationId'], []);
|
|
22
23
|
const GOAL_ORIGIN_SHAPE = defineObjectShape()(['kind', 'goalId'], []);
|
|
23
24
|
const AGENT_GRAPH_ORIGIN_SHAPE = defineObjectShape()(['kind', 'graphId', 'wakeId', 'attemptId'], []);
|
|
@@ -44,6 +45,11 @@ export function decodeTurnOrigin(value) {
|
|
|
44
45
|
typeof value.scheduledTaskId === 'string') {
|
|
45
46
|
return { kind: 'scheduled_task', scheduledTaskId: value.scheduledTaskId };
|
|
46
47
|
}
|
|
48
|
+
if (hasExactShape(value, CLOUD_ACTIVATION_ORIGIN_SHAPE) &&
|
|
49
|
+
value.kind === 'cloud_activation' &&
|
|
50
|
+
typeof value.activationId === 'string') {
|
|
51
|
+
return { kind: 'cloud_activation', activationId: value.activationId };
|
|
52
|
+
}
|
|
47
53
|
if (hasExactShape(value, LEGACY_AUTOMATION_ORIGIN_SHAPE) &&
|
|
48
54
|
(value.kind === 'automation' || value.kind === 'legacy_automation') &&
|
|
49
55
|
typeof value.automationId === 'string') {
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"./incognito": "./dist/incognito.js",
|
|
95
95
|
"./backend-types": "./dist/backend-types.js",
|
|
96
96
|
"./codex-model-compatibility": "./dist/codex-model-compatibility.js",
|
|
97
|
+
"./openai-urls": "./dist/openai-urls.js",
|
|
97
98
|
"./llm-connections": "./dist/llm-connections.js",
|
|
98
99
|
"./provider-registry": "./dist/provider-registry.js",
|
|
99
100
|
"./model-catalog": "./dist/model-catalog.js",
|
|
@@ -21,9 +21,8 @@ import { buildContextBudgetDiagnosticShell, mergeContextBudgetDiagnostic, mergeC
|
|
|
21
21
|
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
|
-
import { createHash } from 'node:crypto';
|
|
25
24
|
import { archiveToolResultAsTransition, collectToolResultArchiveCandidates, serializedToolResultProjection, } from './tool-result-archive-transition.js';
|
|
26
|
-
import { estimateTokens } from './context-budget-helpers.js';
|
|
25
|
+
import { estimateTokens, sha256 } from './context-budget-helpers.js';
|
|
27
26
|
import { reduceEffectiveModelProjections, } from './model-projection-transition-ledger.js';
|
|
28
27
|
import { buildRuntimeEventModelReplayPlan, collectToolActivityTurnIds, compatibleProviderReasoningReplayEventIds, } from './model-history.js';
|
|
29
28
|
import { planHistoryCompaction } from './history-compaction.js';
|
|
@@ -969,9 +968,6 @@ function projectAcceptedMidTurnCompactionMessages(incomingMessages, acceptedProj
|
|
|
969
968
|
...incomingMessages.slice(acceptedProjection.sourceSignatures.length),
|
|
970
969
|
];
|
|
971
970
|
}
|
|
972
|
-
function sha256(text) {
|
|
973
|
-
return createHash('sha256').update(text).digest('hex');
|
|
974
|
-
}
|
|
975
971
|
function modelMessageSignature(message) {
|
|
976
972
|
return sha256(stableStringifyForSignature(message));
|
|
977
973
|
}
|
|
@@ -38,7 +38,7 @@ import { hasBlockingReplayDiagnostics } from './ai-sdk-compaction.js';
|
|
|
38
38
|
import { portableApplyPatchTool } from './apply-patch-profile.js';
|
|
39
39
|
import { RunTrace } from './run-trace.js';
|
|
40
40
|
import { REQUEST_SANDBOX_BOUNDARY_TOOL_NAME, SANDBOX_BOUNDARY_DENIED_FOR_TURN, SANDBOX_BOUNDARY_FINALIZATION_PROMPT, } from './sandbox-boundary-tool.js';
|
|
41
|
-
import { buildRuntimeEventModelReplayPlan, buildSteeringEnvelope, collectToolActivityTurnIds, compatibleProviderReasoningReplayEventIds, formatTextWithInlineRefs, steeringMessagesMissingFromBase, steeringModelMessage, } from './model-history.js';
|
|
41
|
+
import { buildRuntimeEventModelReplayPlan, appendPriorUnknownToolResponses, buildSteeringEnvelope, collectToolActivityTurnIds, compatibleProviderReasoningReplayEventIds, formatTextWithInlineRefs, inspectPriorUnknownToolOutcomes, steeringMessagesMissingFromBase, steeringModelMessage, } from './model-history.js';
|
|
42
42
|
import { toolSchemaCharsForDiagnostics, requestCompositionToolSchemas, stableHash, toolCatalogHash, } from './request-shape.js';
|
|
43
43
|
import { toolAvailabilityHash } from './tool-availability.js';
|
|
44
44
|
import { hasFinalizedReasoning } from './ai-sdk-message-projection.js';
|
|
@@ -401,11 +401,13 @@ export class AiSdkTurn {
|
|
|
401
401
|
runId;
|
|
402
402
|
orchestration;
|
|
403
403
|
toolRuntime;
|
|
404
|
+
startedAt;
|
|
404
405
|
constructor(deps, request) {
|
|
405
406
|
this.deps = deps;
|
|
406
407
|
this.request = request;
|
|
407
408
|
this.turnId = request.turnId;
|
|
408
409
|
this.runId = request.runId;
|
|
410
|
+
this.startedAt = deps.now();
|
|
409
411
|
this.orchestration =
|
|
410
412
|
request.orchestration ??
|
|
411
413
|
resolveEffectiveOrchestration(deps.backend.header.orchestrationMode, undefined);
|
|
@@ -582,7 +584,24 @@ export class AiSdkTurn {
|
|
|
582
584
|
const maxSteps = input.maxSteps === null ? undefined : (input.maxSteps ?? this.deps.maxSteps);
|
|
583
585
|
const toolRuntime = this.toolRuntime;
|
|
584
586
|
const turnAbortController = this.abortController;
|
|
585
|
-
const
|
|
587
|
+
const priorEvents = (input.runtimeContext ?? []).filter((event) => input.continuation !== undefined || event.turnId !== input.turnId);
|
|
588
|
+
const observedPriorUnknownProjection = !input.continuation
|
|
589
|
+
? inspectPriorUnknownToolOutcomes(priorEvents, input.runtimeContextInvocations)
|
|
590
|
+
: { kind: 'none' };
|
|
591
|
+
if (observedPriorUnknownProjection.kind === 'blocked') {
|
|
592
|
+
throw new Error(`Cannot use prior tool history: ${observedPriorUnknownProjection.reason}`);
|
|
593
|
+
}
|
|
594
|
+
if (observedPriorUnknownProjection.kind === 'projected' &&
|
|
595
|
+
!input.allowPriorUnknownToolOutcomes) {
|
|
596
|
+
throw new Error('Cannot continue an automated turn while a prior tool outcome is unknown; an explicit user message is required');
|
|
597
|
+
}
|
|
598
|
+
const priorUnknownProjection = input.allowPriorUnknownToolOutcomes
|
|
599
|
+
? observedPriorUnknownProjection
|
|
600
|
+
: { kind: 'none' };
|
|
601
|
+
const preservingUnknownHistory = priorUnknownProjection.kind === 'projected';
|
|
602
|
+
const midTurnState = preservingUnknownHistory
|
|
603
|
+
? undefined
|
|
604
|
+
: this.deps.compaction.buildMidTurnCapacityCompactState(input);
|
|
586
605
|
const queue = new AsyncEventQueue();
|
|
587
606
|
const codeModeExecTool = this.createCodeModeExecTool(queue);
|
|
588
607
|
// One AssistantMessage is flushed per provider step (not per turn), so the
|
|
@@ -842,7 +861,7 @@ export class AiSdkTurn {
|
|
|
842
861
|
let resolvedSystemPrompt = { sourceRevisions: [] };
|
|
843
862
|
let systemPrompt;
|
|
844
863
|
// --- Build messages from RuntimeEvent history and its compatibility projection. ---
|
|
845
|
-
const priorReplayResult = await this.buildPriorMessages(input);
|
|
864
|
+
const priorReplayResult = await this.buildPriorMessages(input, priorUnknownProjection);
|
|
846
865
|
if (this.aborted) {
|
|
847
866
|
queue.push({
|
|
848
867
|
type: 'abort',
|
|
@@ -973,6 +992,10 @@ export class AiSdkTurn {
|
|
|
973
992
|
};
|
|
974
993
|
const loadDurableTurnProjection = async () => {
|
|
975
994
|
const turnEvents = await loadDurableTurnEvents();
|
|
995
|
+
// Prior unknown call/result pairs are outside this current-turn event
|
|
996
|
+
// set and are preserved separately in priorReplay. Continue pruning
|
|
997
|
+
// new tool results from this turn so one unknown predecessor does not
|
|
998
|
+
// make an unrelated large result permanently unprunable.
|
|
976
999
|
const pruned = await this.deps.compaction.pruneToolResults(turnEvents, turnId);
|
|
977
1000
|
if (pruned.stats) {
|
|
978
1001
|
contextBudgetForTelemetry = addToolResultPruneStats(contextBudgetForTelemetry ?? minimalContextBudgetDiagnostic(), pruned.stats);
|
|
@@ -1104,6 +1127,9 @@ export class AiSdkTurn {
|
|
|
1104
1127
|
}
|
|
1105
1128
|
const requestSystemPromptBase = joinPromptFragments([
|
|
1106
1129
|
systemPrompt,
|
|
1130
|
+
priorUnknownProjection.kind === 'projected'
|
|
1131
|
+
? priorUnknownProjection.systemNotice
|
|
1132
|
+
: undefined,
|
|
1107
1133
|
finalChildSummaryStep ? CHILD_STEP_BUDGET_FINALIZATION_PROMPT : undefined,
|
|
1108
1134
|
toolRuntime.hasSandboxBoundaryDenial() ? SANDBOX_BOUNDARY_DENIED_FOR_TURN : undefined,
|
|
1109
1135
|
sandboxBoundaryFinalizationStep ? SANDBOX_BOUNDARY_FINALIZATION_PROMPT : undefined,
|
|
@@ -1127,19 +1153,16 @@ export class AiSdkTurn {
|
|
|
1127
1153
|
};
|
|
1128
1154
|
};
|
|
1129
1155
|
const dynamicContextMessages = (resolvedSystemPrompt.contexts ?? []).map(({ text }) => ({ role: 'user', content: text }));
|
|
1130
|
-
const contextualRequestMessages = dynamicContextMessages.length === 0
|
|
1131
|
-
? requestMessages
|
|
1132
|
-
: [...requestMessages, ...dynamicContextMessages];
|
|
1133
1156
|
const shaped = requestProjection
|
|
1134
1157
|
? await requestProjection({
|
|
1135
1158
|
completedSteps: completedProviderSteps,
|
|
1136
1159
|
stepNumber: runtimeSteps,
|
|
1137
1160
|
model,
|
|
1138
|
-
messages:
|
|
1161
|
+
messages: requestMessages,
|
|
1139
1162
|
resolveDispatch,
|
|
1140
1163
|
})
|
|
1141
1164
|
: undefined;
|
|
1142
|
-
const projectedMessages = shaped?.messages ??
|
|
1165
|
+
const projectedMessages = shaped?.messages ?? requestMessages;
|
|
1143
1166
|
const activeToolsForRequest = resolveDispatch(shaped?.activeTools).activeTools;
|
|
1144
1167
|
const requestSystemPrompt = joinPromptFragments([
|
|
1145
1168
|
requestSystemPromptBase,
|
|
@@ -1184,9 +1207,11 @@ export class AiSdkTurn {
|
|
|
1184
1207
|
let attemptSawReplayBarrier = false;
|
|
1185
1208
|
const attemptHasNoObservableOutput = () => !attemptSawVisibleContent && !attemptSawToolActivity && !attemptSawReplayBarrier;
|
|
1186
1209
|
const attemptCanReplay = () => !attemptSawToolActivity && !attemptSawReplayBarrier;
|
|
1187
|
-
|
|
1210
|
+
// Request-only facts must survive history replacement and overflow recovery.
|
|
1211
|
+
const dispatchMessages = [...attemptMessages, ...dynamicContextMessages];
|
|
1212
|
+
this.memorySourceMessages = dispatchMessages;
|
|
1188
1213
|
this.memorySourceEventMessagePositions =
|
|
1189
|
-
this.deps.messageProjection.memoryEventMessagePositions(
|
|
1214
|
+
this.deps.messageProjection.memoryEventMessagePositions(dispatchMessages);
|
|
1190
1215
|
this.memorySourceSystemPrompt = requestSystemPrompt;
|
|
1191
1216
|
this.memorySourceTools = modelTools;
|
|
1192
1217
|
this.memorySourceActiveTools = [...activeToolsForRequest];
|
|
@@ -1208,7 +1233,7 @@ export class AiSdkTurn {
|
|
|
1208
1233
|
const historyCompactBoundary = requestHistoryCompactBoundary();
|
|
1209
1234
|
result = await this.deps.modelAdapter.startStream({
|
|
1210
1235
|
model,
|
|
1211
|
-
messages:
|
|
1236
|
+
messages: dispatchMessages,
|
|
1212
1237
|
tools: modelTools,
|
|
1213
1238
|
activeTools: activeToolsForRequest,
|
|
1214
1239
|
onStreamActivity: () => requestWatchdog?.markActivity(),
|
|
@@ -1541,7 +1566,8 @@ export class AiSdkTurn {
|
|
|
1541
1566
|
// more step; with the send-level budget already spent there is
|
|
1542
1567
|
// nothing left to grant it, so the error is terminal.
|
|
1543
1568
|
const stepBudgetRemains = maxSteps === undefined || runtimeSteps < maxSteps;
|
|
1544
|
-
const recovered =
|
|
1569
|
+
const recovered = !preservingUnknownHistory &&
|
|
1570
|
+
stepBudgetRemains &&
|
|
1545
1571
|
failure.kind === 'context_overflow' &&
|
|
1546
1572
|
providerAttempt < MAX_PROVIDER_ATTEMPTS_PER_STEP &&
|
|
1547
1573
|
attemptHasNoObservableOutput()
|
|
@@ -2217,7 +2243,7 @@ export class AiSdkTurn {
|
|
|
2217
2243
|
return this.deps.modelAdapter.makeErrorEvent(turnId, err, reasonOverride);
|
|
2218
2244
|
}
|
|
2219
2245
|
/** Materialize canonical RuntimeEvent history into ai-sdk's message format. */
|
|
2220
|
-
async buildPriorMessages(input) {
|
|
2246
|
+
async buildPriorMessages(input, priorUnknownProjection) {
|
|
2221
2247
|
if (!input.runtimeContext) {
|
|
2222
2248
|
return {
|
|
2223
2249
|
status: 'ready',
|
|
@@ -2235,26 +2261,57 @@ export class AiSdkTurn {
|
|
|
2235
2261
|
// the durable projection-transition reducer (#4283). Replay, budgeting and
|
|
2236
2262
|
// compaction share one input, so no RuntimeEvent replay path can resurrect
|
|
2237
2263
|
// content a committed transition removed.
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
let contextBudget
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2264
|
+
const preservingUnknownHistory = priorUnknownProjection.kind === 'projected';
|
|
2265
|
+
let priorRuntimeContext;
|
|
2266
|
+
let runtimeContext;
|
|
2267
|
+
let contextBudget;
|
|
2268
|
+
let contextBudgetDiagnostic;
|
|
2269
|
+
let projectedHistoryCompactCheckpoint;
|
|
2270
|
+
if (priorUnknownProjection.kind === 'projected') {
|
|
2271
|
+
const preparedContextBudget = await this.deps.compaction.prepareContextBudgetPolicy(rawPriorRuntimeContext, input.turnId);
|
|
2272
|
+
priorRuntimeContext = preparedContextBudget.events;
|
|
2273
|
+
contextBudget = preparedContextBudget.policy;
|
|
2274
|
+
const budgeted = applyRuntimeEventContextBudget(rawPriorRuntimeContext, contextBudget);
|
|
2275
|
+
const budgetedEvents = budgeted?.events ?? rawPriorRuntimeContext;
|
|
2276
|
+
const preservesUnknownCalls = priorUnknownProjection.outcomes.every((outcome) => budgetedEvents.some((event) => event.id === outcome.callEventId));
|
|
2277
|
+
// Existing checkpoints and durable result pruning are safe when they
|
|
2278
|
+
// leave every unknown call available to pair with its temporary result.
|
|
2279
|
+
// Otherwise replay the full effective ledger: a summary that erases T1
|
|
2280
|
+
// would make the request-local T2 orphaned or hide the uncertainty.
|
|
2281
|
+
const selectedEvents = preservesUnknownCalls ? budgetedEvents : rawPriorRuntimeContext;
|
|
2282
|
+
const effectiveEvents = await this.deps.compaction.foldEffectiveModelHistory(selectedEvents, preparedContextBudget.projectionSnapshot);
|
|
2283
|
+
runtimeContext = appendPriorUnknownToolResponses(effectiveEvents, priorUnknownProjection);
|
|
2284
|
+
if (preservesUnknownCalls) {
|
|
2285
|
+
contextBudgetDiagnostic = budgeted?.diagnostic;
|
|
2286
|
+
projectedHistoryCompactCheckpoint = budgeted?.historyCompactCheckpoint;
|
|
2287
|
+
}
|
|
2288
|
+
if (preparedContextBudget.diagnosticPatch) {
|
|
2289
|
+
contextBudgetDiagnostic = mergeContextBudgetDiagnostic(contextBudgetDiagnostic ??
|
|
2290
|
+
buildContextBudgetDiagnosticShell(priorRuntimeContext, effectiveEvents, contextBudget), preparedContextBudget.diagnosticPatch);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
else {
|
|
2294
|
+
const preparedContextBudget = await this.deps.compaction.prepareContextBudgetPolicy(rawPriorRuntimeContext, input.turnId);
|
|
2295
|
+
priorRuntimeContext = preparedContextBudget.events;
|
|
2296
|
+
contextBudget = preparedContextBudget.policy;
|
|
2297
|
+
// Match the durable checkpoint against the RAW ledger prefix: every
|
|
2298
|
+
// creation path (standalone compactHistory and the mid-turn state) pins
|
|
2299
|
+
// its coverage digest on raw events, so matching the folded view here
|
|
2300
|
+
// lets any durable projection transition inside the covered prefix orphan
|
|
2301
|
+
// the checkpoint and silently fail open into a full-history replay
|
|
2302
|
+
// (#4842). The projected [block, tail] is then folded through the
|
|
2303
|
+
// transition reducer before it becomes messages, so a committed
|
|
2304
|
+
// transition still cannot resurrect content for the model (#4283).
|
|
2305
|
+
const budgeted = applyRuntimeEventContextBudget(rawPriorRuntimeContext, contextBudget);
|
|
2306
|
+
runtimeContext = await this.deps.compaction.foldEffectiveModelHistory(budgeted?.events ?? rawPriorRuntimeContext, preparedContextBudget.projectionSnapshot);
|
|
2307
|
+
contextBudgetDiagnostic = budgeted?.diagnostic;
|
|
2308
|
+
projectedHistoryCompactCheckpoint = budgeted?.historyCompactCheckpoint;
|
|
2309
|
+
if (preparedContextBudget.diagnosticPatch) {
|
|
2310
|
+
contextBudgetDiagnostic = mergeContextBudgetDiagnostic(contextBudgetDiagnostic ??
|
|
2311
|
+
buildContextBudgetDiagnosticShell(priorRuntimeContext, runtimeContext, contextBudget), preparedContextBudget.diagnosticPatch);
|
|
2312
|
+
}
|
|
2257
2313
|
}
|
|
2314
|
+
const providerReasoningReplayEventIds = compatibleProviderReasoningReplayEventIds(priorRuntimeContext, input.runtimeContextInvocations, this.deps.backend.providerStateIdentity, this.deps.backend.modelId);
|
|
2258
2315
|
// No pre-turn estimate gate: the turn's first request is judged by the
|
|
2259
2316
|
// request-projection hook from the previous request's real usage, and by
|
|
2260
2317
|
// the provider when it goes out (#4559).
|
|
@@ -2349,6 +2406,7 @@ export class AiSdkTurn {
|
|
|
2349
2406
|
sessionId: this.deps.backend.sessionId,
|
|
2350
2407
|
turnId,
|
|
2351
2408
|
cwd: this.deps.backend.header.cwd,
|
|
2409
|
+
turnStartedAt: this.startedAt,
|
|
2352
2410
|
emitSkillCatalogTrace: (message, data) => this.runTrace?.emit('skill', 'skill_catalog_built', message, data),
|
|
2353
2411
|
});
|
|
2354
2412
|
return typeof resolved === 'string' || resolved === undefined
|
|
@@ -25,14 +25,14 @@ const DEFAULT_TIMEOUT_MS = 15_000;
|
|
|
25
25
|
export async function proxiedFetch(input, init = {}) {
|
|
26
26
|
const url = typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url;
|
|
27
27
|
const proxy = resolveActiveProxy();
|
|
28
|
+
const { timeoutMs = DEFAULT_TIMEOUT_MS, signal, ...fetchInit } = init;
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const requestSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
|
|
28
31
|
let dispatcher;
|
|
29
32
|
if (proxy && !matchesBypassList(new URL(url).hostname, proxy.bypassList)) {
|
|
30
|
-
dispatcher = buildProxyDispatcher(proxy);
|
|
33
|
+
dispatcher = buildProxyDispatcher(proxy, requestSignal);
|
|
31
34
|
}
|
|
32
|
-
const { timeoutMs = DEFAULT_TIMEOUT_MS, signal, ...fetchInit } = init;
|
|
33
35
|
const timeoutEnabled = timeoutMs > 0;
|
|
34
|
-
const controller = new AbortController();
|
|
35
|
-
const requestSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
|
|
36
36
|
let timedOut = false;
|
|
37
37
|
const disposeDispatcher = async (force = false) => {
|
|
38
38
|
const disposable = dispatcher;
|
|
@@ -70,6 +70,7 @@ export async function proxiedFetch(input, init = {}) {
|
|
|
70
70
|
catch (error) {
|
|
71
71
|
if (timer)
|
|
72
72
|
clearTimeout(timer);
|
|
73
|
+
controller.abort(error);
|
|
73
74
|
await disposeDispatcher(timedOut);
|
|
74
75
|
throw error;
|
|
75
76
|
}
|
|
@@ -382,7 +382,7 @@ export function buildBuiltinTools(options = {}) {
|
|
|
382
382
|
{
|
|
383
383
|
name: 'Glob',
|
|
384
384
|
activityKind: 'search',
|
|
385
|
-
description: 'Find file and directory paths matching a glob pattern. Case sensitivity follows platform defaults. Hidden entries require an explicit dot-prefixed pattern component. Returns at most 200 matches in traversal order, without sorting.',
|
|
385
|
+
description: 'Find file and directory paths matching a glob pattern. Case sensitivity follows platform defaults. Hidden entries require an explicit dot-prefixed pattern component. Returns at most 200 matches in traversal order, without sorting. `truncated` is true when more matches exist or an error prevents confirming whether more matches exist after the limit.',
|
|
386
386
|
parameters: z.object({
|
|
387
387
|
pattern: z
|
|
388
388
|
.string()
|
|
@@ -400,7 +400,7 @@ export function buildBuiltinTools(options = {}) {
|
|
|
400
400
|
});
|
|
401
401
|
if (result.kind !== 'glob')
|
|
402
402
|
throw internalFilesystemReadFailure('Glob', 'no file list came back', 'no files match the pattern');
|
|
403
|
-
return { files: result.files };
|
|
403
|
+
return { files: result.files, truncated: result.truncated };
|
|
404
404
|
},
|
|
405
405
|
},
|
|
406
406
|
{
|