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
|
@@ -31,12 +31,15 @@
|
|
|
31
31
|
* Phase 1 scope: types + small pure helpers only. No storage, runner,
|
|
32
32
|
* projection, or ledger logic lives here. Those arrive in later nodes.
|
|
33
33
|
*/
|
|
34
|
+
import { isModelRetryDecision } from './model-failure.js';
|
|
35
|
+
import { isRuntimeHandoffPause, runtimeHandoffPause, } from './runtime-handoff.js';
|
|
34
36
|
import { isMessageContent, normalizeMessageContent, } from './events.js';
|
|
35
37
|
import { INTERACTION_ID_MAX_BYTES, INTERACTION_TOOL_NAME_MAX_BYTES, decodeInteractionRequest, } from './interaction.js';
|
|
36
38
|
import { isPermissionMode, } from './permission.js';
|
|
37
39
|
import { isCollaborationMode } from './collaboration.js';
|
|
38
40
|
import { isAgentSwarmAuthorizationSource, isEffectiveOrchestrationSource, isOrchestrationMode, } from './orchestration.js';
|
|
39
41
|
import { isToolMode } from './tool-mode.js';
|
|
42
|
+
import { isRuntimeSystemNoteKind, } from './session.js';
|
|
40
43
|
import { decodeTurnOrigin } from './turn-origin.js';
|
|
41
44
|
import { defineObjectShape, hasExactShape, isFiniteNumber, isOptionalMember, isOptionalString, isRecord, isStringArray, } from './record-schema.js';
|
|
42
45
|
import { isPermissionDecisionFields, isPermissionRequestPayload, isUserQuestionRequest, } from './interaction-record-schema.js';
|
|
@@ -106,6 +109,7 @@ export const RUNTIME_EVENT_CONTENT_KINDS = [
|
|
|
106
109
|
'function_call',
|
|
107
110
|
'function_response',
|
|
108
111
|
'error',
|
|
112
|
+
'system_note',
|
|
109
113
|
'invocation_opened',
|
|
110
114
|
];
|
|
111
115
|
export const TOOL_BOUNDARY_PROTOCOL_V1 = 't1_after_preflight_v1';
|
|
@@ -178,7 +182,8 @@ const TEXT_CONTENT_SHAPE = defineObjectShape()(['kind', 'text'], [
|
|
|
178
182
|
const THINKING_CONTENT_SHAPE = defineObjectShape()(['kind', 'text'], ['signature', 'providerOptions']);
|
|
179
183
|
const FUNCTION_CALL_CONTENT_SHAPE = defineObjectShape()(['kind', 'id', 'name', 'args'], ['providerOptions', 'providerExecuted']);
|
|
180
184
|
const FUNCTION_RESPONSE_CONTENT_SHAPE = defineObjectShape()(['kind', 'id', 'name', 'result'], ['isError', 'providerExecuted', 'providerOutput', 'modelProjection']);
|
|
181
|
-
const ERROR_CONTENT_SHAPE = defineObjectShape()(['kind', 'message'], ['code', 'reason', 'details']);
|
|
185
|
+
const ERROR_CONTENT_SHAPE = defineObjectShape()(['kind', 'message'], ['code', 'reason', 'details', 'retry']);
|
|
186
|
+
const SYSTEM_NOTE_CONTENT_SHAPE = defineObjectShape()(['kind', 'note'], ['data']);
|
|
182
187
|
const INVOCATION_OPENED_CONTENT_SHAPE = defineObjectShape()(['kind', 'protocol', 'route', 'configuration', 'root', 'source'], ['lineage']);
|
|
183
188
|
const INVOCATION_ROUTE_RUNTIME_SHAPE = defineObjectShape()(['provenance', 'backendKind', 'llmConnectionId', 'llmConnectionSlug', 'modelId'], ['providerStateIdentity']);
|
|
184
189
|
const INVOCATION_ROUTE_UNKNOWN_SHAPE = defineObjectShape()(['provenance', 'backendKind', 'llmConnectionSlug', 'modelId'], []);
|
|
@@ -204,6 +209,16 @@ const INVOCATION_LINEAGE_SHAPE = defineObjectShape()([], [
|
|
|
204
209
|
]);
|
|
205
210
|
const INVOCATION_CONTINUATION_SOURCE_SHAPE = defineObjectShape()(['kind', 'sourceInvocationId', 'sourceRunId', 'sourceTurnId', 'sourceRuntimeEventHighWater'], ['claimId', 'boundaryDigest']);
|
|
206
211
|
const INVOCATION_FRESH_SOURCE_SHAPE = defineObjectShape()(['kind'], []);
|
|
212
|
+
const INVOCATION_HANDOFF_SOURCE_SHAPE = defineObjectShape()([
|
|
213
|
+
'kind',
|
|
214
|
+
'rootRunId',
|
|
215
|
+
'sourceInvocationId',
|
|
216
|
+
'sourceRunId',
|
|
217
|
+
'sourceTurnId',
|
|
218
|
+
'sourceRuntimeEventHighWater',
|
|
219
|
+
'claimId',
|
|
220
|
+
'boundaryDigest',
|
|
221
|
+
], []);
|
|
207
222
|
const INVOCATION_ROOT_SHAPES = {
|
|
208
223
|
user: defineObjectShape()(['kind'], []),
|
|
209
224
|
context_compact: defineObjectShape()(['kind'], []),
|
|
@@ -213,6 +228,7 @@ const INVOCATION_ROOT_SHAPES = {
|
|
|
213
228
|
legacy_automation: defineObjectShape()(['kind', 'legacyAutomationId'], []),
|
|
214
229
|
};
|
|
215
230
|
const RUNTIME_ACTIONS_SHAPE = defineObjectShape()([], [
|
|
231
|
+
'handoffPause',
|
|
216
232
|
'stateDelta',
|
|
217
233
|
'artifactDelta',
|
|
218
234
|
'permissionRequest',
|
|
@@ -236,7 +252,7 @@ const RUNTIME_ACTIONS_SHAPE = defineObjectShape()([], [
|
|
|
236
252
|
const RUNTIME_MANAGED_MUTATION_TERMINAL_SHAPE = defineObjectShape()(['protocol', 'operationId', 'dispatchEventId', 'workspaceInstanceId', 'terminalKind'], []);
|
|
237
253
|
const ANSWER_ACCEPTED_IDENTITY_SHAPE = defineObjectShape()(['requestId'], []);
|
|
238
254
|
const PERMISSION_CLOSURE_ACCEPTED_SHAPE = defineObjectShape()(['requestId', 'reason'], []);
|
|
239
|
-
const RUNTIME_PERMISSION_DECISION_SHAPE = defineObjectShape()(['requestId', 'decision'], ['rememberForTurn', 'reviewer', 'rationale', 'riskLevel', 'toolName']);
|
|
255
|
+
const RUNTIME_PERMISSION_DECISION_SHAPE = defineObjectShape()(['requestId', 'decision'], ['rememberForTurn', 'reviewer', 'rationale', 'riskLevel', 'toolName', 'hint']);
|
|
240
256
|
const UTF8 = new TextEncoder();
|
|
241
257
|
const RUNTIME_TOOL_DISPATCH_SHAPE = defineObjectShape()([
|
|
242
258
|
'protocol',
|
|
@@ -341,6 +357,7 @@ export function decodeRuntimeEvent(value) {
|
|
|
341
357
|
(value.refs !== undefined && !isRuntimeEventRefs(value.refs))) {
|
|
342
358
|
throw new Error('Invalid RuntimeEvent schema');
|
|
343
359
|
}
|
|
360
|
+
runtimeHandoffPause(value);
|
|
344
361
|
if (isRecord(value.content) && value.content.kind === 'text') {
|
|
345
362
|
return {
|
|
346
363
|
...value,
|
|
@@ -415,8 +432,13 @@ function isRuntimeEventContent(value) {
|
|
|
415
432
|
return (hasExactShape(value, ERROR_CONTENT_SHAPE) &&
|
|
416
433
|
isOptionalString(value.code) &&
|
|
417
434
|
isOptionalString(value.reason) &&
|
|
435
|
+
(value.retry === undefined || isModelRetryDecision(value.retry)) &&
|
|
418
436
|
typeof value.message === 'string' &&
|
|
419
437
|
(value.details === undefined || isStringArray(value.details) || isRecord(value.details)));
|
|
438
|
+
case 'system_note':
|
|
439
|
+
return (hasExactShape(value, SYSTEM_NOTE_CONTENT_SHAPE) &&
|
|
440
|
+
typeof value.note === 'string' &&
|
|
441
|
+
isRuntimeSystemNoteKind(value.note));
|
|
420
442
|
case 'invocation_opened':
|
|
421
443
|
return isRuntimeInvocationOpened(value);
|
|
422
444
|
default:
|
|
@@ -508,8 +530,14 @@ function isRuntimeInvocationOpenSource(value) {
|
|
|
508
530
|
return false;
|
|
509
531
|
if (value.kind === 'fresh')
|
|
510
532
|
return hasExactShape(value, INVOCATION_FRESH_SOURCE_SHAPE);
|
|
511
|
-
return (value.kind === 'continuation' &&
|
|
512
|
-
hasExactShape(value, INVOCATION_CONTINUATION_SOURCE_SHAPE)
|
|
533
|
+
return (((value.kind === 'continuation' &&
|
|
534
|
+
hasExactShape(value, INVOCATION_CONTINUATION_SOURCE_SHAPE)) ||
|
|
535
|
+
(value.kind === 'handoff' &&
|
|
536
|
+
hasExactShape(value, INVOCATION_HANDOFF_SOURCE_SHAPE) &&
|
|
537
|
+
isNonEmptyString(value.rootRunId) &&
|
|
538
|
+
isNonEmptyString(value.claimId) &&
|
|
539
|
+
isSha256Digest(value.boundaryDigest) &&
|
|
540
|
+
value.sourceRuntimeEventHighWater > 0)) &&
|
|
513
541
|
isNonEmptyString(value.sourceInvocationId) &&
|
|
514
542
|
isNonEmptyString(value.sourceRunId) &&
|
|
515
543
|
isNonEmptyString(value.sourceTurnId) &&
|
|
@@ -554,7 +582,8 @@ function isRuntimeEventActions(value) {
|
|
|
554
582
|
Object.keys(value).some((key) => key !== 'permissionClosureAccepted')) {
|
|
555
583
|
return false;
|
|
556
584
|
}
|
|
557
|
-
return ((value.
|
|
585
|
+
return ((value.handoffPause === undefined || isRuntimeHandoffPause(value.handoffPause)) &&
|
|
586
|
+
(value.stateDelta === undefined || isRecord(value.stateDelta)) &&
|
|
558
587
|
(value.artifactDelta === undefined ||
|
|
559
588
|
(isRecord(value.artifactDelta) &&
|
|
560
589
|
Object.values(value.artifactDelta).every((item) => typeof item === 'string' || typeof item === 'boolean' || isFiniteNumber(item)))) &&
|
|
@@ -621,7 +650,8 @@ function isRuntimeEventPermissionDecision(value) {
|
|
|
621
650
|
(value.toolName === undefined ||
|
|
622
651
|
(typeof value.toolName === 'string' &&
|
|
623
652
|
value.toolName.length > 0 &&
|
|
624
|
-
UTF8.encode(value.toolName).byteLength <= INTERACTION_TOOL_NAME_MAX_BYTES))
|
|
653
|
+
UTF8.encode(value.toolName).byteLength <= INTERACTION_TOOL_NAME_MAX_BYTES)) &&
|
|
654
|
+
isOptionalString(value.hint));
|
|
625
655
|
}
|
|
626
656
|
function isRuntimeEventAnswerAcceptedIdentity(value) {
|
|
627
657
|
return (isRecord(value) &&
|
|
@@ -804,6 +834,7 @@ export function runtimeEventHasModelVisibleContent(event) {
|
|
|
804
834
|
case 'function_response':
|
|
805
835
|
return true;
|
|
806
836
|
case 'error':
|
|
837
|
+
case 'system_note':
|
|
807
838
|
case 'invocation_opened':
|
|
808
839
|
return false;
|
|
809
840
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { defineObjectShape, hasExactShape, isRecord } from './record-schema.js';
|
|
20
|
+
import { stableJsonStringify } from './tool-args-identity.js';
|
|
21
|
+
const PAUSE_SHAPE = defineObjectShape()([
|
|
22
|
+
'protocol',
|
|
23
|
+
'handoffId',
|
|
24
|
+
'hostEpoch',
|
|
25
|
+
'rootRunId',
|
|
26
|
+
'successorRunId',
|
|
27
|
+
'successorInvocationId',
|
|
28
|
+
'claimId',
|
|
29
|
+
'remainingSteps',
|
|
30
|
+
], []);
|
|
31
|
+
export function isRuntimeHandoffPause(value) {
|
|
32
|
+
return (isRecord(value) &&
|
|
33
|
+
hasExactShape(value, PAUSE_SHAPE) &&
|
|
34
|
+
value.protocol === 'runtime_handoff_pause_v1' &&
|
|
35
|
+
(value.remainingSteps === null ||
|
|
36
|
+
(Number.isSafeInteger(value.remainingSteps) && value.remainingSteps > 0)) &&
|
|
37
|
+
[
|
|
38
|
+
value.handoffId,
|
|
39
|
+
value.hostEpoch,
|
|
40
|
+
value.rootRunId,
|
|
41
|
+
value.successorRunId,
|
|
42
|
+
value.successorInvocationId,
|
|
43
|
+
value.claimId,
|
|
44
|
+
].every((id) => typeof id === 'string' &&
|
|
45
|
+
id.length > 0 &&
|
|
46
|
+
id.length <= 256 &&
|
|
47
|
+
!/[\u0000-\u001f\u007f]/u.test(id)));
|
|
48
|
+
}
|
|
49
|
+
/** The seal cannot simultaneously publish content or claim a logical outcome. */
|
|
50
|
+
export function runtimeHandoffPause(event) {
|
|
51
|
+
const pause = event.actions?.handoffPause;
|
|
52
|
+
if (pause === undefined)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (!isRuntimeHandoffPause(pause) ||
|
|
55
|
+
event.partial !== false ||
|
|
56
|
+
event.role !== 'system' ||
|
|
57
|
+
(event.author !== 'host' && event.author !== 'system') ||
|
|
58
|
+
event.status !== undefined ||
|
|
59
|
+
event.content !== undefined ||
|
|
60
|
+
event.actions?.endInvocation !== true ||
|
|
61
|
+
Object.keys(event.actions).some((key) => key !== 'endInvocation' && key !== 'handoffPause') ||
|
|
62
|
+
pause.successorRunId === event.runId ||
|
|
63
|
+
pause.successorRunId === event.invocationId ||
|
|
64
|
+
pause.successorInvocationId === event.invocationId ||
|
|
65
|
+
pause.successorRunId === pause.rootRunId) {
|
|
66
|
+
throw new Error('Invalid Runtime handoff pause seal');
|
|
67
|
+
}
|
|
68
|
+
return pause;
|
|
69
|
+
}
|
|
70
|
+
/** Verify against source facts, not the proposed claim's description of them. */
|
|
71
|
+
export function assertHandoffClaimSource(claim, prefix) {
|
|
72
|
+
const last = prefix.events.at(-1);
|
|
73
|
+
const pause = last && runtimeHandoffPause(last);
|
|
74
|
+
const source = claim.targetOpening.source;
|
|
75
|
+
if (source.kind !== 'handoff') {
|
|
76
|
+
if (pause)
|
|
77
|
+
throw new Error('A handoff pause is reserved for its authorized successor');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const opening = prefix.events[0]?.content;
|
|
81
|
+
if (!pause ||
|
|
82
|
+
opening?.kind !== 'invocation_opened' ||
|
|
83
|
+
prefix.identity.sessionId !== claim.target.sessionId ||
|
|
84
|
+
prefix.identity.turnId !== claim.target.turnId ||
|
|
85
|
+
pause.claimId !== claim.claimId ||
|
|
86
|
+
pause.successorRunId !== claim.target.runId ||
|
|
87
|
+
pause.successorInvocationId !== claim.target.invocationId ||
|
|
88
|
+
pause.rootRunId !== source.rootRunId ||
|
|
89
|
+
pause.rootRunId !==
|
|
90
|
+
(opening.source.kind === 'handoff' ? opening.source.rootRunId : prefix.identity.runId) ||
|
|
91
|
+
stableJsonStringify(opening.root) !== stableJsonStringify(claim.targetOpening.root) ||
|
|
92
|
+
stableJsonStringify(opening.configuration) !==
|
|
93
|
+
stableJsonStringify(claim.targetOpening.configuration) ||
|
|
94
|
+
stableJsonStringify(opening.lineage ?? null) !==
|
|
95
|
+
stableJsonStringify(claim.targetOpening.lineage ?? null)) {
|
|
96
|
+
throw new Error('Handoff claim does not preserve the sealed source authority');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -149,7 +149,7 @@ export function runtimeInvocationOutcome(record) {
|
|
|
149
149
|
export function isSessionInlineInvocation(opening) {
|
|
150
150
|
const lineage = opening.lineage;
|
|
151
151
|
return (lineage?.parentRunId === undefined ||
|
|
152
|
-
(opening.source.kind
|
|
152
|
+
(opening.source.kind !== 'fresh' && lineage.agentId === undefined));
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* Is this invocation the one the Host admitted for that root execution?
|
|
@@ -0,0 +1,112 @@
|
|
|
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 { continuationStartEventMatchesClaim, createRuntimeBoundaryCursor, invocationMatchesClaimTarget, runtimePrefixSegment, } from './runtime-boundary.js';
|
|
20
|
+
import { readRunInvocation, } from './runtime-event-store.js';
|
|
21
|
+
import { assertHandoffClaimSource, runtimeHandoffPause, } from './runtime-handoff.js';
|
|
22
|
+
/** All logical snapshot and command routing paths share these edge checks. */
|
|
23
|
+
export async function readLogicalRuntimeExecution(store, identity, knownRoot) {
|
|
24
|
+
const root = knownRoot ?? (await readRunInvocation(store, identity.sessionId, identity.runId));
|
|
25
|
+
if (!root)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (root.sessionId !== identity.sessionId ||
|
|
28
|
+
root.runId !== identity.runId ||
|
|
29
|
+
root.turnId !== identity.turnId ||
|
|
30
|
+
root.opening.source.kind === 'handoff') {
|
|
31
|
+
throw new Error('Logical execution reference does not name its original admission');
|
|
32
|
+
}
|
|
33
|
+
let tip = root;
|
|
34
|
+
let segments;
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
for (;;) {
|
|
37
|
+
if (seen.has(tip.runId) || seen.size >= 64)
|
|
38
|
+
throw new Error('Invalid logical execution handoff lineage');
|
|
39
|
+
seen.add(tip.runId);
|
|
40
|
+
const events = await store.readImmutableRuntimeEvents(identity.sessionId, tip.runId);
|
|
41
|
+
const last = events.at(-1);
|
|
42
|
+
const pause = last && runtimeHandoffPause(last);
|
|
43
|
+
if (!pause)
|
|
44
|
+
return { root, tip, events, runIds: [...seen] };
|
|
45
|
+
if (pause.rootRunId !== root.runId)
|
|
46
|
+
throw new Error('Handoff seal changes the logical root');
|
|
47
|
+
const prefix = await store.readImmutableRuntimePrefix({
|
|
48
|
+
sessionId: identity.sessionId,
|
|
49
|
+
runId: tip.runId,
|
|
50
|
+
});
|
|
51
|
+
if (prefix.position.lastEventId !== last.id)
|
|
52
|
+
throw new Error('Handoff source changed after its seal');
|
|
53
|
+
if (!segments) {
|
|
54
|
+
// A manual continuation may itself become a handoff root. Preserve its
|
|
55
|
+
// earlier replay boundary without treating those earlier Turns as this Turn.
|
|
56
|
+
const source = root.opening.source;
|
|
57
|
+
if (source.kind === 'continuation') {
|
|
58
|
+
if (!source.boundaryDigest)
|
|
59
|
+
throw new Error('Handoff requires authenticated source lineage');
|
|
60
|
+
const initial = await store.readContinuationClaimStateByBoundary(source.boundaryDigest);
|
|
61
|
+
if (!initial ||
|
|
62
|
+
initial.startEventId !== prefix.events[0]?.id ||
|
|
63
|
+
!invocationMatchesClaimTarget(root, initial.claim) ||
|
|
64
|
+
!continuationStartEventMatchesClaim(prefix.events[0], initial.claim, initial.startKind)) {
|
|
65
|
+
throw new Error('Handoff root continuation is not authenticated');
|
|
66
|
+
}
|
|
67
|
+
segments = [...initial.claim.boundary.segments];
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
segments = [];
|
|
71
|
+
}
|
|
72
|
+
segments.push(runtimePrefixSegment(prefix));
|
|
73
|
+
const boundary = createRuntimeBoundaryCursor(segments);
|
|
74
|
+
let state = await store.readContinuationClaimStateByBoundary(boundary.manifestDigest);
|
|
75
|
+
const next = await readRunInvocation(store, identity.sessionId, pause.successorRunId);
|
|
76
|
+
// A start can commit between the two reads. Authority is monotonic; refresh
|
|
77
|
+
// it once when the later opening read proves the earlier snapshot was old.
|
|
78
|
+
if (next && !state?.startEventId) {
|
|
79
|
+
state = await store.readContinuationClaimStateByBoundary(boundary.manifestDigest);
|
|
80
|
+
}
|
|
81
|
+
if (!state) {
|
|
82
|
+
if (next)
|
|
83
|
+
throw new Error('Handoff successor opened without its continuation claim');
|
|
84
|
+
return { root, tip, events, runIds: [...seen], pendingHandoff: pause };
|
|
85
|
+
}
|
|
86
|
+
assertHandoffClaimSource(state.claim, prefix);
|
|
87
|
+
if (!next) {
|
|
88
|
+
if (state.startEventId)
|
|
89
|
+
throw new Error('Handoff successor opening is missing');
|
|
90
|
+
return { root, tip, events, runIds: [...seen], pendingHandoff: pause };
|
|
91
|
+
}
|
|
92
|
+
const first = (await store.readImmutableRuntimeEvents(identity.sessionId, next.runId))[0];
|
|
93
|
+
if (state.startEventId !== first?.id ||
|
|
94
|
+
!invocationMatchesClaimTarget(next, state.claim) ||
|
|
95
|
+
!continuationStartEventMatchesClaim(first, state.claim, state.startKind)) {
|
|
96
|
+
throw new Error('Handoff successor does not match its authenticated start');
|
|
97
|
+
}
|
|
98
|
+
tip = next;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Resolve a durable physical proof back to its root, then authenticate membership. */
|
|
102
|
+
export async function readLogicalRuntimeExecutionForRun(store, identity) {
|
|
103
|
+
const run = await readRunInvocation(store, identity.sessionId, identity.runId);
|
|
104
|
+
if (!run)
|
|
105
|
+
return undefined;
|
|
106
|
+
const rootRunId = run.opening.source.kind === 'handoff' ? run.opening.source.rootRunId : run.runId;
|
|
107
|
+
const logical = await readLogicalRuntimeExecution(store, { ...identity, runId: rootRunId });
|
|
108
|
+
if (!logical?.runIds.includes(identity.runId)) {
|
|
109
|
+
throw new Error('Physical proof is not an authenticated member of its logical execution');
|
|
110
|
+
}
|
|
111
|
+
return logical;
|
|
112
|
+
}
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { MODEL_FAILURE_MESSAGE_MAX_BYTES, isModelRetryDecision, } from './model-failure.js';
|
|
19
20
|
import { decodeMessageContent, TOOL_ACTIVITY_KINDS, } from './events.js';
|
|
20
|
-
import { isToolCategory, } from './permission.js';
|
|
21
|
-
import { defineObjectShape, hasExactShape, isFiniteNumber, isOptionalString, isRecord, } from './record-schema.js';
|
|
21
|
+
import { isPermissionMode, isToolCategory, } from './permission.js';
|
|
22
|
+
import { defineObjectShape, hasExactShape, isFiniteNumber, isOptionalString, isRecord, pickShape, } from './record-schema.js';
|
|
22
23
|
import { isPermissionDecisionFields } from './interaction-record-schema.js';
|
|
23
24
|
import { isTokenUsageFields } from './usage-record-schema.js';
|
|
24
25
|
import { decodeCanonicalToolResultContent, decodePersistedToolResultContent, } from './tool-result-record-schema.js';
|
|
@@ -90,16 +91,7 @@ const SUBAGENT_SESSION_RUNTIME_SHAPE = defineObjectShape()([
|
|
|
90
91
|
'systemPrompt',
|
|
91
92
|
'toolNames',
|
|
92
93
|
'categoryPolicy',
|
|
93
|
-
], ['presetId']);
|
|
94
|
-
/**
|
|
95
|
-
* Keys older child sessions wrote that this type no longer has.
|
|
96
|
-
*
|
|
97
|
-
* `hasExactShape` rejects unknown keys, so without this a record written before
|
|
98
|
-
* the key was dropped would fail validation and make the whole child Session
|
|
99
|
-
* unreadable. Nothing reads the values, and they stay in the stored JSON as
|
|
100
|
-
* written — this only stops their presence from being treated as corruption.
|
|
101
|
-
*/
|
|
102
|
-
const RETIRED_SUBAGENT_RUNTIME_KEYS = ['permissionCeiling'];
|
|
94
|
+
], ['presetId'], ['permissionCeiling']);
|
|
103
95
|
const SUBAGENT_SESSION_SPAWN_IDENTITY_SHAPE = defineObjectShape()(['schemaVersion', 'requestFingerprint', 'initialTurnId', 'initialRunId'], []);
|
|
104
96
|
const SESSION_CONVERSATION_COPY_SHAPE = defineObjectShape()(['kind', 'sourceSessionId', 'requestFingerprint', 'state'], ['sourceTurnId', 'intent']);
|
|
105
97
|
const SESSION_LINEAGE_ID_MAX_CHARS = 512;
|
|
@@ -135,15 +127,10 @@ export function isSubagentSessionParent(value) {
|
|
|
135
127
|
isSessionLineageId(value.graph.operatorId));
|
|
136
128
|
return swarmValid && graphValid && !(value.swarm && value.graph);
|
|
137
129
|
}
|
|
138
|
-
function withoutRetiredSubagentRuntimeKeys(value) {
|
|
139
|
-
if (!RETIRED_SUBAGENT_RUNTIME_KEYS.some((key) => Object.hasOwn(value, key)))
|
|
140
|
-
return value;
|
|
141
|
-
return Object.fromEntries(Object.entries(value).filter(([key]) => !RETIRED_SUBAGENT_RUNTIME_KEYS.includes(key)));
|
|
142
|
-
}
|
|
143
130
|
/** Strict decoder guard for the persisted child execution snapshot. */
|
|
144
131
|
export function isSubagentSessionRuntime(value) {
|
|
145
132
|
if (!isRecord(value) ||
|
|
146
|
-
!hasExactShape(
|
|
133
|
+
!hasExactShape(value, SUBAGENT_SESSION_RUNTIME_SHAPE) ||
|
|
147
134
|
value.schemaVersion !== SUBAGENT_SESSION_RUNTIME_SCHEMA_VERSION ||
|
|
148
135
|
!Number.isSafeInteger(value.definitionVersion) ||
|
|
149
136
|
value.definitionVersion < 1 ||
|
|
@@ -286,23 +273,29 @@ function isSubagentCategoryPolicy(value) {
|
|
|
286
273
|
export function userFacingText(message) {
|
|
287
274
|
return message.displayText ?? message.text;
|
|
288
275
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
'context_window_suggestion',
|
|
294
|
-
'context_window_overrun',
|
|
295
|
-
'context_reported_window_exceeded',
|
|
296
|
-
'context_overflow_after_compaction',
|
|
297
|
-
'step_limit',
|
|
298
|
-
]);
|
|
299
|
-
/** Closed policy for system notes that are part of the user-visible transcript. */
|
|
276
|
+
/**
|
|
277
|
+
* Closed policy for system notes that are part of the user-visible transcript:
|
|
278
|
+
* exactly the notes the runtime writes.
|
|
279
|
+
*/
|
|
300
280
|
export function isUserVisibleSessionSystemNote(kind) {
|
|
301
|
-
return
|
|
281
|
+
return isRuntimeSystemNoteKind(kind);
|
|
302
282
|
}
|
|
303
283
|
export const WORKHUB_COORDINATION_RECORD_SCHEMA_VERSION = 1;
|
|
304
284
|
export const WORKHUB_COORDINATION_REPLACEMENT_SCHEMA_VERSION = 2;
|
|
305
285
|
export const WORKHUB_COORDINATION_STOP_SCHEMA_VERSION = 3;
|
|
286
|
+
export function isWorkHubCreateDefaults(value) {
|
|
287
|
+
if (!isRecord(value) ||
|
|
288
|
+
Object.keys(value).some((key) => key !== 'model' && key !== 'permissionMode'))
|
|
289
|
+
return false;
|
|
290
|
+
if (value.permissionMode !== undefined && !isPermissionMode(value.permissionMode))
|
|
291
|
+
return false;
|
|
292
|
+
if (value.model === undefined)
|
|
293
|
+
return true;
|
|
294
|
+
const model = value.model;
|
|
295
|
+
return (isRecord(model) &&
|
|
296
|
+
Object.keys(model).length === 3 &&
|
|
297
|
+
['llmConnectionId', 'llmConnectionSlug', 'model'].every((key) => typeof model[key] === 'string' && model[key].trim().length > 0 && model[key].length <= 512));
|
|
298
|
+
}
|
|
306
299
|
function isWorkHubDelegationStopResolution(outcome, targetTurnId) {
|
|
307
300
|
const hasTargetTurnId = typeof targetTurnId === 'string' && targetTurnId.length > 0;
|
|
308
301
|
if (outcome === 'stop_delivered' || outcome === 'not_owned')
|
|
@@ -311,6 +304,36 @@ function isWorkHubDelegationStopResolution(outcome, targetTurnId) {
|
|
|
311
304
|
return targetTurnId === undefined;
|
|
312
305
|
return outcome === 'already_terminal' && (targetTurnId === undefined || hasTargetTurnId);
|
|
313
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* The notes the runtime writes: things that happened inside one invocation and
|
|
309
|
+
* are part of what that invocation did. Their record is its RuntimeEvent ledger.
|
|
310
|
+
*/
|
|
311
|
+
export const RUNTIME_SYSTEM_NOTE_KINDS = [
|
|
312
|
+
'context_compacted',
|
|
313
|
+
'context_compaction_failed_open',
|
|
314
|
+
'context_provider_dropping',
|
|
315
|
+
'context_window_suggestion',
|
|
316
|
+
'context_window_overrun',
|
|
317
|
+
'context_reported_window_exceeded',
|
|
318
|
+
'context_overflow_after_compaction',
|
|
319
|
+
'step_limit',
|
|
320
|
+
];
|
|
321
|
+
/**
|
|
322
|
+
* Notes only legacy transcripts carry, still decoded so those rows stay
|
|
323
|
+
* readable. Nothing writes them: the Session header and the invocation's
|
|
324
|
+
* opening and terminal facts already own what each of them said.
|
|
325
|
+
*/
|
|
326
|
+
export const RETIRED_SYSTEM_NOTE_KINDS = [
|
|
327
|
+
'session_start',
|
|
328
|
+
'session_resume',
|
|
329
|
+
'mode_change',
|
|
330
|
+
'model_change',
|
|
331
|
+
'error',
|
|
332
|
+
'abort',
|
|
333
|
+
];
|
|
334
|
+
export function isRuntimeSystemNoteKind(kind) {
|
|
335
|
+
return RUNTIME_SYSTEM_NOTE_KINDS.includes(kind);
|
|
336
|
+
}
|
|
314
337
|
const USER_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 'ts', 'text'], [
|
|
315
338
|
'displayText',
|
|
316
339
|
'attachments',
|
|
@@ -366,7 +389,7 @@ const TOKEN_USAGE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', '
|
|
|
366
389
|
'providerRequestTraceId',
|
|
367
390
|
'lastRequestAnchor',
|
|
368
391
|
]);
|
|
369
|
-
const TURN_STATE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 'ts', 'status'
|
|
392
|
+
const TURN_STATE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 'ts', 'status'], [
|
|
370
393
|
'parentTurnId',
|
|
371
394
|
'retriedFromTurnId',
|
|
372
395
|
'regeneratedFromTurnId',
|
|
@@ -375,7 +398,9 @@ const TURN_STATE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 't
|
|
|
375
398
|
'abortedAt',
|
|
376
399
|
'abortSource',
|
|
377
400
|
'errorClass',
|
|
378
|
-
|
|
401
|
+
'failureMessage',
|
|
402
|
+
'retry',
|
|
403
|
+
], ['partialOutputRetained']);
|
|
379
404
|
const WORKHUB_DELEGATION_ASSIGNED_MESSAGE_SHAPE = defineObjectShape()([
|
|
380
405
|
'type',
|
|
381
406
|
'id',
|
|
@@ -393,7 +418,7 @@ const WORKHUB_DELEGATION_ASSIGNED_MESSAGE_SHAPE = defineObjectShape()([
|
|
|
393
418
|
'targetTurnId',
|
|
394
419
|
'targetMessageId',
|
|
395
420
|
'targetSessionName',
|
|
396
|
-
], ['create', 'steered', 'replacesActionId', 'replacesDelegationId']);
|
|
421
|
+
], ['attachments', 'create', 'steered', 'replacesActionId', 'replacesDelegationId']);
|
|
397
422
|
const WORKHUB_DELEGATION_REPLACEMENT_REQUESTED_MESSAGE_SHAPE = defineObjectShape()([
|
|
398
423
|
'type',
|
|
399
424
|
'id',
|
|
@@ -412,7 +437,7 @@ const WORKHUB_DELEGATION_REPLACEMENT_REQUESTED_MESSAGE_SHAPE = defineObjectShape
|
|
|
412
437
|
'replacedTargetSessionId',
|
|
413
438
|
'replacedTargetMessageId',
|
|
414
439
|
'targetSessionName',
|
|
415
|
-
], ['create']);
|
|
440
|
+
], ['attachments', 'create']);
|
|
416
441
|
const WORKHUB_DELEGATION_SUPERSEDED_MESSAGE_SHAPE = defineObjectShape()([
|
|
417
442
|
'type',
|
|
418
443
|
'id',
|
|
@@ -474,27 +499,15 @@ const WORKHUB_DELEGATION_STOP_RESOLVED_MESSAGE_SHAPE = defineObjectShape()([
|
|
|
474
499
|
'targetSessionId',
|
|
475
500
|
'outcome',
|
|
476
501
|
], ['targetTurnId']);
|
|
477
|
-
const WORKHUB_DELEGATION_CREATE_SHAPE = defineObjectShape()(['title', 'workspace'], []);
|
|
502
|
+
const WORKHUB_DELEGATION_CREATE_SHAPE = defineObjectShape()(['title', 'workspace'], ['defaults']);
|
|
478
503
|
const WORKHUB_DELEGATION_PROJECT_WORKSPACE_SHAPE = defineObjectShape()(['kind', 'projectId'], []);
|
|
479
504
|
const WORKHUB_DELEGATION_HOST_PATH_WORKSPACE_SHAPE = defineObjectShape()(['kind', 'path'], []);
|
|
480
505
|
const SYSTEM_NOTE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'ts', 'kind'], ['turnId', 'data']);
|
|
481
506
|
const ASSISTANT_THINKING_PART_SHAPE = defineObjectShape()(['text'], ['signature', 'providerOptions']);
|
|
482
507
|
const ASSISTANT_THINKING_SHAPE = defineObjectShape()(['text'], ['signature', 'providerOptions', 'parts']);
|
|
483
508
|
const SYSTEM_NOTE_KINDS = new Set([
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
'mode_change',
|
|
487
|
-
'model_change',
|
|
488
|
-
'context_compacted',
|
|
489
|
-
'context_compaction_failed_open',
|
|
490
|
-
'context_provider_dropping',
|
|
491
|
-
'context_window_suggestion',
|
|
492
|
-
'context_window_overrun',
|
|
493
|
-
'context_reported_window_exceeded',
|
|
494
|
-
'context_overflow_after_compaction',
|
|
495
|
-
'step_limit',
|
|
496
|
-
'error',
|
|
497
|
-
'abort',
|
|
509
|
+
...RUNTIME_SYSTEM_NOTE_KINDS,
|
|
510
|
+
...RETIRED_SYSTEM_NOTE_KINDS,
|
|
498
511
|
]);
|
|
499
512
|
export function decodeCanonicalMessage(value) {
|
|
500
513
|
return decodeMessage(value, decodeCanonicalToolResultContent);
|
|
@@ -588,7 +601,6 @@ function decodeMessage(value, decodeToolResultContent) {
|
|
|
588
601
|
if (hasExactShape(message, TURN_STATE_MESSAGE_SHAPE) &&
|
|
589
602
|
hasMessageEnvelope(message, true) &&
|
|
590
603
|
isTurnStatus(message.status) &&
|
|
591
|
-
typeof message.partialOutputRetained === 'boolean' &&
|
|
592
604
|
isOptionalString(message.parentTurnId) &&
|
|
593
605
|
isOptionalString(message.retriedFromTurnId) &&
|
|
594
606
|
isOptionalString(message.regeneratedFromTurnId) &&
|
|
@@ -596,8 +608,13 @@ function decodeMessage(value, decodeToolResultContent) {
|
|
|
596
608
|
isOptionalString(message.parentSessionId) &&
|
|
597
609
|
(message.abortedAt === undefined || isFiniteNumber(message.abortedAt)) &&
|
|
598
610
|
isOptionalString(message.abortSource) &&
|
|
599
|
-
isOptionalString(message.errorClass)
|
|
600
|
-
|
|
611
|
+
isOptionalString(message.errorClass) &&
|
|
612
|
+
(message.failureMessage === undefined ||
|
|
613
|
+
(typeof message.failureMessage === 'string' &&
|
|
614
|
+
new TextEncoder().encode(message.failureMessage).byteLength <=
|
|
615
|
+
MODEL_FAILURE_MESSAGE_MAX_BYTES)) &&
|
|
616
|
+
(message.retry === undefined || isModelRetryDecision(message.retry)))
|
|
617
|
+
return pickShape(message, TURN_STATE_MESSAGE_SHAPE);
|
|
601
618
|
break;
|
|
602
619
|
case 'workhub_coordination':
|
|
603
620
|
if (isWorkHubCoordinationMessage(message)) {
|
|
@@ -690,6 +707,7 @@ function isWorkHubCoordinationMessage(message) {
|
|
|
690
707
|
typeof message.targetSessionId === 'string' &&
|
|
691
708
|
typeof message.userText === 'string' &&
|
|
692
709
|
message.userText.trim().length > 0 &&
|
|
710
|
+
isWorkHubMessageAttachments(message.attachments) &&
|
|
693
711
|
((message.disposition === 'delegate_existing' && message.create === undefined) ||
|
|
694
712
|
(message.disposition === 'create_new' && isWorkHubDelegationCreateSpec(message.create))) &&
|
|
695
713
|
(message.disposition === 'delegate_existing' || message.disposition === 'create_new');
|
|
@@ -735,9 +753,21 @@ function isWorkHubActionIdentity(message) {
|
|
|
735
753
|
message.coordinationTurnId.length > 0 &&
|
|
736
754
|
message.turnId === message.coordinationTurnId);
|
|
737
755
|
}
|
|
756
|
+
function isWorkHubMessageAttachments(value) {
|
|
757
|
+
if (value === undefined)
|
|
758
|
+
return true;
|
|
759
|
+
try {
|
|
760
|
+
decodeMessageContent({ text: '', attachments: value });
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
catch {
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
738
767
|
function isWorkHubDelegationCreateSpec(value) {
|
|
739
768
|
if (!isRecord(value) ||
|
|
740
769
|
!hasExactShape(value, WORKHUB_DELEGATION_CREATE_SHAPE) ||
|
|
770
|
+
(value.defaults !== undefined && !isWorkHubCreateDefaults(value.defaults)) ||
|
|
741
771
|
typeof value.title !== 'string' ||
|
|
742
772
|
value.title.trim().length === 0 ||
|
|
743
773
|
!isRecord(value.workspace)) {
|
|
@@ -823,8 +853,6 @@ export function deriveTurnRecords(messages) {
|
|
|
823
853
|
const latestState = bucket
|
|
824
854
|
.filter((message) => message.type === 'turn_state')
|
|
825
855
|
.at(-1);
|
|
826
|
-
const partialOutputRetained = bucket.some((message) => (message.type === 'assistant' && message.text.trim().length > 0) ||
|
|
827
|
-
message.type === 'tool_result');
|
|
828
856
|
if (latestState) {
|
|
829
857
|
return {
|
|
830
858
|
turnId,
|
|
@@ -842,14 +870,14 @@ export function deriveTurnRecords(messages) {
|
|
|
842
870
|
...(latestState.abortedAt !== undefined ? { abortedAt: latestState.abortedAt } : {}),
|
|
843
871
|
...(latestState.abortSource ? { abortSource: latestState.abortSource } : {}),
|
|
844
872
|
...(latestState.errorClass ? { errorClass: latestState.errorClass } : {}),
|
|
845
|
-
|
|
873
|
+
...(latestState.failureMessage ? { failureMessage: latestState.failureMessage } : {}),
|
|
874
|
+
...(latestState.retry ? { retry: latestState.retry } : {}),
|
|
846
875
|
};
|
|
847
876
|
}
|
|
848
877
|
return {
|
|
849
878
|
turnId,
|
|
850
879
|
status: inferLegacyTurnStatus(bucket),
|
|
851
880
|
statusSource: 'inferred',
|
|
852
|
-
partialOutputRetained,
|
|
853
881
|
};
|
|
854
882
|
});
|
|
855
883
|
}
|
|
@@ -24,6 +24,7 @@ export const SLASH_COMMAND_CATALOG = [
|
|
|
24
24
|
{ id: 'goal', session: 'required', surfaces: ['tui'] },
|
|
25
25
|
{ id: 'graph', session: 'none', surfaces: ['desktop', 'tui'] },
|
|
26
26
|
{ id: 'help', session: 'none', surfaces: ['tui'] },
|
|
27
|
+
{ id: 'host', session: 'none', surfaces: ['tui'] },
|
|
27
28
|
{ id: 'mcp', session: 'none', surfaces: ['tui'] },
|
|
28
29
|
{ id: 'model', session: 'required', surfaces: ['tui'] },
|
|
29
30
|
{ id: 'move', session: 'required', surfaces: ['tui'] },
|
|
@@ -39,7 +40,9 @@ export const SLASH_COMMAND_CATALOG = [
|
|
|
39
40
|
{ id: 'skill', session: 'required', surfaces: ['tui'] },
|
|
40
41
|
{ id: 'swarm', session: 'none', surfaces: ['desktop', 'tui'] },
|
|
41
42
|
{ id: 'thinking', session: 'required', surfaces: ['tui'] },
|
|
43
|
+
{ id: 'todo', session: 'required', surfaces: ['tui'] },
|
|
42
44
|
{ id: 'transcript', session: 'required', surfaces: ['tui'] },
|
|
45
|
+
{ id: 'update', session: 'none', surfaces: ['tui'] },
|
|
43
46
|
];
|
|
44
47
|
export function slashCommandsForSurface(surface) {
|
|
45
48
|
return SLASH_COMMAND_CATALOG.filter((command) => command.surfaces.includes(surface));
|