@sema-agent/client-core 0.100.0 → 0.102.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 +452 -0
- package/README.md +172 -120
- package/dist/adapt/arms.js +51 -16
- package/dist/adapt/textStream.js +7 -4
- package/dist/adapt/toolCards.d.ts +2 -1
- package/dist/adapt/toolCards.js +28 -13
- package/dist/adapt.d.ts +1 -1
- package/dist/adapt.js +8 -2
- package/dist/adapter/activeRunSelfHeal.d.ts +24 -2
- package/dist/adapter/activeRunSelfHeal.js +108 -6
- package/dist/adapter/downstream/eventToSdkMessage.js +38 -79
- package/dist/adapter/downstream/terminalToSdkResult.d.ts +60 -1
- package/dist/adapter/downstream/terminalToSdkResult.js +209 -39
- package/dist/adapter/downstream/wiringManifestView.d.ts +1 -0
- package/dist/adapter/downstream/wiringManifestView.js +138 -0
- package/dist/adapter/runStream.d.ts +4 -4
- package/dist/adapter/runStream.js +158 -43
- package/dist/agentsWireCaps.d.ts +2 -7
- package/dist/agentsWireCaps.js +1 -2
- package/dist/approvalDecidedByCapability.js +2 -2
- package/dist/approvalFrameFamilies.d.ts +33 -0
- package/dist/approvalFrameFamilies.js +120 -0
- package/dist/approvalsStreamLiveCapability.js +2 -2
- package/dist/attachmentsWireCaps.js +41 -13
- package/dist/callerCwdCapability.js +2 -2
- package/dist/centerWiringCapability.js +2 -2
- package/dist/clockReading.d.ts +2 -0
- package/dist/clockReading.js +4 -0
- package/dist/cloudConfigWireCaps.d.ts +19 -5
- package/dist/cloudConfigWireCaps.js +193 -56
- package/dist/compensations.js +1 -1
- package/dist/coreValuePorts.d.ts +12 -2
- package/dist/coreValuePorts.js +9 -0
- package/dist/decideFailureNote.js +5 -3
- package/dist/decideReceipt.js +2 -2
- package/dist/deviceExecutorManagementCapability.js +2 -2
- package/dist/deviceFlowPolling.js +1 -1
- package/dist/disableSkillsWire.d.ts +1 -1
- package/dist/disableSkillsWire.js +4 -3
- package/dist/displayUntrusted.d.ts +9 -4
- package/dist/displayUntrusted.js +834 -104
- package/dist/engineCapReader.js +1 -1
- package/dist/engineConfigDrift.js +1 -1
- package/dist/engineErrorCodes.d.ts +14 -5
- package/dist/engineErrorCodes.js +27 -6
- package/dist/engineGenerationConvergence.d.ts +39 -0
- package/dist/engineGenerationConvergence.js +95 -0
- package/dist/engineGenerationPort.d.ts +61 -0
- package/dist/engineGenerationPort.js +144 -0
- package/dist/engineHealthFacts.d.ts +23 -0
- package/dist/engineHealthFacts.js +92 -0
- package/dist/engineIdentity.d.ts +4 -0
- package/dist/engineIdentity.js +11 -0
- package/dist/engineNoticeCodes.d.ts +2 -5
- package/dist/engineRowRef.js +4 -0
- package/dist/engineSessionMessages.js +2 -2
- package/dist/engineToolDirectory.js +2 -2
- package/dist/engineWireFor.d.ts +99 -0
- package/dist/engineWireFor.js +248 -6
- package/dist/engineWireTarget.d.ts +1 -0
- package/dist/engineWireTarget.js +8 -0
- package/dist/env/uiLanguage.js +1 -1
- package/dist/errorSupplementRoles.d.ts +3 -0
- package/dist/errorSupplementRoles.js +37 -0
- package/dist/executionLaneCapability.js +2 -2
- package/dist/fileHistoryCaptureCapability.js +3 -3
- package/dist/finalVerifyWire.d.ts +6 -3
- package/dist/finalVerifyWire.js +6 -23
- package/dist/flagInput.d.ts +4 -0
- package/dist/flagInput.js +24 -0
- package/dist/fleet/fleetLedger.js +5 -2
- package/dist/fleet/fleetProjection.d.ts +1 -0
- package/dist/fleet/fleetProjection.js +16 -3
- package/dist/gateVocabulary.js +3 -0
- package/dist/generated/engineFactTables.d.ts +7 -3
- package/dist/generated/engineFactTables.js +52 -0
- package/dist/generated/engineNoticeTables.js +12 -0
- package/dist/generated/settingsSchemaActiveTiers.d.ts +1 -0
- package/dist/generated/settingsSchemaActiveTiers.js +14 -0
- package/dist/generated/settingsSchemaCallerTextEcho.d.ts +1 -0
- package/dist/generated/settingsSchemaCallerTextEcho.js +8 -0
- package/dist/generated/settingsSchemaControlAndBidi.d.ts +1 -0
- package/dist/generated/settingsSchemaControlAndBidi.js +8 -0
- package/dist/generated/settingsSchemaDefaultModel.d.ts +11 -0
- package/dist/generated/settingsSchemaDefaultModel.js +25 -0
- package/dist/generated/settingsSchemaFns.d.ts +54 -0
- package/dist/generated/settingsSchemaFns.js +26 -1
- package/dist/generated/settingsSchemaMcpRequestEntry.d.ts +1 -1
- package/dist/generated/settingsSchemaMcpRequestEntry.js +1 -7
- package/dist/generated/settingsSchemaSafetyMergeSpec.d.ts +1 -0
- package/dist/generated/settingsSchemaSafetyMergeSpec.js +95 -0
- package/dist/generated/settingsSchemaSettingsSources.d.ts +1 -0
- package/dist/generated/settingsSchemaSettingsSources.js +58 -0
- package/dist/generated/settingsSchemaTables.d.ts +2 -0
- package/dist/generated/settingsSchemaTables.js +13 -0
- package/dist/generated/settingsSchemaUrlPattern.d.ts +1 -0
- package/dist/generated/settingsSchemaUrlPattern.js +183 -0
- package/dist/headlessPermissionModeWire.d.ts +18 -2
- package/dist/headlessPermissionModeWire.js +30 -19
- package/dist/hitl/allowRuleShadow.js +7 -5
- package/dist/hitl/approvalCardReading.d.ts +3 -0
- package/dist/hitl/approvalCardReading.js +17 -0
- package/dist/hitl/approvalCompleteParked.js +1 -1
- package/dist/hitl/approvalDelivery.d.ts +87 -0
- package/dist/hitl/approvalDelivery.js +193 -0
- package/dist/hitl/approvalResolution.d.ts +11 -0
- package/dist/hitl/approvalResolution.js +50 -11
- package/dist/hitl/askClassPair.d.ts +6 -0
- package/dist/hitl/askClassPair.js +30 -3
- package/dist/hitl/askParkAutoReopenBlock.d.ts +30 -0
- package/dist/hitl/askParkAutoReopenBlock.js +117 -0
- package/dist/hitl/askParkRowRouting.js +4 -1
- package/dist/hitl/attributionLadder.d.ts +42 -3
- package/dist/hitl/attributionLadder.js +79 -8
- package/dist/hitl/automaticAnswerVerdict.d.ts +6 -1
- package/dist/hitl/automaticAnswerVerdict.js +46 -11
- package/dist/hitl/crashConverged.js +2 -2
- package/dist/hitl/decisionConflict.d.ts +6 -2
- package/dist/hitl/decisionConflict.js +24 -9
- package/dist/hitl/decisionRefusal.d.ts +20 -10
- package/dist/hitl/decisionRefusal.js +99 -54
- package/dist/hitl/decisionSend.d.ts +3 -0
- package/dist/hitl/decisionSend.js +87 -103
- package/dist/hitl/frameRouter.d.ts +1 -0
- package/dist/hitl/frameRouter.js +9 -2
- package/dist/hitl/hitlBridge.d.ts +18 -6
- package/dist/hitl/hitlBridge.js +41 -37
- package/dist/hitl/livePendingAsk.js +4 -3
- package/dist/hitl/noAllowCause.js +1 -1
- package/dist/hitl/parkResolver.js +3 -2
- package/dist/hitl/persistedRulesWire.js +1 -0
- package/dist/hitl/planReviewWire.d.ts +4 -0
- package/dist/hitl/planReviewWire.js +59 -30
- package/dist/hitl/resumeRunningCard.d.ts +3 -2
- package/dist/hitl/resumeRunningCard.js +17 -11
- package/dist/hitl/sessionPolicyDeliverable.d.ts +5 -2
- package/dist/hitl/sessionPolicyDeliverable.js +62 -29
- package/dist/hitl/sessionPolicyWire.d.ts +13 -3
- package/dist/hitl/sessionPolicyWire.js +81 -16
- package/dist/hitl/standingRows.js +1 -1
- package/dist/hitl/toolApprovalWire.d.ts +9 -10
- package/dist/hitl/toolApprovalWire.js +72 -54
- package/dist/hookMatcherVerdict.d.ts +2 -0
- package/dist/hookMatcherVerdict.js +12 -0
- package/dist/hooksCompactTransition.d.ts +19 -0
- package/dist/hooksCompactTransition.js +41 -0
- package/dist/hooksWireCaps.d.ts +1 -1
- package/dist/hooksWireCaps.js +202 -203
- package/dist/host.d.ts +1 -14
- package/dist/host.js +0 -8
- package/dist/hostCallbackGuard.d.ts +1 -0
- package/dist/hostCallbackGuard.js +1 -1
- package/dist/hostSettingsSource.d.ts +172 -0
- package/dist/hostSettingsSource.js +675 -0
- package/dist/hostTurnSettings.d.ts +73 -17
- package/dist/hostTurnSettings.js +594 -97
- package/dist/httpHookPolicy.d.ts +37 -0
- package/dist/httpHookPolicy.js +176 -0
- package/dist/humanTurn.d.ts +2 -1
- package/dist/humanTurn.js +37 -7
- package/dist/humanTurnRead.js +4 -3
- package/dist/humanTurnSentences.d.ts +10 -0
- package/dist/humanTurnSentences.js +74 -0
- package/dist/i18n/messages.en.d.ts +222 -2
- package/dist/i18n/messages.en.js +225 -5
- package/dist/i18n/messages.zh.js +237 -5
- package/dist/i18n/translate.js +3 -3
- package/dist/index.d.ts +77 -15
- package/dist/index.js +50 -13
- package/dist/inheritEnvCapability.d.ts +3 -1
- package/dist/inheritEnvCapability.js +31 -17
- package/dist/inheritEnvWire.d.ts +2 -1
- package/dist/inheritEnvWire.js +11 -5
- package/dist/interactiveHalt.d.ts +3 -1
- package/dist/interactiveHalt.js +2 -0
- package/dist/interactiveInterrupt.d.ts +2 -0
- package/dist/interactiveInterrupt.js +15 -0
- package/dist/interactiveToolsWire.d.ts +4 -2
- package/dist/interactiveToolsWire.js +5 -5
- package/dist/jsonFaithful.d.ts +20 -0
- package/dist/jsonFaithful.js +152 -0
- package/dist/limitsWire.d.ts +7 -2
- package/dist/limitsWire.js +19 -13
- package/dist/liveInitToolFace.d.ts +6 -1
- package/dist/liveInitToolFace.js +5 -3
- package/dist/liveModelCatalog.d.ts +22 -0
- package/dist/liveModelCatalog.js +132 -18
- package/dist/mcpPanel.js +1 -1
- package/dist/mcpProbeCapability.js +2 -2
- package/dist/mcpStatusSupersetKeys.d.ts +24 -0
- package/dist/mcpStatusSupersetKeys.js +45 -0
- package/dist/mcpToolToggles.js +2 -1
- package/dist/mcpWireCaps.d.ts +39 -1
- package/dist/mcpWireCaps.js +254 -50
- package/dist/memoryComplianceCapability.js +2 -2
- package/dist/memoryOriginCapability.js +2 -2
- package/dist/model/catalogDefault.d.ts +24 -0
- package/dist/model/catalogDefault.js +4 -0
- package/dist/model/liveCatalogShape.js +5 -4
- package/dist/model/modelsPolicy.js +4 -3
- package/dist/model/onboardJudgement.d.ts +1 -0
- package/dist/model/onboardJudgement.js +1 -1
- package/dist/model/subagentModelWord.js +2 -2
- package/dist/modelCapabilityProbe.js +6 -6
- package/dist/modelIdentityResolvability.d.ts +10 -1
- package/dist/modelIdentityResolvability.js +62 -39
- package/dist/modsFace.d.ts +8 -0
- package/dist/modsFace.js +59 -0
- package/dist/modsKernelIdentity.d.ts +10 -0
- package/dist/modsKernelIdentity.js +103 -0
- package/dist/modsKernelTransit.d.ts +8 -0
- package/dist/modsKernelTransit.js +6 -0
- package/dist/notifications.d.ts +30 -12
- package/dist/notifications.js +241 -53
- package/dist/outputStyleSeatCapability.js +2 -2
- package/dist/ownKey.d.ts +12 -0
- package/dist/ownKey.js +179 -3
- package/dist/panelReduce.js +1 -1
- package/dist/peerFrames.d.ts +1 -1
- package/dist/peerFrames.js +6 -2
- package/dist/peerLaneCapability.js +2 -2
- package/dist/permissionModesCapability.js +4 -4
- package/dist/permissionRuleIssue.js +2 -0
- package/dist/permissionRulesWriteCapability.js +2 -2
- package/dist/permissionsAllowGrantCapability.js +2 -2
- package/dist/permissionsDeclaration.d.ts +43 -4
- package/dist/permissionsDeclaration.js +102 -35
- package/dist/pluginHooksWire.d.ts +20 -4
- package/dist/pluginHooksWire.js +92 -53
- package/dist/prepareRefusal.d.ts +3 -2
- package/dist/prepareRefusal.js +27 -9
- package/dist/printInitToolFace.js +2 -2
- package/dist/printModelStatus.js +1 -1
- package/dist/printToolResultFrame.js +1 -1
- package/dist/projectMemory.d.ts +32 -0
- package/dist/projectMemory.js +70 -0
- package/dist/promptBlockedCopy.d.ts +2 -1
- package/dist/promptBlockedCopy.js +2 -1
- package/dist/promptDelivery.d.ts +23 -3
- package/dist/promptDelivery.js +169 -30
- package/dist/providerRejection.d.ts +19 -1
- package/dist/providerRejection.js +75 -4
- package/dist/queuedDelivery.d.ts +48 -0
- package/dist/queuedDelivery.js +233 -0
- package/dist/reattachWindow.d.ts +94 -0
- package/dist/reattachWindow.js +127 -0
- package/dist/request/printNotification.d.ts +1 -1
- package/dist/request/printNotification.js +6 -2
- package/dist/request/submissionIdentity.d.ts +37 -0
- package/dist/request/submissionIdentity.js +65 -0
- package/dist/request/taskRequest.d.ts +33 -4
- package/dist/request/taskRequest.js +341 -156
- package/dist/resultFrameKeys.d.ts +1 -0
- package/dist/resultFrameKeys.js +4 -1
- package/dist/retryStatus.d.ts +8 -0
- package/dist/retryStatus.js +57 -9
- package/dist/rewindArchiveCapability.js +2 -2
- package/dist/rewindEngineAction.d.ts +2 -0
- package/dist/rewindEngineAction.js +23 -1
- package/dist/rowKind.d.ts +36 -0
- package/dist/rowKind.js +97 -0
- package/dist/ruleCompileVerdict.d.ts +18 -0
- package/dist/ruleCompileVerdict.js +67 -2
- package/dist/ruleReadings.d.ts +58 -0
- package/dist/ruleReadings.js +132 -0
- package/dist/ruleRefusalSentence.d.ts +4 -0
- package/dist/ruleRefusalSentence.js +9 -3
- package/dist/runCancelContext.d.ts +0 -1
- package/dist/runCancelContext.js +1 -2
- package/dist/runTerminal.d.ts +5 -0
- package/dist/runTerminal.js +52 -17
- package/dist/sandboxWire.d.ts +1 -1
- package/dist/sandboxWire.js +4 -6
- package/dist/scenarioRefusal.js +1 -1
- package/dist/scenarioSkills.d.ts +20 -0
- package/dist/scenarioSkills.js +72 -0
- package/dist/scenarioWire.d.ts +5 -2
- package/dist/scenarioWire.js +9 -9
- package/dist/sealedKeyCapability.js +2 -2
- package/dist/seam.d.ts +2 -0
- package/dist/seam.js +3 -3
- package/dist/seatContract.d.ts +68 -7
- package/dist/seatContract.js +84 -25
- package/dist/selfOrchestrationDenial.js +1 -1
- package/dist/sessionBackground.d.ts +165 -0
- package/dist/sessionBackground.js +781 -0
- package/dist/sessionBackgroundHandoff.d.ts +54 -0
- package/dist/sessionBackgroundHandoff.js +321 -0
- package/dist/sessionMap.js +4 -1
- package/dist/sessionPolicyCapability.js +2 -2
- package/dist/sessionRulesChildrenReadLive.d.ts +6 -0
- package/dist/sessionRulesChildrenReadLive.js +5 -0
- package/dist/sessionRulesNamespaceFormsCapability.d.ts +12 -0
- package/dist/sessionRulesNamespaceFormsCapability.js +29 -0
- package/dist/sessionSyncFileHistoryCapability.js +2 -2
- package/dist/settingsCredentialKeyPaths.js +55 -15
- package/dist/settingsHooksSalvage.d.ts +1 -0
- package/dist/settingsHooksSalvage.js +7 -1
- package/dist/settingsLayerAdmission.d.ts +4 -0
- package/dist/settingsLayerAdmission.js +16 -0
- package/dist/skillToolListsCapability.js +6 -5
- package/dist/skillsWireCaps.d.ts +14 -0
- package/dist/skillsWireCaps.js +47 -16
- package/dist/slashCommandGate.d.ts +24 -0
- package/dist/slashCommandGate.js +74 -0
- package/dist/slashCommandTable.d.ts +14 -0
- package/dist/slashCommandTable.js +99 -0
- package/dist/sqlEngineCapability.js +2 -2
- package/dist/steerPriorityCapability.js +2 -2
- package/dist/storePostureCapability.js +2 -2
- package/dist/subagent/agentStateDetail.js +1 -1
- package/dist/subagent/engineDelegatedPrompt.d.ts +9 -0
- package/dist/subagent/engineDelegatedPrompt.js +38 -7
- package/dist/subagent/engineRowStopGate.js +2 -2
- package/dist/subagent/engineSubagentResume.js +3 -3
- package/dist/subagent/engineTaskHandleWire.d.ts +1 -0
- package/dist/subagent/engineTaskHandleWire.js +10 -0
- package/dist/submitFailure.d.ts +8 -0
- package/dist/submitFailure.js +17 -0
- package/dist/supportFloor.d.ts +1 -0
- package/dist/supportFloor.js +7 -0
- package/dist/terminationIntent.d.ts +55 -0
- package/dist/terminationIntent.js +352 -0
- package/dist/thinkingLatch.d.ts +69 -0
- package/dist/thinkingLatch.js +255 -0
- package/dist/thinkingLatchWords.d.ts +7 -0
- package/dist/thinkingLatchWords.js +4 -0
- package/dist/toolHistoryMismatch.d.ts +8 -0
- package/dist/toolHistoryMismatch.js +37 -6
- package/dist/toolResult.d.ts +13 -3
- package/dist/toolResult.js +159 -32
- package/dist/toolResultContent.d.ts +13 -0
- package/dist/toolResultContent.js +82 -7
- package/dist/toolRoster.d.ts +18 -0
- package/dist/toolRoster.js +64 -0
- package/dist/turnFailurePresentation.js +27 -90
- package/dist/usageLimitAutoResume.d.ts +74 -0
- package/dist/usageLimitAutoResume.js +227 -0
- package/dist/userAttachmentEnvelope.js +1 -1
- package/dist/userAttachmentSeat.js +5 -5
- package/dist/userInvokedSkillsCapability.js +2 -2
- package/dist/webSearchBackendCapability.js +2 -2
- package/dist/wireErrorTriage.js +99 -50
- package/dist/wireFailureShape.d.ts +25 -1
- package/dist/wireFailureShape.js +92 -5
- package/dist/wireRefusalCopy.d.ts +24 -1
- package/dist/wireRefusalCopy.js +253 -32
- package/dist/wiringFleetDoctor.d.ts +3 -0
- package/dist/wiringFleetDoctor.js +21 -0
- package/dist/workflow.d.ts +2 -1
- package/dist/workflow.js +38 -1
- package/dist/workflowClient.d.ts +2 -7
- package/dist/workflowsJournalCapability.js +2 -2
- package/dist/writeProtectionCapability.js +2 -2
- package/docs/INTEGRATION-CLIENTS.md +907 -182
- package/package.json +14 -3
- package/dist/argvFlagValue.d.ts +0 -8
- package/dist/argvFlagValue.js +0 -37
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { isCcToolDenialKind, isCcToolDenialKindADenial, isGateDeniedByWord } from '../../gateVocabulary.js';
|
|
2
2
|
import { stamp } from '../types.js';
|
|
3
|
-
import { putOwnKey, readFrameStringKey } from '../../ownKey.js';
|
|
3
|
+
import { guardedRead, putOwnKey, readFrameStringKey, readOwnDataFiniteNumber, readOwnDataNonEmptyString, readOwnDataValue } from '../../ownKey.js';
|
|
4
4
|
import { REDACTION_MARKER_PREFIX, washCredentials } from '../../displayUntrusted.js';
|
|
5
5
|
import { readEffectiveReasoning, readEffectiveMemoryScopes } from '../../effectiveFacts.js';
|
|
6
|
-
import { isReviewPark, readRunTerminal, runTerminalCode, runTerminalGateToolName, } from '../../runTerminal.js';
|
|
6
|
+
import { isReviewPark, readRunTerminal, runTerminalCode, runTerminalCodedDetail, runTerminalGateToolName, } from '../../runTerminal.js';
|
|
7
7
|
import { doneResultView, isReplayedTerminal } from '../../replayBody.js';
|
|
8
8
|
import { terminalRunIdOf, terminalUuidOf } from '../../engineRowRef.js';
|
|
9
9
|
import { toCcModelUsage } from './turnUsageToModelUsage.js';
|
|
10
|
-
import {
|
|
10
|
+
import { LIMITS_MAX_TOKENS_EXCEEDED, LIMITS_MAX_WALLTIME_EXCEEDED, isCorruptSessionCode, isLimitsExceededCode, RESULT_LIMIT_WORDS, resultLimitRowOfCode, idempotencyPayloadMismatchContent, isIdempotencyPayloadMismatchCode, isRewindFamilyCode, } from '../../engineErrorCodes.js';
|
|
11
11
|
import { corruptSessionContent } from '../../corruptSessionCopy.js';
|
|
12
12
|
import { runBlockedText } from '../../promptBlockedCopy.js';
|
|
13
13
|
import { abortCauseNoteOf, readAbortCause } from '../../runCancelContext.js';
|
|
14
|
+
import { wayOutOfApiErrorFacts } from '../../providerRejection.js';
|
|
14
15
|
function withTerminalNote(text, code, frame) {
|
|
15
16
|
const withCorrupt = isCorruptSessionCode(code)
|
|
16
17
|
? `${text}\n${corruptSessionContent()}`
|
|
@@ -296,6 +297,26 @@ function costFactParts(stats, observed) {
|
|
|
296
297
|
...(facts.nested !== undefined ? { _sema_nested_usage: facts.nested } : {}),
|
|
297
298
|
};
|
|
298
299
|
}
|
|
300
|
+
export function terminalPartsOfObserved(observed) {
|
|
301
|
+
let denials;
|
|
302
|
+
try {
|
|
303
|
+
denials = permissionDenialParts(undefined, observed);
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
denials = permissionDenialParts(undefined, undefined);
|
|
307
|
+
}
|
|
308
|
+
let lowerBound = false;
|
|
309
|
+
try {
|
|
310
|
+
lowerBound = usageLowerBoundOf(undefined, observed);
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
lowerBound = false;
|
|
314
|
+
}
|
|
315
|
+
return Object.freeze({
|
|
316
|
+
...denials,
|
|
317
|
+
...(lowerBound ? { _sema_usage_lower_bound: true } : {}),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
299
320
|
export const SEMA_SUBAGENT_USAGE_PARTIAL_KEY = '_sema_subagent_usage_partial';
|
|
300
321
|
export function subagentUsageIsPartial(row, opts) {
|
|
301
322
|
if (opts?.tablePartial === true)
|
|
@@ -427,23 +448,10 @@ function degradedOf(r) {
|
|
|
427
448
|
const d = r.degraded;
|
|
428
449
|
return d !== undefined && d !== null && typeof d === 'object' ? d : undefined;
|
|
429
450
|
}
|
|
430
|
-
const COST_EXCEEDED_CODES = new Set([LIMITS_MAX_COST_EXCEEDED]);
|
|
431
|
-
const TURNS_EXCEEDED_CODES = new Set([LIMITS_MAX_TURNS_EXCEEDED]);
|
|
432
451
|
const CUTOFF_EXCEEDED_CODES = new Set([
|
|
433
452
|
LIMITS_MAX_TOKENS_EXCEEDED,
|
|
434
453
|
LIMITS_MAX_WALLTIME_EXCEEDED,
|
|
435
454
|
]);
|
|
436
|
-
function subtypeForErrorCode(code) {
|
|
437
|
-
if (code === undefined || code.length === 0)
|
|
438
|
-
return 'error_during_execution';
|
|
439
|
-
if (COST_EXCEEDED_CODES.has(code))
|
|
440
|
-
return 'error_max_budget_usd';
|
|
441
|
-
if (TURNS_EXCEEDED_CODES.has(code))
|
|
442
|
-
return 'error_max_turns';
|
|
443
|
-
if (code === OUTPUT_INVALID)
|
|
444
|
-
return 'error_max_structured_output_retries';
|
|
445
|
-
return 'error_during_execution';
|
|
446
|
-
}
|
|
447
455
|
function terminalReasonOf(subtype, isError) {
|
|
448
456
|
switch (subtype) {
|
|
449
457
|
case 'success':
|
|
@@ -476,6 +484,103 @@ export function terminalReasonForResult(msg) {
|
|
|
476
484
|
return undefined;
|
|
477
485
|
}
|
|
478
486
|
}
|
|
487
|
+
export function resultLimitOf(frame) {
|
|
488
|
+
const raw = guardedRead(() => readOwnDataNonEmptyString(frame, '_sema_limit'));
|
|
489
|
+
return raw !== undefined && RESULT_LIMIT_WORDS.includes(raw) ? raw : undefined;
|
|
490
|
+
}
|
|
491
|
+
const PRINT_ARM_KIND_TABLE = Object.freeze({ completed: true, failed: true, blocked: true, paused: true, unknown: true });
|
|
492
|
+
function printArmNonBlank(v) {
|
|
493
|
+
return typeof v === 'string' && v.trim().length > 0;
|
|
494
|
+
}
|
|
495
|
+
function printArmObjectLike(v) {
|
|
496
|
+
return typeof v === 'object' && v !== null;
|
|
497
|
+
}
|
|
498
|
+
function printArmRowText(row) {
|
|
499
|
+
const message = readOwnDataValue(row, 'message');
|
|
500
|
+
if (!printArmObjectLike(message) || Array.isArray(message))
|
|
501
|
+
return undefined;
|
|
502
|
+
const content = readOwnDataValue(message, 'content');
|
|
503
|
+
if (typeof content === 'string')
|
|
504
|
+
return printArmNonBlank(content) ? content : undefined;
|
|
505
|
+
if (!Array.isArray(content) || content.length === 0)
|
|
506
|
+
return undefined;
|
|
507
|
+
const last = readOwnDataValue(content, String(content.length - 1));
|
|
508
|
+
if (!printArmObjectLike(last) || Array.isArray(last))
|
|
509
|
+
return undefined;
|
|
510
|
+
const text = readOwnDataValue(last, 'text');
|
|
511
|
+
return readOwnDataValue(last, 'type') === 'text' && printArmNonBlank(text) ? text : undefined;
|
|
512
|
+
}
|
|
513
|
+
function printArmLastRowOriginOf(row) {
|
|
514
|
+
try {
|
|
515
|
+
if (!printArmObjectLike(row) || Array.isArray(row))
|
|
516
|
+
return { origin: 'other' };
|
|
517
|
+
const isAssistant = readOwnDataValue(row, 'type') === 'assistant';
|
|
518
|
+
if (isAssistant && readOwnDataValue(row, '_sema_api_error_message') === true) {
|
|
519
|
+
const text = printArmRowText(row);
|
|
520
|
+
return text !== undefined ? { origin: 'api_error', text } : { origin: 'api_error' };
|
|
521
|
+
}
|
|
522
|
+
const salvaged = readOwnDataValue(row, 'salvagedText');
|
|
523
|
+
if (printArmNonBlank(salvaged))
|
|
524
|
+
return { origin: 'model_text', text: salvaged };
|
|
525
|
+
if (!isAssistant)
|
|
526
|
+
return { origin: 'other' };
|
|
527
|
+
const text = printArmRowText(row);
|
|
528
|
+
return text !== undefined ? { origin: 'model_text', text } : { origin: 'other' };
|
|
529
|
+
}
|
|
530
|
+
catch {
|
|
531
|
+
return { origin: 'other' };
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function printArmStopReasonOf(row) {
|
|
535
|
+
try {
|
|
536
|
+
if (!printArmObjectLike(row) || Array.isArray(row))
|
|
537
|
+
return null;
|
|
538
|
+
const message = readOwnDataValue(row, 'message');
|
|
539
|
+
if (!printArmObjectLike(message) || Array.isArray(message))
|
|
540
|
+
return null;
|
|
541
|
+
return readOwnDataNonEmptyString(message, 'stop_reason') ?? null;
|
|
542
|
+
}
|
|
543
|
+
catch {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const PRINT_ARM_UNKNOWN_OUTCOME = Object.freeze({ subtype: 'error_during_execution', is_error: true, stop_reason: null });
|
|
548
|
+
export function printResultArmOf(input) {
|
|
549
|
+
return printArmReadingOf(input).arm;
|
|
550
|
+
}
|
|
551
|
+
function printArmReadingOf(input) {
|
|
552
|
+
try {
|
|
553
|
+
if (!printArmObjectLike(input) || Array.isArray(input))
|
|
554
|
+
return PRINT_ARM_UNKNOWN_READING;
|
|
555
|
+
if (!Object.hasOwn(input, 'terminal'))
|
|
556
|
+
return PRINT_ARM_UNKNOWN_READING;
|
|
557
|
+
const terminal = readOwnDataValue(input, 'terminal');
|
|
558
|
+
if (terminal !== null && (!printArmObjectLike(terminal) || Array.isArray(terminal)))
|
|
559
|
+
return PRINT_ARM_UNKNOWN_READING;
|
|
560
|
+
const kind = terminal === null ? null : readOwnDataValue(terminal, 'kind');
|
|
561
|
+
if (terminal !== null && (typeof kind !== 'string' || !Object.hasOwn(PRINT_ARM_KIND_TABLE, kind)))
|
|
562
|
+
return PRINT_ARM_UNKNOWN_READING;
|
|
563
|
+
const lastRow = readOwnDataValue(input, 'lastRow');
|
|
564
|
+
const stop_reason = printArmStopReasonOf(lastRow);
|
|
565
|
+
if (kind === 'completed')
|
|
566
|
+
return { arm: Object.freeze({ subtype: 'success', is_error: false, stop_reason }) };
|
|
567
|
+
if (kind === 'failed') {
|
|
568
|
+
const code = readOwnDataValue(terminal, 'code');
|
|
569
|
+
const limit = typeof code === 'string' ? resultLimitRowOfCode(code) : undefined;
|
|
570
|
+
if (limit !== undefined)
|
|
571
|
+
return { arm: Object.freeze({ subtype: limit.subtype, is_error: true, stop_reason, limit: limit.word }) };
|
|
572
|
+
}
|
|
573
|
+
const row = printArmLastRowOriginOf(lastRow);
|
|
574
|
+
if (row.origin === 'api_error' || row.origin === 'model_text') {
|
|
575
|
+
return { arm: Object.freeze({ subtype: 'success', is_error: true, stop_reason }), ...(row.text !== undefined ? { text: row.text, errorRow: row.origin === 'api_error' } : {}) };
|
|
576
|
+
}
|
|
577
|
+
return { arm: Object.freeze({ subtype: 'error_during_execution', is_error: true, stop_reason }) };
|
|
578
|
+
}
|
|
579
|
+
catch {
|
|
580
|
+
return PRINT_ARM_UNKNOWN_READING;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
const PRINT_ARM_UNKNOWN_READING = Object.freeze({ arm: PRINT_ARM_UNKNOWN_OUTCOME });
|
|
479
584
|
function selectedModelParts(model) {
|
|
480
585
|
return typeof model === 'string' && model.length > 0 ? { _sema_selected_model: model } : {};
|
|
481
586
|
}
|
|
@@ -496,17 +601,28 @@ function cutoffParts(r, message, fallbackMessage, code) {
|
|
|
496
601
|
...(salvaged !== undefined ? { salvagedResult: salvaged } : {}),
|
|
497
602
|
};
|
|
498
603
|
}
|
|
604
|
+
function localWayOutFacts(r, rejection) {
|
|
605
|
+
const apiFailure = guardedRead(() => readOwnDataValue(r, 'apiFailure'));
|
|
606
|
+
const apiFailureStatus = typeof apiFailure === 'object' && apiFailure !== null && guardedRead(() => !Array.isArray(apiFailure) || undefined) === true
|
|
607
|
+
? guardedRead(() => readOwnDataFiniteNumber(apiFailure, 'status'))
|
|
608
|
+
: undefined;
|
|
609
|
+
const status = apiFailureStatus ?? rejection?.status;
|
|
610
|
+
return {
|
|
611
|
+
...(status !== undefined ? { status } : {}),
|
|
612
|
+
...(rejection?.providerCondition !== undefined ? { providerCondition: rejection.providerCondition } : {}),
|
|
613
|
+
...(rejection?.route !== undefined ? { credentialSource: rejection.route.credentialSource } : {}),
|
|
614
|
+
};
|
|
615
|
+
}
|
|
499
616
|
function errorResult(ctx, parts) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
subtype: parts.subtype,
|
|
617
|
+
const errors = parts.errors.map(washCredentials);
|
|
618
|
+
const arm = parts.arm;
|
|
619
|
+
const result = arm.subtype === 'success' ? (parts.lastRowText ?? errors.join('\n')) : undefined;
|
|
620
|
+
const head = {
|
|
505
621
|
duration_ms: parts.durationMs,
|
|
506
622
|
duration_api_ms: parts.durationMs,
|
|
507
|
-
is_error:
|
|
623
|
+
is_error: arm.is_error,
|
|
508
624
|
num_turns: parts.stats?.turns ?? 0,
|
|
509
|
-
stop_reason:
|
|
625
|
+
stop_reason: arm.stop_reason,
|
|
510
626
|
total_cost_usd: costOrNull(parts.stats),
|
|
511
627
|
usage: flattenUsage(parts.stats),
|
|
512
628
|
modelUsage: modelUsageFor(parts.stats, parts.model),
|
|
@@ -514,8 +630,9 @@ function errorResult(ctx, parts) {
|
|
|
514
630
|
...costFactParts(parts.stats, parts.observed),
|
|
515
631
|
...reemitEffectiveFacts(parts.facts),
|
|
516
632
|
...nestedUsageByTaskParts(parts.stats, parts.observed?.nestedUsageByTask),
|
|
517
|
-
|
|
518
|
-
|
|
633
|
+
};
|
|
634
|
+
const tail = {
|
|
635
|
+
...terminalReasonParts(arm.subtype, arm.is_error),
|
|
519
636
|
...(parts.errorCode !== undefined && parts.errorCode.length > 0 ? { _sema_error_code: parts.errorCode } : {}),
|
|
520
637
|
...(parts.degraded !== undefined ? { _sema_model_degraded: parts.degraded } : {}),
|
|
521
638
|
...selectedModelParts(parts.model),
|
|
@@ -524,8 +641,39 @@ function errorResult(ctx, parts) {
|
|
|
524
641
|
...(parts.parkFailedReason !== undefined ? { _sema_park_failed_reason: washCredentials(parts.parkFailedReason) } : {}),
|
|
525
642
|
...(parts.abortCause !== undefined ? { _sema_abort_cause: parts.abortCause } : {}),
|
|
526
643
|
...(parts.route !== undefined ? { _sema_route: routeOnFrame(parts.route) } : {}),
|
|
644
|
+
...('limit' in arm && arm.limit !== undefined ? { _sema_limit: arm.limit } : {}),
|
|
645
|
+
...(parts.wayOut !== undefined ? { _sema_wayOut: wayOutOnFrame(parts.wayOut) } : {}),
|
|
646
|
+
...(parts.codedDetail !== undefined ? { _sema_coded_detail: parts.codedDetail } : {}),
|
|
647
|
+
...(parts.errorCode !== undefined && parts.errorCode.length > 0 && errorsStateCode(errors[0], parts.errorCode) ? { _sema_error_code_in_text: true } : {}),
|
|
648
|
+
};
|
|
649
|
+
if (arm.subtype === 'success') {
|
|
650
|
+
return stamp(ctx, {
|
|
651
|
+
uuid: parts.uuid,
|
|
652
|
+
session_id: undefined,
|
|
653
|
+
type: 'result',
|
|
654
|
+
subtype: 'success',
|
|
655
|
+
...head,
|
|
656
|
+
result,
|
|
657
|
+
errors,
|
|
658
|
+
...tail,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
return stamp(ctx, {
|
|
662
|
+
uuid: parts.uuid,
|
|
663
|
+
session_id: undefined,
|
|
664
|
+
type: 'result',
|
|
665
|
+
subtype: arm.subtype,
|
|
666
|
+
...head,
|
|
667
|
+
errors,
|
|
668
|
+
...tail,
|
|
527
669
|
});
|
|
528
670
|
}
|
|
671
|
+
function errorsStateCode(first, code) {
|
|
672
|
+
return typeof first === 'string' && (first === code || first.startsWith(`${code}\n`) || first.includes(` (${code})`));
|
|
673
|
+
}
|
|
674
|
+
function wayOutOnFrame(wayOut) {
|
|
675
|
+
return { word: wayOut.word, ...(wayOut.keySource !== undefined ? { keySource: wayOut.keySource } : {}) };
|
|
676
|
+
}
|
|
529
677
|
function routeOnFrame(route) {
|
|
530
678
|
return {
|
|
531
679
|
credentialSource: route.credentialSource,
|
|
@@ -534,6 +682,19 @@ function routeOnFrame(route) {
|
|
|
534
682
|
root: route.root,
|
|
535
683
|
};
|
|
536
684
|
}
|
|
685
|
+
function lastRowOf(observed) {
|
|
686
|
+
if (observed === undefined || !Object.hasOwn(observed, 'lastRow'))
|
|
687
|
+
return null;
|
|
688
|
+
return observed.lastRow ?? null;
|
|
689
|
+
}
|
|
690
|
+
function lastRowTextOf(reading) {
|
|
691
|
+
if (reading.text === undefined)
|
|
692
|
+
return undefined;
|
|
693
|
+
return reading.errorRow === true ? washCredentials(reading.text) : reading.text;
|
|
694
|
+
}
|
|
695
|
+
function failedEventTerminal(code) {
|
|
696
|
+
return typeof code === 'string' && code.length > 0 ? { kind: 'failed', plane: 'flat', code } : { kind: 'failed', plane: 'flat' };
|
|
697
|
+
}
|
|
537
698
|
export function doneToSdkResult(ev, ctx, observed) {
|
|
538
699
|
const msg = doneToSdkResultBody(ev, ctx, observed);
|
|
539
700
|
return isReplayedTerminal(ev) ? Object.assign({}, msg, { _sema_replay: true }) : msg;
|
|
@@ -549,29 +710,40 @@ function doneToSdkResultBody(ev, ctx, observed) {
|
|
|
549
710
|
if (typeof echoedSid === 'string' && echoedSid.length > 0)
|
|
550
711
|
ctx.sessionId = echoedSid;
|
|
551
712
|
const terminal = readRunTerminal(ev.result);
|
|
713
|
+
const armReading = printArmReadingOf({ terminal: terminal ?? null, lastRow: lastRowOf(observed) });
|
|
714
|
+
const arm = armReading.arm;
|
|
552
715
|
const durationMs = elapsedMs(ctx);
|
|
553
716
|
const errorCode = runTerminalCode(terminal);
|
|
554
717
|
const degraded = degradedOf(r);
|
|
555
718
|
const parkFailedReason = readFrameStringKey(ev, '_sema_park_failed_reason');
|
|
556
719
|
const terminalRunId = terminalRunIdOf(ev);
|
|
557
720
|
const resultUuid = terminalRunId === undefined ? undefined : terminalUuidOf(terminalRunId, 'result');
|
|
558
|
-
const errorBase = { uuid: resultUuid, durationMs, stats, model: r.model, errorCode, degraded, observed, facts: effectiveFactParts(rec), parkFailedReason, abortCause: abortCauseWordOf(ev) };
|
|
721
|
+
const errorBase = { uuid: resultUuid, arm, lastRowText: lastRowTextOf(armReading), durationMs, stats, model: r.model, errorCode, degraded, observed, facts: effectiveFactParts(rec), parkFailedReason, abortCause: abortCauseWordOf(ev) };
|
|
559
722
|
if (terminal?.kind === 'failed') {
|
|
560
723
|
const failedCode = terminal.code;
|
|
561
724
|
const failedMessage = terminal.message;
|
|
562
|
-
const
|
|
725
|
+
const failedLimit = 'limit' in arm ? arm.limit : undefined;
|
|
726
|
+
const failedCoded = observed !== undefined && Object.hasOwn(observed, 'codedDetail') ? observed.codedDetail : runTerminalCodedDetail(terminal);
|
|
563
727
|
if (failedCode !== undefined && CUTOFF_EXCEEDED_CODES.has(failedCode)) {
|
|
564
728
|
return errorResult(ctx, {
|
|
565
729
|
...errorBase,
|
|
566
|
-
|
|
730
|
+
...(failedCoded !== undefined ? { codedDetail: failedCoded } : {}),
|
|
567
731
|
...cutoffParts(r, failedMessage, failedCode === LIMITS_MAX_TOKENS_EXCEEDED
|
|
568
732
|
? 'run exhausted its token budget'
|
|
569
733
|
: 'run hit its wall-clock limit', failedCode),
|
|
570
734
|
});
|
|
571
735
|
}
|
|
736
|
+
const rejection = terminal.detail?.kind === 'provider_rejected' ? terminal.detail : undefined;
|
|
737
|
+
const wayOutFacts = observed !== undefined && Object.hasOwn(observed, 'wayOutFacts')
|
|
738
|
+
? observed.wayOutFacts
|
|
739
|
+
: failedLimit !== undefined || isLimitsExceededCode(failedCode)
|
|
740
|
+
? undefined
|
|
741
|
+
: localWayOutFacts(r, rejection);
|
|
742
|
+
const failedWayOut = wayOutFacts === undefined || failedLimit !== undefined ? undefined : wayOutOfApiErrorFacts(wayOutFacts);
|
|
572
743
|
return errorResult(ctx, {
|
|
573
744
|
...errorBase,
|
|
574
|
-
|
|
745
|
+
...(failedWayOut !== undefined ? { wayOut: failedWayOut } : {}),
|
|
746
|
+
...(failedCoded !== undefined ? { codedDetail: failedCoded } : {}),
|
|
575
747
|
...(terminal.detail?.kind === 'provider_rejected' && terminal.detail.route !== undefined ? { route: terminal.detail.route } : {}),
|
|
576
748
|
errors: [
|
|
577
749
|
withTerminalNote(isRewindFamilyCode(failedCode) && failedMessage
|
|
@@ -583,7 +755,6 @@ function doneToSdkResultBody(ev, ctx, observed) {
|
|
|
583
755
|
if (terminal?.kind === 'blocked') {
|
|
584
756
|
return errorResult(ctx, {
|
|
585
757
|
...errorBase,
|
|
586
|
-
subtype: 'error_during_execution',
|
|
587
758
|
errors: [runBlockedText(terminal)],
|
|
588
759
|
});
|
|
589
760
|
}
|
|
@@ -599,7 +770,6 @@ function doneToSdkResultBody(ev, ctx, observed) {
|
|
|
599
770
|
: `Answer it in the interactive REPL${sid ? ` (sema --resume ${sid})` : ''}, or decide the pending approval via the engine approvals API${sid ? ` (POST /v1/approvals/${sid}/decide)` : ''}.`;
|
|
600
771
|
return errorResult(ctx, {
|
|
601
772
|
...errorBase,
|
|
602
|
-
subtype: 'error_during_execution',
|
|
603
773
|
errors: [
|
|
604
774
|
`Turn suspended awaiting ${awaiting} that no one can provide in -p (non-interactive) mode${runId ? ` (run ${runId})` : ''}. ${wayOut}`,
|
|
605
775
|
],
|
|
@@ -608,7 +778,6 @@ function doneToSdkResultBody(ev, ctx, observed) {
|
|
|
608
778
|
if (terminal === null || terminal === undefined) {
|
|
609
779
|
return errorResult(ctx, {
|
|
610
780
|
...errorBase,
|
|
611
|
-
subtype: 'error_during_execution',
|
|
612
781
|
outcomeUnknown: true,
|
|
613
782
|
errors: [
|
|
614
783
|
'run ended with no terminal record — outcome unknown, not a failure verdict (this client cannot tell whether the run succeeded; treat the result as unverified)',
|
|
@@ -618,7 +787,6 @@ function doneToSdkResultBody(ev, ctx, observed) {
|
|
|
618
787
|
if (terminal?.kind === 'unknown') {
|
|
619
788
|
return errorResult(ctx, {
|
|
620
789
|
...errorBase,
|
|
621
|
-
subtype: 'error_during_execution',
|
|
622
790
|
outcomeUnknown: true,
|
|
623
791
|
errors: [
|
|
624
792
|
terminal.message ??
|
|
@@ -629,24 +797,25 @@ function doneToSdkResultBody(ev, ctx, observed) {
|
|
|
629
797
|
],
|
|
630
798
|
});
|
|
631
799
|
}
|
|
800
|
+
const completedArm = arm;
|
|
632
801
|
return stamp(ctx, {
|
|
633
802
|
uuid: resultUuid,
|
|
634
803
|
session_id: undefined,
|
|
635
804
|
type: 'result',
|
|
636
|
-
subtype:
|
|
805
|
+
subtype: completedArm.subtype,
|
|
637
806
|
duration_ms: durationMs,
|
|
638
807
|
duration_api_ms: durationMs,
|
|
639
|
-
is_error:
|
|
808
|
+
is_error: completedArm.is_error,
|
|
640
809
|
num_turns: stats?.turns ?? 0,
|
|
641
810
|
result: r.result ?? '',
|
|
642
811
|
...structuredOutputParts(r),
|
|
643
812
|
...(degraded !== undefined ? { _sema_model_degraded: degraded } : {}),
|
|
644
|
-
stop_reason:
|
|
813
|
+
stop_reason: completedArm.stop_reason,
|
|
645
814
|
total_cost_usd: costOrNull(stats),
|
|
646
815
|
usage: flattenUsage(stats),
|
|
647
816
|
modelUsage: modelUsageFor(stats, r.model),
|
|
648
817
|
...permissionDenialParts(stats, observed),
|
|
649
|
-
...terminalReasonParts(
|
|
818
|
+
...terminalReasonParts(completedArm.subtype, completedArm.is_error),
|
|
650
819
|
...costFactParts(stats, observed),
|
|
651
820
|
...effectiveFactParts(rec),
|
|
652
821
|
...nestedUsageByTaskParts(stats, observed?.nestedUsageByTask),
|
|
@@ -654,9 +823,10 @@ function doneToSdkResultBody(ev, ctx, observed) {
|
|
|
654
823
|
});
|
|
655
824
|
}
|
|
656
825
|
export function failedToSdkResult(ev, ctx, observed) {
|
|
657
|
-
const
|
|
826
|
+
const armReading = printArmReadingOf({ terminal: failedEventTerminal(ev.errorCode), lastRow: lastRowOf(observed) });
|
|
658
827
|
return errorResult(ctx, {
|
|
659
|
-
|
|
828
|
+
arm: armReading.arm,
|
|
829
|
+
lastRowText: lastRowTextOf(armReading),
|
|
660
830
|
observed,
|
|
661
831
|
durationMs: elapsedMs(ctx),
|
|
662
832
|
errorCode: ev.errorCode,
|
|
@@ -46,3 +46,4 @@ export declare function readInstructionsSegment(holder: object, key: 'instructio
|
|
|
46
46
|
} | undefined;
|
|
47
47
|
export declare function readFleetSegment(holder: object, key: 'fleet' | '_sema_fleet'): WiringManifestFleetView | undefined;
|
|
48
48
|
export declare function wiringManifestViewOf(s: WiringManifestSections): WiringManifestView | undefined;
|
|
49
|
+
export declare function modRowsOf(records: unknown): readonly WiringManifestModView[] | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appendOwnElement } from '../../ownKey.js';
|
|
1
2
|
const _viewPin = true;
|
|
2
3
|
void _viewPin;
|
|
3
4
|
const _viewKeysPin = true;
|
|
@@ -67,3 +68,140 @@ export function wiringManifestViewOf(s) {
|
|
|
67
68
|
view.eventId = s.eventId;
|
|
68
69
|
return view;
|
|
69
70
|
}
|
|
71
|
+
const isModRecordObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
72
|
+
function ownSlot(o, key) {
|
|
73
|
+
try {
|
|
74
|
+
const d = Object.getOwnPropertyDescriptor(o, key);
|
|
75
|
+
if (d === undefined)
|
|
76
|
+
return { state: 'absent' };
|
|
77
|
+
if (!Object.hasOwn(d, 'value'))
|
|
78
|
+
return { state: 'unreadable' };
|
|
79
|
+
return d.value === undefined ? { state: 'absent' } : { state: 'value', value: d.value };
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return { state: 'unreadable' };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function ownLength(v) {
|
|
86
|
+
const s = ownSlot(v, 'length');
|
|
87
|
+
return s.state === 'value' && typeof s.value === 'number' && Number.isSafeInteger(s.value) && s.value >= 0 ? s.value : undefined;
|
|
88
|
+
}
|
|
89
|
+
const nonEmpty = (s) => (s.state === 'value' && typeof s.value === 'string' && s.value.length > 0 ? s.value : undefined);
|
|
90
|
+
function ownStringList(v) {
|
|
91
|
+
try {
|
|
92
|
+
if (!Array.isArray(v))
|
|
93
|
+
return undefined;
|
|
94
|
+
const n = ownLength(v);
|
|
95
|
+
if (n === undefined)
|
|
96
|
+
return undefined;
|
|
97
|
+
const out = [];
|
|
98
|
+
for (let i = 0; i < n; i++) {
|
|
99
|
+
const x = ownSlot(v, String(i));
|
|
100
|
+
if (x.state !== 'value' || typeof x.value !== 'string')
|
|
101
|
+
return undefined;
|
|
102
|
+
appendOwnElement(out, x.value);
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function skipOf(x) {
|
|
111
|
+
try {
|
|
112
|
+
if (!isModRecordObject(x))
|
|
113
|
+
return undefined;
|
|
114
|
+
const registration = nonEmpty(ownSlot(x, 'registration'));
|
|
115
|
+
const cause = nonEmpty(ownSlot(x, 'cause'));
|
|
116
|
+
const reason = nonEmpty(ownSlot(x, 'reason'));
|
|
117
|
+
return registration === undefined || cause === undefined || reason === undefined ? undefined : { registration, cause, reason };
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function modRowOf(r) {
|
|
124
|
+
try {
|
|
125
|
+
if (!isModRecordObject(r))
|
|
126
|
+
return undefined;
|
|
127
|
+
const name = nonEmpty(ownSlot(r, 'name'));
|
|
128
|
+
const seat = nonEmpty(ownSlot(r, 'seat'));
|
|
129
|
+
const tier = nonEmpty(ownSlot(r, 'tier'));
|
|
130
|
+
if (name === undefined || seat === undefined || tier === undefined)
|
|
131
|
+
return undefined;
|
|
132
|
+
const events = ownSlot(r, 'events');
|
|
133
|
+
const observe = ownSlot(r, 'observe');
|
|
134
|
+
const skipped = ownSlot(r, 'skipped');
|
|
135
|
+
const refusedBy = ownSlot(r, 'refusedBy');
|
|
136
|
+
const reason = ownSlot(r, 'reason');
|
|
137
|
+
const hasMountedKey = events.state !== 'absent' || observe.state !== 'absent' || skipped.state !== 'absent';
|
|
138
|
+
const hasRefusedKey = refusedBy.state !== 'absent' || reason.state !== 'absent';
|
|
139
|
+
if (hasMountedKey && hasRefusedKey)
|
|
140
|
+
return undefined;
|
|
141
|
+
if (hasRefusedKey) {
|
|
142
|
+
const by = nonEmpty(refusedBy);
|
|
143
|
+
const why = nonEmpty(reason);
|
|
144
|
+
if (by === undefined || why === undefined)
|
|
145
|
+
return undefined;
|
|
146
|
+
const refused = { name, seat, tier, refusedBy: by, reason: why };
|
|
147
|
+
return refused;
|
|
148
|
+
}
|
|
149
|
+
const eventList = events.state === 'value' ? ownStringList(events.value) : undefined;
|
|
150
|
+
if (eventList === undefined)
|
|
151
|
+
return undefined;
|
|
152
|
+
const observeList = observe.state === 'value' ? ownStringList(observe.value) : undefined;
|
|
153
|
+
const skipList = skipped.state === 'value' ? skipListOf(skipped.value) : undefined;
|
|
154
|
+
const mounted = {
|
|
155
|
+
name,
|
|
156
|
+
seat,
|
|
157
|
+
tier,
|
|
158
|
+
events: eventList,
|
|
159
|
+
...(observeList !== undefined ? { observe: observeList } : {}),
|
|
160
|
+
...(skipList !== undefined && skipList.length > 0 ? { skipped: skipList } : {}),
|
|
161
|
+
};
|
|
162
|
+
return mounted;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function skipListOf(v) {
|
|
169
|
+
try {
|
|
170
|
+
if (!Array.isArray(v))
|
|
171
|
+
return undefined;
|
|
172
|
+
const n = ownLength(v);
|
|
173
|
+
if (n === undefined)
|
|
174
|
+
return undefined;
|
|
175
|
+
const out = [];
|
|
176
|
+
for (let i = 0; i < n; i++) {
|
|
177
|
+
const x = ownSlot(v, String(i));
|
|
178
|
+
const s = x.state === 'value' ? skipOf(x.value) : undefined;
|
|
179
|
+
if (s !== undefined)
|
|
180
|
+
appendOwnElement(out, s);
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export function modRowsOf(records) {
|
|
189
|
+
try {
|
|
190
|
+
if (!Array.isArray(records))
|
|
191
|
+
return undefined;
|
|
192
|
+
const n = ownLength(records);
|
|
193
|
+
if (n === undefined)
|
|
194
|
+
return undefined;
|
|
195
|
+
const rows = [];
|
|
196
|
+
for (let i = 0; i < n; i++) {
|
|
197
|
+
const x = ownSlot(records, String(i));
|
|
198
|
+
const row = x.state === 'value' ? modRowOf(x.value) : undefined;
|
|
199
|
+
if (row !== undefined)
|
|
200
|
+
appendOwnElement(rows, row);
|
|
201
|
+
}
|
|
202
|
+
return n > 0 && rows.length === 0 ? undefined : rows;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { AgentEvent } from '@sema-agent/sdk';
|
|
2
2
|
import { type SDKMessage, type EmitContext, type ModelUsage } from './types.js';
|
|
3
3
|
import { type EngineTurnUsage } from './downstream/turnUsageToModelUsage.js';
|
|
4
|
+
import type { ObservedTerminalParts } from './downstream/terminalToSdkResult.js';
|
|
4
5
|
import { type ToolHistoryErrorCarrier } from '../toolHistoryMismatch.js';
|
|
6
|
+
import { MODEL_OUTPUT_ERROR_PREFIX, OUTCOME_UNKNOWN_ROW_PREFIX, RUN_BLOCKED_MESSAGE_PREFIX, RUN_STOPPED_MESSAGE_PREFIX } from '../rowKind.js';
|
|
7
|
+
export { MODEL_OUTPUT_ERROR_PREFIX, OUTCOME_UNKNOWN_ROW_PREFIX, RUN_BLOCKED_MESSAGE_PREFIX, RUN_STOPPED_MESSAGE_PREFIX };
|
|
5
8
|
export interface ActiveRunPendingGate {
|
|
6
9
|
readonly kind: string | null;
|
|
7
10
|
readonly decidePath: string | null;
|
|
@@ -16,13 +19,9 @@ export interface ActiveRunBusySignal {
|
|
|
16
19
|
readonly msSinceLastActivity?: number;
|
|
17
20
|
}
|
|
18
21
|
export declare function activeRunBusySignal(ev: unknown): ActiveRunBusySignal | null;
|
|
19
|
-
export declare const RUN_STOPPED_MESSAGE_PREFIX = "Run stopped";
|
|
20
|
-
export declare const RUN_BLOCKED_MESSAGE_PREFIX = "Run blocked";
|
|
21
22
|
export declare function isGovernanceStopRowText(text: string): boolean;
|
|
22
|
-
export declare const MODEL_OUTPUT_ERROR_PREFIX = "Model output error";
|
|
23
23
|
export declare function isModelOutputErrorText(text: string): boolean;
|
|
24
24
|
export declare function isModelOutputErrorRowText(text: string): boolean;
|
|
25
|
-
export declare const OUTCOME_UNKNOWN_ROW_PREFIX = "Outcome unknown";
|
|
26
25
|
export declare function isOutcomeUnknownRowText(text: string): boolean;
|
|
27
26
|
export declare function isGovernanceTerminal(input: {
|
|
28
27
|
status: string | undefined;
|
|
@@ -36,6 +35,7 @@ export interface RunStreamHandle {
|
|
|
36
35
|
latestUsage?: ModelUsage;
|
|
37
36
|
latestEngineUsage?: EngineTurnUsage | undefined;
|
|
38
37
|
latestUsageMissing?: true;
|
|
38
|
+
observedTerminalParts?: () => ObservedTerminalParts;
|
|
39
39
|
}
|
|
40
40
|
export declare function isRunStreamActive(): boolean;
|
|
41
41
|
export declare function runStream(events: AsyncIterable<AgentEvent>, ctx: EmitContext, handle?: RunStreamHandle): AsyncGenerator<SDKMessage>;
|