@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,335 @@
|
|
|
1
|
+
export const USAGE_SENTENCES = Object.freeze({
|
|
2
|
+
analyticsUnavailable: 'Usage analytics aren’t available on this backend.',
|
|
3
|
+
analyticsUnread: 'Usage analytics couldn’t be read just now.',
|
|
4
|
+
modelsUnavailable: "Per-model usage breakdown isn't available on this backend.",
|
|
5
|
+
modelsUnread: 'Per-model usage breakdown couldn’t be read just now.',
|
|
6
|
+
});
|
|
7
|
+
const _sdkClientIsAnInjection = [true];
|
|
8
|
+
void _sdkClientIsAnInjection;
|
|
9
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
10
|
+
const nonNeg = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0;
|
|
11
|
+
const nonEmpty = (v) => typeof v === 'string' && v.length > 0;
|
|
12
|
+
export function classifyUsageFailure(e) {
|
|
13
|
+
let code;
|
|
14
|
+
let status;
|
|
15
|
+
try {
|
|
16
|
+
const o = e;
|
|
17
|
+
const rawCode = o?.errorCode;
|
|
18
|
+
const rawStatus = o?.status;
|
|
19
|
+
code = typeof rawCode === 'string' ? rawCode : undefined;
|
|
20
|
+
status = typeof rawStatus === 'number' ? rawStatus : undefined;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return { kind: 'failed', error: e };
|
|
24
|
+
}
|
|
25
|
+
if (code !== undefined) {
|
|
26
|
+
if (code.startsWith('capability.'))
|
|
27
|
+
return { kind: 'unavailable', why: 'capability' };
|
|
28
|
+
if (code.startsWith('feature.'))
|
|
29
|
+
return { kind: 'unavailable', why: 'feature' };
|
|
30
|
+
if (code === 'not_found.route')
|
|
31
|
+
return { kind: 'unavailable', why: 'route' };
|
|
32
|
+
return { kind: 'failed', error: e };
|
|
33
|
+
}
|
|
34
|
+
if (status === 501)
|
|
35
|
+
return { kind: 'unavailable', why: 'capability' };
|
|
36
|
+
return { kind: 'failed', error: e };
|
|
37
|
+
}
|
|
38
|
+
function windowOf(o) {
|
|
39
|
+
const w = { truncated: o.truncated === true };
|
|
40
|
+
if (nonEmpty(o.from))
|
|
41
|
+
w.from = o.from;
|
|
42
|
+
if (nonEmpty(o.to))
|
|
43
|
+
w.to = o.to;
|
|
44
|
+
return w;
|
|
45
|
+
}
|
|
46
|
+
const precisionOf = (estimated) => (estimated === false ? 'exact' : 'estimated');
|
|
47
|
+
const TOTAL_FIELDS = ['tasks', 'tokensIn', 'tokensOut', 'cost'];
|
|
48
|
+
const TOTAL_WIRE_KEYS = Object.freeze({ tasks: 'tasks', tokensIn: 'tokensIn', tokensOut: 'tokensOut', cost: 'costUsd' });
|
|
49
|
+
function totalsOf(o) {
|
|
50
|
+
const t = { precision: precisionOf(o.estimated) };
|
|
51
|
+
for (const field of TOTAL_FIELDS) {
|
|
52
|
+
const v = o[TOTAL_WIRE_KEYS[field]];
|
|
53
|
+
if (nonNeg(v))
|
|
54
|
+
t[field] = v;
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
export function projectUsageSummary(body) {
|
|
59
|
+
try {
|
|
60
|
+
if (!isRecord(body))
|
|
61
|
+
return undefined;
|
|
62
|
+
return { ...windowOf(body), ...totalsOf(body) };
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function projectUsageSeries(body) {
|
|
69
|
+
try {
|
|
70
|
+
if (!isRecord(body))
|
|
71
|
+
return undefined;
|
|
72
|
+
const series = body.series;
|
|
73
|
+
if (!Array.isArray(series))
|
|
74
|
+
return undefined;
|
|
75
|
+
const points = [];
|
|
76
|
+
let unreadable = 0;
|
|
77
|
+
for (const raw of series) {
|
|
78
|
+
if (!isRecord(raw) || typeof raw.t !== 'string' || usageInstantOf(raw.t) === undefined || !nonNeg(raw.v)) {
|
|
79
|
+
unreadable++;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const p = { t: raw.t, v: raw.v };
|
|
83
|
+
if (typeof raw.estimated === 'boolean')
|
|
84
|
+
p.estimated = raw.estimated;
|
|
85
|
+
points.push(p);
|
|
86
|
+
}
|
|
87
|
+
return { ...windowOf(body), points, unreadable };
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function projectUsageBreakdown(body) {
|
|
94
|
+
try {
|
|
95
|
+
if (!isRecord(body))
|
|
96
|
+
return undefined;
|
|
97
|
+
const breakdown = body.breakdown;
|
|
98
|
+
if (!Array.isArray(breakdown))
|
|
99
|
+
return undefined;
|
|
100
|
+
const rows = [];
|
|
101
|
+
let unreadable = 0;
|
|
102
|
+
for (const raw of breakdown) {
|
|
103
|
+
if (!isRecord(raw) || !nonEmpty(raw.key)) {
|
|
104
|
+
unreadable++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
rows.push({ key: raw.key, ...totalsOf(raw) });
|
|
108
|
+
}
|
|
109
|
+
return { ...windowOf(body), rows, unreadable };
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function windowBag(opts) {
|
|
116
|
+
const bag = {};
|
|
117
|
+
if (opts.from !== undefined)
|
|
118
|
+
bag.from = opts.from;
|
|
119
|
+
if (opts.to !== undefined)
|
|
120
|
+
bag.to = opts.to;
|
|
121
|
+
if (opts.principal !== undefined)
|
|
122
|
+
bag.principal = opts.principal;
|
|
123
|
+
if (opts.signal !== undefined)
|
|
124
|
+
bag.signal = opts.signal;
|
|
125
|
+
return bag;
|
|
126
|
+
}
|
|
127
|
+
async function readOne(call, project, what) {
|
|
128
|
+
try {
|
|
129
|
+
const pending = call();
|
|
130
|
+
if (pending === undefined)
|
|
131
|
+
return { kind: 'unavailable', why: 'route' };
|
|
132
|
+
const view = project(await pending);
|
|
133
|
+
if (view === undefined)
|
|
134
|
+
return { kind: 'failed', error: new Error(`usage ${what}: malformed body`) };
|
|
135
|
+
return { kind: 'ok', value: view };
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
return classifyUsageFailure(e);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export function readUsageSummary(client, opts = {}) {
|
|
142
|
+
return readOne(() => (typeof client?.usage?.summary === 'function' ? client.usage.summary(windowBag(opts)) : undefined), projectUsageSummary, 'summary');
|
|
143
|
+
}
|
|
144
|
+
export function readUsageSeries(client, opts = {}) {
|
|
145
|
+
return readOne(() => {
|
|
146
|
+
if (typeof client?.usage?.series !== 'function')
|
|
147
|
+
return undefined;
|
|
148
|
+
const bag = windowBag(opts);
|
|
149
|
+
if (opts.metric !== undefined)
|
|
150
|
+
bag.metric = opts.metric;
|
|
151
|
+
if (opts.granularity !== undefined)
|
|
152
|
+
bag.granularity = opts.granularity;
|
|
153
|
+
return client.usage.series(bag);
|
|
154
|
+
}, projectUsageSeries, 'series');
|
|
155
|
+
}
|
|
156
|
+
export function readUsageBreakdown(client, opts = {}) {
|
|
157
|
+
return readOne(() => {
|
|
158
|
+
if (typeof client?.usage?.breakdown !== 'function')
|
|
159
|
+
return undefined;
|
|
160
|
+
const bag = windowBag(opts);
|
|
161
|
+
if (opts.dimension !== undefined)
|
|
162
|
+
bag.dimension = opts.dimension;
|
|
163
|
+
return client.usage.breakdown(bag);
|
|
164
|
+
}, projectUsageBreakdown, 'breakdown');
|
|
165
|
+
}
|
|
166
|
+
export function usageBoundPrefix(bound) {
|
|
167
|
+
return bound === 'lower' ? '≥' : bound === 'approximate' ? '≈' : '';
|
|
168
|
+
}
|
|
169
|
+
const DAY_MS = 86_400_000;
|
|
170
|
+
export const USAGE_HEATMAP_MAX_DAYS = 70;
|
|
171
|
+
export function usageWindowOfRange(range, now) {
|
|
172
|
+
if (range === 'all')
|
|
173
|
+
return { from: 0, to: now };
|
|
174
|
+
const days = range === '30d' ? 30 : 7;
|
|
175
|
+
return { from: now - days * DAY_MS, to: now };
|
|
176
|
+
}
|
|
177
|
+
function unavailableCauseOf(v) {
|
|
178
|
+
return v.kind === 'unavailable' ? 'no_backend_face' : 'read_failed';
|
|
179
|
+
}
|
|
180
|
+
function modelsUnavailable(cause) {
|
|
181
|
+
return { state: 'unavailable', cause, sentence: cause === 'no_backend_face' ? USAGE_SENTENCES.modelsUnavailable : USAGE_SENTENCES.modelsUnread };
|
|
182
|
+
}
|
|
183
|
+
const USAGE_TS_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[Tt ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?([Zz]|[+-]\d{2}:?\d{2}))?$/;
|
|
184
|
+
const OFFSET_RE = /^([+-])(\d{2}):?(\d{2})$/;
|
|
185
|
+
function usageInstantOf(t) {
|
|
186
|
+
if (typeof t !== 'string')
|
|
187
|
+
return undefined;
|
|
188
|
+
const m = USAGE_TS_RE.exec(t);
|
|
189
|
+
if (m === null)
|
|
190
|
+
return undefined;
|
|
191
|
+
const y = Number(m[1]);
|
|
192
|
+
const mo = Number(m[2]);
|
|
193
|
+
const d = Number(m[3]);
|
|
194
|
+
const date = new Date(Date.UTC(y, mo - 1, d));
|
|
195
|
+
if (date.getUTCFullYear() !== y || date.getUTCMonth() !== mo - 1 || date.getUTCDate() !== d)
|
|
196
|
+
return undefined;
|
|
197
|
+
if (m[4] === undefined)
|
|
198
|
+
return { dayKey: t.slice(0, 10), hourUtc: 0 };
|
|
199
|
+
const hh = Number(m[4]);
|
|
200
|
+
const mi = Number(m[5]);
|
|
201
|
+
const ss = m[6] === undefined ? 0 : Number(m[6]);
|
|
202
|
+
if (hh > 23 || mi > 59 || ss > 59)
|
|
203
|
+
return undefined;
|
|
204
|
+
let offsetMin = 0;
|
|
205
|
+
const zone = m[7];
|
|
206
|
+
if (zone !== 'Z' && zone !== 'z') {
|
|
207
|
+
const o = OFFSET_RE.exec(zone);
|
|
208
|
+
if (o === null)
|
|
209
|
+
return undefined;
|
|
210
|
+
const oh = Number(o[2]);
|
|
211
|
+
const om = Number(o[3]);
|
|
212
|
+
if (oh > 23 || om > 59)
|
|
213
|
+
return undefined;
|
|
214
|
+
offsetMin = (o[1] === '-' ? -1 : 1) * (oh * 60 + om);
|
|
215
|
+
}
|
|
216
|
+
const at = new Date(date.getTime() + ((hh * 60 + mi - offsetMin) * 60 + ss) * 1000);
|
|
217
|
+
const iso = at.toISOString();
|
|
218
|
+
if (!/^\d{4}-/.test(iso))
|
|
219
|
+
return undefined;
|
|
220
|
+
return { dayKey: iso.slice(0, 10), hourUtc: at.getUTCHours() };
|
|
221
|
+
}
|
|
222
|
+
const isWhole = (v) => v.unreadable === 0 && !v.truncated;
|
|
223
|
+
function peakHourOf(points) {
|
|
224
|
+
if (points.length === 0)
|
|
225
|
+
return undefined;
|
|
226
|
+
const perHour = new Array(24).fill(0);
|
|
227
|
+
for (const p of points) {
|
|
228
|
+
const at = usageInstantOf(p.t);
|
|
229
|
+
if (at === undefined)
|
|
230
|
+
return undefined;
|
|
231
|
+
perHour[at.hourUtc] = (perHour[at.hourUtc] ?? 0) + p.v;
|
|
232
|
+
}
|
|
233
|
+
let peakHour = -1;
|
|
234
|
+
let peakValue = -1;
|
|
235
|
+
perHour.forEach((value, h) => {
|
|
236
|
+
if (value > peakValue) {
|
|
237
|
+
peakValue = value;
|
|
238
|
+
peakHour = h;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
return peakHour >= 0 && peakValue > 0 ? peakHour : undefined;
|
|
242
|
+
}
|
|
243
|
+
function heatmapOf(window, dayValues) {
|
|
244
|
+
if (!Number.isFinite(window.from) || !Number.isFinite(window.to))
|
|
245
|
+
return null;
|
|
246
|
+
const windowDays = Math.max(1, Math.round((window.to - window.from) / DAY_MS) + 1);
|
|
247
|
+
const days = Math.min(windowDays, USAGE_HEATMAP_MAX_DAYS);
|
|
248
|
+
const cells = [];
|
|
249
|
+
for (let i = days - 1; i >= 0; i--) {
|
|
250
|
+
const at = new Date(window.to - i * DAY_MS);
|
|
251
|
+
if (Number.isNaN(at.getTime()))
|
|
252
|
+
return null;
|
|
253
|
+
const key = at.toISOString().slice(0, 10);
|
|
254
|
+
cells.push({ date: key, tasks: dayValues.get(key) ?? 0 });
|
|
255
|
+
}
|
|
256
|
+
return cells;
|
|
257
|
+
}
|
|
258
|
+
export function projectUsageAnalytics(inputs, window) {
|
|
259
|
+
const s = inputs.summary;
|
|
260
|
+
if (s.kind !== 'ok') {
|
|
261
|
+
const cause = unavailableCauseOf(s);
|
|
262
|
+
return {
|
|
263
|
+
state: 'unavailable',
|
|
264
|
+
cause,
|
|
265
|
+
sentence: cause === 'no_backend_face' ? USAGE_SENTENCES.analyticsUnavailable : USAGE_SENTENCES.analyticsUnread,
|
|
266
|
+
models: modelsUnavailable(cause),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
const sv = s.value;
|
|
270
|
+
const readings = {
|
|
271
|
+
state: sv.precision === 'estimated' ? 'estimated' : 'available',
|
|
272
|
+
truncated: sv.truncated,
|
|
273
|
+
heatmap: null,
|
|
274
|
+
models: modelsUnavailable('read_failed'),
|
|
275
|
+
};
|
|
276
|
+
if (sv.tasks !== undefined)
|
|
277
|
+
readings.runs = sv.tasks;
|
|
278
|
+
const exact = sv.precision === 'exact';
|
|
279
|
+
if (sv.tokensIn !== undefined && sv.tokensOut !== undefined) {
|
|
280
|
+
readings.tokens = { value: sv.tokensIn + sv.tokensOut, bound: !exact ? 'approximate' : sv.truncated ? 'lower' : 'exact' };
|
|
281
|
+
}
|
|
282
|
+
if (sv.cost !== undefined)
|
|
283
|
+
readings.cost = { value: sv.cost, bound: exact && !sv.truncated ? 'exact' : 'lower' };
|
|
284
|
+
const day = inputs.daySeries;
|
|
285
|
+
if (day.kind === 'ok' && isWhole(day.value)) {
|
|
286
|
+
const dayValues = new Map();
|
|
287
|
+
let allKeysReadable = true;
|
|
288
|
+
for (const p of day.value.points) {
|
|
289
|
+
const at = usageInstantOf(p.t);
|
|
290
|
+
if (at === undefined)
|
|
291
|
+
allKeysReadable = false;
|
|
292
|
+
else
|
|
293
|
+
dayValues.set(at.dayKey, (dayValues.get(at.dayKey) ?? 0) + p.v);
|
|
294
|
+
}
|
|
295
|
+
if (allKeysReadable) {
|
|
296
|
+
readings.activeDays = [...dayValues.values()].filter((v) => v > 0).length;
|
|
297
|
+
readings.heatmap = heatmapOf(window, dayValues);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const hour = inputs.hourSeries;
|
|
301
|
+
if (hour.kind === 'ok' && isWhole(hour.value)) {
|
|
302
|
+
const peak = peakHourOf(hour.value.points);
|
|
303
|
+
if (peak !== undefined)
|
|
304
|
+
readings.peakHourUtc = peak;
|
|
305
|
+
}
|
|
306
|
+
const br = inputs.modelBreakdown;
|
|
307
|
+
if (br.kind === 'ok') {
|
|
308
|
+
readings.models = { state: 'available', rows: br.value.rows, unreadable: br.value.unreadable };
|
|
309
|
+
if (isWhole(br.value)) {
|
|
310
|
+
let favorite;
|
|
311
|
+
for (const row of br.value.rows) {
|
|
312
|
+
if (row.tasks === undefined)
|
|
313
|
+
continue;
|
|
314
|
+
if (favorite === undefined || row.tasks > (favorite.tasks ?? -1))
|
|
315
|
+
favorite = row;
|
|
316
|
+
}
|
|
317
|
+
if (favorite !== undefined)
|
|
318
|
+
readings.favoriteModel = favorite.key;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
readings.models = modelsUnavailable(unavailableCauseOf(br));
|
|
323
|
+
}
|
|
324
|
+
return readings;
|
|
325
|
+
}
|
|
326
|
+
export async function readUsageAnalytics(client, window, opts = {}) {
|
|
327
|
+
const base = { from: window.from, to: window.to, ...(opts.signal ? { signal: opts.signal } : {}) };
|
|
328
|
+
const [summary, daySeries, hourSeries, modelBreakdown] = await Promise.all([
|
|
329
|
+
readUsageSummary(client, base),
|
|
330
|
+
readUsageSeries(client, { ...base, metric: 'tasks', granularity: 'day' }),
|
|
331
|
+
readUsageSeries(client, { ...base, metric: 'tasks', granularity: 'hour' }),
|
|
332
|
+
readUsageBreakdown(client, { ...base, dimension: 'model' }),
|
|
333
|
+
]);
|
|
334
|
+
return projectUsageAnalytics({ summary, daySeries, hourSeries, modelBreakdown }, window);
|
|
335
|
+
}
|
|
@@ -14,5 +14,3 @@ export declare function noteEngineCapsForUserInvokedSkills(baseUrl: string, caps
|
|
|
14
14
|
export declare function observedUserInvokedSkills(baseUrl?: string | undefined): UserInvokedSkillsReading;
|
|
15
15
|
export declare function userInvokedSkillsAvailable(reading: UserInvokedSkillsReading): 'yes' | 'no' | 'unknown';
|
|
16
16
|
export declare function userInvokedSkillsDoctorDetail(reading: UserInvokedSkillsReading): string;
|
|
17
|
-
export declare function forgetUserInvokedSkillsReading(baseUrl: string | undefined): void;
|
|
18
|
-
export declare function __resetUserInvokedSkillsReadingsForTests(): void;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { engineWireTarget } from './engineWireTarget.js';
|
|
2
2
|
import { createEngineCapReader } from './engineCapReader.js';
|
|
3
|
+
import { ownDataField } from './ownKey.js';
|
|
3
4
|
export function projectUserInvokedSkillsCapability(caps) {
|
|
4
5
|
try {
|
|
5
6
|
if (caps === null || typeof caps !== 'object' || Array.isArray(caps))
|
|
6
7
|
return undefined;
|
|
7
|
-
|
|
8
|
-
return { kind: 'not_reported' };
|
|
9
|
-
const v = caps.userInvokedSkills;
|
|
8
|
+
const v = ownDataField(caps, 'userInvokedSkills');
|
|
10
9
|
if (v === undefined)
|
|
11
10
|
return { kind: 'not_reported' };
|
|
12
11
|
if (typeof v !== 'boolean')
|
|
@@ -47,9 +46,3 @@ export function userInvokedSkillsDoctorDetail(reading) {
|
|
|
47
46
|
return 'user-invoked skills on — skills the user names on a request take effect when the run starts';
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
export function forgetUserInvokedSkillsReading(baseUrl) {
|
|
51
|
-
reader.forget(baseUrl);
|
|
52
|
-
}
|
|
53
|
-
export function __resetUserInvokedSkillsReadingsForTests() {
|
|
54
|
-
reader.__resetForTests();
|
|
55
|
-
}
|
|
@@ -18,5 +18,4 @@ export declare function noteEngineCapsForWebSearchBackend(baseUrl: string, caps:
|
|
|
18
18
|
}): void;
|
|
19
19
|
export declare function observedWebSearchBackend(baseUrl?: string | undefined): WebSearchBackendReading;
|
|
20
20
|
export declare function webSearchBackendDoctorDetail(reading: WebSearchBackendReading): string;
|
|
21
|
-
export declare function forgetWebSearchBackendReading(baseUrl: string | undefined): void;
|
|
22
21
|
export declare function __resetWebSearchBackendReadingsForTests(): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { capForDisplay } from './fleetTaskDesc.js';
|
|
2
2
|
import { engineWireTarget } from './engineWireTarget.js';
|
|
3
3
|
import { createEngineCapReader } from './engineCapReader.js';
|
|
4
|
+
import { ownDataField } from './ownKey.js';
|
|
4
5
|
export const WEB_SEARCH_BACKEND_NONE = 'none';
|
|
5
6
|
export function projectWebSearchBackendCapability(caps) {
|
|
6
7
|
try {
|
|
@@ -8,14 +9,12 @@ export function projectWebSearchBackendCapability(caps) {
|
|
|
8
9
|
return undefined;
|
|
9
10
|
if (caps === null || typeof caps !== 'object' || Array.isArray(caps))
|
|
10
11
|
return undefined;
|
|
11
|
-
|
|
12
|
-
return { kind: 'not_reported' };
|
|
13
|
-
const ws = caps.webSearch;
|
|
12
|
+
const ws = ownDataField(caps, 'webSearch');
|
|
14
13
|
if (ws === undefined)
|
|
15
14
|
return { kind: 'not_reported' };
|
|
16
15
|
if (ws === null || typeof ws !== 'object' || Array.isArray(ws))
|
|
17
16
|
return undefined;
|
|
18
|
-
const backend = ws
|
|
17
|
+
const backend = ownDataField(ws, 'backend');
|
|
19
18
|
if (typeof backend !== 'string' || backend === '')
|
|
20
19
|
return undefined;
|
|
21
20
|
if (backend === WEB_SEARCH_BACKEND_NONE)
|
|
@@ -56,9 +55,6 @@ export function webSearchBackendDoctorDetail(reading) {
|
|
|
56
55
|
'(per-request overrides are not echoed here)');
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
export function forgetWebSearchBackendReading(baseUrl) {
|
|
60
|
-
reader.forget(baseUrl);
|
|
61
|
-
}
|
|
62
58
|
export function __resetWebSearchBackendReadingsForTests() {
|
|
63
59
|
reader.__resetForTests();
|
|
64
60
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SETTINGS_IS_HIERARCHICAL_URL } from './generated/settingsSchemaFns.js';
|
|
1
2
|
import { hostEnv } from './hostEnv.js';
|
|
2
3
|
export const WEBSEARCH_ENV = {
|
|
3
4
|
provider: 'SEMA_WEBSEARCH_PROVIDER',
|
|
@@ -6,15 +7,6 @@ export const WEBSEARCH_ENV = {
|
|
|
6
7
|
maxResults: 'SEMA_WEBSEARCH_MAX_RESULTS',
|
|
7
8
|
};
|
|
8
9
|
const isBlankText = (v) => v.trim() === '';
|
|
9
|
-
function isHierarchicalUrl(raw) {
|
|
10
|
-
try {
|
|
11
|
-
const u = new URL(raw);
|
|
12
|
-
return u.href.startsWith(u.protocol + '//');
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
10
|
function judgeProvider(raw) {
|
|
19
11
|
const word = typeof raw === 'string' ? raw.trim().toLowerCase() : undefined;
|
|
20
12
|
if (word === 'brave' || word === 'tavily' || word === 'searxng')
|
|
@@ -71,7 +63,7 @@ function judgeEndpoint(raw) {
|
|
|
71
63
|
return { ok: false, issue: ENDPOINT_ISSUE };
|
|
72
64
|
if (isBlankText(raw))
|
|
73
65
|
return { ok: true, value: undefined };
|
|
74
|
-
if (!
|
|
66
|
+
if (!SETTINGS_IS_HIERARCHICAL_URL(raw))
|
|
75
67
|
return { ok: false, issue: ENDPOINT_ISSUE };
|
|
76
68
|
const u = new URL(raw);
|
|
77
69
|
return u.username !== '' || u.password !== ''
|
|
@@ -236,7 +228,7 @@ export function webSearchVerdictMessage(verdict, context = 'submit') {
|
|
|
236
228
|
: `Web search is misconfigured: ${where} ${verdict.issue}. Requests will be refused until you ${fix}.`;
|
|
237
229
|
}
|
|
238
230
|
export function webSearchEndpointForDisplay(raw) {
|
|
239
|
-
if (typeof raw !== 'string' || !
|
|
231
|
+
if (typeof raw !== 'string' || !SETTINGS_IS_HIERARCHICAL_URL(raw))
|
|
240
232
|
return undefined;
|
|
241
233
|
try {
|
|
242
234
|
const u = new URL(raw);
|
|
@@ -43,6 +43,8 @@ export interface ScenarioDenyDetail {
|
|
|
43
43
|
allowlist: string[];
|
|
44
44
|
}
|
|
45
45
|
export declare function scenarioDenyFromError(err: unknown): ScenarioDenyDetail | null;
|
|
46
|
+
export type ScenarioDenySurface = 'request' | 'resumed_work';
|
|
47
|
+
export declare function scenarioNotAllowedContent(detail: ScenarioDenyDetail, requestedScenario?: string, surface?: ScenarioDenySurface): string;
|
|
46
48
|
export interface ResumeRetryLaterDetail {
|
|
47
49
|
code: string;
|
|
48
50
|
retryAfterSec?: number;
|
package/dist/wireErrorTriage.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { readErrorNumber, readErrorString, readErrorStringList } from './wireFailureShape.js';
|
|
2
|
-
import { capForDisplay } from './fleetTaskDesc.js';
|
|
1
|
+
import { readBlockedBy, readErrorNumber, readErrorString, readErrorStringList } from './wireFailureShape.js';
|
|
2
|
+
import { capForDisplay, escapeDisplayControlChars } from './fleetTaskDesc.js';
|
|
3
3
|
import { readOwnDataValue } from './ownKey.js';
|
|
4
4
|
import { fleetLeaseUnavailableFromError } from './wireRefusalCopy.js';
|
|
5
5
|
import { DRAINING_ERROR_CODE, isCorruptSessionCode, RESUME_AT_ERROR_CODE_PREFIX, RESUME_POLICY_FOLD_CODE, RESUME_RETRY_LATER_CODES, RESUME_USAGE_WINDOW_EXHAUSTED, SCENARIO_NOT_ALLOWED_ERROR_CODE, } from './engineErrorCodes.js';
|
|
6
|
-
export const WIRE_NETWORK_ERROR_PATTERN = /fetch failed|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|EHOSTUNREACH|ENETUNREACH|EPIPE|socket hang up|UND_ERR
|
|
6
|
+
export const WIRE_NETWORK_ERROR_PATTERN = /fetch failed|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|EHOSTUNREACH|ENETUNREACH|EPIPE|socket hang up|UND_ERR|\bterminated\b|\bother side closed\b/i;
|
|
7
7
|
function wireErrorDetail(err) {
|
|
8
8
|
const e = err;
|
|
9
9
|
const cause = e?.cause;
|
|
@@ -64,8 +64,8 @@ export function effectiveWireErrorCode(err) {
|
|
|
64
64
|
const outer = typeof outerRaw === 'string' && outerRaw.length > 0 ? outerRaw : undefined;
|
|
65
65
|
if (outer !== RESUME_POLICY_FOLD_CODE)
|
|
66
66
|
return outer;
|
|
67
|
-
const inner =
|
|
68
|
-
return inner
|
|
67
|
+
const inner = readBlockedBy(err);
|
|
68
|
+
return inner.kind === 'named' ? inner.code : outer;
|
|
69
69
|
}
|
|
70
70
|
export function corruptStoredRowWhere(err) {
|
|
71
71
|
if (effectiveWireErrorCode(err) !== 'corrupt')
|
|
@@ -151,6 +151,35 @@ export function scenarioDenyFromError(err) {
|
|
|
151
151
|
const allowlist = (readErrorStringList(err, 'allowlist') ?? []).filter((x) => x.length > 0);
|
|
152
152
|
return { allowlist };
|
|
153
153
|
}
|
|
154
|
+
export function scenarioNotAllowedContent(detail, requestedScenario, surface) {
|
|
155
|
+
const resumed = surface === 'resumed_work';
|
|
156
|
+
const names = [];
|
|
157
|
+
try {
|
|
158
|
+
const raw = detail?.allowlist;
|
|
159
|
+
if (Array.isArray(raw)) {
|
|
160
|
+
const n = raw.length;
|
|
161
|
+
for (let i = 0; i < n; i++) {
|
|
162
|
+
const item = raw[i];
|
|
163
|
+
if (typeof item === 'string' && item.length > 0)
|
|
164
|
+
names.push(escapeDisplayControlChars(item));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
names.length = 0;
|
|
170
|
+
}
|
|
171
|
+
const subject = typeof requestedScenario === 'string' && requestedScenario.length > 0
|
|
172
|
+
? `Scenario "${escapeDisplayControlChars(requestedScenario)}" is not in your allowed list`
|
|
173
|
+
: resumed
|
|
174
|
+
? 'The scenario this work resumes under is not in your allowed list'
|
|
175
|
+
: 'The requested scenario is not in your allowed list';
|
|
176
|
+
const parts = [subject];
|
|
177
|
+
if (names.length > 0)
|
|
178
|
+
parts.push(`Available: ${names.join(', ')}`);
|
|
179
|
+
if (!resumed)
|
|
180
|
+
parts.push('You can also omit the scenario to run on your default assignment');
|
|
181
|
+
return parts.join(' · ');
|
|
182
|
+
}
|
|
154
183
|
export function resumeRetryLaterFromError(err) {
|
|
155
184
|
if (typeof err !== 'object' || err === null)
|
|
156
185
|
return null;
|
|
@@ -8,17 +8,38 @@ interface WireFailureShape {
|
|
|
8
8
|
bodyVerdict?: string;
|
|
9
9
|
bodyCurrentName?: string;
|
|
10
10
|
message: string;
|
|
11
|
-
ownMessage?: string;
|
|
12
11
|
}
|
|
12
|
+
export declare const THROWN_SLOT_UNREADABLE: unique symbol;
|
|
13
|
+
export declare function readThrownSlot(o: unknown, key: string, own?: boolean): unknown;
|
|
14
|
+
export declare function thrownIsInstanceOf<C extends abstract new (...args: never[]) => unknown>(e: unknown, cls: C): e is InstanceType<C>;
|
|
15
|
+
export type ThrownExtraReading = {
|
|
16
|
+
readonly state: 'object';
|
|
17
|
+
readonly value: object;
|
|
18
|
+
} | {
|
|
19
|
+
readonly state: 'absent';
|
|
20
|
+
} | {
|
|
21
|
+
readonly state: 'unreadable';
|
|
22
|
+
};
|
|
23
|
+
export declare function readThrownExtra(o: {} | null | undefined): ThrownExtraReading;
|
|
13
24
|
export declare function readErrorNumber(o: object, key: string): number | undefined;
|
|
14
25
|
export declare function readErrorRecord(o: object, key: string): object | undefined;
|
|
15
26
|
export declare function readErrorString(o: object, key: string): string | undefined;
|
|
16
27
|
export declare function readErrorStringList(o: object, key: string): readonly string[] | undefined;
|
|
17
28
|
export declare function readErrorStrictStringList(o: object, key: string): readonly string[] | undefined;
|
|
18
|
-
export declare function wireFailureShapeOf(e: unknown): WireFailureShape;
|
|
19
29
|
export declare const WIRE_FAILURE_UNRENDERABLE_TEXT = "the call failed with an error this client could not render";
|
|
30
|
+
export declare function wireFailureShapeOf(e: unknown): WireFailureShape;
|
|
20
31
|
export declare function wireFailureTextsOf(e: unknown): {
|
|
21
32
|
reason: string;
|
|
22
33
|
log: string;
|
|
23
34
|
};
|
|
35
|
+
export type BlockedByReading = {
|
|
36
|
+
kind: 'named';
|
|
37
|
+
code: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'absent';
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'unreadable';
|
|
42
|
+
};
|
|
43
|
+
export declare function readBlockedBy(o: object): BlockedByReading;
|
|
44
|
+
export declare function readRefusalField(o: object): string | undefined;
|
|
24
45
|
export {};
|