@smthrs/harness 0.0.0-stage → 1.0.0-rc.3
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 +387 -0
- package/LICENSE +21 -0
- package/README.md +138 -2
- package/dist/cjs/AgentEvent.d.ts +3092 -0
- package/dist/cjs/AgentEvent.d.ts.map +1 -0
- package/dist/cjs/AgentEvent.js +1116 -0
- package/dist/cjs/AgentEvent.js.map +7 -0
- package/dist/cjs/CallLedger.d.ts +378 -0
- package/dist/cjs/CallLedger.d.ts.map +1 -0
- package/dist/cjs/CallLedger.js +240 -0
- package/dist/cjs/CallLedger.js.map +7 -0
- package/dist/cjs/Cell.d.ts +774 -0
- package/dist/cjs/Cell.d.ts.map +1 -0
- package/dist/cjs/Cell.js +431 -0
- package/dist/cjs/Cell.js.map +7 -0
- package/dist/cjs/CellCalls.d.ts +115 -0
- package/dist/cjs/CellCalls.d.ts.map +1 -0
- package/dist/cjs/CellCalls.js +98 -0
- package/dist/cjs/CellCalls.js.map +7 -0
- package/dist/cjs/CellHistory.d.ts +102 -0
- package/dist/cjs/CellHistory.d.ts.map +1 -0
- package/dist/cjs/CellHistory.js +54 -0
- package/dist/cjs/CellHistory.js.map +7 -0
- package/dist/cjs/CellTurn.d.ts +1071 -0
- package/dist/cjs/CellTurn.d.ts.map +1 -0
- package/dist/cjs/CellTurn.js +2618 -0
- package/dist/cjs/CellTurn.js.map +7 -0
- package/dist/cjs/CellValidation.d.ts +94 -0
- package/dist/cjs/CellValidation.d.ts.map +1 -0
- package/dist/cjs/CellValidation.js +218 -0
- package/dist/cjs/CellValidation.js.map +7 -0
- package/dist/cjs/Compaction.d.ts +158 -0
- package/dist/cjs/Compaction.d.ts.map +1 -0
- package/dist/cjs/Compaction.js +189 -0
- package/dist/cjs/Compaction.js.map +7 -0
- package/dist/cjs/CompletionClaim.d.ts +801 -0
- package/dist/cjs/CompletionClaim.d.ts.map +1 -0
- package/dist/cjs/CompletionClaim.js +303 -0
- package/dist/cjs/CompletionClaim.js.map +7 -0
- package/dist/cjs/ContextWindow.d.ts +435 -0
- package/dist/cjs/ContextWindow.d.ts.map +1 -0
- package/dist/cjs/ContextWindow.js +319 -0
- package/dist/cjs/ContextWindow.js.map +7 -0
- package/dist/cjs/EngineLike.d.ts +546 -0
- package/dist/cjs/EngineLike.d.ts.map +1 -0
- package/dist/cjs/EngineLike.js +114 -0
- package/dist/cjs/EngineLike.js.map +7 -0
- package/dist/cjs/ExternalTranscript.d.ts +349 -0
- package/dist/cjs/ExternalTranscript.d.ts.map +1 -0
- package/dist/cjs/ExternalTranscript.js +826 -0
- package/dist/cjs/ExternalTranscript.js.map +7 -0
- package/dist/cjs/FailedCall.d.ts +132 -0
- package/dist/cjs/FailedCall.d.ts.map +1 -0
- package/dist/cjs/FailedCall.js +53 -0
- package/dist/cjs/FailedCall.js.map +7 -0
- package/dist/cjs/FlowBinding.d.ts +289 -0
- package/dist/cjs/FlowBinding.d.ts.map +1 -0
- package/dist/cjs/FlowBinding.js +251 -0
- package/dist/cjs/FlowBinding.js.map +7 -0
- package/dist/cjs/HarnessError.d.ts +57 -0
- package/dist/cjs/HarnessError.d.ts.map +1 -0
- package/dist/cjs/HarnessError.js +75 -0
- package/dist/cjs/HarnessError.js.map +7 -0
- package/dist/cjs/Judgement.d.ts +289 -0
- package/dist/cjs/Judgement.d.ts.map +1 -0
- package/dist/cjs/Judgement.js +240 -0
- package/dist/cjs/Judgement.js.map +7 -0
- package/dist/cjs/Monitor.d.ts +374 -0
- package/dist/cjs/Monitor.d.ts.map +1 -0
- package/dist/cjs/Monitor.js +233 -0
- package/dist/cjs/Monitor.js.map +7 -0
- package/dist/cjs/NarrowedCheck.d.ts +523 -0
- package/dist/cjs/NarrowedCheck.d.ts.map +1 -0
- package/dist/cjs/NarrowedCheck.js +263 -0
- package/dist/cjs/NarrowedCheck.js.map +7 -0
- package/dist/cjs/Notifications.d.ts +42 -0
- package/dist/cjs/Notifications.d.ts.map +1 -0
- package/dist/cjs/Notifications.js +177 -0
- package/dist/cjs/Notifications.js.map +7 -0
- package/dist/cjs/Plan.d.ts +127 -0
- package/dist/cjs/Plan.d.ts.map +1 -0
- package/dist/cjs/Plan.js +77 -0
- package/dist/cjs/Plan.js.map +7 -0
- package/dist/cjs/QuickJSSandbox.d.ts +151 -0
- package/dist/cjs/QuickJSSandbox.d.ts.map +1 -0
- package/dist/cjs/QuickJSSandbox.js +987 -0
- package/dist/cjs/QuickJSSandbox.js.map +7 -0
- package/dist/cjs/Relevance.d.ts +213 -0
- package/dist/cjs/Relevance.d.ts.map +1 -0
- package/dist/cjs/Relevance.js +183 -0
- package/dist/cjs/Relevance.js.map +7 -0
- package/dist/cjs/Sandbox.d.ts +637 -0
- package/dist/cjs/Sandbox.d.ts.map +1 -0
- package/dist/cjs/Sandbox.js +260 -0
- package/dist/cjs/Sandbox.js.map +7 -0
- package/dist/cjs/Steering.d.ts +464 -0
- package/dist/cjs/Steering.d.ts.map +1 -0
- package/dist/cjs/Steering.js +153 -0
- package/dist/cjs/Steering.js.map +7 -0
- package/dist/cjs/StructuredOutput.d.ts +252 -0
- package/dist/cjs/StructuredOutput.d.ts.map +1 -0
- package/dist/cjs/StructuredOutput.js +266 -0
- package/dist/cjs/StructuredOutput.js.map +7 -0
- package/dist/cjs/Sufficiency.d.ts +195 -0
- package/dist/cjs/Sufficiency.d.ts.map +1 -0
- package/dist/cjs/Sufficiency.js +110 -0
- package/dist/cjs/Sufficiency.js.map +7 -0
- package/dist/cjs/Supervisor.d.ts +719 -0
- package/dist/cjs/Supervisor.d.ts.map +1 -0
- package/dist/cjs/Supervisor.js +313 -0
- package/dist/cjs/Supervisor.js.map +7 -0
- package/dist/cjs/Tokens.d.ts +86 -0
- package/dist/cjs/Tokens.d.ts.map +1 -0
- package/dist/cjs/Tokens.js +72 -0
- package/dist/cjs/Tokens.js.map +7 -0
- package/dist/cjs/Transcript.d.ts +171 -0
- package/dist/cjs/Transcript.d.ts.map +1 -0
- package/dist/cjs/Transcript.js +342 -0
- package/dist/cjs/Transcript.js.map +7 -0
- package/dist/cjs/TruncatedOutput.d.ts +186 -0
- package/dist/cjs/TruncatedOutput.d.ts.map +1 -0
- package/dist/cjs/TruncatedOutput.js +143 -0
- package/dist/cjs/TruncatedOutput.js.map +7 -0
- package/dist/cjs/UnmovedTree.d.ts +113 -0
- package/dist/cjs/UnmovedTree.d.ts.map +1 -0
- package/dist/cjs/UnmovedTree.js +38 -0
- package/dist/cjs/UnmovedTree.js.map +7 -0
- package/dist/cjs/UnresolvedFailure.d.ts +196 -0
- package/dist/cjs/UnresolvedFailure.d.ts.map +1 -0
- package/dist/cjs/UnresolvedFailure.js +77 -0
- package/dist/cjs/UnresolvedFailure.js.map +7 -0
- package/dist/cjs/VacuousVerification.d.ts +237 -0
- package/dist/cjs/VacuousVerification.d.ts.map +1 -0
- package/dist/cjs/VacuousVerification.js +91 -0
- package/dist/cjs/VacuousVerification.js.map +7 -0
- package/dist/cjs/VariablesPanel.d.ts +117 -0
- package/dist/cjs/VariablesPanel.d.ts.map +1 -0
- package/dist/cjs/VariablesPanel.js +108 -0
- package/dist/cjs/VariablesPanel.js.map +7 -0
- package/dist/cjs/index.d.ts +172 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +99 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/bytes.d.ts +36 -0
- package/dist/cjs/internal/bytes.d.ts.map +1 -0
- package/dist/cjs/internal/bytes.js +57 -0
- package/dist/cjs/internal/bytes.js.map +7 -0
- package/dist/cjs/internal/cellPrompt.d.ts +122 -0
- package/dist/cjs/internal/cellPrompt.d.ts.map +1 -0
- package/dist/cjs/internal/cellPrompt.js +146 -0
- package/dist/cjs/internal/cellPrompt.js.map +7 -0
- package/dist/cjs/internal/compactable.d.ts +44 -0
- package/dist/cjs/internal/compactable.d.ts.map +1 -0
- package/dist/cjs/internal/compactable.js +56 -0
- package/dist/cjs/internal/compactable.js.map +7 -0
- package/dist/cjs/internal/compactionMarks.d.ts +278 -0
- package/dist/cjs/internal/compactionMarks.d.ts.map +1 -0
- package/dist/cjs/internal/compactionMarks.js +212 -0
- package/dist/cjs/internal/compactionMarks.js.map +7 -0
- package/dist/cjs/internal/demandText.d.ts +95 -0
- package/dist/cjs/internal/demandText.d.ts.map +1 -0
- package/dist/cjs/internal/demandText.js +70 -0
- package/dist/cjs/internal/demandText.js.map +7 -0
- package/dist/cjs/internal/elide.d.ts +109 -0
- package/dist/cjs/internal/elide.d.ts.map +1 -0
- package/dist/cjs/internal/elide.js +59 -0
- package/dist/cjs/internal/elide.js.map +7 -0
- package/dist/cjs/internal/frame.d.ts +463 -0
- package/dist/cjs/internal/frame.d.ts.map +1 -0
- package/dist/cjs/internal/frame.js +514 -0
- package/dist/cjs/internal/frame.js.map +7 -0
- package/dist/cjs/internal/nonNegativeSafeInt.d.ts +20 -0
- package/dist/cjs/internal/nonNegativeSafeInt.d.ts.map +1 -0
- package/dist/cjs/internal/nonNegativeSafeInt.js +29 -0
- package/dist/cjs/internal/nonNegativeSafeInt.js.map +7 -0
- package/dist/cjs/internal/paidUsage.d.ts +52 -0
- package/dist/cjs/internal/paidUsage.d.ts.map +1 -0
- package/dist/cjs/internal/paidUsage.js +70 -0
- package/dist/cjs/internal/paidUsage.js.map +7 -0
- package/dist/cjs/internal/printChannel.d.ts +233 -0
- package/dist/cjs/internal/printChannel.d.ts.map +1 -0
- package/dist/cjs/internal/printChannel.js +165 -0
- package/dist/cjs/internal/printChannel.js.map +7 -0
- package/dist/cjs/internal/printsObservation.d.ts +26 -0
- package/dist/cjs/internal/printsObservation.d.ts.map +1 -0
- package/dist/cjs/internal/printsObservation.js +27 -0
- package/dist/cjs/internal/printsObservation.js.map +7 -0
- package/dist/cjs/internal/refusal.d.ts +40 -0
- package/dist/cjs/internal/refusal.d.ts.map +1 -0
- package/dist/cjs/internal/refusal.js +45 -0
- package/dist/cjs/internal/refusal.js.map +7 -0
- package/dist/cjs/internal/supervision.d.ts +174 -0
- package/dist/cjs/internal/supervision.d.ts.map +1 -0
- package/dist/cjs/internal/supervision.js +402 -0
- package/dist/cjs/internal/supervision.js.map +7 -0
- package/dist/cjs/internal/unfinishedWork.d.ts +99 -0
- package/dist/cjs/internal/unfinishedWork.d.ts.map +1 -0
- package/dist/cjs/internal/unfinishedWork.js +80 -0
- package/dist/cjs/internal/unfinishedWork.js.map +7 -0
- package/dist/cjs/internal/unobservedCall.d.ts +112 -0
- package/dist/cjs/internal/unobservedCall.d.ts.map +1 -0
- package/dist/cjs/internal/unobservedCall.js +345 -0
- package/dist/cjs/internal/unobservedCall.js.map +7 -0
- package/dist/cjs/internal/untrustedData.d.ts +14 -0
- package/dist/cjs/internal/untrustedData.d.ts.map +1 -0
- package/dist/cjs/internal/untrustedData.js +30 -0
- package/dist/cjs/internal/untrustedData.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/AgentEvent.d.ts +3092 -0
- package/dist/esm/AgentEvent.d.ts.map +1 -0
- package/dist/esm/AgentEvent.js +1610 -0
- package/dist/esm/AgentEvent.js.map +1 -0
- package/dist/esm/CallLedger.d.ts +378 -0
- package/dist/esm/CallLedger.d.ts.map +1 -0
- package/dist/esm/CallLedger.js +506 -0
- package/dist/esm/CallLedger.js.map +1 -0
- package/dist/esm/Cell.d.ts +774 -0
- package/dist/esm/Cell.d.ts.map +1 -0
- package/dist/esm/Cell.js +772 -0
- package/dist/esm/Cell.js.map +1 -0
- package/dist/esm/CellCalls.d.ts +115 -0
- package/dist/esm/CellCalls.d.ts.map +1 -0
- package/dist/esm/CellCalls.js +97 -0
- package/dist/esm/CellCalls.js.map +1 -0
- package/dist/esm/CellHistory.d.ts +102 -0
- package/dist/esm/CellHistory.d.ts.map +1 -0
- package/dist/esm/CellHistory.js +91 -0
- package/dist/esm/CellHistory.js.map +1 -0
- package/dist/esm/CellTurn.d.ts +1071 -0
- package/dist/esm/CellTurn.d.ts.map +1 -0
- package/dist/esm/CellTurn.js +3410 -0
- package/dist/esm/CellTurn.js.map +1 -0
- package/dist/esm/CellValidation.d.ts +94 -0
- package/dist/esm/CellValidation.d.ts.map +1 -0
- package/dist/esm/CellValidation.js +335 -0
- package/dist/esm/CellValidation.js.map +1 -0
- package/dist/esm/Compaction.d.ts +158 -0
- package/dist/esm/Compaction.d.ts.map +1 -0
- package/dist/esm/Compaction.js +216 -0
- package/dist/esm/Compaction.js.map +1 -0
- package/dist/esm/CompletionClaim.d.ts +801 -0
- package/dist/esm/CompletionClaim.d.ts.map +1 -0
- package/dist/esm/CompletionClaim.js +833 -0
- package/dist/esm/CompletionClaim.js.map +1 -0
- package/dist/esm/ContextWindow.d.ts +435 -0
- package/dist/esm/ContextWindow.d.ts.map +1 -0
- package/dist/esm/ContextWindow.js +427 -0
- package/dist/esm/ContextWindow.js.map +1 -0
- package/dist/esm/EngineLike.d.ts +546 -0
- package/dist/esm/EngineLike.d.ts.map +1 -0
- package/dist/esm/EngineLike.js +218 -0
- package/dist/esm/EngineLike.js.map +1 -0
- package/dist/esm/ExternalTranscript.d.ts +349 -0
- package/dist/esm/ExternalTranscript.d.ts.map +1 -0
- package/dist/esm/ExternalTranscript.js +987 -0
- package/dist/esm/ExternalTranscript.js.map +1 -0
- package/dist/esm/FailedCall.d.ts +132 -0
- package/dist/esm/FailedCall.d.ts.map +1 -0
- package/dist/esm/FailedCall.js +131 -0
- package/dist/esm/FailedCall.js.map +1 -0
- package/dist/esm/FlowBinding.d.ts +289 -0
- package/dist/esm/FlowBinding.d.ts.map +1 -0
- package/dist/esm/FlowBinding.js +376 -0
- package/dist/esm/FlowBinding.js.map +1 -0
- package/dist/esm/HarnessError.d.ts +57 -0
- package/dist/esm/HarnessError.d.ts.map +1 -0
- package/dist/esm/HarnessError.js +85 -0
- package/dist/esm/HarnessError.js.map +1 -0
- package/dist/esm/Judgement.d.ts +289 -0
- package/dist/esm/Judgement.d.ts.map +1 -0
- package/dist/esm/Judgement.js +305 -0
- package/dist/esm/Judgement.js.map +1 -0
- package/dist/esm/Monitor.d.ts +374 -0
- package/dist/esm/Monitor.d.ts.map +1 -0
- package/dist/esm/Monitor.js +370 -0
- package/dist/esm/Monitor.js.map +1 -0
- package/dist/esm/NarrowedCheck.d.ts +523 -0
- package/dist/esm/NarrowedCheck.d.ts.map +1 -0
- package/dist/esm/NarrowedCheck.js +612 -0
- package/dist/esm/NarrowedCheck.js.map +1 -0
- package/dist/esm/Notifications.d.ts +42 -0
- package/dist/esm/Notifications.d.ts.map +1 -0
- package/dist/esm/Notifications.js +215 -0
- package/dist/esm/Notifications.js.map +1 -0
- package/dist/esm/Plan.d.ts +127 -0
- package/dist/esm/Plan.d.ts.map +1 -0
- package/dist/esm/Plan.js +97 -0
- package/dist/esm/Plan.js.map +1 -0
- package/dist/esm/QuickJSSandbox.d.ts +151 -0
- package/dist/esm/QuickJSSandbox.d.ts.map +1 -0
- package/dist/esm/QuickJSSandbox.js +1364 -0
- package/dist/esm/QuickJSSandbox.js.map +1 -0
- package/dist/esm/Relevance.d.ts +213 -0
- package/dist/esm/Relevance.d.ts.map +1 -0
- package/dist/esm/Relevance.js +254 -0
- package/dist/esm/Relevance.js.map +1 -0
- package/dist/esm/Sandbox.d.ts +637 -0
- package/dist/esm/Sandbox.d.ts.map +1 -0
- package/dist/esm/Sandbox.js +464 -0
- package/dist/esm/Sandbox.js.map +1 -0
- package/dist/esm/Steering.d.ts +464 -0
- package/dist/esm/Steering.d.ts.map +1 -0
- package/dist/esm/Steering.js +193 -0
- package/dist/esm/Steering.js.map +1 -0
- package/dist/esm/StructuredOutput.d.ts +252 -0
- package/dist/esm/StructuredOutput.d.ts.map +1 -0
- package/dist/esm/StructuredOutput.js +430 -0
- package/dist/esm/StructuredOutput.js.map +1 -0
- package/dist/esm/Sufficiency.d.ts +195 -0
- package/dist/esm/Sufficiency.d.ts.map +1 -0
- package/dist/esm/Sufficiency.js +207 -0
- package/dist/esm/Sufficiency.js.map +1 -0
- package/dist/esm/Supervisor.d.ts +719 -0
- package/dist/esm/Supervisor.d.ts.map +1 -0
- package/dist/esm/Supervisor.js +575 -0
- package/dist/esm/Supervisor.js.map +1 -0
- package/dist/esm/Tokens.d.ts +86 -0
- package/dist/esm/Tokens.d.ts.map +1 -0
- package/dist/esm/Tokens.js +92 -0
- package/dist/esm/Tokens.js.map +1 -0
- package/dist/esm/Transcript.d.ts +171 -0
- package/dist/esm/Transcript.d.ts.map +1 -0
- package/dist/esm/Transcript.js +424 -0
- package/dist/esm/Transcript.js.map +1 -0
- package/dist/esm/TruncatedOutput.d.ts +186 -0
- package/dist/esm/TruncatedOutput.d.ts.map +1 -0
- package/dist/esm/TruncatedOutput.js +257 -0
- package/dist/esm/TruncatedOutput.js.map +1 -0
- package/dist/esm/UnmovedTree.d.ts +113 -0
- package/dist/esm/UnmovedTree.d.ts.map +1 -0
- package/dist/esm/UnmovedTree.js +90 -0
- package/dist/esm/UnmovedTree.js.map +1 -0
- package/dist/esm/UnresolvedFailure.d.ts +196 -0
- package/dist/esm/UnresolvedFailure.d.ts.map +1 -0
- package/dist/esm/UnresolvedFailure.js +218 -0
- package/dist/esm/UnresolvedFailure.js.map +1 -0
- package/dist/esm/VacuousVerification.d.ts +237 -0
- package/dist/esm/VacuousVerification.d.ts.map +1 -0
- package/dist/esm/VacuousVerification.js +245 -0
- package/dist/esm/VacuousVerification.js.map +1 -0
- package/dist/esm/VariablesPanel.d.ts +117 -0
- package/dist/esm/VariablesPanel.d.ts.map +1 -0
- package/dist/esm/VariablesPanel.js +142 -0
- package/dist/esm/VariablesPanel.js.map +1 -0
- package/dist/esm/index.d.ts +172 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +172 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/bytes.d.ts +36 -0
- package/dist/esm/internal/bytes.d.ts.map +1 -0
- package/dist/esm/internal/bytes.js +70 -0
- package/dist/esm/internal/bytes.js.map +1 -0
- package/dist/esm/internal/cellPrompt.d.ts +122 -0
- package/dist/esm/internal/cellPrompt.d.ts.map +1 -0
- package/dist/esm/internal/cellPrompt.js +276 -0
- package/dist/esm/internal/cellPrompt.js.map +1 -0
- package/dist/esm/internal/compactable.d.ts +44 -0
- package/dist/esm/internal/compactable.d.ts.map +1 -0
- package/dist/esm/internal/compactable.js +71 -0
- package/dist/esm/internal/compactable.js.map +1 -0
- package/dist/esm/internal/compactionMarks.d.ts +278 -0
- package/dist/esm/internal/compactionMarks.d.ts.map +1 -0
- package/dist/esm/internal/compactionMarks.js +317 -0
- package/dist/esm/internal/compactionMarks.js.map +1 -0
- package/dist/esm/internal/demandText.d.ts +95 -0
- package/dist/esm/internal/demandText.d.ts.map +1 -0
- package/dist/esm/internal/demandText.js +128 -0
- package/dist/esm/internal/demandText.js.map +1 -0
- package/dist/esm/internal/elide.d.ts +109 -0
- package/dist/esm/internal/elide.d.ts.map +1 -0
- package/dist/esm/internal/elide.js +123 -0
- package/dist/esm/internal/elide.js.map +1 -0
- package/dist/esm/internal/frame.d.ts +463 -0
- package/dist/esm/internal/frame.d.ts.map +1 -0
- package/dist/esm/internal/frame.js +861 -0
- package/dist/esm/internal/frame.js.map +1 -0
- package/dist/esm/internal/nonNegativeSafeInt.d.ts +20 -0
- package/dist/esm/internal/nonNegativeSafeInt.d.ts.map +1 -0
- package/dist/esm/internal/nonNegativeSafeInt.js +20 -0
- package/dist/esm/internal/nonNegativeSafeInt.js.map +1 -0
- package/dist/esm/internal/paidUsage.d.ts +52 -0
- package/dist/esm/internal/paidUsage.d.ts.map +1 -0
- package/dist/esm/internal/paidUsage.js +72 -0
- package/dist/esm/internal/paidUsage.js.map +1 -0
- package/dist/esm/internal/printChannel.d.ts +233 -0
- package/dist/esm/internal/printChannel.d.ts.map +1 -0
- package/dist/esm/internal/printChannel.js +376 -0
- package/dist/esm/internal/printChannel.js.map +1 -0
- package/dist/esm/internal/printsObservation.d.ts +26 -0
- package/dist/esm/internal/printsObservation.d.ts.map +1 -0
- package/dist/esm/internal/printsObservation.js +29 -0
- package/dist/esm/internal/printsObservation.js.map +1 -0
- package/dist/esm/internal/refusal.d.ts +40 -0
- package/dist/esm/internal/refusal.d.ts.map +1 -0
- package/dist/esm/internal/refusal.js +47 -0
- package/dist/esm/internal/refusal.js.map +1 -0
- package/dist/esm/internal/supervision.d.ts +174 -0
- package/dist/esm/internal/supervision.d.ts.map +1 -0
- package/dist/esm/internal/supervision.js +485 -0
- package/dist/esm/internal/supervision.js.map +1 -0
- package/dist/esm/internal/unfinishedWork.d.ts +99 -0
- package/dist/esm/internal/unfinishedWork.d.ts.map +1 -0
- package/dist/esm/internal/unfinishedWork.js +85 -0
- package/dist/esm/internal/unfinishedWork.js.map +1 -0
- package/dist/esm/internal/unobservedCall.d.ts +112 -0
- package/dist/esm/internal/unobservedCall.d.ts.map +1 -0
- package/dist/esm/internal/unobservedCall.js +501 -0
- package/dist/esm/internal/unobservedCall.js.map +1 -0
- package/dist/esm/internal/untrustedData.d.ts +14 -0
- package/dist/esm/internal/untrustedData.d.ts.map +1 -0
- package/dist/esm/internal/untrustedData.js +15 -0
- package/dist/esm/internal/untrustedData.js.map +1 -0
- package/docs/README.md +129 -0
- package/docs/api.md +1869 -0
- package/docs/concepts.md +238 -0
- package/docs/external-transcripts.md +245 -0
- package/docs/guides/bind-flows.md +167 -0
- package/docs/guides/drive-the-loop.md +265 -0
- package/docs/guides/run-cells.md +262 -0
- package/docs/guides/workerd.md +144 -0
- package/docs/installation.md +69 -0
- package/docs/quickstart.md +121 -0
- package/docs/reference.md +954 -0
- package/docs/troubleshooting.md +177 -0
- package/package.json +463 -3
- package/src/AgentEvent.ts +1772 -0
- package/src/CallLedger.ts +560 -0
- package/src/Cell.ts +926 -0
- package/src/CellCalls.ts +198 -0
- package/src/CellHistory.ts +128 -0
- package/src/CellTurn.ts +4450 -0
- package/src/CellValidation.ts +382 -0
- package/src/Compaction.ts +330 -0
- package/src/CompletionClaim.ts +1013 -0
- package/src/ContextWindow.ts +669 -0
- package/src/EngineLike.ts +614 -0
- package/src/ExternalTranscript.ts +1143 -0
- package/src/FailedCall.ts +163 -0
- package/src/FlowBinding.ts +603 -0
- package/src/HarnessError.ts +98 -0
- package/src/Judgement.ts +526 -0
- package/src/Monitor.ts +579 -0
- package/src/NarrowedCheck.ts +694 -0
- package/src/Notifications.ts +262 -0
- package/src/Plan.ts +113 -0
- package/src/QuickJSSandbox.ts +1557 -0
- package/src/Relevance.ts +352 -0
- package/src/Sandbox.ts +908 -0
- package/src/Steering.ts +405 -0
- package/src/StructuredOutput.ts +484 -0
- package/src/Sufficiency.ts +247 -0
- package/src/Supervisor.ts +798 -0
- package/src/Tokens.ts +108 -0
- package/src/Transcript.ts +513 -0
- package/src/TruncatedOutput.ts +297 -0
- package/src/UnmovedTree.ts +121 -0
- package/src/UnresolvedFailure.ts +240 -0
- package/src/VacuousVerification.ts +280 -0
- package/src/VariablesPanel.ts +165 -0
- package/src/index.ts +204 -0
- package/src/internal/bytes.ts +70 -0
- package/src/internal/cellPrompt.ts +337 -0
- package/src/internal/compactable.ts +76 -0
- package/src/internal/compactionMarks.ts +454 -0
- package/src/internal/demandText.ts +145 -0
- package/src/internal/elide.ts +130 -0
- package/src/internal/frame.ts +1178 -0
- package/src/internal/nonNegativeSafeInt.ts +24 -0
- package/src/internal/paidUsage.ts +90 -0
- package/src/internal/printChannel.ts +434 -0
- package/src/internal/printsObservation.ts +31 -0
- package/src/internal/refusal.ts +53 -0
- package/src/internal/supervision.ts +652 -0
- package/src/internal/unfinishedWork.ts +123 -0
- package/src/internal/unobservedCall.ts +536 -0
- package/src/internal/untrustedData.ts +19 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning one agent's final text into a value the declared output schema
|
|
3
|
+
* accepts, or into a typed failure.
|
|
4
|
+
*
|
|
5
|
+
* A model may answer with a bare JSON document, prose wrapped around a JSON
|
|
6
|
+
* document, a fenced block, or JSON of the wrong shape. Downstream nodes must
|
|
7
|
+
* never receive that ambiguity, so this module implements the recovery
|
|
8
|
+
* contract in `../docs/concepts.md#structured-output`:
|
|
9
|
+
*
|
|
10
|
+
* 1. parse the complete, BOM-stripped response and decode it;
|
|
11
|
+
* 2. otherwise scan once for balanced JSON containers, take the container
|
|
12
|
+
* whose matching close ends last, and decode that;
|
|
13
|
+
* 3. otherwise report a typed {@link StructuredOutputFailure} carrying bounded
|
|
14
|
+
* diagnostics, which is what a caller re-prompts with when it still holds a
|
|
15
|
+
* correction slot.
|
|
16
|
+
*
|
|
17
|
+
* Every candidate is decoded by the declared schema. Extraction never relaxes
|
|
18
|
+
* validation: it only decides which bytes are offered to it, and the schema may
|
|
19
|
+
* accept any JSON root rather than silently requiring an object.
|
|
20
|
+
*
|
|
21
|
+
* The prompt half is {@link instructions}. It renders the declared schema as a
|
|
22
|
+
* JSON Schema document placed in the run's system teaching, which is BAML's
|
|
23
|
+
* `ctx.output_format` injection reached through the seam the vault note
|
|
24
|
+
* specifies — the model is told the shape before it answers, and the answer is
|
|
25
|
+
* still validated locally. Provider acceptance is not a cast.
|
|
26
|
+
*
|
|
27
|
+
* Reference consulted: the `generateObject` function from Effect's
|
|
28
|
+
* `effect/unstable/ai/LanguageModel` module, which
|
|
29
|
+
* sends `responseFormat: { type: "json", schema }` and then decodes the result
|
|
30
|
+
* with the same schema, failing `AiError.InvalidOutputError` on mismatch. The
|
|
31
|
+
* decode-and-fail-typed half is copied. The provider `responseFormat` half is
|
|
32
|
+
* not reachable here: `@smthrs/model`'s `ModelRequest.GenerationParams` has no
|
|
33
|
+
* response-format field, and the cell loop's final answer is a `Cell.Complete`
|
|
34
|
+
* `output` string rather than a provider-decoded value, so the schema is
|
|
35
|
+
* carried in the prompt and enforced at this boundary.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.1.0
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import * as Digest from "@smthrs/core/Digest"
|
|
41
|
+
import * as Fault from "@smthrs/flow/Fault"
|
|
42
|
+
import * as Effect from "effect/Effect"
|
|
43
|
+
import * as Schema from "effect/Schema"
|
|
44
|
+
import * as SchemaIssue from "effect/SchemaIssue"
|
|
45
|
+
import * as elide from "./internal/elide.ts"
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Stable reasons a structured-output boundary failed.
|
|
49
|
+
*
|
|
50
|
+
* `invalid_json` means candidate text was not JSON. `schema_mismatch` means
|
|
51
|
+
* JSON parsed but the declared schema refused it. `no_candidate` means the
|
|
52
|
+
* answer contained no candidate text. `correction_exhausted` means the
|
|
53
|
+
* boundary had already spent its correction budget.
|
|
54
|
+
*
|
|
55
|
+
* @category models
|
|
56
|
+
* @since 1.0.0-rc.0
|
|
57
|
+
* @slop
|
|
58
|
+
*/
|
|
59
|
+
export const StructuredOutputFailureCode = Schema.Literals([
|
|
60
|
+
"invalid_json",
|
|
61
|
+
"schema_mismatch",
|
|
62
|
+
"no_candidate",
|
|
63
|
+
"correction_exhausted"
|
|
64
|
+
])
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Stable reasons a structured-output boundary failed.
|
|
68
|
+
*
|
|
69
|
+
* @category models
|
|
70
|
+
* @since 1.0.0-rc.0
|
|
71
|
+
* @slop
|
|
72
|
+
*/
|
|
73
|
+
export type StructuredOutputFailureCode = typeof StructuredOutputFailureCode.Type
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Stable reasons an individual structured-output issue was reported.
|
|
77
|
+
*
|
|
78
|
+
* `invalid_json` means candidate text was not JSON. `no_candidate` means the
|
|
79
|
+
* answer contained no candidate text. `invalid_type` means a decoded value had
|
|
80
|
+
* the wrong type. `invalid_value` means a value of the expected type was still
|
|
81
|
+
* invalid. `missing_key` means a required property was absent.
|
|
82
|
+
* `unexpected_key` means a prohibited extra property was present. `forbidden`
|
|
83
|
+
* means decoding attempted an operation the schema forbids. `one_of` means
|
|
84
|
+
* more than one exclusive union member matched. `constraint` means a schema
|
|
85
|
+
* check or empty-union fallback failed.
|
|
86
|
+
*
|
|
87
|
+
* @category models
|
|
88
|
+
* @since 1.0.0-rc.0
|
|
89
|
+
* @slop
|
|
90
|
+
*/
|
|
91
|
+
export const OutputIssueCode = Schema.Literals([
|
|
92
|
+
"invalid_json",
|
|
93
|
+
"no_candidate",
|
|
94
|
+
"invalid_type",
|
|
95
|
+
"invalid_value",
|
|
96
|
+
"missing_key",
|
|
97
|
+
"unexpected_key",
|
|
98
|
+
"forbidden",
|
|
99
|
+
"one_of",
|
|
100
|
+
"constraint"
|
|
101
|
+
])
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Stable reasons an individual structured-output issue was reported.
|
|
105
|
+
*
|
|
106
|
+
* @category models
|
|
107
|
+
* @since 1.0.0-rc.0
|
|
108
|
+
* @slop
|
|
109
|
+
*/
|
|
110
|
+
export type OutputIssueCode = typeof OutputIssueCode.Type
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* One bounded issue raised while decoding structured output.
|
|
114
|
+
*
|
|
115
|
+
* @category models
|
|
116
|
+
* @since 1.0.0-rc.0
|
|
117
|
+
* @slop
|
|
118
|
+
*/
|
|
119
|
+
export class OutputIssue extends Schema.Class<OutputIssue>("flows/harness/StructuredOutput/OutputIssue")({
|
|
120
|
+
/** The stable reason this issue was reported. */
|
|
121
|
+
code: OutputIssueCode,
|
|
122
|
+
/** The JSON path of the offending value, dot/bracket joined; empty for the root. */
|
|
123
|
+
path: Schema.String,
|
|
124
|
+
/** What the decoder wanted there. */
|
|
125
|
+
message: Schema.String
|
|
126
|
+
}) {
|
|
127
|
+
/** Renders the issue for existing prose-oriented consumers. */
|
|
128
|
+
override toString(): string {
|
|
129
|
+
return this.path === "" ? this.message : `${this.path}: ${this.message}`
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The terminal failure of one structured-output boundary.
|
|
135
|
+
*
|
|
136
|
+
* It carries what an operator needs to tell two identical-looking refusals
|
|
137
|
+
* apart: which schema was demanded, how many correction slots the attempt
|
|
138
|
+
* consumed out of its budget, the digest of the last candidate that was
|
|
139
|
+
* offered to the decoder, and the bounded issue list.
|
|
140
|
+
*
|
|
141
|
+
* @category errors
|
|
142
|
+
* @since 0.1.0
|
|
143
|
+
* @slop
|
|
144
|
+
*/
|
|
145
|
+
export class StructuredOutputFailure extends Schema.TaggedError<StructuredOutputFailure>()(
|
|
146
|
+
"/harness/StructuredOutputFailure",
|
|
147
|
+
{
|
|
148
|
+
/** The stable reason this boundary failed. */
|
|
149
|
+
code: StructuredOutputFailureCode,
|
|
150
|
+
/** The declared output schema's canonical digest. */
|
|
151
|
+
schema: Schema.String,
|
|
152
|
+
/** SHA-256 of the text the decoder was last offered. */
|
|
153
|
+
candidate: Schema.String,
|
|
154
|
+
/** Correction attempts already spent on this boundary. */
|
|
155
|
+
corrections: Schema.Number,
|
|
156
|
+
/** The correction budget the boundary was declared with. */
|
|
157
|
+
limit: Schema.Number,
|
|
158
|
+
/** At most {@link maxIssues} structured validation issues. */
|
|
159
|
+
issues: Schema.Array(OutputIssue),
|
|
160
|
+
message: Schema.String
|
|
161
|
+
}
|
|
162
|
+
) {}
|
|
163
|
+
// The model's answer did not fit the declared shape: another model may answer it.
|
|
164
|
+
Fault.register("/harness/StructuredOutputFailure", "dependency")
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The most validation issues a failure or a correction prompt carries.
|
|
168
|
+
*
|
|
169
|
+
* Bounded for the same reason smithers bounds its own validation summary: a
|
|
170
|
+
* wide struct that mismatched everywhere would otherwise spend the correction
|
|
171
|
+
* prompt's whole budget restating the schema back to the model.
|
|
172
|
+
*
|
|
173
|
+
* @category constants
|
|
174
|
+
* @since 0.1.0
|
|
175
|
+
* @slop
|
|
176
|
+
*/
|
|
177
|
+
export const maxIssues = 5
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The JSON Schema document for a declared output schema.
|
|
181
|
+
*
|
|
182
|
+
* @category conversions
|
|
183
|
+
* @since 0.1.0
|
|
184
|
+
* @slop
|
|
185
|
+
*/
|
|
186
|
+
export const jsonSchema = (schema: Schema.Top): unknown => {
|
|
187
|
+
const document = Schema.toJsonSchemaDocument(schema, { onExcessProperty: "error" })
|
|
188
|
+
return Object.keys(document.definitions).length > 0
|
|
189
|
+
? { ...document.schema, $defs: document.definitions }
|
|
190
|
+
: document.schema
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The canonical digest of a declared output schema.
|
|
195
|
+
*
|
|
196
|
+
* Two declarations that render the same JSON Schema name the same boundary, so
|
|
197
|
+
* this is what a step key folds in rather than the schema value itself.
|
|
198
|
+
*
|
|
199
|
+
* @category identity
|
|
200
|
+
* @since 0.1.0
|
|
201
|
+
* @slop
|
|
202
|
+
*/
|
|
203
|
+
export const digest = (schema: Schema.Top): string => Digest.digest(Digest.canonical(jsonSchema(schema)))
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The system teaching that tells a run what its final `output` must be.
|
|
207
|
+
*
|
|
208
|
+
* Written against the cell contract: a cell finishes by calling
|
|
209
|
+
* `ctx.done(output)`, and the sandbox rejects a returned transition, so the
|
|
210
|
+
* instruction is about the argument of that call and not about the assistant
|
|
211
|
+
* message around it. The run passes the value itself: a structured value
|
|
212
|
+
* reaches {@link decode} as canonical JSON, and a string as its own text.
|
|
213
|
+
*
|
|
214
|
+
* @category prompts
|
|
215
|
+
* @since 0.1.0
|
|
216
|
+
* @slop
|
|
217
|
+
*/
|
|
218
|
+
export const instructions = (schema: Schema.Top): string =>
|
|
219
|
+
`## Required output shape
|
|
220
|
+
|
|
221
|
+
Finish by calling \`ctx.done(output)\` with the value itself: a JavaScript
|
|
222
|
+
value that validates against this JSON Schema, such as
|
|
223
|
+
\`ctx.done({ ...fields })\`. Do not stringify it, and add no prose around it.
|
|
224
|
+
|
|
225
|
+
\`\`\`json
|
|
226
|
+
${JSON.stringify(jsonSchema(schema), null, 2)}
|
|
227
|
+
\`\`\``
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The digest of one failure's rendered validation issues.
|
|
231
|
+
*
|
|
232
|
+
* Two rejections that raised the same issues share this digest, which is what a
|
|
233
|
+
* record carries instead of the issues themselves: a journal that repeated the
|
|
234
|
+
* validator's prose for every correction would grow with the model's verbosity,
|
|
235
|
+
* and what an operator actually asks is whether the second answer was wrong the
|
|
236
|
+
* same way as the first.
|
|
237
|
+
*
|
|
238
|
+
* @category identity
|
|
239
|
+
* @since 0.1.0
|
|
240
|
+
*/
|
|
241
|
+
export const issuesDigest = (failure: StructuredOutputFailure): string =>
|
|
242
|
+
Digest.digest(
|
|
243
|
+
Digest.canonical(failure.issues.map((issue) => ({ path: issue.path, message: issue.message })))
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The correction teaching appended when a candidate failed to decode.
|
|
248
|
+
*
|
|
249
|
+
* It restates the schema and the bounded diagnostics and nothing else: a
|
|
250
|
+
* correction does not reinterpret the task, so the original prompt is repeated
|
|
251
|
+
* verbatim by the caller and only this section is new.
|
|
252
|
+
*
|
|
253
|
+
* @category prompts
|
|
254
|
+
* @since 0.1.0
|
|
255
|
+
* @slop
|
|
256
|
+
*/
|
|
257
|
+
export const correction = (failure: StructuredOutputFailure): string =>
|
|
258
|
+
`## Your previous answer did not validate
|
|
259
|
+
|
|
260
|
+
The output you passed to \`ctx.done\` could not be decoded against the required
|
|
261
|
+
schema. Call \`ctx.done(output)\` again with the same information as a value
|
|
262
|
+
that validates.
|
|
263
|
+
|
|
264
|
+
Validation issues:
|
|
265
|
+
${failure.issues.map((issue) => `- ${issue}`).join("\n")}`
|
|
266
|
+
|
|
267
|
+
const stripBom = (text: string): string => text.charCodeAt(0) === 0xfeff ? text.slice(1) : text
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The balanced JSON container whose matching close ends last.
|
|
271
|
+
*
|
|
272
|
+
* Scans once, left to right, tracking object and array delimiters, quoted
|
|
273
|
+
* strings, and escapes. A mismatched close abandons the open container rather
|
|
274
|
+
* than pairing it with the wrong opener, so a truncated prefix cannot be
|
|
275
|
+
* reported as a complete document. `undefined` means the text holds no
|
|
276
|
+
* balanced container at all.
|
|
277
|
+
*
|
|
278
|
+
* This is the array-capable form of smithers' `extractLastBalancedJson`, which
|
|
279
|
+
* is object-only.
|
|
280
|
+
*
|
|
281
|
+
* @category extraction
|
|
282
|
+
* @since 0.1.0
|
|
283
|
+
* @slop
|
|
284
|
+
*/
|
|
285
|
+
export const lastBalanced = (text: string): string | undefined => {
|
|
286
|
+
const stack: Array<string> = []
|
|
287
|
+
let start = -1
|
|
288
|
+
let found: string | undefined = undefined
|
|
289
|
+
let quoted = false
|
|
290
|
+
let escaped = false
|
|
291
|
+
for (let index = 0; index < text.length; index++) {
|
|
292
|
+
const char = text[index]!
|
|
293
|
+
if (quoted) {
|
|
294
|
+
if (escaped) escaped = false
|
|
295
|
+
else if (char === "\\") escaped = true
|
|
296
|
+
else if (char === "\"") quoted = false
|
|
297
|
+
continue
|
|
298
|
+
}
|
|
299
|
+
if (char === "\"") {
|
|
300
|
+
if (stack.length > 0) quoted = true
|
|
301
|
+
continue
|
|
302
|
+
}
|
|
303
|
+
if (char === "{" || char === "[") {
|
|
304
|
+
if (stack.length === 0) start = index
|
|
305
|
+
stack.push(char)
|
|
306
|
+
continue
|
|
307
|
+
}
|
|
308
|
+
if (char === "}" || char === "]") {
|
|
309
|
+
const opener = stack.pop()
|
|
310
|
+
if (opener === undefined) continue
|
|
311
|
+
if ((char === "}") !== (opener === "{")) {
|
|
312
|
+
// Mismatched close: abandon the whole open container rather than
|
|
313
|
+
// reporting a pairing the text does not contain.
|
|
314
|
+
stack.length = 0
|
|
315
|
+
start = -1
|
|
316
|
+
continue
|
|
317
|
+
}
|
|
318
|
+
if (stack.length === 0 && start >= 0) found = text.slice(start, index + 1)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return found
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* The candidates offered to the decoder, in the declared recovery order.
|
|
326
|
+
*
|
|
327
|
+
* @category extraction
|
|
328
|
+
* @since 0.1.0
|
|
329
|
+
* @slop
|
|
330
|
+
*/
|
|
331
|
+
export const candidates = (text: string): ReadonlyArray<string> => {
|
|
332
|
+
const stripped = stripBom(text).trim()
|
|
333
|
+
const balanced = lastBalanced(stripped)
|
|
334
|
+
return balanced === undefined || balanced === stripped ? [stripped] : [stripped, balanced]
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const issueMessage = (message: string): string => elide.head(message, 240, "reissue the answer to see the whole issue")
|
|
338
|
+
|
|
339
|
+
const issuePath = (path: ReadonlyArray<PropertyKey>): string =>
|
|
340
|
+
path.map((segment, index) =>
|
|
341
|
+
typeof segment === "number" ? `[${segment}]` : `${index === 0 ? "" : "."}${String(segment)}`
|
|
342
|
+
).join("")
|
|
343
|
+
|
|
344
|
+
type FormattedIssue = {
|
|
345
|
+
readonly message: string
|
|
346
|
+
readonly path: ReadonlyArray<PropertyKey>
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const issueCodeSeparator = "\u0000"
|
|
350
|
+
|
|
351
|
+
const leafCodes: Record<SchemaIssue.Leaf["_tag"], OutputIssueCode> = {
|
|
352
|
+
InvalidType: "invalid_type",
|
|
353
|
+
InvalidValue: "invalid_value",
|
|
354
|
+
MissingKey: "missing_key",
|
|
355
|
+
UnexpectedKey: "unexpected_key",
|
|
356
|
+
Forbidden: "forbidden",
|
|
357
|
+
OneOf: "one_of"
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const formatSchemaIssues = SchemaIssue.makeFormatterStandardSchemaV1({
|
|
361
|
+
leafHook: (issue) => `${issue._tag}${issueCodeSeparator}${SchemaIssue.defaultLeafHook(issue)}`
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
const schemaIssuesOf = (error: Schema.SchemaError): ReadonlyArray<OutputIssue> =>
|
|
365
|
+
(formatSchemaIssues(error.issue).issues as ReadonlyArray<FormattedIssue>).slice(0, maxIssues).map((issue) => {
|
|
366
|
+
const separator = issue.message.indexOf(issueCodeSeparator)
|
|
367
|
+
const tagged = separator >= 0
|
|
368
|
+
return new OutputIssue({
|
|
369
|
+
code: tagged ? leafCodes[issue.message.slice(0, separator) as SchemaIssue.Leaf["_tag"]] : "constraint",
|
|
370
|
+
path: issuePath(issue.path),
|
|
371
|
+
message: issueMessage(tagged ? issue.message.slice(separator + issueCodeSeparator.length) : issue.message)
|
|
372
|
+
})
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
const textIssuesOf = (code: OutputIssueCode, message: string): ReadonlyArray<OutputIssue> =>
|
|
376
|
+
message.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).slice(0, maxIssues).map((line) =>
|
|
377
|
+
new OutputIssue({ code, path: "", message: issueMessage(line) })
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
const quoted = (text: string): boolean => {
|
|
381
|
+
try {
|
|
382
|
+
return typeof JSON.parse(text) === "string"
|
|
383
|
+
} catch {
|
|
384
|
+
return false
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Decodes one agent answer with the declared output schema.
|
|
390
|
+
*
|
|
391
|
+
* Decodes an original completion value first when supplied. Only a string
|
|
392
|
+
* refused for its type proceeds to legacy text extraction; refinements and
|
|
393
|
+
* nonstring failures retain the original value's diagnostics.
|
|
394
|
+
* Tries every {@link candidates} entry in order and returns the first the
|
|
395
|
+
* schema accepts, then the answer itself, untrimmed, as a string unless it is
|
|
396
|
+
* a JSON string literal, which is how a `ctx.done("text")` answer reaches a
|
|
397
|
+
* string schema. When none does, the failure reports the issues raised by the
|
|
398
|
+
* LAST candidate, which is the narrowest text the extractor could isolate and
|
|
399
|
+
* therefore the one a correction prompt should be about.
|
|
400
|
+
*
|
|
401
|
+
* @category decoding
|
|
402
|
+
* @since 0.1.0
|
|
403
|
+
* @slop
|
|
404
|
+
*/
|
|
405
|
+
export const decode = <S extends Schema.Top>(
|
|
406
|
+
schema: S,
|
|
407
|
+
text: string,
|
|
408
|
+
attempt: { readonly corrections: number; readonly limit: number },
|
|
409
|
+
value?: Schema.Json | undefined
|
|
410
|
+
): Effect.Effect<S["Type"], StructuredOutputFailure, S["DecodingServices"]> =>
|
|
411
|
+
Effect.gen(function*() {
|
|
412
|
+
const offered = candidates(text)
|
|
413
|
+
const decoder = Schema.decodeUnknownEffect(schema)
|
|
414
|
+
let code: StructuredOutputFailureCode = "no_candidate"
|
|
415
|
+
let issues: ReadonlyArray<OutputIssue> = [
|
|
416
|
+
new OutputIssue({ code: "no_candidate", path: "", message: "the answer held no JSON document" })
|
|
417
|
+
]
|
|
418
|
+
if (value !== undefined) {
|
|
419
|
+
const result = yield* Effect.result(decoder(value))
|
|
420
|
+
if (result._tag === "Success") return result.success
|
|
421
|
+
const rawIssues = schemaIssuesOf(result.failure)
|
|
422
|
+
// Extraction is only for text offered to a schema expecting another type.
|
|
423
|
+
// Preserve string refinements and nonstring type failures on the value.
|
|
424
|
+
if (typeof value !== "string" || !rawIssues.every((issue) => issue.code === "invalid_type")) {
|
|
425
|
+
return yield* new StructuredOutputFailure({
|
|
426
|
+
code: attempt.corrections >= attempt.limit ? "correction_exhausted" : "schema_mismatch",
|
|
427
|
+
schema: digest(schema),
|
|
428
|
+
candidate: Digest.digest(JSON.stringify(value)),
|
|
429
|
+
corrections: attempt.corrections,
|
|
430
|
+
limit: attempt.limit,
|
|
431
|
+
issues: rawIssues,
|
|
432
|
+
message:
|
|
433
|
+
`The agent's answer did not validate against its declared output schema after ${attempt.corrections} of ${attempt.limit} corrections`
|
|
434
|
+
})
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
for (const candidate of offered) {
|
|
438
|
+
if (candidate.length === 0) continue
|
|
439
|
+
let parsed: unknown
|
|
440
|
+
try {
|
|
441
|
+
parsed = JSON.parse(candidate)
|
|
442
|
+
} catch (error) {
|
|
443
|
+
code = "invalid_json"
|
|
444
|
+
// The ECMAScript JSON parser throws a SyntaxError with a message.
|
|
445
|
+
issues = textIssuesOf("invalid_json", (error as SyntaxError).message)
|
|
446
|
+
continue
|
|
447
|
+
}
|
|
448
|
+
const result = yield* Effect.result(decoder(parsed))
|
|
449
|
+
if (result._tag === "Success") return result.success
|
|
450
|
+
code = "schema_mismatch"
|
|
451
|
+
issues = schemaIssuesOf(result.failure)
|
|
452
|
+
}
|
|
453
|
+
// `ctx.done("text")` reaches the boundary as the text itself, not as a
|
|
454
|
+
// JSON string, so a schema that accepts the raw answer takes it as it is.
|
|
455
|
+
// An answer that is a whole JSON string literal already said which string
|
|
456
|
+
// it meant, and its quotes are not part of it.
|
|
457
|
+
// Untrimmed, so an empty or whitespace-bearing string arrives as written.
|
|
458
|
+
const raw = stripBom(text)
|
|
459
|
+
if (!quoted(offered[0]!)) {
|
|
460
|
+
const result = yield* Effect.result(decoder(raw))
|
|
461
|
+
if (result._tag === "Success") return result.success
|
|
462
|
+
// A string the schema read and refused on its merits (too short, not
|
|
463
|
+
// one of the literals) is the issue to correct, not the JSON parse. A
|
|
464
|
+
// schema that wanted no string at all keeps the JSON diagnosis.
|
|
465
|
+
const rawIssues = schemaIssuesOf(result.failure)
|
|
466
|
+
if (code === "invalid_json" && rawIssues[0]?.code !== "invalid_type") {
|
|
467
|
+
code = "schema_mismatch"
|
|
468
|
+
issues = rawIssues
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return yield* new StructuredOutputFailure({
|
|
472
|
+
// Once the budget is spent, exhaustion is the actionable classification;
|
|
473
|
+
// the issue records retain whether the last candidate was invalid JSON or
|
|
474
|
+
// failed schema decoding.
|
|
475
|
+
code: attempt.corrections >= attempt.limit ? "correction_exhausted" : code,
|
|
476
|
+
schema: digest(schema),
|
|
477
|
+
candidate: Digest.digest(offered[offered.length - 1]!),
|
|
478
|
+
corrections: attempt.corrections,
|
|
479
|
+
limit: attempt.limit,
|
|
480
|
+
issues,
|
|
481
|
+
message:
|
|
482
|
+
`The agent's answer did not validate against its declared output schema after ${attempt.corrections} of ${attempt.limit} corrections`
|
|
483
|
+
})
|
|
484
|
+
})
|