@sema-agent/client-core 0.94.0 → 0.96.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 +521 -0
- package/README.md +104 -57
- package/dist/adapt/arms.js +12 -7
- package/dist/adapt/panelTasks.js +4 -10
- package/dist/adapt/toolCards.d.ts +1 -0
- package/dist/adapt/toolCards.js +18 -5
- package/dist/adapt/wireShapes.js +5 -24
- package/dist/adapter/activeRunSelfHeal.d.ts +12 -3
- package/dist/adapter/activeRunSelfHeal.js +50 -16
- package/dist/adapter/downstream/eventToSdkMessage.js +33 -18
- package/dist/adapter/downstream/terminalToSdkResult.js +19 -12
- package/dist/adapter/runStream.js +30 -46
- package/dist/adapter/types.d.ts +7 -0
- package/dist/adapter/types.js +15 -0
- package/dist/agentSession/backgroundView.js +5 -1
- package/dist/agentSession/engineAgentRegistryRead.js +7 -5
- package/dist/agentSession/engineSessionBackgroundStop.js +25 -17
- package/dist/agentsWireCaps.d.ts +2 -0
- package/dist/agentsWireCaps.js +13 -2
- package/dist/approvalDecidedByCapability.d.ts +0 -1
- package/dist/approvalDecidedByCapability.js +2 -7
- package/dist/approvalsStreamLiveCapability.d.ts +0 -1
- package/dist/approvalsStreamLiveCapability.js +2 -6
- package/dist/atMostOnce.d.ts +8 -0
- package/dist/atMostOnce.js +36 -0
- package/dist/attachmentSeatCapability.d.ts +0 -1
- package/dist/attachmentSeatCapability.js +0 -3
- package/dist/attachmentsWireCaps.js +11 -6
- package/dist/bashExitReading.d.ts +10 -0
- package/dist/bashExitReading.js +12 -0
- package/dist/callerCwdCapability.d.ts +0 -5
- package/dist/callerCwdCapability.js +2 -13
- package/dist/centerWiringCapability.d.ts +1 -7
- package/dist/centerWiringCapability.js +18 -27
- package/dist/classifierStatus.js +4 -4
- package/dist/classifierVerdictWire.js +4 -16
- package/dist/clientSlice.js +1 -1
- package/dist/cloudConfigWireCaps.d.ts +3 -3
- package/dist/cloudConfigWireCaps.js +85 -43
- package/dist/compensations.js +1 -1
- package/dist/coreValuePorts.d.ts +11 -7
- package/dist/coreValuePorts.js +5 -8
- package/dist/credentialProvenance.d.ts +28 -0
- package/dist/credentialProvenance.js +76 -0
- package/dist/cycleOrder.d.ts +15 -0
- package/dist/cycleOrder.js +45 -0
- package/dist/decideFailureNote.js +7 -2
- package/dist/decideReceipt.d.ts +2 -1
- package/dist/decideReceipt.js +39 -14
- package/dist/declared/supportFloorDeclared.d.ts +1 -0
- package/dist/declared/supportFloorDeclared.js +5 -0
- package/dist/deviceExecutorManagementCapability.d.ts +0 -1
- package/dist/deviceExecutorManagementCapability.js +7 -16
- package/dist/deviceRebind.d.ts +88 -0
- package/dist/deviceRebind.js +242 -0
- package/dist/displayUntrusted.d.ts +8 -3
- package/dist/displayUntrusted.js +661 -63
- package/dist/engineAgentAbsence.d.ts +2 -2
- package/dist/engineAgentPanelStore.d.ts +8 -18
- package/dist/engineAgentPanelStore.js +19 -537
- package/dist/engineCapReader.d.ts +6 -6
- package/dist/engineCapReader.js +30 -43
- package/dist/engineCapsCache.d.ts +13 -2
- package/dist/engineCapsCache.js +276 -44
- package/dist/engineCredentialRequirement.d.ts +9 -0
- package/dist/engineCredentialRequirement.js +23 -0
- package/dist/engineDirectory.d.ts +79 -0
- package/dist/engineDirectory.js +186 -0
- package/dist/engineEnvSourcing.d.ts +53 -0
- package/dist/engineEnvSourcing.js +81 -0
- package/dist/engineErrorCodes.d.ts +28 -4
- package/dist/engineErrorCodes.js +68 -25
- package/dist/engineIdentity.js +2 -0
- package/dist/engineNoticeCodes.d.ts +17 -0
- package/dist/engineNoticeCodes.js +57 -3
- package/dist/engineWireSdk.js +2 -2
- package/dist/engineWordRenames.d.ts +8 -0
- package/dist/engineWordRenames.js +13 -0
- package/dist/executionLaneCapability.d.ts +2 -3
- package/dist/executionLaneCapability.js +18 -23
- package/dist/fileHistoryCaptureCapability.d.ts +14 -1
- package/dist/fileHistoryCaptureCapability.js +72 -6
- package/dist/fileHistoryLegNotice.d.ts +3 -2
- package/dist/fileHistoryLegNotice.js +51 -2
- package/dist/fleet/bgSubagentRow.d.ts +15 -0
- package/dist/fleet/bgSubagentRow.js +67 -0
- package/dist/fleet/fleetLedger.d.ts +3 -0
- package/dist/fleet/fleetLedger.js +153 -122
- package/dist/fleet/fleetProjection.d.ts +1 -3
- package/dist/fleet/fleetProjection.js +19 -19
- package/dist/fleetAgentPanelProjection.d.ts +4 -17
- package/dist/fleetAgentPanelProjection.js +7 -197
- package/dist/fleetAgentRowLike.d.ts +16 -0
- package/dist/fleetAgentRowLike.js +1 -0
- package/dist/fleetTaskDesc.js +4 -17
- package/dist/gateOutcome.d.ts +12 -1
- package/dist/gateOutcome.js +87 -18
- package/dist/gateVocabulary.d.ts +7 -2
- package/dist/gateVocabulary.js +5 -1
- package/dist/generated/engineAskFaceTables.js +1 -1
- package/dist/generated/engineFactTables.d.ts +5 -3
- package/dist/generated/engineFactTables.js +17 -4
- package/dist/generated/engineNoticeTables.js +12 -3
- package/dist/generated/sdkFactTables.d.ts +2 -0
- package/dist/generated/sdkFactTables.js +17 -0
- package/dist/generated/settingsSchemaFns.d.ts +13 -0
- package/dist/generated/settingsSchemaFns.js +75 -0
- package/dist/generated/toolNameTables.d.ts +1 -0
- package/dist/generated/toolNameTables.js +1 -0
- package/dist/headlessPermissionModeWire.d.ts +1 -1
- package/dist/headlessPermissionModeWire.js +1 -1
- package/dist/headlessReconnectWire.js +49 -20
- package/dist/hitl/allowRuleShadow.d.ts +1 -1
- package/dist/hitl/allowRuleShadow.js +49 -8
- package/dist/hitl/approvalCompleteParked.d.ts +1 -0
- package/dist/hitl/approvalCompleteParked.js +14 -0
- package/dist/hitl/approvalEndingCause.d.ts +7 -0
- package/dist/hitl/approvalEndingCause.js +71 -0
- package/dist/hitl/approvalHolds.d.ts +12 -2
- package/dist/hitl/approvalHolds.js +53 -2
- package/dist/hitl/approvalsFeed.js +23 -11
- package/dist/hitl/askGateWire.d.ts +2 -1
- package/dist/hitl/askGateWire.js +26 -1
- package/dist/hitl/askParkRowRouting.js +1 -1
- package/dist/hitl/automaticAnswerVerdict.d.ts +1 -1
- package/dist/hitl/automaticAnswerVerdict.js +15 -10
- package/dist/hitl/crashConverged.js +2 -0
- package/dist/hitl/decisionConflict.d.ts +3 -0
- package/dist/hitl/decisionConflict.js +41 -0
- package/dist/hitl/decisionRefusal.d.ts +12 -0
- package/dist/hitl/decisionRefusal.js +63 -4
- package/dist/hitl/frameRouter.d.ts +0 -1
- package/dist/hitl/frameRouter.js +32 -57
- package/dist/hitl/gateLedger.d.ts +5 -0
- package/dist/hitl/gateLedger.js +21 -0
- package/dist/hitl/hitlBridge.d.ts +17 -2
- package/dist/hitl/hitlBridge.js +91 -55
- package/dist/hitl/hitlHostSurface.js +3 -11
- package/dist/hitl/livePendingAsk.d.ts +16 -6
- package/dist/hitl/livePendingAsk.js +36 -4
- package/dist/hitl/localAllowRule.d.ts +1 -0
- package/dist/hitl/localAllowRule.js +2 -2
- package/dist/hitl/noAllowCause.d.ts +2 -1
- package/dist/hitl/noAllowCause.js +3 -2
- package/dist/hitl/parkExpiryJudgements.d.ts +19 -0
- package/dist/hitl/parkExpiryJudgements.js +46 -0
- package/dist/hitl/parkResolver.d.ts +4 -7
- package/dist/hitl/parkResolver.js +12 -34
- package/dist/hitl/parkRowBirthWait.d.ts +1 -0
- package/dist/hitl/parkRowBirthWait.js +2 -2
- package/dist/hitl/persistedRulesWire.js +5 -1
- package/dist/hitl/planReviewWire.d.ts +3 -2
- package/dist/hitl/planReviewWire.js +154 -50
- package/dist/hitl/replayedApproval.d.ts +9 -0
- package/dist/hitl/replayedApproval.js +139 -10
- package/dist/hitl/resumeRunningCard.d.ts +2 -0
- package/dist/hitl/resumeRunningCard.js +15 -4
- package/dist/hitl/sessionPolicyDeliverable.js +8 -6
- package/dist/hitl/standingRows.d.ts +18 -0
- package/dist/hitl/standingRows.js +127 -0
- package/dist/hitl/toolApprovalWire.d.ts +39 -7
- package/dist/hitl/toolApprovalWire.js +351 -61
- package/dist/hookMatcherVerdict.d.ts +1 -9
- package/dist/hookMatcherVerdict.js +21 -61
- package/dist/hooksWireCaps.js +40 -8
- package/dist/host.d.ts +5 -0
- package/dist/host.js +3 -1
- package/dist/hostCallbackGuard.d.ts +2 -0
- package/dist/hostCallbackGuard.js +31 -0
- package/dist/index.d.ts +48 -17
- package/dist/index.js +36 -15
- package/dist/interactiveInterrupt.d.ts +8 -0
- package/dist/interactiveInterrupt.js +54 -0
- package/dist/limitsWire.d.ts +5 -0
- package/dist/limitsWire.js +49 -3
- package/dist/liveModelCatalog.d.ts +95 -0
- package/dist/liveModelCatalog.js +297 -32
- package/dist/mcpEngineLeg.d.ts +25 -0
- package/dist/mcpEngineLeg.js +71 -15
- package/dist/mcpPanel.js +2 -1
- package/dist/mcpProbeCapability.d.ts +0 -5
- package/dist/mcpProbeCapability.js +2 -12
- package/dist/mcpReconnect.d.ts +1 -3
- package/dist/mcpReconnect.js +10 -5
- package/dist/memoryComplianceCapability.d.ts +0 -5
- package/dist/memoryComplianceCapability.js +2 -12
- package/dist/memoryOriginCapability.d.ts +0 -5
- package/dist/memoryOriginCapability.js +2 -12
- package/dist/memorySpecWire.js +2 -2
- package/dist/memoryVerbsWire.d.ts +1 -1
- package/dist/memoryVerbsWire.js +4 -0
- package/dist/model/liveCatalogShape.d.ts +14 -0
- package/dist/model/liveCatalogShape.js +71 -0
- package/dist/model/modelSupplyRules.d.ts +1 -0
- package/dist/model/modelSupplyRules.js +30 -9
- package/dist/model/modelsPolicy.d.ts +21 -0
- package/dist/model/modelsPolicy.js +90 -0
- package/dist/modelIdentityResolvability.d.ts +2 -2
- package/dist/modelIdentityResolvability.js +14 -12
- package/dist/modelSwitchFallback.d.ts +69 -0
- package/dist/modelSwitchFallback.js +206 -0
- package/dist/noticePresentation.d.ts +68 -0
- package/dist/noticePresentation.js +247 -0
- package/dist/notifications.js +12 -11
- package/dist/outputStyleSeatCapability.d.ts +0 -2
- package/dist/outputStyleSeatCapability.js +2 -10
- package/dist/ownKey.d.ts +8 -0
- package/dist/ownKey.js +66 -0
- package/dist/panelReduce.d.ts +114 -0
- package/dist/panelReduce.js +1135 -0
- package/dist/panelStateHolder.d.ts +17 -0
- package/dist/panelStateHolder.js +201 -0
- package/dist/peerFrames.js +13 -9
- package/dist/peerLaneCapability.d.ts +0 -1
- package/dist/peerLaneCapability.js +2 -6
- package/dist/permissionModesCapability.d.ts +0 -5
- package/dist/permissionModesCapability.js +5 -16
- package/dist/permissionRuleIssue.js +0 -3
- package/dist/permissionRulesWriteCapability.d.ts +0 -1
- package/dist/permissionRulesWriteCapability.js +2 -6
- package/dist/permissionsAllowGrantCapability.d.ts +0 -1
- package/dist/permissionsAllowGrantCapability.js +3 -9
- package/dist/permissionsDeclaration.d.ts +8 -0
- package/dist/permissionsDeclaration.js +101 -41
- package/dist/printPermissionOutcome.d.ts +12 -0
- package/dist/printPermissionOutcome.js +50 -0
- package/dist/printToolResultFrame.d.ts +1 -0
- package/dist/printToolResultFrame.js +5 -17
- package/dist/promptBlockedCopy.d.ts +5 -0
- package/dist/promptBlockedCopy.js +35 -0
- package/dist/promptDelivery.js +0 -8
- package/dist/protocolSegment.d.ts +9 -6
- package/dist/protocolSegment.js +31 -21
- package/dist/providerRejection.d.ts +4 -0
- package/dist/providerRejection.js +75 -14
- package/dist/replayBody.d.ts +12 -0
- package/dist/replayBody.js +25 -0
- package/dist/resumeRefusalCopy.d.ts +18 -1
- package/dist/resumeRefusalCopy.js +127 -32
- package/dist/retryStatus.d.ts +9 -1
- package/dist/retryStatus.js +9 -2
- package/dist/rewindArchiveCapability.d.ts +5 -14
- package/dist/rewindArchiveCapability.js +18 -61
- package/dist/rewindArchiveReading.d.ts +15 -0
- package/dist/rewindArchiveReading.js +56 -0
- package/dist/rewindEngineAction.d.ts +21 -0
- package/dist/rewindEngineAction.js +36 -0
- package/dist/rewindWireCaps.d.ts +2 -1
- package/dist/rewindWireCaps.js +1 -0
- package/dist/ruleCompileVerdict.d.ts +9 -1
- package/dist/ruleCompileVerdict.js +29 -4
- package/dist/runTerminal.d.ts +15 -12
- package/dist/runTerminal.js +60 -35
- package/dist/sandboxWire.js +13 -0
- package/dist/sdkRegistryTransit.d.ts +2 -1
- package/dist/sdkRegistryTransit.js +1 -0
- package/dist/sealedKeyCapability.d.ts +0 -5
- package/dist/sealedKeyCapability.js +3 -15
- package/dist/seam.js +4 -2
- package/dist/seatContract.d.ts +125 -34
- package/dist/seatContract.js +583 -179
- package/dist/sessionIdSegment.d.ts +1 -0
- package/dist/sessionIdSegment.js +11 -0
- package/dist/sessionMemoryErase.d.ts +1 -1
- package/dist/sessionMemoryErase.js +6 -1
- package/dist/sessionMemoryStatus.js +3 -2
- package/dist/sessionPolicyCapability.d.ts +0 -1
- package/dist/sessionPolicyCapability.js +2 -6
- package/dist/sessionReadRedactionCapability.d.ts +0 -5
- package/dist/sessionReadRedactionCapability.js +2 -13
- package/dist/sessionSyncFileHistory.d.ts +4 -0
- package/dist/sessionSyncFileHistory.js +66 -0
- package/dist/sessionSyncFileHistoryCapability.d.ts +0 -2
- package/dist/sessionSyncFileHistoryCapability.js +2 -9
- package/dist/skillToolListsCapability.d.ts +0 -2
- package/dist/skillToolListsCapability.js +2 -9
- package/dist/skillsWireCaps.d.ts +4 -0
- package/dist/skillsWireCaps.js +66 -1
- package/dist/sqlEngineCapability.d.ts +0 -1
- package/dist/sqlEngineCapability.js +9 -14
- package/dist/steerPriorityCapability.d.ts +0 -2
- package/dist/steerPriorityCapability.js +3 -12
- package/dist/storePostureCapability.d.ts +1 -5
- package/dist/storePostureCapability.js +16 -22
- package/dist/streamDrainingLegs.d.ts +6 -0
- package/dist/streamDrainingLegs.js +23 -0
- package/dist/subagent/engineCompactWire.js +13 -38
- package/dist/subagent/engineDelegatedPrompt.js +10 -6
- package/dist/subagent/engineSubagentOutput.d.ts +0 -1
- package/dist/subagent/engineSubagentOutput.js +5 -20
- package/dist/subagent/engineSubagentSteer.js +7 -5
- package/dist/subagent/engineSubagentTail.d.ts +0 -1
- package/dist/subagent/engineSubagentTail.js +7 -32
- package/dist/subagentContentStore.js +7 -18
- package/dist/supportFloor.d.ts +1 -0
- package/dist/supportFloor.js +15 -14
- package/dist/systemReminderTag.d.ts +1 -0
- package/dist/systemReminderTag.js +8 -0
- package/dist/terminalStatuses.d.ts +30 -0
- package/dist/terminalStatuses.js +67 -0
- package/dist/toolHistoryMismatch.d.ts +0 -3
- package/dist/toolHistoryMismatch.js +3 -7
- package/dist/toolResult.d.ts +6 -1
- package/dist/toolResult.js +90 -37
- package/dist/toolResultContent.d.ts +2 -0
- package/dist/toolResultContent.js +63 -0
- package/dist/types/engineState.d.ts +2 -1
- package/dist/usageAnalytics.d.ts +146 -0
- package/dist/usageAnalytics.js +335 -0
- package/dist/userInvokedSkillsCapability.d.ts +0 -2
- package/dist/userInvokedSkillsCapability.js +2 -9
- package/dist/webSearchBackendCapability.d.ts +0 -1
- package/dist/webSearchBackendCapability.js +3 -7
- package/dist/webSearchWireCaps.js +3 -11
- package/dist/wireErrorTriage.d.ts +2 -0
- package/dist/wireErrorTriage.js +34 -5
- package/dist/wireFailureShape.d.ts +23 -2
- package/dist/wireFailureShape.js +88 -43
- package/dist/wireRefusalCopy.js +2 -18
- package/dist/workflowClient.js +7 -11
- package/dist/workflowsJournalCapability.d.ts +0 -1
- package/dist/workflowsJournalCapability.js +2 -6
- package/dist/writeProtectionCapability.d.ts +0 -1
- package/dist/writeProtectionCapability.js +5 -10
- package/docs/INTEGRATION-CLIENTS.md +2279 -27
- package/package.json +5 -5
- package/dist/engineCapsGenerationGuard.d.ts +0 -4
- package/dist/engineCapsGenerationGuard.js +0 -19
- package/dist/panelRunningHistory.d.ts +0 -22
- package/dist/panelRunningHistory.js +0 -82
- package/dist/registryConflict.d.ts +0 -3
- package/dist/registryConflict.js +0 -44
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { resultErrorCodeOf, resultSelectedModelOf } from './resultFrameKeys.js';
|
|
2
|
+
import { readFrameStringKey, readOwnDataValue } from './ownKey.js';
|
|
3
|
+
const trimmed = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
4
|
+
const reasonOf = (v) => {
|
|
5
|
+
const t = trimmed(v);
|
|
6
|
+
return t.length > 0 ? t : undefined;
|
|
7
|
+
};
|
|
8
|
+
function thrownReason(e) {
|
|
9
|
+
try {
|
|
10
|
+
if (e instanceof Error)
|
|
11
|
+
return reasonOf(e.message);
|
|
12
|
+
return reasonOf(e);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function modelSwitchProbeOutcomeOf(input) {
|
|
19
|
+
let model = '';
|
|
20
|
+
let lane;
|
|
21
|
+
let absent;
|
|
22
|
+
let probe;
|
|
23
|
+
try {
|
|
24
|
+
model = trimmed(input?.model);
|
|
25
|
+
lane = input?.lane;
|
|
26
|
+
absent = reasonOf(input?.engineAbsentReason);
|
|
27
|
+
probe = input?.probe;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return { ok: false, kind: 'unavailable', cause: 'probe_missing', model };
|
|
31
|
+
}
|
|
32
|
+
if (model.length === 0)
|
|
33
|
+
return { ok: true, probed: false };
|
|
34
|
+
if (lane === 'unwired')
|
|
35
|
+
return { ok: false, kind: 'unavailable', cause: 'unwired', model };
|
|
36
|
+
if (lane === 'mock' || (lane === 'engine_absent' && absent === undefined))
|
|
37
|
+
return { ok: true, probed: false };
|
|
38
|
+
if (lane !== 'live' && lane !== 'engine_absent')
|
|
39
|
+
return { ok: false, kind: 'unavailable', cause: 'unwired', model };
|
|
40
|
+
let kind;
|
|
41
|
+
let verdict;
|
|
42
|
+
let error;
|
|
43
|
+
try {
|
|
44
|
+
kind = probe?.kind;
|
|
45
|
+
verdict = kind === 'verdict' ? probe.verdict : undefined;
|
|
46
|
+
error = kind === 'threw' ? probe.error : undefined;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
kind = undefined;
|
|
50
|
+
}
|
|
51
|
+
if (kind === 'threw') {
|
|
52
|
+
const reason = thrownReason(error);
|
|
53
|
+
return { ok: false, kind: 'unavailable', cause: 'probe_threw', model, ...(reason !== undefined ? { reason } : {}) };
|
|
54
|
+
}
|
|
55
|
+
if (kind !== 'verdict' || verdict === null || typeof verdict !== 'object')
|
|
56
|
+
return { ok: false, kind: 'unavailable', cause: 'probe_missing', model };
|
|
57
|
+
let valid;
|
|
58
|
+
let unchecked;
|
|
59
|
+
let why;
|
|
60
|
+
try {
|
|
61
|
+
valid = verdict.valid;
|
|
62
|
+
unchecked = verdict.unchecked;
|
|
63
|
+
why = reasonOf(verdict.error);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return { ok: false, kind: 'unavailable', cause: 'probe_missing', model };
|
|
67
|
+
}
|
|
68
|
+
if (valid === true)
|
|
69
|
+
return { ok: true, probed: lane === 'live' };
|
|
70
|
+
if (unchecked === true) {
|
|
71
|
+
const reason = why ?? absent;
|
|
72
|
+
return { ok: false, kind: 'unavailable', cause: 'unchecked', model, ...(reason !== undefined ? { reason } : {}) };
|
|
73
|
+
}
|
|
74
|
+
return { ok: false, kind: 'rejected', model, ...(why !== undefined ? { reason: why } : {}) };
|
|
75
|
+
}
|
|
76
|
+
export async function runModelSwitchProbe(model, ports) {
|
|
77
|
+
let laneReading;
|
|
78
|
+
try {
|
|
79
|
+
const got = await ports.lane();
|
|
80
|
+
const lane = got?.lane;
|
|
81
|
+
const why = got?.engineAbsentReason;
|
|
82
|
+
laneReading = {
|
|
83
|
+
lane: lane === 'live' || lane === 'mock' || lane === 'engine_absent' || lane === 'unwired' ? lane : 'unwired',
|
|
84
|
+
...(typeof why === 'string' ? { engineAbsentReason: why } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
laneReading = { lane: 'unwired' };
|
|
89
|
+
}
|
|
90
|
+
const base = { model, ...laneReading };
|
|
91
|
+
const pre = modelSwitchProbeOutcomeOf(base);
|
|
92
|
+
if (pre.ok || (pre.kind === 'unavailable' && pre.cause !== 'probe_missing'))
|
|
93
|
+
return pre;
|
|
94
|
+
try {
|
|
95
|
+
const verdict = await ports.validate(trimmed(model));
|
|
96
|
+
return modelSwitchProbeOutcomeOf({ ...base, probe: { kind: 'verdict', verdict } });
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
return modelSwitchProbeOutcomeOf({ ...base, probe: { kind: 'threw', error } });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const EMPTY_STREAM_ERROR_CODE = 'stream_torn';
|
|
103
|
+
const LEDGER_SESSION_CAP = 1024;
|
|
104
|
+
function isEmptyStreamFailureFrame(frame) {
|
|
105
|
+
try {
|
|
106
|
+
if (frame === null || typeof frame !== 'object' || Array.isArray(frame))
|
|
107
|
+
return false;
|
|
108
|
+
if (readFrameStringKey(frame, 'type') !== 'result')
|
|
109
|
+
return false;
|
|
110
|
+
if (readOwnDataValue(frame, 'is_error') !== true)
|
|
111
|
+
return false;
|
|
112
|
+
return resultErrorCodeOf(frame) === EMPTY_STREAM_ERROR_CODE;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function createModelSwitchFallbackLedger() {
|
|
119
|
+
const bySession = new Map();
|
|
120
|
+
let lastSeq = 0;
|
|
121
|
+
const drop = (sid) => {
|
|
122
|
+
if (sid.length > 0)
|
|
123
|
+
bySession.delete(sid);
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
noteSwitch(input) {
|
|
127
|
+
let sid = '';
|
|
128
|
+
let current = '';
|
|
129
|
+
let previous = '';
|
|
130
|
+
try {
|
|
131
|
+
sid = trimmed(input?.sessionId);
|
|
132
|
+
current = trimmed(input?.to);
|
|
133
|
+
previous = trimmed(input?.lastServed);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
if (sid.length === 0)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (current.length === 0 || previous.length === 0 || previous === current) {
|
|
141
|
+
drop(sid);
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
lastSeq += 1;
|
|
145
|
+
const rec = Object.freeze({ previous, current, seq: lastSeq });
|
|
146
|
+
bySession.delete(sid);
|
|
147
|
+
bySession.set(sid, rec);
|
|
148
|
+
while (bySession.size > LEDGER_SESSION_CAP) {
|
|
149
|
+
const oldest = bySession.keys().next().value;
|
|
150
|
+
if (oldest === undefined)
|
|
151
|
+
break;
|
|
152
|
+
bySession.delete(oldest);
|
|
153
|
+
}
|
|
154
|
+
return rec;
|
|
155
|
+
},
|
|
156
|
+
peek(sessionId) {
|
|
157
|
+
const sid = trimmed(sessionId);
|
|
158
|
+
return sid.length > 0 ? bySession.get(sid) : undefined;
|
|
159
|
+
},
|
|
160
|
+
advisoryFor(input) {
|
|
161
|
+
let frame;
|
|
162
|
+
let sid = '';
|
|
163
|
+
let streamModel = '';
|
|
164
|
+
let served = '';
|
|
165
|
+
try {
|
|
166
|
+
frame = input?.frame;
|
|
167
|
+
sid = trimmed(input?.sessionId);
|
|
168
|
+
streamModel = trimmed(input?.streamModel);
|
|
169
|
+
served = trimmed(input?.lastServed);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
if (!isEmptyStreamFailureFrame(frame))
|
|
175
|
+
return undefined;
|
|
176
|
+
if (sid.length === 0)
|
|
177
|
+
return undefined;
|
|
178
|
+
const rec = bySession.get(sid);
|
|
179
|
+
if (rec === undefined)
|
|
180
|
+
return undefined;
|
|
181
|
+
const frameModel = trimmed(resultSelectedModelOf(frame));
|
|
182
|
+
const candidates = frameModel.length > 0 && frameModel !== streamModel ? [streamModel, frameModel] : [streamModel];
|
|
183
|
+
for (const c of candidates) {
|
|
184
|
+
if (c.length === 0 || rec.current !== c)
|
|
185
|
+
continue;
|
|
186
|
+
if (served === c)
|
|
187
|
+
return undefined;
|
|
188
|
+
return rec;
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
},
|
|
192
|
+
release(sessionId, seq) {
|
|
193
|
+
const sid = trimmed(sessionId);
|
|
194
|
+
if (sid.length === 0)
|
|
195
|
+
return false;
|
|
196
|
+
const rec = bySession.get(sid);
|
|
197
|
+
if (rec === undefined || typeof seq !== 'number' || rec.seq !== seq)
|
|
198
|
+
return false;
|
|
199
|
+
bySession.delete(sid);
|
|
200
|
+
return true;
|
|
201
|
+
},
|
|
202
|
+
clear(sessionId) {
|
|
203
|
+
drop(trimmed(sessionId));
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export interface CutForDisplayOptions {
|
|
2
|
+
readonly boundary?: 'sentence' | 'word';
|
|
3
|
+
readonly mark?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface CutForDisplayResult {
|
|
6
|
+
readonly shown: string;
|
|
7
|
+
readonly truncated: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function cutForDisplay(text: string, budget: number, opts?: CutForDisplayOptions): CutForDisplayResult;
|
|
10
|
+
export type NoticePresentationAudience = 'user' | 'operator' | 'unknown';
|
|
11
|
+
export type NoticeOutlet = 'present' | 'absent' | 'unknown';
|
|
12
|
+
export type NoticeOccurrence = {
|
|
13
|
+
readonly kind: 'event';
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'occurrence';
|
|
16
|
+
readonly key: string;
|
|
17
|
+
};
|
|
18
|
+
export type NoticeSeatClass = 'persistent+hint' | 'persistent' | 'transient' | 'diagnostic';
|
|
19
|
+
export type NoticeDeployment = 'local' | 'remote';
|
|
20
|
+
export interface NoticePresentationFacts {
|
|
21
|
+
readonly audience: NoticePresentationAudience;
|
|
22
|
+
readonly outlet: NoticeOutlet;
|
|
23
|
+
readonly remedy?: string;
|
|
24
|
+
readonly occurrence: NoticeOccurrence;
|
|
25
|
+
readonly seatClass: NoticeSeatClass;
|
|
26
|
+
}
|
|
27
|
+
export declare const NOTICE_SEAT_CLASS: Readonly<Record<NoticePresentationAudience, Readonly<Record<NoticeOutlet, NoticeSeatClass>>>>;
|
|
28
|
+
export declare function noticeSeatClassOf(audience: NoticePresentationAudience, outlet: NoticeOutlet, deployment?: NoticeDeployment): NoticeSeatClass;
|
|
29
|
+
export declare function noticePresentationFacts(notice: unknown, deployment?: NoticeDeployment): NoticePresentationFacts;
|
|
30
|
+
export declare const OUTLET_KINDS: readonly ["slash-command", "cli-command", "http-endpoint", "env-or-settings", "operator-action", "identity-attach", "resend"];
|
|
31
|
+
export type OutletKind = (typeof OUTLET_KINDS)[number];
|
|
32
|
+
export type OutletReachability = 'reachable' | 'unreachable' | 'unknown';
|
|
33
|
+
export interface OutletReachabilityContext {
|
|
34
|
+
readonly lane: 'interactive' | 'print';
|
|
35
|
+
readonly engineManagedByShell: 'shell' | 'external-local' | 'remote' | 'unknown';
|
|
36
|
+
readonly configScope: 'reaches-engine' | 'does-not' | 'unknown';
|
|
37
|
+
readonly endpointAccess: 'has-address-and-credential' | 'no' | 'unknown';
|
|
38
|
+
readonly operator: 'present' | 'absent' | 'unknown';
|
|
39
|
+
readonly identityAttach: 'available' | 'unavailable' | 'unknown';
|
|
40
|
+
}
|
|
41
|
+
export declare function outletReachable(kind: OutletKind, ctx: OutletReachabilityContext): OutletReachability;
|
|
42
|
+
export interface OutletRenderingPlan {
|
|
43
|
+
readonly state: readonly OutletKind[];
|
|
44
|
+
readonly confirm: readonly OutletKind[];
|
|
45
|
+
readonly omit: readonly OutletKind[];
|
|
46
|
+
readonly nothingReachable: boolean;
|
|
47
|
+
}
|
|
48
|
+
export declare function planOutletRendering(kinds: readonly OutletKind[], ctx: OutletReachabilityContext): OutletRenderingPlan;
|
|
49
|
+
export declare const NOTICE_FULL_TEXT_CAP = 8000;
|
|
50
|
+
export type NoticePrintCarrier = {
|
|
51
|
+
readonly kind: 'transcript';
|
|
52
|
+
readonly sessionId: string;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: 'stream-json';
|
|
55
|
+
} | {
|
|
56
|
+
readonly kind: 'none';
|
|
57
|
+
};
|
|
58
|
+
export interface NoticePrintLineInput {
|
|
59
|
+
readonly text: string | undefined;
|
|
60
|
+
readonly audience: NoticePresentationAudience;
|
|
61
|
+
readonly code?: string;
|
|
62
|
+
readonly carrier: NoticePrintCarrier;
|
|
63
|
+
}
|
|
64
|
+
export interface NoticePrintLineResult {
|
|
65
|
+
readonly line: string;
|
|
66
|
+
readonly truncated: boolean;
|
|
67
|
+
}
|
|
68
|
+
export declare function noticePrintLine(input: NoticePrintLineInput): NoticePrintLineResult;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { capDisplay, displayUntrusted } from './displayUntrusted.js';
|
|
2
|
+
import { engineNoticeInCatalog, noticeAudienceOf } from './engineNoticeCodes.js';
|
|
3
|
+
import { guardedRead, readOwnDataNonEmptyString, readOwnDataValue } from './ownKey.js';
|
|
4
|
+
const DEFAULT_CUT_MARK = '…';
|
|
5
|
+
const CUT_KEEP_DIVISOR = 2;
|
|
6
|
+
const CLOSERS = '"\')]”’」』)】';
|
|
7
|
+
const ASCII_SENTENCE_END = '.!?;';
|
|
8
|
+
const WIDE_SENTENCE_END = '。!?;';
|
|
9
|
+
const ASCII_CLAUSE_END = ',:';
|
|
10
|
+
const WIDE_CLAUSE_END = ',、:';
|
|
11
|
+
const EM_DASH = '—';
|
|
12
|
+
function isWs(c) {
|
|
13
|
+
return c !== '' && c.trim() === '';
|
|
14
|
+
}
|
|
15
|
+
function readCutOptions(opts) {
|
|
16
|
+
if (typeof opts !== 'object' || opts === null)
|
|
17
|
+
return { boundary: 'sentence', mark: DEFAULT_CUT_MARK };
|
|
18
|
+
const boundary = guardedRead(() => readOwnDataValue(opts, 'boundary'));
|
|
19
|
+
const mark = guardedRead(() => readOwnDataValue(opts, 'mark'));
|
|
20
|
+
return { boundary: boundary === 'word' ? 'word' : 'sentence', mark: typeof mark === 'string' ? mark : DEFAULT_CUT_MARK };
|
|
21
|
+
}
|
|
22
|
+
function sentenceEndAt(src, j) {
|
|
23
|
+
const c = src.charAt(j);
|
|
24
|
+
const ascii = ASCII_SENTENCE_END.includes(c);
|
|
25
|
+
if (!ascii && !WIDE_SENTENCE_END.includes(c))
|
|
26
|
+
return -1;
|
|
27
|
+
let k = j + 1;
|
|
28
|
+
while (k < src.length && CLOSERS.includes(src.charAt(k)))
|
|
29
|
+
k++;
|
|
30
|
+
if (!ascii)
|
|
31
|
+
return k;
|
|
32
|
+
return k === src.length || isWs(src.charAt(k)) ? k : -1;
|
|
33
|
+
}
|
|
34
|
+
function clauseEndAt(src, j) {
|
|
35
|
+
const c = src.charAt(j);
|
|
36
|
+
if (WIDE_CLAUSE_END.includes(c))
|
|
37
|
+
return j + 1;
|
|
38
|
+
if (!ASCII_CLAUSE_END.includes(c))
|
|
39
|
+
return -1;
|
|
40
|
+
const k = j + 1;
|
|
41
|
+
return k === src.length || isWs(src.charAt(k)) ? k : -1;
|
|
42
|
+
}
|
|
43
|
+
function pickCut(src, limit, floor, boundary) {
|
|
44
|
+
let sentence = -1;
|
|
45
|
+
let clause = -1;
|
|
46
|
+
let word = -1;
|
|
47
|
+
for (let j = 0; j <= limit && j < src.length; j++) {
|
|
48
|
+
const c = src.charAt(j);
|
|
49
|
+
if (isWs(c)) {
|
|
50
|
+
word = j;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (boundary === 'word')
|
|
54
|
+
continue;
|
|
55
|
+
const s = sentenceEndAt(src, j);
|
|
56
|
+
if (s !== -1 && s <= limit)
|
|
57
|
+
sentence = Math.max(sentence, s);
|
|
58
|
+
else if (c === EM_DASH && j > 0 && isWs(src.charAt(j - 1)) && (j + 1 === src.length || isWs(src.charAt(j + 1))))
|
|
59
|
+
sentence = Math.max(sentence, j);
|
|
60
|
+
const k = clauseEndAt(src, j);
|
|
61
|
+
if (k !== -1 && k <= limit)
|
|
62
|
+
clause = Math.max(clause, k);
|
|
63
|
+
}
|
|
64
|
+
if (boundary === 'word')
|
|
65
|
+
return word >= floor ? word : -1;
|
|
66
|
+
if (sentence >= floor)
|
|
67
|
+
return sentence;
|
|
68
|
+
if (clause >= floor)
|
|
69
|
+
return clause;
|
|
70
|
+
return word >= floor ? word : -1;
|
|
71
|
+
}
|
|
72
|
+
export function cutForDisplay(text, budget, opts) {
|
|
73
|
+
const src = typeof text === 'string' ? text : (guardedRead(() => String(text ?? '')) ?? '');
|
|
74
|
+
if (typeof budget !== 'number' || !Number.isFinite(budget))
|
|
75
|
+
return { shown: src, truncated: false };
|
|
76
|
+
const limit = Math.max(0, Math.floor(budget));
|
|
77
|
+
if (src.length <= limit)
|
|
78
|
+
return { shown: src, truncated: false };
|
|
79
|
+
const { boundary, mark } = readCutOptions(opts);
|
|
80
|
+
const room = limit - mark.length;
|
|
81
|
+
if (room <= 0)
|
|
82
|
+
return { shown: limit >= mark.length ? mark : '', truncated: true };
|
|
83
|
+
const head = capDisplay(src, room, 'escape');
|
|
84
|
+
const floor = Math.ceil(head.length / CUT_KEEP_DIVISOR);
|
|
85
|
+
const at = pickCut(src, head.length, floor, boundary);
|
|
86
|
+
const kept = (at === -1 ? head : src.slice(0, at)).trimEnd();
|
|
87
|
+
return { shown: `${kept}${mark}`, truncated: true };
|
|
88
|
+
}
|
|
89
|
+
export const NOTICE_SEAT_CLASS = Object.freeze({
|
|
90
|
+
user: Object.freeze({ present: 'persistent+hint', unknown: 'persistent+hint', absent: 'persistent' }),
|
|
91
|
+
operator: Object.freeze({ present: 'transient', unknown: 'transient', absent: 'diagnostic' }),
|
|
92
|
+
unknown: Object.freeze({ present: 'persistent+hint', unknown: 'persistent+hint', absent: 'persistent+hint' }),
|
|
93
|
+
});
|
|
94
|
+
export function noticeSeatClassOf(audience, outlet, deployment) {
|
|
95
|
+
const a = typeof audience === 'string' && Object.hasOwn(NOTICE_SEAT_CLASS, audience) ? audience : 'unknown';
|
|
96
|
+
const row = a === 'operator' && deployment !== 'remote' ? NOTICE_SEAT_CLASS.user : NOTICE_SEAT_CLASS[a];
|
|
97
|
+
return typeof outlet === 'string' && Object.hasOwn(row, outlet) ? row[outlet] : row.unknown;
|
|
98
|
+
}
|
|
99
|
+
const OCCURRENCE_KEY_BY_CODE = Object.freeze({
|
|
100
|
+
'memory.harvest_quarantined': 'reportId',
|
|
101
|
+
'memory.hold_opened': 'reportId',
|
|
102
|
+
'memory.hold_released': 'reportId',
|
|
103
|
+
'memory.hold_disposed': 'reportId',
|
|
104
|
+
'memory.consolidation_recommended': 'reportId',
|
|
105
|
+
'memory.capture_opted_out': 'sessionId',
|
|
106
|
+
'memory.delegation_static_mark_waived': 'runId',
|
|
107
|
+
});
|
|
108
|
+
export function noticePresentationFacts(notice, deployment) {
|
|
109
|
+
const envelope = typeof notice === 'object' && notice !== null ? notice : undefined;
|
|
110
|
+
const code = guardedRead(() => readOwnDataValue(envelope, 'code'));
|
|
111
|
+
const detailRaw = guardedRead(() => readOwnDataValue(envelope, 'detail'));
|
|
112
|
+
const detail = typeof detailRaw === 'object' && detailRaw !== null ? detailRaw : undefined;
|
|
113
|
+
const audience = typeof code === 'string' && engineNoticeInCatalog(code) ? noticeAudienceOf(code) : 'unknown';
|
|
114
|
+
const remedy = guardedRead(() => readOwnDataNonEmptyString(detail, 'remedy'));
|
|
115
|
+
const outlet = remedy !== undefined ? 'present' : 'unknown';
|
|
116
|
+
const keyField = typeof code === 'string' && Object.hasOwn(OCCURRENCE_KEY_BY_CODE, code) ? OCCURRENCE_KEY_BY_CODE[code] : undefined;
|
|
117
|
+
const identity = keyField !== undefined ? guardedRead(() => readOwnDataNonEmptyString(detail, keyField)) : undefined;
|
|
118
|
+
const occurrence = Object.freeze(identity !== undefined ? { kind: 'occurrence', key: identity } : { kind: 'event' });
|
|
119
|
+
return Object.freeze({
|
|
120
|
+
audience,
|
|
121
|
+
outlet,
|
|
122
|
+
...(remedy !== undefined ? { remedy } : {}),
|
|
123
|
+
occurrence,
|
|
124
|
+
seatClass: noticeSeatClassOf(audience, outlet, deployment),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export const OUTLET_KINDS = Object.freeze(['slash-command', 'cli-command', 'http-endpoint', 'env-or-settings', 'operator-action', 'identity-attach', 'resend']);
|
|
128
|
+
function ctxSlot(ctx, key, closed) {
|
|
129
|
+
if (typeof ctx !== 'object' || ctx === null)
|
|
130
|
+
return undefined;
|
|
131
|
+
const v = guardedRead(() => readOwnDataValue(ctx, key));
|
|
132
|
+
return typeof v === 'string' && closed.includes(v) ? v : undefined;
|
|
133
|
+
}
|
|
134
|
+
function isOutletKind(v) {
|
|
135
|
+
return typeof v === 'string' && OUTLET_KINDS.includes(v);
|
|
136
|
+
}
|
|
137
|
+
export function outletReachable(kind, ctx) {
|
|
138
|
+
if (!isOutletKind(kind))
|
|
139
|
+
return 'unknown';
|
|
140
|
+
const lane = ctxSlot(ctx, 'lane', ['interactive', 'print']);
|
|
141
|
+
switch (kind) {
|
|
142
|
+
case 'resend':
|
|
143
|
+
case 'cli-command':
|
|
144
|
+
return 'reachable';
|
|
145
|
+
case 'slash-command':
|
|
146
|
+
return lane === 'interactive' ? 'reachable' : lane === 'print' ? 'unreachable' : 'unknown';
|
|
147
|
+
case 'http-endpoint': {
|
|
148
|
+
if (lane === 'interactive')
|
|
149
|
+
return 'unreachable';
|
|
150
|
+
const access = ctxSlot(ctx, 'endpointAccess', ['has-address-and-credential', 'no', 'unknown']);
|
|
151
|
+
if (access === 'no')
|
|
152
|
+
return 'unreachable';
|
|
153
|
+
return lane === 'print' && access === 'has-address-and-credential' ? 'reachable' : 'unknown';
|
|
154
|
+
}
|
|
155
|
+
case 'env-or-settings': {
|
|
156
|
+
const scope = ctxSlot(ctx, 'configScope', ['reaches-engine', 'does-not', 'unknown']);
|
|
157
|
+
if (scope === 'reaches-engine')
|
|
158
|
+
return 'reachable';
|
|
159
|
+
if (scope === 'does-not')
|
|
160
|
+
return 'unreachable';
|
|
161
|
+
return ctxSlot(ctx, 'engineManagedByShell', ['shell', 'external-local', 'remote', 'unknown']) === 'remote' ? 'unreachable' : 'unknown';
|
|
162
|
+
}
|
|
163
|
+
case 'operator-action': {
|
|
164
|
+
const op = ctxSlot(ctx, 'operator', ['present', 'absent', 'unknown']);
|
|
165
|
+
return op === 'present' ? 'reachable' : op === 'absent' ? 'unreachable' : 'unknown';
|
|
166
|
+
}
|
|
167
|
+
case 'identity-attach': {
|
|
168
|
+
const id = ctxSlot(ctx, 'identityAttach', ['available', 'unavailable', 'unknown']);
|
|
169
|
+
return id === 'available' ? 'reachable' : id === 'unavailable' ? 'unreachable' : 'unknown';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const LIST_READ_MAX = 64;
|
|
174
|
+
function listItems(list) {
|
|
175
|
+
if (guardedRead(() => (Array.isArray(list) ? true : undefined)) !== true)
|
|
176
|
+
return [];
|
|
177
|
+
const length = guardedRead(() => readOwnDataValue(list, 'length'));
|
|
178
|
+
if (typeof length !== 'number' || !Number.isInteger(length) || length < 0)
|
|
179
|
+
return [];
|
|
180
|
+
const out = [];
|
|
181
|
+
for (let i = 0; i < Math.min(length, LIST_READ_MAX); i++) {
|
|
182
|
+
const item = guardedRead(() => readOwnDataValue(list, String(i)));
|
|
183
|
+
if (item !== undefined)
|
|
184
|
+
out.push(item);
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
export function planOutletRendering(kinds, ctx) {
|
|
189
|
+
const state = [];
|
|
190
|
+
const confirm = [];
|
|
191
|
+
const omit = [];
|
|
192
|
+
const seen = new Set();
|
|
193
|
+
for (const k of listItems(kinds)) {
|
|
194
|
+
if (!isOutletKind(k) || seen.has(k))
|
|
195
|
+
continue;
|
|
196
|
+
seen.add(k);
|
|
197
|
+
const r = outletReachable(k, ctx);
|
|
198
|
+
(r === 'reachable' ? state : r === 'unknown' ? confirm : omit).push(k);
|
|
199
|
+
}
|
|
200
|
+
return Object.freeze({
|
|
201
|
+
state: Object.freeze(state),
|
|
202
|
+
confirm: Object.freeze(confirm),
|
|
203
|
+
omit: Object.freeze(omit),
|
|
204
|
+
nothingReachable: state.length === 0 && confirm.length === 0 && omit.length > 0,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
export const NOTICE_FULL_TEXT_CAP = 8000;
|
|
208
|
+
const PRINT_BUDGET_USER = 1000;
|
|
209
|
+
const PRINT_BUDGET_OPERATOR = 160;
|
|
210
|
+
const PRINT_PREFIX = '[sema] ';
|
|
211
|
+
const NO_TEXT_SENTENCE = 'Engine notice (no message text)';
|
|
212
|
+
const PRINT_CODE_MAX = 160;
|
|
213
|
+
const PRE_CAP_SLACK = 2;
|
|
214
|
+
const PRINT_SESSION_MAX = 128;
|
|
215
|
+
function lineFace(max) {
|
|
216
|
+
return max === undefined ? { foldLines: false, mark: 'dot' } : { foldLines: false, mark: 'dot', max };
|
|
217
|
+
}
|
|
218
|
+
function printCarrier(carrier) {
|
|
219
|
+
if (typeof carrier !== 'object' || carrier === null)
|
|
220
|
+
return { kind: 'none' };
|
|
221
|
+
const kind = guardedRead(() => readOwnDataValue(carrier, 'kind'));
|
|
222
|
+
if (kind === 'stream-json')
|
|
223
|
+
return { kind };
|
|
224
|
+
if (kind === 'transcript') {
|
|
225
|
+
const sid = guardedRead(() => readOwnDataNonEmptyString(carrier, 'sessionId'));
|
|
226
|
+
if (sid !== undefined) {
|
|
227
|
+
const shown = displayUntrusted(sid, lineFace(PRINT_SESSION_MAX));
|
|
228
|
+
if (shown !== '')
|
|
229
|
+
return { kind, sessionId: shown };
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return { kind: 'none' };
|
|
233
|
+
}
|
|
234
|
+
export function noticePrintLine(input) {
|
|
235
|
+
const textRaw = guardedRead(() => readOwnDataValue(input, 'text'));
|
|
236
|
+
const audience = guardedRead(() => readOwnDataValue(input, 'audience'));
|
|
237
|
+
const codeRaw = guardedRead(() => readOwnDataValue(input, 'code'));
|
|
238
|
+
const carrier = printCarrier(guardedRead(() => readOwnDataValue(input, 'carrier')));
|
|
239
|
+
const washed = displayUntrusted(typeof textRaw === 'string' ? textRaw : '', lineFace(NOTICE_FULL_TEXT_CAP + PRE_CAP_SLACK));
|
|
240
|
+
const bounded = cutForDisplay(washed, NOTICE_FULL_TEXT_CAP);
|
|
241
|
+
const text = bounded.shown.trim() === '' ? NO_TEXT_SENTENCE : bounded.shown;
|
|
242
|
+
const budget = audience === 'operator' ? PRINT_BUDGET_OPERATOR : PRINT_BUDGET_USER;
|
|
243
|
+
const cut = carrier.kind === 'none' ? { shown: text, truncated: bounded.truncated } : cutForDisplay(text, budget);
|
|
244
|
+
const where = cut.truncated && carrier.kind === 'transcript' ? ` (full text: sema -r ${carrier.sessionId})` : '';
|
|
245
|
+
const code = typeof codeRaw === 'string' && codeRaw !== '' ? displayUntrusted(codeRaw, lineFace(PRINT_CODE_MAX)) : '';
|
|
246
|
+
return Object.freeze({ line: `${PRINT_PREFIX}${cut.shown}${where}${code !== '' ? ` [${code}]` : ''}`, truncated: cut.truncated });
|
|
247
|
+
}
|
package/dist/notifications.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { hostEnv } from './hostEnv.js';
|
|
2
2
|
import { unrefTimer } from './unrefTimer.js';
|
|
3
3
|
import { clearEnginePanelTaskResidentByWire, publishEngineAgentPanelEvent, } from './engineAgentPanelStore.js';
|
|
4
|
-
import {
|
|
4
|
+
import { panelEndFact } from './panelReduce.js';
|
|
5
|
+
import { isCoreTaskNotificationTerminal, isCoreTaskNotificationTerminalNotSuccess } from './terminalStatuses.js';
|
|
6
|
+
import { cycleSeqValue } from './cycleOrder.js';
|
|
5
7
|
function escapeXml(v) {
|
|
6
8
|
return v.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
7
9
|
}
|
|
@@ -130,7 +132,7 @@ export function parseTranscriptNotificationSeeds(messages) {
|
|
|
130
132
|
continue;
|
|
131
133
|
const external = /\btype="external"/.test(attrs);
|
|
132
134
|
renderedKeys.push(`${external ? 'external:' : ''}${taskId}:${status}`);
|
|
133
|
-
if (!external && (
|
|
135
|
+
if (!external && isCoreTaskNotificationTerminal(status)) {
|
|
134
136
|
notifiedKeys.push(taskId);
|
|
135
137
|
}
|
|
136
138
|
seeded++;
|
|
@@ -316,6 +318,10 @@ const BG_FIRST_SEQ = 1;
|
|
|
316
318
|
function normalizeBgSeq(seq) {
|
|
317
319
|
return typeof seq === 'number' && Number.isFinite(seq) && seq >= BG_FIRST_SEQ ? Math.floor(seq) : BG_FIRST_SEQ;
|
|
318
320
|
}
|
|
321
|
+
function notificationCycleOf(n) {
|
|
322
|
+
const cycleSeq = cycleSeqValue(n.seq);
|
|
323
|
+
return cycleSeq !== undefined ? { cycleSeq } : undefined;
|
|
324
|
+
}
|
|
319
325
|
function bgOutstandingKey(taskId, seq) {
|
|
320
326
|
return `${taskId}:${seq}`;
|
|
321
327
|
}
|
|
@@ -570,20 +576,15 @@ export function enqueueBgChildNotification(n) {
|
|
|
570
576
|
return;
|
|
571
577
|
}
|
|
572
578
|
bgNotifiedKeys.add(key);
|
|
573
|
-
const terminal =
|
|
579
|
+
const terminal = isCoreTaskNotificationTerminal(n.status);
|
|
574
580
|
if (terminal) {
|
|
575
581
|
markRunNotified(n.taskId, cycle);
|
|
576
582
|
cardEnqueuedRunIds.add(n.taskId);
|
|
577
583
|
}
|
|
578
584
|
if (terminal) {
|
|
579
585
|
try {
|
|
580
|
-
clearEnginePanelTaskResidentByWire(n.taskId,
|
|
581
|
-
publishEngineAgentPanelEvent(
|
|
582
|
-
kind: 'end',
|
|
583
|
-
taskId: n.taskId,
|
|
584
|
-
isError: isTerminalNotSuccess(n.status),
|
|
585
|
-
...(typeof n.seq === 'number' && Number.isInteger(n.seq) && n.seq >= BG_FIRST_SEQ ? { cycleSeq: n.seq } : {}),
|
|
586
|
-
});
|
|
586
|
+
clearEnginePanelTaskResidentByWire(n.taskId, notificationCycleOf(n));
|
|
587
|
+
publishEngineAgentPanelEvent(panelEndFact(n.taskId, isCoreTaskNotificationTerminalNotSuccess(n.status), notificationCycleOf(n)));
|
|
587
588
|
}
|
|
588
589
|
catch {
|
|
589
590
|
}
|
|
@@ -667,7 +668,7 @@ export function taskNotificationDeliverySupplement(objective) {
|
|
|
667
668
|
return `${SUPPLEMENT_LINE_PREFIX}completed — only this notification delivery failed. Check /tasks for the result.`;
|
|
668
669
|
}
|
|
669
670
|
const statusNote = status && status.length > 0 ? ` (status: ${status})` : '';
|
|
670
|
-
if (
|
|
671
|
+
if (isCoreTaskNotificationTerminal(status)) {
|
|
671
672
|
return `${SUPPLEMENT_LINE_PREFIX}already finished${statusNote} — only this notification delivery failed. Check /tasks for the result.`;
|
|
672
673
|
}
|
|
673
674
|
return `${SUPPLEMENT_LINE_PREFIX}is in a state this client cannot confirm${statusNote} — this notification delivery failed and the task's outcome is unknown here. Check /tasks for its current state.`;
|
|
@@ -12,5 +12,3 @@ export declare function noteEngineCapsForOutputStyleSeat(baseUrl: string, caps:
|
|
|
12
12
|
}): void;
|
|
13
13
|
export declare function observedOutputStyleSeat(baseUrl?: string | undefined): OutputStyleSeatReading;
|
|
14
14
|
export declare function outputStyleSeatAdmitted(reading: OutputStyleSeatReading | undefined): boolean;
|
|
15
|
-
export declare function forgetOutputStyleSeatReading(baseUrl: string | undefined): void;
|
|
16
|
-
export declare function __resetOutputStyleSeatReadingsForTests(): void;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { engineWireTarget } from './engineWireTarget.js';
|
|
2
2
|
import { createEngineCapReader } from './engineCapReader.js';
|
|
3
|
-
import { readOwnDataValue } from './ownKey.js';
|
|
3
|
+
import { ownDataField, readOwnDataValue } from './ownKey.js';
|
|
4
4
|
export function projectOutputStyleSeatCapability(caps) {
|
|
5
5
|
try {
|
|
6
6
|
if (caps === null || typeof caps !== 'object' || Array.isArray(caps))
|
|
7
7
|
return undefined;
|
|
8
|
-
|
|
9
|
-
return { kind: 'not_reported' };
|
|
10
|
-
const v = caps.outputStyle;
|
|
8
|
+
const v = ownDataField(caps, 'outputStyle');
|
|
11
9
|
if (v === undefined)
|
|
12
10
|
return { kind: 'not_reported' };
|
|
13
11
|
return v === true ? { kind: 'present', value: true } : undefined;
|
|
@@ -39,9 +37,3 @@ export function outputStyleSeatAdmitted(reading) {
|
|
|
39
37
|
return false;
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
|
-
export function forgetOutputStyleSeatReading(baseUrl) {
|
|
43
|
-
reader.forget(baseUrl);
|
|
44
|
-
}
|
|
45
|
-
export function __resetOutputStyleSeatReadingsForTests() {
|
|
46
|
-
reader.__resetForTests();
|
|
47
|
-
}
|
package/dist/ownKey.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export declare function putOwnKey<T>(table: Record<string, T>, key: string, value: T): void;
|
|
2
2
|
export declare function readOwnNonEmptyString(v: object | null | undefined, key: string): string | undefined;
|
|
3
|
+
export declare function readAskOrigin(carrier: object | null | undefined): string | undefined;
|
|
3
4
|
export declare function readOwnDataNonEmptyString(v: object | null | undefined, key: string): string | undefined;
|
|
4
5
|
export declare function readOwnDataValue<T>(v: object | null | undefined, key: string): T | undefined;
|
|
6
|
+
export declare function guardedRead<T>(read: () => T | undefined): T | undefined;
|
|
7
|
+
export declare function ownDataField(v: object, key: string): unknown;
|
|
8
|
+
export declare function ownSendableField(v: object, key: string): unknown;
|
|
9
|
+
export declare function ownDataRefusalKeyOf(e: unknown): string | undefined;
|
|
5
10
|
export declare function readFrameStringKey(frame: unknown, key: string): string | undefined;
|
|
11
|
+
export declare function readFrameTrueMark(frame: object | null | undefined, key: string): boolean;
|
|
12
|
+
export declare function markMcpSectionDroppedNamedRows(rows: object, dropped: ReadonlyMap<string, number>): void;
|
|
13
|
+
export declare function mcpSectionDroppedNamedRowsOf(rows: object | null | undefined, name: string): number;
|