@sema-agent/client-core 0.97.0 → 0.98.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 +429 -0
- package/README.md +74 -36
- package/dist/adapt/arms.d.ts +1 -0
- package/dist/adapt/arms.js +128 -34
- package/dist/adapt/ids.d.ts +12 -1
- package/dist/adapt/ids.js +59 -8
- package/dist/adapt/instanceLedger.d.ts +50 -0
- package/dist/adapt/instanceLedger.js +147 -0
- package/dist/adapt/textStream.d.ts +1 -0
- package/dist/adapt/textStream.js +24 -7
- package/dist/adapt/toolCards.d.ts +27 -5
- package/dist/adapt/toolCards.js +39 -6
- package/dist/adapt/wireShapes.js +6 -2
- package/dist/adapt.d.ts +2 -0
- package/dist/adapt.js +8 -3
- package/dist/adapter/activeRunSelfHeal.d.ts +5 -0
- package/dist/adapter/activeRunSelfHeal.js +51 -28
- package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
- package/dist/adapter/downstream/eventToSdkMessage.js +27 -34
- package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
- package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
- package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
- package/dist/adapter/runStream.js +29 -13
- package/dist/adapter/types.d.ts +4 -4
- package/dist/agentSession/backgroundView.js +2 -1
- package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
- package/dist/agentSession/engineAgentRegistryRead.js +12 -13
- package/dist/agentsWireCaps.d.ts +8 -6
- package/dist/agentsWireCaps.js +177 -162
- package/dist/approvalDecidedByCapability.d.ts +0 -4
- package/dist/approvalDecidedByCapability.js +0 -6
- package/dist/approvalsStreamLiveCapability.d.ts +0 -4
- package/dist/approvalsStreamLiveCapability.js +0 -6
- package/dist/assistantInbox.d.ts +34 -0
- package/dist/assistantInbox.js +118 -0
- package/dist/centerWiringCapability.js +9 -1
- package/dist/clientSlice.d.ts +0 -9
- package/dist/clientSlice.js +0 -3
- package/dist/cloudConfigWireCaps.d.ts +4 -2
- package/dist/cloudConfigWireCaps.js +81 -61
- package/dist/compensations.js +1 -1
- package/dist/connectorStatus.d.ts +21 -0
- package/dist/connectorStatus.js +112 -0
- package/dist/controlRouter.d.ts +14 -1
- package/dist/controlRouter.js +68 -17
- package/dist/coreValuePorts.d.ts +3 -3
- package/dist/decideReceipt.d.ts +2 -2
- package/dist/decideReceipt.js +5 -2
- package/dist/declared/supportFloorDeclared.js +3 -3
- package/dist/deviceExecutorManagementCapability.d.ts +0 -4
- package/dist/deviceExecutorManagementCapability.js +0 -6
- package/dist/deviceRebind.d.ts +49 -1
- package/dist/deviceRebind.js +221 -3
- package/dist/displayUntrusted.d.ts +1 -0
- package/dist/displayUntrusted.js +250 -76
- package/dist/engineAgentAbsence.d.ts +1 -1
- package/dist/engineAgentPanelStore.d.ts +5 -4
- package/dist/engineAgentPanelStore.js +3 -12
- package/dist/engineCapReader.d.ts +0 -4
- package/dist/engineCapReader.js +1 -5
- package/dist/engineCapsCache.d.ts +4 -0
- package/dist/engineCapsCache.js +17 -12
- package/dist/engineClosedSets.d.ts +1 -0
- package/dist/engineClosedSets.js +4 -1
- package/dist/engineErrorCodes.d.ts +9 -2
- package/dist/engineErrorCodes.js +9 -1
- package/dist/engineIdentity.d.ts +1 -0
- package/dist/engineIdentity.js +8 -0
- package/dist/engineRowRef.d.ts +28 -0
- package/dist/engineRowRef.js +111 -0
- package/dist/engineSessionMessages.d.ts +67 -0
- package/dist/engineSessionMessages.js +364 -0
- package/dist/engineToolDirectory.d.ts +18 -0
- package/dist/engineToolDirectory.js +85 -0
- package/dist/engineUrl.d.ts +18 -0
- package/dist/engineUrl.js +52 -0
- package/dist/env/uiLanguage.d.ts +9 -0
- package/dist/env/uiLanguage.js +35 -0
- package/dist/eventLeg.d.ts +92 -0
- package/dist/eventLeg.js +285 -0
- package/dist/executionLaneCapability.d.ts +0 -4
- package/dist/executionLaneCapability.js +3 -16
- package/dist/fileHistoryCaptureCapability.d.ts +0 -4
- package/dist/fileHistoryCaptureCapability.js +5 -7
- package/dist/fleet/fleetLedger.d.ts +0 -3
- package/dist/fleet/fleetLedger.js +21 -36
- package/dist/fleet/fleetProjection.d.ts +2 -2
- package/dist/fleet/fleetProjection.js +10 -8
- package/dist/frameBinding.d.ts +5 -0
- package/dist/frameBinding.js +23 -0
- package/dist/gateFailureCodes.d.ts +2 -0
- package/dist/gateFailureCodes.js +15 -0
- package/dist/gateOutcome.d.ts +3 -1
- package/dist/gateOutcome.js +25 -6
- package/dist/gateVocabulary.d.ts +5 -0
- package/dist/gateVocabulary.js +64 -2
- package/dist/generated/engineAskFaceTables.js +2 -2
- package/dist/generated/engineFactTables.d.ts +6 -3
- package/dist/generated/engineFactTables.js +22 -4
- package/dist/generated/engineNoticeTables.js +9 -0
- package/dist/generated/toolNameTables.d.ts +1 -0
- package/dist/generated/toolNameTables.js +1 -0
- package/dist/hitl/allowRuleShadow.d.ts +6 -1
- package/dist/hitl/allowRuleShadow.js +21 -17
- package/dist/hitl/approvalCardReading.d.ts +15 -0
- package/dist/hitl/approvalCardReading.js +154 -0
- package/dist/hitl/approvalCardReasons.d.ts +13 -0
- package/dist/hitl/approvalCardReasons.js +120 -0
- package/dist/hitl/approvalHolds.d.ts +47 -15
- package/dist/hitl/approvalHolds.js +134 -28
- package/dist/hitl/approvalResolution.d.ts +51 -26
- package/dist/hitl/approvalResolution.js +86 -122
- package/dist/hitl/approvalsFeed.js +6 -18
- package/dist/hitl/askClassPair.d.ts +2 -0
- package/dist/hitl/askClassPair.js +1 -0
- package/dist/hitl/askGateWire.d.ts +20 -2
- package/dist/hitl/askGateWire.js +49 -1
- package/dist/hitl/askParkRowRouting.d.ts +5 -0
- package/dist/hitl/askParkRowRouting.js +32 -1
- package/dist/hitl/askSettlementLine.d.ts +18 -0
- package/dist/hitl/askSettlementLine.js +79 -0
- package/dist/hitl/automaticAnswerVerdict.d.ts +1 -1
- package/dist/hitl/automaticAnswerVerdict.js +21 -5
- package/dist/hitl/crashConverged.d.ts +11 -20
- package/dist/hitl/crashConverged.js +56 -0
- package/dist/hitl/crashConvergedNotice.d.ts +3 -1
- package/dist/hitl/crashConvergedNotice.js +48 -11
- package/dist/hitl/decisionConflict.js +3 -10
- package/dist/hitl/decisionRefusal.d.ts +40 -1
- package/dist/hitl/decisionRefusal.js +199 -42
- package/dist/hitl/frameRouter.d.ts +5 -2
- package/dist/hitl/frameRouter.js +20 -16
- package/dist/hitl/gateLedger.d.ts +2 -0
- package/dist/hitl/gateLedger.js +50 -13
- package/dist/hitl/hitlBridge.d.ts +1 -2
- package/dist/hitl/hitlBridge.js +10 -7
- package/dist/hitl/livePendingAsk.d.ts +3 -3
- package/dist/hitl/livePendingAsk.js +7 -18
- package/dist/hitl/parkResolver.d.ts +2 -24
- package/dist/hitl/parkResolver.js +61 -97
- package/dist/hitl/persistedRulesWire.d.ts +24 -0
- package/dist/hitl/persistedRulesWire.js +122 -2
- package/dist/hitl/planReviewWire.d.ts +26 -13
- package/dist/hitl/planReviewWire.js +112 -78
- package/dist/hitl/refusedToolNameProse.d.ts +0 -1
- package/dist/hitl/refusedToolNameProse.js +0 -3
- package/dist/hitl/replayedApproval.d.ts +4 -3
- package/dist/hitl/replayedApproval.js +7 -4
- package/dist/hitl/sessionPolicyDeliverable.js +2 -4
- package/dist/hitl/sessionPolicyWire.d.ts +32 -20
- package/dist/hitl/sessionPolicyWire.js +162 -52
- package/dist/hitl/standingRows.d.ts +20 -2
- package/dist/hitl/standingRows.js +69 -8
- package/dist/hitl/toolApprovalWire.d.ts +87 -152
- package/dist/hitl/toolApprovalWire.js +591 -380
- package/dist/hookMatcherVerdict.d.ts +6 -1
- package/dist/hookMatcherVerdict.js +14 -7
- package/dist/hooksWireCaps.d.ts +2 -2
- package/dist/hooksWireCaps.js +59 -55
- package/dist/i18n/messages.en.d.ts +121 -0
- package/dist/i18n/messages.en.js +119 -0
- package/dist/i18n/messages.zh.d.ts +3 -0
- package/dist/i18n/messages.zh.js +120 -0
- package/dist/i18n/translate.d.ts +25 -0
- package/dist/i18n/translate.js +127 -0
- package/dist/index.d.ts +53 -18
- package/dist/index.js +38 -10
- package/dist/inheritEnvCapability.d.ts +31 -0
- package/dist/inheritEnvCapability.js +104 -0
- package/dist/liveModelCatalog.d.ts +1 -2
- package/dist/liveModelCatalog.js +2 -6
- package/dist/liveQuestionStore.d.ts +2 -21
- package/dist/mcpLiveness.d.ts +2 -1
- package/dist/mcpProbeWire.d.ts +6 -1
- package/dist/mcpProbeWire.js +1 -1
- package/dist/mcpWireCaps.d.ts +13 -2
- package/dist/mcpWireCaps.js +48 -0
- package/dist/memoryEntriesWire.d.ts +4 -9
- package/dist/model/modelSupplyRules.d.ts +0 -2
- package/dist/model/modelSupplyRules.js +3 -12
- package/dist/model/modelsPolicy.d.ts +0 -5
- package/dist/model/modelsPolicy.js +6 -36
- package/dist/model/subagentModelWord.d.ts +31 -0
- package/dist/model/subagentModelWord.js +261 -0
- package/dist/notifications.d.ts +6 -0
- package/dist/notifications.js +71 -23
- package/dist/outputStyleSeatCapability.d.ts +0 -3
- package/dist/outputStyleSeatCapability.js +0 -3
- package/dist/ownKey.d.ts +15 -0
- package/dist/ownKey.js +60 -3
- package/dist/panelReduce.d.ts +15 -9
- package/dist/panelReduce.js +680 -549
- package/dist/panelStateHolder.d.ts +3 -7
- package/dist/panelStateHolder.js +14 -130
- package/dist/peerLaneCapability.d.ts +0 -4
- package/dist/peerLaneCapability.js +0 -6
- package/dist/permissionRulesWriteCapability.d.ts +0 -4
- package/dist/permissionRulesWriteCapability.js +0 -6
- package/dist/permissionWireCaps.d.ts +2 -2
- package/dist/permissionWireCaps.js +2 -0
- package/dist/permissionsAllowGrantCapability.d.ts +0 -4
- package/dist/permissionsAllowGrantCapability.js +0 -6
- package/dist/permissionsDeclaration.d.ts +0 -11
- package/dist/permissionsDeclaration.js +60 -53
- package/dist/pluginHooksWire.d.ts +1 -1
- package/dist/pluginHooksWire.js +3 -6
- package/dist/preemptWire.d.ts +44 -0
- package/dist/preemptWire.js +83 -0
- package/dist/printToolResultFrame.js +15 -4
- package/dist/replayBody.d.ts +3 -0
- package/dist/replayBody.js +14 -0
- package/dist/request/taskRequest.d.ts +0 -1
- package/dist/request/taskRequest.js +0 -3
- package/dist/resumeRefusalCopy.d.ts +2 -1
- package/dist/resumeRefusalCopy.js +38 -2
- package/dist/retryStatus.d.ts +8 -0
- package/dist/retryStatus.js +106 -1
- package/dist/rewindArchiveCapability.d.ts +0 -4
- package/dist/rewindArchiveCapability.js +2 -10
- package/dist/rewindArchiveReading.d.ts +0 -1
- package/dist/rewindArchiveReading.js +0 -3
- package/dist/runCancelContext.d.ts +2 -1
- package/dist/runCancelContext.js +4 -2
- package/dist/runReattachPolicy.d.ts +31 -0
- package/dist/runReattachPolicy.js +46 -0
- package/dist/runTerminal.d.ts +3 -6
- package/dist/runTerminal.js +8 -9
- package/dist/sandboxWire.d.ts +3 -1
- package/dist/sandboxWire.js +76 -27
- package/dist/scenarioWire.js +1 -1
- package/dist/seam.d.ts +24 -2
- package/dist/seam.js +15 -3
- package/dist/seatContract.d.ts +53 -10
- package/dist/seatContract.js +132 -81
- package/dist/sessionPolicyCapability.d.ts +0 -4
- package/dist/sessionPolicyCapability.js +0 -6
- package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
- package/dist/sessionSyncFileHistoryCapability.js +0 -3
- package/dist/skillToolListsCapability.d.ts +0 -3
- package/dist/skillToolListsCapability.js +0 -3
- package/dist/sqlEngineCapability.d.ts +0 -4
- package/dist/sqlEngineCapability.js +0 -6
- package/dist/steerPriorityCapability.d.ts +0 -3
- package/dist/steerPriorityCapability.js +0 -3
- package/dist/streamDrainingLegs.d.ts +4 -0
- package/dist/streamDrainingLegs.js +6 -1
- package/dist/subagent/engineCompactWire.d.ts +0 -1
- package/dist/subagent/engineCompactWire.js +7 -5
- package/dist/subagent/engineTaskHandleWire.js +4 -7
- package/dist/subagentContentStore.js +1 -11
- package/dist/submitReopen.d.ts +24 -0
- package/dist/submitReopen.js +75 -0
- package/dist/terminalStatuses.d.ts +3 -0
- package/dist/terminalStatuses.js +10 -2
- package/dist/toolResult.d.ts +10 -1
- package/dist/toolResult.js +34 -6
- package/dist/toolRoster.d.ts +0 -2
- package/dist/toolRoster.js +0 -2
- package/dist/turnFailurePresentation.d.ts +28 -0
- package/dist/turnFailurePresentation.js +205 -0
- package/dist/userInvokedSkillsCapability.d.ts +0 -3
- package/dist/userInvokedSkillsCapability.js +0 -3
- package/dist/webSearchBackendCapability.d.ts +0 -4
- package/dist/webSearchBackendCapability.js +0 -6
- package/dist/wireErrorTriage.js +5 -24
- package/dist/wireFailureShape.d.ts +62 -5
- package/dist/wireFailureShape.js +105 -5
- package/dist/wireRefusalCopy.d.ts +12 -2
- package/dist/wireRefusalCopy.js +50 -52
- package/dist/workflowsJournalCapability.d.ts +0 -4
- package/dist/workflowsJournalCapability.js +0 -6
- package/dist/writeProtectionCapability.d.ts +0 -4
- package/dist/writeProtectionCapability.js +0 -6
- package/docs/INTEGRATION-CLIENTS.md +1305 -46
- package/package.json +5 -4
- package/dist/attachmentSeatCapability.d.ts +0 -12
- package/dist/attachmentSeatCapability.js +0 -23
- package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
- package/dist/hitl/approvalOutcomeNote.js +0 -29
- package/dist/sessionReadRedactionCapability.d.ts +0 -13
- package/dist/sessionReadRedactionCapability.js +0 -35
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { isAssistantLaneAbsent } from './assistantInbox.js';
|
|
2
|
+
import { atMostOnceVerdictOf } from './atMostOnce.js';
|
|
3
|
+
import { readOwnDataValue } from './ownKey.js';
|
|
4
|
+
import { isSdkRunTerminal } from './terminalStatuses.js';
|
|
5
|
+
import { isDisplayableWireCode, readErrorString } from './wireFailureShape.js';
|
|
6
|
+
const ALREADY_SUSPENDED = 'conflict.already_suspended';
|
|
7
|
+
const APPROVAL_SETTLED = 'conflict.approval_settled';
|
|
8
|
+
function own(v, key) {
|
|
9
|
+
try {
|
|
10
|
+
return readOwnDataValue(v, key);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function preemptReadingOfAck(taskId, ack) {
|
|
17
|
+
const body = ack;
|
|
18
|
+
const unreadable = { kind: 'unconfirmed', why: 'unreadable-answer' };
|
|
19
|
+
if (body === null || typeof body !== 'object')
|
|
20
|
+
return unreadable;
|
|
21
|
+
const echoed = own(body, 'taskId');
|
|
22
|
+
const status = own(body, 'status');
|
|
23
|
+
if (echoed !== taskId || typeof status !== 'string' || status === '')
|
|
24
|
+
return unreadable;
|
|
25
|
+
if (status === 'preempting')
|
|
26
|
+
return { kind: 'yield-requested', taskId };
|
|
27
|
+
if (status === 'running')
|
|
28
|
+
return { kind: 'not-eligible', taskId };
|
|
29
|
+
if (status === 'suspended' || status === 'needs_review')
|
|
30
|
+
return { kind: 'already-parked', status };
|
|
31
|
+
if (isSdkRunTerminal(status))
|
|
32
|
+
return { kind: 'already-ended', taskId, status };
|
|
33
|
+
return unreadable;
|
|
34
|
+
}
|
|
35
|
+
export function preemptReadingOfError(e) {
|
|
36
|
+
if (isAssistantLaneAbsent(e))
|
|
37
|
+
return { kind: 'lane-absent' };
|
|
38
|
+
const v = atMostOnceVerdictOf(e);
|
|
39
|
+
if (v.delivery === 'rejected' && v.status !== undefined) {
|
|
40
|
+
if (v.status === 409 && v.code === ALREADY_SUSPENDED) {
|
|
41
|
+
const word = e === null || e === undefined ? undefined : readErrorString(e, 'status');
|
|
42
|
+
return { kind: 'already-parked', ...(word === 'suspended' || word === 'needs_review' ? { status: word } : {}) };
|
|
43
|
+
}
|
|
44
|
+
if (v.status === 409 && v.code === APPROVAL_SETTLED)
|
|
45
|
+
return { kind: 'approval-settled' };
|
|
46
|
+
if (v.status === 404)
|
|
47
|
+
return { kind: 'not-found' };
|
|
48
|
+
return { kind: 'refused', status: v.status, ...(v.code !== undefined ? { errorCode: v.code } : {}) };
|
|
49
|
+
}
|
|
50
|
+
if (v.status !== undefined)
|
|
51
|
+
return { kind: 'unconfirmed', why: 'server-error', status: v.status };
|
|
52
|
+
return { kind: 'unconfirmed', why: 'transport' };
|
|
53
|
+
}
|
|
54
|
+
export function preemptReceiptLine(outcome) {
|
|
55
|
+
switch (outcome.kind) {
|
|
56
|
+
case 'yield-requested':
|
|
57
|
+
return 'Asked the run to yield — it will pause at its next clean turn boundary and can be resumed later.';
|
|
58
|
+
case 'not-eligible':
|
|
59
|
+
return 'This run cannot be asked to yield (it is a verification or cascade leg), so nothing changed and it keeps running — stop it instead if it has to end.';
|
|
60
|
+
case 'already-ended':
|
|
61
|
+
return isSdkRunTerminal(outcome.status)
|
|
62
|
+
? `The run had already ended (${outcome.status}), so there was nothing to yield.`
|
|
63
|
+
: 'The run had already ended, so there was nothing to yield.';
|
|
64
|
+
case 'already-parked':
|
|
65
|
+
return 'The run is already paused waiting on a decision, so there is nothing to yield — answer what it is waiting on, or stop it.';
|
|
66
|
+
case 'approval-settled':
|
|
67
|
+
return 'The approval this run was waiting on was decided at the same moment, so the yield request did not apply — check the run and ask again if it is still active.';
|
|
68
|
+
case 'not-found':
|
|
69
|
+
return 'No such run is visible to you, so nothing was asked.';
|
|
70
|
+
case 'unconfirmed':
|
|
71
|
+
return 'The yield request was sent but no confirmation came back — it may or may not have been applied, so check the run before asking again.';
|
|
72
|
+
case 'refused':
|
|
73
|
+
return outcome.errorCode !== undefined && isDisplayableWireCode(outcome.errorCode)
|
|
74
|
+
? `The engine refused the yield request (${outcome.status} ${outcome.errorCode}).`
|
|
75
|
+
: `The engine refused the yield request (${outcome.status}).`;
|
|
76
|
+
case 'no-run':
|
|
77
|
+
return 'There is no run in flight to yield.';
|
|
78
|
+
case 'cancelled-instead':
|
|
79
|
+
return 'Yielding is not available on this engine, so the run was stopped instead — that is a hard stop and the run cannot be resumed.';
|
|
80
|
+
case 'unavailable':
|
|
81
|
+
return 'Yielding is not available on this engine, so nothing was sent.';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { isCcToolDenialKind } from './gateVocabulary.js';
|
|
2
2
|
export { flattenWireOutput as flattenToolOutput } from './adapt/wireShapes.js';
|
|
3
3
|
import { flattenWireOutput } from './adapt/wireShapes.js';
|
|
4
|
-
import { toolResultEnvelopeParts, toolResultOutcomeOf } from './adapt/toolCards.js';
|
|
5
|
-
import {
|
|
4
|
+
import { toolResultEnvelopeParts, toolResultOutcomeOf, toolResultRowFlagParts, toolResultRowIdentity } from './adapt/toolCards.js';
|
|
5
|
+
import { engineRefOf } from './engineRowRef.js';
|
|
6
|
+
import { guardedRead } from './ownKey.js';
|
|
7
|
+
import { gateOutcomeOf } from './gateOutcome.js';
|
|
8
|
+
import { isUnsettledHeldToolEnd } from './engineRowRef.js';
|
|
6
9
|
export function toolEndResultToUserFrame(arm) {
|
|
7
10
|
if (typeof arm.toolCallId !== 'string' || arm.toolCallId.length === 0)
|
|
8
11
|
return null;
|
|
12
|
+
if (isUnsettledHeldToolEnd(arm))
|
|
13
|
+
return null;
|
|
14
|
+
const armEventId = arm.eventId;
|
|
15
|
+
const callId = arm.toolCallId;
|
|
16
|
+
const rowIdentity = toolResultRowIdentity([{ eventId: typeof armEventId === 'string' ? armEventId : undefined, engineRef: engineRefOf(arm) }], callId, { uuid: () => callId });
|
|
9
17
|
const text = flattenWireOutput(arm.output);
|
|
10
18
|
const parent = typeof arm.parentToolCallId === 'string' ? arm.parentToolCallId : null;
|
|
11
19
|
const outcome = toolResultOutcomeOf(typeof arm.toolName === 'string' ? arm.toolName : '', {
|
|
@@ -15,6 +23,7 @@ export function toolEndResultToUserFrame(arm) {
|
|
|
15
23
|
isError: arm.isError === true,
|
|
16
24
|
}, undefined, parent === null ? 'leader' : 'subagent');
|
|
17
25
|
const envelope = toolResultEnvelopeParts(outcome);
|
|
26
|
+
const gateView = guardedRead(() => gateOutcomeOf(arm));
|
|
18
27
|
const content = Array.isArray(outcome.body.content) ? outcome.body.content : arm.truncated === true ? `${text}\n…(truncated)` : text;
|
|
19
28
|
return {
|
|
20
29
|
type: 'user',
|
|
@@ -31,10 +40,12 @@ export function toolEndResultToUserFrame(arm) {
|
|
|
31
40
|
},
|
|
32
41
|
parent_tool_use_id: parent,
|
|
33
42
|
...(isCcToolDenialKind(arm._sema_denial_kind) ? { _sema_denial_kind: arm._sema_denial_kind } : {}),
|
|
34
|
-
...(
|
|
43
|
+
...(gateView !== undefined ? { _sema_gate: gateView } : {}),
|
|
44
|
+
...toolResultRowFlagParts(arm),
|
|
35
45
|
...(Object.hasOwn(envelope, 'tool_use_result') ? { tool_use_result: envelope.tool_use_result } : {}),
|
|
36
46
|
...(Object.hasOwn(envelope, '_sema_degraded') ? { _sema_degraded: envelope._sema_degraded } : {}),
|
|
37
|
-
uuid:
|
|
47
|
+
uuid: rowIdentity.uuid,
|
|
38
48
|
session_id: arm.session_id,
|
|
49
|
+
...(rowIdentity.engineRef !== undefined ? { _sema_engine_ref: rowIdentity.engineRef } : {}),
|
|
39
50
|
};
|
|
40
51
|
}
|
package/dist/replayBody.d.ts
CHANGED
|
@@ -10,3 +10,6 @@ export interface DoneResultView {
|
|
|
10
10
|
readonly row?: ReplayRowView;
|
|
11
11
|
}
|
|
12
12
|
export declare function doneResultView(result: unknown): DoneResultView;
|
|
13
|
+
export declare function isReplayedTerminal(frame: object | null | undefined): boolean;
|
|
14
|
+
export declare function isReplayMarked(message: object | null | undefined): boolean;
|
|
15
|
+
export declare const RESULT_REPLAYED_TEXT = "No new run was started: this request's idempotency key matched an earlier submission.";
|
package/dist/replayBody.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFrameTrueMark } from './ownKey.js';
|
|
1
2
|
function guarded(o, k) {
|
|
2
3
|
try {
|
|
3
4
|
return o[k];
|
|
@@ -23,3 +24,16 @@ export function doneResultView(result) {
|
|
|
23
24
|
}
|
|
24
25
|
return { replay: true, engine: guarded(result, 'result'), row };
|
|
25
26
|
}
|
|
27
|
+
export function isReplayedTerminal(frame) {
|
|
28
|
+
if (frame === null || typeof frame !== 'object' || Array.isArray(frame))
|
|
29
|
+
return false;
|
|
30
|
+
if (guarded(frame, 'type') !== 'done')
|
|
31
|
+
return false;
|
|
32
|
+
if (readFrameTrueMark(frame, 'replay'))
|
|
33
|
+
return true;
|
|
34
|
+
return doneResultView(guarded(frame, 'result')).replay;
|
|
35
|
+
}
|
|
36
|
+
export function isReplayMarked(message) {
|
|
37
|
+
return readFrameTrueMark(message, '_sema_replay');
|
|
38
|
+
}
|
|
39
|
+
export const RESULT_REPLAYED_TEXT = "No new run was started: this request's idempotency key matched an earlier submission.";
|
|
@@ -75,7 +75,6 @@ export interface TaskRequestOmission {
|
|
|
75
75
|
export declare function taskRequestOmissionCauseDetail(cause: unknown): string;
|
|
76
76
|
export declare const TASK_REQUEST_OMISSION_CAUSE_NOTICES: Readonly<Record<TaskRequestOmissionCause, string>>;
|
|
77
77
|
export declare function taskRequestOmissionCauseNotice(cause: unknown): string;
|
|
78
|
-
export declare function taskRequestOmissionCausePhrase(cause: unknown): string;
|
|
79
78
|
export interface TaskRequestAssembly {
|
|
80
79
|
readonly request: TaskRequestLike;
|
|
81
80
|
readonly omitted: readonly TaskRequestOmission[];
|
|
@@ -112,9 +112,6 @@ export function taskRequestOmissionCauseNotice(cause) {
|
|
|
112
112
|
? TASK_REQUEST_OMISSION_CAUSE_NOTICES[cause]
|
|
113
113
|
: TASK_REQUEST_OMISSION_UNKNOWN_CAUSE_NOTICE;
|
|
114
114
|
}
|
|
115
|
-
export function taskRequestOmissionCausePhrase(cause) {
|
|
116
|
-
return omissionNoticePartsOf(cause)?.reason ?? TASK_REQUEST_OMISSION_UNKNOWN_CAUSE_REASON;
|
|
117
|
-
}
|
|
118
115
|
const row = (field) => ({ via: 'matrix', field });
|
|
119
116
|
const INPUT_KEY_ROUTES = {
|
|
120
117
|
objective: { via: 'always' },
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ResumeStartupCause } from '@sema-agent/sdk';
|
|
1
2
|
import { RESUME_CONTEXT_UNAVAILABLE, CHECKPOINT_UNSUPPORTED_VERSION, CHECKPOINT_WALLTIME_AXIS_RETIRED, CHECKPOINT_CONFIG_REFUSED } from './engineErrorCodes.js';
|
|
2
3
|
export declare const RESUME_REFUSAL_CODES: readonly string[];
|
|
3
4
|
export interface ResumeRefusalDetail {
|
|
@@ -41,7 +42,7 @@ export interface ParkedResumeStartupDetail {
|
|
|
41
42
|
code: string;
|
|
42
43
|
cause: ParkedResumeStartupCause;
|
|
43
44
|
taskId?: string;
|
|
44
|
-
startupCause?:
|
|
45
|
+
startupCause?: ResumeStartupCause;
|
|
45
46
|
resendable: false;
|
|
46
47
|
denyStaysOpen: true;
|
|
47
48
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readBlockedBy, readErrorNumber, readErrorString } from './wireFailureShape.js';
|
|
2
|
-
import { guardedRead, ownDataField, readOwnDataNonEmptyString } from './ownKey.js';
|
|
2
|
+
import { guardedRead, ownDataField, readOwnDataNonEmptyString, readOwnDataValue } from './ownKey.js';
|
|
3
|
+
import { CORE_RESUME_STARTUP_CAUSES } from './generated/engineFactTables.js';
|
|
3
4
|
import { RESUME_CONTEXT_UNAVAILABLE, RESUME_PLACEMENT_MISMATCH, RESUME_PREFLIGHT_REJECTED, RESUME_POLICY_FOLD_CODE, PARKED_RESUME_STARTUP_FAILED, isStatusDerivedCoarseCode, RESUME_SESSION_NOT_FOUND, REQUEST_FIELD_CONFLICT, CHECKPOINT_UNSUPPORTED_VERSION, CHECKPOINT_WALLTIME_AXIS_RETIRED, CHECKPOINT_CONFIG_REFUSED, isRefusedParkCode, refusalSaysStillPending, refusalRetriableReading, } from './engineErrorCodes.js';
|
|
4
5
|
import { capForDisplay } from './fleetTaskDesc.js';
|
|
5
6
|
import { engineVersionTier } from './supportFloor.js';
|
|
@@ -144,8 +145,13 @@ function parkedResumeStartupCauseWord(err) {
|
|
|
144
145
|
catch {
|
|
145
146
|
named = undefined;
|
|
146
147
|
}
|
|
147
|
-
return named;
|
|
148
|
+
return isResumeStartupCause(named) ? named : undefined;
|
|
148
149
|
}
|
|
150
|
+
function isResumeStartupCause(v) {
|
|
151
|
+
return typeof v === 'string' && CORE_RESUME_STARTUP_CAUSES.includes(v);
|
|
152
|
+
}
|
|
153
|
+
const _startupCausePin = true;
|
|
154
|
+
void _startupCausePin;
|
|
149
155
|
export function parkedResumeStartupFromError(err, decision) {
|
|
150
156
|
if (typeof err !== 'object' || err === null)
|
|
151
157
|
return null;
|
|
@@ -183,7 +189,37 @@ const PARKED_RESUME_STARTUP_SENTENCES = Object.freeze({
|
|
|
183
189
|
'If the card is still there: when the engine rejected the decision itself (for example an answer given to the wrong question), correct it and decide again; when the approved tool is one the agent inherits from the task that started it, approving it again will not work on this server — deny the card, or wait for a server upgrade',
|
|
184
190
|
].join(' · '),
|
|
185
191
|
});
|
|
192
|
+
const PARKED_RESUME_STARTUP_CAUSE_SENTENCES = Object.freeze({
|
|
193
|
+
environment: [
|
|
194
|
+
'The engine could not start the parked work to apply this decision: the environment it runs in failed to come up (for example the workspace could not be restored); the decision itself was not rejected',
|
|
195
|
+
PARKED_RESUME_STARTUP_STATE,
|
|
196
|
+
'If the card is still there, deciding it again replays the same decision',
|
|
197
|
+
].join(' · '),
|
|
198
|
+
session_gone: [
|
|
199
|
+
'The engine could not start the parked work to apply this decision: the session of the agent it would resume is gone',
|
|
200
|
+
PARKED_RESUME_STARTUP_STATE,
|
|
201
|
+
'If the card is still there, deny it to close it; the work it was waiting on cannot be resumed',
|
|
202
|
+
].join(' · '),
|
|
203
|
+
tool_unavailable: [
|
|
204
|
+
'The engine could not start the parked work to apply this decision: the approved tool is not available to the resumed work (it is gone, or a different tool now has its name)',
|
|
205
|
+
PARKED_RESUME_STARTUP_STATE,
|
|
206
|
+
'This approval cannot run as decided — if the card is still there, decide it afresh (denying it settles it)',
|
|
207
|
+
].join(' · '),
|
|
208
|
+
configuration: [
|
|
209
|
+
"The engine could not start the parked work to apply this decision: this deployment's configuration refuses the resumed work",
|
|
210
|
+
PARKED_RESUME_STARTUP_STATE,
|
|
211
|
+
'Deciding again under the same configuration fails the same way — the configuration has to change first; denying the card settles it',
|
|
212
|
+
].join(' · '),
|
|
213
|
+
decision_rejected: [
|
|
214
|
+
'The engine could not start the parked work to apply this decision: the engine rejected the decision itself (for example an answer given to the wrong question, or an edited input the constraints refuse)',
|
|
215
|
+
PARKED_RESUME_STARTUP_STATE,
|
|
216
|
+
'If the card is still there, correct the decision and decide it again from the fresh list',
|
|
217
|
+
].join(' · '),
|
|
218
|
+
});
|
|
186
219
|
export function parkedResumeStartupContent(detail) {
|
|
220
|
+
const word = guardedRead(() => readOwnDataValue(detail, 'startupCause'));
|
|
221
|
+
if (isResumeStartupCause(word))
|
|
222
|
+
return PARKED_RESUME_STARTUP_CAUSE_SENTENCES[word];
|
|
187
223
|
return detail.cause === 'resume_rejected' ? PARKED_RESUME_STARTUP_SENTENCES.resume_rejected : PARKED_RESUME_STARTUP_SENTENCES.undetermined;
|
|
188
224
|
}
|
|
189
225
|
export function checkpointUnsupportedVersionFromError(err) {
|
package/dist/retryStatus.d.ts
CHANGED
|
@@ -71,4 +71,12 @@ export interface BrainStatusPayload {
|
|
|
71
71
|
}
|
|
72
72
|
export declare const BRAIN_STATUS_PAYLOAD_KEYS: readonly ["phase", "detail", "retryInSec", "retryInMs", "attempt", "maxRetries", "errClass", "retryAtMs", "errorStatus", "elapsedMs", "timeoutMs", "providerCondition", "providerConditionSource"];
|
|
73
73
|
export declare function mapBrainStatusToRetry(p: BrainStatusPayload, nowMs: number): RetryStatus | null;
|
|
74
|
+
export interface RetryStatusNotice {
|
|
75
|
+
readonly line: string;
|
|
76
|
+
readonly recourse?: 'switch_model' | 'wait' | 'fix_request';
|
|
77
|
+
readonly phase: 'retrying' | 'reconnecting' | 'waiting_first_token' | 'gave_up' | 'cleared';
|
|
78
|
+
}
|
|
79
|
+
export declare function retryStatusNotice(status: RetryStatus | null, ctx?: {
|
|
80
|
+
readonly modelName?: string;
|
|
81
|
+
}): RetryStatusNotice;
|
|
74
82
|
export {};
|
package/dist/retryStatus.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { displayUntrusted } from './displayUntrusted.js';
|
|
2
|
+
import { guardedRead, readOwnDataFiniteNumber, readOwnDataNonEmptyString, readOwnDataValue } from './ownKey.js';
|
|
2
3
|
export const BRAIN_STATUS_PHASES = [
|
|
3
4
|
'rate_limited',
|
|
4
5
|
'retrying',
|
|
@@ -25,9 +26,12 @@ export const BRAIN_STATUS_PAYLOAD_KEYS = [
|
|
|
25
26
|
];
|
|
26
27
|
const _brainStatusKeyPin = [true, true];
|
|
27
28
|
void _brainStatusKeyPin;
|
|
29
|
+
const RETRY_AT_SKEW_BUDGET_MS = 5_000;
|
|
28
30
|
export function mapBrainStatusToRetry(p, nowMs) {
|
|
29
31
|
const remainingMs = typeof p.retryInMs === 'number' ? p.retryInMs : (p.retryInSec ?? 0) * 1000;
|
|
30
|
-
const
|
|
32
|
+
const localDeadline = nowMs + Math.max(0, remainingMs);
|
|
33
|
+
const producerAt = typeof p.retryAtMs === 'number' && Number.isFinite(p.retryAtMs) ? p.retryAtMs : undefined;
|
|
34
|
+
const deadline = producerAt !== undefined && Math.abs(producerAt - localDeadline) <= RETRY_AT_SKEW_BUDGET_MS ? producerAt : localDeadline;
|
|
31
35
|
const counts = {
|
|
32
36
|
...(typeof p.attempt === 'number' ? { attempt: p.attempt } : {}),
|
|
33
37
|
...(typeof p.maxRetries === 'number' ? { maxRetries: p.maxRetries } : {}),
|
|
@@ -74,3 +78,104 @@ export function mapBrainStatusToRetry(p, nowMs) {
|
|
|
74
78
|
return { kind: 'error', deadline, ...extra, error: { formatted: '' } };
|
|
75
79
|
}
|
|
76
80
|
}
|
|
81
|
+
const WAIT_SWITCH_FRACTION = 0.5;
|
|
82
|
+
const CONDITION_READINGS = Object.freeze({
|
|
83
|
+
quota_exhausted: { clause: 'this account cannot be served by the model service until someone acts or its usage window resets', recourse: 'switch_model' },
|
|
84
|
+
throttled: { clause: 'the model service is rate limiting requests, which clears on its own', recourse: 'switch_model' },
|
|
85
|
+
overloaded: { clause: 'the model service is overloaded', recourse: 'switch_model' },
|
|
86
|
+
stop_other: { clause: 'the model service refused this request', resendNote: 'resending will not change it', recourse: 'fix_request' },
|
|
87
|
+
unknown: null,
|
|
88
|
+
});
|
|
89
|
+
function conditionReadingOf(word) {
|
|
90
|
+
if (word === undefined || !Object.hasOwn(CONDITION_READINGS, word))
|
|
91
|
+
return undefined;
|
|
92
|
+
return CONDITION_READINGS[word] ?? undefined;
|
|
93
|
+
}
|
|
94
|
+
function noticeNumber(carrier, key) {
|
|
95
|
+
return guardedRead(() => readOwnDataFiniteNumber(carrier, key));
|
|
96
|
+
}
|
|
97
|
+
function noticeText(carrier, key) {
|
|
98
|
+
return guardedRead(() => readOwnDataNonEmptyString(carrier, key));
|
|
99
|
+
}
|
|
100
|
+
function noticeValue(carrier, key) {
|
|
101
|
+
return guardedRead(() => readOwnDataValue(carrier, key));
|
|
102
|
+
}
|
|
103
|
+
function washedText(raw) {
|
|
104
|
+
if (raw === undefined)
|
|
105
|
+
return undefined;
|
|
106
|
+
const shown = displayUntrusted(raw);
|
|
107
|
+
return shown.trim() === '' ? undefined : shown;
|
|
108
|
+
}
|
|
109
|
+
function noticeCount(n) {
|
|
110
|
+
return n !== undefined && Number.isInteger(n) && n >= 1 ? n : undefined;
|
|
111
|
+
}
|
|
112
|
+
function noticeHttp(n) {
|
|
113
|
+
return n !== undefined && Number.isInteger(n) && n >= 100 && n <= 999 ? n : undefined;
|
|
114
|
+
}
|
|
115
|
+
function spanText(ms) {
|
|
116
|
+
const total = Math.floor(ms / 1000);
|
|
117
|
+
const h = Math.floor(total / 3600);
|
|
118
|
+
const mi = Math.floor((total % 3600) / 60);
|
|
119
|
+
const se = total % 60;
|
|
120
|
+
return h > 0 ? `${h}h ${mi}m ${se}s` : mi > 0 ? `${mi}m ${se}s` : `${se}s`;
|
|
121
|
+
}
|
|
122
|
+
function noticeAttemptTail(attempt, maxRetries) {
|
|
123
|
+
if (attempt !== undefined && maxRetries !== undefined)
|
|
124
|
+
return `, attempt ${attempt} of ${maxRetries}`;
|
|
125
|
+
if (attempt !== undefined)
|
|
126
|
+
return `, attempt ${attempt}`;
|
|
127
|
+
if (maxRetries !== undefined)
|
|
128
|
+
return `, up to ${maxRetries} ${maxRetries === 1 ? 'retry' : 'retries'}`;
|
|
129
|
+
return '';
|
|
130
|
+
}
|
|
131
|
+
function sealNotice(line, phase, recourse) {
|
|
132
|
+
return Object.freeze(recourse === undefined ? { line, phase } : { line, recourse, phase });
|
|
133
|
+
}
|
|
134
|
+
export function retryStatusNotice(status, ctx) {
|
|
135
|
+
const modelName = washedText(noticeText(ctx, 'modelName'))?.trim();
|
|
136
|
+
const prefix = modelName === undefined || modelName === '' ? '' : `${modelName}: `;
|
|
137
|
+
if (status === null)
|
|
138
|
+
return sealNotice('', 'cleared', undefined);
|
|
139
|
+
const armWord = noticeText(status, 'kind');
|
|
140
|
+
const kind = armWord === 'stalled' || armWord === 'waiting' ? armWord : 'error';
|
|
141
|
+
if (kind === 'waiting') {
|
|
142
|
+
const elapsedRaw = noticeNumber(status, 'elapsedMs');
|
|
143
|
+
const timeoutRaw = noticeNumber(status, 'timeoutMs');
|
|
144
|
+
const elapsed = elapsedRaw !== undefined && elapsedRaw >= 0 && elapsedRaw <= Number.MAX_SAFE_INTEGER ? elapsedRaw : undefined;
|
|
145
|
+
const ceiling = timeoutRaw !== undefined && timeoutRaw > 0 && timeoutRaw <= Number.MAX_SAFE_INTEGER ? timeoutRaw : undefined;
|
|
146
|
+
const progress = [...(elapsed === undefined ? [] : [`${spanText(elapsed)} so far`]), ...(ceiling === undefined ? [] : [`limit ${spanText(ceiling)}`])];
|
|
147
|
+
const offerSwitch = prefix !== '' && elapsed !== undefined && ceiling !== undefined && elapsed >= ceiling * WAIT_SWITCH_FRACTION;
|
|
148
|
+
const text = `${prefix}Waiting for the model's first token${progress.length === 0 ? '' : ` — ${progress.join(', ')}`}${offerSwitch ? '; keep waiting or switch model' : ''}`;
|
|
149
|
+
return sealNotice(text, 'waiting_first_token', offerSwitch ? 'switch_model' : 'wait');
|
|
150
|
+
}
|
|
151
|
+
const terminal = kind === 'error' && noticeValue(status, 'terminal') === true;
|
|
152
|
+
const reading = conditionReadingOf(noticeText(status, 'providerCondition'));
|
|
153
|
+
const http = noticeHttp(noticeNumber(status, 'errorStatus'));
|
|
154
|
+
const attempt = noticeCount(noticeNumber(status, 'attempt'));
|
|
155
|
+
const maxRetries = noticeCount(noticeNumber(status, 'maxRetries'));
|
|
156
|
+
const engineWords = kind === 'stalled' ? noticeText(status, 'detail') : noticeText(noticeValue(status, 'error'), 'formatted');
|
|
157
|
+
const httpPart = http === undefined ? '' : ` (HTTP ${http})`;
|
|
158
|
+
let first;
|
|
159
|
+
if (terminal) {
|
|
160
|
+
const after = attempt === undefined ? '' : ` after ${attempt} attempt${attempt === 1 ? '' : 's'}`;
|
|
161
|
+
const why = reading === undefined ? '' : `: ${reading.clause}${reading.resendNote === undefined ? '' : `, and ${reading.resendNote}`}`;
|
|
162
|
+
first = `Stopped${after}${why}${httpPart}`;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const head = reading !== undefined ? `${reading.clause.charAt(0).toUpperCase()}${reading.clause.slice(1)}` : http !== undefined || kind === 'error' ? 'Request failed' : 'Waiting for the API response';
|
|
166
|
+
first = `${head}${httpPart} — ${kind === 'stalled' ? 'will retry' : 'retrying'}${noticeAttemptTail(attempt, maxRetries)}`;
|
|
167
|
+
}
|
|
168
|
+
const note = washedText(engineWords);
|
|
169
|
+
const serviceSide = http !== undefined && (http === 429 || (http >= 500 && http <= 599));
|
|
170
|
+
const knownArm = armWord === 'stalled' || armWord === 'error';
|
|
171
|
+
const recourse = !knownArm
|
|
172
|
+
? undefined
|
|
173
|
+
: reading !== undefined
|
|
174
|
+
? reading.recourse
|
|
175
|
+
: serviceSide
|
|
176
|
+
? 'switch_model'
|
|
177
|
+
: !terminal
|
|
178
|
+
? 'wait'
|
|
179
|
+
: undefined;
|
|
180
|
+
return sealNotice(`${prefix}${first}${note === undefined ? '' : ` · ${note}`}`, kind === 'stalled' ? 'reconnecting' : terminal ? 'gave_up' : 'retrying', recourse);
|
|
181
|
+
}
|
|
@@ -3,13 +3,9 @@ import type { RewindMode } from './rewindWireCaps.js';
|
|
|
3
3
|
export { projectRewindArchiveCapability, rewindConversationAvailability } from './rewindArchiveReading.js';
|
|
4
4
|
export type { RewindArchiveBit, RewindArchiveReading, RewindCodeArchive } from './rewindArchiveReading.js';
|
|
5
5
|
export type RewindArchiveMode = 'both' | 'code';
|
|
6
|
-
export declare function noteEngineCapsForRewindArchive(baseUrl: string, caps: unknown, opts?: {
|
|
7
|
-
generation?: number;
|
|
8
|
-
}): void;
|
|
9
6
|
export declare function observedRewindArchive(baseUrl?: string | undefined): RewindArchiveReading;
|
|
10
7
|
export declare function rewindCodeArchiveAvailability(reading: RewindArchiveReading, mode: RewindArchiveMode): RewindCodeArchive;
|
|
11
8
|
export declare function rewindArchiveDoctorDetail(reading: RewindArchiveReading, mode: RewindArchiveMode): string;
|
|
12
9
|
export declare function engineRewindRefusedNow(option: RewindMode, reading?: RewindArchiveReading): boolean;
|
|
13
10
|
export declare function rewindConversationDoctorDetail(reading: RewindArchiveReading): string;
|
|
14
11
|
export declare function rewindRestoreFilesEpochDetail(reading: RewindArchiveReading): string;
|
|
15
|
-
export declare function __resetRewindArchiveReadingsForTests(): void;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { engineWireTarget } from './engineWireTarget.js';
|
|
2
|
-
import {
|
|
2
|
+
import { rewindArchiveReadingAt, rewindConversationAvailability, } from './rewindArchiveReading.js';
|
|
3
3
|
import { unreadableReadingDetail } from './engineCapReader.js';
|
|
4
4
|
export { projectRewindArchiveCapability, rewindConversationAvailability } from './rewindArchiveReading.js';
|
|
5
|
-
export function noteEngineCapsForRewindArchive(baseUrl, caps, opts) {
|
|
6
|
-
void baseUrl;
|
|
7
|
-
void caps;
|
|
8
|
-
void opts;
|
|
9
|
-
}
|
|
10
5
|
export function observedRewindArchive(baseUrl = engineWireTarget()?.baseUrl) {
|
|
11
6
|
return rewindArchiveReadingAt(baseUrl);
|
|
12
7
|
}
|
|
@@ -87,11 +82,8 @@ export function rewindRestoreFilesEpochDetail(reading) {
|
|
|
87
82
|
case 'off':
|
|
88
83
|
return 'this engine does not announce the restore-files request key, so a rewind with code restore built from this reading leaves the key out and moves the conversation only';
|
|
89
84
|
case 'not_reported':
|
|
90
|
-
return 'this engine does not report the restore-files epoch bit
|
|
85
|
+
return 'this engine does not report the restore-files epoch bit, so a rewind with code restore built from this reading leaves the key out and moves the conversation only';
|
|
91
86
|
case 'malformed':
|
|
92
87
|
return 'the restore-files epoch bit is reported in an unreadable shape, so a rewind with code restore built from this reading leaves the key out and moves the conversation only';
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
|
-
export function __resetRewindArchiveReadingsForTests() {
|
|
96
|
-
resetRewindArchiveReader();
|
|
97
|
-
}
|
|
@@ -13,5 +13,4 @@ export type RewindArchiveReading = {
|
|
|
13
13
|
export type RewindCodeArchive = 'available' | 'unavailable' | 'unknown';
|
|
14
14
|
export declare function projectRewindArchiveCapability(caps: unknown): RewindArchiveReading | undefined;
|
|
15
15
|
export declare function rewindArchiveReadingAt(baseUrl: string | undefined): RewindArchiveReading;
|
|
16
|
-
export declare function resetRewindArchiveReader(): void;
|
|
17
16
|
export declare function rewindConversationAvailability(reading: RewindArchiveReading): RewindCodeArchive;
|
|
@@ -41,9 +41,6 @@ const reader = createEngineCapReader({
|
|
|
41
41
|
export function rewindArchiveReadingAt(baseUrl) {
|
|
42
42
|
return reader.observed(baseUrl);
|
|
43
43
|
}
|
|
44
|
-
export function resetRewindArchiveReader() {
|
|
45
|
-
reader.__resetForTests();
|
|
46
|
-
}
|
|
47
44
|
export function rewindConversationAvailability(reading) {
|
|
48
45
|
if (reading.kind !== 'present')
|
|
49
46
|
return 'unknown';
|
|
@@ -12,6 +12,7 @@ export type RunCancelContextReading = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare function readRunCancelContext(record: unknown): RunCancelContextReading | undefined;
|
|
14
14
|
import { type RunTerminalRead } from './runTerminal.js';
|
|
15
|
+
import type { AbortCause } from '@sema-agent/sdk';
|
|
15
16
|
export type RunAbortCause = {
|
|
16
17
|
kind: 'cancelled';
|
|
17
18
|
context?: RunCancelContextView;
|
|
@@ -30,7 +31,7 @@ export type RunAbortCause = {
|
|
|
30
31
|
export declare const RUN_CANCELLED_CODE: "cancelled";
|
|
31
32
|
export declare function classifyRunAbortCause(record: unknown): RunAbortCause;
|
|
32
33
|
export declare const ABORT_CAUSES: readonly ["client_disconnected", "ask_park_grace_exhausted", "cancel_verb"];
|
|
33
|
-
export type AbortCause
|
|
34
|
+
export type { AbortCause };
|
|
34
35
|
export type AbortCauseReading = {
|
|
35
36
|
readonly kind: 'known';
|
|
36
37
|
readonly cause: AbortCause;
|
package/dist/runCancelContext.js
CHANGED
|
@@ -34,9 +34,9 @@ export function readRunCancelContext(record) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
import { readRunTerminal } from './runTerminal.js';
|
|
37
|
+
import { isSdkRunLive } from './terminalStatuses.js';
|
|
37
38
|
import { SDK_ABORT_CAUSES } from './generated/sdkFactTables.js';
|
|
38
39
|
export const RUN_CANCELLED_CODE = 'cancelled';
|
|
39
|
-
const LIVE_STATUSES = new Set(['running', 'queued', 'suspended', 'needs_review']);
|
|
40
40
|
export function classifyRunAbortCause(record) {
|
|
41
41
|
if (record === null || typeof record !== 'object')
|
|
42
42
|
return { kind: 'unknown' };
|
|
@@ -53,11 +53,13 @@ export function classifyRunAbortCause(record) {
|
|
|
53
53
|
}
|
|
54
54
|
if (read !== null && read.kind === 'paused')
|
|
55
55
|
return { kind: 'run_still_live', ...(status !== undefined ? { status } : {}) };
|
|
56
|
-
if ((read === null || read.kind === 'unknown') && status !== undefined &&
|
|
56
|
+
if ((read === null || read.kind === 'unknown') && status !== undefined && isSdkRunLive(status))
|
|
57
57
|
return { kind: 'run_still_live', status };
|
|
58
58
|
return { kind: 'unknown', ...(read !== null ? { terminal: read.kind } : {}) };
|
|
59
59
|
}
|
|
60
60
|
export const ABORT_CAUSES = SDK_ABORT_CAUSES;
|
|
61
|
+
const _abortCauseTablePin = true;
|
|
62
|
+
void _abortCauseTablePin;
|
|
61
63
|
function ownDataOf(o, key) {
|
|
62
64
|
const d = Object.getOwnPropertyDescriptor(o, key);
|
|
63
65
|
return d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const REATTACH_MAX_TRIES = 5;
|
|
2
|
+
export interface ReattachBudget {
|
|
3
|
+
readonly tries: number;
|
|
4
|
+
readonly drainingStreak: number;
|
|
5
|
+
readonly drainingTotal: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const REATTACH_BUDGET_FRESH: ReattachBudget;
|
|
8
|
+
export type ReattachEvent = {
|
|
9
|
+
readonly cause: 'connection_lost';
|
|
10
|
+
readonly hasRunId: boolean;
|
|
11
|
+
readonly error?: object;
|
|
12
|
+
} | {
|
|
13
|
+
readonly cause: 'stream_cap';
|
|
14
|
+
readonly hasRunId: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
readonly cause: 'stream_draining';
|
|
17
|
+
readonly hasRunId: boolean;
|
|
18
|
+
readonly frame: object;
|
|
19
|
+
readonly madeProgress?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type ReattachGiveUp = 'no_run_id' | 'budget_exhausted' | 'bad_input';
|
|
22
|
+
export type ReattachDecision = {
|
|
23
|
+
readonly action: 'reattach';
|
|
24
|
+
readonly afterMs: number;
|
|
25
|
+
readonly budget: ReattachBudget;
|
|
26
|
+
} | {
|
|
27
|
+
readonly action: 'give_up';
|
|
28
|
+
readonly reason: ReattachGiveUp;
|
|
29
|
+
readonly budget: ReattachBudget;
|
|
30
|
+
};
|
|
31
|
+
export declare function runReattachPolicy(budget: ReattachBudget, event: ReattachEvent): ReattachDecision;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { STREAM_DRAINING_RECONNECT_MAX, drainingRetryDelayMs, isPreStreamDrainingReject } from './wireErrorTriage.js';
|
|
2
|
+
import { drainingLegStep } from './streamDrainingLegs.js';
|
|
3
|
+
export const REATTACH_MAX_TRIES = 5;
|
|
4
|
+
const DRAINING_TOTAL_MAX = REATTACH_MAX_TRIES * STREAM_DRAINING_RECONNECT_MAX;
|
|
5
|
+
export const REATTACH_BUDGET_FRESH = Object.freeze({ tries: 0, drainingStreak: 0, drainingTotal: 0 });
|
|
6
|
+
const isCount = (v) => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0;
|
|
7
|
+
const giveUp = (reason, budget) => Object.freeze({ action: 'give_up', reason, budget });
|
|
8
|
+
const reattach = (afterMs, tries, drainingStreak, drainingTotal) => Object.freeze({ action: 'reattach', afterMs, budget: Object.freeze({ tries, drainingStreak, drainingTotal }) });
|
|
9
|
+
export function runReattachPolicy(budget, event) {
|
|
10
|
+
try {
|
|
11
|
+
if (typeof budget !== 'object' || budget === null || !isCount(budget.tries) || !isCount(budget.drainingStreak) || !isCount(budget.drainingTotal))
|
|
12
|
+
return giveUp('bad_input', REATTACH_BUDGET_FRESH);
|
|
13
|
+
if (typeof event !== 'object' || event === null || typeof event.hasRunId !== 'boolean')
|
|
14
|
+
return giveUp('bad_input', budget);
|
|
15
|
+
if (!event.hasRunId)
|
|
16
|
+
return giveUp('no_run_id', budget);
|
|
17
|
+
const { tries, drainingStreak, drainingTotal } = budget;
|
|
18
|
+
if (event.cause === 'connection_lost') {
|
|
19
|
+
if (tries >= REATTACH_MAX_TRIES)
|
|
20
|
+
return giveUp('budget_exhausted', budget);
|
|
21
|
+
const next = tries + 1;
|
|
22
|
+
const afterMs = isPreStreamDrainingReject(event.error) ? drainingRetryDelayMs(event.error, next - 1) : 1000 * next;
|
|
23
|
+
return reattach(afterMs, next, 0, drainingTotal);
|
|
24
|
+
}
|
|
25
|
+
if (event.cause === 'stream_cap') {
|
|
26
|
+
if (tries >= REATTACH_MAX_TRIES)
|
|
27
|
+
return giveUp('budget_exhausted', budget);
|
|
28
|
+
return reattach(0, tries + 1, 0, drainingTotal);
|
|
29
|
+
}
|
|
30
|
+
if (event.cause === 'stream_draining') {
|
|
31
|
+
const streak = event.madeProgress === true ? 0 : drainingStreak;
|
|
32
|
+
const { decision, streak: nextStreak } = drainingLegStep(streak, event.frame);
|
|
33
|
+
if ('reconnectAfterMs' in decision && drainingTotal < DRAINING_TOTAL_MAX)
|
|
34
|
+
return reattach(decision.reconnectAfterMs, tries, nextStreak, drainingTotal + 1);
|
|
35
|
+
if ('giveUp' in decision && decision.giveUp === 'not_draining_end')
|
|
36
|
+
return giveUp('bad_input', budget);
|
|
37
|
+
if (tries >= REATTACH_MAX_TRIES)
|
|
38
|
+
return giveUp('budget_exhausted', budget);
|
|
39
|
+
return reattach(0, tries + 1, nextStreak, drainingTotal);
|
|
40
|
+
}
|
|
41
|
+
return giveUp('bad_input', budget);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return giveUp('bad_input', REATTACH_BUDGET_FRESH);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/dist/runTerminal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CheckpointGate, TerminalModelOutputInvalidDetail } from '@sema-agent/sdk';
|
|
1
|
+
import type { CheckpointGate, PromptBlockCause, TerminalModelOutputInvalidDetail } from '@sema-agent/sdk';
|
|
2
2
|
export type RunTerminalPlane = 'cause' | 'flat';
|
|
3
3
|
export interface RunTerminalPause {
|
|
4
4
|
gate?: CheckpointGate;
|
|
@@ -55,7 +55,7 @@ export type RunTerminalCompletedDetail = {
|
|
|
55
55
|
word: string;
|
|
56
56
|
};
|
|
57
57
|
export declare const PROMPT_BLOCK_CAUSES: readonly ["block", "crashed", "timeout", "cancelled"];
|
|
58
|
-
export type PromptBlockCause
|
|
58
|
+
export type { PromptBlockCause };
|
|
59
59
|
export type RunTerminalBlockedDetail = {
|
|
60
60
|
kind: 'prompt_blocked_by_hook';
|
|
61
61
|
cause: PromptBlockCause;
|
|
@@ -69,9 +69,7 @@ export type RunTerminalBlockedDetail = {
|
|
|
69
69
|
kind: 'unrecognized';
|
|
70
70
|
word: string;
|
|
71
71
|
};
|
|
72
|
-
export type RunTerminalRead = RunTerminalReadArm
|
|
73
|
-
readonly replay?: true;
|
|
74
|
-
};
|
|
72
|
+
export type RunTerminalRead = RunTerminalReadArm;
|
|
75
73
|
type RunTerminalReadArm = {
|
|
76
74
|
kind: 'completed';
|
|
77
75
|
plane: RunTerminalPlane;
|
|
@@ -102,4 +100,3 @@ export declare function runTerminalGateKind(read: RunTerminalRead | null): strin
|
|
|
102
100
|
export declare function runTerminalGateToolName(read: RunTerminalRead | null): string | undefined;
|
|
103
101
|
export declare function runTerminalCode(read: RunTerminalRead | null): string | undefined;
|
|
104
102
|
export declare function isReviewPark(read: RunTerminalRead | null): boolean;
|
|
105
|
-
export {};
|