@sema-agent/client-core 0.100.0 → 0.101.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 +395 -0
- package/README.md +164 -117
- package/dist/adapt/arms.js +51 -16
- package/dist/adapt/textStream.js +7 -4
- package/dist/adapt/toolCards.js +9 -8
- package/dist/adapt.js +7 -1
- package/dist/adapter/activeRunSelfHeal.d.ts +24 -2
- package/dist/adapter/activeRunSelfHeal.js +108 -6
- package/dist/adapter/downstream/eventToSdkMessage.js +33 -12
- package/dist/adapter/downstream/terminalToSdkResult.d.ts +60 -1
- package/dist/adapter/downstream/terminalToSdkResult.js +209 -39
- 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/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 +1 -0
- package/dist/displayUntrusted.js +65 -8
- 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 +3 -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 +15 -2
- 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 +184 -2
- package/dist/i18n/messages.en.js +187 -5
- package/dist/i18n/messages.zh.js +197 -5
- package/dist/i18n/translate.js +3 -3
- package/dist/index.d.ts +69 -15
- package/dist/index.js +45 -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/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/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 +11 -0
- package/dist/ownKey.js +164 -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/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 +5 -1
- package/dist/request/submissionIdentity.d.ts +37 -0
- package/dist/request/submissionIdentity.js +65 -0
- package/dist/request/taskRequest.d.ts +12 -4
- package/dist/request/taskRequest.js +221 -152
- 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 +2 -2
- package/dist/seatContract.d.ts +46 -1
- package/dist/seatContract.js +49 -19
- package/dist/selfOrchestrationDenial.js +1 -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 +60 -5
- 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/toolHistoryMismatch.d.ts +8 -0
- package/dist/toolHistoryMismatch.js +37 -6
- package/dist/toolResult.d.ts +13 -3
- package/dist/toolResult.js +158 -9
- 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 +607 -181
- package/package.json +14 -3
|
@@ -5,7 +5,7 @@ import { ccToolDenialKindForToolEnd, gateOutcomeOf } from '../../gateOutcome.js'
|
|
|
5
5
|
import { projectToolRoster, projectToolRosterDelta } from '../../toolRoster.js';
|
|
6
6
|
import { projectHandsSection } from '../../handsSeam.js';
|
|
7
7
|
import { readMcpLiveness } from '../../mcpLiveness.js';
|
|
8
|
-
import { contextUsageReadingOf, humanInputAttachmentsOf, markMcpSectionDroppedNamedRows, promptManifestIdentityOfFrame, promptManifestSectionViewOf, readFrameTrueMark } from '../../ownKey.js';
|
|
8
|
+
import { contextUsageReadingOf, humanInputAttachmentsOf, guardedRead, markMcpSectionDroppedNamedRows, ownSnapshotTyped, promptManifestIdentityOfFrame, promptManifestSectionViewOf, readFrameTrueMark, readOwnDataNonEmptyString } from '../../ownKey.js';
|
|
9
9
|
import { SEGMENT_END_IDENTITY_KEYS, eventSeq, stripToolUseSideChannels } from '../types.js';
|
|
10
10
|
import { frozenSet } from '../../frozenSet.js';
|
|
11
11
|
import { isCoreWorkflowRunTerminal } from '../../terminalStatuses.js';
|
|
@@ -76,12 +76,27 @@ function isCompactionStartedFrame(ev) {
|
|
|
76
76
|
function assertNeverArm(_ev) {
|
|
77
77
|
}
|
|
78
78
|
export function eventToSdkMessage(ev, ctx) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const entry = sampleNotificationEntry(ev);
|
|
80
|
+
if (entry.dropped !== undefined)
|
|
81
|
+
return entry.dropped;
|
|
82
|
+
return withEngineIdentity(projectEvent(entry.frame, ctx), ev, ctx, entry.frame);
|
|
83
|
+
}
|
|
84
|
+
function sampleNotificationEntry(ev) {
|
|
85
|
+
const word = guardedRead(() => readOwnDataNonEmptyString(ev, 'type'));
|
|
86
|
+
if (word !== 'task_notification' && word !== 'workflow_complete')
|
|
87
|
+
return { frame: ev };
|
|
88
|
+
const sampled = ownSnapshotTyped(ev);
|
|
89
|
+
if (sampled === undefined)
|
|
90
|
+
return { dropped: dropped('malformed', word) };
|
|
91
|
+
return { frame: sampled };
|
|
92
|
+
}
|
|
93
|
+
function noticeSnapshotOf(ev) {
|
|
94
|
+
return ownSnapshotTyped(ev);
|
|
95
|
+
}
|
|
96
|
+
function withEngineIdentity(p, ev, ctx, identityFrame = ev) {
|
|
82
97
|
if (p.kind !== 'message')
|
|
83
98
|
return p;
|
|
84
|
-
const eventId = wireEventIdOf(
|
|
99
|
+
const eventId = wireEventIdOf(identityFrame);
|
|
85
100
|
if (eventId === undefined)
|
|
86
101
|
return p;
|
|
87
102
|
const env = p.message;
|
|
@@ -128,17 +143,20 @@ function projectEvent(ev, ctx) {
|
|
|
128
143
|
})));
|
|
129
144
|
}
|
|
130
145
|
case 'workflow_complete': {
|
|
131
|
-
|
|
146
|
+
const wf = noticeSnapshotOf(ev);
|
|
147
|
+
if (wf === undefined)
|
|
148
|
+
return dropped('malformed', 'workflow_complete');
|
|
149
|
+
if (typeof wf.runId !== 'string' || wf.runId.length === 0) {
|
|
132
150
|
return dropped('malformed', 'workflow_complete');
|
|
133
151
|
}
|
|
134
|
-
if (!isCoreWorkflowRunTerminal(
|
|
152
|
+
if (!isCoreWorkflowRunTerminal(wf.status)) {
|
|
135
153
|
return dropped('malformed', 'workflow_complete');
|
|
136
154
|
}
|
|
137
155
|
return projected(stamp(ctx, armBody({
|
|
138
156
|
type: 'workflow_complete',
|
|
139
|
-
runId:
|
|
140
|
-
status:
|
|
141
|
-
summary: typeof
|
|
157
|
+
runId: wf.runId,
|
|
158
|
+
status: wf.status,
|
|
159
|
+
summary: typeof wf.summary === 'string' ? wf.summary : '',
|
|
142
160
|
})));
|
|
143
161
|
}
|
|
144
162
|
case 'text':
|
|
@@ -313,8 +331,11 @@ function projectEvent(ev, ctx) {
|
|
|
313
331
|
return projected(stamp(ctx, armBody({ type: 'wiring_manifest', ...body, ...identity })));
|
|
314
332
|
}
|
|
315
333
|
case 'task_notification': {
|
|
316
|
-
const
|
|
317
|
-
|
|
334
|
+
const notice = noticeSnapshotOf(ev);
|
|
335
|
+
if (notice === undefined)
|
|
336
|
+
return dropped('malformed', 'task_notification');
|
|
337
|
+
const nested = notice.notification;
|
|
338
|
+
const n = (nested ?? notice);
|
|
318
339
|
if (typeof n.task_id !== 'string')
|
|
319
340
|
return dropped('malformed', 'task_notification');
|
|
320
341
|
return projected(stamp(ctx, armBody({
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { AgentEvent, TaskStats } from '@sema-agent/sdk';
|
|
2
2
|
import { type CcToolDenialKind, type GateDeniedByWord } from '../../gateVocabulary.js';
|
|
3
3
|
import { type SDKMessage, type EmitContext } from '../types.js';
|
|
4
|
-
import type { TerminalReason } from '@sema-agent/agent-types';
|
|
4
|
+
import type { SDKPermissionDenial, SDKResultError, SDKResultSuccess, TerminalReason } from '@sema-agent/agent-types';
|
|
5
|
+
import { type RunTerminalCodedDetail, type RunTerminalRead } from '../../runTerminal.js';
|
|
5
6
|
import { type SemaModelUsage } from './turnUsageToModelUsage.js';
|
|
7
|
+
import { type ResultLimitWord } from '../../engineErrorCodes.js';
|
|
8
|
+
import { type ResultWayOutFacts } from '../../providerRejection.js';
|
|
6
9
|
export interface SemaFlatUsage {
|
|
7
10
|
readonly inputTokens: number;
|
|
8
11
|
readonly outputTokens: number;
|
|
@@ -23,6 +26,9 @@ export interface TerminalStreamObserved {
|
|
|
23
26
|
readonly streamSawRunOpen?: boolean;
|
|
24
27
|
readonly deniedToolNameByCallId?: ReadonlyMap<string, string | undefined>;
|
|
25
28
|
readonly deniedCallsOverflowed?: boolean;
|
|
29
|
+
readonly wayOutFacts?: ResultWayOutFacts | undefined;
|
|
30
|
+
readonly codedDetail?: RunTerminalCodedDetail | undefined;
|
|
31
|
+
readonly lastRow?: PrintResultLastRow | null;
|
|
26
32
|
}
|
|
27
33
|
export declare const TOOL_INPUT_JOIN_MAX_CALLS = 4096;
|
|
28
34
|
export interface SemaPermissionDenial {
|
|
@@ -36,6 +42,22 @@ export interface SemaPermissionDenial {
|
|
|
36
42
|
readonly _sema_denied_by_source?: 'tool_end';
|
|
37
43
|
readonly toolDenialKind?: CcToolDenialKind;
|
|
38
44
|
}
|
|
45
|
+
export interface CcPermissionDenial {
|
|
46
|
+
readonly tool_name: string;
|
|
47
|
+
readonly tool_use_id: string;
|
|
48
|
+
readonly tool_input: SDKPermissionDenial['tool_input'];
|
|
49
|
+
readonly _sema_tool_arg?: string;
|
|
50
|
+
readonly _sema_tool_input_redacted?: true;
|
|
51
|
+
readonly deniedBy?: GateDeniedByWord;
|
|
52
|
+
readonly _sema_denied_by_source?: 'tool_end';
|
|
53
|
+
readonly toolDenialKind?: CcToolDenialKind;
|
|
54
|
+
}
|
|
55
|
+
export interface PermissionDenialParts {
|
|
56
|
+
readonly permission_denials: readonly CcPermissionDenial[];
|
|
57
|
+
readonly _sema_permission_denials?: readonly SemaPermissionDenial[];
|
|
58
|
+
readonly _sema_permission_denials_absent?: true;
|
|
59
|
+
readonly _sema_zero_output_denied?: true;
|
|
60
|
+
}
|
|
39
61
|
export interface SemaCostBreakdown {
|
|
40
62
|
readonly llmRootMicroUsd?: number;
|
|
41
63
|
readonly nestedSubagentMicroUsd?: number;
|
|
@@ -68,6 +90,10 @@ export interface RunCostFacts {
|
|
|
68
90
|
export declare function readRunCostFacts(stats: TaskStats | undefined, observed?: {
|
|
69
91
|
readonly usageMissingObserved?: boolean;
|
|
70
92
|
}): RunCostFacts | undefined;
|
|
93
|
+
export interface ObservedTerminalParts extends PermissionDenialParts {
|
|
94
|
+
readonly _sema_usage_lower_bound?: true;
|
|
95
|
+
}
|
|
96
|
+
export declare function terminalPartsOfObserved(observed: TerminalStreamObserved | undefined): ObservedTerminalParts;
|
|
71
97
|
export interface SemaSubagentUsageRow {
|
|
72
98
|
readonly turns: number;
|
|
73
99
|
readonly inputTokens: number;
|
|
@@ -98,6 +124,39 @@ export interface SemaTerminalModelUsage extends SemaModelUsage {
|
|
|
98
124
|
readonly _sema_cache_write_tokens_long?: number;
|
|
99
125
|
}
|
|
100
126
|
export declare function terminalReasonForResult(msg: SDKMessage): TerminalReason | undefined;
|
|
127
|
+
export type { ResultLimitWord };
|
|
128
|
+
export declare function resultLimitOf(frame: object | null | undefined): ResultLimitWord | undefined;
|
|
129
|
+
export interface PrintResultLastRowBlock {
|
|
130
|
+
readonly type?: string;
|
|
131
|
+
readonly text?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface PrintResultLastRowMessage {
|
|
134
|
+
readonly content?: string | readonly PrintResultLastRowBlock[];
|
|
135
|
+
readonly stop_reason?: string | null;
|
|
136
|
+
}
|
|
137
|
+
export interface PrintResultLastRow {
|
|
138
|
+
readonly type?: string;
|
|
139
|
+
readonly _sema_api_error_message?: boolean;
|
|
140
|
+
readonly message?: PrintResultLastRowMessage;
|
|
141
|
+
readonly salvagedText?: string;
|
|
142
|
+
}
|
|
143
|
+
export interface PrintResultArmInput {
|
|
144
|
+
readonly terminal: RunTerminalRead | null;
|
|
145
|
+
readonly lastRow?: PrintResultLastRow | null;
|
|
146
|
+
}
|
|
147
|
+
export interface PrintResultSuccessArm {
|
|
148
|
+
readonly subtype: SDKResultSuccess['subtype'];
|
|
149
|
+
readonly is_error: boolean;
|
|
150
|
+
readonly stop_reason: SDKResultSuccess['stop_reason'];
|
|
151
|
+
}
|
|
152
|
+
export interface PrintResultErrorArm {
|
|
153
|
+
readonly subtype: SDKResultError['subtype'];
|
|
154
|
+
readonly is_error: true;
|
|
155
|
+
readonly stop_reason: SDKResultError['stop_reason'];
|
|
156
|
+
readonly limit?: ResultLimitWord;
|
|
157
|
+
}
|
|
158
|
+
export type PrintResultArm = PrintResultSuccessArm | PrintResultErrorArm;
|
|
159
|
+
export declare function printResultArmOf(input: PrintResultArmInput | null | undefined): PrintResultArm;
|
|
101
160
|
export declare function doneToSdkResult(ev: Extract<AgentEvent, {
|
|
102
161
|
type: 'done';
|
|
103
162
|
}>, ctx: EmitContext, observed?: TerminalStreamObserved): SDKMessage;
|
|
@@ -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,
|
|
@@ -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>;
|