@sema-agent/client-core 0.97.1 → 0.99.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 +607 -0
- package/README.md +96 -46
- package/dist/adapt/arms.d.ts +1 -0
- package/dist/adapt/arms.js +188 -53
- package/dist/adapt/ids.d.ts +12 -1
- package/dist/adapt/ids.js +59 -8
- package/dist/adapt/instanceLedger.d.ts +50 -0
- package/dist/adapt/instanceLedger.js +147 -0
- package/dist/adapt/panelTasks.d.ts +1 -1
- package/dist/adapt/panelTasks.js +2 -2
- package/dist/adapt/textStream.d.ts +1 -0
- package/dist/adapt/textStream.js +24 -7
- package/dist/adapt/toolCards.d.ts +27 -5
- package/dist/adapt/toolCards.js +39 -6
- package/dist/adapt/wireShapes.js +6 -2
- package/dist/adapt.d.ts +2 -0
- package/dist/adapt.js +8 -3
- package/dist/adapter/activeRunSelfHeal.d.ts +9 -3
- package/dist/adapter/activeRunSelfHeal.js +205 -313
- package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
- package/dist/adapter/downstream/eventToSdkMessage.js +77 -36
- package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
- package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
- package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
- package/dist/adapter/runStream.js +79 -48
- package/dist/adapter/types.d.ts +4 -4
- package/dist/adapter/types.js +2 -1
- package/dist/agentSession/backgroundView.js +2 -1
- package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
- package/dist/agentSession/engineAgentRegistryRead.js +12 -13
- package/dist/agentSession/engineSessionBackgroundStop.js +16 -8
- package/dist/agentsWireCaps.d.ts +8 -11
- package/dist/agentsWireCaps.js +196 -194
- package/dist/approvalDecidedByCapability.d.ts +0 -4
- package/dist/approvalDecidedByCapability.js +0 -6
- package/dist/approvalsStreamLiveCapability.d.ts +0 -4
- package/dist/approvalsStreamLiveCapability.js +0 -6
- package/dist/assistantInbox.d.ts +34 -0
- package/dist/assistantInbox.js +118 -0
- package/dist/centerWiringCapability.js +9 -1
- package/dist/clientSlice.d.ts +0 -9
- package/dist/clientSlice.js +0 -3
- package/dist/cloudConfigWireCaps.d.ts +5 -3
- package/dist/cloudConfigWireCaps.js +106 -64
- package/dist/compensations.js +1 -1
- package/dist/connectorStatus.d.ts +21 -0
- package/dist/connectorStatus.js +112 -0
- package/dist/controlRouter.d.ts +18 -3
- package/dist/controlRouter.js +106 -67
- package/dist/coreValuePorts.d.ts +29 -4
- package/dist/coreValuePorts.js +10 -0
- package/dist/corruptSessionCopy.d.ts +2 -1
- package/dist/corruptSessionCopy.js +3 -3
- package/dist/decideReceipt.d.ts +2 -2
- package/dist/decideReceipt.js +5 -2
- package/dist/declared/supportFloorDeclared.js +3 -3
- package/dist/detachWire.js +3 -2
- package/dist/deviceExecutorManagementCapability.d.ts +0 -4
- package/dist/deviceExecutorManagementCapability.js +0 -6
- package/dist/deviceRebind.d.ts +49 -1
- package/dist/deviceRebind.js +221 -3
- package/dist/devicesFace.d.ts +34 -0
- package/dist/devicesFace.js +90 -0
- package/dist/displayUntrusted.d.ts +2 -0
- package/dist/displayUntrusted.js +253 -76
- package/dist/engineAgentAbsence.d.ts +1 -1
- package/dist/engineAgentPanelStore.d.ts +12 -4
- package/dist/engineAgentPanelStore.js +16 -11
- package/dist/engineCapReader.d.ts +2 -5
- package/dist/engineCapReader.js +8 -10
- package/dist/engineCapsCache.d.ts +12 -0
- package/dist/engineCapsCache.js +76 -18
- package/dist/engineCapsChange.d.ts +2 -0
- package/dist/engineCapsChange.js +9 -0
- package/dist/engineClosedSets.d.ts +1 -0
- package/dist/engineClosedSets.js +4 -1
- package/dist/engineErrorCodes.d.ts +11 -3
- package/dist/engineErrorCodes.js +11 -8
- package/dist/engineIdentity.d.ts +1 -0
- package/dist/engineIdentity.js +8 -0
- package/dist/engineRowRef.d.ts +28 -0
- package/dist/engineRowRef.js +114 -0
- package/dist/engineSessionMessages.d.ts +68 -0
- package/dist/engineSessionMessages.js +370 -0
- package/dist/engineTargetSeat.d.ts +27 -0
- package/dist/engineTargetSeat.js +199 -0
- package/dist/engineToolDirectory.d.ts +0 -9
- package/dist/engineToolDirectory.js +1 -94
- package/dist/engineUrl.d.ts +18 -0
- package/dist/engineUrl.js +52 -0
- package/dist/engineWireFor.js +3 -8
- package/dist/env/uiLanguage.d.ts +11 -1
- package/dist/env/uiLanguage.js +38 -2
- package/dist/eventLeg.d.ts +100 -0
- package/dist/eventLeg.js +305 -0
- package/dist/executionLaneCapability.d.ts +0 -4
- package/dist/executionLaneCapability.js +3 -16
- package/dist/fileHistoryCaptureCapability.d.ts +2 -5
- package/dist/fileHistoryCaptureCapability.js +13 -21
- package/dist/fileHistoryLegNotice.d.ts +2 -1
- package/dist/fileHistoryLegNotice.js +3 -3
- package/dist/fleet/fleetLedger.d.ts +0 -3
- package/dist/fleet/fleetLedger.js +21 -36
- package/dist/fleet/fleetProjection.d.ts +2 -2
- package/dist/fleet/fleetProjection.js +10 -8
- package/dist/frameBinding.d.ts +8 -0
- package/dist/frameBinding.js +35 -0
- package/dist/gateFailureCodes.d.ts +2 -0
- package/dist/gateFailureCodes.js +15 -0
- package/dist/gateOutcome.d.ts +3 -1
- package/dist/gateOutcome.js +41 -8
- package/dist/gateVocabulary.d.ts +10 -4
- package/dist/gateVocabulary.js +107 -47
- package/dist/generated/engineAskFaceTables.js +2 -2
- package/dist/generated/engineFactTables.d.ts +22 -3
- package/dist/generated/engineFactTables.js +51 -4
- package/dist/generated/engineNoticeTables.js +18 -3
- package/dist/generated/settingsSchemaFns.d.ts +6 -0
- package/dist/generated/settingsSchemaFns.js +57 -0
- package/dist/generated/settingsSchemaHooksClassifier.d.ts +2 -0
- package/dist/generated/settingsSchemaHooksClassifier.js +254 -0
- package/dist/generated/settingsSchemaTables.d.ts +1 -0
- package/dist/generated/settingsSchemaTables.js +4 -0
- package/dist/generated/settingsSchemaTypes.d.ts +105 -0
- package/dist/generated/settingsSchemaTypes.js +1 -0
- package/dist/generated/toolNameTables.d.ts +1 -0
- package/dist/generated/toolNameTables.js +1 -0
- package/dist/hitl/allowRuleShadow.d.ts +8 -2
- package/dist/hitl/allowRuleShadow.js +36 -29
- package/dist/hitl/approvalCardReading.d.ts +15 -0
- package/dist/hitl/approvalCardReading.js +154 -0
- package/dist/hitl/approvalCardReasons.d.ts +14 -0
- package/dist/hitl/approvalCardReasons.js +119 -0
- package/dist/hitl/approvalHolds.d.ts +50 -15
- package/dist/hitl/approvalHolds.js +177 -27
- package/dist/hitl/approvalResolution.d.ts +51 -26
- package/dist/hitl/approvalResolution.js +86 -122
- package/dist/hitl/approvalsFeed.js +6 -18
- package/dist/hitl/askClassPair.d.ts +2 -0
- package/dist/hitl/askClassPair.js +17 -0
- package/dist/hitl/askGateWire.d.ts +20 -2
- package/dist/hitl/askGateWire.js +50 -1
- package/dist/hitl/askParkRowRouting.d.ts +5 -0
- package/dist/hitl/askParkRowRouting.js +32 -1
- package/dist/hitl/askSettlementLine.d.ts +28 -0
- package/dist/hitl/askSettlementLine.js +99 -0
- package/dist/hitl/automaticAnswerVerdict.d.ts +3 -2
- package/dist/hitl/automaticAnswerVerdict.js +29 -13
- package/dist/hitl/crashConverged.d.ts +11 -20
- package/dist/hitl/crashConverged.js +56 -0
- package/dist/hitl/crashConvergedNotice.d.ts +6 -3
- package/dist/hitl/crashConvergedNotice.js +48 -24
- package/dist/hitl/decisionConflict.js +3 -10
- package/dist/hitl/decisionRefusal.d.ts +40 -1
- package/dist/hitl/decisionRefusal.js +199 -42
- package/dist/hitl/frameRouter.d.ts +5 -2
- package/dist/hitl/frameRouter.js +27 -24
- package/dist/hitl/gateLedger.d.ts +2 -0
- package/dist/hitl/gateLedger.js +50 -13
- package/dist/hitl/hitlBridge.d.ts +2 -2
- package/dist/hitl/hitlBridge.js +13 -10
- package/dist/hitl/livePendingAsk.d.ts +3 -3
- package/dist/hitl/livePendingAsk.js +7 -18
- package/dist/hitl/parkResolver.d.ts +2 -24
- package/dist/hitl/parkResolver.js +61 -97
- package/dist/hitl/persistedRulesWire.d.ts +25 -0
- package/dist/hitl/persistedRulesWire.js +104 -2
- package/dist/hitl/planReviewWire.d.ts +31 -13
- package/dist/hitl/planReviewWire.js +120 -78
- package/dist/hitl/refusedToolNameProse.d.ts +0 -1
- package/dist/hitl/refusedToolNameProse.js +0 -3
- package/dist/hitl/replayedApproval.d.ts +4 -3
- package/dist/hitl/replayedApproval.js +7 -4
- package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
- package/dist/hitl/sessionPolicyDeliverable.js +48 -7
- package/dist/hitl/sessionPolicyWire.d.ts +34 -21
- package/dist/hitl/sessionPolicyWire.js +179 -70
- package/dist/hitl/standingRows.d.ts +20 -2
- package/dist/hitl/standingRows.js +69 -8
- package/dist/hitl/suspendedReopen.d.ts +2 -1
- package/dist/hitl/suspendedReopen.js +7 -10
- package/dist/hitl/toolApprovalWire.d.ts +103 -156
- package/dist/hitl/toolApprovalWire.js +661 -411
- package/dist/hookMatcherVerdict.d.ts +6 -1
- package/dist/hookMatcherVerdict.js +14 -7
- package/dist/hooksWireCaps.d.ts +2 -2
- package/dist/hooksWireCaps.js +174 -81
- package/dist/host.d.ts +21 -0
- package/dist/hostTurnSettings.d.ts +71 -0
- package/dist/hostTurnSettings.js +291 -0
- package/dist/humanTurn.d.ts +14 -1
- package/dist/humanTurn.js +100 -12
- package/dist/humanTurnRead.d.ts +2 -0
- package/dist/humanTurnRead.js +22 -1
- package/dist/i18n/messages.en.d.ts +703 -0
- package/dist/i18n/messages.en.js +701 -0
- package/dist/i18n/messages.zh.d.ts +3 -0
- package/dist/i18n/messages.zh.js +837 -0
- package/dist/i18n/translate.d.ts +25 -0
- package/dist/i18n/translate.js +127 -0
- package/dist/index.d.ts +78 -29
- package/dist/index.js +54 -18
- package/dist/inheritEnvCapability.d.ts +32 -0
- package/dist/inheritEnvCapability.js +104 -0
- package/dist/inheritEnvWire.d.ts +3 -2
- package/dist/inheritEnvWire.js +12 -14
- package/dist/interactiveHalt.js +17 -6
- package/dist/liveModelCatalog.d.ts +3 -3
- package/dist/liveModelCatalog.js +15 -13
- package/dist/liveQuestionStore.d.ts +2 -21
- package/dist/mcpLiveness.d.ts +2 -1
- package/dist/mcpPanel.d.ts +10 -1
- package/dist/mcpPanel.js +40 -13
- package/dist/mcpProbeCapability.d.ts +2 -1
- package/dist/mcpProbeCapability.js +7 -11
- package/dist/mcpProbeWire.d.ts +9 -2
- package/dist/mcpProbeWire.js +6 -1
- package/dist/mcpWireCaps.d.ts +47 -2
- package/dist/mcpWireCaps.js +164 -16
- package/dist/memoryEntriesWire.d.ts +4 -9
- package/dist/memoryEntriesWire.js +5 -10
- package/dist/model/modelSupplyRules.d.ts +0 -2
- package/dist/model/modelSupplyRules.js +3 -12
- package/dist/model/modelsPolicy.d.ts +0 -5
- package/dist/model/modelsPolicy.js +6 -36
- package/dist/model/onboardJudgement.d.ts +93 -0
- package/dist/model/onboardJudgement.js +415 -0
- package/dist/model/subagentModelWord.d.ts +31 -0
- package/dist/model/subagentModelWord.js +261 -0
- package/dist/model/tierVocabulary.d.ts +2 -0
- package/dist/model/tierVocabulary.js +17 -5
- package/dist/modelCapabilityProbe.d.ts +64 -0
- package/dist/modelCapabilityProbe.js +600 -0
- package/dist/modelIdentityResolvability.d.ts +3 -0
- package/dist/modelIdentityResolvability.js +26 -17
- package/dist/notifications.d.ts +6 -0
- package/dist/notifications.js +71 -23
- package/dist/outputStyleSeatCapability.d.ts +0 -3
- package/dist/outputStyleSeatCapability.js +0 -3
- package/dist/ownKey.d.ts +22 -0
- package/dist/ownKey.js +94 -3
- package/dist/panelReduce.d.ts +21 -10
- package/dist/panelReduce.js +728 -550
- package/dist/panelStateHolder.d.ts +3 -7
- package/dist/panelStateHolder.js +14 -130
- package/dist/peerLaneCapability.d.ts +0 -4
- package/dist/peerLaneCapability.js +0 -6
- package/dist/permissionRuleIssue.js +2 -0
- package/dist/permissionRulesWriteCapability.d.ts +2 -5
- package/dist/permissionRulesWriteCapability.js +8 -12
- package/dist/permissionWireCaps.d.ts +2 -2
- package/dist/permissionWireCaps.js +2 -0
- package/dist/permissionsAllowGrantCapability.d.ts +0 -4
- package/dist/permissionsAllowGrantCapability.js +0 -6
- package/dist/permissionsDeclaration.d.ts +0 -11
- package/dist/permissionsDeclaration.js +60 -53
- package/dist/pluginHooksWire.d.ts +46 -3
- package/dist/pluginHooksWire.js +219 -16
- package/dist/preemptWire.d.ts +44 -0
- package/dist/preemptWire.js +83 -0
- package/dist/printModelStatus.d.ts +63 -0
- package/dist/printModelStatus.js +155 -0
- package/dist/printToolResultFrame.js +15 -4
- package/dist/replayBody.d.ts +3 -0
- package/dist/replayBody.js +14 -0
- package/dist/request/taskRequest.d.ts +11 -6
- package/dist/request/taskRequest.js +112 -19
- package/dist/resumeRefusalCopy.d.ts +13 -9
- package/dist/resumeRefusalCopy.js +81 -118
- package/dist/retryStatus.d.ts +45 -0
- package/dist/retryStatus.js +185 -1
- package/dist/rewindArchiveCapability.d.ts +0 -4
- package/dist/rewindArchiveCapability.js +2 -10
- package/dist/rewindArchiveReading.d.ts +0 -1
- package/dist/rewindArchiveReading.js +0 -3
- package/dist/runCancelContext.d.ts +2 -1
- package/dist/runCancelContext.js +4 -2
- package/dist/runReattachPolicy.d.ts +31 -0
- package/dist/runReattachPolicy.js +46 -0
- package/dist/runTerminal.d.ts +3 -6
- package/dist/runTerminal.js +8 -9
- package/dist/sandboxWire.d.ts +3 -1
- package/dist/sandboxWire.js +76 -27
- package/dist/scenarioRefusal.d.ts +9 -0
- package/dist/scenarioRefusal.js +111 -0
- package/dist/scenarioWire.js +1 -1
- package/dist/seam.d.ts +48 -2
- package/dist/seam.js +25 -4
- package/dist/seatContract.d.ts +311 -18
- package/dist/seatContract.js +824 -100
- package/dist/selfOrchestrationDenial.js +7 -19
- package/dist/sessionIdSegment.d.ts +6 -0
- package/dist/sessionIdSegment.js +24 -0
- package/dist/sessionMemoryStatus.js +6 -11
- package/dist/sessionPolicyCapability.d.ts +2 -5
- package/dist/sessionPolicyCapability.js +8 -12
- package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
- package/dist/sessionSyncFileHistoryCapability.js +0 -3
- package/dist/settingsHooksSalvage.d.ts +44 -0
- package/dist/settingsHooksSalvage.js +211 -0
- package/dist/skillToolListsCapability.d.ts +2 -4
- package/dist/skillToolListsCapability.js +8 -9
- package/dist/sqlEngineCapability.d.ts +0 -4
- package/dist/sqlEngineCapability.js +0 -6
- package/dist/sseIdleTriage.js +3 -2
- package/dist/steerPriorityCapability.d.ts +0 -3
- package/dist/steerPriorityCapability.js +0 -3
- package/dist/streamDrainingLegs.d.ts +4 -0
- package/dist/streamDrainingLegs.js +6 -1
- package/dist/subagent/engineCompactWire.d.ts +0 -1
- package/dist/subagent/engineCompactWire.js +7 -5
- package/dist/subagent/engineSubagentResume.js +15 -9
- package/dist/subagent/engineTaskHandleWire.js +4 -7
- package/dist/subagentContentStore.d.ts +3 -0
- package/dist/subagentContentStore.js +22 -10
- package/dist/submitReopen.d.ts +24 -0
- package/dist/submitReopen.js +75 -0
- package/dist/terminalStatuses.d.ts +3 -0
- package/dist/terminalStatuses.js +10 -2
- package/dist/toolHistoryMismatch.js +3 -2
- package/dist/toolResult.d.ts +10 -1
- package/dist/toolResult.js +34 -6
- package/dist/toolRoster.d.ts +3 -4
- package/dist/toolRoster.js +21 -22
- package/dist/turnFailurePresentation.d.ts +39 -0
- package/dist/turnFailurePresentation.js +402 -0
- package/dist/usageAnalytics.js +6 -11
- package/dist/userAttachmentEnvelope.d.ts +1 -0
- package/dist/userAttachmentEnvelope.js +37 -7
- package/dist/userAttachmentSeat.d.ts +21 -0
- package/dist/userAttachmentSeat.js +75 -0
- package/dist/userInvokedSkillsCapability.d.ts +11 -4
- package/dist/userInvokedSkillsCapability.js +31 -10
- package/dist/webSearchBackendCapability.d.ts +0 -4
- package/dist/webSearchBackendCapability.js +0 -6
- package/dist/wireErrorTriage.d.ts +7 -0
- package/dist/wireErrorTriage.js +26 -23
- package/dist/wireFailureShape.d.ts +62 -5
- package/dist/wireFailureShape.js +106 -5
- package/dist/wireRefusalCopy.d.ts +25 -3
- package/dist/wireRefusalCopy.js +74 -80
- package/dist/workflowsJournalCapability.d.ts +2 -5
- package/dist/workflowsJournalCapability.js +8 -12
- package/dist/writeProtectionCapability.d.ts +0 -4
- package/dist/writeProtectionCapability.js +0 -6
- package/docs/INTEGRATION-CLIENTS.md +1775 -56
- package/package.json +6 -5
- package/dist/attachmentSeatCapability.d.ts +0 -12
- package/dist/attachmentSeatCapability.js +0 -23
- package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
- package/dist/hitl/approvalOutcomeNote.js +0 -29
- package/dist/sessionReadRedactionCapability.d.ts +0 -13
- package/dist/sessionReadRedactionCapability.js +0 -35
|
@@ -2,6 +2,7 @@ import type { AgentEvent, CheckpointGate, TaskResult } from '@sema-agent/sdk';
|
|
|
2
2
|
import { type WiringManifestView } from './wiringManifestView.js';
|
|
3
3
|
import { type SDKMessage, type EmitContext, type ModelUsage } from '../types.js';
|
|
4
4
|
import { type McpLivenessView } from '../../mcpLiveness.js';
|
|
5
|
+
import { type ContextUsageSectionRow } from '../../ownKey.js';
|
|
5
6
|
export declare const INTERNAL_SDK_ARM_TYPES: ReadonlySet<string>;
|
|
6
7
|
export type EventProjectionNoneReason = 'usage_only' | 'terminal_delegated' | 'hitl_out_of_slice' | 'not_in_slice' | 'empty_payload';
|
|
7
8
|
export type EventProjectionDropReason = 'malformed' | 'unknown_arm' | 'unsupported_arm';
|
|
@@ -66,11 +67,7 @@ export interface WiringManifestLspSeamView {
|
|
|
66
67
|
mounted: boolean;
|
|
67
68
|
lane?: string;
|
|
68
69
|
}
|
|
69
|
-
export
|
|
70
|
-
id: string;
|
|
71
|
-
tokens: number;
|
|
72
|
-
kind?: string;
|
|
73
|
-
}
|
|
70
|
+
export type ContextUsageSectionView = ContextUsageSectionRow;
|
|
74
71
|
export interface PromptManifestSectionView {
|
|
75
72
|
id: string;
|
|
76
73
|
chars: number;
|
|
@@ -5,10 +5,11 @@ 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 { markMcpSectionDroppedNamedRows, readFrameTrueMark } from '../../ownKey.js';
|
|
9
|
-
import { SEGMENT_END_IDENTITY_KEYS, stripToolUseSideChannels } from '../types.js';
|
|
8
|
+
import { contextUsageReadingOf, humanInputAttachmentsOf, markMcpSectionDroppedNamedRows, readFrameTrueMark } from '../../ownKey.js';
|
|
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';
|
|
12
|
+
import { envelopeUuidOf, mintEngineRowRef, readBoundRun, wireEventIdOf } from '../../engineRowRef.js';
|
|
12
13
|
function armBody(body) {
|
|
13
14
|
return body;
|
|
14
15
|
}
|
|
@@ -23,8 +24,10 @@ export const INTERNAL_SDK_ARM_TYPES = frozenSet([
|
|
|
23
24
|
'prompt_assembled',
|
|
24
25
|
'workflow_complete',
|
|
25
26
|
'tool_end_result',
|
|
27
|
+
'terminal_fact',
|
|
26
28
|
'retry_status',
|
|
27
29
|
'task_progress',
|
|
30
|
+
'task_started',
|
|
28
31
|
'task_notification',
|
|
29
32
|
'diagnostics',
|
|
30
33
|
'steering_injected',
|
|
@@ -69,7 +72,22 @@ const dropped = (why, type) => ({ kind: 'dropped', why, type });
|
|
|
69
72
|
function assertNeverArm(_ev) {
|
|
70
73
|
}
|
|
71
74
|
export function eventToSdkMessage(ev, ctx) {
|
|
75
|
+
return withEngineIdentity(projectEvent(ev, ctx), ev, ctx);
|
|
76
|
+
}
|
|
77
|
+
function withEngineIdentity(p, ev, ctx) {
|
|
78
|
+
if (p.kind !== 'message')
|
|
79
|
+
return p;
|
|
80
|
+
const eventId = wireEventIdOf(ev);
|
|
81
|
+
if (eventId === undefined)
|
|
82
|
+
return p;
|
|
83
|
+
const env = p.message;
|
|
84
|
+
const ref = mintEngineRowRef(eventId, ctx.boundRun === undefined ? undefined : readBoundRun(() => ctx.boundRun?.(ev)));
|
|
85
|
+
return projected(Object.assign({}, env, { uuid: envelopeUuidOf(eventId, env.type), _sema_engine_ref: ref }));
|
|
86
|
+
}
|
|
87
|
+
function projectEvent(ev, ctx) {
|
|
72
88
|
switch (ev.type) {
|
|
89
|
+
case 'task_started':
|
|
90
|
+
return taskStartedProjection(ev, ctx);
|
|
73
91
|
case 'text_end':
|
|
74
92
|
return textEndProjection(ev, ctx);
|
|
75
93
|
case 'reasoning_end':
|
|
@@ -178,7 +196,6 @@ export function eventToSdkMessage(ev, ctx) {
|
|
|
178
196
|
const toolEndGatedCallId = ev.gatedCallId;
|
|
179
197
|
const collateralAbort = ev._sema_collateral_abort;
|
|
180
198
|
const denialKind = ccToolDenialKindForToolEnd(ev);
|
|
181
|
-
const denialUnclassified = denialKind === undefined && toolEndGate?.disposition.kind === 'denied';
|
|
182
199
|
const toolEndNotExecuted = readFrameTrueMark(ev, 'notExecuted');
|
|
183
200
|
return projected(stamp(ctx, armBody({
|
|
184
201
|
type: 'tool_end_result',
|
|
@@ -201,7 +218,6 @@ export function eventToSdkMessage(ev, ctx) {
|
|
|
201
218
|
: {}),
|
|
202
219
|
...(collateralAbort === true ? { _sema_collateral_abort: true } : {}),
|
|
203
220
|
...(denialKind !== undefined ? { _sema_denial_kind: denialKind } : {}),
|
|
204
|
-
...(denialUnclassified ? { _sema_denial_unclassified: true } : {}),
|
|
205
221
|
...(toolEndNotExecuted ? { notExecuted: true } : {}),
|
|
206
222
|
...(ev.eventId !== undefined ? { eventId: ev.eventId } : {}),
|
|
207
223
|
...(ev.parentToolCallId !== undefined
|
|
@@ -210,19 +226,18 @@ export function eventToSdkMessage(ev, ctx) {
|
|
|
210
226
|
})));
|
|
211
227
|
}
|
|
212
228
|
case 'status': {
|
|
213
|
-
const st2 = ev;
|
|
214
229
|
const num = (v) => typeof v === 'number' && Number.isFinite(v) ? v : undefined;
|
|
215
230
|
const attempt = num(ev.attempt);
|
|
216
231
|
const maxRetries = num(ev.maxRetries);
|
|
217
232
|
const retryInMs = num(ev.retryInMs);
|
|
218
|
-
const retryAtMs = num(
|
|
219
|
-
const errorStatus = num(
|
|
220
|
-
const elapsedMs = num(
|
|
221
|
-
const timeoutMs = num(
|
|
233
|
+
const retryAtMs = num(ev.retryAtMs);
|
|
234
|
+
const errorStatus = num(ev.errorStatus);
|
|
235
|
+
const elapsedMs = num(ev.elapsedMs);
|
|
236
|
+
const timeoutMs = num(ev.timeoutMs);
|
|
222
237
|
const errClass = typeof ev.errClass === 'string' && ev.errClass.length > 0 ? ev.errClass : undefined;
|
|
223
238
|
const nonEmptyStr = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
|
|
224
|
-
const providerCondition = nonEmptyStr(
|
|
225
|
-
const providerConditionSource = nonEmptyStr(
|
|
239
|
+
const providerCondition = nonEmptyStr(ev.providerCondition);
|
|
240
|
+
const providerConditionSource = nonEmptyStr(ev.providerConditionSource);
|
|
226
241
|
return projected(stamp(ctx, armBody({
|
|
227
242
|
type: 'retry_status',
|
|
228
243
|
phase: ev.phase,
|
|
@@ -648,33 +663,54 @@ function contextUsageProjection(ev, ctx) {
|
|
|
648
663
|
const { identity, bad } = identityOrMalformed(ev, 'context_usage');
|
|
649
664
|
if (bad !== null)
|
|
650
665
|
return bad;
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
const windowTokens = fin(ev.windowTokens);
|
|
654
|
-
const compactAtTokens = fin(ev.compactAtTokens);
|
|
655
|
-
let sections;
|
|
656
|
-
if (Array.isArray(ev.sections)) {
|
|
657
|
-
const rows = [];
|
|
658
|
-
for (const r of ev.sections) {
|
|
659
|
-
if (typeof r !== 'object' || r === null || Array.isArray(r))
|
|
660
|
-
continue;
|
|
661
|
-
const o = r;
|
|
662
|
-
const tokens = fin(o.tokens);
|
|
663
|
-
if (typeof o.id !== 'string' || o.id.length === 0 || tokens === undefined)
|
|
664
|
-
continue;
|
|
665
|
-
rows.push({ id: o.id, tokens, ...(typeof o.kind === 'string' && o.kind.length > 0 ? { kind: o.kind } : {}) });
|
|
666
|
-
}
|
|
667
|
-
if (rows.length > 0)
|
|
668
|
-
sections = rows;
|
|
669
|
-
}
|
|
670
|
-
if (usedTokens === undefined && windowTokens === undefined && compactAtTokens === undefined && sections === undefined)
|
|
666
|
+
const reading = contextUsageReadingOf(ev);
|
|
667
|
+
if (reading === undefined)
|
|
671
668
|
return nothing('empty_payload');
|
|
672
669
|
return projected(internalArmExit(stamp(ctx, armBody({
|
|
673
670
|
type: 'context_usage',
|
|
674
|
-
...
|
|
675
|
-
...
|
|
676
|
-
|
|
677
|
-
|
|
671
|
+
...reading,
|
|
672
|
+
...identity,
|
|
673
|
+
}))));
|
|
674
|
+
}
|
|
675
|
+
function taskStartedProjection(frame, ctx) {
|
|
676
|
+
const ev = frame;
|
|
677
|
+
const { identity, bad } = identityOrMalformed(ev, 'task_started');
|
|
678
|
+
if (bad !== null)
|
|
679
|
+
return bad;
|
|
680
|
+
const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
|
|
681
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
|
|
682
|
+
const taskId = str(ev.taskId);
|
|
683
|
+
if (taskId === undefined)
|
|
684
|
+
return dropped('malformed', 'task_started');
|
|
685
|
+
const sessionId = str(ev.sessionId);
|
|
686
|
+
const model = str(ev.model);
|
|
687
|
+
const taskType = str(ev.taskType);
|
|
688
|
+
const seq = num(ev.seq);
|
|
689
|
+
const workflowRunId = str(ev.workflowRunId);
|
|
690
|
+
const workflowAgentLabel = str(ev.workflowAgentLabel);
|
|
691
|
+
const parentTaskId = str(ev.parentTaskId);
|
|
692
|
+
const parentSessionId = str(ev.parentSessionId);
|
|
693
|
+
const rootSessionId = str(ev.rootSessionId);
|
|
694
|
+
const name = str(ev.name);
|
|
695
|
+
const spawnName = str(ev.spawnName);
|
|
696
|
+
const agentType = str(ev.agentType);
|
|
697
|
+
const startedAt = num(ev.startedAt);
|
|
698
|
+
return projected(internalArmExit(stamp(ctx, armBody({
|
|
699
|
+
type: 'task_started',
|
|
700
|
+
taskId,
|
|
701
|
+
...(sessionId !== undefined ? { sessionId } : {}),
|
|
702
|
+
...(model !== undefined ? { model } : {}),
|
|
703
|
+
...(taskType !== undefined ? { taskType } : {}),
|
|
704
|
+
...(seq !== undefined ? { seq } : {}),
|
|
705
|
+
...(workflowRunId !== undefined ? { workflowRunId } : {}),
|
|
706
|
+
...(workflowAgentLabel !== undefined ? { workflowAgentLabel } : {}),
|
|
707
|
+
...(parentTaskId !== undefined ? { parentTaskId } : {}),
|
|
708
|
+
...(parentSessionId !== undefined ? { parentSessionId } : {}),
|
|
709
|
+
...(rootSessionId !== undefined ? { rootSessionId } : {}),
|
|
710
|
+
...(name !== undefined ? { name } : {}),
|
|
711
|
+
...(spawnName !== undefined ? { spawnName } : {}),
|
|
712
|
+
...(agentType !== undefined ? { agentType } : {}),
|
|
713
|
+
...(startedAt !== undefined ? { startedAt } : {}),
|
|
678
714
|
...identity,
|
|
679
715
|
}))));
|
|
680
716
|
}
|
|
@@ -774,6 +810,7 @@ function engineNoticeProjection(ev, ctx) {
|
|
|
774
810
|
const detail = typeof rawDetail === 'object' && rawDetail !== null && !Array.isArray(rawDetail)
|
|
775
811
|
? rawDetail
|
|
776
812
|
: {};
|
|
813
|
+
const seq = eventSeq(ev);
|
|
777
814
|
return projected(stamp(ctx, armBody({
|
|
778
815
|
type: 'engine_notice',
|
|
779
816
|
code,
|
|
@@ -782,7 +819,7 @@ function engineNoticeProjection(ev, ctx) {
|
|
|
782
819
|
...(sessionId !== undefined ? { sessionId } : {}),
|
|
783
820
|
...(ts !== undefined ? { ts } : {}),
|
|
784
821
|
...(typeof ev.eventId === 'string' && ev.eventId.length > 0 ? { eventId: ev.eventId } : {}),
|
|
785
|
-
...(
|
|
822
|
+
...(seq !== undefined ? { eventSeq: seq } : {}),
|
|
786
823
|
})));
|
|
787
824
|
}
|
|
788
825
|
function approvalFrameBody(ev) {
|
|
@@ -820,8 +857,12 @@ function humanInputProjection(ev, ctx) {
|
|
|
820
857
|
...(str(ev.entryId) !== undefined ? { entryId: str(ev.entryId) } : {}),
|
|
821
858
|
...(str(ev.eventId) !== undefined ? { eventId: str(ev.eventId) } : {}),
|
|
822
859
|
...(str(ev.parentToolCallId) !== undefined ? { parentToolCallId: str(ev.parentToolCallId) } : {}),
|
|
860
|
+
...attachmentsKey(humanInputAttachmentsOf(ev)),
|
|
823
861
|
})));
|
|
824
862
|
}
|
|
863
|
+
function attachmentsKey(rows) {
|
|
864
|
+
return rows !== undefined ? { attachments: rows } : {};
|
|
865
|
+
}
|
|
825
866
|
export function turnEndUsage(ev) {
|
|
826
867
|
const rawValue = ev.usage;
|
|
827
868
|
if (typeof rawValue !== 'object' || rawValue === null || Array.isArray(rawValue))
|
|
@@ -4,7 +4,8 @@ import { putOwnKey, readFrameStringKey } from '../../ownKey.js';
|
|
|
4
4
|
import { REDACTION_MARKER_PREFIX, washCredentials } from '../../displayUntrusted.js';
|
|
5
5
|
import { readEffectiveReasoning, readEffectiveMemoryScopes } from '../../effectiveFacts.js';
|
|
6
6
|
import { isReviewPark, readRunTerminal, runTerminalCode, runTerminalGateToolName, } from '../../runTerminal.js';
|
|
7
|
-
import { doneResultView } from '../../replayBody.js';
|
|
7
|
+
import { doneResultView, isReplayedTerminal } from '../../replayBody.js';
|
|
8
|
+
import { terminalRunIdOf, terminalUuidOf } from '../../engineRowRef.js';
|
|
8
9
|
import { toCcModelUsage } from './turnUsageToModelUsage.js';
|
|
9
10
|
import { LIMITS_MAX_COST_EXCEEDED, LIMITS_MAX_TOKENS_EXCEEDED, LIMITS_MAX_TURNS_EXCEEDED, LIMITS_MAX_WALLTIME_EXCEEDED, OUTPUT_INVALID, isCorruptSessionCode, idempotencyPayloadMismatchContent, isIdempotencyPayloadMismatchCode, isRewindFamilyCode, } from '../../engineErrorCodes.js';
|
|
10
11
|
import { corruptSessionContent } from '../../corruptSessionCopy.js';
|
|
@@ -497,7 +498,7 @@ function cutoffParts(r, message, fallbackMessage, code) {
|
|
|
497
498
|
}
|
|
498
499
|
function errorResult(ctx, parts) {
|
|
499
500
|
return stamp(ctx, {
|
|
500
|
-
uuid:
|
|
501
|
+
uuid: parts.uuid,
|
|
501
502
|
session_id: undefined,
|
|
502
503
|
type: 'result',
|
|
503
504
|
subtype: parts.subtype,
|
|
@@ -525,6 +526,10 @@ function errorResult(ctx, parts) {
|
|
|
525
526
|
});
|
|
526
527
|
}
|
|
527
528
|
export function doneToSdkResult(ev, ctx, observed) {
|
|
529
|
+
const msg = doneToSdkResultBody(ev, ctx, observed);
|
|
530
|
+
return isReplayedTerminal(ev) ? Object.assign({}, msg, { _sema_replay: true }) : msg;
|
|
531
|
+
}
|
|
532
|
+
function doneToSdkResultBody(ev, ctx, observed) {
|
|
528
533
|
const view = doneResultView(ev.result);
|
|
529
534
|
const rRaw = view.engine;
|
|
530
535
|
const rec = typeof rRaw === 'object' && rRaw !== null ? rRaw : {};
|
|
@@ -539,7 +544,9 @@ export function doneToSdkResult(ev, ctx, observed) {
|
|
|
539
544
|
const errorCode = runTerminalCode(terminal);
|
|
540
545
|
const degraded = degradedOf(r);
|
|
541
546
|
const parkFailedReason = readFrameStringKey(ev, '_sema_park_failed_reason');
|
|
542
|
-
const
|
|
547
|
+
const terminalRunId = terminalRunIdOf(ev);
|
|
548
|
+
const resultUuid = terminalRunId === undefined ? undefined : terminalUuidOf(terminalRunId, 'result');
|
|
549
|
+
const errorBase = { uuid: resultUuid, durationMs, stats, model: r.model, errorCode, degraded, observed, facts: effectiveFactParts(rec), parkFailedReason, abortCause: abortCauseWordOf(ev) };
|
|
543
550
|
if (terminal?.kind === 'failed') {
|
|
544
551
|
const failedCode = terminal.code;
|
|
545
552
|
const failedMessage = terminal.message;
|
|
@@ -613,7 +620,7 @@ export function doneToSdkResult(ev, ctx, observed) {
|
|
|
613
620
|
});
|
|
614
621
|
}
|
|
615
622
|
return stamp(ctx, {
|
|
616
|
-
uuid:
|
|
623
|
+
uuid: resultUuid,
|
|
617
624
|
session_id: undefined,
|
|
618
625
|
type: 'result',
|
|
619
626
|
subtype: 'success',
|
|
@@ -12,10 +12,13 @@ export interface EngineUsageLike {
|
|
|
12
12
|
readonly costMicroUsd?: number | undefined;
|
|
13
13
|
readonly webSearchRequests?: number | undefined;
|
|
14
14
|
}
|
|
15
|
-
export type SemaModelUsage = ModelUsage &
|
|
15
|
+
export type SemaModelUsage = ModelUsage & SemaModelUsageAbsenceBits;
|
|
16
|
+
export interface SemaModelUsageAbsenceBits {
|
|
16
17
|
readonly _sema_cost_absent?: true;
|
|
17
18
|
readonly _sema_web_search_requests_absent?: true;
|
|
18
|
-
|
|
19
|
+
readonly _sema_context_window_absent?: true;
|
|
20
|
+
readonly _sema_max_output_tokens_absent?: true;
|
|
21
|
+
}
|
|
19
22
|
export declare function toCcModelUsage(raw: EngineUsageLike): SemaModelUsage;
|
|
20
23
|
export declare function turnUsageToModelUsage(usage: TurnUsage): SemaModelUsage;
|
|
21
24
|
export {};
|
|
@@ -15,6 +15,8 @@ export function toCcModelUsage(raw) {
|
|
|
15
15
|
maxOutputTokens: 0,
|
|
16
16
|
...(costPriced ? {} : { _sema_cost_absent: true }),
|
|
17
17
|
...(webSearchKnown ? {} : { _sema_web_search_requests_absent: true }),
|
|
18
|
+
_sema_context_window_absent: true,
|
|
19
|
+
_sema_max_output_tokens_absent: true,
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
export function turnUsageToModelUsage(usage) {
|
|
@@ -2,19 +2,36 @@ import { eventSeq, stamp, } from './types.js';
|
|
|
2
2
|
import { eventToSdkMessage, turnEndUsage } from './downstream/eventToSdkMessage.js';
|
|
3
3
|
import { turnUsageToModelUsage } from './downstream/turnUsageToModelUsage.js';
|
|
4
4
|
import { readRunCostFacts, terminalToSdkResult, TOOL_INPUT_JOIN_MAX_CALLS } from './downstream/terminalToSdkResult.js';
|
|
5
|
-
import {
|
|
5
|
+
import { terminalRunIdOf, terminalUuidOf } from '../engineRowRef.js';
|
|
6
|
+
import { publishSubagentContentEvent, subagentContentEventOf } from '../subagentContentStore.js';
|
|
6
7
|
import { OUTPUT_INVALID, activeRunBusyCarrierOf, classifyActiveRunBusy, isCorruptSessionCode, isLimitsExceededCode } from '../engineErrorCodes.js';
|
|
7
|
-
import { doneResultView } from '../replayBody.js';
|
|
8
|
+
import { doneResultView, isReplayedTerminal } from '../replayBody.js';
|
|
9
|
+
import { readFrameStringKey } from '../ownKey.js';
|
|
8
10
|
import { corruptSessionContent } from '../corruptSessionCopy.js';
|
|
9
11
|
import { abortCauseNoteOf } from '../runCancelContext.js';
|
|
10
12
|
import { classifyToolHistoryMismatch, noteToolHistoryTerminal, openToolHistoryGeneration, TOOL_HISTORY_REWIND_SENTENCE, toolHistoryMismatchRowKey, toolHistoryRepeatSentence, toolHistoryRewindOffered, } from '../toolHistoryMismatch.js';
|
|
11
13
|
import { isReviewPark, readRunTerminal, runTerminalCode } from '../runTerminal.js';
|
|
14
|
+
import { parkHeldCallIdOf } from '../engineRowRef.js';
|
|
12
15
|
import { providerRejectionResend } from '../providerRejection.js';
|
|
13
|
-
import { washCredentials } from '../displayUntrusted.js';
|
|
16
|
+
import { displayUntrusted, washCredentials } from '../displayUntrusted.js';
|
|
14
17
|
import { PROMPT_BLOCKED_BY_HOOK_ROW_LEAD, runBlockedText } from '../promptBlockedCopy.js';
|
|
15
18
|
import { ccToolDenialKindForToolEnd, gateDeniedBy, gateOutcomeOf } from '../gateOutcome.js';
|
|
16
19
|
import { resumeReopenContent, resumeReopenFromError, suspendedReopenOf } from '../hitl/suspendedReopen.js';
|
|
17
20
|
import { isCcToolDenialKind, isCcToolDenialKindADenial, isGateDeniedByWord } from '../gateVocabulary.js';
|
|
21
|
+
const ENGINE_TURN_USAGE_KEYS = Object.freeze(['inputTokens', 'totalInputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens', 'costMicroUsd']);
|
|
22
|
+
const _engineTurnUsageKeysPin = true;
|
|
23
|
+
void _engineTurnUsageKeysPin;
|
|
24
|
+
function closedEngineTurnUsage(raw) {
|
|
25
|
+
const out = {};
|
|
26
|
+
let unknownKeys = 0;
|
|
27
|
+
for (const k of Object.keys(raw)) {
|
|
28
|
+
if (ENGINE_TURN_USAGE_KEYS.includes(k))
|
|
29
|
+
out[k] = raw[k];
|
|
30
|
+
else
|
|
31
|
+
unknownKeys++;
|
|
32
|
+
}
|
|
33
|
+
return { usage: out, unknownKeys };
|
|
34
|
+
}
|
|
18
35
|
const mainLane = () => ({ lane: 'main' });
|
|
19
36
|
function emitChromeFireAndForget(ctx, event) {
|
|
20
37
|
try {
|
|
@@ -108,9 +125,25 @@ export function isModelOutputErrorRowText(text) {
|
|
|
108
125
|
return text.trimStart().startsWith(`${MODEL_OUTPUT_ERROR_PREFIX}:`);
|
|
109
126
|
}
|
|
110
127
|
export const OUTCOME_UNKNOWN_ROW_PREFIX = 'Outcome unknown';
|
|
111
|
-
function
|
|
128
|
+
function apiErrorRowBitsOf(read) {
|
|
129
|
+
try {
|
|
130
|
+
const status = read.carrier.status;
|
|
131
|
+
const providerCondition = read.detail !== undefined && ownDataBit(read.detail, 'kind') === PROVIDER_REJECTED_DETAIL ? nonEmptyStr(ownDataBit(read.detail, 'providerCondition')) : undefined;
|
|
132
|
+
const errorCode = nonEmptyStr(read.carrier.code);
|
|
133
|
+
const bits = {
|
|
134
|
+
...(typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 999 ? { status } : {}),
|
|
135
|
+
...(providerCondition !== undefined ? { providerCondition } : {}),
|
|
136
|
+
...(errorCode !== undefined ? { errorCode } : {}),
|
|
137
|
+
};
|
|
138
|
+
return Object.keys(bits).length > 0 ? bits : undefined;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function syntheticTerminalRow(ctx, identity, replayed, text, historyKey, resend, apiError) {
|
|
112
145
|
return stamp(ctx, {
|
|
113
|
-
uuid: undefined,
|
|
146
|
+
uuid: identity.runId === undefined ? undefined : terminalUuidOf(identity.runId, identity.label),
|
|
114
147
|
session_id: undefined,
|
|
115
148
|
type: 'assistant',
|
|
116
149
|
message: { role: 'assistant', model: '<synthetic>', content: [{ type: 'text', text: washCredentials(text) }] },
|
|
@@ -118,12 +151,12 @@ function syntheticTerminalRow(ctx, text, historyKey, resend) {
|
|
|
118
151
|
_sema_api_error_message: true,
|
|
119
152
|
...(historyKey !== undefined ? { _sema_tool_history_mismatch: historyKey } : {}),
|
|
120
153
|
...(resend !== undefined ? { _sema_provider_rejection_resend: { resend: resend.resend, text: resend.text, kind: resend.kind } } : {}),
|
|
154
|
+
...(apiError?.status !== undefined ? { _sema_api_error_status: apiError.status } : {}),
|
|
155
|
+
...(apiError?.providerCondition !== undefined ? { _sema_provider_condition: apiError.providerCondition } : {}),
|
|
156
|
+
...(apiError?.errorCode !== undefined ? { _sema_api_error_code: apiError.errorCode } : {}),
|
|
157
|
+
...(replayed ? { _sema_replay: true } : {}),
|
|
121
158
|
});
|
|
122
159
|
}
|
|
123
|
-
function engineRunIdOf(result) {
|
|
124
|
-
const v = result?.runId;
|
|
125
|
-
return typeof v === 'string' && v.length > 0 ? v : undefined;
|
|
126
|
-
}
|
|
127
160
|
function engineResultOf(result) {
|
|
128
161
|
const v = doneResultView(result);
|
|
129
162
|
return v.replay ? (v.engine ?? result) : result;
|
|
@@ -142,6 +175,19 @@ export function isGovernanceTerminal(input) {
|
|
|
142
175
|
return true;
|
|
143
176
|
return input.errorCode === OUTPUT_INVALID;
|
|
144
177
|
}
|
|
178
|
+
function terminalFactOf(ev, doneTerminal) {
|
|
179
|
+
const engine = ev.type === 'done' ? engineResultOf(ev.result) : ev;
|
|
180
|
+
const taskId = readFrameStringKey(engine, 'taskId');
|
|
181
|
+
if (ev.type !== 'done' || doneTerminal?.kind !== 'paused')
|
|
182
|
+
return { type: 'terminal_fact', ...(taskId !== undefined ? { taskId } : {}) };
|
|
183
|
+
const checkpointId = doneTerminal.checkpointId;
|
|
184
|
+
const heldCallId = parkHeldCallIdOf(engine);
|
|
185
|
+
return {
|
|
186
|
+
type: 'terminal_fact',
|
|
187
|
+
...(taskId !== undefined ? { taskId } : {}),
|
|
188
|
+
paused: { ...(checkpointId !== undefined ? { checkpointId } : {}), ...(heldCallId !== undefined ? { heldCallId } : {}) },
|
|
189
|
+
};
|
|
190
|
+
}
|
|
145
191
|
function terminalRowFacts(ev) {
|
|
146
192
|
const doneTerminal = ev.type === 'done' ? readRunTerminal(ev.result) : null;
|
|
147
193
|
const errTextRaw = ev.type === 'failed'
|
|
@@ -220,7 +266,7 @@ function ownTerminalSnapshot(result) {
|
|
|
220
266
|
const ts = ownDataCopy(t, ['kind', 'code', 'message']);
|
|
221
267
|
const detail = plainObjectOf(ownDataBit(t, 'detail'));
|
|
222
268
|
if (detail !== undefined)
|
|
223
|
-
ts.detail = ownDataCopy(detail, ['kind', 'status', 'code']);
|
|
269
|
+
ts.detail = ownDataCopy(detail, ['kind', 'status', 'code', 'providerCondition']);
|
|
224
270
|
snap.terminal = ts;
|
|
225
271
|
return snap;
|
|
226
272
|
}
|
|
@@ -301,12 +347,10 @@ function apiErrorTerminalOfRowFrame(ev, facts) {
|
|
|
301
347
|
}
|
|
302
348
|
const reportedDroppedTypes = new Set();
|
|
303
349
|
const DROPPED_TYPE_MEMO_CAP = 64;
|
|
304
|
-
const
|
|
305
|
-
function
|
|
306
|
-
const
|
|
307
|
-
return
|
|
308
|
-
? `${flattened.slice(0, DROPPED_TYPE_DISPLAY_CAP)}…`
|
|
309
|
-
: flattened;
|
|
350
|
+
const DROPPED_TYPE_DISPLAY_MAX = 60;
|
|
351
|
+
function droppedTypeForLog(type) {
|
|
352
|
+
const full = displayUntrusted(type);
|
|
353
|
+
return full.length > DROPPED_TYPE_DISPLAY_MAX ? `${displayUntrusted(type, { max: DROPPED_TYPE_DISPLAY_MAX })}…` : full;
|
|
310
354
|
}
|
|
311
355
|
const DROPPED_WHY_SENTENCE = Object.freeze({
|
|
312
356
|
duplicate_seq: 'a frame with this event id was already consumed on this run stream, so it was dropped as a replay (durable idempotency, contract 02 §1.1). ' +
|
|
@@ -335,7 +379,7 @@ function reportDroppedFrame(why, type, ctx) {
|
|
|
335
379
|
return;
|
|
336
380
|
if (reportedDroppedTypes.size < DROPPED_TYPE_MEMO_CAP)
|
|
337
381
|
reportedDroppedTypes.add(type);
|
|
338
|
-
console.error(`[client-core] dropped an engine frame (${why}): type="${
|
|
382
|
+
console.error(`[client-core] dropped an engine frame (${why}): type="${droppedTypeForLog(type)}" — ${droppedWhySentence(why)}`);
|
|
339
383
|
}
|
|
340
384
|
export function _resetDroppedFrameReportForTest() {
|
|
341
385
|
reportedDroppedTypes.clear();
|
|
@@ -499,27 +543,9 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
499
543
|
}
|
|
500
544
|
}
|
|
501
545
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
ev.type === 'reasoning' ||
|
|
506
|
-
ev.type === 'tool_start' ||
|
|
507
|
-
ev.type === 'tool_end') &&
|
|
508
|
-
typeof ev.parentToolCallId === 'string') {
|
|
509
|
-
const sub = ev;
|
|
510
|
-
publishSubagentContentEvent({
|
|
511
|
-
type: sub.type,
|
|
512
|
-
taskId: sub.taskId ?? sub.parentToolCallId,
|
|
513
|
-
parentToolCallId: sub.parentToolCallId,
|
|
514
|
-
delta: sub.delta,
|
|
515
|
-
text: sub.text,
|
|
516
|
-
eventId: sub.eventId,
|
|
517
|
-
toolCallId: sub.toolCallId,
|
|
518
|
-
toolName: sub.toolName,
|
|
519
|
-
args: sub.args,
|
|
520
|
-
output: coerceOutput(sub.output),
|
|
521
|
-
isError: sub.isError,
|
|
522
|
-
});
|
|
546
|
+
const sub = subagentContentEventOf(ev);
|
|
547
|
+
if (sub !== undefined) {
|
|
548
|
+
publishSubagentContentEvent(sub);
|
|
523
549
|
if (!(ctx.lane === 'print' && (sub.type === 'tool_start' || sub.type === 'tool_end')))
|
|
524
550
|
continue;
|
|
525
551
|
}
|
|
@@ -533,10 +559,10 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
533
559
|
const responseModelRaw = turnEndLoose.responseModel;
|
|
534
560
|
const responseModelWord = typeof responseModelRaw === 'string' && responseModelRaw.length > 0 ? responseModelRaw : undefined;
|
|
535
561
|
const rawUsage = ev.usage;
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
const usage =
|
|
562
|
+
const closedUsage = typeof rawUsage === 'object' && rawUsage !== null && !Array.isArray(rawUsage) ? closedEngineTurnUsage(rawUsage) : undefined;
|
|
563
|
+
const engineUsage = closedUsage?.usage;
|
|
564
|
+
const usageUnknownKeys = closedUsage !== undefined && closedUsage.unknownKeys > 0 ? { engineUsageUnknownKeys: closedUsage.unknownKeys } : {};
|
|
565
|
+
const usage = closedUsage !== undefined ? turnUsageToModelUsage(rawUsage) : undefined;
|
|
540
566
|
const measured = turnEndUsage(ev);
|
|
541
567
|
if (engineUsage === undefined || usage === undefined) {
|
|
542
568
|
usageMissingObserved = true;
|
|
@@ -564,6 +590,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
564
590
|
laneProof: mainLane(),
|
|
565
591
|
usage,
|
|
566
592
|
engineUsage,
|
|
593
|
+
...usageUnknownKeys,
|
|
567
594
|
...(usageMissing ? { usageMissing: true } : {}),
|
|
568
595
|
...(stopWord !== undefined ? { stopReason: stopWord } : {}),
|
|
569
596
|
...(responseModelWord !== undefined ? { responseModel: responseModelWord } : {}),
|
|
@@ -587,6 +614,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
587
614
|
parentToolCallId: parent,
|
|
588
615
|
usage,
|
|
589
616
|
engineUsage,
|
|
617
|
+
...usageUnknownKeys,
|
|
590
618
|
...(usageMissing ? { usageMissing: true } : {}),
|
|
591
619
|
...(stopWord !== undefined ? { stopReason: stopWord } : {}),
|
|
592
620
|
...(responseModelWord !== undefined ? { responseModel: responseModelWord } : {}),
|
|
@@ -625,6 +653,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
625
653
|
if (ev.type === 'done' || ev.type === 'failed') {
|
|
626
654
|
const rowFacts = terminalRowFacts(ev);
|
|
627
655
|
const doneTerminal = rowFacts.doneTerminal;
|
|
656
|
+
const terminalRunId = terminalRunIdOf(ev);
|
|
657
|
+
const replayed = isReplayedTerminal(ev);
|
|
628
658
|
const errText = rowFacts.errText;
|
|
629
659
|
if (errText) {
|
|
630
660
|
const busy = rowFacts.busy;
|
|
@@ -655,8 +685,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
655
685
|
sessionId: historyEchoedSid ?? ctx.sessionId,
|
|
656
686
|
sessionEchoed: historyEchoedSid !== undefined,
|
|
657
687
|
generation: historyGeneration,
|
|
658
|
-
runId:
|
|
659
|
-
replay:
|
|
688
|
+
runId: terminalRunId,
|
|
689
|
+
replay: replayed,
|
|
660
690
|
mismatch: historyMismatch,
|
|
661
691
|
});
|
|
662
692
|
const rewindOffered = historyMismatch !== null && ctx.lane !== 'print' && ctx.lane !== 'utility' && toolHistoryRewindOffered(ctx.offersRewind);
|
|
@@ -665,7 +695,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
665
695
|
: '';
|
|
666
696
|
const resend = historyTerminal.detail !== undefined ? providerRejectionResend(historyTerminal.detail, historyTerminal.carrier) : undefined;
|
|
667
697
|
const resendLine = resend !== undefined ? `\n${resend.text}` : '';
|
|
668
|
-
yield syntheticTerminalRow(ctx, `${sessionUnreadable ? `${rowText}\n${corruptSessionContent()}` : rowText}${abortNote !== undefined ? `\n${abortNote}` : ''}${rewindLine}${resendLine}`, historyMismatch === null ? undefined : toolHistoryMismatchRowKey(historyMismatch, historyRepeat, rewindOffered), resend);
|
|
698
|
+
yield syntheticTerminalRow(ctx, { runId: terminalRunId, label: 'terminal-row' }, replayed, `${sessionUnreadable ? `${rowText}\n${corruptSessionContent()}` : rowText}${abortNote !== undefined ? `\n${abortNote}` : ''}${rewindLine}${resendLine}`, historyMismatch === null ? undefined : toolHistoryMismatchRowKey(historyMismatch, historyRepeat, rewindOffered), resend, arm === 'apiError' ? apiErrorRowBitsOf(historyTerminal) : undefined);
|
|
669
699
|
}
|
|
670
700
|
else {
|
|
671
701
|
const echoedSid = ev.type === 'done' ? engineSessionIdOf(engineResultOf(ev.result)) : undefined;
|
|
@@ -673,8 +703,8 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
673
703
|
sessionId: echoedSid ?? ctx.sessionId,
|
|
674
704
|
sessionEchoed: echoedSid !== undefined,
|
|
675
705
|
generation: historyGeneration,
|
|
676
|
-
runId:
|
|
677
|
-
replay:
|
|
706
|
+
runId: terminalRunId,
|
|
707
|
+
replay: replayed,
|
|
678
708
|
mismatch: null,
|
|
679
709
|
});
|
|
680
710
|
}
|
|
@@ -707,8 +737,9 @@ async function* runStreamInner(events, ctx, handle = {}) {
|
|
|
707
737
|
if (outcome === 'unknown') {
|
|
708
738
|
const errs = resultFrame.errors;
|
|
709
739
|
const sentence = Array.isArray(errs) && typeof errs[0] === 'string' ? errs[0] : 'the run ended without a terminal record this client can read';
|
|
710
|
-
yield syntheticTerminalRow(ctx, `${OUTCOME_UNKNOWN_ROW_PREFIX}: ${sentence}`);
|
|
740
|
+
yield syntheticTerminalRow(ctx, { runId: terminalRunId, label: 'outcome-unknown' }, replayed, `${OUTCOME_UNKNOWN_ROW_PREFIX}: ${sentence}`);
|
|
711
741
|
}
|
|
742
|
+
yield terminalFactOf(ev, doneTerminal);
|
|
712
743
|
yield resultFrame;
|
|
713
744
|
return;
|
|
714
745
|
}
|
package/dist/adapter/types.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { AgentEvent } from '@sema-agent/sdk';
|
|
1
|
+
import type { AgentEvent, StampedAgentEvent } from '@sema-agent/sdk';
|
|
2
2
|
import type { ModelUsage, SDKMessage } from '@sema-agent/agent-types';
|
|
3
3
|
import type { ChromeEvent } from '../seam.js';
|
|
4
4
|
import type { RequestLane } from '../request/taskRequest.js';
|
|
5
|
+
import type { EngineBoundRun } from '../engineRowRef.js';
|
|
5
6
|
export type { ModelUsage, SDKMessage };
|
|
6
|
-
export type StampedAgentEvent
|
|
7
|
-
id?: string;
|
|
8
|
-
};
|
|
7
|
+
export type { StampedAgentEvent };
|
|
9
8
|
export declare function eventSeq(ev: AgentEvent): string | undefined;
|
|
10
9
|
export declare function uuid(): string;
|
|
11
10
|
export interface DroppedFrameInfo {
|
|
@@ -23,6 +22,7 @@ export interface EmitContext {
|
|
|
23
22
|
};
|
|
24
23
|
emitChrome?(event: ChromeEvent): void | Promise<void>;
|
|
25
24
|
onDroppedFrame?(info: DroppedFrameInfo): void;
|
|
25
|
+
boundRun?(frame: AgentEvent): EngineBoundRun | undefined;
|
|
26
26
|
}
|
|
27
27
|
export declare function stamp<T extends {
|
|
28
28
|
uuid?: string | undefined;
|
package/dist/adapter/types.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { abortableSleep } from '../abortableSleep.js';
|
|
2
|
+
import { isAssistantLaneAbsent } from '../assistantInbox.js';
|
|
2
3
|
import { errCodes } from '../controlRouter.js';
|
|
3
4
|
import { engineWireDebugEnabled } from '../engineWireTarget.js';
|
|
4
5
|
import { hostLog } from '../host.js';
|
|
@@ -145,7 +146,7 @@ export function createBackgroundView(client, opts) {
|
|
|
145
146
|
}
|
|
146
147
|
catch (err) {
|
|
147
148
|
debugLog(`assistant.tasks degrade: ${String(err)}`);
|
|
148
|
-
const health =
|
|
149
|
+
const health = isAssistantLaneAbsent(err)
|
|
149
150
|
? 'not-configured'
|
|
150
151
|
: isReadCredentialRefusal(err)
|
|
151
152
|
? 'unauthorized'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentClient
|
|
1
|
+
import type { AgentClient } from '@sema-agent/sdk';
|
|
2
2
|
import type { EngineAgentRegistryListing, EngineAgentRegistryRowView } from '../engineAgentAbsence.js';
|
|
3
3
|
export interface EngineAgentRegistryClient {
|
|
4
4
|
readonly sessions: Pick<AgentClient['sessions'], 'background'>;
|
|
@@ -13,6 +13,6 @@ export interface RegistryListingProvenance {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function registryListingProvenanceOf(listing: EngineAgentRegistryListing | null | undefined): RegistryListingProvenance | undefined;
|
|
15
15
|
export declare function isEngineAgentRegistryListingSuperseded(listing: EngineAgentRegistryListing | null | undefined): boolean;
|
|
16
|
-
export declare function readEngineAgentRegistry(client: EngineAgentRegistryClient, sessionId: string,
|
|
16
|
+
export declare function readEngineAgentRegistry(client: EngineAgentRegistryClient, sessionId: string, capsBaseUrl: string | undefined, opts?: {
|
|
17
17
|
readonly signal?: AbortSignal;
|
|
18
18
|
}): Promise<EngineAgentRegistryListing>;
|