@sema-agent/core 7.72.0 → 7.74.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 +565 -0
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +46 -2
- package/dist/agents/list-agents-tool.js +1 -1
- package/dist/agents/parked-resume-drive.d.ts +10 -0
- package/dist/agents/parked-resume-drive.js +9 -0
- package/dist/agents/retain-ledger.d.ts +3 -0
- package/dist/agents/retain-ledger.js +3 -3
- package/dist/agents/send-message-tool.js +5 -4
- package/dist/agents/send-user-message-tool.d.ts +12 -0
- package/dist/agents/send-user-message-tool.js +67 -0
- package/dist/agents/subagent-steps.d.ts +9 -0
- package/dist/agents/subagent-steps.js +38 -0
- package/dist/agents/subagent.d.ts +2 -0
- package/dist/agents/subagent.js +43 -12
- package/dist/agents/verify.js +23 -8
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.d.ts +42 -1
- package/dist/brain/anthropic.js +68 -13
- package/dist/brain/failover.d.ts +5 -0
- package/dist/brain/failover.js +51 -22
- package/dist/brain/model-lane.d.ts +12 -3
- package/dist/brain/model-lane.js +5 -5
- package/dist/brain/open-responses.js +7 -8
- package/dist/brain/openai.js +31 -24
- package/dist/brain/route-adjudicator.d.ts +33 -4
- package/dist/brain/route-adjudicator.js +49 -12
- package/dist/brain/stream-engine.js +166 -156
- package/dist/brain/stream-shared.d.ts +4 -3
- package/dist/brain/stream-shared.js +2 -2
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/allow-entry.js +4 -4
- package/dist/core/ask-class.d.ts +2 -2
- package/dist/core/ask-headline.d.ts +1 -1
- package/dist/core/ask-origin.d.ts +44 -4
- package/dist/core/ask-origin.js +29 -10
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/background-agent-store.d.ts +1 -0
- package/dist/core/background-agent-store.js +49 -8
- package/dist/core/checkpoint-features.d.ts +3 -2
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-rekey.d.ts +1 -1
- package/dist/core/checkpoint-rekey.js +6 -1
- package/dist/core/checkpoint-requirements.d.ts +23 -3
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-row-verdict.d.ts +1 -1
- package/dist/core/checkpoint-row-verdict.js +9 -3
- package/dist/core/checkpoint-store.d.ts +26 -2
- package/dist/core/checkpoint-store.js +9 -2
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +1 -0
- package/dist/core/cron.js +9 -1
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/deployment-shape.d.ts +7 -0
- package/dist/core/deployment-shape.js +19 -0
- package/dist/core/engine-capabilities.d.ts +13 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +41 -28
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +19 -7
- package/dist/core/entries-not-applied.js +33 -1
- package/dist/core/gate-fold.js +5 -4
- package/dist/core/gate-lanes.js +8 -12
- package/dist/core/gate-outcome.d.ts +8 -2
- package/dist/core/gate-outcome.js +10 -3
- package/dist/core/governance-codes.d.ts +14 -2
- package/dist/core/governance-codes.js +22 -6
- package/dist/core/hook-condition.d.ts +37 -0
- package/dist/core/hook-condition.js +567 -0
- package/dist/core/hooks.d.ts +5 -0
- package/dist/core/hooks.js +1 -0
- package/dist/core/host-instance.d.ts +23 -0
- package/dist/core/host-instance.js +69 -0
- package/dist/core/instruction-preview.d.ts +63 -0
- package/dist/core/instruction-preview.js +406 -0
- package/dist/core/leg-budget.d.ts +26 -0
- package/dist/core/leg-budget.js +9 -0
- package/dist/core/leg-identity.d.ts +51 -1
- package/dist/core/leg-identity.js +45 -2
- package/dist/core/manager-launch-check.d.ts +48 -0
- package/dist/core/manager-launch-check.js +64 -0
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-injection-drop.d.ts +20 -10
- package/dist/core/mcp-injection-drop.js +9 -3
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/member-outcome.d.ts +3 -2
- package/dist/core/member-outcome.js +1 -1
- package/dist/core/memory-engine/deletion-record.d.ts +46 -0
- package/dist/core/memory-engine/deletion-record.js +96 -0
- package/dist/core/memory-engine/engine.js +24 -16
- package/dist/core/memory-engine/file-backend.js +7 -5
- package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
- package/dist/core/memory-engine/projection-ledger.js +1 -1
- package/dist/core/memory-engine/scope-contract.d.ts +18 -13
- package/dist/core/memory-engine/scope-contract.js +18 -18
- package/dist/core/memory-engine/sync-client.js +26 -6
- package/dist/core/memory-engine/sync.d.ts +20 -2
- package/dist/core/memory-engine/sync.js +18 -17
- package/dist/core/mode-policy.d.ts +25 -6
- package/dist/core/mode-policy.js +33 -8
- package/dist/core/model-seat.d.ts +8 -5
- package/dist/core/model-shell.d.ts +129 -0
- package/dist/core/model-shell.js +249 -0
- package/dist/core/mods/kernel/digest.d.ts +4 -0
- package/dist/core/mods/kernel/digest.js +5 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +15 -6
- package/dist/core/mods/kernel/events.d.ts +21 -5
- package/dist/core/mods/kernel/events.js +19 -10
- package/dist/core/mods/kernel/hash-mirror.d.ts +1 -0
- package/dist/core/mods/kernel/hash-mirror.js +55 -0
- package/dist/core/mods/kernel/index.d.ts +1 -0
- package/dist/core/mods/kernel/index.js +1 -0
- package/dist/core/mods/kernel/package-reader.d.ts +48 -0
- package/dist/core/mods/kernel/package-reader.js +149 -0
- package/dist/core/mods/kernel/site-rules.d.ts +4 -0
- package/dist/core/mods/kernel/site-rules.js +13 -0
- package/dist/core/mods/package.d.ts +7 -3
- package/dist/core/mods/package.js +47 -80
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/parent-spec-seat.d.ts +13 -11
- package/dist/core/parent-spec-seat.js +13 -9
- package/dist/core/peer-seat.js +3 -3
- package/dist/core/peer-task-store.d.ts +365 -0
- package/dist/core/peer-task-store.js +682 -0
- package/dist/core/permission-rule-consent.js +6 -11
- package/dist/core/permission-rule-model.d.ts +27 -0
- package/dist/core/permission-rule-model.js +33 -5
- package/dist/core/permission-rule-org.js +13 -3
- package/dist/core/permission-rule-provider.d.ts +35 -33
- package/dist/core/permission-rule-provider.js +38 -295
- package/dist/core/permission-rule-store.d.ts +181 -8
- package/dist/core/permission-rule-store.js +420 -17
- package/dist/core/permission-rule-sync.js +15 -1
- package/dist/core/permission-rules.js +4 -1
- package/dist/core/project-seat.d.ts +55 -0
- package/dist/core/project-seat.js +96 -0
- package/dist/core/protocol-http-auth.d.ts +3 -2
- package/dist/core/protocol-http-auth.js +26 -18
- package/dist/core/remote-env.d.ts +4 -4
- package/dist/core/retain-seat.d.ts +42 -0
- package/dist/core/retain-seat.js +76 -0
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rewind-refusal-codes.d.ts +8 -0
- package/dist/core/rewind-refusal-codes.js +12 -0
- package/dist/core/roles.d.ts +2 -2
- package/dist/core/roles.js +15 -1
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/rule-store-fault.d.ts +9 -7
- package/dist/core/rule-store-fault.js +8 -3
- package/dist/core/run-ledger-seat.d.ts +66 -0
- package/dist/core/run-ledger-seat.js +70 -0
- package/dist/core/run-ledger.d.ts +332 -0
- package/dist/core/run-ledger.js +550 -0
- package/dist/core/runner/checkpoint-scope.d.ts +14 -3
- package/dist/core/runner/checkpoint-scope.js +16 -6
- package/dist/core/runner/compact-session.js +1 -1
- package/dist/core/runner/construction-doors.js +8 -0
- package/dist/core/runner/contracts.d.ts +21 -5
- package/dist/core/runner/cross-boundary-lane.d.ts +8 -1
- package/dist/core/runner/cross-boundary-lane.js +4 -0
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/gate-exit.d.ts +7 -0
- package/dist/core/runner/gate-exit.js +2 -1
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/model-lane-seat.d.ts +3 -0
- package/dist/core/runner/model-lane-seat.js +4 -0
- package/dist/core/runner/nested-memory-lane.d.ts +22 -5
- package/dist/core/runner/nested-memory-lane.js +91 -30
- package/dist/core/runner/person-path-rows.d.ts +27 -16
- package/dist/core/runner/person-path-rows.js +93 -15
- package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +13 -7
- package/dist/core/runner/prepare-context-lane.js +1 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +6 -0
- package/dist/core/runner/prepare-execution-env.d.ts +3 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +6 -0
- package/dist/core/runner/prepare-gate-stations.js +3 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
- package/dist/core/runner/prepare-hands-readface.js +15 -3
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
- package/dist/core/runner/prepare-inherited-gate.js +13 -5
- package/dist/core/runner/prepare-offload-wrappers.js +1 -1
- package/dist/core/runner/prepare-run-refs.d.ts +1 -1
- package/dist/core/runner/prepare-run-refs.js +3 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
- package/dist/core/runner/prepare-suspend-saga.js +4 -2
- package/dist/core/runner/prepare-task.js +42 -30
- package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
- package/dist/core/runner/prepare-turn-wiring.js +2 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +8 -6
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-policy-outcome.js +5 -2
- package/dist/core/runner/resume-review-outcome.d.ts +3 -0
- package/dist/core/runner/resume-review-outcome.js +24 -1
- package/dist/core/runner/role-seat-defaulted.d.ts +3 -3
- package/dist/core/runner/role-seat-defaulted.js +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.js +3 -3
- package/dist/core/runner/run-harness-handlers.js +4 -1
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +5 -2
- package/dist/core/runner/run-notification-lane.js +20 -1
- package/dist/core/runner/run-settle-and-teardown.js +21 -12
- package/dist/core/runner/run-stop-and-final-verify.js +6 -0
- package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
- package/dist/core/runner/runtask.d.ts +6 -2
- package/dist/core/runner/runtask.js +21 -9
- package/dist/core/runner/shell-env-withheld.d.ts +6 -4
- package/dist/core/runner/shell-env-withheld.js +25 -3
- package/dist/core/runner/stop-tail-notice.d.ts +10 -2
- package/dist/core/runner/stop-tail-notice.js +9 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/sub-agent-deny-lists.js +9 -5
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +6 -1
- package/dist/core/runner/terminal-account.js +16 -1
- package/dist/core/runner/tool-end-body.d.ts +1 -1
- package/dist/core/runner/tool-not-executed.d.ts +27 -8
- package/dist/core/runner/tool-not-executed.js +22 -11
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner/write-protection-station.d.ts +1 -1
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +17 -10
- package/dist/core/secret-env.d.ts +61 -37
- package/dist/core/secret-env.js +49 -49
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +1 -0
- package/dist/core/session-store.d.ts +12 -6
- package/dist/core/session-store.js +26 -6
- package/dist/core/session.d.ts +31 -8
- package/dist/core/shell-read-silence.d.ts +40 -2
- package/dist/core/shell-read-silence.js +23 -4
- package/dist/core/store-contracts/checkpoint-store-contract.js +10 -0
- package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
- package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
- package/dist/core/store-contracts/session-store-contract.js +87 -3
- package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
- package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
- package/dist/core/task-event.d.ts +14 -7
- package/dist/core/task-notification.d.ts +96 -10
- package/dist/core/task-notification.js +135 -6
- package/dist/core/task-registry-agent.d.ts +1 -0
- package/dist/core/task-registry-agent.js +1 -1
- package/dist/core/task-registry-shared.d.ts +12 -1
- package/dist/core/task-registry-shared.js +3 -1
- package/dist/core/task-registry-workflow.d.ts +1 -1
- package/dist/core/task-registry-workflow.js +9 -1
- package/dist/core/task-registry.d.ts +40 -2
- package/dist/core/task-registry.js +80 -15
- package/dist/core/task-result.d.ts +18 -3
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +19 -3
- package/dist/core/task-spec.d.ts +48 -22
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-gate-phase.d.ts +6 -3
- package/dist/core/tool-gate-phase.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +8 -4
- package/dist/core/tool-mount-facts.js +7 -2
- package/dist/core/tool-mount-plan.d.ts +3 -1
- package/dist/core/tool-mount-plan.js +10 -3
- package/dist/core/tool-mount-static.d.ts +1 -1
- package/dist/core/tool-mount-static.js +4 -2
- package/dist/core/tool-result-store.d.ts +56 -3
- package/dist/core/tool-result-store.js +219 -25
- package/dist/core/tool-spec.d.ts +9 -2
- package/dist/core/trace.d.ts +3 -3
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +26 -20
- package/dist/core/wiring-manifest.js +7 -3
- package/dist/core/workflow-journal-store.d.ts +53 -10
- package/dist/core/workflow-journal-store.js +27 -4
- package/dist/core/workflow-run-store-contract.js +16 -0
- package/dist/core/workflow-run-store.d.ts +9 -7
- package/dist/core/workflow-run-store.js +4 -1
- package/dist/engine/execution-env/node-execution-env.d.ts +75 -1
- package/dist/engine/execution-env/node-execution-env.js +227 -13
- package/dist/engine/harness/types.d.ts +49 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +13 -7
- package/dist/engine/llm/validation.d.ts +8 -1
- package/dist/engine/llm/validation.js +31 -2
- package/dist/engine/lsp/node-lsp-manager.js +2 -1
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +15 -2
- package/dist/engine/session/session.js +34 -4
- package/dist/host-env.d.ts +10 -0
- package/dist/host-env.js +1 -0
- package/dist/index.d.ts +28 -9
- package/dist/index.js +22 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/goal.js +1 -1
- package/dist/orchestration/run-workflow-tool.js +40 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
- package/dist/orchestration/workflow-park-adoption.js +47 -12
- package/dist/orchestration/workflow-primitives.js +10 -1
- package/dist/orchestration/workflow-script-runner.d.ts +2 -2
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +31 -7
- package/dist/orchestration/workflow.js +119 -57
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/shell/lex.d.ts +2 -2
- package/dist/shell/lex.js +1 -1
- package/dist/stores/file/permission-rule-store.d.ts +3 -1
- package/dist/stores/file/permission-rule-store.js +0 -1
- package/dist/stores/file/workflow-journal-store.d.ts +16 -3
- package/dist/stores/file/workflow-journal-store.js +93 -5
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/tools/fs/bash-model-shell.d.ts +23 -0
- package/dist/tools/fs/bash-model-shell.js +25 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -0
- package/dist/tools/fs/bash-readonly-classifier.js +3 -0
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/fs-bash.js +13 -11
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- package/dist/tools/fs/read-deny-home.d.ts +1 -1
- package/dist/tools/fs/read-deny-home.js +5 -5
- package/dist/tools/fs/read-deny.d.ts +33 -8
- package/dist/tools/fs/read-deny.js +114 -25
- package/dist/tools/fs/safety.d.ts +4 -1
- package/dist/tools/fs/safety.js +4 -2
- package/dist/tools/fs/shell-read-argv.js +1 -0
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +134 -22
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +21 -11
- package/dist/tools/fs/shell-read-judge.d.ts +13 -1
- package/dist/tools/fs/shell-read-judge.js +26 -7
- package/dist/tools/fs/shell-read-plan.d.ts +7 -3
- package/dist/tools/fs/shell-read-plan.js +8 -5
- package/dist/tools/fs/shell-read-word.d.ts +8 -0
- package/dist/tools/fs/shell-read-word.js +13 -4
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/dist/tools/monitor.js +12 -8
- package/dist/tools/scheduler-tools.d.ts +1 -0
- package/dist/tools/scheduler-tools.js +5 -2
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +192 -3
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core-stores-sql@7.74.0.json +7 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/core@7.74.0.json +68 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/mods-kernel@7.74.0.json +21 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/primitives@7.74.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.74.0.json +8 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core-stores-sql@7.74.0.json +143 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/core@7.74.0.json +2210 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/mods-kernel@7.74.0.json +421 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/primitives@7.74.0.json +174 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
- package/wire-changes/wiki-gate@7.74.0.json +145 -0
package/dist/brain/openai.js
CHANGED
|
@@ -404,9 +404,11 @@ export function createOpenAIBrain(given = {}) {
|
|
|
404
404
|
let lastDegenCheckReasoning = 0;
|
|
405
405
|
const detectRep = config.detectRepetition !== false;
|
|
406
406
|
let emittedTextStart = false;
|
|
407
|
-
let emittedThinkingStart = false;
|
|
408
|
-
let thinkingClosed = false;
|
|
409
407
|
let textIndex = 0;
|
|
408
|
+
let nextIndex = 0;
|
|
409
|
+
const segments = [];
|
|
410
|
+
let segmentOpen = false;
|
|
411
|
+
let thinkingIndex = 0;
|
|
410
412
|
const toolAccum = new Map();
|
|
411
413
|
const responseIds = responseToolCallIds();
|
|
412
414
|
let finishReason = null;
|
|
@@ -422,25 +424,26 @@ export function createOpenAIBrain(given = {}) {
|
|
|
422
424
|
malformedFrames++;
|
|
423
425
|
malformedSample ??= ctrl.providerWords(data).slice(0, 160);
|
|
424
426
|
};
|
|
425
|
-
|
|
427
|
+
let thinkingBlock = { type: "thinking", thinking: "" };
|
|
426
428
|
const textBlock = { type: "text", text: "" };
|
|
427
429
|
const pushReasoningDelta = (delta) => {
|
|
428
430
|
if (!delta)
|
|
429
431
|
return;
|
|
430
432
|
ctrl.sawContentToken();
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
433
|
+
if (!segmentOpen) {
|
|
434
|
+
segmentOpen = true;
|
|
435
|
+
thinkingIndex = nextIndex++;
|
|
436
|
+
thinkingBlock = { type: "thinking", thinking: "" };
|
|
437
|
+
lastDegenCheckReasoning = 0;
|
|
435
438
|
partial.content = [thinkingBlock];
|
|
436
|
-
out.push({ type: "thinking_start", contentIndex:
|
|
439
|
+
out.push({ type: "thinking_start", contentIndex: thinkingIndex, partial: { ...partial } });
|
|
437
440
|
}
|
|
438
441
|
accumReasoning += delta;
|
|
439
|
-
thinkingBlock.thinking
|
|
440
|
-
out.push({ type: "thinking_delta", contentIndex:
|
|
441
|
-
if (detectRep && !degenerate &&
|
|
442
|
-
lastDegenCheckReasoning =
|
|
443
|
-
if (rep.poll(
|
|
442
|
+
thinkingBlock.thinking += delta;
|
|
443
|
+
out.push({ type: "thinking_delta", contentIndex: thinkingIndex, delta, partial: { ...partial } });
|
|
444
|
+
if (detectRep && !degenerate && thinkingBlock.thinking.length - lastDegenCheckReasoning >= 64) {
|
|
445
|
+
lastDegenCheckReasoning = thinkingBlock.thinking.length;
|
|
446
|
+
if (rep.poll(thinkingBlock.thinking)) {
|
|
444
447
|
degenerate = true;
|
|
445
448
|
degenFace = "reasoning";
|
|
446
449
|
ctrl.cancel();
|
|
@@ -448,22 +451,27 @@ export function createOpenAIBrain(given = {}) {
|
|
|
448
451
|
}
|
|
449
452
|
};
|
|
450
453
|
const closeThinking = () => {
|
|
451
|
-
if (
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
454
|
+
if (!segmentOpen)
|
|
455
|
+
return false;
|
|
456
|
+
segmentOpen = false;
|
|
457
|
+
segments.push(thinkingBlock.thinking);
|
|
458
|
+
out.push({ type: "thinking_end", contentIndex: thinkingIndex, content: thinkingBlock.thinking, partial: { ...partial } });
|
|
459
|
+
return true;
|
|
455
460
|
};
|
|
456
461
|
const pushTextDelta = (delta) => {
|
|
457
462
|
if (!delta)
|
|
458
463
|
return;
|
|
459
464
|
ctrl.sawContentToken();
|
|
465
|
+
const segmentClosed = closeThinking();
|
|
460
466
|
if (!emittedTextStart) {
|
|
461
|
-
closeThinking();
|
|
462
467
|
emittedTextStart = true;
|
|
463
|
-
textIndex =
|
|
468
|
+
textIndex = nextIndex++;
|
|
464
469
|
partial.content = [textBlock];
|
|
465
470
|
out.push({ type: "text_start", contentIndex: textIndex, partial: { ...partial } });
|
|
466
471
|
}
|
|
472
|
+
else if (segmentClosed) {
|
|
473
|
+
partial.content = [textBlock];
|
|
474
|
+
}
|
|
467
475
|
accumText += delta;
|
|
468
476
|
textBlock.text = accumText;
|
|
469
477
|
out.push({ type: "text_delta", contentIndex: textIndex, delta, partial: { ...partial } });
|
|
@@ -522,7 +530,7 @@ export function createOpenAIBrain(given = {}) {
|
|
|
522
530
|
usageRaw = chunk.usage;
|
|
523
531
|
if (chunk.usageUnreadable)
|
|
524
532
|
usageUnreadable = true;
|
|
525
|
-
noteResponseModel(partial, chunk.model, model.id);
|
|
533
|
+
noteResponseModel(partial, chunk.model, model.id, ctrl.providerWords);
|
|
526
534
|
const choice = chunk.choice;
|
|
527
535
|
if (terminalFrameSeen()) {
|
|
528
536
|
if (choice !== undefined && choice.finish !== null && choice.finish !== finishReason)
|
|
@@ -586,8 +594,8 @@ export function createOpenAIBrain(given = {}) {
|
|
|
586
594
|
out.push({ type: "text_end", contentIndex: textIndex, content: textFace, partial: { ...partial } });
|
|
587
595
|
}
|
|
588
596
|
const finalContent = [];
|
|
589
|
-
|
|
590
|
-
|
|
597
|
+
const thinkingBlocks = segments.map((thinking) => ({ type: "thinking", thinking }));
|
|
598
|
+
finalContent.push(...thinkingBlocks);
|
|
591
599
|
if (textFace)
|
|
592
600
|
finalContent.push({ type: "text", text: textFace });
|
|
593
601
|
const toolCalls = [];
|
|
@@ -618,8 +626,7 @@ export function createOpenAIBrain(given = {}) {
|
|
|
618
626
|
const repaired = repairTextToolCalls(textFace, names);
|
|
619
627
|
if (repaired.toolCalls.length > 0) {
|
|
620
628
|
finalContent.length = 0;
|
|
621
|
-
|
|
622
|
-
finalContent.push({ type: "thinking", thinking: accumReasoning });
|
|
629
|
+
finalContent.push(...thinkingBlocks);
|
|
623
630
|
if (repaired.cleanedText)
|
|
624
631
|
finalContent.push({ type: "text", text: repaired.cleanedText });
|
|
625
632
|
for (const repairedCall of repaired.toolCalls) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Model, PerModelAuth } from "../internal/llm.js";
|
|
2
|
+
import type { AssertAllKeysHandled } from "../core/ask-origin.js";
|
|
2
3
|
import type { RouteAdjudication, RouteCredential, RoutePairingConfig, RoutePairingPosture, RouteRefusalCode } from "../internal/llm.js";
|
|
3
4
|
import type { Brain, EngineNotice } from "../core/types.js";
|
|
4
5
|
import { BrainError } from "./errors.js";
|
|
@@ -226,16 +227,33 @@ export interface JudgedRefusal {
|
|
|
226
227
|
ok: false;
|
|
227
228
|
}>;
|
|
228
229
|
}
|
|
230
|
+
/** Whether a route judgment's answer is a Promise (any object whose `then`, read once, is a function): a judgment answers
|
|
231
|
+
* synchronously, so a Promise is no verdict, and its own settlement belongs to nobody — it must not become an unhandled
|
|
232
|
+
* rejection. That very `then` is handed two empty reactions, called with the answer as `this` (a throw of the call is absorbed
|
|
233
|
+
* too). A plain answer is not touched beyond that one read; a `then` that will not read (a strict Proxy whose `get` throws) shows
|
|
234
|
+
* no `then`, so the answer is no Promise and is read by the `ok` it gives — as 7.73.0 read an answer whose members read the same at
|
|
235
|
+
* every read; reading `then` before `ok` is new (`KL-4241-d` (9)). */
|
|
236
|
+
export declare function settleUnread(answer: unknown): boolean;
|
|
237
|
+
/** What a sentence says for a model whose `id` will not read (an accessor that throws, a revoked proxy). */
|
|
238
|
+
export declare const UNREADABLE_MODEL_ID = "<unreadable model id>";
|
|
239
|
+
/** A model's id for a sentence about it: one guarded read; an id that will not read is said as {@link UNREADABLE_MODEL_ID}. */
|
|
240
|
+
export declare function sayableModelId(model: {
|
|
241
|
+
readonly id: string;
|
|
242
|
+
}): string;
|
|
229
243
|
/**
|
|
230
244
|
* THE reading of a route judgment's answer — every seat that asks the deployment Brain's `adjudicateRoute` reads the answer here,
|
|
231
245
|
* once (the model lane before each hop, a derived seat's pre-flight): `undefined` when the route goes ahead — the judgment
|
|
232
246
|
* admitted it (`ok: true`) or gave none (`undefined`: no judgment) — else the route as refused. `ok: false` is a refusal, read
|
|
233
247
|
* member by member; ANY other answer is a judgment that failed ({@link ROUTE_JUDGMENT_FAILED}, the sentence saying how): it
|
|
234
|
-
* threw, answered a Promise (a route judgment answers synchronously — a pending answer is no answer, and
|
|
235
|
-
* admit every route it was asked about), answered a value that is not a verdict, or a verdict whose members would not read.
|
|
236
|
-
* Never throws. `ask` is the call (so its throw is read here); `
|
|
248
|
+
* threw, answered a Promise, whatever `ok` it carries (a route judgment answers synchronously — a pending answer is no answer, and
|
|
249
|
+
* reading it as one would admit every route it was asked about; its settlement is absorbed, {@link settleUnread}), answered a value that is not a verdict, or a verdict whose members would not read.
|
|
250
|
+
* Never throws. `ask` is the call (so its throw is read here); `judged` is the judged model, whose id names it in the sentence —
|
|
251
|
+
* read once, only when there is a refusal to say (a route that goes ahead costs no read of the model), and said as
|
|
252
|
+
* {@link UNREADABLE_MODEL_ID} when it will not read ({@link sayableModelId}).
|
|
237
253
|
*/
|
|
238
|
-
export declare function readRouteJudgment(ask: () => unknown,
|
|
254
|
+
export declare function readRouteJudgment(ask: () => unknown, judged: {
|
|
255
|
+
readonly id: string;
|
|
256
|
+
}): JudgedRefusal | undefined;
|
|
239
257
|
/**
|
|
240
258
|
* THE request gate of a first-party brain — the seat that binds a credential where it is first SENT (the table's other
|
|
241
259
|
* writer is the host's explicit rebind, {@link rebindCredentialOrigin}, which sets a credential's origin by the host's
|
|
@@ -373,6 +391,13 @@ export declare function rebindCredentialOrigin(model: Pick<Model, "id" | "baseUr
|
|
|
373
391
|
* not ride — the header half of the keyless door the blank key is ({@link keyCarriedBy}).
|
|
374
392
|
*/
|
|
375
393
|
export declare function applyRouteCredentialHeaders(merged: Record<string, string>, credential: RouteCredential): void;
|
|
394
|
+
/**
|
|
395
|
+
* THE one reading of "a credential header whose value is blank is no credential and does not ride" ({@link isBlankCredential}):
|
|
396
|
+
* every header of `headers` whose name is a credential header ({@link isCredentialHeaderName}) and whose value is blank is deleted
|
|
397
|
+
* from it. Read by {@link applyRouteCredentialHeaders} on a request's merged bag, and by a judge that answers for the same bag
|
|
398
|
+
* before a request is built (`anthropicCredentialHeadersOf`). A credential header's value is a string.
|
|
399
|
+
*/
|
|
400
|
+
export declare function dropBlankCredentialHeaders(headers: Record<string, string>): void;
|
|
376
401
|
/** A brain's construction config, received ONCE by the engine's receipt law for caller objects
|
|
377
402
|
* ({@link receiveOwnProperties}: a plain object, every own member read once): the request gate and the pre-flight
|
|
378
403
|
* judge both read this frozen copy, so a config object mutated after construction moves neither and the two cannot
|
|
@@ -405,6 +430,10 @@ export declare function createBrainRouteJudge(config: {
|
|
|
405
430
|
* built, so a value that is not a boolean is refused at construction rather than at the first request. */
|
|
406
431
|
requireCredential?: boolean;
|
|
407
432
|
}): (model: Model, perModelAuth?: PerModelAuth) => RouteAdjudication;
|
|
433
|
+
/** The words of {@link RoutePairingStatus}, spelled (the release manifest and a host's table read them): fenced both ways to the type below, so neither can gain a word the other lacks. */
|
|
434
|
+
export declare const ROUTE_PAIRING_STATUSES: readonly ["ok:per-model", "ok:paired", "ok:keyless", "broken:credential_mismatch", "broken:credential_missing", "broken:credential_origin_mismatch", "broken:credential_answer_conflict", "broken:protocol_plaintext_credentials", "broken:model_unavailable", "unknown"];
|
|
435
|
+
export type RoutePairingStatusesAllListed = AssertAllKeysHandled<Exclude<RoutePairingStatus, (typeof ROUTE_PAIRING_STATUSES)[number]>>;
|
|
436
|
+
export type RoutePairingStatusesAllWords = AssertAllKeysHandled<Exclude<(typeof ROUTE_PAIRING_STATUSES)[number], RoutePairingStatus>>;
|
|
408
437
|
/**
|
|
409
438
|
* Per-entry pairing status — the read-face predicate a roster/diagnostic surface annotates entries
|
|
410
439
|
* with, so a torn pair is visible at configuration time instead of on the first real request.
|
|
@@ -9,7 +9,7 @@ import { deliverEngineNotice } from "../core/engine-notice.js";
|
|
|
9
9
|
import { uuidv7 } from "../engine/session/uuid.js";
|
|
10
10
|
import { CREDENTIAL_VOCABULARY, REDACTION_MARKS, isRedactionMark } from "@sema-agent/primitives";
|
|
11
11
|
import { PROTOCOL_PLAINTEXT_CREDENTIALS_CODE, crossesNetworkInClear } from "../core/protocol-http-auth.js";
|
|
12
|
-
import { thrownText } from "../core/thrown-value.js";
|
|
12
|
+
import { readMemberOrUnreadable, thrownText, UNREADABLE } from "../core/thrown-value.js";
|
|
13
13
|
import { headerBagOnce } from "./request-params.js";
|
|
14
14
|
const REDACTED_VALUE = REDACTION_MARKS.bare;
|
|
15
15
|
const REDACTED_USERINFO = REDACTION_MARKS.userinfo;
|
|
@@ -553,8 +553,32 @@ const BOUND_BY_WORDS = { declaration: true, table: true, generation: true };
|
|
|
553
553
|
function boundByOf(value) {
|
|
554
554
|
return typeof value === "string" && Object.hasOwn(BOUND_BY_WORDS, value) ? value : undefined;
|
|
555
555
|
}
|
|
556
|
-
export function
|
|
557
|
-
|
|
556
|
+
export function settleUnread(answer) {
|
|
557
|
+
if (typeof answer !== "object" || answer === null)
|
|
558
|
+
return false;
|
|
559
|
+
let then;
|
|
560
|
+
try {
|
|
561
|
+
then = answer.then;
|
|
562
|
+
}
|
|
563
|
+
catch {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
if (typeof then !== "function")
|
|
567
|
+
return false;
|
|
568
|
+
Promise.resolve()
|
|
569
|
+
.then(() => Reflect.apply(then, answer, [() => undefined, () => undefined]))
|
|
570
|
+
.catch(() => undefined);
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
export const UNREADABLE_MODEL_ID = "<unreadable model id>";
|
|
574
|
+
export function sayableModelId(model) {
|
|
575
|
+
const id = readMemberOrUnreadable(model, "id");
|
|
576
|
+
return id === UNREADABLE ? UNREADABLE_MODEL_ID : id;
|
|
577
|
+
}
|
|
578
|
+
export function readRouteJudgment(ask, judged) {
|
|
579
|
+
let said;
|
|
580
|
+
const modelIdOf = () => (said ??= sayableModelId(judged));
|
|
581
|
+
const failed = (how) => ({ code: ROUTE_JUDGMENT_FAILED, fixHint: `the deployment Brain's route judgment for "${modelIdOf()}" ${how}` });
|
|
558
582
|
let answer;
|
|
559
583
|
try {
|
|
560
584
|
answer = ask();
|
|
@@ -565,15 +589,13 @@ export function readRouteJudgment(ask, modelId) {
|
|
|
565
589
|
if (answer === undefined)
|
|
566
590
|
return undefined;
|
|
567
591
|
try {
|
|
592
|
+
if (settleUnread(answer)) {
|
|
593
|
+
return failed("answered a Promise — a route judgment must answer synchronously (a verdict, or undefined for no judgment); nothing was sent");
|
|
594
|
+
}
|
|
568
595
|
const ok = typeof answer === "object" && answer !== null ? answer.ok : undefined;
|
|
569
596
|
if (ok === true)
|
|
570
597
|
return undefined;
|
|
571
598
|
if (ok !== false) {
|
|
572
|
-
const then = typeof answer === "object" && answer !== null ? answer.then : undefined;
|
|
573
|
-
if (typeof then === "function") {
|
|
574
|
-
Promise.resolve(answer).catch(() => undefined);
|
|
575
|
-
return failed("answered a Promise — a route judgment must answer synchronously (a verdict, or undefined for no judgment); nothing was sent");
|
|
576
|
-
}
|
|
577
599
|
return failed(`answered ${describeRejectedValue(answer)}${ok === undefined ? "" : ` whose ok is ${describeRejectedValue(ok)}`} — not a verdict (ok true or false) nor undefined; nothing was sent`);
|
|
578
600
|
}
|
|
579
601
|
const code = answer.code;
|
|
@@ -592,7 +614,7 @@ export function readRouteJudgment(ask, modelId) {
|
|
|
592
614
|
const verdict = {
|
|
593
615
|
ok: false,
|
|
594
616
|
code,
|
|
595
|
-
detail: { modelId: typeof named === "string" ? named :
|
|
617
|
+
detail: { modelId: typeof named === "string" ? named : modelIdOf(), ...roots, ...(boundBy !== undefined ? { boundBy } : {}), fixHint },
|
|
596
618
|
};
|
|
597
619
|
return { code, fixHint, verdict };
|
|
598
620
|
}
|
|
@@ -785,9 +807,12 @@ export function applyRouteCredentialHeaders(merged, credential) {
|
|
|
785
807
|
}
|
|
786
808
|
Object.assign(merged, resolvedCredentialFacts.get(credential)?.headers);
|
|
787
809
|
}
|
|
788
|
-
|
|
810
|
+
dropBlankCredentialHeaders(merged);
|
|
811
|
+
}
|
|
812
|
+
export function dropBlankCredentialHeaders(headers) {
|
|
813
|
+
for (const [k, value] of Object.entries(headers)) {
|
|
789
814
|
if (isCredentialHeaderName(k) && isBlankCredential(value))
|
|
790
|
-
delete
|
|
815
|
+
delete headers[k];
|
|
791
816
|
}
|
|
792
817
|
}
|
|
793
818
|
export function brainConfigSnapshot(given, subject) {
|
|
@@ -822,6 +847,18 @@ export function createBrainRouteJudge(config) {
|
|
|
822
847
|
return adjudicateModelRoute(routed, credential, { baseUrl: config.baseUrl, laneDefault: config.laneDefault, requireCredential });
|
|
823
848
|
};
|
|
824
849
|
}
|
|
850
|
+
export const ROUTE_PAIRING_STATUSES = Object.freeze([
|
|
851
|
+
"ok:per-model",
|
|
852
|
+
"ok:paired",
|
|
853
|
+
"ok:keyless",
|
|
854
|
+
"broken:credential_mismatch",
|
|
855
|
+
"broken:credential_missing",
|
|
856
|
+
"broken:credential_origin_mismatch",
|
|
857
|
+
"broken:credential_answer_conflict",
|
|
858
|
+
"broken:protocol_plaintext_credentials",
|
|
859
|
+
"broken:model_unavailable",
|
|
860
|
+
"unknown",
|
|
861
|
+
]);
|
|
825
862
|
const BROKEN_PAIRING_STATUS = {
|
|
826
863
|
"route.credential_mismatch": "broken:credential_mismatch",
|
|
827
864
|
"route.credential_missing": "broken:credential_missing",
|
|
@@ -908,7 +945,7 @@ export async function adjudicateDerivedRoute(args) {
|
|
|
908
945
|
clearTimeout(timer);
|
|
909
946
|
}
|
|
910
947
|
}
|
|
911
|
-
return readRouteJudgment(() => judge(args.model, auth), args.model
|
|
948
|
+
return readRouteJudgment(() => judge(args.model, auth), args.model);
|
|
912
949
|
}
|
|
913
950
|
export function sameRouteIdentity(a, b) {
|
|
914
951
|
return a.id === b.id && routeKeyOf(a.baseUrl) === routeKeyOf(b.baseUrl);
|