@sema-agent/core 7.58.0 → 7.60.0
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/CHANGELOG.md +1340 -0
- package/README.md +6 -4
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-definition.js +12 -0
- package/dist/agents/agent-transcript-tool.d.ts +2 -1
- package/dist/agents/agent-transcript-tool.js +3 -1
- package/dist/agents/cc-peer-directory.js +8 -8
- package/dist/agents/child-model-seat.d.ts +4 -2
- package/dist/agents/child-model-seat.js +9 -4
- package/dist/agents/cumulative-stats.js +0 -1
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +22 -0
- package/dist/agents/peer-directory.d.ts +9 -0
- package/dist/agents/peer-directory.js +6 -2
- package/dist/agents/retain-ledger.d.ts +11 -1
- package/dist/agents/retain-ledger.js +13 -2
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/roster-store.js +3 -1
- package/dist/agents/send-message-tool.d.ts +8 -19
- package/dist/agents/send-message-tool.js +32 -50
- package/dist/agents/subagent.d.ts +51 -17
- package/dist/agents/subagent.js +150 -112
- package/dist/agents/tool-filter.d.ts +1 -3
- package/dist/agents/tool-filter.js +4 -12
- package/dist/bench/metrics.d.ts +3 -5
- package/dist/bench/metrics.js +0 -1
- package/dist/brain/anthropic.js +161 -45
- package/dist/brain/degrading.js +3 -1
- package/dist/brain/errors.d.ts +9 -3
- package/dist/brain/errors.js +7 -1
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +3 -3
- package/dist/brain/openai.js +103 -53
- package/dist/brain/provider-dialect.d.ts +11 -0
- package/dist/brain/provider-dialect.js +5 -2
- package/dist/brain/reasoning-request.js +5 -4
- package/dist/brain/reasoning.d.ts +19 -0
- package/dist/brain/reasoning.js +17 -2
- package/dist/brain/request-route.d.ts +4 -1
- package/dist/brain/request-route.js +4 -1
- package/dist/brain/route-adjudicator.d.ts +84 -18
- package/dist/brain/route-adjudicator.js +90 -22
- package/dist/brain/route-conformance.js +1 -1
- package/dist/brain/status-sink.d.ts +7 -1
- package/dist/brain/status-sink.js +6 -0
- package/dist/brain/stream-engine.js +84 -49
- package/dist/brain/stream-shared.d.ts +30 -0
- package/dist/brain/stream-shared.js +34 -1
- package/dist/brain/timeout.d.ts +65 -6
- package/dist/brain/timeout.js +111 -11
- package/dist/core/a2a.d.ts +15 -5
- package/dist/core/a2a.js +34 -19
- package/dist/core/account-row.d.ts +61 -0
- package/dist/core/account-row.js +51 -0
- package/dist/core/advisor-verdict.d.ts +2 -1
- package/dist/core/advisor-verdict.js +1 -1
- package/dist/core/agent-definition.d.ts +20 -0
- package/dist/core/allow-entry.d.ts +20 -6
- package/dist/core/allow-entry.js +17 -7
- package/dist/core/approval-object.d.ts +29 -15
- package/dist/core/approval-object.js +47 -19
- package/dist/core/artifact-host.d.ts +0 -2
- package/dist/core/artifact-host.js +0 -1
- package/dist/core/auto-compaction.js +1 -1
- package/dist/core/auto-mode-defaults.d.ts +8 -0
- package/dist/core/auto-mode-defaults.js +1 -0
- package/dist/core/auto-mode-rebuild.d.ts +2 -1
- package/dist/core/auto-mode.d.ts +39 -4
- package/dist/core/auto-mode.js +63 -12
- package/dist/core/background-agent-store.d.ts +26 -4
- package/dist/core/background-agent-store.js +3 -2
- package/dist/core/background-shell.d.ts +12 -1
- package/dist/core/background-shell.js +12 -0
- package/dist/core/checkpoint-requirements.d.ts +13 -1
- package/dist/core/checkpoint-requirements.js +3 -1
- package/dist/core/checkpoint-store.d.ts +66 -25
- package/dist/core/checkpoint-store.js +22 -9
- package/dist/core/child-clamp-seats.d.ts +29 -0
- package/dist/core/child-clamp-seats.js +56 -1
- package/dist/core/compliance.d.ts +3 -3
- package/dist/core/compliance.js +1 -1
- package/dist/core/credential-echo.d.ts +52 -0
- package/dist/core/credential-echo.js +65 -0
- package/dist/core/credential-vocabulary.d.ts +13 -3
- package/dist/core/credential-vocabulary.js +12 -4
- package/dist/core/cross-boundary-taint.d.ts +4 -5
- package/dist/core/effective-path-target.d.ts +8 -2
- package/dist/core/effective-path-target.js +8 -3
- package/dist/core/engine-notice.d.ts +156 -23
- package/dist/core/engine-notice.js +19 -5
- package/dist/core/frame-settlement.d.ts +5 -0
- package/dist/core/frame-settlement.js +4 -0
- package/dist/core/gate-fold.js +8 -6
- package/dist/core/gate-lanes.js +47 -12
- package/dist/core/gate-outcome.d.ts +32 -3
- package/dist/core/gate-outcome.js +19 -1
- package/dist/core/governance-codes.d.ts +17 -1
- package/dist/core/governance-codes.js +25 -0
- package/dist/core/hands-band-screen.js +0 -1
- package/dist/core/hands-band.d.ts +0 -3
- package/dist/core/hooks.d.ts +70 -59
- package/dist/core/hooks.js +125 -80
- package/dist/core/image-admission.d.ts +106 -52
- package/dist/core/image-admission.js +184 -56
- package/dist/core/image-downsample.d.ts +36 -69
- package/dist/core/image-downsample.js +111 -73
- package/dist/core/integer-option.d.ts +21 -0
- package/dist/core/integer-option.js +13 -0
- package/dist/core/locked-config.d.ts +59 -5
- package/dist/core/locked-config.js +82 -50
- package/dist/core/mailbox-store.d.ts +45 -1
- package/dist/core/mailbox-store.js +53 -9
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-call-meta.js +9 -10
- package/dist/core/mcp-failure.d.ts +122 -20
- package/dist/core/mcp-failure.js +73 -5
- package/dist/core/mcp-host-seat.d.ts +92 -0
- package/dist/core/mcp-host-seat.js +131 -0
- package/dist/core/mcp-probe.d.ts +7 -2
- package/dist/core/mcp-probe.js +7 -2
- package/dist/core/mcp-server-link.d.ts +22 -1
- package/dist/core/mcp-server-link.js +25 -1
- package/dist/core/mcp-server-spec.d.ts +38 -9
- package/dist/core/mcp-server-spec.js +55 -21
- package/dist/core/mcp.d.ts +27 -12
- package/dist/core/mcp.js +105 -76
- package/dist/core/memory-admission.d.ts +23 -6
- package/dist/core/memory-admission.js +19 -9
- package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
- package/dist/core/memory-engine/consolidation-driver.js +3 -3
- package/dist/core/memory-engine/consolidation.d.ts +4 -0
- package/dist/core/memory-engine/consolidation.js +1 -0
- package/dist/core/memory-engine/content-origin.d.ts +13 -0
- package/dist/core/memory-engine/content-origin.js +21 -3
- package/dist/core/memory-engine/delegation-settlement.js +5 -12
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +50 -1
- package/dist/core/memory-engine/dual-root.js +44 -1
- package/dist/core/memory-engine/engine.d.ts +67 -14
- package/dist/core/memory-engine/engine.js +384 -212
- package/dist/core/memory-engine/export-bundle.d.ts +23 -0
- package/dist/core/memory-engine/export-bundle.js +23 -4
- package/dist/core/memory-engine/file-backend.d.ts +128 -55
- package/dist/core/memory-engine/file-backend.js +290 -117
- package/dist/core/memory-engine/index.d.ts +3 -2
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/layout.d.ts +59 -11
- package/dist/core/memory-engine/layout.js +190 -40
- package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
- package/dist/core/memory-engine/memory-backend-contract.js +39 -2
- package/dist/core/memory-engine/scope-contract.d.ts +13 -3
- package/dist/core/memory-engine/scope-contract.js +2 -2
- package/dist/core/memory-engine/sync-client.d.ts +51 -9
- package/dist/core/memory-engine/sync-client.js +107 -13
- package/dist/core/memory-engine/sync-report.d.ts +103 -0
- package/dist/core/memory-engine/sync-report.js +119 -0
- package/dist/core/memory-engine/sync.d.ts +8 -1
- package/dist/core/memory-engine/types.d.ts +6 -0
- package/dist/core/mode-policy.d.ts +9 -1
- package/dist/core/mode-policy.js +11 -1
- package/dist/core/model-receipt.d.ts +39 -0
- package/dist/core/model-receipt.js +139 -0
- package/dist/core/mods/agent-stations.d.ts +65 -0
- package/dist/core/mods/agent-stations.js +105 -0
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/kernel/dispatch.d.ts +5 -1
- package/dist/core/mods/kernel/dispatch.js +6 -5
- package/dist/core/mods/kernel/events.d.ts +11 -4
- package/dist/core/mods/kernel/events.js +11 -7
- package/dist/core/mods/kernel/receive.d.ts +5 -0
- package/dist/core/mods/kernel/receive.js +10 -0
- package/dist/core/mods/kernel/registration.d.ts +4 -0
- package/dist/core/mods/kernel/registration.js +3 -0
- package/dist/core/mods/lifecycle-stations.d.ts +41 -0
- package/dist/core/mods/lifecycle-stations.js +35 -0
- package/dist/core/mods/stations.d.ts +73 -60
- package/dist/core/mods/stations.js +64 -40
- package/dist/core/mods/tool-call.d.ts +10 -4
- package/dist/core/mods/tool-call.js +28 -12
- package/dist/core/mounted-mcp.d.ts +5 -0
- package/dist/core/mounted-mcp.js +2 -2
- package/dist/core/namespaced-rule-name.d.ts +7 -1
- package/dist/core/namespaced-rule-name.js +13 -2
- package/dist/core/oracle-isolation.js +1 -1
- package/dist/core/own-property-receipt.d.ts +3 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/parent-spec-seat.d.ts +8 -3
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +14 -8
- package/dist/core/peer-seat.d.ts +133 -16
- package/dist/core/peer-seat.js +319 -42
- package/dist/core/permission-rule-consent.d.ts +0 -21
- package/dist/core/permission-rule-consent.js +11 -6
- package/dist/core/permission-rule-model.d.ts +20 -2
- package/dist/core/permission-rule-model.js +8 -7
- package/dist/core/present-plan-tool.d.ts +11 -3
- package/dist/core/present-plan-tool.js +2 -2
- package/dist/core/protocol-http-auth.d.ts +14 -2
- package/dist/core/protocol-http-auth.js +16 -7
- package/dist/core/read-face-seats.d.ts +7 -5
- package/dist/core/read-face-seats.js +4 -1
- package/dist/core/redaction-marks.d.ts +4 -3
- package/dist/core/redaction-marks.js +2 -2
- package/dist/core/remote-env.d.ts +146 -98
- package/dist/core/remote-env.js +113 -14
- package/dist/core/resume-startup-cause.js +1 -0
- package/dist/core/retention.js +37 -12
- package/dist/core/retired-keys.d.ts +6 -1
- package/dist/core/retired-keys.js +4 -1
- package/dist/core/rewrite-rejudge.d.ts +13 -5
- package/dist/core/rewrite-rejudge.js +9 -5
- package/dist/core/roles.d.ts +69 -3
- package/dist/core/roles.js +167 -80
- package/dist/core/rule-owner.d.ts +3 -0
- package/dist/core/runner/announce-once-ledger.d.ts +5 -4
- package/dist/core/runner/announce-once-ledger.js +4 -2
- package/dist/core/runner/assemble-result.d.ts +0 -5
- package/dist/core/runner/assemble-result.js +0 -1
- package/dist/core/runner/call-hook-stations.d.ts +17 -10
- package/dist/core/runner/call-hook-stations.js +23 -12
- package/dist/core/runner/child-tree.d.ts +7 -8
- package/dist/core/runner/child-tree.js +6 -6
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +39 -8
- package/dist/core/runner/construction-doors.js +5 -0
- package/dist/core/runner/contracts.d.ts +82 -57
- package/dist/core/runner/credential-origin-seat.js +4 -3
- package/dist/core/runner/cross-boundary-lane.d.ts +3 -5
- package/dist/core/runner/cross-boundary-lane.js +11 -2
- package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
- package/dist/core/runner/cwd-alignment-probe.js +21 -0
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/env-capability-census.d.ts +15 -20
- package/dist/core/runner/env-capability-census.js +25 -34
- package/dist/core/runner/file-history-request.d.ts +2 -2
- package/dist/core/runner/file-history-request.js +0 -8
- package/dist/core/runner/gate-exit.d.ts +87 -11
- package/dist/core/runner/gate-exit.js +30 -8
- package/dist/core/runner/git-status-frame.d.ts +5 -2
- package/dist/core/runner/git-status-frame.js +3 -4
- package/dist/core/runner/image-removed-seat.d.ts +12 -0
- package/dist/core/runner/image-removed-seat.js +19 -0
- package/dist/core/runner/image.d.ts +7 -2
- package/dist/core/runner/image.js +14 -8
- package/dist/core/runner/inline-image.d.ts +10 -8
- package/dist/core/runner/inline-image.js +11 -9
- package/dist/core/runner/memory-consolidation-driver.js +5 -5
- package/dist/core/runner/park-commit.d.ts +1 -1
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/permission-rule-lanes.js +1 -1
- package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
- package/dist/core/runner/prepare-ask-lane.js +2 -1
- package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
- package/dist/core/runner/prepare-boundary-parks.js +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -1
- package/dist/core/runner/prepare-config-doors.js +16 -9
- package/dist/core/runner/prepare-context-lane.js +2 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +9 -3
- package/dist/core/runner/prepare-delegation-surface.js +5 -4
- package/dist/core/runner/prepare-file-history.d.ts +10 -12
- package/dist/core/runner/prepare-file-history.js +3 -12
- package/dist/core/runner/prepare-gate-stations.d.ts +4 -3
- package/dist/core/runner/prepare-gate-stations.js +4 -3
- package/dist/core/runner/prepare-hands-readface.d.ts +7 -1
- package/dist/core/runner/prepare-hands-readface.js +19 -6
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -7
- package/dist/core/runner/prepare-inherited-gate.js +22 -31
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +2 -2
- package/dist/core/runner/prepare-memory.js +12 -19
- package/dist/core/runner/prepare-park-ask.d.ts +4 -6
- package/dist/core/runner/prepare-park-ask.js +5 -9
- package/dist/core/runner/prepare-policy-chain.d.ts +8 -7
- package/dist/core/runner/prepare-policy-chain.js +136 -121
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +10 -7
- package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -2
- package/dist/core/runner/prepare-prompt-inputs.js +10 -20
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
- package/dist/core/runner/prepare-protocol-tools.js +17 -2
- package/dist/core/runner/prepare-run-refs.d.ts +2 -3
- package/dist/core/runner/prepare-run-refs.js +4 -1
- package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
- package/dist/core/runner/prepare-suspend-saga.js +5 -7
- package/dist/core/runner/prepare-task.js +44 -28
- package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
- package/dist/core/runner/prepare-turn-wiring.js +7 -2
- package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -4
- package/dist/core/runner/prepare-wiring-manifest.js +34 -19
- package/dist/core/runner/prepare-workspace-restore.js +3 -3
- package/dist/core/runner/reply-pricing.d.ts +30 -0
- package/dist/core/runner/reply-pricing.js +19 -0
- package/dist/core/runner/resume-admission.js +4 -2
- package/dist/core/runner/resume-apply.js +6 -1
- package/dist/core/runner/resume-checkpoint-screen.js +4 -4
- package/dist/core/runner/resume-policy-outcome.js +5 -5
- package/dist/core/runner/retired-runner-deps.js +4 -1
- package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
- package/dist/core/runner/role-seat-defaulted.js +40 -0
- package/dist/core/runner/run-attachment-seats.js +3 -3
- package/dist/core/runner/run-brain-sinks.js +3 -0
- package/dist/core/runner/run-git-lane.d.ts +3 -1
- package/dist/core/runner/run-git-lane.js +1 -1
- package/dist/core/runner/run-harness-handlers.d.ts +3 -1
- package/dist/core/runner/run-harness-handlers.js +3 -1
- package/dist/core/runner/run-identity-wiring.d.ts +2 -5
- package/dist/core/runner/run-identity-wiring.js +6 -5
- package/dist/core/runner/run-leg.d.ts +2 -0
- package/dist/core/runner/run-leg.js +63 -56
- package/dist/core/runner/run-notification-lane.d.ts +3 -1
- package/dist/core/runner/run-notification-lane.js +16 -10
- package/dist/core/runner/run-settle-and-teardown.js +5 -1
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
- package/dist/core/runner/run-stop-and-final-verify.js +14 -6
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
- package/dist/core/runner/run-terminal-adoption.js +9 -3
- package/dist/core/runner/run-turn-boundary.js +89 -77
- package/dist/core/runner/runtask.d.ts +8 -5
- package/dist/core/runner/runtask.js +21 -13
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +3 -18
- package/dist/core/runner/skills-seat.js +2 -2
- package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
- package/dist/core/runner/sub-agent-deny-lists.js +20 -7
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-disclosure.js +0 -2
- package/dist/core/runner/tool-end-body.js +2 -2
- package/dist/core/runner/tool-face-overlay.d.ts +1 -1
- package/dist/core/runner/tool-face-overlay.js +26 -19
- package/dist/core/runner/tool-occurrence.d.ts +1 -1
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
- package/dist/core/runner/tool-result-media-seat.js +17 -1
- package/dist/core/runner/turn-attachments.d.ts +29 -27
- package/dist/core/runner/turn-attachments.js +27 -42
- package/dist/core/runner-deps.d.ts +32 -19
- package/dist/core/secret-env.d.ts +35 -4
- package/dist/core/secret-env.js +65 -3
- package/dist/core/sensitive-path-policy.js +3 -3
- package/dist/core/session-policy-store.d.ts +12 -3
- package/dist/core/session-policy-store.js +29 -10
- package/dist/core/session-store.d.ts +5 -7
- package/dist/core/session-store.js +50 -11
- package/dist/core/side-query.d.ts +11 -1
- package/dist/core/side-query.js +9 -0
- package/dist/core/skill-grant-binding.d.ts +31 -2
- package/dist/core/skill-grant-binding.js +31 -1
- package/dist/core/skill-grant.d.ts +17 -5
- package/dist/core/skill-grant.js +24 -6
- package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +3 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +37 -0
- package/dist/core/stub-env.d.ts +5 -5
- package/dist/core/stub-env.js +11 -1
- package/dist/core/swappable-deps.d.ts +17 -43
- package/dist/core/swappable-deps.js +15 -5
- package/dist/core/synthetic-read-verdict.d.ts +1 -1
- package/dist/core/synthetic-read-verdict.js +2 -1
- package/dist/core/task-event.d.ts +50 -10
- package/dist/core/task-notification.d.ts +88 -5
- package/dist/core/task-notification.js +146 -17
- package/dist/core/task-registry-agent.d.ts +18 -12
- package/dist/core/task-registry-agent.js +19 -6
- package/dist/core/task-registry-monitor.d.ts +7 -0
- package/dist/core/task-registry-monitor.js +28 -1
- package/dist/core/task-registry-shared.d.ts +43 -3
- package/dist/core/task-registry-shared.js +21 -7
- package/dist/core/task-registry-workflow.js +1 -1
- package/dist/core/task-registry.d.ts +50 -35
- package/dist/core/task-registry.js +64 -23
- package/dist/core/task-result.d.ts +3 -12
- package/dist/core/task-spec.d.ts +15 -7
- package/dist/core/task-stream.d.ts +1 -1
- package/dist/core/terminal-cause.d.ts +10 -0
- package/dist/core/tool-catalog-entries.js +1 -1
- package/dist/core/tool-check-reading.d.ts +1 -0
- package/dist/core/tool-check-reading.js +3 -3
- package/dist/core/tool-face-reader.d.ts +7 -6
- package/dist/core/tool-face-reader.js +4 -3
- package/dist/core/tool-name-aliases.d.ts +19 -0
- package/dist/core/tool-name-aliases.js +54 -2
- package/dist/core/tool-policy.d.ts +21 -4
- package/dist/core/tool-policy.js +1 -1
- package/dist/core/tool-registry.d.ts +5 -5
- package/dist/core/tool-registry.js +2 -2
- package/dist/core/tool-result-store.d.ts +88 -5
- package/dist/core/tool-result-store.js +51 -12
- package/dist/core/tool-roster.d.ts +112 -5
- package/dist/core/tool-roster.js +42 -1
- package/dist/core/tool-spec.d.ts +23 -5
- package/dist/core/trace.d.ts +0 -1
- package/dist/core/types.d.ts +5 -5
- package/dist/core/types.js +2 -2
- package/dist/core/untrusted-text.js +1 -1
- package/dist/core/user-attachment.d.ts +10 -5
- package/dist/core/user-attachment.js +15 -7
- package/dist/core/wiring-manifest.d.ts +6 -3
- package/dist/engine/compaction/compaction.js +29 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +11 -5
- package/dist/engine/execution-env/node-execution-env.js +21 -13
- package/dist/engine/harness/agent-harness.d.ts +26 -3
- package/dist/engine/harness/agent-harness.js +49 -16
- package/dist/engine/harness/messages.d.ts +3 -1
- package/dist/engine/harness/messages.js +3 -2
- package/dist/engine/harness/types.d.ts +119 -28
- package/dist/engine/llm/rejected-images.d.ts +46 -0
- package/dist/engine/llm/rejected-images.js +54 -0
- package/dist/engine/llm/tool-turns.d.ts +2 -1
- package/dist/engine/llm/types.d.ts +18 -7
- package/dist/engine/loop/agent-loop.d.ts +20 -12
- package/dist/engine/loop/agent-loop.js +205 -36
- package/dist/engine/loop/types.d.ts +12 -3
- package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
- package/dist/engine/lsp/node-lsp-manager.js +32 -13
- package/dist/engine/session/path-to-root.d.ts +38 -0
- package/dist/engine/session/path-to-root.js +39 -0
- package/dist/engine/session/storage-base.js +4 -21
- package/dist/index.d.ts +35 -21
- package/dist/index.js +26 -17
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +1 -0
- package/dist/internal/llm.d.ts +1 -0
- package/dist/orchestration/run-workflow-tool.d.ts +9 -3
- package/dist/orchestration/run-workflow-tool.js +59 -29
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-governance.js +2 -1
- package/dist/orchestration/workflow-observe.d.ts +17 -1
- package/dist/orchestration/workflow-observe.js +20 -0
- package/dist/orchestration/workflow-types.d.ts +32 -7
- package/dist/orchestration/workflow.d.ts +4 -0
- package/dist/orchestration/workflow.js +762 -491
- package/dist/prompts/default.d.ts +1 -10
- package/dist/prompts/default.js +0 -2
- package/dist/shell/counting-pass.d.ts +50 -0
- package/dist/shell/counting-pass.js +502 -0
- package/dist/shell/lex.d.ts +4 -2
- package/dist/shell/lex.js +93 -34
- package/dist/shell/shell-words.d.ts +1 -1
- package/dist/shell/shell-words.js +7 -6
- package/dist/stores/file/background-agent-store.d.ts +1 -1
- package/dist/stores/file/background-agent-store.js +3 -1
- package/dist/stores/file/checkpoint-store.d.ts +127 -2
- package/dist/stores/file/checkpoint-store.js +19 -14
- package/dist/stores/file/file-history-store.d.ts +1 -1
- package/dist/stores/file/file-history-store.js +3 -1
- package/dist/stores/file/index.d.ts +4 -3
- package/dist/stores/file/index.js +17 -8
- package/dist/stores/file/mailbox-store.d.ts +1 -1
- package/dist/stores/file/mailbox-store.js +9 -11
- package/dist/stores/file/memory-store.d.ts +1 -1
- package/dist/stores/file/memory-store.js +3 -1
- package/dist/stores/file/session-policy-store.d.ts +1 -1
- package/dist/stores/file/session-policy-store.js +3 -1
- package/dist/stores/file/session-store.d.ts +1 -1
- package/dist/stores/file/session-store.js +3 -1
- package/dist/stores/file/shared-ledger.d.ts +26 -0
- package/dist/stores/file/shared-ledger.js +38 -9
- package/dist/stores/file/tool-result-store.d.ts +20 -2
- package/dist/stores/file/tool-result-store.js +74 -6
- package/dist/stores/file/usage-window-store.d.ts +1 -1
- package/dist/stores/file/usage-window-store.js +3 -1
- package/dist/stores/file/workflow-journal-store.d.ts +1 -11
- package/dist/stores/file/workflow-journal-store.js +3 -2
- package/dist/tools/fs/containment-face.d.ts +5 -0
- package/dist/tools/fs/encoding.d.ts +13 -4
- package/dist/tools/fs/encoding.js +17 -2
- package/dist/tools/fs/fs-bash-background-text.d.ts +7 -0
- package/dist/tools/fs/fs-bash-background-text.js +1 -0
- package/dist/tools/fs/fs-bash.d.ts +14 -4
- package/dist/tools/fs/fs-bash.js +29 -35
- package/dist/tools/fs/fs-pdf.d.ts +2 -2
- package/dist/tools/fs/fs-pdf.js +26 -21
- package/dist/tools/fs/fs-read.d.ts +5 -4
- package/dist/tools/fs/fs-read.js +35 -18
- package/dist/tools/fs/fs-search-tools.js +4 -1
- package/dist/tools/fs/fs-shared.d.ts +11 -13
- package/dist/tools/fs/fs-shared.js +11 -7
- package/dist/tools/fs/fs-write.js +5 -5
- package/dist/tools/fs/index.d.ts +14 -8
- package/dist/tools/fs/index.js +13 -5
- package/dist/tools/fs/program-read-model.d.ts +13 -0
- package/dist/tools/fs/program-read-model.js +15 -0
- package/dist/tools/fs/program-read-model.rows.js +1 -1
- package/dist/tools/fs/read-deny.d.ts +13 -10
- package/dist/tools/fs/read-deny.js +25 -5
- package/dist/tools/fs/read-floor.d.ts +62 -0
- package/dist/tools/fs/read-floor.js +58 -0
- package/dist/tools/fs/removal-targets.d.ts +9 -4
- package/dist/tools/fs/removal-targets.js +17 -9
- package/dist/tools/fs/search.d.ts +3 -3
- package/dist/tools/fs/search.js +4 -4
- package/dist/tools/fs/shell-read-check.d.ts +1 -1
- package/dist/tools/fs/shell-read-check.js +2 -1
- package/dist/tools/fs/shell-read-judge.d.ts +16 -8
- package/dist/tools/fs/shell-read-judge.js +10 -6
- package/dist/tools/fs/shell-read-plan.d.ts +6 -1
- package/dist/tools/fs/shell-read-plan.js +22 -15
- package/dist/tools/fs/shell-read-start.js +1 -0
- package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
- package/dist/tools/fs/shell-reentry-text.js +25 -3
- package/dist/tools/monitor.d.ts +9 -4
- package/dist/tools/monitor.js +17 -8
- package/dist/tools/scheduler-tools.js +42 -4
- package/dist/tools/web.d.ts +0 -10
- package/dist/tools/web.js +1 -4
- package/package.json +5 -2
- package/test/export-surface.snapshot.json +161 -21
- package/wire-changes/core-stores-sql@7.59.0.json +29 -0
- package/wire-changes/core-stores-sql@7.60.0.json +30 -0
- package/wire-changes/core@7.59.0.json +2459 -0
- package/wire-changes/core@7.60.0.json +3274 -0
- package/wire-changes/mods-kernel@7.59.0.json +29 -0
- package/wire-changes/mods-kernel@7.60.0.json +62 -0
- package/wire-changes/primitives@7.59.0.json +29 -0
- package/wire-changes/primitives@7.60.0.json +30 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { describeFault, receive } from "./mods/kernel/receive.js";
|
|
3
|
+
import { DECLARATION_RECEIPT_MODE } from "./own-property-receipt.js";
|
|
4
|
+
import { assertNoRetiredKeys, RETIRED_MODEL_KEYS } from "./retired-keys.js";
|
|
5
|
+
export function modelBindingRefusal(field, reason, message) {
|
|
6
|
+
const e = new Error(message);
|
|
7
|
+
e.code = "config.unknown_role";
|
|
8
|
+
e.detail = { field, reason };
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
export function isList(value) {
|
|
12
|
+
try {
|
|
13
|
+
return Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function bindingShown(value) {
|
|
20
|
+
if (typeof value === "string")
|
|
21
|
+
return JSON.stringify(value.length > 80 ? `${value.slice(0, 80)}…` : value);
|
|
22
|
+
return value === null ? "null" : isList(value) ? "a list" : `a ${typeof value}`;
|
|
23
|
+
}
|
|
24
|
+
const MODEL_MEMBER_TABLE = {
|
|
25
|
+
id: true,
|
|
26
|
+
name: true,
|
|
27
|
+
api: true,
|
|
28
|
+
provider: true,
|
|
29
|
+
baseUrl: true,
|
|
30
|
+
reasoning: true,
|
|
31
|
+
defaultThinking: true,
|
|
32
|
+
thinkingLevelMap: true,
|
|
33
|
+
input: true,
|
|
34
|
+
cost: true,
|
|
35
|
+
contextWindow: true,
|
|
36
|
+
contextTokens: true,
|
|
37
|
+
autoCompactTokens: true,
|
|
38
|
+
charsPerToken: true,
|
|
39
|
+
maxTokens: true,
|
|
40
|
+
params: true,
|
|
41
|
+
extraBody: true,
|
|
42
|
+
headers: true,
|
|
43
|
+
promptTraits: true,
|
|
44
|
+
compat: true,
|
|
45
|
+
};
|
|
46
|
+
const MODEL_MEMBERS = new Set(Object.keys(MODEL_MEMBER_TABLE));
|
|
47
|
+
export const MODEL_RECEIPT_MODE = Object.freeze({ ...DECLARATION_RECEIPT_MODE, live: Object.freeze(["headers"]) });
|
|
48
|
+
const MINTED = new WeakSet();
|
|
49
|
+
const LAST = new WeakMap();
|
|
50
|
+
const ORIGIN = new WeakMap();
|
|
51
|
+
export function isModelSnapshot(value) {
|
|
52
|
+
return typeof value === "object" && value !== null && MINTED.has(value);
|
|
53
|
+
}
|
|
54
|
+
export function modelOriginOf(model) {
|
|
55
|
+
return ORIGIN.get(model)?.origin ?? model;
|
|
56
|
+
}
|
|
57
|
+
function unreadableModelRefusal(seat, what, note, fault) {
|
|
58
|
+
const how = fault.path.length > 0
|
|
59
|
+
? describeFault(fault)
|
|
60
|
+
: fault.kind === "proxy"
|
|
61
|
+
? "a Proxy"
|
|
62
|
+
: "an object of another prototype (a class instance, an `Object.create(…)` value): a Model is a plain record, its members its own";
|
|
63
|
+
return modelBindingRefusal(seat, "not_a_model_ref", `${seat} is ${what} that could not be read as plain data — ${how}.${note}`);
|
|
64
|
+
}
|
|
65
|
+
export function receiveModel(value, seat, what = "a Model object", note = "") {
|
|
66
|
+
if (isModelSnapshot(value))
|
|
67
|
+
return value;
|
|
68
|
+
if (typeof value !== "object" || value === null || isList(value)) {
|
|
69
|
+
throw modelBindingRefusal(seat, "not_a_model_ref", `${seat} is ${what} that is ${bindingShown(value)}, not a Model — a Model is a plain record carrying a non-empty string \`id\` and a string \`api\`.${note}`);
|
|
70
|
+
}
|
|
71
|
+
if (types.isProxy(value))
|
|
72
|
+
throw unreadableModelRefusal(seat, what, note, { kind: "proxy", path: [] });
|
|
73
|
+
const headersAt = Object.getOwnPropertyDescriptor(value, "headers");
|
|
74
|
+
const headers = headersAt !== undefined && !Object.hasOwn(headersAt, "value") ? headersAt.get : undefined;
|
|
75
|
+
const received = receive(value, MODEL_RECEIPT_MODE, MINTED);
|
|
76
|
+
if (!received.ok)
|
|
77
|
+
throw unreadableModelRefusal(seat, what, note, received.fault);
|
|
78
|
+
const copy = received.value;
|
|
79
|
+
judgeModelCopy(copy, seat, what, note);
|
|
80
|
+
const prior = LAST.get(value);
|
|
81
|
+
if (prior !== undefined && ORIGIN.get(prior)?.headers === headers && sameData(prior, copy, true))
|
|
82
|
+
return prior;
|
|
83
|
+
MINTED.add(copy);
|
|
84
|
+
LAST.set(value, copy);
|
|
85
|
+
ORIGIN.set(copy, { origin: value, headers });
|
|
86
|
+
return copy;
|
|
87
|
+
}
|
|
88
|
+
function judgeModelCopy(copy, seat, what, note) {
|
|
89
|
+
assertNoRetiredKeys(copy, RETIRED_MODEL_KEYS, "Model");
|
|
90
|
+
const id = copy["id"];
|
|
91
|
+
const api = copy["api"];
|
|
92
|
+
const [member, got] = typeof id !== "string" || id === "" ? ["id", id] : typeof api !== "string" ? ["api", api] : [undefined, undefined];
|
|
93
|
+
if (member !== undefined) {
|
|
94
|
+
const shown = got === undefined ? "absent" : bindingShown(got);
|
|
95
|
+
throw modelBindingRefusal(seat, "not_a_model_ref", `${seat} is ${what} whose \`${member}\` is ${shown} — a Model carries a non-empty string \`id\` and a string \`api\`.${note}`);
|
|
96
|
+
}
|
|
97
|
+
for (const key of Object.keys(copy)) {
|
|
98
|
+
if (!MODEL_MEMBERS.has(key)) {
|
|
99
|
+
throw modelBindingRefusal(seat, "not_a_model_ref", `${seat} is ${what} carrying ${bindingShown(key)}, which is not a member of Model — a provider's own parameters belong in \`Model.params\`.${note}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function sameData(a, b, top = false, compared = new Map()) {
|
|
104
|
+
if (Object.is(a, b))
|
|
105
|
+
return true;
|
|
106
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null)
|
|
107
|
+
return false;
|
|
108
|
+
const partners = compared.get(a);
|
|
109
|
+
if (partners?.has(b) === true)
|
|
110
|
+
return true;
|
|
111
|
+
if (partners === undefined)
|
|
112
|
+
compared.set(a, new Set([b]));
|
|
113
|
+
else
|
|
114
|
+
partners.add(b);
|
|
115
|
+
if (Array.isArray(a) !== Array.isArray(b) || (Array.isArray(a) && Array.isArray(b) && a.length !== b.length))
|
|
116
|
+
return false;
|
|
117
|
+
const ka = Object.keys(a);
|
|
118
|
+
const kb = Object.keys(b);
|
|
119
|
+
if (ka.length !== kb.length)
|
|
120
|
+
return false;
|
|
121
|
+
for (let i = 0; i < ka.length; i++) {
|
|
122
|
+
const k = ka[i];
|
|
123
|
+
if (k !== kb[i])
|
|
124
|
+
return false;
|
|
125
|
+
const da = Object.getOwnPropertyDescriptor(a, k);
|
|
126
|
+
const db = Object.getOwnPropertyDescriptor(b, k);
|
|
127
|
+
const aData = Object.hasOwn(da, "value");
|
|
128
|
+
if (aData !== Object.hasOwn(db, "value"))
|
|
129
|
+
return false;
|
|
130
|
+
if (!aData) {
|
|
131
|
+
if (!top)
|
|
132
|
+
return false;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!sameData(da.value, db.value, false, compared))
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { HookInvocationIdentity } from "../hooks.js";
|
|
2
|
+
import type { PermissionMode } from "../ask-origin.js";
|
|
3
|
+
import { type LegModBus } from "./stations.js";
|
|
4
|
+
/** One agent type as the model is offered it. */
|
|
5
|
+
export interface OfferedAgent {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly description: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The offered set — the ONE reading of "which agent types is the model offered": each type the chain does not answer
|
|
11
|
+
* `{ isOffered: false }`, in the order given. No handler on the bus, no dispatch: the types as given. A dispatch the engine
|
|
12
|
+
* itself could not raise offers the type (an observation of the offer is never what hides it).
|
|
13
|
+
*/
|
|
14
|
+
export declare function offeredAgents<A extends OfferedAgent>(bus: LegModBus | undefined, agents: readonly A[], signal: AbortSignal | undefined): Promise<readonly A[]>;
|
|
15
|
+
/** A rendered agent listing read through the offered set: the same listing when every type is offered, else a copy with the
|
|
16
|
+
* types the chain hid left out — what a listing frame renders, commits and mirrors. */
|
|
17
|
+
export declare function offeredAgentListing<L extends {
|
|
18
|
+
readonly entries: readonly OfferedAgent[];
|
|
19
|
+
}>(bus: LegModBus | undefined, listing: L | undefined, signal: AbortSignal | undefined): Promise<L | undefined>;
|
|
20
|
+
/** What the delegation decided about the subagent it is about to start, as `agent.spawn` names it. */
|
|
21
|
+
export interface AgentSpawnFacts {
|
|
22
|
+
/** The delegation call this spawn belongs to. */
|
|
23
|
+
readonly toolCallId: string;
|
|
24
|
+
readonly prompt: string;
|
|
25
|
+
readonly description: string;
|
|
26
|
+
/** The resolved type (a definition's name, `general-purpose`, `fork`). */
|
|
27
|
+
readonly subagentType: string;
|
|
28
|
+
/** The model the subagent starts on, as the delegation settled it; absent when its own prepare decides (a stated tier). */
|
|
29
|
+
readonly model?: string;
|
|
30
|
+
/** The parent's own model. */
|
|
31
|
+
readonly parentModel?: string;
|
|
32
|
+
readonly background: boolean;
|
|
33
|
+
readonly fork: boolean;
|
|
34
|
+
/** The name it is addressed by (a teammate), when the call gave one. */
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
readonly cwd?: string;
|
|
37
|
+
/** A workflow script's agent rather than a model's delegation. */
|
|
38
|
+
readonly workflow?: true;
|
|
39
|
+
}
|
|
40
|
+
/** What `agent.spawn` came to: the subagent may start, or the chain refused it (`by` = the registration). */
|
|
41
|
+
export type AgentSpawnVerdict = {
|
|
42
|
+
readonly go: true;
|
|
43
|
+
} | {
|
|
44
|
+
readonly go: false;
|
|
45
|
+
readonly by: string;
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
};
|
|
48
|
+
/** The delegating leg's two agent stations, as its delegation tools read them (a Runner-filled seat, never a model argument). */
|
|
49
|
+
export interface AgentStations {
|
|
50
|
+
/** Whether a handler hangs on the event — a caller with nothing to raise reads none (no await on its path). */
|
|
51
|
+
listens(event: "agent.offer" | "agent.spawn"): boolean;
|
|
52
|
+
/** {@link offeredAgents} over the leg's bus. */
|
|
53
|
+
offered<A extends OfferedAgent>(agents: readonly A[], signal: AbortSignal | undefined): Promise<readonly A[]>;
|
|
54
|
+
/** Raise `agent.spawn` (no handler ⇒ nothing raised: the subagent may start). */
|
|
55
|
+
spawn(facts: AgentSpawnFacts, signal: AbortSignal | undefined): Promise<AgentSpawnVerdict>;
|
|
56
|
+
}
|
|
57
|
+
export interface AgentStationsInput {
|
|
58
|
+
readonly bus: LegModBus;
|
|
59
|
+
/** The delegating leg's identity (its `agentId` is the spawn's `parentAgentId`). */
|
|
60
|
+
readonly identity: HookInvocationIdentity | undefined;
|
|
61
|
+
/** The delegating leg's mode as observed at the spawn. */
|
|
62
|
+
readonly permissionMode: () => PermissionMode | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** The leg's agent stations over its bus. */
|
|
65
|
+
export declare function createAgentStations(input: AgentStationsInput): AgentStations;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ENGINE_ORIGIN } from "./kernel/index.js";
|
|
2
|
+
import { isPlainRecord } from "./kernel/receive.js";
|
|
3
|
+
import { NEXT_IN_FLIGHT } from "./kernel/site-rules.js";
|
|
4
|
+
import { describeThrown } from "../tool-policy.js";
|
|
5
|
+
import { extensionWords } from "../untrusted-egress.js";
|
|
6
|
+
import { agentIdOf, failedHandlerClause } from "./stations.js";
|
|
7
|
+
const ENGINE_PROVIDER = Object.freeze({ plugin: ENGINE_ORIGIN.plugin, tier: ENGINE_ORIGIN.tier });
|
|
8
|
+
const OFFERED = Object.freeze({ isOffered: true });
|
|
9
|
+
function offerAnswer(answer) {
|
|
10
|
+
if (!isPlainRecord(answer) || typeof answer["isOffered"] !== "boolean" || Object.keys(answer).some((k) => k !== "isOffered"))
|
|
11
|
+
return "agent.offer takes next(e) or { isOffered: <boolean> }";
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
export async function offeredAgents(bus, agents, signal) {
|
|
15
|
+
if (bus === undefined || agents.length === 0 || !bus.hasHandlers("agent.offer"))
|
|
16
|
+
return agents;
|
|
17
|
+
const out = [];
|
|
18
|
+
for (const a of agents) {
|
|
19
|
+
let outcome;
|
|
20
|
+
try {
|
|
21
|
+
outcome = await bus.dispatch("agent.offer", { agent: a.name, description: a.description, provider: ENGINE_PROVIDER }, { bottom: () => OFFERED, checkAnswer: offerAnswer, ...(signal !== undefined ? { signal } : {}) });
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
out.push(a);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (outcome.kind === "answered" && isPlainRecord(outcome.answer) && outcome.answer["isOffered"] === false)
|
|
28
|
+
continue;
|
|
29
|
+
out.push(a);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
export async function offeredAgentListing(bus, listing, signal) {
|
|
34
|
+
if (listing === undefined)
|
|
35
|
+
return undefined;
|
|
36
|
+
const entries = await offeredAgents(bus, listing.entries, signal);
|
|
37
|
+
return entries === listing.entries || entries.length === listing.entries.length ? listing : { ...listing, entries };
|
|
38
|
+
}
|
|
39
|
+
const GO = Object.freeze({ go: true });
|
|
40
|
+
const FORM = "agent.spawn takes next(e) or { deny: <reason> } (every member is pinned: a spawn is refused, never rewritten)";
|
|
41
|
+
const denyOf = (a) => isPlainRecord(a) && Object.keys(a).length === 1 && typeof a["deny"] === "string" && a["deny"] !== "" ? a["deny"] : undefined;
|
|
42
|
+
const RANKS = Object.freeze({ of: (a) => (denyOf(a) !== undefined ? 1 : 0), top: 1 });
|
|
43
|
+
export function createAgentStations(input) {
|
|
44
|
+
return {
|
|
45
|
+
listens: (event) => input.bus.hasHandlers(event),
|
|
46
|
+
offered: (agents, signal) => offeredAgents(input.bus, agents, signal),
|
|
47
|
+
spawn: async (facts, signal) => {
|
|
48
|
+
if (!input.bus.hasHandlers("agent.spawn"))
|
|
49
|
+
return GO;
|
|
50
|
+
const parentAgentId = agentIdOf(input.identity);
|
|
51
|
+
const permissionMode = input.permissionMode();
|
|
52
|
+
const e = {
|
|
53
|
+
...(input.identity !== undefined ? { identity: input.identity } : {}),
|
|
54
|
+
tool_use_id: facts.toolCallId,
|
|
55
|
+
prompt: facts.prompt,
|
|
56
|
+
description: facts.description,
|
|
57
|
+
subagentType: facts.subagentType,
|
|
58
|
+
provider: ENGINE_PROVIDER,
|
|
59
|
+
...(facts.model !== undefined ? { model: facts.model } : {}),
|
|
60
|
+
...(facts.parentModel !== undefined ? { parentModel: facts.parentModel } : {}),
|
|
61
|
+
...(parentAgentId !== undefined ? { parentAgentId } : {}),
|
|
62
|
+
...(permissionMode !== undefined ? { permissionMode } : {}),
|
|
63
|
+
background: facts.background,
|
|
64
|
+
fork: facts.fork,
|
|
65
|
+
isTeammate: facts.name !== undefined,
|
|
66
|
+
...(facts.name !== undefined ? { name: facts.name } : {}),
|
|
67
|
+
...(facts.cwd !== undefined ? { cwd: facts.cwd } : {}),
|
|
68
|
+
...(facts.workflow === true ? { workflow: true } : {}),
|
|
69
|
+
};
|
|
70
|
+
const started = Object.freeze({ model: facts.model ?? "inherit" });
|
|
71
|
+
const checkAnswer = (a, _e, _by, below, ran) => {
|
|
72
|
+
if (a === started)
|
|
73
|
+
return undefined;
|
|
74
|
+
const reason = denyOf(a);
|
|
75
|
+
if (reason === undefined)
|
|
76
|
+
return FORM;
|
|
77
|
+
if (ran.bottomStarted)
|
|
78
|
+
return "a deny after the subagent was let start (once it starts, only its own run stands)";
|
|
79
|
+
if (below.includes(NEXT_IN_FLIGHT) || below.some((b) => denyOf(b) === undefined))
|
|
80
|
+
return "a deny while its next(e) still runs or after it was answered (deny in place of next)";
|
|
81
|
+
return undefined;
|
|
82
|
+
};
|
|
83
|
+
let outcome;
|
|
84
|
+
try {
|
|
85
|
+
outcome = await input.bus.dispatch("agent.spawn", e, { bottom: () => started, checkAnswer, ranks: RANKS, ...(signal !== undefined ? { signal } : {}) });
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
return { go: false, by: ENGINE_ORIGIN.plugin, reason: `the agent.spawn station could not be raised (${describeThrown(err)}); no subagent was started (fail-closed)` };
|
|
89
|
+
}
|
|
90
|
+
if (outcome.kind === "aborted")
|
|
91
|
+
return outcome.bottomStarted === true ? GO : { go: false, by: ENGINE_ORIGIN.plugin, reason: "the delegation was cancelled before its subagent started" };
|
|
92
|
+
if (outcome.kind === "failed")
|
|
93
|
+
return { go: false, by: outcome.registration, reason: `an agent.spawn extension ${failedHandlerClause(outcome)} before the subagent started; no subagent was started (fail-closed)` };
|
|
94
|
+
if (outcome.answer === started)
|
|
95
|
+
return GO;
|
|
96
|
+
const by = outcome.answeredBy ?? ENGINE_ORIGIN.plugin;
|
|
97
|
+
const reason = denyOf(outcome.answer);
|
|
98
|
+
return {
|
|
99
|
+
go: false,
|
|
100
|
+
by,
|
|
101
|
+
reason: reason !== undefined ? `extension "${extensionWords(by, 80)}" refused this delegation before its subagent started: ${extensionWords(reason, 300)}` : `extension "${extensionWords(by, 80)}" answered this delegation in a form agent.spawn does not take; no subagent was started (fail-closed)`,
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* registration form types a handler by it. Its keys are the event table's `classic.*` rows that carry a station — the key
|
|
5
5
|
* set is held to that table.
|
|
6
6
|
*/
|
|
7
|
-
import type { PermissionDeniedPayload, PostCompactEvent, PostToolBatchEvent, PostToolBatchResult, PostToolUseEvent, PostToolUseFailureEvent, PostToolUseFailureResult, PostToolUseResult, PreCompactEvent, PreCompactResult, PreToolUseEvent, PreToolUseResult, StopEvent, StopFailureEvent, StopHookResult, UserPromptSubmitEvent, UserPromptSubmitResult } from "../hooks.js";
|
|
7
|
+
import type { PermissionDeniedPayload, PostCompactEvent, PostToolBatchEvent, PostToolBatchResult, PostToolUseEvent, PostToolUseFailureEvent, PostToolUseFailureResult, PostToolUseResult, PreCompactEvent, PreCompactResult, PreToolUseEvent, PreToolUseResult, StopEvent, StopFailureEvent, StopHookResult, SubagentStartEvent, SubagentStartResult, UserPromptSubmitEvent, UserPromptSubmitResult } from "../hooks.js";
|
|
8
8
|
import type { MappedOn, ModRegistration } from "./kernel/index.js";
|
|
9
9
|
import type { EngineDollar } from "./dollar.js";
|
|
10
10
|
/** The answer of an event whose station reads none (an observation event): a chain handler passes `next(e)`'s on. */
|
|
@@ -31,6 +31,10 @@ export type ClassicEventMap = {
|
|
|
31
31
|
readonly e: UserPromptSubmitEvent;
|
|
32
32
|
readonly answer: UserPromptSubmitResult;
|
|
33
33
|
};
|
|
34
|
+
readonly "classic.SubagentStart": {
|
|
35
|
+
readonly e: SubagentStartEvent;
|
|
36
|
+
readonly answer: SubagentStartResult;
|
|
37
|
+
};
|
|
34
38
|
readonly "classic.Stop": {
|
|
35
39
|
readonly e: StopEvent;
|
|
36
40
|
readonly answer: StopHookResult;
|
|
@@ -40,12 +40,16 @@ export type ModDispatchOutcome = {
|
|
|
40
40
|
readonly answer: unknown;
|
|
41
41
|
readonly answeredBy?: string;
|
|
42
42
|
readonly skipped: readonly ModSkip[];
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
|
+
/** `bottomStarted`: the chain's bottom had started when the handler failed — on an effect event, what it did happened, and
|
|
45
|
+
* its outcome is the station's to withhold. */
|
|
46
|
+
| {
|
|
44
47
|
readonly kind: "failed";
|
|
45
48
|
readonly registration: string;
|
|
46
49
|
readonly cause: ModFailureCause;
|
|
47
50
|
readonly reason: string;
|
|
48
51
|
readonly skipped: readonly ModSkip[];
|
|
52
|
+
readonly bottomStarted?: true;
|
|
49
53
|
}
|
|
50
54
|
/** `bottomStarted`: the chain's bottom had started when the dispatch was cancelled — on an effect event, what it did is
|
|
51
55
|
* not known from here. */
|
|
@@ -584,7 +584,8 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
|
|
|
584
584
|
if (caught !== undefined && "answer" in caught) {
|
|
585
585
|
if (failure.cause !== "violation" && failure.cause !== "reentry")
|
|
586
586
|
report(new Error(`${name}: ${event}: ${failure.reason}; its .catch answered`));
|
|
587
|
-
producers.
|
|
587
|
+
if (!(typeof caught.answer === "object" && caught.answer !== null && producers.has(caught.answer)))
|
|
588
|
+
producers.set(caught.answer, name);
|
|
588
589
|
traceOf(sink, i, name, h.reg.tier, "caught", ms);
|
|
589
590
|
return caught.answer;
|
|
590
591
|
}
|
|
@@ -595,12 +596,12 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
|
|
|
595
596
|
throw failure.error;
|
|
596
597
|
}
|
|
597
598
|
const reason = caught !== undefined ? `${failure.reason}; ${caught.problem}` : failure.reason;
|
|
598
|
-
const
|
|
599
|
-
if (refusing && !
|
|
600
|
-
if (failure.cause !== "violation")
|
|
599
|
+
const goAheadStands = st.failure === "refuse_until_run" && bottomStarted && state.last !== undefined;
|
|
600
|
+
if (refusing && !goAheadStands) {
|
|
601
|
+
if (failure.cause !== "violation" || bottomStarted)
|
|
601
602
|
report(new Error(`${name}: ${event}: ${reason} — failed closed: the dispatch ends here`));
|
|
602
603
|
traceOf(sink, i, name, h.reg.tier, "rejected", ms);
|
|
603
|
-
finish({ kind: "failed", registration: name, cause: failure.cause, reason, skipped: Object.freeze([...skipped]) });
|
|
604
|
+
finish({ kind: "failed", registration: name, cause: failure.cause, reason, skipped: Object.freeze([...skipped]), ...(bottomStarted ? { bottomStarted: true } : {}) });
|
|
604
605
|
throw terminal;
|
|
605
606
|
}
|
|
606
607
|
skipped.push(Object.freeze({ registration: name, cause: failure.cause, reason }));
|
|
@@ -25,8 +25,13 @@
|
|
|
25
25
|
* changed pinned key is), `tool.call` takes one member more than its own — `requestMeta`, a record of strings, judged there —
|
|
26
26
|
* and an admission record carries the registration's `provenance` as the host gave it and lists in `observe` only the patterns
|
|
27
27
|
* on which every handler it hung watches.
|
|
28
|
+
* 5: `classic.SubagentStart` has a station (a delegated leg's opening event).
|
|
29
|
+
* 6: `agent.offer` (a listed or named agent type, before the model is offered it), `agent.spawn` (a delegation the gate let
|
|
30
|
+
* go, before its subagent starts — every argument pinned, a refusal its only answer), `turn.complete` (a model turn ended)
|
|
31
|
+
* and `session.end` (a leg ended) have stations; `tool.call`'s failure column is `refuse` — a failure once the body has
|
|
32
|
+
* started withholds the result (under `refuse_until_run`, its column until 5, the result stood).
|
|
28
33
|
*/
|
|
29
|
-
export declare const KERNEL_CONTRACT_VERSION =
|
|
34
|
+
export declare const KERNEL_CONTRACT_VERSION = 6;
|
|
30
35
|
/** The five tiers in run order (CC names). `builtin` and `core` are the engine's own. */
|
|
31
36
|
export declare const MOD_TIERS: readonly ["prepend", "user", "append", "builtin", "core"];
|
|
32
37
|
export type ModTier = (typeof MOD_TIERS)[number];
|
|
@@ -41,9 +46,11 @@ export type ModEventSide = (typeof MOD_EVENT_SIDES)[number];
|
|
|
41
46
|
/** A bus is one side. */
|
|
42
47
|
export type ModBusSide = Exclude<ModEventSide, "both">;
|
|
43
48
|
/**
|
|
44
|
-
* What a handler's failure means for the dispatch: the station's refusal (final); skip the handler; or — on an event
|
|
45
|
-
*
|
|
46
|
-
* the bottom
|
|
49
|
+
* What a handler's failure means for the dispatch: the station's refusal (final); skip the handler; or — on an event whose
|
|
50
|
+
* bottom is a go-ahead the station acts on after the dispatch (`agent.spawn`: the subagent is let start) — the refusal
|
|
51
|
+
* while the bottom has not started and, once it has, the go-ahead stands (the failure is reported beside it). A `refuse`
|
|
52
|
+
* station refuses whether or not its bottom has started: on one whose bottom is an effect (`tool.call`: a tool runs), the
|
|
53
|
+
* dispatch's `failed` outcome says the bottom had started, and the station withholds what it produced.
|
|
47
54
|
*/
|
|
48
55
|
export declare const MOD_FAILURE_ANSWERS: readonly ["refuse", "skip", "refuse_until_run"];
|
|
49
56
|
export type ModFailureAnswer = (typeof MOD_FAILURE_ANSWERS)[number];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const KERNEL_CONTRACT_VERSION =
|
|
1
|
+
export const KERNEL_CONTRACT_VERSION = 6;
|
|
2
2
|
export const MOD_TIERS = Object.freeze(["prepend", "user", "append", "builtin", "core"]);
|
|
3
3
|
export const MOD_SEATS = Object.freeze(["deployment", "task"]);
|
|
4
4
|
export const MOD_EVENT_SIDES = Object.freeze(["engine", "surface", "both"]);
|
|
@@ -43,6 +43,10 @@ const surface = (s) => Object.freeze(s === undefined ? { side: "surface" } : { s
|
|
|
43
43
|
const RENDER_PINNED = ["surface", "component", "requestId", "viewport"];
|
|
44
44
|
const ELEMENT_PINNED = ["plugin", "element", "component", "requestId", "surface"];
|
|
45
45
|
const PROMPT_EDIT_BUDGET_MS = 50;
|
|
46
|
+
const AGENT_SPAWN_PINNED = [
|
|
47
|
+
"tool_use_id", "name", "fork", "isTeammate", "workflow", "parentModel", "permissionMode", "parentAgentId", "provider",
|
|
48
|
+
"prompt", "description", "subagentType", "model", "background", "cwd", "identity",
|
|
49
|
+
];
|
|
46
50
|
export const MOD_EVENT_TABLE = Object.freeze({
|
|
47
51
|
"classic.PreToolUse": engine(station("refuse", "immediate", ["tool", "tool_use_id", "agentId", "input"])),
|
|
48
52
|
"classic.PostToolUse": engine(station("skip", "grace")),
|
|
@@ -55,7 +59,7 @@ export const MOD_EVENT_TABLE = Object.freeze({
|
|
|
55
59
|
"classic.SessionEnd": engine(),
|
|
56
60
|
"classic.Stop": engine(station("skip", "immediate")),
|
|
57
61
|
"classic.StopFailure": engine(station("skip", "grace")),
|
|
58
|
-
"classic.SubagentStart": engine(),
|
|
62
|
+
"classic.SubagentStart": engine(station("skip", "immediate", ["agentId", "agentType"])),
|
|
59
63
|
"classic.SubagentStop": engine(station("skip", "immediate")),
|
|
60
64
|
"classic.PreCompact": engine(station("skip", "grace")),
|
|
61
65
|
"classic.PostCompact": engine(station("skip", "grace")),
|
|
@@ -77,7 +81,7 @@ export const MOD_EVENT_TABLE = Object.freeze({
|
|
|
77
81
|
"classic.FileChanged": engine(),
|
|
78
82
|
"classic.DirectoryAdded": engine(),
|
|
79
83
|
"classic.MessageDisplay": engine(),
|
|
80
|
-
"tool.call": engine(station("
|
|
84
|
+
"tool.call": engine(station("refuse", "immediate", ["tool", "tool_use_id", "agentId", "input"], { call: true })),
|
|
81
85
|
"tool.check": engine(station("refuse", "immediate", ["tool", "input", "tool_use_id", "agentId", "ceiling"])),
|
|
82
86
|
"ui.render": surface(station("skip", "grace", RENDER_PINNED)),
|
|
83
87
|
"ui.resolve": surface(station("skip", "grace", ["surface", "component"])),
|
|
@@ -88,8 +92,8 @@ export const MOD_EVENT_TABLE = Object.freeze({
|
|
|
88
92
|
"ui.fault": surface(),
|
|
89
93
|
"ui.scroll": surface(station("skip", "grace", ["component", "requestId", "by", "bodyRows", "contentRows", "origin", "pointer"], { call: true })),
|
|
90
94
|
"ui.focus": surface(station("skip", "grace", ["component", "requestId", "plugin", "origin", "element"], { call: true })),
|
|
91
|
-
"agent.offer": engine(),
|
|
92
|
-
"agent.spawn": engine(),
|
|
95
|
+
"agent.offer": engine(station("skip", "grace", ["agent", "provider"])),
|
|
96
|
+
"agent.spawn": engine(station("refuse_until_run", "immediate", AGENT_SPAWN_PINNED)),
|
|
93
97
|
"prompt.submit": engine(),
|
|
94
98
|
"prompt.fill": surface(station("skip", "grace", ["origin", "mode"], { call: true })),
|
|
95
99
|
"prompt.suggest": surface(station("skip", "grace", ["origin"], { call: true })),
|
|
@@ -117,11 +121,11 @@ export const MOD_EVENT_TABLE = Object.freeze({
|
|
|
117
121
|
"session.attach": engine(),
|
|
118
122
|
"session.detach": engine(),
|
|
119
123
|
"session.measure": engine(),
|
|
120
|
-
"session.end": engine(),
|
|
124
|
+
"session.end": engine(station("skip", "grace", ["reason", "sessionId", "agentId"])),
|
|
121
125
|
"plugin.register": Object.freeze({ side: "both", station: station("refuse", "immediate", ["name", "seat", "tier", "uses"]) }),
|
|
122
126
|
"turn.start": engine(),
|
|
123
127
|
"turn.step": engine(),
|
|
124
|
-
"turn.complete": engine(),
|
|
128
|
+
"turn.complete": engine(station("skip", "grace", ["answer", "agentId", "turn"])),
|
|
125
129
|
"engine.create": engine(),
|
|
126
130
|
"model.complete": engine(method(true)),
|
|
127
131
|
"model.classify": engine(),
|
|
@@ -72,6 +72,11 @@ export interface ReceiptMode {
|
|
|
72
72
|
readonly leaves?: "cloned";
|
|
73
73
|
/** The host's Proxy probe. */
|
|
74
74
|
readonly isProxy?: (value: object) => boolean;
|
|
75
|
+
/** Members of the received value itself (its top level only, never `wire`) that are read PER USE rather than at the receipt:
|
|
76
|
+
* one of them that is an own accessor is never called by the receipt — the copy carries it as an accessor whose every read
|
|
77
|
+
* calls the caller's getter on the caller's object, once per read (a getter that throws, throws at that read). One that is a
|
|
78
|
+
* data property is received like any other member. */
|
|
79
|
+
readonly live?: readonly string[];
|
|
75
80
|
}
|
|
76
81
|
/** Why a receipt was refused. `uncopyable` has two causes, and depth is neither (the walk keeps its own stack): reading
|
|
77
82
|
* the value threw where none of its getters runs — a Proxy's trap, on a receipt given no Proxy probe; what it threw is
|
|
@@ -336,6 +336,16 @@ export function receive(value, mode, held) {
|
|
|
336
336
|
if (f.list && key === "length")
|
|
337
337
|
continue;
|
|
338
338
|
captured = f.captured[key];
|
|
339
|
+
if (f.level === 0 && !f.list && mode.live?.includes(key) === true && !Object.hasOwn(captured, "value")) {
|
|
340
|
+
const get = Object.hasOwn(captured, "get") ? captured.get : undefined;
|
|
341
|
+
const holder = f.v;
|
|
342
|
+
const d = Object.create(null);
|
|
343
|
+
d.get = get === undefined ? () => undefined : () => Reflect.apply(get, holder, []);
|
|
344
|
+
d.enumerable = true;
|
|
345
|
+
d.configurable = true;
|
|
346
|
+
DEFINE(f.out, key, d);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
339
349
|
}
|
|
340
350
|
if (key !== undefined) {
|
|
341
351
|
path[path.length] = key;
|
|
@@ -23,6 +23,10 @@ export interface ModOrigin {
|
|
|
23
23
|
}
|
|
24
24
|
/** The engine's own origin; its `plugin` word is reserved (no registration may take it). */
|
|
25
25
|
export declare const ENGINE_ORIGIN: ModOrigin;
|
|
26
|
+
/** The extension a refusal names: the registration's own name — never the engine's origin word (a raise the engine could not run
|
|
27
|
+
* names no extension), never an absent one. The one reading of "who refused" for every station that refuses a call at the hook
|
|
28
|
+
* layer (`GateDisposition.extension`). Module-level: not part of the kernel's entry. */
|
|
29
|
+
export declare function namedRegistration(registration: string | undefined): string | undefined;
|
|
26
30
|
/** The facts `$.plugin` carries. */
|
|
27
31
|
export interface ModPluginFacts {
|
|
28
32
|
readonly name: string;
|
|
@@ -3,6 +3,9 @@ import { resolveModBudgetMs } from "./budget.js";
|
|
|
3
3
|
export const MODS_INVALID_CODE = "config.mods_invalid";
|
|
4
4
|
export const MODS_REGISTRATION_REFUSED_CODE = "mods.registration_refused";
|
|
5
5
|
export const ENGINE_ORIGIN = Object.freeze({ plugin: "engine", tier: "core" });
|
|
6
|
+
export function namedRegistration(registration) {
|
|
7
|
+
return registration === undefined || registration === ENGINE_ORIGIN.plugin ? undefined : registration;
|
|
8
|
+
}
|
|
6
9
|
export const MOD_TRACE_OUTCOMES = Object.freeze(["returned", "passed", "rejected", "caught", "expired", "kept", "skipped", "bypassed"]);
|
|
7
10
|
export function modsInvalid(message) {
|
|
8
11
|
return Object.assign(new Error(message), { code: MODS_INVALID_CODE });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A leg's two lifecycle stations over its bus, both observations (an answer changes nothing, a failure skips the handler).
|
|
3
|
+
* `turn.complete`: the turn's end records it ({@link noteCompletedTurn}); the next await point raises it once
|
|
4
|
+
* ({@link raiseCompletedTurn}) — the turn boundary after it, or the leg's settle for a turn whose boundary never ran.
|
|
5
|
+
* `e = { answer, reason, turn, isAborted, agentId?, usage? }`; the bottom comes up as `{ text: answer, usage? }`.
|
|
6
|
+
* `session.end`: a leg's terminal settled; `e = { reason, sessionId, agentId? }`, `reason` the terminal status word.
|
|
7
|
+
*/
|
|
8
|
+
import type { AssistantMessage } from "../../internal/llm.js";
|
|
9
|
+
import type { HookInvocationIdentity } from "../hooks.js";
|
|
10
|
+
import { type LegModBus } from "./stations.js";
|
|
11
|
+
/** Why a model turn ended. */
|
|
12
|
+
export type CompletedTurnReason = "answer" | "aborted" | "error";
|
|
13
|
+
/** A model turn that ended, as `turn.complete` names it (raised once, then gone). */
|
|
14
|
+
export interface CompletedTurn {
|
|
15
|
+
readonly answer: string;
|
|
16
|
+
readonly reason: CompletedTurnReason;
|
|
17
|
+
/** The leg's turn count at the turn's end (1 = its first turn). */
|
|
18
|
+
readonly turn: number;
|
|
19
|
+
readonly usage?: {
|
|
20
|
+
readonly inputTokens: number;
|
|
21
|
+
readonly outputTokens: number;
|
|
22
|
+
readonly cacheReadTokens: number;
|
|
23
|
+
readonly cacheWriteTokens: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Where the leg keeps the turns it has not raised yet, in order (a turn can end with no boundary after it — a recovery
|
|
27
|
+
* re-prompt, a failure's own `turn_end` — so the next await point may find more than one). */
|
|
28
|
+
export interface CompletedTurnSeat {
|
|
29
|
+
completed?: readonly CompletedTurn[];
|
|
30
|
+
}
|
|
31
|
+
/** Record the turn that just ended for `turn.complete` (nothing when no handler hangs on it); `aborted` = the leg's cancel was
|
|
32
|
+
* already in force when the turn ended, `usage` absent when none was reported. */
|
|
33
|
+
export declare function noteCompletedTurn(bus: LegModBus, seat: CompletedTurnSeat, message: AssistantMessage | undefined, turn: number, aborted: boolean, usage: CompletedTurn["usage"] | undefined): void;
|
|
34
|
+
/** Raise `turn.complete` for each turn the seat holds, in order, each once (the seat is emptied first). An engine-side
|
|
35
|
+
* rejection is swallowed: an observation never changes what it observes. */
|
|
36
|
+
export declare function raiseCompletedTurn(bus: LegModBus, seat: CompletedTurnSeat, identity: HookInvocationIdentity | undefined, signal: AbortSignal | undefined): Promise<void>;
|
|
37
|
+
/** Raise `session.end` as the leg's terminal settles (nothing when no handler hangs on it). */
|
|
38
|
+
export declare function raiseSessionEnd(bus: LegModBus, identity: HookInvocationIdentity | undefined, end: {
|
|
39
|
+
readonly reason: string;
|
|
40
|
+
readonly sessionId: string;
|
|
41
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { classicEventBase } from "./stations.js";
|
|
2
|
+
const answerOf = (message) => (message?.content ?? []).flatMap((c) => (c.type === "text" ? [c.text] : [])).join("");
|
|
3
|
+
export function noteCompletedTurn(bus, seat, message, turn, aborted, usage) {
|
|
4
|
+
if (!bus.hasHandlers("turn.complete"))
|
|
5
|
+
return;
|
|
6
|
+
const reason = aborted || message?.stopReason === "aborted" ? "aborted" : message?.stopReason === "error" ? "error" : "answer";
|
|
7
|
+
const ended = Object.freeze({ answer: answerOf(message), reason, turn, ...(usage !== undefined ? { usage: Object.freeze({ inputTokens: usage.inputTokens, outputTokens: usage.outputTokens, cacheReadTokens: usage.cacheReadTokens, cacheWriteTokens: usage.cacheWriteTokens }) } : {}) });
|
|
8
|
+
seat.completed = Object.freeze([...(seat.completed ?? []), ended]);
|
|
9
|
+
}
|
|
10
|
+
export async function raiseCompletedTurn(bus, seat, identity, signal) {
|
|
11
|
+
const turns = seat.completed ?? [];
|
|
12
|
+
seat.completed = undefined;
|
|
13
|
+
if (!bus.hasHandlers("turn.complete"))
|
|
14
|
+
return;
|
|
15
|
+
for (const turn of turns) {
|
|
16
|
+
const e = { ...classicEventBase(identity), answer: turn.answer, reason: turn.reason, turn: turn.turn, isAborted: turn.reason === "aborted", ...(turn.usage !== undefined ? { usage: turn.usage } : {}) };
|
|
17
|
+
const core = Object.freeze({ text: turn.answer, ...(turn.usage !== undefined ? { usage: turn.usage } : {}) });
|
|
18
|
+
try {
|
|
19
|
+
await bus.dispatch("turn.complete", e, { bottom: () => core, ...(signal !== undefined ? { signal } : {}) });
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function raiseSessionEnd(bus, identity, end) {
|
|
26
|
+
if (!bus.hasHandlers("session.end"))
|
|
27
|
+
return;
|
|
28
|
+
const e = { ...classicEventBase(identity), reason: end.reason, sessionId: end.sessionId };
|
|
29
|
+
const core = Object.freeze({ sessionId: end.sessionId });
|
|
30
|
+
try {
|
|
31
|
+
await bus.dispatch("session.end", e, { bottom: () => core });
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
}
|
|
35
|
+
}
|