maka-agent 0.2.0-dev.30.20260912 → 0.2.0-dev.32.20260914
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.txt +392 -0
- package/dist/acp/maka-acp-agent.js +8 -2
- package/dist/acp/prompt-content.js +225 -0
- package/dist/acp/session-event-mapper.js +103 -0
- package/dist/acp/session-registry.js +654 -17
- package/dist/acp/stdio-server.js +10 -1
- package/dist/cli-core.js +1 -1
- package/dist/pi-transcript-tools.js +3 -2
- package/dist/pi-transcript.js +15 -6
- package/dist/runtime-host-session-channel.js +63 -9
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/agent-graph-schedule.js +15 -4
- package/node_modules/@maka/core/dist/artifacts.js +6 -0
- package/node_modules/@maka/core/dist/attachments.js +7 -2
- package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
- package/node_modules/@maka/core/dist/events.js +21 -0
- package/node_modules/@maka/core/dist/executor-id.js +22 -0
- package/node_modules/@maka/core/dist/external-session.js +18 -0
- package/node_modules/@maka/core/dist/goal.js +44 -2
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -13
- package/node_modules/@maka/core/dist/permission.js +0 -1
- package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
- package/node_modules/@maka/core/dist/runtime-event.js +25 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
- package/node_modules/@maka/core/dist/session-send-projection.js +6 -3
- package/node_modules/@maka/core/dist/session.js +8 -2
- package/node_modules/@maka/core/dist/shell-run-result.js +1 -0
- package/node_modules/@maka/core/dist/shell-run.js +4 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/unified-diff.js +33 -26
- package/node_modules/@maka/core/dist/work-board.js +94 -1
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/eval/dist/fleet-simulation.js +270 -0
- package/node_modules/@maka/eval/dist/fleet-store.js +243 -0
- package/node_modules/@maka/eval/dist/fleet-worker.js +125 -0
- package/node_modules/@maka/eval/dist/fleet.js +329 -0
- package/node_modules/@maka/eval/dist/index.js +3 -0
- package/node_modules/@maka/runtime/dist/agent-run.js +2 -17
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +55 -180
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +43 -26
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +271 -382
- package/node_modules/@maka/runtime/dist/background-task-health-tool.js +104 -0
- package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
- package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
- package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
- package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
- package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
- package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
- package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
- package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
- package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
- package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
- package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
- package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
- package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
- package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
- package/node_modules/@maka/runtime/dist/history-compaction.js +3 -1
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +1 -1
- package/node_modules/@maka/runtime/dist/model-adapter.js +62 -53
- package/node_modules/@maka/runtime/dist/model-history.js +26 -8
- package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +311 -0
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +344 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +7 -1
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +35 -8
- package/node_modules/@maka/runtime/dist/read-page.js +231 -0
- package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
- package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
- package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +7 -1
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +188 -20
- package/node_modules/@maka/runtime/dist/runtime-invocation-route.js +49 -0
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +72 -150
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -3
- package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +106 -64
- package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
- package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +10 -4
- package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +2 -1
- package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
- package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +1 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +26 -4
- package/node_modules/@maka/runtime/dist/subagent-tools.js +7 -0
- package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
- package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
- package/node_modules/@maka/runtime/dist/tool-runtime.js +52 -471
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
- package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
- package/node_modules/@maka/runtime/package.json +5 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +7 -2
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +24 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +42 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +31 -3
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +8 -2
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
- package/node_modules/@maka/runtime-host/dist/server/child-agent-composition.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +3 -30
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +56 -8
- package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +14 -1
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
- package/node_modules/@maka/runtime-host/dist/server/host-session-availability.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +56 -16
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +9 -5
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
- package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +37 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
- package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +450 -234
- package/node_modules/@maka/storage/dist/claude-code-transcript-lineage.js +106 -77
- package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
- package/node_modules/@maka/storage/dist/legacy-run-header.js +2 -2
- package/node_modules/@maka/storage/dist/model-call-usage-sql.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
- package/node_modules/@maka/storage/dist/session-store.js +12 -2
- package/node_modules/@maka/storage/dist/sqlite-long-term-memory-store.js +86 -12
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
- package/node_modules/@maka/storage/dist/work-board-store.js +40 -1
- package/node_modules/balanced-match/LICENSE.md +23 -0
- package/node_modules/balanced-match/README.md +57 -0
- package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
- package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
- package/node_modules/balanced-match/dist/esm/index.js +54 -0
- package/node_modules/balanced-match/dist/esm/package.json +3 -0
- package/node_modules/balanced-match/package.json +68 -0
- package/node_modules/brace-expansion/LICENSE +23 -0
- package/node_modules/brace-expansion/README.md +105 -0
- package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
- package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
- package/node_modules/brace-expansion/dist/esm/index.js +285 -0
- package/node_modules/brace-expansion/dist/esm/package.json +3 -0
- package/node_modules/brace-expansion/package.json +64 -0
- package/node_modules/glob/LICENSE.md +63 -0
- package/node_modules/glob/README.md +1203 -0
- package/node_modules/glob/dist/commonjs/glob.js +248 -0
- package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
- package/node_modules/glob/dist/commonjs/ignore.js +119 -0
- package/node_modules/glob/dist/commonjs/index.js +68 -0
- package/node_modules/glob/dist/commonjs/index.min.js +4 -0
- package/node_modules/glob/dist/commonjs/package.json +3 -0
- package/node_modules/glob/dist/commonjs/pattern.js +223 -0
- package/node_modules/glob/dist/commonjs/processor.js +301 -0
- package/node_modules/glob/dist/commonjs/walker.js +387 -0
- package/node_modules/glob/dist/esm/glob.js +244 -0
- package/node_modules/glob/dist/esm/has-magic.js +23 -0
- package/node_modules/glob/dist/esm/ignore.js +115 -0
- package/node_modules/glob/dist/esm/index.js +55 -0
- package/node_modules/glob/dist/esm/index.min.js +4 -0
- package/node_modules/glob/dist/esm/package.json +3 -0
- package/node_modules/glob/dist/esm/pattern.js +219 -0
- package/node_modules/glob/dist/esm/processor.js +294 -0
- package/node_modules/glob/dist/esm/walker.js +381 -0
- package/node_modules/glob/package.json +98 -0
- package/node_modules/minimatch/LICENSE.md +55 -0
- package/node_modules/minimatch/README.md +528 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
- package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
- package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
- package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
- package/node_modules/minimatch/dist/commonjs/package.json +3 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
- package/node_modules/minimatch/dist/esm/ast.js +841 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
- package/node_modules/minimatch/dist/esm/escape.js +26 -0
- package/node_modules/minimatch/dist/esm/index.js +1114 -0
- package/node_modules/minimatch/dist/esm/package.json +3 -0
- package/node_modules/minimatch/dist/esm/unescape.js +34 -0
- package/node_modules/minimatch/package.json +73 -0
- package/node_modules/minipass/LICENSE.md +55 -0
- package/node_modules/minipass/README.md +825 -0
- package/node_modules/minipass/dist/commonjs/index.js +1038 -0
- package/node_modules/minipass/dist/commonjs/package.json +3 -0
- package/node_modules/minipass/dist/esm/index.js +1020 -0
- package/node_modules/minipass/dist/esm/package.json +3 -0
- package/node_modules/minipass/package.json +77 -0
- package/node_modules/path-scurry/LICENSE.md +55 -0
- package/node_modules/path-scurry/README.md +636 -0
- package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
- package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/dist/esm/index.js +1983 -0
- package/node_modules/path-scurry/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
- package/node_modules/path-scurry/package.json +72 -0
- package/package.json +1 -1
- package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
- package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +0 -115
|
@@ -25,6 +25,7 @@ import { isPartialRuntimeEvent, isTerminalRuntimeEvent, isTerminalRuntimeEventSt
|
|
|
25
25
|
import { decodePersistedToolResultContent } from '@maka/core/tool-result-record-schema';
|
|
26
26
|
const SETTLED_SANDBOX_BOUNDARY_STATUSES = SANDBOX_BOUNDARY_REQUEST_STATUSES.filter((status) => status !== 'pending');
|
|
27
27
|
import { isArchivedToolResultPlaceholder } from './tool-result-archive.js';
|
|
28
|
+
import { truncateToolOutput } from './tool-output.js';
|
|
28
29
|
/**
|
|
29
30
|
* Whether a diagnostic means the projection may have lost user-visible content.
|
|
30
31
|
*
|
|
@@ -94,7 +95,54 @@ const UNCLAIMED_RUNTIME_EVENT_DIAGNOSTIC_CODES = [
|
|
|
94
95
|
export function isUnclaimedRuntimeEventDiagnostic(diagnostic) {
|
|
95
96
|
return UNCLAIMED_RUNTIME_EVENT_DIAGNOSTIC_CODES.includes(diagnostic.code);
|
|
96
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Keep a completed local terminal result useful but bounded in transcript views.
|
|
100
|
+
* The durable RuntimeEvent remains untouched and the marker names its retained
|
|
101
|
+
* result, so readers can fetch the full output without repeating the command.
|
|
102
|
+
*/
|
|
103
|
+
export function projectTranscriptToolResult(event, content) {
|
|
104
|
+
if (content.kind !== 'terminal' ||
|
|
105
|
+
content.output.mode !== 'pipes' ||
|
|
106
|
+
!hasLocalTerminalModelProjection(event)) {
|
|
107
|
+
return content;
|
|
108
|
+
}
|
|
109
|
+
const recoveryHint = `Read ${JSON.stringify({
|
|
110
|
+
path: `maka://runtime/tool-results/${encodeURIComponent(event.id)}`,
|
|
111
|
+
})} for the retained output; follow next to continue.`;
|
|
112
|
+
const options = { maxBytes: 1024, maxLines: 20, direction: 'tail', recoveryHint };
|
|
113
|
+
const stdout = truncateToolOutput(content.output.stdout, options);
|
|
114
|
+
const stderr = truncateToolOutput(content.output.stderr, options);
|
|
115
|
+
if (!stdout.truncated && !stderr.truncated)
|
|
116
|
+
return content;
|
|
117
|
+
return {
|
|
118
|
+
...content,
|
|
119
|
+
output: {
|
|
120
|
+
...content.output,
|
|
121
|
+
stdout: stdout.content,
|
|
122
|
+
stderr: stderr.content,
|
|
123
|
+
stdoutTruncated: content.output.stdoutTruncated || stdout.truncated,
|
|
124
|
+
stderrTruncated: content.output.stderrTruncated || stderr.truncated,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function hasLocalTerminalModelProjection(event) {
|
|
129
|
+
const content = event.content;
|
|
130
|
+
if (content?.kind !== 'function_response' || content.providerExecuted)
|
|
131
|
+
return false;
|
|
132
|
+
const projection = content.modelProjection;
|
|
133
|
+
return (projection?.kind === 'json' &&
|
|
134
|
+
projection.value !== null &&
|
|
135
|
+
typeof projection.value === 'object' &&
|
|
136
|
+
'kind' in projection.value &&
|
|
137
|
+
projection.value.kind === 'terminal');
|
|
138
|
+
}
|
|
97
139
|
export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
140
|
+
const projector = createRuntimeEventStoredMessageProjector(options);
|
|
141
|
+
for (const event of events)
|
|
142
|
+
projector.push(event);
|
|
143
|
+
return projector.finish();
|
|
144
|
+
}
|
|
145
|
+
export function createRuntimeEventStoredMessageProjector(options) {
|
|
98
146
|
const state = {
|
|
99
147
|
invocations: normalizeInvocations(options.invocations),
|
|
100
148
|
diagnostics: [],
|
|
@@ -102,6 +150,8 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
102
150
|
permissionRequestById: new Map(),
|
|
103
151
|
thinkingByMessageId: new Map(),
|
|
104
152
|
contentOrderByMessageId: new Map(),
|
|
153
|
+
...(options.projectToolResult ? { projectToolResult: options.projectToolResult } : {}),
|
|
154
|
+
sourceOrder: -1,
|
|
105
155
|
};
|
|
106
156
|
const messages = [];
|
|
107
157
|
/**
|
|
@@ -112,19 +162,48 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
112
162
|
* handled are exactly that event's rows. A durable reader numbers its pages
|
|
113
163
|
* from this, which is why it is recorded here rather than rediscovered.
|
|
114
164
|
*/
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
165
|
+
const messageSources = [];
|
|
166
|
+
const diagnosticSources = [];
|
|
167
|
+
const deferredPermissionAcceptances = [];
|
|
168
|
+
const permissionRequestIds = new Set();
|
|
169
|
+
let nextSourceOrder = 0;
|
|
170
|
+
let finished;
|
|
171
|
+
const attributeEmitted = (event, sourceOrder, firstSourcePosition) => {
|
|
172
|
+
let sourcePosition = firstSourcePosition;
|
|
173
|
+
while (messageSources.length < messages.length) {
|
|
174
|
+
const message = messages[messageSources.length];
|
|
175
|
+
messageSources.push({
|
|
176
|
+
eventId: event.id,
|
|
177
|
+
sourceOrder,
|
|
178
|
+
sourcePosition,
|
|
179
|
+
emittedOrder: messageSources.length,
|
|
180
|
+
});
|
|
181
|
+
sourcePosition += 1;
|
|
182
|
+
options.onMessage?.(message, event.id);
|
|
183
|
+
}
|
|
184
|
+
return sourcePosition;
|
|
120
185
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
186
|
+
const attributeDiagnostics = (sourceOrder, firstSourcePosition) => {
|
|
187
|
+
let sourcePosition = firstSourcePosition;
|
|
188
|
+
while (diagnosticSources.length < state.diagnostics.length) {
|
|
189
|
+
diagnosticSources.push({
|
|
190
|
+
sourceOrder,
|
|
191
|
+
sourcePosition,
|
|
192
|
+
emittedOrder: diagnosticSources.length,
|
|
193
|
+
});
|
|
194
|
+
sourcePosition += 1;
|
|
195
|
+
}
|
|
196
|
+
return sourcePosition;
|
|
197
|
+
};
|
|
198
|
+
const projectEvent = (event, sourceOrder) => {
|
|
199
|
+
let nextMessagePosition = 0;
|
|
200
|
+
let nextDiagnosticPosition = 0;
|
|
201
|
+
state.sourceOrder = sourceOrder;
|
|
124
202
|
recordStepContentOrder(event, state);
|
|
125
203
|
if (isPartialRuntimeEvent(event)) {
|
|
126
204
|
diagnostic(state, event, 'partial_skipped', 'partial RuntimeEvent skipped');
|
|
127
|
-
|
|
205
|
+
attributeDiagnostics(sourceOrder, nextDiagnosticPosition);
|
|
206
|
+
return;
|
|
128
207
|
}
|
|
129
208
|
let projected = false;
|
|
130
209
|
const content = event.content;
|
|
@@ -197,7 +276,17 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
197
276
|
projected = true;
|
|
198
277
|
}
|
|
199
278
|
if (event.actions?.permissionAnswerAccepted) {
|
|
200
|
-
|
|
279
|
+
nextMessagePosition = attributeEmitted(event, sourceOrder, nextMessagePosition);
|
|
280
|
+
nextDiagnosticPosition = attributeDiagnostics(sourceOrder, nextDiagnosticPosition);
|
|
281
|
+
const requestId = event.actions.permissionAnswerAccepted.requestId;
|
|
282
|
+
permissionRequestIds.add(requestId);
|
|
283
|
+
deferredPermissionAcceptances.push({
|
|
284
|
+
event: permissionAcceptanceProjectionEvent(event),
|
|
285
|
+
ledgerRequest: state.permissionRequestById.get(requestId),
|
|
286
|
+
sourceOrder,
|
|
287
|
+
messagePosition: nextMessagePosition++,
|
|
288
|
+
diagnosticPosition: nextDiagnosticPosition++,
|
|
289
|
+
});
|
|
201
290
|
projected = true;
|
|
202
291
|
}
|
|
203
292
|
if (event.actions?.permissionClosureAccepted) {
|
|
@@ -284,14 +373,74 @@ export function projectRuntimeEventsToStoredMessages(events, options) {
|
|
|
284
373
|
diagnostic(state, event, 'unsupported_event', 'RuntimeEvent shape is not supported by the legacy read-model projection');
|
|
285
374
|
}
|
|
286
375
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
376
|
+
attributeEmitted(event, sourceOrder, nextMessagePosition);
|
|
377
|
+
attributeDiagnostics(sourceOrder, nextDiagnosticPosition);
|
|
378
|
+
};
|
|
379
|
+
const push = (event) => {
|
|
380
|
+
if (finished)
|
|
381
|
+
throw new Error('RuntimeEvent StoredMessage projector is already finished');
|
|
382
|
+
const sourceOrder = nextSourceOrder++;
|
|
383
|
+
projectEvent(options.active ? settledPresentationEvent(event) : event, sourceOrder);
|
|
384
|
+
};
|
|
385
|
+
const finish = () => {
|
|
386
|
+
if (finished)
|
|
387
|
+
return finished;
|
|
388
|
+
for (const acceptance of deferredPermissionAcceptances) {
|
|
389
|
+
const before = messages.length;
|
|
390
|
+
projectCanonicalPermissionOutcome(acceptance.event, state, messages, options.canonicalPermissionOutcomes, acceptance.ledgerRequest);
|
|
391
|
+
if (messages.length > before) {
|
|
392
|
+
attributeEmitted(acceptance.event, acceptance.sourceOrder, acceptance.messagePosition);
|
|
393
|
+
}
|
|
394
|
+
attributeDiagnostics(acceptance.sourceOrder, acceptance.diagnosticPosition);
|
|
291
395
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
396
|
+
if (options.active) {
|
|
397
|
+
for (const pendingItems of [...state.thinkingByMessageId.values()]) {
|
|
398
|
+
const pending = pendingItems.at(-1);
|
|
399
|
+
if (pending)
|
|
400
|
+
projectEvent(emptyAssistantText(pending.event), pending.sourceOrder);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const orderedDiagnostics = state.diagnostics
|
|
404
|
+
.map((diagnostic, index) => ({ diagnostic, source: diagnosticSources[index] }))
|
|
405
|
+
.sort((left, right) => left.source.sourceOrder - right.source.sourceOrder ||
|
|
406
|
+
left.source.sourcePosition - right.source.sourcePosition ||
|
|
407
|
+
left.source.emittedOrder - right.source.emittedOrder);
|
|
408
|
+
state.diagnostics.splice(0, state.diagnostics.length, ...orderedDiagnostics.map(({ diagnostic }) => diagnostic));
|
|
409
|
+
if (!options.active) {
|
|
410
|
+
for (const pendingItems of state.thinkingByMessageId.values()) {
|
|
411
|
+
for (const pending of pendingItems) {
|
|
412
|
+
diagnostic(state, pending.event, 'unsupported_event', 'thinking content has no assistant text row with a matching message id');
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const ordered = messages
|
|
417
|
+
.map((message, index) => ({ message, source: messageSources[index] }))
|
|
418
|
+
.sort((left, right) => left.source.sourceOrder - right.source.sourceOrder ||
|
|
419
|
+
left.source.sourcePosition - right.source.sourcePosition ||
|
|
420
|
+
left.source.emittedOrder - right.source.emittedOrder);
|
|
421
|
+
finished = {
|
|
422
|
+
messages: ordered.map(({ message }) => message),
|
|
423
|
+
diagnostics: state.diagnostics,
|
|
424
|
+
sourceEventIds: ordered.map(({ source }) => source.eventId),
|
|
425
|
+
};
|
|
426
|
+
deferredPermissionAcceptances.length = 0;
|
|
427
|
+
messageSources.length = 0;
|
|
428
|
+
diagnosticSources.length = 0;
|
|
429
|
+
state.invocations.clear();
|
|
430
|
+
state.toolNameByUseId.clear();
|
|
431
|
+
state.permissionRequestById.clear();
|
|
432
|
+
state.thinkingByMessageId.clear();
|
|
433
|
+
state.contentOrderByMessageId.clear();
|
|
434
|
+
state.projectToolResult = undefined;
|
|
435
|
+
return finished;
|
|
436
|
+
};
|
|
437
|
+
return {
|
|
438
|
+
push,
|
|
439
|
+
finish,
|
|
440
|
+
get permissionRequestIds() {
|
|
441
|
+
return [...permissionRequestIds];
|
|
442
|
+
},
|
|
443
|
+
};
|
|
295
444
|
}
|
|
296
445
|
/**
|
|
297
446
|
* A running invocation's events as the transcript should show them right now.
|
|
@@ -489,6 +638,7 @@ function projectText(event, state, messages) {
|
|
|
489
638
|
turnId: event.turnId,
|
|
490
639
|
ts: event.ts,
|
|
491
640
|
text: event.content.text,
|
|
641
|
+
...(event.content.interrupted ? { interrupted: true } : {}),
|
|
492
642
|
...(event.content.providerOptions !== undefined
|
|
493
643
|
? { providerOptions: structuredClone(event.content.providerOptions) }
|
|
494
644
|
: {}),
|
|
@@ -564,6 +714,7 @@ function projectThinking(event, state, messages) {
|
|
|
564
714
|
event,
|
|
565
715
|
messageId,
|
|
566
716
|
text: event.content.text,
|
|
717
|
+
sourceOrder: state.sourceOrder,
|
|
567
718
|
...(event.content.signature !== undefined ? { signature: event.content.signature } : {}),
|
|
568
719
|
...(event.content.providerOptions !== undefined
|
|
569
720
|
? { providerOptions: structuredClone(event.content.providerOptions) }
|
|
@@ -669,7 +820,7 @@ function projectFunctionResponse(event, state, messages) {
|
|
|
669
820
|
}
|
|
670
821
|
if (event.content.name)
|
|
671
822
|
state.toolNameByUseId.set(toolUseId, event.content.name);
|
|
672
|
-
const
|
|
823
|
+
const decodedResult = archivedPlaceholder
|
|
673
824
|
? {
|
|
674
825
|
kind: 'archived_tool_result',
|
|
675
826
|
status: 'not_loaded',
|
|
@@ -687,6 +838,9 @@ function projectFunctionResponse(event, state, messages) {
|
|
|
687
838
|
reason: archivedPlaceholder.reason,
|
|
688
839
|
}
|
|
689
840
|
: normalizedResult;
|
|
841
|
+
const resultContent = state.projectToolResult
|
|
842
|
+
? state.projectToolResult(event, decodedResult)
|
|
843
|
+
: decodedResult;
|
|
690
844
|
messages.push({
|
|
691
845
|
type: 'tool_result',
|
|
692
846
|
id: stableMessageId(event, state, 'tool_result'),
|
|
@@ -766,11 +920,10 @@ function projectPermissionDecision(event, state, messages) {
|
|
|
766
920
|
});
|
|
767
921
|
return true;
|
|
768
922
|
}
|
|
769
|
-
function projectCanonicalPermissionOutcome(event, state, messages, outcomes) {
|
|
923
|
+
function projectCanonicalPermissionOutcome(event, state, messages, outcomes, ledgerRequest) {
|
|
770
924
|
const accepted = event.actions?.permissionAnswerAccepted;
|
|
771
925
|
if (!accepted)
|
|
772
926
|
return;
|
|
773
|
-
const ledgerRequest = state.permissionRequestById.get(accepted.requestId);
|
|
774
927
|
const canonical = outcomes?.get(accepted.requestId);
|
|
775
928
|
const toolUseId = event.refs?.toolCallId;
|
|
776
929
|
if (!canonical || !toolUseId) {
|
|
@@ -807,6 +960,21 @@ function projectCanonicalPermissionOutcome(event, state, messages, outcomes) {
|
|
|
807
960
|
...(ledgerRequest?.hint !== undefined ? { hint: ledgerRequest.hint } : {}),
|
|
808
961
|
});
|
|
809
962
|
}
|
|
963
|
+
function permissionAcceptanceProjectionEvent(event) {
|
|
964
|
+
return {
|
|
965
|
+
id: event.id,
|
|
966
|
+
sessionId: event.sessionId,
|
|
967
|
+
invocationId: event.invocationId,
|
|
968
|
+
runId: event.runId,
|
|
969
|
+
turnId: event.turnId,
|
|
970
|
+
ts: event.ts,
|
|
971
|
+
partial: event.partial,
|
|
972
|
+
role: event.role,
|
|
973
|
+
author: event.author,
|
|
974
|
+
actions: { permissionAnswerAccepted: event.actions.permissionAnswerAccepted },
|
|
975
|
+
...(event.refs?.toolCallId ? { refs: { toolCallId: event.refs.toolCallId } } : {}),
|
|
976
|
+
};
|
|
977
|
+
}
|
|
810
978
|
function projectTokenUsage(event, state, messages) {
|
|
811
979
|
const usage = event.actions?.tokenUsage;
|
|
812
980
|
if (!usage)
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { isExecutorId } from '@maka/core/executor-id';
|
|
20
|
+
export function runtimeInvocationRouteForHeader(header, providerStateIdentity) {
|
|
21
|
+
if (header.backend === 'plugin-executor' &&
|
|
22
|
+
isExecutorId(header.executorId) &&
|
|
23
|
+
providerStateIdentity) {
|
|
24
|
+
return {
|
|
25
|
+
provenance: 'runtime',
|
|
26
|
+
backendKind: header.backend,
|
|
27
|
+
executorId: header.executorId,
|
|
28
|
+
llmConnectionSlug: header.llmConnectionSlug,
|
|
29
|
+
modelId: header.model,
|
|
30
|
+
providerStateIdentity,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (header.backend !== 'plugin-executor' && header.llmConnectionId !== undefined) {
|
|
34
|
+
return {
|
|
35
|
+
provenance: 'runtime',
|
|
36
|
+
backendKind: header.backend,
|
|
37
|
+
llmConnectionId: header.llmConnectionId,
|
|
38
|
+
llmConnectionSlug: header.llmConnectionSlug,
|
|
39
|
+
modelId: header.model,
|
|
40
|
+
...(providerStateIdentity ? { providerStateIdentity } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
provenance: 'unknown',
|
|
45
|
+
backendKind: header.backend,
|
|
46
|
+
llmConnectionSlug: header.llmConnectionSlug,
|
|
47
|
+
modelId: header.model,
|
|
48
|
+
};
|
|
49
|
+
}
|