@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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export type ConfigPath = readonly (string | number)[];
|
|
2
|
+
declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "PostToolBatch", "Notification", "UserPromptSubmit", "UserPromptExpansion", "SessionStart", "SessionEnd", "Stop", "StopFailure", "SubagentStart", "SubagentStop", "PreCompact", "PostCompact", "PermissionRequest", "PermissionDenied", "Setup", "TeammateIdle", "TaskCreated", "TaskCompleted", "Elicitation", "ElicitationResult", "ConfigChange", "WorktreeCreate", "WorktreeRemove", "InstructionsLoaded", "CwdChanged", "FileChanged", "MessageDisplay", "DirectoryAdded", "PreModelSwitch", "PostModelSwitch"];
|
|
3
|
+
type HookEventWord = (typeof HOOK_EVENTS)[number];
|
|
4
|
+
declare const HOOK_ENTRY_TYPES: readonly ["command", "prompt", "agent", "http", "mcp_tool"];
|
|
5
|
+
export type HookEntryType = (typeof HOOK_ENTRY_TYPES)[number];
|
|
6
|
+
declare const HOOK_SHELLS: readonly ["bash", "powershell"];
|
|
7
|
+
declare const HOOK_ENTRY_FIELDS: {
|
|
8
|
+
readonly command: {
|
|
9
|
+
readonly if: "string?";
|
|
10
|
+
readonly timeout: "seconds?";
|
|
11
|
+
readonly statusMessage: "string?";
|
|
12
|
+
readonly once: "boolean?";
|
|
13
|
+
readonly command: "text";
|
|
14
|
+
readonly shell: "shell?";
|
|
15
|
+
readonly async: "boolean?";
|
|
16
|
+
readonly asyncRewake: "boolean?";
|
|
17
|
+
};
|
|
18
|
+
readonly prompt: {
|
|
19
|
+
readonly if: "string?";
|
|
20
|
+
readonly timeout: "seconds?";
|
|
21
|
+
readonly statusMessage: "string?";
|
|
22
|
+
readonly once: "boolean?";
|
|
23
|
+
readonly prompt: "text";
|
|
24
|
+
readonly model: "string?";
|
|
25
|
+
};
|
|
26
|
+
readonly agent: {
|
|
27
|
+
readonly if: "string?";
|
|
28
|
+
readonly timeout: "seconds?";
|
|
29
|
+
readonly statusMessage: "string?";
|
|
30
|
+
readonly once: "boolean?";
|
|
31
|
+
readonly prompt: "text";
|
|
32
|
+
readonly model: "string?";
|
|
33
|
+
};
|
|
34
|
+
readonly http: {
|
|
35
|
+
readonly if: "string?";
|
|
36
|
+
readonly timeout: "seconds?";
|
|
37
|
+
readonly statusMessage: "string?";
|
|
38
|
+
readonly once: "boolean?";
|
|
39
|
+
readonly url: "text";
|
|
40
|
+
readonly headers: "stringRecord?";
|
|
41
|
+
readonly allowedEnvVars: "stringList?";
|
|
42
|
+
};
|
|
43
|
+
readonly mcp_tool: {
|
|
44
|
+
readonly if: "string?";
|
|
45
|
+
readonly timeout: "seconds?";
|
|
46
|
+
readonly statusMessage: "string?";
|
|
47
|
+
readonly once: "boolean?";
|
|
48
|
+
readonly server: "string";
|
|
49
|
+
readonly tool: "string";
|
|
50
|
+
readonly input: "record?";
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
type HookFieldBaseValue<B> = B extends "text" | "string" ? string : B extends "shell" ? (typeof HOOK_SHELLS)[number] : B extends "boolean" ? boolean : B extends "seconds" ? number : B extends "stringRecord" ? Record<string, string> : B extends "stringList" ? string[] : B extends "record" ? Record<string, unknown> : never;
|
|
54
|
+
type HookFieldValue<K> = K extends `${infer B}?` ? HookFieldBaseValue<B> : HookFieldBaseValue<K>;
|
|
55
|
+
type Flat<O> = {
|
|
56
|
+
[K in keyof O]: O[K];
|
|
57
|
+
};
|
|
58
|
+
type HookEntryOf<T extends HookEntryType, F = (typeof HOOK_ENTRY_FIELDS)[T]> = Flat<{
|
|
59
|
+
type: T;
|
|
60
|
+
} & {
|
|
61
|
+
-readonly [K in keyof F as F[K] extends `${string}?` ? never : K]: HookFieldValue<F[K]>;
|
|
62
|
+
} & {
|
|
63
|
+
-readonly [K in keyof F as F[K] extends `${string}?` ? K : never]?: HookFieldValue<F[K]>;
|
|
64
|
+
}>;
|
|
65
|
+
export type HookEntry = {
|
|
66
|
+
[T in HookEntryType]: HookEntryOf<T>;
|
|
67
|
+
}[HookEntryType];
|
|
68
|
+
export type HookMatcherEntry = {
|
|
69
|
+
matcher?: string;
|
|
70
|
+
hooks: HookEntry[];
|
|
71
|
+
};
|
|
72
|
+
export type HooksConfig = Partial<Record<HookEventWord, HookMatcherEntry[]>>;
|
|
73
|
+
declare const HOOKS_CLASSIFICATION_OUTCOMES: readonly ["loaded", "loaded-partial", "rejected"];
|
|
74
|
+
export type HooksClassificationOutcome = (typeof HOOKS_CLASSIFICATION_OUTCOMES)[number];
|
|
75
|
+
declare const HOOKS_DROPPED_PIECE_CODES: readonly ["hooks-not-object", "unknown-event", "event-not-array", "matcher-invalid", "entry-invalid"];
|
|
76
|
+
export type HooksDroppedPieceCode = (typeof HOOKS_DROPPED_PIECE_CODES)[number];
|
|
77
|
+
declare const HOOKS_REJECTION_CODES: readonly ["guard-outside-hooks", "hooks-is-matcher", "guard-under-unknown-event", "guard-event-not-array", "guard-matcher-invalid", "guard-entry-invalid"];
|
|
78
|
+
export type HooksRejectionCode = (typeof HOOKS_REJECTION_CODES)[number];
|
|
79
|
+
export interface HooksDroppedPiece {
|
|
80
|
+
readonly code: HooksDroppedPieceCode;
|
|
81
|
+
readonly path: ConfigPath;
|
|
82
|
+
readonly field?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface HooksRejection {
|
|
85
|
+
readonly code: HooksRejectionCode;
|
|
86
|
+
readonly path: ConfigPath;
|
|
87
|
+
readonly field?: string;
|
|
88
|
+
}
|
|
89
|
+
export type HooksClassification = {
|
|
90
|
+
readonly outcome: "loaded";
|
|
91
|
+
readonly hooks: HooksConfig | undefined;
|
|
92
|
+
readonly dropped: readonly [];
|
|
93
|
+
readonly rejections: readonly [];
|
|
94
|
+
} | {
|
|
95
|
+
readonly outcome: "loaded-partial";
|
|
96
|
+
readonly hooks: HooksConfig | undefined;
|
|
97
|
+
readonly dropped: readonly HooksDroppedPiece[];
|
|
98
|
+
readonly rejections: readonly [];
|
|
99
|
+
} | {
|
|
100
|
+
readonly outcome: "rejected";
|
|
101
|
+
readonly hooks: undefined;
|
|
102
|
+
readonly dropped: readonly [];
|
|
103
|
+
readonly rejections: readonly HooksRejection[];
|
|
104
|
+
};
|
|
105
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UiLanguage } from '../env/uiLanguage.js';
|
|
1
2
|
export interface ApprovalAllowRuleShadowMember {
|
|
2
3
|
readonly member?: string;
|
|
3
4
|
readonly known: boolean;
|
|
@@ -11,11 +12,16 @@ export interface AllowRuleShadowedWireMember {
|
|
|
11
12
|
readonly omitted?: number;
|
|
12
13
|
}
|
|
13
14
|
export interface ApprovalAllowRuleShadow {
|
|
14
|
-
readonly source: 'allow_rule_shadowed'
|
|
15
|
+
readonly source: 'allow_rule_shadowed';
|
|
15
16
|
readonly members: readonly ApprovalAllowRuleShadowMember[];
|
|
16
17
|
readonly unreadable?: true;
|
|
17
18
|
}
|
|
19
|
+
export declare const RETIRED_SHADOW_EVIDENCE_LABEL: Readonly<{
|
|
20
|
+
readonly frame: "persistedRuleShadowed";
|
|
21
|
+
readonly row: "riskDescriptor.shadowedRule";
|
|
22
|
+
}>;
|
|
23
|
+
export declare function retiredAllowRuleShadowKeyPresent(carrier: object | null | undefined, leg: 'frame' | 'row'): boolean;
|
|
18
24
|
export declare function readAllowRuleShadowFromWire(carrier: object | null | undefined, leg: 'frame' | 'row'): ApprovalAllowRuleShadow | undefined;
|
|
19
25
|
export declare function readApprovalAllowRuleShadow(card: object | null | undefined): ApprovalAllowRuleShadow | undefined;
|
|
20
26
|
export declare function approvalAllowRuleShadowed(card: object | null | undefined): boolean;
|
|
21
|
-
export declare function allowRuleShadowSentence(card: object | null | undefined): string | undefined;
|
|
27
|
+
export declare function allowRuleShadowSentence(card: object | null | undefined, lang?: UiLanguage): string | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CORE_ALLOW_RULE_MEMBERS } from '../generated/engineFactTables.js';
|
|
2
2
|
import { quoteUntrustedForSentence } from '../displayUntrusted.js';
|
|
3
|
+
import { msg, renderMessage } from '../i18n/translate.js';
|
|
3
4
|
const KNOWN_MEMBERS = new Set(CORE_ALLOW_RULE_MEMBERS);
|
|
4
5
|
function freezeMember(m) {
|
|
5
6
|
return Object.freeze({ ...m });
|
|
@@ -76,20 +77,27 @@ function readNewKeyValue(raw) {
|
|
|
76
77
|
return unreadable();
|
|
77
78
|
return Object.freeze({ source: 'allow_rule_shadowed', members: Object.freeze(members) });
|
|
78
79
|
}
|
|
79
|
-
function readLegacyValue(raw) {
|
|
80
|
-
if (typeof raw !== 'string' || raw.trim() === '')
|
|
81
|
-
return undefined;
|
|
82
|
-
return Object.freeze({
|
|
83
|
-
source: 'legacy_shadowed_rule',
|
|
84
|
-
members: Object.freeze([freezeMember({ member: 'persisted', known: true, entries: Object.freeze([raw]) })]),
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
80
|
function ownValue(v, key) {
|
|
88
81
|
return Object.hasOwn(v, key) ? v[key] : undefined;
|
|
89
82
|
}
|
|
90
83
|
function keyValue(v, key) {
|
|
91
84
|
return v[key];
|
|
92
85
|
}
|
|
86
|
+
const RETIRED_SHADOW_KEY = Object.freeze({ frame: 'persistedRuleShadowed', row: 'shadowedRule' });
|
|
87
|
+
export const RETIRED_SHADOW_EVIDENCE_LABEL = Object.freeze({ frame: 'persistedRuleShadowed', row: 'riskDescriptor.shadowedRule' });
|
|
88
|
+
export function retiredAllowRuleShadowKeyPresent(carrier, leg) {
|
|
89
|
+
try {
|
|
90
|
+
if (typeof carrier !== 'object' || carrier === null)
|
|
91
|
+
return false;
|
|
92
|
+
const host = leg === 'row' ? keyValue(carrier, 'riskDescriptor') : carrier;
|
|
93
|
+
if (typeof host !== 'object' || host === null)
|
|
94
|
+
return false;
|
|
95
|
+
return RETIRED_SHADOW_KEY[leg] in host;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
93
101
|
function readMemberAt(arr, i) {
|
|
94
102
|
const d = Object.getOwnPropertyDescriptor(arr, i);
|
|
95
103
|
return d !== undefined && 'value' in d ? readMemberRecord(d.value) : freezeMember({ known: false, malformed: true });
|
|
@@ -105,10 +113,7 @@ export function readAllowRuleShadowFromWire(carrier, leg) {
|
|
|
105
113
|
}
|
|
106
114
|
if (host === undefined)
|
|
107
115
|
return undefined;
|
|
108
|
-
|
|
109
|
-
if (fresh !== undefined)
|
|
110
|
-
return fresh;
|
|
111
|
-
return readLegacyValue(keyValue(host, leg === 'row' ? 'shadowedRule' : 'persistedRuleShadowed'));
|
|
116
|
+
return readNewKeyValue(keyValue(host, 'allowRuleShadowed'));
|
|
112
117
|
}
|
|
113
118
|
catch {
|
|
114
119
|
return unreadable();
|
|
@@ -119,7 +124,7 @@ function readStampedValue(raw) {
|
|
|
119
124
|
return unreadable();
|
|
120
125
|
const source = ownValue(raw, 'source');
|
|
121
126
|
const members = ownValue(raw, 'members');
|
|
122
|
-
if (
|
|
127
|
+
if (source !== 'allow_rule_shadowed' || !Array.isArray(members))
|
|
123
128
|
return unreadable();
|
|
124
129
|
const length = members.length;
|
|
125
130
|
if (typeof length !== 'number' || !Number.isSafeInteger(length))
|
|
@@ -158,8 +163,7 @@ export function approvalAllowRuleShadowed(card) {
|
|
|
158
163
|
const ENTRY_MAX = 4096;
|
|
159
164
|
const MEMBER_MAX = 64;
|
|
160
165
|
const ENTRIES_SHOWN = 5;
|
|
161
|
-
|
|
162
|
-
function legacySingleEntry(shadow) {
|
|
166
|
+
function singlePersistedEntry(shadow) {
|
|
163
167
|
if (shadow.unreadable === true || shadow.members.length !== 1)
|
|
164
168
|
return undefined;
|
|
165
169
|
const m = shadow.members[0];
|
|
@@ -169,12 +173,12 @@ function legacySingleEntry(shadow) {
|
|
|
169
173
|
return undefined;
|
|
170
174
|
return quoteUntrustedForSentence(m.entries[0], ENTRY_MAX);
|
|
171
175
|
}
|
|
172
|
-
function memberPhrase(m) {
|
|
176
|
+
function memberPhrase(m, lang) {
|
|
173
177
|
const memberWord = m.member === undefined ? undefined : KNOWN_MEMBERS.has(m.member) ? m.member : quoteUntrustedForSentence(m.member, MEMBER_MAX);
|
|
174
|
-
const word = memberWord ?? '
|
|
178
|
+
const word = memberWord ?? msg('approval.card.shadow.unrecognisedSource');
|
|
175
179
|
const entries = m.entries ?? [];
|
|
176
180
|
if (m.malformed === true && entries.length === 0)
|
|
177
|
-
return
|
|
181
|
+
return renderMessage(msg('approval.card.shadow.memberUnreadable', { word }), lang);
|
|
178
182
|
const listed = entries
|
|
179
183
|
.map((e) => quoteUntrustedForSentence(e, ENTRY_MAX))
|
|
180
184
|
.filter((e) => e !== undefined)
|
|
@@ -184,25 +188,28 @@ function memberPhrase(m) {
|
|
|
184
188
|
if (listed.length > 0)
|
|
185
189
|
parts.push(listed.join(', '));
|
|
186
190
|
if (notListed > 0)
|
|
187
|
-
parts.push(listed.length > 0 ?
|
|
191
|
+
parts.push(renderMessage(listed.length > 0 ? msg('approval.card.shadow.moreNotListed', { count: notListed }) : msg('approval.card.shadow.notListed', { count: notListed }), lang));
|
|
188
192
|
if (m.malformed === true)
|
|
189
|
-
parts.push('
|
|
190
|
-
return parts.length > 0
|
|
193
|
+
parts.push(renderMessage(msg('approval.card.shadow.partUnreadable'), lang));
|
|
194
|
+
return parts.length > 0
|
|
195
|
+
? renderMessage(msg('approval.card.shadow.memberWithParts', { word, parts: parts.join(renderMessage(msg('approval.card.shadow.partJoin'), lang)) }), lang)
|
|
196
|
+
: typeof word === 'string'
|
|
197
|
+
? word
|
|
198
|
+
: renderMessage(word, lang);
|
|
191
199
|
}
|
|
192
|
-
export function allowRuleShadowSentence(card) {
|
|
200
|
+
export function allowRuleShadowSentence(card, lang) {
|
|
193
201
|
const shadow = readApprovalAllowRuleShadow(card);
|
|
194
202
|
if (shadow === undefined)
|
|
195
203
|
return undefined;
|
|
196
204
|
try {
|
|
197
205
|
if (shadow.unreadable === true || shadow.members.length === 0)
|
|
198
|
-
return
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
return
|
|
202
|
-
}
|
|
203
|
-
return `Allow rules matched this call but cannot clear it, so this one is confirmed individually — ${shadow.members.map(memberPhrase).join(' · ')}.`;
|
|
206
|
+
return renderMessage(msg('approval.card.shadow.unreadable'), lang);
|
|
207
|
+
const single = singlePersistedEntry(shadow);
|
|
208
|
+
if (single !== undefined)
|
|
209
|
+
return renderMessage(msg('approval.card.shadow.single', { entry: single }), lang);
|
|
210
|
+
return renderMessage(msg('approval.card.shadow.several', { members: shadow.members.map((m) => memberPhrase(m, lang)).join(' · ') }), lang);
|
|
204
211
|
}
|
|
205
212
|
catch {
|
|
206
|
-
return
|
|
213
|
+
return renderMessage(msg('approval.card.shadow.unreadable'), lang);
|
|
207
214
|
}
|
|
208
215
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApprovalCardRequest } from './toolApprovalWire.js';
|
|
2
|
+
export declare function readRequiresRealApproval(carrier: object | null | undefined): boolean;
|
|
3
|
+
export interface ApprovalWindowKeys {
|
|
4
|
+
readonly expiresInMs?: number;
|
|
5
|
+
readonly expiresAtMs?: number;
|
|
6
|
+
readonly serverNowMs?: number;
|
|
7
|
+
readonly receivedAtMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ApprovalWindowReadOpts {
|
|
10
|
+
readonly windowIsCurrent?: boolean;
|
|
11
|
+
readonly receivedAtMs?: number;
|
|
12
|
+
readonly unknownShape?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function approvalWindowKeysOf(carrier: object | null | undefined, opts?: ApprovalWindowReadOpts | null): Readonly<ApprovalWindowKeys>;
|
|
15
|
+
export declare function probeCauseRowsOf(card: Pick<ApprovalCardRequest, 'probeCause'> | null | undefined): readonly string[] | undefined;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { displayUntrusted } from '../displayUntrusted.js';
|
|
2
|
+
import { guardedRead, readOwnDataValue } from '../ownKey.js';
|
|
3
|
+
export function readRequiresRealApproval(carrier) {
|
|
4
|
+
if (typeof carrier !== 'object' || carrier === null)
|
|
5
|
+
return false;
|
|
6
|
+
let failed = false;
|
|
7
|
+
let failure;
|
|
8
|
+
try {
|
|
9
|
+
if (carrier.requiresRealApproval === true)
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
failed = true;
|
|
14
|
+
failure = e;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const risk = carrier.risk;
|
|
18
|
+
if (typeof risk === 'object' && risk !== null && risk.requiresRealApproval === true)
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (!failed)
|
|
23
|
+
failure = e;
|
|
24
|
+
failed = true;
|
|
25
|
+
}
|
|
26
|
+
if (failed)
|
|
27
|
+
throw failure;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const EMPTY = Object.freeze({});
|
|
31
|
+
const UNKNOWN_SHAPE_COHERENCE_TOLERANCE_MS = 1_000;
|
|
32
|
+
function nonNegativeFinite(v) {
|
|
33
|
+
return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : undefined;
|
|
34
|
+
}
|
|
35
|
+
export function approvalWindowKeysOf(carrier, opts) {
|
|
36
|
+
if (typeof carrier !== 'object' || carrier === null)
|
|
37
|
+
return EMPTY;
|
|
38
|
+
if (typeof opts !== 'object' || opts === null)
|
|
39
|
+
return EMPTY;
|
|
40
|
+
let current;
|
|
41
|
+
let anchor;
|
|
42
|
+
let unknownShape;
|
|
43
|
+
try {
|
|
44
|
+
current = opts.windowIsCurrent;
|
|
45
|
+
anchor = opts.receivedAtMs;
|
|
46
|
+
unknownShape = opts.unknownShape;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return EMPTY;
|
|
50
|
+
}
|
|
51
|
+
if (current !== true)
|
|
52
|
+
return EMPTY;
|
|
53
|
+
const read = (key) => {
|
|
54
|
+
try {
|
|
55
|
+
return nonNegativeFinite(carrier[key]);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const inMs = read('expiresInMs');
|
|
62
|
+
const atMs = read('expiresAtMs');
|
|
63
|
+
const nowMs = read('serverNowMs');
|
|
64
|
+
if (unknownShape === true) {
|
|
65
|
+
if (inMs === undefined || atMs === undefined || nowMs === undefined)
|
|
66
|
+
return EMPTY;
|
|
67
|
+
if (atMs <= 0 || nowMs <= 0)
|
|
68
|
+
return EMPTY;
|
|
69
|
+
if (Math.abs(inMs - Math.max(0, atMs - nowMs)) > UNKNOWN_SHAPE_COHERENCE_TOLERANCE_MS)
|
|
70
|
+
return EMPTY;
|
|
71
|
+
}
|
|
72
|
+
const receivedAtMs = nonNegativeFinite(anchor);
|
|
73
|
+
const out = {};
|
|
74
|
+
if (inMs !== undefined)
|
|
75
|
+
out.expiresInMs = inMs;
|
|
76
|
+
if (atMs !== undefined)
|
|
77
|
+
out.expiresAtMs = atMs;
|
|
78
|
+
if (nowMs !== undefined)
|
|
79
|
+
out.serverNowMs = nowMs;
|
|
80
|
+
if ((inMs !== undefined || atMs !== undefined) && receivedAtMs !== undefined)
|
|
81
|
+
out.receivedAtMs = receivedAtMs;
|
|
82
|
+
return Object.freeze(out);
|
|
83
|
+
}
|
|
84
|
+
const PROBE_CAUSE_SHOWN_MAX = 8;
|
|
85
|
+
const PROBE_CAUSE_ENTRY_MAX = 200;
|
|
86
|
+
function own(v, key) {
|
|
87
|
+
if (typeof v !== 'object' || v === null)
|
|
88
|
+
return undefined;
|
|
89
|
+
return guardedRead(() => readOwnDataValue(v, key));
|
|
90
|
+
}
|
|
91
|
+
function readOperands(v) {
|
|
92
|
+
if (typeof v !== 'object' || v === null)
|
|
93
|
+
return undefined;
|
|
94
|
+
const shown = own(v, 'shown');
|
|
95
|
+
const isList = guardedRead(() => Array.isArray(shown));
|
|
96
|
+
if (isList !== true)
|
|
97
|
+
return undefined;
|
|
98
|
+
const length = own(shown, 'length');
|
|
99
|
+
if (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0)
|
|
100
|
+
return undefined;
|
|
101
|
+
const items = [];
|
|
102
|
+
for (let i = 0; i < length; i++) {
|
|
103
|
+
const item = own(shown, String(i));
|
|
104
|
+
if (typeof item !== 'string')
|
|
105
|
+
return undefined;
|
|
106
|
+
items.push(item);
|
|
107
|
+
}
|
|
108
|
+
const total = own(v, 'total');
|
|
109
|
+
if (typeof total !== 'number' || !Number.isSafeInteger(total) || total < 0 || total < items.length)
|
|
110
|
+
return undefined;
|
|
111
|
+
return { shown: items, total };
|
|
112
|
+
}
|
|
113
|
+
function operandsText(label, o) {
|
|
114
|
+
const shown = o.shown.slice(0, PROBE_CAUSE_SHOWN_MAX).map((p) => displayUntrusted(p, { max: PROBE_CAUSE_ENTRY_MAX }));
|
|
115
|
+
if (shown.length === 0)
|
|
116
|
+
return `${label}: ${String(o.total)} total`;
|
|
117
|
+
const more = o.total - shown.length;
|
|
118
|
+
return more > 0 ? `${label}: ${shown.join(', ')} (+${String(more)} more)` : `${label}: ${shown.join(', ')}`;
|
|
119
|
+
}
|
|
120
|
+
export function probeCauseRowsOf(card) {
|
|
121
|
+
try {
|
|
122
|
+
if (typeof card !== 'object' || card === null)
|
|
123
|
+
return undefined;
|
|
124
|
+
const cause = own(card, 'probeCause');
|
|
125
|
+
if (typeof cause !== 'object' || cause === null)
|
|
126
|
+
return undefined;
|
|
127
|
+
if (guardedRead(() => Array.isArray(cause)) !== false)
|
|
128
|
+
return undefined;
|
|
129
|
+
const code = own(cause, 'code');
|
|
130
|
+
if (typeof code !== 'string' || code === '')
|
|
131
|
+
return undefined;
|
|
132
|
+
const roots = readOperands(own(cause, 'roots'));
|
|
133
|
+
if (roots === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
let fd;
|
|
136
|
+
try {
|
|
137
|
+
fd = Object.getOwnPropertyDescriptor(cause, 'further');
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
if (fd === undefined || (Object.hasOwn(fd, 'value') && fd.value === undefined))
|
|
143
|
+
return Object.freeze([operandsText('roots', roots)]);
|
|
144
|
+
if (!Object.hasOwn(fd, 'value'))
|
|
145
|
+
return undefined;
|
|
146
|
+
const further = readOperands(fd.value);
|
|
147
|
+
if (further === undefined)
|
|
148
|
+
return undefined;
|
|
149
|
+
return Object.freeze([operandsText('roots', roots), operandsText('further', further)]);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { UiLanguage } from '../env/uiLanguage.js';
|
|
2
|
+
import { type DenialLimitFallback } from './toolApprovalWire.js';
|
|
3
|
+
export declare const APPROVAL_CARD_REASON_SOURCES: readonly ["payload_unreadable", "prior_cards", "message", "mandated", "mandate", "origin", "denial_limit", "probe", "allow_rule_shadow", "classifier_no_ruling", "bound_grants", "more"];
|
|
4
|
+
export type ApprovalCardReasonSource = (typeof APPROVAL_CARD_REASON_SOURCES)[number];
|
|
5
|
+
export interface ApprovalCardReasonLine {
|
|
6
|
+
readonly source: ApprovalCardReasonSource;
|
|
7
|
+
readonly text: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ApprovalCardReasonsOptions {
|
|
10
|
+
readonly maxLines?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const APPROVAL_CARD_REASONS_DEFAULT_MAX_LINES = 4;
|
|
13
|
+
export declare function denialLimitFallbackDetail(v: DenialLimitFallback | null | undefined, lang?: UiLanguage): string | undefined;
|
|
14
|
+
export declare function approvalCardReasons(card: object | null | undefined, opts?: ApprovalCardReasonsOptions | null, lang?: UiLanguage): readonly ApprovalCardReasonLine[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { displayUntrusted } from '../displayUntrusted.js';
|
|
2
|
+
import { msg, renderMessage } from '../i18n/translate.js';
|
|
3
|
+
import { approvalMandateDetail, askOriginNoteOf } from '../gateVocabulary.js';
|
|
4
|
+
import { readAskOrigin, readOwnDataValue, guardedRead } from '../ownKey.js';
|
|
5
|
+
import { allowRuleShadowSentence } from './allowRuleShadow.js';
|
|
6
|
+
import { mandatedApprovalDetailOf } from './automaticAnswerVerdict.js';
|
|
7
|
+
import { approvalBoundGrantsDetail, approvalIsMandated, approvalPriorCardsDetail, askProbeReasonDetail, classifierNoRulingDetail, readApprovalBoundGrants, readApprovalClassifierNoRuling, readApprovalMandate, readDenialLimitFallback, } from './toolApprovalWire.js';
|
|
8
|
+
export const APPROVAL_CARD_REASON_SOURCES = Object.freeze([
|
|
9
|
+
'payload_unreadable',
|
|
10
|
+
'prior_cards',
|
|
11
|
+
'message',
|
|
12
|
+
'mandated',
|
|
13
|
+
'mandate',
|
|
14
|
+
'origin',
|
|
15
|
+
'denial_limit',
|
|
16
|
+
'probe',
|
|
17
|
+
'allow_rule_shadow',
|
|
18
|
+
'classifier_no_ruling',
|
|
19
|
+
'bound_grants',
|
|
20
|
+
'more',
|
|
21
|
+
]);
|
|
22
|
+
export const APPROVAL_CARD_REASONS_DEFAULT_MAX_LINES = 4;
|
|
23
|
+
const MESSAGE_DISPLAY_MAX = 300;
|
|
24
|
+
function payloadUnreadableDetail(lang) {
|
|
25
|
+
return renderMessage(msg('approval.card.payloadUnreadable'), lang);
|
|
26
|
+
}
|
|
27
|
+
function moreDetail(n, lang) {
|
|
28
|
+
return renderMessage(n === 1 ? msg('approval.card.more.one') : msg('approval.card.more.other', { count: n }), lang);
|
|
29
|
+
}
|
|
30
|
+
export function denialLimitFallbackDetail(v, lang) {
|
|
31
|
+
const d = readDenialLimitFallback(v);
|
|
32
|
+
if (d === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
const limit = displayUntrusted(d.limit, { max: 24 });
|
|
35
|
+
return renderMessage(d.autoDenyAfterMs > 0
|
|
36
|
+
? msg('approval.card.denialLimit.withAutoDeny', { consecutive: d.consecutive, total: d.total, limit, seconds: Math.round(d.autoDenyAfterMs / 1000) })
|
|
37
|
+
: msg('approval.card.denialLimit.plain', { consecutive: d.consecutive, total: d.total, limit }), lang);
|
|
38
|
+
}
|
|
39
|
+
function ownData(card, key) {
|
|
40
|
+
return guardedRead(() => readOwnDataValue(card, key));
|
|
41
|
+
}
|
|
42
|
+
function readMaxLines(opts) {
|
|
43
|
+
const raw = typeof opts === 'object' && opts !== null ? guardedRead(() => readOwnDataValue(opts, 'maxLines')) : undefined;
|
|
44
|
+
return typeof raw === 'number' && Number.isSafeInteger(raw) && raw >= 1 ? raw : APPROVAL_CARD_REASONS_DEFAULT_MAX_LINES;
|
|
45
|
+
}
|
|
46
|
+
export function approvalCardReasons(card, opts, lang) {
|
|
47
|
+
if (typeof card !== 'object' || card === null)
|
|
48
|
+
return Object.freeze([]);
|
|
49
|
+
const raw = [];
|
|
50
|
+
const add = (source, read) => {
|
|
51
|
+
let text;
|
|
52
|
+
try {
|
|
53
|
+
text = read();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
text = undefined;
|
|
57
|
+
}
|
|
58
|
+
raw.push({ source, text });
|
|
59
|
+
};
|
|
60
|
+
let denialLimitReadable = false;
|
|
61
|
+
try {
|
|
62
|
+
denialLimitReadable = readDenialLimitFallback(ownData(card, 'denialLimitFallback')) !== undefined;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
denialLimitReadable = false;
|
|
66
|
+
}
|
|
67
|
+
add('payload_unreadable', () => (ownData(card, 'cardPayloadUnreadable') === true ? payloadUnreadableDetail(lang) : undefined));
|
|
68
|
+
add('prior_cards', () => approvalPriorCardsDetail(card, lang));
|
|
69
|
+
add('message', () => {
|
|
70
|
+
const engineMessage = ownData(card, 'message');
|
|
71
|
+
if (typeof engineMessage !== 'string' || engineMessage.trim() === '')
|
|
72
|
+
return undefined;
|
|
73
|
+
const tool = ownData(card, 'toolName');
|
|
74
|
+
if (typeof tool === 'string' && engineMessage.trim() === `approval required for "${tool}"`)
|
|
75
|
+
return undefined;
|
|
76
|
+
return displayUntrusted(engineMessage, { max: MESSAGE_DISPLAY_MAX });
|
|
77
|
+
});
|
|
78
|
+
add('mandated', () => (approvalIsMandated(card) ? mandatedApprovalDetailOf(card, lang) : undefined));
|
|
79
|
+
add('mandate', () => {
|
|
80
|
+
const word = readApprovalMandate(card);
|
|
81
|
+
return word !== undefined ? approvalMandateDetail(word, lang) : undefined;
|
|
82
|
+
});
|
|
83
|
+
add('origin', () => {
|
|
84
|
+
const origin = readAskOrigin(card);
|
|
85
|
+
if (origin === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
if (origin === 'denial_limit_fallback' && denialLimitReadable)
|
|
88
|
+
return undefined;
|
|
89
|
+
return askOriginNoteOf(origin, lang);
|
|
90
|
+
});
|
|
91
|
+
add('denial_limit', () => denialLimitFallbackDetail(ownData(card, 'denialLimitFallback'), lang));
|
|
92
|
+
add('probe', () => askProbeReasonDetail(card, lang));
|
|
93
|
+
add('allow_rule_shadow', () => allowRuleShadowSentence(card, lang));
|
|
94
|
+
add('classifier_no_ruling', () => {
|
|
95
|
+
const word = readApprovalClassifierNoRuling(card);
|
|
96
|
+
return word !== undefined ? classifierNoRulingDetail(word, lang) : undefined;
|
|
97
|
+
});
|
|
98
|
+
add('bound_grants', () => {
|
|
99
|
+
const grants = readApprovalBoundGrants(card);
|
|
100
|
+
return grants !== undefined ? approvalBoundGrantsDetail(grants, lang) : undefined;
|
|
101
|
+
});
|
|
102
|
+
const seen = new Set();
|
|
103
|
+
const lines = [];
|
|
104
|
+
for (const r of raw) {
|
|
105
|
+
if (r.text === undefined)
|
|
106
|
+
continue;
|
|
107
|
+
const text = displayUntrusted(r.text);
|
|
108
|
+
if (text === '' || seen.has(text))
|
|
109
|
+
continue;
|
|
110
|
+
seen.add(text);
|
|
111
|
+
lines.push(Object.freeze({ source: r.source, text }));
|
|
112
|
+
}
|
|
113
|
+
const max = readMaxLines(opts);
|
|
114
|
+
if (lines.length <= max)
|
|
115
|
+
return Object.freeze(lines);
|
|
116
|
+
const kept = lines.slice(0, max - 1);
|
|
117
|
+
kept.push(Object.freeze({ source: 'more', text: moreDetail(lines.length - kept.length, lang) }));
|
|
118
|
+
return Object.freeze(kept);
|
|
119
|
+
}
|