@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
package/dist/toolResult.js
CHANGED
|
@@ -3,6 +3,8 @@ import { markEngineWorkflowNotified, registerOutstandingBgTask, registerOutstand
|
|
|
3
3
|
import { parseWorkflowPollEnvelope, projectWorkflowTaskOutput } from './workflow.js';
|
|
4
4
|
import { asModelFallbackReason } from './engineErrorCodes.js';
|
|
5
5
|
import { frozenSet } from './frozenSet.js';
|
|
6
|
+
import { bashExitOf, bashExitReadingFailed } from './bashExitReading.js';
|
|
7
|
+
import { isCoreSemaTaskTerminal } from './terminalStatuses.js';
|
|
6
8
|
import { CORE_ENGINE_CARD_TYPES } from './generated/engineFactTables.js';
|
|
7
9
|
export const STRUCTURED_DETAIL_TYPES = frozenSet(CORE_ENGINE_CARD_TYPES);
|
|
8
10
|
export function structuredDetailType(structured) {
|
|
@@ -12,11 +14,6 @@ export function structuredDetailType(structured) {
|
|
|
12
14
|
return typeof t === 'string' && STRUCTURED_DETAIL_TYPES.has(t) ? t : undefined;
|
|
13
15
|
}
|
|
14
16
|
const MAX_STRUCTURED_FIELD_CHARS = 1_000_000;
|
|
15
|
-
const WF_TERMINAL_STATUSES = new Set([
|
|
16
|
-
'completed',
|
|
17
|
-
'failed',
|
|
18
|
-
'cancelled',
|
|
19
|
-
]);
|
|
20
17
|
export const PROTOCOL_MARKERS = {
|
|
21
18
|
bashHead: /^exit code: (-?\d+)(?: \(([^)\n]*)\))?\n(--- stdout ---\n)?/,
|
|
22
19
|
bashStderrSep: '\n--- stderr ---\n',
|
|
@@ -28,6 +25,7 @@ export const PROTOCOL_MARKERS = {
|
|
|
28
25
|
delegationNoTextResult: '(no text result)',
|
|
29
26
|
delegationTrailer: 'Verify this result before concluding. If it leaves more to do, continue or delegate again.',
|
|
30
27
|
delegationTrailerFork: 'Verify this result before concluding. If it leaves more to do, continue the work yourself or fork again.',
|
|
28
|
+
delegationFieldLine: /^(status|error|error_kind|observer|stats|worktree):(?: ([^\r\u2028\u2029\u0085]*))?/,
|
|
31
29
|
taskOutputLabel: /^TaskOutput\s+(\S+)$/,
|
|
32
30
|
taskOutputStatus: /^status:\s*(.+)$/m,
|
|
33
31
|
taskOutputHeadSlots: /^(\r?\n)(?:(state: ([^\r\n\u2028\u2029\u0085]*)(?:\r?\n|$)))?(?:(error: ([^\r\n\u2028\u2029\u0085]*)(?:\r?\n|$)))?/,
|
|
@@ -35,7 +33,7 @@ export const PROTOCOL_MARKERS = {
|
|
|
35
33
|
taskOutputNoneSentinel: '(none)',
|
|
36
34
|
taskOutputStdoutLine: /^--- (?:new )?stdout[^\n]*---\n?/m,
|
|
37
35
|
taskOutputStderrLine: /^--- (?:new )?stderr[^\n]*---\n?/m,
|
|
38
|
-
taskOutputResultLine: /^--- result(?: \([^)\n]*\))? ---\n?/m,
|
|
36
|
+
taskOutputResultLine: /^--- result(?: \((?:[^)\n\r\u2028\u2029]|[\r\u2028\u2029](?!--- result))*\))? ---\n?/m,
|
|
39
37
|
spoolStdoutFull: '--- stdout (full, re-readable) ---',
|
|
40
38
|
spoolStdoutIncremental: '--- new stdout ---',
|
|
41
39
|
};
|
|
@@ -78,6 +76,59 @@ export function stripUntrustedFence(text) {
|
|
|
78
76
|
return null;
|
|
79
77
|
return { label: m[1] ?? '', body: m[2] ?? '' };
|
|
80
78
|
}
|
|
79
|
+
function delegationFrameSlots(lines, headAt, labelAt, fromAt) {
|
|
80
|
+
const read = (i) => {
|
|
81
|
+
const line = lines[i] ?? '';
|
|
82
|
+
const hit = PROTOCOL_MARKERS.delegationFieldLine.exec(line);
|
|
83
|
+
if (hit === null)
|
|
84
|
+
return null;
|
|
85
|
+
const value = hit[2];
|
|
86
|
+
return { key: hit[1] ?? '', value: value !== undefined && hit[0].length === line.length && value.trim() !== '' ? value : undefined };
|
|
87
|
+
};
|
|
88
|
+
const fields = [];
|
|
89
|
+
for (let i = headAt + 1; i < labelAt; i++)
|
|
90
|
+
fields.push(read(i));
|
|
91
|
+
const errorFollowedByEngineField = (at) => {
|
|
92
|
+
const next = fields[at + 1];
|
|
93
|
+
return next !== null && next !== undefined && next.value !== undefined && (next.key === 'error_kind' || next.key === 'observer' || next.key === 'stats');
|
|
94
|
+
};
|
|
95
|
+
const worktreeBefore = (at) => fields.slice(0, at).some((f) => f?.key === 'worktree');
|
|
96
|
+
const soleAt = (key) => {
|
|
97
|
+
let at = -1;
|
|
98
|
+
for (let i = 0; i < fields.length; i++) {
|
|
99
|
+
if (fields[i]?.key !== key)
|
|
100
|
+
continue;
|
|
101
|
+
if (at >= 0)
|
|
102
|
+
return -1;
|
|
103
|
+
at = i;
|
|
104
|
+
}
|
|
105
|
+
return at;
|
|
106
|
+
};
|
|
107
|
+
const claimed = new Set([headAt, labelAt]);
|
|
108
|
+
if (fromAt > labelAt + 1)
|
|
109
|
+
claimed.add(labelAt + 1);
|
|
110
|
+
const slots = {};
|
|
111
|
+
const first = fields[0] ?? null;
|
|
112
|
+
if (first !== null && first.key === 'status' && first.value !== undefined && soleAt('status') === 0) {
|
|
113
|
+
slots.status = first.value.trim();
|
|
114
|
+
claimed.add(headAt + 1);
|
|
115
|
+
for (const key of ['error', 'stats']) {
|
|
116
|
+
const at = soleAt(key);
|
|
117
|
+
const value = at >= 0 ? fields[at]?.value : undefined;
|
|
118
|
+
if (value === undefined || (key === 'error' && (!errorFollowedByEngineField(at) || worktreeBefore(at))))
|
|
119
|
+
continue;
|
|
120
|
+
slots[key] = value;
|
|
121
|
+
claimed.add(headAt + 1 + at);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let rest = '';
|
|
125
|
+
for (let i = 0; i < fromAt; i++)
|
|
126
|
+
if (!claimed.has(i))
|
|
127
|
+
rest += `${lines[i] ?? ''}\n`;
|
|
128
|
+
if (rest.trim() !== '')
|
|
129
|
+
slots.headRest = rest;
|
|
130
|
+
return slots;
|
|
131
|
+
}
|
|
81
132
|
function locateDelegationResultSection(text) {
|
|
82
133
|
const lines = text.split('\n');
|
|
83
134
|
const soleLineAt = (hit) => {
|
|
@@ -107,14 +158,14 @@ function locateDelegationResultSection(text) {
|
|
|
107
158
|
};
|
|
108
159
|
if (trailerAt === labelAt + 2 && lines[labelAt + 1] === PROTOCOL_MARKERS.delegationNoTextResult) {
|
|
109
160
|
const c = cut(labelAt + 1);
|
|
110
|
-
return { section: 'no_text_result', before: c.before, after: c.after };
|
|
161
|
+
return { section: 'no_text_result', before: c.before, after: c.after, slots: delegationFrameSlots(lines, headAt, labelAt, labelAt + 1) };
|
|
111
162
|
}
|
|
112
163
|
const partial = lines[labelAt + 1] === PROTOCOL_MARKERS.delegationPartialFindingsLabel;
|
|
113
164
|
const from = partial ? labelAt + 2 : labelAt + 1;
|
|
114
165
|
if (from >= trailerAt)
|
|
115
166
|
return null;
|
|
116
167
|
const c = cut(from);
|
|
117
|
-
return { section: partial ? 'partial_findings' : 'result', before: c.before, fenceText: c.middle, after: c.after };
|
|
168
|
+
return { section: partial ? 'partial_findings' : 'result', before: c.before, fenceText: c.middle, after: c.after, slots: delegationFrameSlots(lines, headAt, labelAt, from) };
|
|
118
169
|
}
|
|
119
170
|
export function displayBody(text, origin = 'any_tool_result') {
|
|
120
171
|
if (typeof text !== 'string')
|
|
@@ -128,14 +179,14 @@ export function displayBody(text, origin = 'any_tool_result') {
|
|
|
128
179
|
if (located === null)
|
|
129
180
|
return { fenced: false, body: text };
|
|
130
181
|
if (located.section === 'no_text_result') {
|
|
131
|
-
const { before, after, section } = located;
|
|
132
|
-
return { fenced: false, body: '', frame: { before, after, section } };
|
|
182
|
+
const { before, after, section, slots } = located;
|
|
183
|
+
return { fenced: false, body: '', frame: { before, after, section, ...slots } };
|
|
133
184
|
}
|
|
134
185
|
const inner = stripUntrustedFence(located.fenceText);
|
|
135
186
|
if (inner === null)
|
|
136
187
|
return { fenced: false, body: text };
|
|
137
|
-
const { before, after, section } = located;
|
|
138
|
-
return { fenced: true, label: inner.label, body: inner.body, frame: { before, after, section } };
|
|
188
|
+
const { before, after, section, slots } = located;
|
|
189
|
+
return { fenced: true, label: inner.label, body: inner.body, frame: { before, after, section, ...slots } };
|
|
139
190
|
}
|
|
140
191
|
export function parseModelFacingTaskOutput(text) {
|
|
141
192
|
modelFacingParseCount++;
|
|
@@ -241,7 +292,7 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
241
292
|
: typeof bgBlock?.task_id === 'string'
|
|
242
293
|
? bgBlock.task_id
|
|
243
294
|
: undefined;
|
|
244
|
-
if (
|
|
295
|
+
if (readBashDetachView(structured)?.handoffTaskId !== undefined)
|
|
245
296
|
bgTaskId = undefined;
|
|
246
297
|
}
|
|
247
298
|
else {
|
|
@@ -255,20 +306,23 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
255
306
|
};
|
|
256
307
|
}
|
|
257
308
|
}
|
|
258
|
-
|
|
309
|
+
let parsedMemo;
|
|
310
|
+
const parseOnce = () => (parsedMemo === undefined ? (parsedMemo = parseModelFacingBash(text)) : parsedMemo);
|
|
311
|
+
const exit = bashExitOf(structured, parseOnce);
|
|
312
|
+
const structuredSlots = sType === 'bash' && (typeof s?.stdout === 'string' || typeof s?.stderr === 'string');
|
|
313
|
+
const textSlots = structuredSlots ? null : parseOnce();
|
|
314
|
+
const slots = structuredSlots
|
|
259
315
|
? {
|
|
260
316
|
stdout: typeof s?.stdout === 'string' ? s.stdout : '',
|
|
261
317
|
stderr: typeof s?.stderr === 'string' ? s.stderr : '',
|
|
262
|
-
exitCode:
|
|
318
|
+
exitCode: exit.exitCode,
|
|
263
319
|
}
|
|
264
|
-
:
|
|
320
|
+
: textSlots !== null
|
|
321
|
+
? { ...textSlots, exitCode: exit.exitCode }
|
|
322
|
+
: null;
|
|
265
323
|
if (slots) {
|
|
266
|
-
const benignInterp =
|
|
267
|
-
|
|
268
|
-
: 'note' in slots && typeof slots.note === 'string' && slots.note.length > 0
|
|
269
|
-
? slots.note
|
|
270
|
-
: undefined;
|
|
271
|
-
const failed = isError || (slots.exitCode != null && slots.exitCode !== 0 && benignInterp === undefined);
|
|
324
|
+
const benignInterp = exit.benignNote;
|
|
325
|
+
const failed = isError || bashExitReadingFailed(exit);
|
|
272
326
|
if (failed) {
|
|
273
327
|
const reason = slots.stderr.length > 0 ? slots.stderr : slots.stdout;
|
|
274
328
|
let body = slots.exitCode != null ? `Exit code ${slots.exitCode}\n${reason}` : reason;
|
|
@@ -293,7 +347,7 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
293
347
|
};
|
|
294
348
|
}
|
|
295
349
|
const stdout = truncated ? `${text}\n…(truncated)` : text;
|
|
296
|
-
if (isError)
|
|
350
|
+
if (isError || bashExitReadingFailed(exit))
|
|
297
351
|
return { content: stdout, isError: true };
|
|
298
352
|
return { content: stdout, isError, toolUseResult: { stdout, stderr: '', interrupted: false } };
|
|
299
353
|
}
|
|
@@ -301,8 +355,9 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
301
355
|
const body = truncated ? `${text}\n…(truncated)` : text;
|
|
302
356
|
const parsed = parseModelFacingTaskOutput(text);
|
|
303
357
|
const wrap = (task) => ({
|
|
304
|
-
content:
|
|
358
|
+
content: body,
|
|
305
359
|
isError,
|
|
360
|
+
toolUseResult: { retrieval_status: 'success', task },
|
|
306
361
|
});
|
|
307
362
|
if (parsed.kind === 'agent') {
|
|
308
363
|
return wrap({
|
|
@@ -316,7 +371,7 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
316
371
|
}
|
|
317
372
|
const wfEnvelope = parseWorkflowPollEnvelope(text);
|
|
318
373
|
if (wfEnvelope) {
|
|
319
|
-
if (leaderLedger &&
|
|
374
|
+
if (leaderLedger && isCoreSemaTaskTerminal(wfEnvelope.status))
|
|
320
375
|
markEngineWorkflowNotified(wfEnvelope.taskId);
|
|
321
376
|
return wrap({
|
|
322
377
|
task_id: wfEnvelope.taskId,
|
|
@@ -362,23 +417,22 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
362
417
|
};
|
|
363
418
|
}
|
|
364
419
|
case 'bash': {
|
|
365
|
-
|
|
420
|
+
const handoffTaskId = readBashDetachView(structured)?.handoffTaskId;
|
|
421
|
+
if (handoffTaskId !== undefined) {
|
|
366
422
|
return {
|
|
367
423
|
toolUseResult: {
|
|
368
424
|
stdout: '',
|
|
369
425
|
stderr: '',
|
|
370
426
|
interrupted: false,
|
|
371
|
-
backgroundTaskId:
|
|
427
|
+
backgroundTaskId: handoffTaskId,
|
|
372
428
|
backgroundedByUser: true,
|
|
373
429
|
},
|
|
374
430
|
};
|
|
375
431
|
}
|
|
376
432
|
if (typeof s.stdout !== 'string' && typeof s.stderr !== 'string')
|
|
377
433
|
return null;
|
|
378
|
-
const
|
|
379
|
-
const benignInterp =
|
|
380
|
-
? s.returnCodeInterpretation
|
|
381
|
-
: undefined;
|
|
434
|
+
const exit = bashExitOf(structured, () => null);
|
|
435
|
+
const benignInterp = exit.benignNote;
|
|
382
436
|
return {
|
|
383
437
|
toolUseResult: {
|
|
384
438
|
stdout: typeof s.stdout === 'string' ? s.stdout : '',
|
|
@@ -386,7 +440,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
386
440
|
interrupted: false,
|
|
387
441
|
...(benignInterp !== undefined ? { returnCodeInterpretation: benignInterp } : {}),
|
|
388
442
|
},
|
|
389
|
-
...(
|
|
443
|
+
...(bashExitReadingFailed(exit) ? { isError: true } : {}),
|
|
390
444
|
};
|
|
391
445
|
}
|
|
392
446
|
case 'edit': {
|
|
@@ -650,7 +704,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
650
704
|
const runErrorCode = typeof s.errorCode === 'string' && s.errorCode.length > 0 ? s.errorCode : undefined;
|
|
651
705
|
let output = bodyText ?? '';
|
|
652
706
|
if (taskType === 'workflow') {
|
|
653
|
-
if (leaderLedger &&
|
|
707
|
+
if (leaderLedger && isCoreSemaTaskTerminal(status))
|
|
654
708
|
markEngineWorkflowNotified(taskId);
|
|
655
709
|
const jsonSrc = output.length > 0 ? output : (modelText ?? '');
|
|
656
710
|
output = projectWorkflowTaskOutput(jsonSrc);
|
|
@@ -716,9 +770,9 @@ export function detectEngineBgShellDetach(toolName, rawInput, structured, output
|
|
|
716
770
|
if (toolName !== 'Bash')
|
|
717
771
|
return null;
|
|
718
772
|
const view = readBashDetachView(structured);
|
|
719
|
-
if (view === null ||
|
|
773
|
+
if (view === null || view.registerFailed || view.handoffTaskId === undefined)
|
|
720
774
|
return null;
|
|
721
|
-
return engineBgShellRegistrationBody(view.
|
|
775
|
+
return engineBgShellRegistrationBody(view.handoffTaskId, rawInput, typeof outputText === 'string' ? outputText : '', 'bash');
|
|
722
776
|
}
|
|
723
777
|
function readBashDetachView(structured) {
|
|
724
778
|
if (typeof structured !== 'object' || structured === null)
|
|
@@ -731,9 +785,8 @@ function readBashDetachView(structured) {
|
|
|
731
785
|
const registerFailed = s.registerFailed;
|
|
732
786
|
const taskId = s.task_id;
|
|
733
787
|
return {
|
|
734
|
-
|
|
788
|
+
handoffTaskId: detached === true && typeof taskId === 'string' && taskId.length > 0 ? taskId : undefined,
|
|
735
789
|
registerFailed: registerFailed === true,
|
|
736
|
-
taskId: typeof taskId === 'string' && taskId.length > 0 ? taskId : undefined,
|
|
737
790
|
};
|
|
738
791
|
}
|
|
739
792
|
export function todoWriteToolUseResult(rawInput, oldTodos, isError) {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const IMAGE_MEDIA_TYPES = Object.freeze(['image/jpeg', 'image/png', 'image/gif', 'image/webp']);
|
|
2
|
+
const OMITTED_CONTENT_NOTE = '[unsupported content omitted]';
|
|
3
|
+
const IMAGE_TEXT_PLACEHOLDER = '[image]';
|
|
4
|
+
function blockOf(raw) {
|
|
5
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
|
6
|
+
return null;
|
|
7
|
+
const b = raw;
|
|
8
|
+
if (b.type === 'text')
|
|
9
|
+
return typeof b.text === 'string' ? { type: 'text', text: b.text } : null;
|
|
10
|
+
if (b.type !== 'image')
|
|
11
|
+
return null;
|
|
12
|
+
const data = b.data;
|
|
13
|
+
const mediaType = b.mimeType;
|
|
14
|
+
if (typeof data !== 'string')
|
|
15
|
+
return null;
|
|
16
|
+
if (typeof mediaType !== 'string' || !IMAGE_MEDIA_TYPES.includes(mediaType))
|
|
17
|
+
return null;
|
|
18
|
+
return { type: 'image', source: { type: 'base64', media_type: mediaType, data } };
|
|
19
|
+
}
|
|
20
|
+
const TRUNCATED_NOTE = '…(truncated)';
|
|
21
|
+
function toolResultContentOf(output) {
|
|
22
|
+
if (typeof output === 'string')
|
|
23
|
+
return output;
|
|
24
|
+
if (!Array.isArray(output))
|
|
25
|
+
return undefined;
|
|
26
|
+
const blocks = [];
|
|
27
|
+
let omitted = 0;
|
|
28
|
+
let images = 0;
|
|
29
|
+
for (const raw of output) {
|
|
30
|
+
const block = blockOf(raw);
|
|
31
|
+
if (block === null)
|
|
32
|
+
omitted++;
|
|
33
|
+
else {
|
|
34
|
+
if (block.type === 'image')
|
|
35
|
+
images++;
|
|
36
|
+
blocks.push(block);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (images === 0 && omitted === 0)
|
|
40
|
+
return blocks.map((b) => b.text).join('');
|
|
41
|
+
if (omitted > 0)
|
|
42
|
+
blocks.push({ type: 'text', text: OMITTED_CONTENT_NOTE });
|
|
43
|
+
return blocks;
|
|
44
|
+
}
|
|
45
|
+
export function toolResultBlocksOf(output, truncated) {
|
|
46
|
+
const content = toolResultContentOf(output);
|
|
47
|
+
if (!Array.isArray(content))
|
|
48
|
+
return undefined;
|
|
49
|
+
if (truncated)
|
|
50
|
+
content.push({ type: 'text', text: TRUNCATED_NOTE });
|
|
51
|
+
return content;
|
|
52
|
+
}
|
|
53
|
+
export function toolEndOutputText(output) {
|
|
54
|
+
const content = toolResultContentOf(output);
|
|
55
|
+
if (content === undefined || typeof content === 'string')
|
|
56
|
+
return content;
|
|
57
|
+
return content
|
|
58
|
+
.map((b) => {
|
|
59
|
+
const block = b;
|
|
60
|
+
return block.type === 'image' ? IMAGE_TEXT_PLACEHOLDER : (block.text ?? '');
|
|
61
|
+
})
|
|
62
|
+
.join('');
|
|
63
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EngineHealth } from '@sema-agent/sdk';
|
|
2
|
-
export interface HealthResponse extends Pick<EngineHealth, 'status' | 'model' | 'sessionBackend' | 'sessions' | 'instanceId' | 'dataRoot' | 'configHash' | 'pid' | 'port' | 'restartRequired' | 'version' | '
|
|
2
|
+
export interface HealthResponse extends Pick<EngineHealth, 'status' | 'model' | 'sessionBackend' | 'sessions' | 'instanceId' | 'dataRoot' | 'configHash' | 'pid' | 'port' | 'restartRequired' | 'version' | 'startedAt'> {
|
|
3
3
|
}
|
|
4
4
|
export interface EnginePortFile {
|
|
5
5
|
port: number;
|
|
@@ -19,6 +19,7 @@ export interface EngineInstance {
|
|
|
19
19
|
instanceId?: string;
|
|
20
20
|
dataRoot?: string;
|
|
21
21
|
configHash?: string;
|
|
22
|
+
startedAt?: number;
|
|
22
23
|
logPath?: string;
|
|
23
24
|
ownedByThisShell: boolean;
|
|
24
25
|
child?: unknown;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { UsageAnalyticsParams, UsageBreakdown, UsageDimension, UsageGranularity, UsageMetric, UsageSeries, UsageSummary } from '@sema-agent/sdk';
|
|
2
|
+
export declare const USAGE_SENTENCES: Readonly<{
|
|
3
|
+
analyticsUnavailable: "Usage analytics aren’t available on this backend.";
|
|
4
|
+
analyticsUnread: "Usage analytics couldn’t be read just now.";
|
|
5
|
+
modelsUnavailable: "Per-model usage breakdown isn't available on this backend.";
|
|
6
|
+
modelsUnread: "Per-model usage breakdown couldn’t be read just now.";
|
|
7
|
+
}>;
|
|
8
|
+
export interface UsageSummaryQuery extends UsageAnalyticsParams {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export interface UsageSeriesQuery extends UsageAnalyticsParams {
|
|
12
|
+
metric?: UsageMetric;
|
|
13
|
+
granularity?: UsageGranularity;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
export interface UsageBreakdownQuery extends UsageAnalyticsParams {
|
|
17
|
+
dimension?: UsageDimension;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
export interface UsageAnalyticsVerbs {
|
|
21
|
+
summary?: (opts?: UsageSummaryQuery) => Promise<UsageSummary>;
|
|
22
|
+
series?: (opts?: UsageSeriesQuery) => Promise<UsageSeries>;
|
|
23
|
+
breakdown?: (opts?: UsageBreakdownQuery) => Promise<UsageBreakdown>;
|
|
24
|
+
}
|
|
25
|
+
export interface UsageAnalyticsClientLike {
|
|
26
|
+
usage: UsageAnalyticsVerbs;
|
|
27
|
+
}
|
|
28
|
+
export interface UsageReadOptions {
|
|
29
|
+
from?: string | number;
|
|
30
|
+
to?: string | number;
|
|
31
|
+
principal?: string;
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
export interface UsageSeriesReadOptions extends UsageReadOptions {
|
|
35
|
+
metric?: UsageMetric;
|
|
36
|
+
granularity?: UsageGranularity;
|
|
37
|
+
}
|
|
38
|
+
export interface UsageBreakdownReadOptions extends UsageReadOptions {
|
|
39
|
+
dimension?: UsageDimension;
|
|
40
|
+
}
|
|
41
|
+
export type UsageBound = 'exact' | 'lower' | 'approximate';
|
|
42
|
+
export type UsagePrecision = 'exact' | 'estimated';
|
|
43
|
+
export interface UsageTotalsView {
|
|
44
|
+
tasks?: number;
|
|
45
|
+
tokensIn?: number;
|
|
46
|
+
tokensOut?: number;
|
|
47
|
+
cost?: number;
|
|
48
|
+
precision: UsagePrecision;
|
|
49
|
+
}
|
|
50
|
+
export interface UsageWindowView {
|
|
51
|
+
from?: string;
|
|
52
|
+
to?: string;
|
|
53
|
+
truncated: boolean;
|
|
54
|
+
}
|
|
55
|
+
export type UsageSummaryView = UsageWindowView & UsageTotalsView;
|
|
56
|
+
export interface UsageSeriesPointView {
|
|
57
|
+
t: string;
|
|
58
|
+
v: number;
|
|
59
|
+
estimated?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface UsageSeriesView extends UsageWindowView {
|
|
62
|
+
points: UsageSeriesPointView[];
|
|
63
|
+
unreadable: number;
|
|
64
|
+
}
|
|
65
|
+
export type UsageBreakdownRowView = UsageTotalsView & {
|
|
66
|
+
key: string;
|
|
67
|
+
};
|
|
68
|
+
export interface UsageBreakdownView extends UsageWindowView {
|
|
69
|
+
rows: UsageBreakdownRowView[];
|
|
70
|
+
unreadable: number;
|
|
71
|
+
}
|
|
72
|
+
export type UsageUnavailableWhy = 'capability' | 'feature' | 'route';
|
|
73
|
+
export type UsageReadVerdict<T> = {
|
|
74
|
+
readonly kind: 'ok';
|
|
75
|
+
readonly value: T;
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'unavailable';
|
|
78
|
+
readonly why: UsageUnavailableWhy;
|
|
79
|
+
} | {
|
|
80
|
+
readonly kind: 'failed';
|
|
81
|
+
readonly error: unknown;
|
|
82
|
+
};
|
|
83
|
+
export declare function classifyUsageFailure(e: unknown): UsageReadVerdict<never>;
|
|
84
|
+
export declare function projectUsageSummary(body: unknown): UsageSummaryView | undefined;
|
|
85
|
+
export declare function projectUsageSeries(body: unknown): UsageSeriesView | undefined;
|
|
86
|
+
export declare function projectUsageBreakdown(body: unknown): UsageBreakdownView | undefined;
|
|
87
|
+
export declare function readUsageSummary(client: UsageAnalyticsClientLike, opts?: UsageReadOptions): Promise<UsageReadVerdict<UsageSummaryView>>;
|
|
88
|
+
export declare function readUsageSeries(client: UsageAnalyticsClientLike, opts?: UsageSeriesReadOptions): Promise<UsageReadVerdict<UsageSeriesView>>;
|
|
89
|
+
export declare function readUsageBreakdown(client: UsageAnalyticsClientLike, opts?: UsageBreakdownReadOptions): Promise<UsageReadVerdict<UsageBreakdownView>>;
|
|
90
|
+
export interface UsageAmount {
|
|
91
|
+
readonly value: number;
|
|
92
|
+
readonly bound: UsageBound;
|
|
93
|
+
}
|
|
94
|
+
export declare function usageBoundPrefix(bound: UsageBound): '' | '≥' | '≈';
|
|
95
|
+
export interface UsageHeatmapCell {
|
|
96
|
+
readonly date: string;
|
|
97
|
+
readonly tasks: number;
|
|
98
|
+
}
|
|
99
|
+
export type UsageUnavailableCause = 'no_backend_face' | 'read_failed';
|
|
100
|
+
export type UsageModelsView = {
|
|
101
|
+
readonly state: 'available';
|
|
102
|
+
readonly rows: readonly UsageBreakdownRowView[];
|
|
103
|
+
readonly unreadable: number;
|
|
104
|
+
} | {
|
|
105
|
+
readonly state: 'unavailable';
|
|
106
|
+
readonly cause: UsageUnavailableCause;
|
|
107
|
+
readonly sentence: string;
|
|
108
|
+
};
|
|
109
|
+
export interface UsageAnalyticsReadings {
|
|
110
|
+
readonly state: 'available' | 'estimated';
|
|
111
|
+
readonly truncated: boolean;
|
|
112
|
+
readonly runs?: number;
|
|
113
|
+
readonly tokens?: UsageAmount;
|
|
114
|
+
readonly cost?: UsageAmount;
|
|
115
|
+
readonly activeDays?: number;
|
|
116
|
+
readonly peakHourUtc?: number;
|
|
117
|
+
readonly favoriteModel?: string;
|
|
118
|
+
readonly heatmap: readonly UsageHeatmapCell[] | null;
|
|
119
|
+
readonly models: UsageModelsView;
|
|
120
|
+
}
|
|
121
|
+
export interface UsageAnalyticsUnavailable {
|
|
122
|
+
readonly state: 'unavailable';
|
|
123
|
+
readonly cause: UsageUnavailableCause;
|
|
124
|
+
readonly sentence: string;
|
|
125
|
+
readonly models: Extract<UsageModelsView, {
|
|
126
|
+
state: 'unavailable';
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
export type UsageAnalyticsView = UsageAnalyticsReadings | UsageAnalyticsUnavailable;
|
|
130
|
+
export interface UsageAnalyticsInputs {
|
|
131
|
+
summary: UsageReadVerdict<UsageSummaryView>;
|
|
132
|
+
daySeries: UsageReadVerdict<UsageSeriesView>;
|
|
133
|
+
hourSeries: UsageReadVerdict<UsageSeriesView>;
|
|
134
|
+
modelBreakdown: UsageReadVerdict<UsageBreakdownView>;
|
|
135
|
+
}
|
|
136
|
+
export interface UsageAnalyticsWindow {
|
|
137
|
+
readonly from: number;
|
|
138
|
+
readonly to: number;
|
|
139
|
+
}
|
|
140
|
+
export type UsageRange = 'all' | '30d' | '7d';
|
|
141
|
+
export declare const USAGE_HEATMAP_MAX_DAYS = 70;
|
|
142
|
+
export declare function usageWindowOfRange(range: UsageRange, now: number): UsageAnalyticsWindow;
|
|
143
|
+
export declare function projectUsageAnalytics(inputs: UsageAnalyticsInputs, window: UsageAnalyticsWindow): UsageAnalyticsView;
|
|
144
|
+
export declare function readUsageAnalytics(client: UsageAnalyticsClientLike, window: UsageAnalyticsWindow, opts?: {
|
|
145
|
+
signal?: AbortSignal;
|
|
146
|
+
}): Promise<UsageAnalyticsView>;
|