maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.25.20260908
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -19
- package/README.zh-CN.md +34 -19
- package/dist/acp/maka-acp-agent.js +2 -1
- package/dist/acp/session-configuration.js +143 -0
- package/dist/acp/session-registry.js +90 -4
- package/dist/cli-core.js +2 -0
- package/dist/pi-transcript-tools.js +6 -0
- package/dist/pi-transcript.js +5 -12
- package/dist/pi-tui-layout.js +56 -10
- package/dist/pi-tui-pickers.js +102 -1
- package/dist/pi-tui-runner.js +230 -46
- package/dist/pi-tui-todo.js +221 -0
- package/dist/pi-tui-transcript-viewer.js +134 -7
- package/dist/runtime-host-cli-context.js +224 -78
- package/dist/runtime-host-cli-installation.js +8 -2
- package/dist/runtime-host-cli.js +31 -1
- package/dist/runtime-host-handoff-surface.js +106 -0
- package/dist/runtime-host-installed-update-bootstrap.js +13 -0
- package/dist/runtime-host-installed-update-coordinator.js +33 -0
- package/dist/runtime-host-lifecycle-transaction.js +9 -1
- package/dist/runtime-host-local-handoff.js +48 -5
- package/dist/runtime-host-local-managed-activation.js +84 -0
- package/dist/runtime-host-local-source-retirement.js +18 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-operator-retirement.js +50 -0
- package/dist/runtime-host-service-manager.js +3 -3
- package/dist/runtime-host-session-channel.js +13 -0
- package/dist/runtime-host-session-driver.js +46 -26
- package/dist/runtime-host-session-update.js +62 -0
- package/dist/runtime-host-tui-command.js +38 -73
- package/dist/runtime-host-tui-context.js +1 -0
- package/dist/runtime-host-tui-owner.js +226 -0
- package/dist/tui-copy-catalog.js +219 -6
- package/dist/tui-host-owner-copy.js +24 -0
- 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-run.js +1 -0
- package/node_modules/@maka/core/dist/attachments.js +3 -0
- package/node_modules/@maka/core/dist/canonical-json.js +27 -0
- package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
- package/node_modules/@maka/core/dist/capabilities.js +35 -0
- package/node_modules/@maka/core/dist/computer-use.js +0 -1
- package/node_modules/@maka/core/dist/display-redaction.js +18 -0
- package/node_modules/@maka/core/dist/llm-connections.js +13 -0
- package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
- package/node_modules/@maka/core/dist/model-failure.js +40 -0
- package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
- package/node_modules/@maka/core/dist/model-metadata.js +7 -3
- package/node_modules/@maka/core/dist/model-web-search.js +5 -4
- package/node_modules/@maka/core/dist/provider-registry.js +45 -4
- package/node_modules/@maka/core/dist/record-schema.js +9 -2
- package/node_modules/@maka/core/dist/redaction.js +35 -0
- package/node_modules/@maka/core/dist/run-composition.js +77 -2
- package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
- package/node_modules/@maka/core/dist/runtime-event.js +37 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
- package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
- package/node_modules/@maka/core/dist/session.js +84 -56
- package/node_modules/@maka/core/dist/slash-command-catalog.js +3 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
- package/node_modules/@maka/core/package.json +5 -0
- package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
- package/node_modules/@maka/mcp/dist/index.js +131 -1
- package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
- package/node_modules/@maka/runtime/dist/agent-run.js +351 -105
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +29 -13
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +184 -183
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
- package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
- package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
- package/node_modules/@maka/runtime/dist/conversation-copy.js +158 -15
- package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
- package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
- package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +174 -0
- package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
- package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
- package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
- package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
- package/node_modules/@maka/runtime/dist/model-fetcher.js +49 -2
- package/node_modules/@maka/runtime/dist/model-history.js +0 -112
- package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
- package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
- package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
- package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +76 -109
- package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
- package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +83 -55
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +121 -159
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +157 -112
- package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
- package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
- package/node_modules/@maka/runtime/dist/test-connection.js +16 -17
- package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
- package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
- package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
- package/node_modules/@maka/runtime/package.json +2 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
- package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +179 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +275 -0
- package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
- package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +46 -5
- package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
- package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
- package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
- package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +29 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
- package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
- package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +31 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
- package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +144 -33
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +45 -16
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
- package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +47 -22
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
- 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 +325 -73
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
- package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +12 -55
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +20 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +13 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
- package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
- package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -5
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -198
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
- package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
- package/node_modules/@maka/storage/dist/git-exec.js +61 -0
- package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
- package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
- package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
- package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
- package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
- package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
- package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
- package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
- package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +26 -5
- package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
- package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
- package/node_modules/@maka/storage/dist/session-repository.js +767 -0
- package/node_modules/@maka/storage/dist/session-store.js +25 -99
- package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +130 -27
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
- package/node_modules/@maka/storage/dist/storage-id.js +28 -0
- package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +138 -0
- package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
- package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
- package/node_modules/@maka/storage/package.json +2 -0
- package/package.json +1 -1
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { MODEL_FAILURE_MESSAGE_MAX_BYTES } from '@maka/core/model-failure';
|
|
20
|
+
import { truncateUtf8 } from '@maka/core/diagnostic-log';
|
|
19
21
|
import { markPersisted } from '@maka/core/persisted-value';
|
|
20
22
|
import { SANDBOX_BOUNDARY_REQUEST_STATUSES, validateSandboxBoundaryExpansion, } from '@maka/core/sandbox-boundary';
|
|
21
23
|
import { TOOL_ACTIVITY_KINDS, normalizeMessageContent } from '@maka/core/events';
|
|
@@ -42,7 +44,6 @@ const RUNTIME_EVENT_READ_MODEL_DIAGNOSTIC_SEVERITY = {
|
|
|
42
44
|
archived_tool_result_placeholder: 'soft',
|
|
43
45
|
generated_id: 'soft',
|
|
44
46
|
tool_use_id_mismatch: 'hard',
|
|
45
|
-
missing_legacy_message: 'soft',
|
|
46
47
|
unexpected_projected_message: 'soft',
|
|
47
48
|
};
|
|
48
49
|
export function isHardRuntimeEventReadModelDiagnostic(diagnostic) {
|
|
@@ -89,7 +90,23 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
89
90
|
contentOrderByMessageId: new Map(),
|
|
90
91
|
};
|
|
91
92
|
const messages = [];
|
|
93
|
+
/**
|
|
94
|
+
* Which event each message came out of, by position.
|
|
95
|
+
*
|
|
96
|
+
* A message belongs to the event being read when it was appended: nothing
|
|
97
|
+
* rewrites an earlier message, so the rows that appear while one event is
|
|
98
|
+
* handled are exactly that event's rows. A durable reader numbers its pages
|
|
99
|
+
* from this, which is why it is recorded here rather than rediscovered.
|
|
100
|
+
*/
|
|
101
|
+
const sourceEventIds = [];
|
|
102
|
+
let reading;
|
|
103
|
+
const attributeEmitted = () => {
|
|
104
|
+
while (sourceEventIds.length < messages.length)
|
|
105
|
+
sourceEventIds.push(reading.id);
|
|
106
|
+
};
|
|
92
107
|
for (const event of events) {
|
|
108
|
+
attributeEmitted();
|
|
109
|
+
reading = event;
|
|
93
110
|
recordStepContentOrder(event, state);
|
|
94
111
|
if (isPartialRuntimeEvent(event)) {
|
|
95
112
|
diagnostic(state, event, 'partial_skipped', 'partial RuntimeEvent skipped');
|
|
@@ -111,6 +128,9 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
111
128
|
case 'thinking':
|
|
112
129
|
projected = projectThinking(event, state, messages) || projected;
|
|
113
130
|
break;
|
|
131
|
+
case 'system_note':
|
|
132
|
+
projected = projectSystemNote(event, state, messages) || projected;
|
|
133
|
+
break;
|
|
114
134
|
case 'invocation_opened':
|
|
115
135
|
// The opening fact records route, configuration and lineage once per
|
|
116
136
|
// invocation. Every reader joins it by invocationId; it has no chat row.
|
|
@@ -197,6 +217,10 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
197
217
|
// every provider-visible row the transfer leads to.
|
|
198
218
|
projected = true;
|
|
199
219
|
}
|
|
220
|
+
if (event.actions?.handoffPause) {
|
|
221
|
+
// Physical pause is not a logical Turn outcome or a chat message.
|
|
222
|
+
projected = true;
|
|
223
|
+
}
|
|
200
224
|
if (event.actions?.runtimeProtocol) {
|
|
201
225
|
// The protocol marker records which runtime contracts were live from a
|
|
202
226
|
// run's first event. RecoveryResolver reads it; it has no chat row.
|
|
@@ -224,7 +248,7 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
224
248
|
if (event.actions?.tokenUsage) {
|
|
225
249
|
projected = projectTokenUsage(event, state, messages) || projected;
|
|
226
250
|
}
|
|
227
|
-
if (isTerminalRuntimeEvent(event)) {
|
|
251
|
+
if (isTerminalRuntimeEvent(event) && !event.actions?.handoffPause) {
|
|
228
252
|
projected = projectTerminalTurnState(event, state, messages) || projected;
|
|
229
253
|
}
|
|
230
254
|
if (!projected) {
|
|
@@ -247,7 +271,66 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
247
271
|
diagnostic(state, pending.event, 'unsupported_event', 'thinking content has no assistant text row with a matching message id');
|
|
248
272
|
}
|
|
249
273
|
}
|
|
250
|
-
|
|
274
|
+
attributeEmitted();
|
|
275
|
+
return { messages, diagnostics: state.diagnostics, sourceEventIds };
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* A running invocation's events as the transcript should show them right now.
|
|
279
|
+
*
|
|
280
|
+
* Two things separate a live run from a finished one. Its last text or thinking
|
|
281
|
+
* event is still arriving, so it is presented as settled rather than withheld;
|
|
282
|
+
* and a step that has only thought so far has no assistant row to hang that
|
|
283
|
+
* thinking on, so an empty one is opened for it. Neither changes the ledger:
|
|
284
|
+
* both are how the same events read before the run ends.
|
|
285
|
+
*/
|
|
286
|
+
export function activePresentationRuntimeEvents(events) {
|
|
287
|
+
const textMessages = new Set();
|
|
288
|
+
const lastThinkingByMessage = new Map();
|
|
289
|
+
for (const event of events) {
|
|
290
|
+
const content = event.content;
|
|
291
|
+
if (event.role !== 'model' || (content?.kind !== 'text' && content?.kind !== 'thinking')) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const messageKey = activeMessageKey(event);
|
|
295
|
+
if (content.kind === 'text')
|
|
296
|
+
textMessages.add(messageKey);
|
|
297
|
+
else
|
|
298
|
+
lastThinkingByMessage.set(messageKey, event);
|
|
299
|
+
}
|
|
300
|
+
const syntheticAfter = new Map();
|
|
301
|
+
for (const [messageKey, thinking] of lastThinkingByMessage) {
|
|
302
|
+
if (textMessages.has(messageKey))
|
|
303
|
+
continue;
|
|
304
|
+
const existing = syntheticAfter.get(thinking) ?? [];
|
|
305
|
+
existing.push(emptyAssistantText(thinking));
|
|
306
|
+
syntheticAfter.set(thinking, existing);
|
|
307
|
+
}
|
|
308
|
+
const presented = [];
|
|
309
|
+
for (const event of events) {
|
|
310
|
+
presented.push(settledPresentationEvent(event));
|
|
311
|
+
presented.push(...(syntheticAfter.get(event) ?? []));
|
|
312
|
+
}
|
|
313
|
+
return presented;
|
|
314
|
+
}
|
|
315
|
+
function activeMessageKey(event) {
|
|
316
|
+
const messageId = event.refs?.providerEventId ?? event.refs?.storedMessageId ?? event.id;
|
|
317
|
+
return `${event.runId}\0${messageId}`;
|
|
318
|
+
}
|
|
319
|
+
function settledPresentationEvent(event) {
|
|
320
|
+
const content = event.content;
|
|
321
|
+
return event.partial &&
|
|
322
|
+
event.role === 'model' &&
|
|
323
|
+
(content?.kind === 'text' || content?.kind === 'thinking')
|
|
324
|
+
? { ...event, partial: false }
|
|
325
|
+
: event;
|
|
326
|
+
}
|
|
327
|
+
function emptyAssistantText(thinking) {
|
|
328
|
+
return {
|
|
329
|
+
...thinking,
|
|
330
|
+
id: `${thinking.id}:active-transcript-empty-text`,
|
|
331
|
+
partial: false,
|
|
332
|
+
content: { kind: 'text', text: '' },
|
|
333
|
+
};
|
|
251
334
|
}
|
|
252
335
|
export function projectRuntimeEventsToStoredMessagesWithArchiveStatuses(events, options) {
|
|
253
336
|
return projectRuntimeEventsToStoredMessages(applyArchivedToolResultReadModelStatuses(events, options.archiveStatuses), options);
|
|
@@ -274,6 +357,7 @@ export function applyArchivedToolResultReadModelStatuses(events, archiveStatuses
|
|
|
274
357
|
toolCallId: placeholder.toolCallId,
|
|
275
358
|
toolName: placeholder.toolName,
|
|
276
359
|
artifactId: placeholder.artifactId,
|
|
360
|
+
...(placeholder.rewriteVersion === 2 ? { resourceRef: placeholder.resourceRef } : {}),
|
|
277
361
|
bodySha256: placeholder.bodySha256,
|
|
278
362
|
originalEstimatedTokens: placeholder.originalEstimatedTokens,
|
|
279
363
|
originalBytes: placeholder.originalBytes,
|
|
@@ -284,32 +368,6 @@ export function applyArchivedToolResultReadModelStatuses(events, archiveStatuses
|
|
|
284
368
|
};
|
|
285
369
|
});
|
|
286
370
|
}
|
|
287
|
-
export function compareRuntimeReadModelMessages(projected, legacy) {
|
|
288
|
-
const diagnostics = [];
|
|
289
|
-
const projectedCounts = countSemanticMessages(projected);
|
|
290
|
-
const legacyCounts = countSemanticMessages(legacy);
|
|
291
|
-
for (const [key, count] of legacyCounts) {
|
|
292
|
-
const projectedCount = projectedCounts.get(key) ?? 0;
|
|
293
|
-
if (projectedCount < count) {
|
|
294
|
-
diagnostics.push({
|
|
295
|
-
code: 'missing_legacy_message',
|
|
296
|
-
message: 'projected RuntimeEvent read model is missing a legacy semantic message',
|
|
297
|
-
detail: JSON.parse(key),
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
for (const [key, count] of projectedCounts) {
|
|
302
|
-
const legacyCount = legacyCounts.get(key) ?? 0;
|
|
303
|
-
if (legacyCount < count) {
|
|
304
|
-
diagnostics.push({
|
|
305
|
-
code: 'unexpected_projected_message',
|
|
306
|
-
message: 'projected RuntimeEvent read model has no matching legacy semantic message',
|
|
307
|
-
detail: JSON.parse(key),
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return { compatible: diagnostics.length === 0, diagnostics };
|
|
312
|
-
}
|
|
313
371
|
export function classifyRuntimeEventTerminalFact(invocation, events) {
|
|
314
372
|
const diagnostics = [];
|
|
315
373
|
if (events.length === 0) {
|
|
@@ -601,6 +659,9 @@ function projectFunctionResponse(event, state, messages) {
|
|
|
601
659
|
toolName: archivedPlaceholder.toolName,
|
|
602
660
|
artifactId: archivedPlaceholder.artifactId,
|
|
603
661
|
bodySha256: archivedPlaceholder.bodySha256,
|
|
662
|
+
...(archivedPlaceholder.rewriteVersion === 2
|
|
663
|
+
? { resourceRef: archivedPlaceholder.resourceRef }
|
|
664
|
+
: {}),
|
|
604
665
|
originalEstimatedTokens: archivedPlaceholder.originalEstimatedTokens,
|
|
605
666
|
originalBytes: archivedPlaceholder.originalBytes,
|
|
606
667
|
rewriteVersion: archivedPlaceholder.rewriteVersion,
|
|
@@ -665,6 +726,9 @@ function projectPermissionDecision(event, state, messages) {
|
|
|
665
726
|
diagnostic(state, event, 'incomplete_event', 'permission decision toolName does not match its paired request or tool call');
|
|
666
727
|
return false;
|
|
667
728
|
}
|
|
729
|
+
// The prompt's own wording when the request survived, and the decision's copy
|
|
730
|
+
// of it when the decision is all that is left.
|
|
731
|
+
const hint = request?.hint ?? decision.hint;
|
|
668
732
|
messages.push({
|
|
669
733
|
type: 'permission_decision',
|
|
670
734
|
id: decision.requestId,
|
|
@@ -679,7 +743,7 @@ function projectPermissionDecision(event, state, messages) {
|
|
|
679
743
|
...(decision.reviewer !== undefined ? { reviewer: decision.reviewer } : {}),
|
|
680
744
|
...(decision.rationale !== undefined ? { rationale: decision.rationale } : {}),
|
|
681
745
|
...(decision.riskLevel !== undefined ? { riskLevel: decision.riskLevel } : {}),
|
|
682
|
-
...(
|
|
746
|
+
...(hint !== undefined ? { hint } : {}),
|
|
683
747
|
});
|
|
684
748
|
return true;
|
|
685
749
|
}
|
|
@@ -783,9 +847,6 @@ function projectTerminalTurnState(event, state, messages) {
|
|
|
783
847
|
}
|
|
784
848
|
const abortSource = status === 'aborted' ? abortSourceFromRuntime(event) : undefined;
|
|
785
849
|
const failureClass = status === 'failed' ? failureClassFromRuntimeEvent(event) : undefined;
|
|
786
|
-
const partialOutputRetained = messages.some((message) => message.turnId === event.turnId &&
|
|
787
|
-
((message.type === 'assistant' && message.text.trim().length > 0) ||
|
|
788
|
-
message.type === 'tool_result'));
|
|
789
850
|
messages.push({
|
|
790
851
|
type: 'turn_state',
|
|
791
852
|
id: stableMessageId(event, state, 'turn_state'),
|
|
@@ -802,7 +863,14 @@ function projectTerminalTurnState(event, state, messages) {
|
|
|
802
863
|
...(status === 'aborted' ? { abortedAt: event.ts } : {}),
|
|
803
864
|
...(abortSource ? { abortSource } : {}),
|
|
804
865
|
...(status === 'failed' ? { errorClass: failureClass ?? 'unknown' } : {}),
|
|
805
|
-
|
|
866
|
+
...(status === 'failed' && event.content?.kind === 'error' && event.content.message
|
|
867
|
+
? {
|
|
868
|
+
failureMessage: truncateUtf8(event.content.message, MODEL_FAILURE_MESSAGE_MAX_BYTES, '…'),
|
|
869
|
+
}
|
|
870
|
+
: {}),
|
|
871
|
+
...(status === 'failed' && event.content?.kind === 'error' && event.content.retry
|
|
872
|
+
? { retry: event.content.retry }
|
|
873
|
+
: {}),
|
|
806
874
|
});
|
|
807
875
|
if (failureClass === 'tool_step_cap_reached') {
|
|
808
876
|
messages.push({
|
|
@@ -818,6 +886,25 @@ function projectTerminalTurnState(event, state, messages) {
|
|
|
818
886
|
// already reads `unknown` into an unreadable Session.
|
|
819
887
|
return true;
|
|
820
888
|
}
|
|
889
|
+
/**
|
|
890
|
+
* The note row of an invocation that wrote one.
|
|
891
|
+
*
|
|
892
|
+
* There is nothing to reconcile: the event carries the kind and the payload the
|
|
893
|
+
* row is made of, so the row is the event said back in the transcript's shape.
|
|
894
|
+
*/
|
|
895
|
+
function projectSystemNote(event, state, messages) {
|
|
896
|
+
if (event.content?.kind !== 'system_note')
|
|
897
|
+
return false;
|
|
898
|
+
messages.push({
|
|
899
|
+
type: 'system_note',
|
|
900
|
+
id: stableMessageId(event, state, 'system_note'),
|
|
901
|
+
turnId: event.turnId,
|
|
902
|
+
ts: event.ts,
|
|
903
|
+
kind: event.content.note,
|
|
904
|
+
...(event.content.data !== undefined ? { data: structuredClone(event.content.data) } : {}),
|
|
905
|
+
});
|
|
906
|
+
return true;
|
|
907
|
+
}
|
|
821
908
|
function attachPendingThinking(event, state, messages, assistantMessageId) {
|
|
822
909
|
const pendingItems = state.thinkingByMessageId.get(assistantMessageId);
|
|
823
910
|
if (!pendingItems)
|
|
@@ -1039,128 +1126,3 @@ function isRuntimeEventDiagnosticDetail(detail) {
|
|
|
1039
1126
|
typeof detail.runId === 'string' &&
|
|
1040
1127
|
typeof detail.turnId === 'string');
|
|
1041
1128
|
}
|
|
1042
|
-
function countSemanticMessages(messages) {
|
|
1043
|
-
const counts = new Map();
|
|
1044
|
-
for (const message of messages) {
|
|
1045
|
-
const key = stableSemanticKey(semanticMessage(message));
|
|
1046
|
-
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
1047
|
-
}
|
|
1048
|
-
return counts;
|
|
1049
|
-
}
|
|
1050
|
-
function stableSemanticKey(value) {
|
|
1051
|
-
return JSON.stringify(sortSemanticValue(value));
|
|
1052
|
-
}
|
|
1053
|
-
function sortSemanticValue(value) {
|
|
1054
|
-
if (Array.isArray(value)) {
|
|
1055
|
-
return value.map(sortSemanticValue);
|
|
1056
|
-
}
|
|
1057
|
-
if (!value || typeof value !== 'object') {
|
|
1058
|
-
return value;
|
|
1059
|
-
}
|
|
1060
|
-
return Object.fromEntries(Object.keys(value)
|
|
1061
|
-
.sort()
|
|
1062
|
-
.map((key) => [key, sortSemanticValue(value[key])]));
|
|
1063
|
-
}
|
|
1064
|
-
function semanticMessage(message) {
|
|
1065
|
-
switch (message.type) {
|
|
1066
|
-
case 'user':
|
|
1067
|
-
return {
|
|
1068
|
-
type: message.type,
|
|
1069
|
-
turnId: message.turnId,
|
|
1070
|
-
text: message.text,
|
|
1071
|
-
displayText: message.displayText,
|
|
1072
|
-
origin: message.origin,
|
|
1073
|
-
attachments: message.attachments ?? [],
|
|
1074
|
-
directoryReferences: message.directoryReferences,
|
|
1075
|
-
quotes: message.quotes ?? [],
|
|
1076
|
-
};
|
|
1077
|
-
case 'assistant':
|
|
1078
|
-
return {
|
|
1079
|
-
type: message.type,
|
|
1080
|
-
turnId: message.turnId,
|
|
1081
|
-
text: message.text,
|
|
1082
|
-
modelId: message.modelId,
|
|
1083
|
-
thinking: message.thinking,
|
|
1084
|
-
};
|
|
1085
|
-
case 'tool_call':
|
|
1086
|
-
return {
|
|
1087
|
-
type: message.type,
|
|
1088
|
-
turnId: message.turnId,
|
|
1089
|
-
toolUseId: message.id,
|
|
1090
|
-
toolName: message.toolName,
|
|
1091
|
-
activityKind: message.activityKind,
|
|
1092
|
-
displayName: message.displayName,
|
|
1093
|
-
intent: message.intent,
|
|
1094
|
-
args: message.args,
|
|
1095
|
-
};
|
|
1096
|
-
case 'tool_result':
|
|
1097
|
-
return {
|
|
1098
|
-
type: message.type,
|
|
1099
|
-
turnId: message.turnId,
|
|
1100
|
-
toolUseId: message.toolUseId,
|
|
1101
|
-
isError: message.isError,
|
|
1102
|
-
content: message.content,
|
|
1103
|
-
durationMs: message.durationMs,
|
|
1104
|
-
};
|
|
1105
|
-
case 'permission_decision':
|
|
1106
|
-
return {
|
|
1107
|
-
type: message.type,
|
|
1108
|
-
turnId: message.turnId,
|
|
1109
|
-
toolUseId: message.toolUseId,
|
|
1110
|
-
toolName: message.toolName,
|
|
1111
|
-
decision: message.decision,
|
|
1112
|
-
rememberForTurn: message.rememberForTurn,
|
|
1113
|
-
hint: message.hint,
|
|
1114
|
-
};
|
|
1115
|
-
case 'token_usage':
|
|
1116
|
-
return {
|
|
1117
|
-
type: message.type,
|
|
1118
|
-
turnId: message.turnId,
|
|
1119
|
-
input: message.input,
|
|
1120
|
-
output: message.output,
|
|
1121
|
-
cacheHitInput: message.cacheHitInput,
|
|
1122
|
-
cacheMissInput: message.cacheMissInput,
|
|
1123
|
-
cacheMissInputSource: message.cacheMissInputSource,
|
|
1124
|
-
cacheWriteInput: message.cacheWriteInput,
|
|
1125
|
-
reasoning: message.reasoning,
|
|
1126
|
-
total: message.total,
|
|
1127
|
-
rawFinishReason: message.rawFinishReason,
|
|
1128
|
-
runtimeSteps: message.runtimeSteps,
|
|
1129
|
-
cacheRead: message.cacheRead,
|
|
1130
|
-
cacheCreation: message.cacheCreation,
|
|
1131
|
-
costUsd: message.costUsd,
|
|
1132
|
-
systemPromptHash: message.systemPromptHash,
|
|
1133
|
-
contextRemaining: message.contextRemaining,
|
|
1134
|
-
prefixHash: message.prefixHash,
|
|
1135
|
-
prefixChangeReason: message.prefixChangeReason,
|
|
1136
|
-
requestShapeHash: message.requestShapeHash,
|
|
1137
|
-
requestShapeChangeReason: message.requestShapeChangeReason,
|
|
1138
|
-
promptSegments: message.promptSegments,
|
|
1139
|
-
contextBudget: message.contextBudget,
|
|
1140
|
-
providerRequestTraceId: message.providerRequestTraceId,
|
|
1141
|
-
lastRequestAnchor: message.lastRequestAnchor,
|
|
1142
|
-
};
|
|
1143
|
-
case 'turn_state':
|
|
1144
|
-
return {
|
|
1145
|
-
type: message.type,
|
|
1146
|
-
turnId: message.turnId,
|
|
1147
|
-
status: message.status,
|
|
1148
|
-
parentTurnId: message.parentTurnId,
|
|
1149
|
-
retriedFromTurnId: message.retriedFromTurnId,
|
|
1150
|
-
regeneratedFromTurnId: message.regeneratedFromTurnId,
|
|
1151
|
-
branchOfTurnId: message.branchOfTurnId,
|
|
1152
|
-
parentSessionId: message.parentSessionId,
|
|
1153
|
-
abortedAt: message.abortedAt,
|
|
1154
|
-
abortSource: message.abortSource,
|
|
1155
|
-
errorClass: message.errorClass,
|
|
1156
|
-
partialOutputRetained: message.partialOutputRetained,
|
|
1157
|
-
};
|
|
1158
|
-
case 'system_note':
|
|
1159
|
-
return {
|
|
1160
|
-
type: message.type,
|
|
1161
|
-
turnId: message.turnId,
|
|
1162
|
-
kind: message.kind,
|
|
1163
|
-
data: message.data,
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
}
|