maka-agent 0.2.0-dev.6.20260830 → 0.2.0-dev.9.20260831
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/cli-core.js +11 -0
- package/dist/runtime-host-cli.js +44 -0
- package/dist/runtime-host-installed-update-activator.js +70 -33
- package/dist/runtime-host-installed-update-coordinator.js +11 -96
- package/dist/runtime-host-lifecycle-transaction.js +2 -0
- package/dist/runtime-host-local-handoff.js +169 -38
- package/dist/runtime-host-local-source-retirement.js +103 -0
- package/dist/runtime-host-local-target-activation.js +141 -0
- package/dist/runtime-host-peer-management-command.js +10 -4
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
- package/node_modules/@maka/core/dist/agent-run.js +0 -2
- package/node_modules/@maka/core/dist/artifacts.js +23 -15
- package/node_modules/@maka/core/dist/durable-tool-result-projection.js +124 -0
- package/node_modules/@maka/core/dist/foreign-session.js +1 -1
- package/node_modules/@maka/core/dist/llm-connections.js +20 -0
- package/node_modules/@maka/core/dist/runtime-event.js +28 -3
- package/node_modules/@maka/core/dist/session-name.js +0 -1
- package/node_modules/@maka/core/dist/task-ledger.js +6 -134
- package/node_modules/@maka/core/dist/usage-record-schema.js +1 -0
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +97 -133
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +4 -18
- package/node_modules/@maka/runtime/dist/context-budget.js +0 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +67 -0
- package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +390 -0
- package/node_modules/@maka/runtime/dist/model-history.js +12 -39
- package/node_modules/@maka/runtime/dist/plan-mode.js +0 -65
- package/node_modules/@maka/runtime/dist/recovery-resolver.js +18 -14
- package/node_modules/@maka/runtime/dist/run-trace.js +0 -10
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +0 -1
- package/node_modules/@maka/runtime/dist/sandbox/index.js +0 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +0 -12
- package/node_modules/@maka/runtime/dist/sandbox/macos-seatbelt.js +0 -12
- package/node_modules/@maka/runtime/dist/sandbox/sandbox-manager.js +0 -35
- package/node_modules/@maka/runtime/dist/sandbox/windows-sandbox.js +0 -12
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +20 -11
- package/node_modules/@maka/runtime/dist/session-manager.js +0 -170
- package/node_modules/@maka/runtime/dist/shell-detect.js +3 -7
- package/node_modules/@maka/runtime/dist/shell-run-contract.js +0 -1
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +1 -39
- package/node_modules/@maka/runtime/dist/shell-tools.js +1 -1
- package/node_modules/@maka/runtime/dist/task-ledger-tools.js +2 -2
- package/node_modules/@maka/runtime/dist/tool-runtime.js +118 -71
- package/node_modules/@maka/runtime/package.json +1 -1
- package/node_modules/@maka/runtime-host/dist/candidate-entry.js +6 -1
- package/node_modules/@maka/runtime-host/dist/candidate-launch-owner-guard.js +13 -0
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +4 -1
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +27 -1
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +8 -2
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +11 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +394 -113
- package/node_modules/@maka/runtime-host/dist/peer-mesh/store.js +90 -21
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/oauth.js +60 -7
- package/node_modules/@maka/runtime-host/dist/protocol/usage-pricing.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/artifact-coordinator.js +2 -4
- package/node_modules/@maka/runtime-host/dist/server/candidate.js +3 -0
- package/node_modules/@maka/runtime-host/dist/server/client-capability-recovery.js +10 -7
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +6 -9
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +9 -7
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +10 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +2 -58
- package/node_modules/@maka/runtime-host/dist/server/oauth-coordinator.js +91 -42
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +10 -1
- package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +45 -5
- package/node_modules/@maka/storage/dist/artifact-attachments.js +62 -11
- package/node_modules/@maka/storage/dist/artifact-store.js +11 -0
- package/node_modules/@maka/storage/dist/artifact-stores.js +4 -1
- package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1154 -0
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +36 -0
- package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +213 -46
- package/node_modules/@maka/storage/dist/runtime-policy/document-io.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-policy/oauth-login-receipt-document.js +186 -0
- package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +120 -1
- package/node_modules/@maka/storage/dist/runtime-policy-stores.js +2 -1
- package/node_modules/@maka/storage/dist/session-bundle-ustar.js +12 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +5 -0
- package/package.json +1 -1
- package/node_modules/@maka/runtime/dist/sandbox/diagnostics.js +0 -285
- package/node_modules/@maka/runtime/dist/system-prompt/sandbox-context-prompt.js +0 -77
- package/node_modules/@maka/runtime/dist/system-prompt/session-environment-prompt.js +0 -47
|
@@ -0,0 +1,390 @@
|
|
|
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
|
+
import { decodeDurableToolResultProjection, DURABLE_TOOL_RESULT_PROJECTION_FAILURE, DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_DEPTH, DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_NODES, DURABLE_TOOL_RESULT_PROJECTION_MAX_PARTS, DURABLE_TOOL_RESULT_PROJECTION_VERSION, } from '@maka/core/durable-tool-result-projection';
|
|
20
|
+
import { MAX_READ_IMAGE_BYTES } from '@maka/core/attachments';
|
|
21
|
+
import { isCanonicalArtifactEntityId, normalizeArtifactImagePreviewMime, } from '@maka/core/artifacts';
|
|
22
|
+
import { isCanonicalStorageRef } from '@maka/core/events';
|
|
23
|
+
import { decodeCanonicalShellToolResultContent } from '@maka/core/shell-run-result';
|
|
24
|
+
import { markPersisted } from '@maka/core/persisted-value';
|
|
25
|
+
import { decodePersistedToolResultContent } from '@maka/core/tool-result-record-schema';
|
|
26
|
+
import { toolResultOutput } from './tool-result-output.js';
|
|
27
|
+
import { withToolResultArchiveResourceRef } from './tool-result-archive.js';
|
|
28
|
+
import { projectBashToolResultForModel } from './bash-model-output.js';
|
|
29
|
+
import { projectFileWriteToolResultForModel } from './file-tool-model-output.js';
|
|
30
|
+
const OMITTED_BINARY_TEXT = '[Binary tool output omitted from the durable model projection; repeat the tool call if it is still needed.]';
|
|
31
|
+
/**
|
|
32
|
+
* The only new-write codec from Runtime's tool-output contract into the
|
|
33
|
+
* provider-neutral durable projection protocol. It is total by construction:
|
|
34
|
+
* invalid, unsafe, or oversized output becomes one stable failure sentinel.
|
|
35
|
+
*/
|
|
36
|
+
export function encodeDurableToolResultOutput(output, sessionId) {
|
|
37
|
+
try {
|
|
38
|
+
const projection = encodeOutput(output, sessionId);
|
|
39
|
+
return decodeDurableToolResultProjection(projection);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return DURABLE_TOOL_RESULT_PROJECTION_FAILURE;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function encodeDurableToolResultOutputWithArtifacts(output, sessionId, planArtifact) {
|
|
46
|
+
if (!planArtifact || output.type !== 'content' || !hasInlineImage(output)) {
|
|
47
|
+
return encodeDurableToolResultOutput(output, sessionId);
|
|
48
|
+
}
|
|
49
|
+
return (async () => {
|
|
50
|
+
try {
|
|
51
|
+
const prepared = prepareContentProjection(output, sessionId, planArtifact);
|
|
52
|
+
const persisted = new Set();
|
|
53
|
+
for (const artifact of prepared.artifacts) {
|
|
54
|
+
if (persisted.has(artifact.ref.relativePath))
|
|
55
|
+
continue;
|
|
56
|
+
await artifact.persist();
|
|
57
|
+
persisted.add(artifact.ref.relativePath);
|
|
58
|
+
}
|
|
59
|
+
return prepared.projection;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return DURABLE_TOOL_RESULT_PROJECTION_FAILURE;
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
}
|
|
66
|
+
export function encodeDefaultDurableToolResultOutput(result, sessionId) {
|
|
67
|
+
const image = sessionImageResult(result, sessionId);
|
|
68
|
+
if (image) {
|
|
69
|
+
try {
|
|
70
|
+
const mediaType = normalizeArtifactImagePreviewMime(image.mimeType);
|
|
71
|
+
if (!mediaType)
|
|
72
|
+
throw new Error('Image has an unsafe media type');
|
|
73
|
+
return decodeDurableToolResultProjection({
|
|
74
|
+
version: DURABLE_TOOL_RESULT_PROJECTION_VERSION,
|
|
75
|
+
kind: 'content',
|
|
76
|
+
parts: [{ kind: 'artifact', mediaType, ref: image.ref }],
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return DURABLE_TOOL_RESULT_PROJECTION_FAILURE;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return encodeDurableToolResultOutput(typeof result === 'string'
|
|
84
|
+
? { type: 'text', value: result }
|
|
85
|
+
: { type: 'json', value: result }, sessionId);
|
|
86
|
+
}
|
|
87
|
+
export function durableProjectionToToolResultOutput(projection) {
|
|
88
|
+
switch (projection.kind) {
|
|
89
|
+
case 'text':
|
|
90
|
+
return projection.isError
|
|
91
|
+
? { type: 'error-text', value: projection.text }
|
|
92
|
+
: { type: 'text', value: projection.text };
|
|
93
|
+
case 'json':
|
|
94
|
+
return projection.isError
|
|
95
|
+
? { type: 'error-json', value: projection.value }
|
|
96
|
+
: { type: 'json', value: projection.value };
|
|
97
|
+
case 'content':
|
|
98
|
+
return {
|
|
99
|
+
type: 'content',
|
|
100
|
+
value: projection.parts.map((part) => part.kind === 'text'
|
|
101
|
+
? { type: 'text', text: part.text }
|
|
102
|
+
: {
|
|
103
|
+
type: 'text',
|
|
104
|
+
text: `[Artifact ${JSON.stringify(part.ref.kind === 'session_context' ? part.ref.refId : part.ref.relativePath)} (${part.mediaType}) is stored in this Session.]`,
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
case 'execution_denied':
|
|
108
|
+
return {
|
|
109
|
+
type: 'execution-denied',
|
|
110
|
+
...(projection.reason !== undefined ? { reason: projection.reason } : {}),
|
|
111
|
+
};
|
|
112
|
+
case 'failure':
|
|
113
|
+
return { type: 'error-text', value: projection.message };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function rewriteDurableToolResultProjectionArtifactRefs(projection, rewrite) {
|
|
117
|
+
if (projection.kind !== 'content')
|
|
118
|
+
return projection;
|
|
119
|
+
return {
|
|
120
|
+
...projection,
|
|
121
|
+
parts: projection.parts.map((part) => part.kind === 'artifact' ? { ...part, ref: rewrite(part.ref) } : part),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** The single compatibility boundary for both current and legacy response events. */
|
|
125
|
+
export function decodeEffectiveToolResultProjection(content, sessionId) {
|
|
126
|
+
if (content.providerExecuted && content.providerOutput !== undefined) {
|
|
127
|
+
return { kind: 'provider_native', output: content.providerOutput };
|
|
128
|
+
}
|
|
129
|
+
if (content.modelProjection !== undefined) {
|
|
130
|
+
try {
|
|
131
|
+
return {
|
|
132
|
+
kind: 'projection',
|
|
133
|
+
projection: decodeDurableToolResultProjection(content.modelProjection),
|
|
134
|
+
legacyOutput: content.result,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return {
|
|
139
|
+
kind: 'projection',
|
|
140
|
+
projection: DURABLE_TOOL_RESULT_PROJECTION_FAILURE,
|
|
141
|
+
legacyOutput: content.result,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let output = withToolResultArchiveResourceRef(content.result);
|
|
146
|
+
if (isRetiredExploreAgentResult(output)) {
|
|
147
|
+
try {
|
|
148
|
+
output = decodePersistedToolResultContent(markPersisted(output));
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return {
|
|
152
|
+
kind: 'invalid_legacy',
|
|
153
|
+
message: 'function_response contains an invalid retired tool result',
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const shellResult = decodeCanonicalShellToolResultContent(output);
|
|
158
|
+
if (shellResult.state === 'invalid') {
|
|
159
|
+
return {
|
|
160
|
+
kind: 'invalid_legacy',
|
|
161
|
+
message: 'function_response contains an invalid shell tool result',
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (shellResult.state === 'valid')
|
|
165
|
+
output = shellResult.content;
|
|
166
|
+
output =
|
|
167
|
+
content.name === 'Bash'
|
|
168
|
+
? projectBashToolResultForModel(output)
|
|
169
|
+
: projectFileWriteToolResultForModel(content.name, output);
|
|
170
|
+
const projection = content.isError === true
|
|
171
|
+
? encodeDurableToolResultOutput(compatibilityErrorOutput(output), sessionId)
|
|
172
|
+
: encodeDefaultDurableToolResultOutput(output, sessionId);
|
|
173
|
+
if (projection.kind === 'failure' && isLegacyPathImageResult(output, sessionId)) {
|
|
174
|
+
return { kind: 'legacy_output', output };
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
kind: 'projection',
|
|
178
|
+
projection,
|
|
179
|
+
legacyOutput: output,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function compatibilityErrorOutput(output) {
|
|
183
|
+
return output !== null &&
|
|
184
|
+
typeof output === 'object' &&
|
|
185
|
+
!Array.isArray(output) &&
|
|
186
|
+
output.kind === 'text' &&
|
|
187
|
+
typeof output.text === 'string'
|
|
188
|
+
? { type: 'error-text', value: new Error(output.text).toString() }
|
|
189
|
+
: toolResultOutput(output, true);
|
|
190
|
+
}
|
|
191
|
+
export function compatibilityToolResultProjection(content, sessionId) {
|
|
192
|
+
const effective = decodeEffectiveToolResultProjection(content, sessionId);
|
|
193
|
+
if (effective.kind === 'provider_native')
|
|
194
|
+
return undefined;
|
|
195
|
+
if (effective.kind === 'legacy_output')
|
|
196
|
+
return DURABLE_TOOL_RESULT_PROJECTION_FAILURE;
|
|
197
|
+
return effective.kind === 'projection'
|
|
198
|
+
? effective.projection
|
|
199
|
+
: DURABLE_TOOL_RESULT_PROJECTION_FAILURE;
|
|
200
|
+
}
|
|
201
|
+
function encodeOutput(output, sessionId) {
|
|
202
|
+
switch (output.type) {
|
|
203
|
+
case 'text':
|
|
204
|
+
case 'error-text':
|
|
205
|
+
return {
|
|
206
|
+
version: DURABLE_TOOL_RESULT_PROJECTION_VERSION,
|
|
207
|
+
kind: 'text',
|
|
208
|
+
text: output.value,
|
|
209
|
+
...(output.type === 'error-text' ? { isError: true } : {}),
|
|
210
|
+
};
|
|
211
|
+
case 'json':
|
|
212
|
+
case 'error-json':
|
|
213
|
+
return {
|
|
214
|
+
version: DURABLE_TOOL_RESULT_PROJECTION_VERSION,
|
|
215
|
+
kind: 'json',
|
|
216
|
+
value: sanitizeJson(output.value),
|
|
217
|
+
...(output.type === 'error-json' ? { isError: true } : {}),
|
|
218
|
+
};
|
|
219
|
+
case 'execution-denied':
|
|
220
|
+
return {
|
|
221
|
+
version: DURABLE_TOOL_RESULT_PROJECTION_VERSION,
|
|
222
|
+
kind: 'execution_denied',
|
|
223
|
+
...(output.reason !== undefined ? { reason: output.reason } : {}),
|
|
224
|
+
};
|
|
225
|
+
case 'content': {
|
|
226
|
+
return prepareContentProjection(output, sessionId).projection;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function prepareContentProjection(output, sessionId, planArtifact) {
|
|
231
|
+
if (output.value.length > DURABLE_TOOL_RESULT_PROJECTION_MAX_PARTS) {
|
|
232
|
+
throw new Error('Tool Result content exceeds the durable part limit');
|
|
233
|
+
}
|
|
234
|
+
const parts = [];
|
|
235
|
+
const artifacts = [];
|
|
236
|
+
for (const part of output.value) {
|
|
237
|
+
if (part.type === 'text') {
|
|
238
|
+
parts.push({ kind: 'text', text: part.text });
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (part.type !== 'file')
|
|
242
|
+
continue;
|
|
243
|
+
const ref = readSessionArtifactRef(part, sessionId);
|
|
244
|
+
if (ref) {
|
|
245
|
+
const mediaType = normalizeArtifactImagePreviewMime(part.mediaType);
|
|
246
|
+
if (!mediaType)
|
|
247
|
+
throw new Error('Artifact has an unsafe media type');
|
|
248
|
+
parts.push({ kind: 'artifact', mediaType, ref });
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (planArtifact &&
|
|
252
|
+
part.data.type === 'data' &&
|
|
253
|
+
part.mediaType.toLowerCase().startsWith('image/')) {
|
|
254
|
+
const mediaType = normalizeArtifactImagePreviewMime(part.mediaType);
|
|
255
|
+
if (!mediaType)
|
|
256
|
+
throw new Error('Inline image has an unsafe media type');
|
|
257
|
+
const artifact = planArtifact({
|
|
258
|
+
bytes: decodeBoundedImageData(part.data.data),
|
|
259
|
+
mediaType,
|
|
260
|
+
});
|
|
261
|
+
artifacts.push(artifact);
|
|
262
|
+
parts.push({ kind: 'artifact', mediaType, ref: artifact.ref });
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
parts.push({ kind: 'text', text: OMITTED_BINARY_TEXT });
|
|
266
|
+
}
|
|
267
|
+
if (parts.length === 0)
|
|
268
|
+
parts.push({ kind: 'text', text: 'Tool completed with no content.' });
|
|
269
|
+
return {
|
|
270
|
+
projection: decodeDurableToolResultProjection({
|
|
271
|
+
version: DURABLE_TOOL_RESULT_PROJECTION_VERSION,
|
|
272
|
+
kind: 'content',
|
|
273
|
+
parts,
|
|
274
|
+
}),
|
|
275
|
+
artifacts,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function readSessionArtifactRef(part, sessionId) {
|
|
279
|
+
if (part.type !== 'file')
|
|
280
|
+
return undefined;
|
|
281
|
+
const data = part.data;
|
|
282
|
+
if (!data || typeof data !== 'object' || Array.isArray(data))
|
|
283
|
+
return undefined;
|
|
284
|
+
const ref = data.ref;
|
|
285
|
+
return isCanonicalStorageRef(ref) &&
|
|
286
|
+
(ref.kind === 'session_context' || ref.kind === 'session_file') &&
|
|
287
|
+
ref.sessionId === sessionId
|
|
288
|
+
? ref
|
|
289
|
+
: undefined;
|
|
290
|
+
}
|
|
291
|
+
function hasInlineImage(output) {
|
|
292
|
+
return output.value.some((part) => part.type === 'file' &&
|
|
293
|
+
part.data.type === 'data' &&
|
|
294
|
+
part.mediaType.toLowerCase().startsWith('image/'));
|
|
295
|
+
}
|
|
296
|
+
function decodeBoundedImageData(data) {
|
|
297
|
+
let bytes;
|
|
298
|
+
if (typeof data === 'string') {
|
|
299
|
+
if (data.length > Math.ceil((MAX_READ_IMAGE_BYTES * 4) / 3) + 4) {
|
|
300
|
+
throw new Error('Inline image exceeds the artifact byte limit');
|
|
301
|
+
}
|
|
302
|
+
const decoded = Buffer.from(data, 'base64');
|
|
303
|
+
if (decoded.toString('base64') !== data)
|
|
304
|
+
throw new Error('Inline image is not canonical base64');
|
|
305
|
+
bytes = decoded;
|
|
306
|
+
}
|
|
307
|
+
else if (data instanceof ArrayBuffer) {
|
|
308
|
+
if (data.byteLength > MAX_READ_IMAGE_BYTES) {
|
|
309
|
+
throw new Error('Inline image exceeds the artifact byte limit');
|
|
310
|
+
}
|
|
311
|
+
bytes = new Uint8Array(data.slice(0));
|
|
312
|
+
}
|
|
313
|
+
else if (ArrayBuffer.isView(data)) {
|
|
314
|
+
if (data.byteLength > MAX_READ_IMAGE_BYTES) {
|
|
315
|
+
throw new Error('Inline image exceeds the artifact byte limit');
|
|
316
|
+
}
|
|
317
|
+
bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
throw new Error('Inline image data is not representable');
|
|
321
|
+
}
|
|
322
|
+
if (bytes.byteLength > MAX_READ_IMAGE_BYTES) {
|
|
323
|
+
throw new Error('Inline image exceeds the artifact byte limit');
|
|
324
|
+
}
|
|
325
|
+
return bytes;
|
|
326
|
+
}
|
|
327
|
+
function sessionImageResult(result, sessionId) {
|
|
328
|
+
if (!result || typeof result !== 'object' || Array.isArray(result))
|
|
329
|
+
return undefined;
|
|
330
|
+
const image = result;
|
|
331
|
+
return image.kind === 'image' &&
|
|
332
|
+
typeof image.mimeType === 'string' &&
|
|
333
|
+
image.mimeType.length > 0 &&
|
|
334
|
+
isCanonicalStorageRef(image.ref) &&
|
|
335
|
+
(image.ref.kind === 'session_context' || image.ref.kind === 'session_file') &&
|
|
336
|
+
image.ref.sessionId === sessionId
|
|
337
|
+
? { mimeType: image.mimeType, ref: image.ref }
|
|
338
|
+
: undefined;
|
|
339
|
+
}
|
|
340
|
+
function isLegacyPathImageResult(result, sessionId) {
|
|
341
|
+
const image = sessionImageResult(result, sessionId);
|
|
342
|
+
return image?.ref.kind === 'session_file' && !isCanonicalArtifactEntityId(image.ref.relativePath);
|
|
343
|
+
}
|
|
344
|
+
function sanitizeJson(value) {
|
|
345
|
+
const state = { nodes: 0 };
|
|
346
|
+
return sanitizeJsonValue(value, state, 0);
|
|
347
|
+
}
|
|
348
|
+
function sanitizeJsonValue(value, state, depth) {
|
|
349
|
+
state.nodes += 1;
|
|
350
|
+
if (state.nodes > DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_NODES ||
|
|
351
|
+
depth > DURABLE_TOOL_RESULT_PROJECTION_MAX_JSON_DEPTH) {
|
|
352
|
+
throw new Error('JSON exceeds limit');
|
|
353
|
+
}
|
|
354
|
+
if (value === null)
|
|
355
|
+
return null;
|
|
356
|
+
if (typeof value === 'string')
|
|
357
|
+
return value;
|
|
358
|
+
if (typeof value === 'boolean')
|
|
359
|
+
return value;
|
|
360
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
361
|
+
return value;
|
|
362
|
+
if (Array.isArray(value)) {
|
|
363
|
+
return value.map((item) => sanitizeJsonValue(item, state, depth + 1));
|
|
364
|
+
}
|
|
365
|
+
if (!value || typeof value !== 'object')
|
|
366
|
+
throw new Error('JSON is not representable');
|
|
367
|
+
const prototype = Object.getPrototypeOf(value);
|
|
368
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
369
|
+
throw new Error('JSON contains an opaque object');
|
|
370
|
+
}
|
|
371
|
+
if (typeof value.toJSON === 'function') {
|
|
372
|
+
throw new Error('JSON contains an opaque serializer');
|
|
373
|
+
}
|
|
374
|
+
const result = {};
|
|
375
|
+
for (const [key, item] of Object.entries(value)) {
|
|
376
|
+
Object.defineProperty(result, key, {
|
|
377
|
+
enumerable: true,
|
|
378
|
+
configurable: true,
|
|
379
|
+
writable: true,
|
|
380
|
+
value: sanitizeJsonValue(item, state, depth + 1),
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return result;
|
|
384
|
+
}
|
|
385
|
+
function isRetiredExploreAgentResult(value) {
|
|
386
|
+
return (value !== null &&
|
|
387
|
+
typeof value === 'object' &&
|
|
388
|
+
!Array.isArray(value) &&
|
|
389
|
+
value.kind === 'explore_agent');
|
|
390
|
+
}
|
|
@@ -51,13 +51,8 @@
|
|
|
51
51
|
* node re-exports it from the core barrel.
|
|
52
52
|
*/
|
|
53
53
|
import { isPartialRuntimeEvent, isTerminalRuntimeEvent, runtimeEventHasModelVisibleContent, } from '@maka/core/runtime-event';
|
|
54
|
-
import { withToolResultArchiveResourceRef } from './tool-result-archive.js';
|
|
55
54
|
import { formatAttachmentResourceRef } from '@maka/core/attachments';
|
|
56
|
-
import {
|
|
57
|
-
import { markPersisted } from '@maka/core/persisted-value';
|
|
58
|
-
import { decodePersistedToolResultContent } from '@maka/core/tool-result-record-schema';
|
|
59
|
-
import { projectBashToolResultForModel } from './bash-model-output.js';
|
|
60
|
-
import { projectFileWriteToolResultForModel } from './file-tool-model-output.js';
|
|
55
|
+
import { decodeEffectiveToolResultProjection } from './durable-tool-result-projection.js';
|
|
61
56
|
export const PROVIDER_REPLAY_PROJECTION_VERSION = 1;
|
|
62
57
|
// ============================================================================
|
|
63
58
|
// Projection
|
|
@@ -328,35 +323,8 @@ export function buildRuntimeEventModelReplayPlan(events, options = {}) {
|
|
|
328
323
|
}));
|
|
329
324
|
continue;
|
|
330
325
|
}
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
let normalizedResult = usesProviderOutput
|
|
334
|
-
? event.content.providerOutput
|
|
335
|
-
: withToolResultArchiveResourceRef(event.content.result);
|
|
336
|
-
if (!usesProviderOutput && isRetiredExploreAgentResult(normalizedResult)) {
|
|
337
|
-
try {
|
|
338
|
-
normalizedResult = decodePersistedToolResultContent(markPersisted(normalizedResult));
|
|
339
|
-
}
|
|
340
|
-
catch {
|
|
341
|
-
invalidResultMessage = 'function_response contains an invalid retired tool result';
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (!invalidResultMessage) {
|
|
345
|
-
const shellResult = decodeCanonicalShellToolResultContent(normalizedResult);
|
|
346
|
-
if (shellResult.state === 'invalid') {
|
|
347
|
-
invalidResultMessage = 'function_response contains an invalid shell tool result';
|
|
348
|
-
}
|
|
349
|
-
else if (shellResult.state === 'valid') {
|
|
350
|
-
normalizedResult = shellResult.content;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
if (!invalidResultMessage && event.content.name === 'Bash') {
|
|
354
|
-
normalizedResult = projectBashToolResultForModel(normalizedResult);
|
|
355
|
-
}
|
|
356
|
-
else if (!invalidResultMessage) {
|
|
357
|
-
normalizedResult = projectFileWriteToolResultForModel(event.content.name, normalizedResult);
|
|
358
|
-
}
|
|
359
|
-
if (invalidResultMessage) {
|
|
326
|
+
const effective = decodeEffectiveToolResultProjection(event.content, event.sessionId);
|
|
327
|
+
if (effective.kind === 'invalid_legacy') {
|
|
360
328
|
const call = callsById.get(event.content.id);
|
|
361
329
|
if (call) {
|
|
362
330
|
const callIndex = items.indexOf(call.item);
|
|
@@ -364,9 +332,12 @@ export function buildRuntimeEventModelReplayPlan(events, options = {}) {
|
|
|
364
332
|
items.splice(callIndex, 1);
|
|
365
333
|
callsById.delete(event.content.id);
|
|
366
334
|
}
|
|
367
|
-
diagnostics.push(diagnostic(event, 'unsupported_content',
|
|
335
|
+
diagnostics.push(diagnostic(event, 'unsupported_content', effective.message));
|
|
368
336
|
continue;
|
|
369
337
|
}
|
|
338
|
+
const normalizedResult = effective.kind === 'provider_native' || effective.kind === 'legacy_output'
|
|
339
|
+
? effective.output
|
|
340
|
+
: effective.legacyOutput;
|
|
370
341
|
const call = callsById.get(event.content.id);
|
|
371
342
|
if (!call) {
|
|
372
343
|
diagnostics.push(diagnostic(event, 'unmatched_tool_result', 'function_response has no prior matching function_call', {
|
|
@@ -386,6 +357,11 @@ export function buildRuntimeEventModelReplayPlan(events, options = {}) {
|
|
|
386
357
|
toolCallId: event.content.id,
|
|
387
358
|
toolName: event.content.name,
|
|
388
359
|
output: normalizedResult,
|
|
360
|
+
...(effective.kind === 'projection'
|
|
361
|
+
? {
|
|
362
|
+
modelProjection: effective.projection,
|
|
363
|
+
}
|
|
364
|
+
: {}),
|
|
389
365
|
isError: event.content.isError === true,
|
|
390
366
|
...(event.content.providerExecuted !== undefined
|
|
391
367
|
? { providerExecuted: event.content.providerExecuted }
|
|
@@ -437,9 +413,6 @@ export function buildRuntimeEventModelReplayPlan(events, options = {}) {
|
|
|
437
413
|
semanticKinds.includes('tool_result'),
|
|
438
414
|
};
|
|
439
415
|
}
|
|
440
|
-
function isRetiredExploreAgentResult(value) {
|
|
441
|
-
return (typeof value === 'object' && value !== null && 'kind' in value && value.kind === 'explore_agent');
|
|
442
|
-
}
|
|
443
416
|
/**
|
|
444
417
|
* Convert projected RuntimeEvent history into the current AI SDK text-only
|
|
445
418
|
* message shape. Tool/function and thinking entries are intentionally skipped.
|
|
@@ -83,68 +83,3 @@ export function renderPlanModePrompt(input = {}) {
|
|
|
83
83
|
'</collaboration_mode>',
|
|
84
84
|
].join('\n');
|
|
85
85
|
}
|
|
86
|
-
export function renderInterruptedPlanContext(input) {
|
|
87
|
-
const steps = input.execution.steps.map((step) => renderExecutionStep(step)).join('\n');
|
|
88
|
-
return [
|
|
89
|
-
'<interrupted_plan_context>',
|
|
90
|
-
`Plan: ${input.proposal.title}`,
|
|
91
|
-
`Plan ID: ${input.proposal.planId}`,
|
|
92
|
-
`Proposal: ${input.proposal.proposalId} (revision ${input.proposal.revision})`,
|
|
93
|
-
`Interrupted execution ID: ${input.execution.executionId}`,
|
|
94
|
-
input.execution.interruptionReason
|
|
95
|
-
? `Interruption reason: ${input.execution.interruptionReason}`
|
|
96
|
-
: '',
|
|
97
|
-
'Progress at interruption:',
|
|
98
|
-
steps,
|
|
99
|
-
input.fullAccess
|
|
100
|
-
? 'The user entered Plan Mode to replan the remaining work. Do not resume the interrupted execution automatically. Full access remains active; modify files or perform side effects only when the user explicitly requests them during replanning. A submitted proposal will supersede this interrupted execution when approved.'
|
|
101
|
-
: 'The user entered Plan Mode to replan the remaining work. Do not resume execution or modify files. A submitted proposal will supersede this interrupted execution when approved.',
|
|
102
|
-
'</interrupted_plan_context>',
|
|
103
|
-
]
|
|
104
|
-
.filter(Boolean)
|
|
105
|
-
.join('\n');
|
|
106
|
-
}
|
|
107
|
-
export function renderPlanExecutionPrompt(input) {
|
|
108
|
-
const steps = input.execution.steps.map((step) => renderExecutionStep(step)).join('\n');
|
|
109
|
-
return [
|
|
110
|
-
'<plan_execution_context>',
|
|
111
|
-
`Plan: ${input.proposal.title}`,
|
|
112
|
-
`Plan ID: ${input.proposal.planId}`,
|
|
113
|
-
`Proposal: ${input.proposal.proposalId} (revision ${input.proposal.revision})`,
|
|
114
|
-
`Execution ID: ${input.execution.executionId}`,
|
|
115
|
-
input.proposal.overview ? `Overview: ${input.proposal.overview}` : '',
|
|
116
|
-
'Approved steps:',
|
|
117
|
-
steps,
|
|
118
|
-
'Execute this approved plan. Before implementation, call update_plan with the first actionable step in_progress and every other step at its current status. Immediately after finishing a step, call update_plan again to mark it completed and move the next step to in_progress. Before the final response, update every finished or skipped step so the execution can close. If the user explicitly abandons the plan, call cancel_plan. Do not delegate to subagents while this execution is active.',
|
|
119
|
-
'</plan_execution_context>',
|
|
120
|
-
]
|
|
121
|
-
.filter(Boolean)
|
|
122
|
-
.join('\n');
|
|
123
|
-
}
|
|
124
|
-
function statusMark(status) {
|
|
125
|
-
if (status === 'completed')
|
|
126
|
-
return 'x';
|
|
127
|
-
if (status === 'in_progress')
|
|
128
|
-
return '>';
|
|
129
|
-
if (status === 'skipped')
|
|
130
|
-
return '-';
|
|
131
|
-
return ' ';
|
|
132
|
-
}
|
|
133
|
-
function renderExecutionStep(step) {
|
|
134
|
-
return [
|
|
135
|
-
'<step>',
|
|
136
|
-
`<id>${escapeXml(step.id)}</id>`,
|
|
137
|
-
`<title>${escapeXml(step.title)}</title>`,
|
|
138
|
-
`<description>${escapeXml(step.description)}</description>`,
|
|
139
|
-
`<status>${step.status}</status>`,
|
|
140
|
-
'</step>',
|
|
141
|
-
].join('\n');
|
|
142
|
-
}
|
|
143
|
-
function escapeXml(value) {
|
|
144
|
-
return value
|
|
145
|
-
.replaceAll('&', '&')
|
|
146
|
-
.replaceAll('<', '<')
|
|
147
|
-
.replaceAll('>', '>')
|
|
148
|
-
.replaceAll('"', '"')
|
|
149
|
-
.replaceAll("'", ''');
|
|
150
|
-
}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import { TOOL_BOUNDARY_PROTOCOL_V1, } from '@maka/core/runtime-event';
|
|
20
20
|
import { scanToolLedger, } from '@maka/core/tool-ledger-scanner';
|
|
21
21
|
import { interpretScannedToolRecovery } from '@maka/core/tool-recovery-bundle';
|
|
22
|
+
import { compatibilityToolResultProjection } from './durable-tool-result-projection.js';
|
|
22
23
|
export function resolveRuntimeRecovery(events) {
|
|
23
24
|
const firstProtocol = events[0]?.actions?.runtimeProtocol;
|
|
24
25
|
const toolBoundaryProtocol = firstProtocol?.toolBoundary === TOOL_BOUNDARY_PROTOCOL_V1
|
|
@@ -66,6 +67,22 @@ export function buildInterruptedCodeModeOutcomeCommits(events, now, toolMode) {
|
|
|
66
67
|
callEvent.modelVisibility === 'hidden') {
|
|
67
68
|
return [];
|
|
68
69
|
}
|
|
70
|
+
const result = {
|
|
71
|
+
kind: 'json',
|
|
72
|
+
value: {
|
|
73
|
+
kind: 'code_mode',
|
|
74
|
+
status: 'interrupted',
|
|
75
|
+
message: 'Code Mode execution was interrupted by runtime recovery.',
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const responseContent = {
|
|
79
|
+
kind: 'function_response',
|
|
80
|
+
id: call.id,
|
|
81
|
+
name: call.name,
|
|
82
|
+
result,
|
|
83
|
+
isError: true,
|
|
84
|
+
};
|
|
85
|
+
const modelProjection = compatibilityToolResultProjection(responseContent, callEvent.sessionId);
|
|
69
86
|
const runtimeEvent = {
|
|
70
87
|
id: `${decision.operationId}_response`,
|
|
71
88
|
invocationId: callEvent.invocationId,
|
|
@@ -78,20 +95,7 @@ export function buildInterruptedCodeModeOutcomeCommits(events, now, toolMode) {
|
|
|
78
95
|
author: 'tool',
|
|
79
96
|
origin: 'provider',
|
|
80
97
|
modelVisibility: 'visible',
|
|
81
|
-
content: {
|
|
82
|
-
kind: 'function_response',
|
|
83
|
-
id: call.id,
|
|
84
|
-
name: call.name,
|
|
85
|
-
result: {
|
|
86
|
-
kind: 'json',
|
|
87
|
-
value: {
|
|
88
|
-
kind: 'code_mode',
|
|
89
|
-
status: 'interrupted',
|
|
90
|
-
message: 'Code Mode execution was interrupted by runtime recovery.',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
isError: true,
|
|
94
|
-
},
|
|
98
|
+
content: { ...responseContent, ...(modelProjection ? { modelProjection } : {}) },
|
|
95
99
|
refs: { operationId: decision.operationId, toolCallId: call.id },
|
|
96
100
|
};
|
|
97
101
|
return [
|
|
@@ -52,16 +52,6 @@ export class RunTrace {
|
|
|
52
52
|
...extra,
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
sandboxContextResolved(snapshot) {
|
|
56
|
-
this.emit('sandbox', 'sandbox_context_resolved', 'Sandbox context resolved', { snapshot });
|
|
57
|
-
}
|
|
58
|
-
sandboxContextFailed(stage, error) {
|
|
59
|
-
this.emit('sandbox', 'sandbox_context_failed', 'Sandbox context unavailable; continuing without prompt context', {
|
|
60
|
-
stage,
|
|
61
|
-
error: explainError(error),
|
|
62
|
-
...diagnoseError(error),
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
55
|
modelResolved() {
|
|
66
56
|
this.emit('model', 'model_resolved', 'Model resolved', {
|
|
67
57
|
connectionSlug: this.input.connectionSlug,
|
|
@@ -1689,7 +1689,6 @@ export class RuntimeKernel {
|
|
|
1689
1689
|
sessionId,
|
|
1690
1690
|
}),
|
|
1691
1691
|
allowMidTurnHistoryCompaction: Boolean(this.deps.runtimeEventStore),
|
|
1692
|
-
shellRunContextSummary: () => this.deps.shellRuns?.buildContextSummary(sessionId) ?? Promise.resolve(undefined),
|
|
1693
1692
|
});
|
|
1694
1693
|
await this.rejectCancelledBackendActivation(backend, header, execution);
|
|
1695
1694
|
const generation = this.createBackendGeneration(sessionId, backend, header);
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
export { SandboxManager } from './sandbox-manager.js';
|
|
20
|
-
export { createSandboxDiagnosticsProvider, toSandboxRunTraceProjection, } from './diagnostics.js';
|
|
21
20
|
export { SandboxCommandError, sandboxErrorMetadata, serializeSandboxError, } from './errors.js';
|
|
22
21
|
export { createBuiltinSandboxManager, createDefaultSandboxManager, isBuiltinFilesystemWorkerSandboxAvailable, } from './default-sandbox-manager.js';
|
|
23
22
|
export { LinuxBubblewrapBackend, buildBubblewrapArgv, buildNetworkSeccompFilter, discoverNestedProtectedMetadataPaths, } from './linux-sandbox.js';
|
|
@@ -41,18 +41,6 @@ export class LinuxBubblewrapBackend {
|
|
|
41
41
|
canEnforceProfile(profile) {
|
|
42
42
|
return validateLinuxProfile(profile, this.options.arch ?? process.arch).ok;
|
|
43
43
|
}
|
|
44
|
-
probe(request) {
|
|
45
|
-
const plan = this.plan(request);
|
|
46
|
-
if (!plan.ok)
|
|
47
|
-
return plan;
|
|
48
|
-
return {
|
|
49
|
-
ok: true,
|
|
50
|
-
executable: plan.bwrapPath,
|
|
51
|
-
sandboxType: 'linux',
|
|
52
|
-
requiresSandbox: true,
|
|
53
|
-
preference: plan.preference,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
44
|
transform(request) {
|
|
57
45
|
const { command } = request;
|
|
58
46
|
const plan = this.plan(request);
|
|
@@ -219,18 +219,6 @@ export function createSeatbeltExecArgs(input) {
|
|
|
219
219
|
}
|
|
220
220
|
export class MacosSeatbeltBackend {
|
|
221
221
|
type = 'macos-seatbelt';
|
|
222
|
-
probe(request) {
|
|
223
|
-
const transformed = this.transform(request);
|
|
224
|
-
if (!transformed.ok)
|
|
225
|
-
return transformed;
|
|
226
|
-
return {
|
|
227
|
-
ok: true,
|
|
228
|
-
executable: MACOS_SEATBELT_EXECUTABLE,
|
|
229
|
-
sandboxType: transformed.sandboxType,
|
|
230
|
-
requiresSandbox: transformed.requiresSandbox,
|
|
231
|
-
preference: transformed.preference,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
222
|
transform(request) {
|
|
235
223
|
const { command } = request;
|
|
236
224
|
const preference = request.preference ?? 'auto';
|