@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,242 @@
|
|
|
1
|
+
import { atMostOnceVerdictOf } from './atMostOnce.js';
|
|
2
|
+
import { readOwnDataValue } from './ownKey.js';
|
|
3
|
+
const LANE_ABSENT = 'capability.device_lane_required';
|
|
4
|
+
const RUN_STORE_ABSENT = 'capability.run_store_required';
|
|
5
|
+
const NOT_FOUND = 'not_found.device';
|
|
6
|
+
const ACTIVE_RUN = 'device.rebind_active_run';
|
|
7
|
+
const REV_CONFLICT = 'device.rebind_rev_conflict';
|
|
8
|
+
const SERVICE_TOKEN_REQUIRED = 'auth.service_token_required';
|
|
9
|
+
function own(v, key) {
|
|
10
|
+
if (v === null || typeof v !== 'object')
|
|
11
|
+
return undefined;
|
|
12
|
+
try {
|
|
13
|
+
return readOwnDataValue(v, key);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function slot(e, key) {
|
|
20
|
+
if (e === null || (typeof e !== 'object' && typeof e !== 'function'))
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
return e[key];
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function nonEmpty(v) {
|
|
30
|
+
return typeof v === 'string' && v !== '' ? v : undefined;
|
|
31
|
+
}
|
|
32
|
+
function nonNegInt(v) {
|
|
33
|
+
return typeof v === 'number' && Number.isInteger(v) && v >= 0 ? v : undefined;
|
|
34
|
+
}
|
|
35
|
+
function isArraySafely(v) {
|
|
36
|
+
try {
|
|
37
|
+
return Array.isArray(v);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function refusedOf(status, code, e) {
|
|
44
|
+
const message = nonEmpty(slot(e, 'message'));
|
|
45
|
+
return { kind: 'refused', status, ...(code !== undefined ? { errorCode: code } : {}), ...(message !== undefined ? { message } : {}) };
|
|
46
|
+
}
|
|
47
|
+
function transportOf(v) {
|
|
48
|
+
return { kind: 'transport', ...(v.name !== undefined ? { detail: v.name } : {}) };
|
|
49
|
+
}
|
|
50
|
+
function commonOf(status, code) {
|
|
51
|
+
if (status === 501 && code === LANE_ABSENT)
|
|
52
|
+
return { kind: 'lane-absent' };
|
|
53
|
+
if (status === 501 && code === RUN_STORE_ABSENT)
|
|
54
|
+
return { kind: 'lane-absent', runStoreOnly: true };
|
|
55
|
+
if (status === 404 && code === NOT_FOUND)
|
|
56
|
+
return { kind: 'not-found' };
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function readFailureOf(e) {
|
|
60
|
+
const v = atMostOnceVerdictOf(e);
|
|
61
|
+
const common = commonOf(v.status, v.code);
|
|
62
|
+
if (common !== null)
|
|
63
|
+
return common;
|
|
64
|
+
return v.status !== undefined ? refusedOf(v.status, v.code, e) : transportOf(v);
|
|
65
|
+
}
|
|
66
|
+
function verbOf(slice, name) {
|
|
67
|
+
const v = slot(slice, name);
|
|
68
|
+
return typeof v === 'function' ? v : undefined;
|
|
69
|
+
}
|
|
70
|
+
function signalOpts(opts) {
|
|
71
|
+
const s = slot(opts, 'signal');
|
|
72
|
+
return s !== undefined && s !== null ? { signal: s } : {};
|
|
73
|
+
}
|
|
74
|
+
function rowOf(raw) {
|
|
75
|
+
const deviceId = nonEmpty(own(raw, 'deviceId'));
|
|
76
|
+
if (deviceId === undefined)
|
|
77
|
+
return null;
|
|
78
|
+
const st = own(raw, 'status');
|
|
79
|
+
const name = nonEmpty(own(raw, 'name'));
|
|
80
|
+
const lastSeenAt = nonEmpty(own(raw, 'lastSeenAt'));
|
|
81
|
+
return {
|
|
82
|
+
deviceId,
|
|
83
|
+
...(name !== undefined ? { name } : {}),
|
|
84
|
+
status: st === 'online' ? 'online' : st === 'offline' ? 'offline' : 'unknown',
|
|
85
|
+
...(lastSeenAt !== undefined ? { lastSeenAt } : {}),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export async function listDevices(devices, opts) {
|
|
89
|
+
const verb = verbOf(devices, 'list');
|
|
90
|
+
if (verb === undefined)
|
|
91
|
+
return { kind: 'unarmed' };
|
|
92
|
+
let body;
|
|
93
|
+
try {
|
|
94
|
+
body = await verb.call(devices, signalOpts(opts));
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
const f = readFailureOf(e);
|
|
98
|
+
return f.kind === 'not-found' ? refusedOf(404, NOT_FOUND, e) : f;
|
|
99
|
+
}
|
|
100
|
+
const raw = own(body, 'devices');
|
|
101
|
+
if (!isArraySafely(raw)) {
|
|
102
|
+
return { kind: 'unreadable', why: 'the body carries no device list (the `devices` key is absent or not an array) — refusing to render that as an empty roster' };
|
|
103
|
+
}
|
|
104
|
+
const rows = [];
|
|
105
|
+
let dropped = 0;
|
|
106
|
+
const len = nonNegInt(own(raw, 'length')) ?? 0;
|
|
107
|
+
for (let i = 0; i < len; i++) {
|
|
108
|
+
const r = rowOf(own(raw, String(i)));
|
|
109
|
+
if (r === null)
|
|
110
|
+
dropped++;
|
|
111
|
+
else
|
|
112
|
+
rows.push(r);
|
|
113
|
+
}
|
|
114
|
+
return { kind: 'ok', devices: rows, dropped };
|
|
115
|
+
}
|
|
116
|
+
function bindingOf(raw) {
|
|
117
|
+
const deviceId = nonEmpty(own(raw, 'deviceId'));
|
|
118
|
+
const rev = nonNegInt(own(raw, 'rev'));
|
|
119
|
+
if (deviceId === undefined || rev === undefined)
|
|
120
|
+
return null;
|
|
121
|
+
const boundAt = nonEmpty(own(raw, 'boundAt'));
|
|
122
|
+
return { deviceId, rev, ...(boundAt !== undefined ? { boundAt } : {}) };
|
|
123
|
+
}
|
|
124
|
+
export async function readSessionBinding(devices, rootSessionId, opts) {
|
|
125
|
+
const verb = verbOf(devices, 'sessionBinding');
|
|
126
|
+
if (verb === undefined)
|
|
127
|
+
return { kind: 'unarmed' };
|
|
128
|
+
let body;
|
|
129
|
+
try {
|
|
130
|
+
body = await verb.call(devices, rootSessionId, signalOpts(opts));
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
return readFailureOf(e);
|
|
134
|
+
}
|
|
135
|
+
const rid = own(body, 'rootSessionId');
|
|
136
|
+
if (typeof rid !== 'string' || rid !== rootSessionId) {
|
|
137
|
+
return { kind: 'unreadable', why: "the binding it returned does not echo the session id that was asked for — refusing to use another session's binding as this one's prior state" };
|
|
138
|
+
}
|
|
139
|
+
const bound = bindingOf(own(body, 'boundDevice'));
|
|
140
|
+
if (bound === null) {
|
|
141
|
+
return { kind: 'unreadable', why: 'the binding it returned has no usable prior state (deviceId + rev) — refusing to treat it as a binding' };
|
|
142
|
+
}
|
|
143
|
+
return { kind: 'ok', rootSessionId: rid, boundDevice: bound };
|
|
144
|
+
}
|
|
145
|
+
function rebindFailureOf(e) {
|
|
146
|
+
const v = atMostOnceVerdictOf(e);
|
|
147
|
+
const { status, code } = v;
|
|
148
|
+
const common = commonOf(status, code);
|
|
149
|
+
if (common !== null)
|
|
150
|
+
return common;
|
|
151
|
+
if (status === 409 && code === ACTIVE_RUN) {
|
|
152
|
+
const activeTaskId = nonEmpty(own(e, 'activeTaskId'));
|
|
153
|
+
return { kind: 'active-run', ...(activeTaskId !== undefined ? { activeTaskId } : {}) };
|
|
154
|
+
}
|
|
155
|
+
if (status === 409 && code === REV_CONFLICT) {
|
|
156
|
+
const currentRev = nonNegInt(own(e, 'currentRev'));
|
|
157
|
+
return { kind: 'rev-conflict', ...(currentRev !== undefined ? { currentRev } : {}) };
|
|
158
|
+
}
|
|
159
|
+
if (status === 503 && code === SERVICE_TOKEN_REQUIRED)
|
|
160
|
+
return refusedOf(status, code, e);
|
|
161
|
+
if (v.delivery === 'rejected' && status !== undefined)
|
|
162
|
+
return refusedOf(status, code, e);
|
|
163
|
+
if (status !== undefined)
|
|
164
|
+
return { kind: 'unconfirmed', why: 'server-error', detail: String(status), mayStillBeRunning: true };
|
|
165
|
+
return { kind: 'unconfirmed', why: 'transport', ...(v.name !== undefined ? { detail: v.name } : {}), mayStillBeRunning: true };
|
|
166
|
+
}
|
|
167
|
+
export async function rebindSession(devices, req, opts) {
|
|
168
|
+
const rootSessionId = slot(req, 'rootSessionId');
|
|
169
|
+
const toDeviceId = slot(req, 'toDeviceId');
|
|
170
|
+
const expectedRev = slot(req, 'expectedRev');
|
|
171
|
+
const fromDeviceId = slot(req, 'fromDeviceId');
|
|
172
|
+
if (nonNegInt(expectedRev) === undefined) {
|
|
173
|
+
return {
|
|
174
|
+
kind: 'refused',
|
|
175
|
+
status: 0,
|
|
176
|
+
errorCode: 'request.field_invalid',
|
|
177
|
+
message: 'expectedRev must be a non-negative integer read from the current binding — refusing to send a made-up prior state',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const verb = verbOf(devices, 'rebind');
|
|
181
|
+
if (verb === undefined)
|
|
182
|
+
return { kind: 'unarmed' };
|
|
183
|
+
let body;
|
|
184
|
+
try {
|
|
185
|
+
body = await verb.call(devices, rootSessionId, { toDeviceId, expectedRev }, signalOpts(opts));
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
return rebindFailureOf(e);
|
|
189
|
+
}
|
|
190
|
+
const deviceId = nonEmpty(own(body, 'deviceId'));
|
|
191
|
+
const rev = nonNegInt(own(body, 'rev'));
|
|
192
|
+
const echoed = own(body, 'rootSessionId');
|
|
193
|
+
const prior = expectedRev;
|
|
194
|
+
const sound = deviceId !== undefined &&
|
|
195
|
+
rev !== undefined &&
|
|
196
|
+
typeof echoed === 'string' &&
|
|
197
|
+
echoed === rootSessionId &&
|
|
198
|
+
deviceId === toDeviceId &&
|
|
199
|
+
(rev === prior + 1 || (rev === prior && fromDeviceId === toDeviceId));
|
|
200
|
+
if (!sound)
|
|
201
|
+
return { kind: 'unconfirmed', why: 'accepted-unreadable', mayStillBeRunning: false };
|
|
202
|
+
const carry = own(body, 'workspaceCarryover') === 'none' ? 'none' : undefined;
|
|
203
|
+
return { kind: 'ok', deviceId, rev, ...(carry !== undefined ? { workspaceCarryover: carry } : {}) };
|
|
204
|
+
}
|
|
205
|
+
export function reconcileRebindOutcome(before, toDeviceId, after, opts) {
|
|
206
|
+
if (after === null)
|
|
207
|
+
return 'unknown';
|
|
208
|
+
const b = bindingOf(before);
|
|
209
|
+
const a = bindingOf(after);
|
|
210
|
+
if (b === null || a === null || typeof toDeviceId !== 'string')
|
|
211
|
+
return 'unknown';
|
|
212
|
+
const onTarget = a.deviceId === toDeviceId;
|
|
213
|
+
const revStepped = a.rev === b.rev + 1;
|
|
214
|
+
const revStatic = a.rev === b.rev;
|
|
215
|
+
const wasMoveRequest = b.deviceId !== toDeviceId;
|
|
216
|
+
if (onTarget && revStepped && wasMoveRequest)
|
|
217
|
+
return 'landed';
|
|
218
|
+
if (slot(opts, 'serverMayStillBeRunning') !== false)
|
|
219
|
+
return 'unknown';
|
|
220
|
+
if (onTarget && revStatic && !wasMoveRequest)
|
|
221
|
+
return 'already-there';
|
|
222
|
+
if (!onTarget && a.deviceId === b.deviceId && revStatic)
|
|
223
|
+
return 'unchanged';
|
|
224
|
+
return 'unknown';
|
|
225
|
+
}
|
|
226
|
+
export function rebindProvesRequestNotApplied(outcome) {
|
|
227
|
+
const kind = slot(outcome, 'kind');
|
|
228
|
+
switch (kind) {
|
|
229
|
+
case 'active-run':
|
|
230
|
+
case 'rev-conflict':
|
|
231
|
+
case 'not-found':
|
|
232
|
+
case 'lane-absent':
|
|
233
|
+
case 'unarmed':
|
|
234
|
+
return true;
|
|
235
|
+
case 'refused': {
|
|
236
|
+
const status = slot(outcome, 'status');
|
|
237
|
+
return typeof status === 'number' && (status < 500 || slot(outcome, 'errorCode') === SERVICE_TOKEN_REQUIRED);
|
|
238
|
+
}
|
|
239
|
+
default:
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -8,9 +8,6 @@ export interface DisplayFace {
|
|
|
8
8
|
readonly mark: DisplayMark;
|
|
9
9
|
readonly keepBlanks?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare const LEGACY_ESCAPE_FACE: DisplayFace;
|
|
12
|
-
export declare const LEGACY_LABEL_FACE: DisplayFace;
|
|
13
|
-
export declare const LEGACY_NAME_FACE: DisplayFace;
|
|
14
11
|
export declare function applyDisplayFace(text: string, face: DisplayFace): string;
|
|
15
12
|
export interface DisplayUntrustedOptions {
|
|
16
13
|
readonly credentialUrls?: boolean;
|
|
@@ -33,9 +30,17 @@ export interface DisplayUntrustedMarked {
|
|
|
33
30
|
readonly text: string;
|
|
34
31
|
readonly marks: readonly DisplayMarkSpan[];
|
|
35
32
|
}
|
|
33
|
+
export declare const ESCAPE_FACE: DisplayFace;
|
|
34
|
+
export declare const LABEL_FACE: DisplayFace;
|
|
35
|
+
export declare const PEER_NAME_FACE: DisplayFace;
|
|
36
|
+
export declare function capDisplay(text: string, max: number | undefined, mark: DisplayMark): string;
|
|
37
|
+
export declare function paintAndCap(text: string, face: DisplayFace, max?: number): string;
|
|
36
38
|
export declare function credentialWashPasses(text: string, opts?: DisplayUntrustedOptions | null): {
|
|
37
39
|
passes: number;
|
|
38
40
|
capped: boolean;
|
|
39
41
|
};
|
|
40
42
|
export declare function displayUntrusted(text: string, opts?: DisplayUntrustedOptions): string;
|
|
43
|
+
export declare function queryCarriesCredential(query: string): boolean;
|
|
44
|
+
export declare function displayConfiguredUrl(url: string, opts?: DisplayUntrustedOptions): string;
|
|
45
|
+
export declare function quoteUntrustedForSentence(text: string, max: number): string | undefined;
|
|
41
46
|
export declare function displayUntrustedMarks(text: string, opts?: DisplayUntrustedOptions): DisplayUntrustedMarked;
|