@sema-agent/client-core 0.97.1 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +607 -0
- package/README.md +96 -46
- package/dist/adapt/arms.d.ts +1 -0
- package/dist/adapt/arms.js +188 -53
- package/dist/adapt/ids.d.ts +12 -1
- package/dist/adapt/ids.js +59 -8
- package/dist/adapt/instanceLedger.d.ts +50 -0
- package/dist/adapt/instanceLedger.js +147 -0
- package/dist/adapt/panelTasks.d.ts +1 -1
- package/dist/adapt/panelTasks.js +2 -2
- package/dist/adapt/textStream.d.ts +1 -0
- package/dist/adapt/textStream.js +24 -7
- package/dist/adapt/toolCards.d.ts +27 -5
- package/dist/adapt/toolCards.js +39 -6
- package/dist/adapt/wireShapes.js +6 -2
- package/dist/adapt.d.ts +2 -0
- package/dist/adapt.js +8 -3
- package/dist/adapter/activeRunSelfHeal.d.ts +9 -3
- package/dist/adapter/activeRunSelfHeal.js +205 -313
- package/dist/adapter/downstream/eventToSdkMessage.d.ts +2 -5
- package/dist/adapter/downstream/eventToSdkMessage.js +77 -36
- package/dist/adapter/downstream/terminalToSdkResult.js +11 -4
- package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +5 -2
- package/dist/adapter/downstream/turnUsageToModelUsage.js +2 -0
- package/dist/adapter/runStream.js +79 -48
- package/dist/adapter/types.d.ts +4 -4
- package/dist/adapter/types.js +2 -1
- package/dist/agentSession/backgroundView.js +2 -1
- package/dist/agentSession/engineAgentRegistryRead.d.ts +2 -2
- package/dist/agentSession/engineAgentRegistryRead.js +12 -13
- package/dist/agentSession/engineSessionBackgroundStop.js +16 -8
- package/dist/agentsWireCaps.d.ts +8 -11
- package/dist/agentsWireCaps.js +196 -194
- package/dist/approvalDecidedByCapability.d.ts +0 -4
- package/dist/approvalDecidedByCapability.js +0 -6
- package/dist/approvalsStreamLiveCapability.d.ts +0 -4
- package/dist/approvalsStreamLiveCapability.js +0 -6
- package/dist/assistantInbox.d.ts +34 -0
- package/dist/assistantInbox.js +118 -0
- package/dist/centerWiringCapability.js +9 -1
- package/dist/clientSlice.d.ts +0 -9
- package/dist/clientSlice.js +0 -3
- package/dist/cloudConfigWireCaps.d.ts +5 -3
- package/dist/cloudConfigWireCaps.js +106 -64
- package/dist/compensations.js +1 -1
- package/dist/connectorStatus.d.ts +21 -0
- package/dist/connectorStatus.js +112 -0
- package/dist/controlRouter.d.ts +18 -3
- package/dist/controlRouter.js +106 -67
- package/dist/coreValuePorts.d.ts +29 -4
- package/dist/coreValuePorts.js +10 -0
- package/dist/corruptSessionCopy.d.ts +2 -1
- package/dist/corruptSessionCopy.js +3 -3
- package/dist/decideReceipt.d.ts +2 -2
- package/dist/decideReceipt.js +5 -2
- package/dist/declared/supportFloorDeclared.js +3 -3
- package/dist/detachWire.js +3 -2
- package/dist/deviceExecutorManagementCapability.d.ts +0 -4
- package/dist/deviceExecutorManagementCapability.js +0 -6
- package/dist/deviceRebind.d.ts +49 -1
- package/dist/deviceRebind.js +221 -3
- package/dist/devicesFace.d.ts +34 -0
- package/dist/devicesFace.js +90 -0
- package/dist/displayUntrusted.d.ts +2 -0
- package/dist/displayUntrusted.js +253 -76
- package/dist/engineAgentAbsence.d.ts +1 -1
- package/dist/engineAgentPanelStore.d.ts +12 -4
- package/dist/engineAgentPanelStore.js +16 -11
- package/dist/engineCapReader.d.ts +2 -5
- package/dist/engineCapReader.js +8 -10
- package/dist/engineCapsCache.d.ts +12 -0
- package/dist/engineCapsCache.js +76 -18
- package/dist/engineCapsChange.d.ts +2 -0
- package/dist/engineCapsChange.js +9 -0
- package/dist/engineClosedSets.d.ts +1 -0
- package/dist/engineClosedSets.js +4 -1
- package/dist/engineErrorCodes.d.ts +11 -3
- package/dist/engineErrorCodes.js +11 -8
- package/dist/engineIdentity.d.ts +1 -0
- package/dist/engineIdentity.js +8 -0
- package/dist/engineRowRef.d.ts +28 -0
- package/dist/engineRowRef.js +114 -0
- package/dist/engineSessionMessages.d.ts +68 -0
- package/dist/engineSessionMessages.js +370 -0
- package/dist/engineTargetSeat.d.ts +27 -0
- package/dist/engineTargetSeat.js +199 -0
- package/dist/engineToolDirectory.d.ts +0 -9
- package/dist/engineToolDirectory.js +1 -94
- package/dist/engineUrl.d.ts +18 -0
- package/dist/engineUrl.js +52 -0
- package/dist/engineWireFor.js +3 -8
- package/dist/env/uiLanguage.d.ts +11 -1
- package/dist/env/uiLanguage.js +38 -2
- package/dist/eventLeg.d.ts +100 -0
- package/dist/eventLeg.js +305 -0
- package/dist/executionLaneCapability.d.ts +0 -4
- package/dist/executionLaneCapability.js +3 -16
- package/dist/fileHistoryCaptureCapability.d.ts +2 -5
- package/dist/fileHistoryCaptureCapability.js +13 -21
- package/dist/fileHistoryLegNotice.d.ts +2 -1
- package/dist/fileHistoryLegNotice.js +3 -3
- package/dist/fleet/fleetLedger.d.ts +0 -3
- package/dist/fleet/fleetLedger.js +21 -36
- package/dist/fleet/fleetProjection.d.ts +2 -2
- package/dist/fleet/fleetProjection.js +10 -8
- package/dist/frameBinding.d.ts +8 -0
- package/dist/frameBinding.js +35 -0
- package/dist/gateFailureCodes.d.ts +2 -0
- package/dist/gateFailureCodes.js +15 -0
- package/dist/gateOutcome.d.ts +3 -1
- package/dist/gateOutcome.js +41 -8
- package/dist/gateVocabulary.d.ts +10 -4
- package/dist/gateVocabulary.js +107 -47
- package/dist/generated/engineAskFaceTables.js +2 -2
- package/dist/generated/engineFactTables.d.ts +22 -3
- package/dist/generated/engineFactTables.js +51 -4
- package/dist/generated/engineNoticeTables.js +18 -3
- package/dist/generated/settingsSchemaFns.d.ts +6 -0
- package/dist/generated/settingsSchemaFns.js +57 -0
- package/dist/generated/settingsSchemaHooksClassifier.d.ts +2 -0
- package/dist/generated/settingsSchemaHooksClassifier.js +254 -0
- package/dist/generated/settingsSchemaTables.d.ts +1 -0
- package/dist/generated/settingsSchemaTables.js +4 -0
- package/dist/generated/settingsSchemaTypes.d.ts +105 -0
- package/dist/generated/settingsSchemaTypes.js +1 -0
- package/dist/generated/toolNameTables.d.ts +1 -0
- package/dist/generated/toolNameTables.js +1 -0
- package/dist/hitl/allowRuleShadow.d.ts +8 -2
- package/dist/hitl/allowRuleShadow.js +36 -29
- package/dist/hitl/approvalCardReading.d.ts +15 -0
- package/dist/hitl/approvalCardReading.js +154 -0
- package/dist/hitl/approvalCardReasons.d.ts +14 -0
- package/dist/hitl/approvalCardReasons.js +119 -0
- package/dist/hitl/approvalHolds.d.ts +50 -15
- package/dist/hitl/approvalHolds.js +177 -27
- package/dist/hitl/approvalResolution.d.ts +51 -26
- package/dist/hitl/approvalResolution.js +86 -122
- package/dist/hitl/approvalsFeed.js +6 -18
- package/dist/hitl/askClassPair.d.ts +2 -0
- package/dist/hitl/askClassPair.js +17 -0
- package/dist/hitl/askGateWire.d.ts +20 -2
- package/dist/hitl/askGateWire.js +50 -1
- package/dist/hitl/askParkRowRouting.d.ts +5 -0
- package/dist/hitl/askParkRowRouting.js +32 -1
- package/dist/hitl/askSettlementLine.d.ts +28 -0
- package/dist/hitl/askSettlementLine.js +99 -0
- package/dist/hitl/automaticAnswerVerdict.d.ts +3 -2
- package/dist/hitl/automaticAnswerVerdict.js +29 -13
- package/dist/hitl/crashConverged.d.ts +11 -20
- package/dist/hitl/crashConverged.js +56 -0
- package/dist/hitl/crashConvergedNotice.d.ts +6 -3
- package/dist/hitl/crashConvergedNotice.js +48 -24
- package/dist/hitl/decisionConflict.js +3 -10
- package/dist/hitl/decisionRefusal.d.ts +40 -1
- package/dist/hitl/decisionRefusal.js +199 -42
- package/dist/hitl/frameRouter.d.ts +5 -2
- package/dist/hitl/frameRouter.js +27 -24
- package/dist/hitl/gateLedger.d.ts +2 -0
- package/dist/hitl/gateLedger.js +50 -13
- package/dist/hitl/hitlBridge.d.ts +2 -2
- package/dist/hitl/hitlBridge.js +13 -10
- package/dist/hitl/livePendingAsk.d.ts +3 -3
- package/dist/hitl/livePendingAsk.js +7 -18
- package/dist/hitl/parkResolver.d.ts +2 -24
- package/dist/hitl/parkResolver.js +61 -97
- package/dist/hitl/persistedRulesWire.d.ts +25 -0
- package/dist/hitl/persistedRulesWire.js +104 -2
- package/dist/hitl/planReviewWire.d.ts +31 -13
- package/dist/hitl/planReviewWire.js +120 -78
- package/dist/hitl/refusedToolNameProse.d.ts +0 -1
- package/dist/hitl/refusedToolNameProse.js +0 -3
- package/dist/hitl/replayedApproval.d.ts +4 -3
- package/dist/hitl/replayedApproval.js +7 -4
- package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
- package/dist/hitl/sessionPolicyDeliverable.js +48 -7
- package/dist/hitl/sessionPolicyWire.d.ts +34 -21
- package/dist/hitl/sessionPolicyWire.js +179 -70
- package/dist/hitl/standingRows.d.ts +20 -2
- package/dist/hitl/standingRows.js +69 -8
- package/dist/hitl/suspendedReopen.d.ts +2 -1
- package/dist/hitl/suspendedReopen.js +7 -10
- package/dist/hitl/toolApprovalWire.d.ts +103 -156
- package/dist/hitl/toolApprovalWire.js +661 -411
- package/dist/hookMatcherVerdict.d.ts +6 -1
- package/dist/hookMatcherVerdict.js +14 -7
- package/dist/hooksWireCaps.d.ts +2 -2
- package/dist/hooksWireCaps.js +174 -81
- package/dist/host.d.ts +21 -0
- package/dist/hostTurnSettings.d.ts +71 -0
- package/dist/hostTurnSettings.js +291 -0
- package/dist/humanTurn.d.ts +14 -1
- package/dist/humanTurn.js +100 -12
- package/dist/humanTurnRead.d.ts +2 -0
- package/dist/humanTurnRead.js +22 -1
- package/dist/i18n/messages.en.d.ts +703 -0
- package/dist/i18n/messages.en.js +701 -0
- package/dist/i18n/messages.zh.d.ts +3 -0
- package/dist/i18n/messages.zh.js +837 -0
- package/dist/i18n/translate.d.ts +25 -0
- package/dist/i18n/translate.js +127 -0
- package/dist/index.d.ts +78 -29
- package/dist/index.js +54 -18
- package/dist/inheritEnvCapability.d.ts +32 -0
- package/dist/inheritEnvCapability.js +104 -0
- package/dist/inheritEnvWire.d.ts +3 -2
- package/dist/inheritEnvWire.js +12 -14
- package/dist/interactiveHalt.js +17 -6
- package/dist/liveModelCatalog.d.ts +3 -3
- package/dist/liveModelCatalog.js +15 -13
- package/dist/liveQuestionStore.d.ts +2 -21
- package/dist/mcpLiveness.d.ts +2 -1
- package/dist/mcpPanel.d.ts +10 -1
- package/dist/mcpPanel.js +40 -13
- package/dist/mcpProbeCapability.d.ts +2 -1
- package/dist/mcpProbeCapability.js +7 -11
- package/dist/mcpProbeWire.d.ts +9 -2
- package/dist/mcpProbeWire.js +6 -1
- package/dist/mcpWireCaps.d.ts +47 -2
- package/dist/mcpWireCaps.js +164 -16
- package/dist/memoryEntriesWire.d.ts +4 -9
- package/dist/memoryEntriesWire.js +5 -10
- package/dist/model/modelSupplyRules.d.ts +0 -2
- package/dist/model/modelSupplyRules.js +3 -12
- package/dist/model/modelsPolicy.d.ts +0 -5
- package/dist/model/modelsPolicy.js +6 -36
- package/dist/model/onboardJudgement.d.ts +93 -0
- package/dist/model/onboardJudgement.js +415 -0
- package/dist/model/subagentModelWord.d.ts +31 -0
- package/dist/model/subagentModelWord.js +261 -0
- package/dist/model/tierVocabulary.d.ts +2 -0
- package/dist/model/tierVocabulary.js +17 -5
- package/dist/modelCapabilityProbe.d.ts +64 -0
- package/dist/modelCapabilityProbe.js +600 -0
- package/dist/modelIdentityResolvability.d.ts +3 -0
- package/dist/modelIdentityResolvability.js +26 -17
- package/dist/notifications.d.ts +6 -0
- package/dist/notifications.js +71 -23
- package/dist/outputStyleSeatCapability.d.ts +0 -3
- package/dist/outputStyleSeatCapability.js +0 -3
- package/dist/ownKey.d.ts +22 -0
- package/dist/ownKey.js +94 -3
- package/dist/panelReduce.d.ts +21 -10
- package/dist/panelReduce.js +728 -550
- package/dist/panelStateHolder.d.ts +3 -7
- package/dist/panelStateHolder.js +14 -130
- package/dist/peerLaneCapability.d.ts +0 -4
- package/dist/peerLaneCapability.js +0 -6
- package/dist/permissionRuleIssue.js +2 -0
- package/dist/permissionRulesWriteCapability.d.ts +2 -5
- package/dist/permissionRulesWriteCapability.js +8 -12
- package/dist/permissionWireCaps.d.ts +2 -2
- package/dist/permissionWireCaps.js +2 -0
- package/dist/permissionsAllowGrantCapability.d.ts +0 -4
- package/dist/permissionsAllowGrantCapability.js +0 -6
- package/dist/permissionsDeclaration.d.ts +0 -11
- package/dist/permissionsDeclaration.js +60 -53
- package/dist/pluginHooksWire.d.ts +46 -3
- package/dist/pluginHooksWire.js +219 -16
- package/dist/preemptWire.d.ts +44 -0
- package/dist/preemptWire.js +83 -0
- package/dist/printModelStatus.d.ts +63 -0
- package/dist/printModelStatus.js +155 -0
- package/dist/printToolResultFrame.js +15 -4
- package/dist/replayBody.d.ts +3 -0
- package/dist/replayBody.js +14 -0
- package/dist/request/taskRequest.d.ts +11 -6
- package/dist/request/taskRequest.js +112 -19
- package/dist/resumeRefusalCopy.d.ts +13 -9
- package/dist/resumeRefusalCopy.js +81 -118
- package/dist/retryStatus.d.ts +45 -0
- package/dist/retryStatus.js +185 -1
- package/dist/rewindArchiveCapability.d.ts +0 -4
- package/dist/rewindArchiveCapability.js +2 -10
- package/dist/rewindArchiveReading.d.ts +0 -1
- package/dist/rewindArchiveReading.js +0 -3
- package/dist/runCancelContext.d.ts +2 -1
- package/dist/runCancelContext.js +4 -2
- package/dist/runReattachPolicy.d.ts +31 -0
- package/dist/runReattachPolicy.js +46 -0
- package/dist/runTerminal.d.ts +3 -6
- package/dist/runTerminal.js +8 -9
- package/dist/sandboxWire.d.ts +3 -1
- package/dist/sandboxWire.js +76 -27
- package/dist/scenarioRefusal.d.ts +9 -0
- package/dist/scenarioRefusal.js +111 -0
- package/dist/scenarioWire.js +1 -1
- package/dist/seam.d.ts +48 -2
- package/dist/seam.js +25 -4
- package/dist/seatContract.d.ts +311 -18
- package/dist/seatContract.js +824 -100
- package/dist/selfOrchestrationDenial.js +7 -19
- package/dist/sessionIdSegment.d.ts +6 -0
- package/dist/sessionIdSegment.js +24 -0
- package/dist/sessionMemoryStatus.js +6 -11
- package/dist/sessionPolicyCapability.d.ts +2 -5
- package/dist/sessionPolicyCapability.js +8 -12
- package/dist/sessionSyncFileHistoryCapability.d.ts +0 -3
- package/dist/sessionSyncFileHistoryCapability.js +0 -3
- package/dist/settingsHooksSalvage.d.ts +44 -0
- package/dist/settingsHooksSalvage.js +211 -0
- package/dist/skillToolListsCapability.d.ts +2 -4
- package/dist/skillToolListsCapability.js +8 -9
- package/dist/sqlEngineCapability.d.ts +0 -4
- package/dist/sqlEngineCapability.js +0 -6
- package/dist/sseIdleTriage.js +3 -2
- package/dist/steerPriorityCapability.d.ts +0 -3
- package/dist/steerPriorityCapability.js +0 -3
- package/dist/streamDrainingLegs.d.ts +4 -0
- package/dist/streamDrainingLegs.js +6 -1
- package/dist/subagent/engineCompactWire.d.ts +0 -1
- package/dist/subagent/engineCompactWire.js +7 -5
- package/dist/subagent/engineSubagentResume.js +15 -9
- package/dist/subagent/engineTaskHandleWire.js +4 -7
- package/dist/subagentContentStore.d.ts +3 -0
- package/dist/subagentContentStore.js +22 -10
- package/dist/submitReopen.d.ts +24 -0
- package/dist/submitReopen.js +75 -0
- package/dist/terminalStatuses.d.ts +3 -0
- package/dist/terminalStatuses.js +10 -2
- package/dist/toolHistoryMismatch.js +3 -2
- package/dist/toolResult.d.ts +10 -1
- package/dist/toolResult.js +34 -6
- package/dist/toolRoster.d.ts +3 -4
- package/dist/toolRoster.js +21 -22
- package/dist/turnFailurePresentation.d.ts +39 -0
- package/dist/turnFailurePresentation.js +402 -0
- package/dist/usageAnalytics.js +6 -11
- package/dist/userAttachmentEnvelope.d.ts +1 -0
- package/dist/userAttachmentEnvelope.js +37 -7
- package/dist/userAttachmentSeat.d.ts +21 -0
- package/dist/userAttachmentSeat.js +75 -0
- package/dist/userInvokedSkillsCapability.d.ts +11 -4
- package/dist/userInvokedSkillsCapability.js +31 -10
- package/dist/webSearchBackendCapability.d.ts +0 -4
- package/dist/webSearchBackendCapability.js +0 -6
- package/dist/wireErrorTriage.d.ts +7 -0
- package/dist/wireErrorTriage.js +26 -23
- package/dist/wireFailureShape.d.ts +62 -5
- package/dist/wireFailureShape.js +106 -5
- package/dist/wireRefusalCopy.d.ts +25 -3
- package/dist/wireRefusalCopy.js +74 -80
- package/dist/workflowsJournalCapability.d.ts +2 -5
- package/dist/workflowsJournalCapability.js +8 -12
- package/dist/writeProtectionCapability.d.ts +0 -4
- package/dist/writeProtectionCapability.js +0 -6
- package/docs/INTEGRATION-CLIENTS.md +1775 -56
- package/package.json +6 -5
- package/dist/attachmentSeatCapability.d.ts +0 -12
- package/dist/attachmentSeatCapability.js +0 -23
- package/dist/hitl/approvalOutcomeNote.d.ts +0 -10
- package/dist/hitl/approvalOutcomeNote.js +0 -29
- package/dist/sessionReadRedactionCapability.d.ts +0 -13
- package/dist/sessionReadRedactionCapability.js +0 -35
|
@@ -1,8 +1,155 @@
|
|
|
1
|
+
export const PARKED_TOOL_ROWS_MAX = 64;
|
|
2
|
+
export const LATEST_START_ROWS_MAX = 1024;
|
|
3
|
+
const str = (v) => (typeof v === 'string' && v.length > 0 ? v : undefined);
|
|
4
|
+
function ownData(o, key) {
|
|
5
|
+
try {
|
|
6
|
+
if (typeof o !== 'object' || o === null)
|
|
7
|
+
return undefined;
|
|
8
|
+
const d = Object.getOwnPropertyDescriptor(o, key);
|
|
9
|
+
return d !== undefined && Object.hasOwn(d, 'value') ? d.value : undefined;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
1
15
|
export function createAdapterInstanceLedger() {
|
|
2
16
|
const renderedNotifications = new Set();
|
|
3
17
|
const seenWorkflowToolCallIds = new Set();
|
|
4
18
|
const firedSubagentStartHookTaskIds = new Set();
|
|
19
|
+
const parkedRows = new Map();
|
|
20
|
+
let passSeq = 0;
|
|
21
|
+
let rowSeq = 0;
|
|
22
|
+
const addParkedRow = (r) => {
|
|
23
|
+
const seq = ++rowSeq;
|
|
24
|
+
const key = `${r.sessionId}\u0000${r.parkedRun ?? ''}\u0000${seq}`;
|
|
25
|
+
parkedRows.set(key, { ...r, key, seq });
|
|
26
|
+
while (parkedRows.size > PARKED_TOOL_ROWS_MAX) {
|
|
27
|
+
const oldest = parkedRows.keys().next();
|
|
28
|
+
if (oldest.done === true)
|
|
29
|
+
break;
|
|
30
|
+
parkedRows.delete(oldest.value);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const latestStartRows = new Map();
|
|
34
|
+
const callKey = (sessionId, toolCallId) => `${sessionId}\u0000${toolCallId}`;
|
|
35
|
+
const isClaimable = (r) => r.card.rowUuid !== undefined && latestStartRows.get(callKey(r.sessionId, r.toolCallId)) === r.card.rowUuid;
|
|
36
|
+
const setLatestStartRow = (key, rowUuid) => {
|
|
37
|
+
latestStartRows.delete(key);
|
|
38
|
+
latestStartRows.set(key, rowUuid);
|
|
39
|
+
if (latestStartRows.size <= LATEST_START_ROWS_MAX)
|
|
40
|
+
return;
|
|
41
|
+
const pinned = new Set([...parkedRows.values()].map((r) => callKey(r.sessionId, r.toolCallId)));
|
|
42
|
+
for (const k of latestStartRows.keys()) {
|
|
43
|
+
if (latestStartRows.size <= LATEST_START_ROWS_MAX)
|
|
44
|
+
break;
|
|
45
|
+
if (!pinned.has(k))
|
|
46
|
+
latestStartRows.delete(k);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const latestFor = (sessionId, toolCallId, pass) => {
|
|
50
|
+
let hit;
|
|
51
|
+
for (const r of parkedRows.values()) {
|
|
52
|
+
if (r.sessionId === sessionId && r.toolCallId === toolCallId && (pass === undefined || r.pass === pass))
|
|
53
|
+
hit = r;
|
|
54
|
+
}
|
|
55
|
+
return hit;
|
|
56
|
+
};
|
|
5
57
|
return {
|
|
58
|
+
beginPass: () => ++passSeq,
|
|
59
|
+
parkToolRow: (row) => {
|
|
60
|
+
addParkedRow({ sessionId: row.sessionId, toolCallId: row.toolCallId, card: row.card, pass: row.pass });
|
|
61
|
+
},
|
|
62
|
+
parkedToolRowFor: (sessionId, toolCallId) => {
|
|
63
|
+
const r = latestFor(sessionId, toolCallId);
|
|
64
|
+
return r !== undefined && isClaimable(r) ? r : undefined;
|
|
65
|
+
},
|
|
66
|
+
noteParkedFact: (sessionId, pass, fact) => {
|
|
67
|
+
if (fact.heldCallId === undefined)
|
|
68
|
+
return;
|
|
69
|
+
const r = latestFor(sessionId, fact.heldCallId, pass);
|
|
70
|
+
if (r === undefined)
|
|
71
|
+
return;
|
|
72
|
+
if (fact.checkpointId !== undefined)
|
|
73
|
+
r.checkpointId = fact.checkpointId;
|
|
74
|
+
if (fact.taskId !== undefined)
|
|
75
|
+
r.parkedRun = fact.taskId;
|
|
76
|
+
},
|
|
77
|
+
retireParkedRowsOfRun: (sessionId, pass, taskId) => {
|
|
78
|
+
for (const [key, r] of parkedRows) {
|
|
79
|
+
if (r.sessionId !== sessionId)
|
|
80
|
+
continue;
|
|
81
|
+
if (r.parkedRun !== undefined ? r.parkedRun === taskId : r.pass === pass)
|
|
82
|
+
parkedRows.delete(key);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
dropParkedToolRow: (key) => {
|
|
86
|
+
parkedRows.delete(key);
|
|
87
|
+
},
|
|
88
|
+
noteStartRow: (sessionId, toolCallId, rowUuid) => {
|
|
89
|
+
setLatestStartRow(callKey(sessionId, toolCallId), rowUuid ?? null);
|
|
90
|
+
},
|
|
91
|
+
listParkedToolRows: () => [...parkedRows.values()].filter(isClaimable).map((r) => ({
|
|
92
|
+
sessionId: r.sessionId,
|
|
93
|
+
toolCallId: r.toolCallId,
|
|
94
|
+
...(r.parkedRun !== undefined ? { parkedRun: r.parkedRun } : {}),
|
|
95
|
+
...(r.checkpointId !== undefined ? { checkpointId: r.checkpointId } : {}),
|
|
96
|
+
card: {
|
|
97
|
+
id: r.card.id,
|
|
98
|
+
name: r.card.name,
|
|
99
|
+
rawInput: r.card.rawInput,
|
|
100
|
+
...(r.card.eventId !== undefined ? { eventId: r.card.eventId } : {}),
|
|
101
|
+
...(r.card.parentToolCallId !== undefined ? { parentToolCallId: r.card.parentToolCallId } : {}),
|
|
102
|
+
...(r.card.rowUuid !== undefined ? { rowUuid: r.card.rowUuid } : {}),
|
|
103
|
+
...(r.card.engineRef !== undefined ? { engineRef: r.card.engineRef } : {}),
|
|
104
|
+
},
|
|
105
|
+
})),
|
|
106
|
+
takeParkedToolRows: (rows) => {
|
|
107
|
+
let n = 0;
|
|
108
|
+
let list = [];
|
|
109
|
+
try {
|
|
110
|
+
list = Array.isArray(rows) ? [...rows] : [];
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
list = [];
|
|
114
|
+
}
|
|
115
|
+
for (const raw of list) {
|
|
116
|
+
const sessionId = str(ownData(raw, 'sessionId'));
|
|
117
|
+
const toolCallId = str(ownData(raw, 'toolCallId'));
|
|
118
|
+
const card = ownData(raw, 'card');
|
|
119
|
+
const id = str(ownData(card, 'id'));
|
|
120
|
+
const name = str(ownData(card, 'name'));
|
|
121
|
+
if (sessionId === undefined || toolCallId === undefined || id === undefined || id !== toolCallId || name === undefined)
|
|
122
|
+
continue;
|
|
123
|
+
const rowUuid = str(ownData(card, 'rowUuid'));
|
|
124
|
+
if ([...parkedRows.values()].some((r) => r.sessionId === sessionId && r.toolCallId === toolCallId && r.card.rowUuid === rowUuid))
|
|
125
|
+
continue;
|
|
126
|
+
const eventId = str(ownData(card, 'eventId'));
|
|
127
|
+
const parentToolCallId = str(ownData(card, 'parentToolCallId'));
|
|
128
|
+
const engineRef = ownData(card, 'engineRef');
|
|
129
|
+
const parkedRun = str(ownData(raw, 'parkedRun'));
|
|
130
|
+
const checkpointId = str(ownData(raw, 'checkpointId'));
|
|
131
|
+
const ck = callKey(sessionId, toolCallId);
|
|
132
|
+
if (!latestStartRows.has(ck) && rowUuid !== undefined)
|
|
133
|
+
setLatestStartRow(ck, rowUuid);
|
|
134
|
+
addParkedRow({
|
|
135
|
+
sessionId,
|
|
136
|
+
toolCallId,
|
|
137
|
+
card: {
|
|
138
|
+
id,
|
|
139
|
+
name,
|
|
140
|
+
rawInput: ownData(card, 'rawInput'),
|
|
141
|
+
...(eventId !== undefined ? { eventId } : {}),
|
|
142
|
+
...(parentToolCallId !== undefined ? { parentToolCallId } : {}),
|
|
143
|
+
...(rowUuid !== undefined ? { rowUuid } : {}),
|
|
144
|
+
...(typeof engineRef === 'object' && engineRef !== null ? { engineRef: engineRef } : {}),
|
|
145
|
+
},
|
|
146
|
+
...(parkedRun !== undefined ? { parkedRun } : {}),
|
|
147
|
+
...(checkpointId !== undefined ? { checkpointId } : {}),
|
|
148
|
+
});
|
|
149
|
+
n++;
|
|
150
|
+
}
|
|
151
|
+
return n;
|
|
152
|
+
},
|
|
6
153
|
hasRenderedNotification: (key) => renderedNotifications.has(key),
|
|
7
154
|
addRenderedNotification: (key) => {
|
|
8
155
|
renderedNotifications.add(key);
|
|
@@ -10,7 +10,7 @@ export interface PanelTaskLedger {
|
|
|
10
10
|
noteResidency(taskId: string, residentKey?: string): void;
|
|
11
11
|
start(taskId: string, agentType?: string): Generator<AdapterOutput>;
|
|
12
12
|
settle(cardId: string | null, isError: boolean, report?: string): Generator<AdapterOutput>;
|
|
13
|
-
settleFromNotification(taskId: string, isError: boolean): Generator<AdapterOutput>;
|
|
13
|
+
settleFromNotification(taskId: string, isError: boolean, sessionId?: string): Generator<AdapterOutput>;
|
|
14
14
|
settleFromTerminalTick(taskId: string, isError: boolean): Generator<AdapterOutput>;
|
|
15
15
|
}
|
|
16
16
|
export declare function createPanelTaskLedger(ctx: AdapterContext, cards: OpenCardView, inst: AdapterInstanceLedger): PanelTaskLedger;
|
package/dist/adapt/panelTasks.js
CHANGED
|
@@ -88,7 +88,7 @@ export function createPanelTaskLedger(ctx, cards, inst) {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
|
-
*settleFromNotification(taskId, isError) {
|
|
91
|
+
*settleFromNotification(taskId, isError, sessionId) {
|
|
92
92
|
clearResidencyBothKeys(taskId);
|
|
93
93
|
if (endedPanelTasks.has(taskId))
|
|
94
94
|
return;
|
|
@@ -96,7 +96,7 @@ export function createPanelTaskLedger(ctx, cards, inst) {
|
|
|
96
96
|
yield chrome({
|
|
97
97
|
kind: 'panel_task',
|
|
98
98
|
laneProof: mainLane(),
|
|
99
|
-
event: panelEndFact(taskId, isError),
|
|
99
|
+
event: panelEndFact(taskId, isError, sessionId !== undefined ? { sessionId } : undefined),
|
|
100
100
|
});
|
|
101
101
|
if (inst.hasFiredSubagentStart(taskId)) {
|
|
102
102
|
yield chrome({
|
|
@@ -35,6 +35,7 @@ export interface TextStream {
|
|
|
35
35
|
closeSegmentAuthorityWindowOnNextText(): void;
|
|
36
36
|
replaceThinkingSegment(content: string, anchor?: Frame): ThinkingSegmentReplacement;
|
|
37
37
|
segmentId(): string;
|
|
38
|
+
anchorWindow(frame: Frame): void;
|
|
38
39
|
rotateSegmentIdentity(anchor: Frame): void;
|
|
39
40
|
stampSegmentIdentity(out: AdapterOutput): AdapterOutput;
|
|
40
41
|
readonly answerLength: number;
|
package/dist/adapt/textStream.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chrome, mainLane, transcript, messageIdentityOf } from './ids.js';
|
|
1
|
+
import { chrome, mainLane, segmentRowId, transcript, messageIdentityOf } from './ids.js';
|
|
2
2
|
import { estimateCjkTokens, FLUSH_INTERVAL_MS } from './wireShapes.js';
|
|
3
3
|
import { resolveTextSegmentAuthority } from './textSegmentAuthority.js';
|
|
4
4
|
export const SEMA_SEGMENT_ID_KEY = '_sema_segment_id';
|
|
@@ -44,14 +44,15 @@ export function createTextStream(ctx, idOf) {
|
|
|
44
44
|
: FLUSH_INTERVAL_MS;
|
|
45
45
|
let segmentAnchor = null;
|
|
46
46
|
let thinkingAnchor = null;
|
|
47
|
+
let segmentLast = null;
|
|
48
|
+
let thinkingLast = null;
|
|
47
49
|
let committedThinking = [];
|
|
48
50
|
let thinkingSettled = false;
|
|
49
51
|
let segmentWindowAnchor = null;
|
|
50
|
-
let segmentWindowSerial = 0;
|
|
51
52
|
let segmentIdCache = null;
|
|
52
53
|
const segmentIdNow = () => {
|
|
53
54
|
if (segmentIdCache === null)
|
|
54
|
-
segmentIdCache = idOf(segmentWindowAnchor ?? {},
|
|
55
|
+
segmentIdCache = idOf(segmentWindowAnchor ?? {}, 'segment');
|
|
55
56
|
return segmentIdCache;
|
|
56
57
|
};
|
|
57
58
|
function* takeThinking() {
|
|
@@ -61,7 +62,7 @@ export function createTextStream(ctx, idOf) {
|
|
|
61
62
|
const msg = {
|
|
62
63
|
type: 'assistant',
|
|
63
64
|
message: { role: 'assistant', content: [{ type: 'thinking', thinking }], ...messageIdentityOf(anchor, ctx) },
|
|
64
|
-
uuid: idOf
|
|
65
|
+
uuid: segmentRowId(idOf, anchor, thinkingLast, 'thinking'),
|
|
65
66
|
session_id: ctx.sessionId,
|
|
66
67
|
parent_tool_use_id: null,
|
|
67
68
|
};
|
|
@@ -70,6 +71,7 @@ export function createTextStream(ctx, idOf) {
|
|
|
70
71
|
thinkingSettled = false;
|
|
71
72
|
thinking = '';
|
|
72
73
|
thinkingAnchor = null;
|
|
74
|
+
thinkingLast = null;
|
|
73
75
|
thinkingBlockOpen = false;
|
|
74
76
|
yield chrome({ kind: 'thinking_activity', laneProof: mainLane(), active: false });
|
|
75
77
|
yield transcript(msg, ctx.now());
|
|
@@ -82,7 +84,7 @@ export function createTextStream(ctx, idOf) {
|
|
|
82
84
|
const msg = {
|
|
83
85
|
type: 'assistant',
|
|
84
86
|
message: { role: 'assistant', content: [{ type: 'text', text: body }], ...messageIdentityOf(anchor, ctx) },
|
|
85
|
-
uuid: idOf
|
|
87
|
+
uuid: segmentRowId(idOf, anchor, segmentLast, 'text'),
|
|
86
88
|
session_id: ctx.sessionId,
|
|
87
89
|
parent_tool_use_id: null,
|
|
88
90
|
};
|
|
@@ -94,6 +96,7 @@ export function createTextStream(ctx, idOf) {
|
|
|
94
96
|
segmentSealed = '';
|
|
95
97
|
answerSegment = '';
|
|
96
98
|
segmentAnchor = null;
|
|
99
|
+
segmentLast = null;
|
|
97
100
|
emittedAssistantText = true;
|
|
98
101
|
textBlockOpen = false;
|
|
99
102
|
yield transcript(msg, ctx.now());
|
|
@@ -158,6 +161,7 @@ export function createTextStream(ctx, idOf) {
|
|
|
158
161
|
}
|
|
159
162
|
if (answerSegment.length === 0 && segmentSealed.length === 0)
|
|
160
163
|
segmentAnchor = frame;
|
|
164
|
+
segmentLast = frame;
|
|
161
165
|
if (segmentWindowAnchor === null)
|
|
162
166
|
segmentWindowAnchor = frame;
|
|
163
167
|
answer += delta;
|
|
@@ -176,6 +180,7 @@ export function createTextStream(ctx, idOf) {
|
|
|
176
180
|
thinkingSettled = false;
|
|
177
181
|
}
|
|
178
182
|
}
|
|
183
|
+
thinkingLast = frame;
|
|
179
184
|
if (thinking.length === 0) {
|
|
180
185
|
thinkingAnchor = frame;
|
|
181
186
|
yield chrome({ kind: 'thinking_activity', laneProof: mainLane(), active: true });
|
|
@@ -283,6 +288,8 @@ export function createTextStream(ctx, idOf) {
|
|
|
283
288
|
}
|
|
284
289
|
else {
|
|
285
290
|
segmentSealed += verdict.tail;
|
|
291
|
+
if (diverged && anchor !== undefined)
|
|
292
|
+
segmentLast = anchor;
|
|
286
293
|
}
|
|
287
294
|
answerSegment = '';
|
|
288
295
|
if (answer.endsWith(liveSegment)) {
|
|
@@ -290,6 +297,8 @@ export function createTextStream(ctx, idOf) {
|
|
|
290
297
|
}
|
|
291
298
|
if (segmentAnchor === null && anchor !== undefined)
|
|
292
299
|
segmentAnchor = anchor;
|
|
300
|
+
if (segmentLast === null && anchor !== undefined)
|
|
301
|
+
segmentLast = anchor;
|
|
293
302
|
segmentCommitted = '';
|
|
294
303
|
previousSegmentCommitted = '';
|
|
295
304
|
idleFlushUsedInSegment = false;
|
|
@@ -314,7 +323,7 @@ export function createTextStream(ctx, idOf) {
|
|
|
314
323
|
if (typeof committed === 'string')
|
|
315
324
|
committedText += committed;
|
|
316
325
|
},
|
|
317
|
-
replaceThinkingSegment: (content) => {
|
|
326
|
+
replaceThinkingSegment: (content, anchor) => {
|
|
318
327
|
const rows = committedThinking;
|
|
319
328
|
committedThinking = [];
|
|
320
329
|
const prefix = rows.map((r) => r.text).join('');
|
|
@@ -330,6 +339,8 @@ export function createTextStream(ctx, idOf) {
|
|
|
330
339
|
thinkingPending = content.startsWith(emitted) ? content.slice(emitted.length) : '';
|
|
331
340
|
thinking = content;
|
|
332
341
|
thinkingSettled = content.length > 0;
|
|
342
|
+
if (diverged && anchor !== undefined)
|
|
343
|
+
thinkingLast = anchor;
|
|
333
344
|
return { diverged, committedPrefixLen: 0, committedPrefixDiverged: false, committedUuids: [] };
|
|
334
345
|
}
|
|
335
346
|
const committedPrefixDiverged = !content.startsWith(prefix);
|
|
@@ -340,19 +351,25 @@ export function createTextStream(ctx, idOf) {
|
|
|
340
351
|
thinkingPending = tail.startsWith(emitted) ? tail.slice(emitted.length) : '';
|
|
341
352
|
thinking = tail;
|
|
342
353
|
thinkingSettled = tail.length > 0;
|
|
354
|
+
if (diverged && anchor !== undefined)
|
|
355
|
+
thinkingLast = anchor;
|
|
343
356
|
}
|
|
344
357
|
return { diverged, committedPrefixLen: prefix.length, committedPrefixDiverged: false, ...(last !== undefined ? { committedUuid: last } : {}), committedUuids: uuids };
|
|
345
358
|
}
|
|
346
359
|
thinking = '';
|
|
347
360
|
thinkingPending = '';
|
|
348
361
|
thinkingAnchor = null;
|
|
362
|
+
thinkingLast = null;
|
|
349
363
|
thinkingSettled = false;
|
|
350
364
|
return { diverged: true, committedPrefixLen: prefix.length, committedPrefixDiverged: true, ...(last !== undefined ? { committedUuid: last } : {}), committedUuids: uuids };
|
|
351
365
|
},
|
|
352
366
|
segmentId: segmentIdNow,
|
|
367
|
+
anchorWindow: (frame) => {
|
|
368
|
+
if (segmentWindowAnchor === null)
|
|
369
|
+
segmentWindowAnchor = frame;
|
|
370
|
+
},
|
|
353
371
|
rotateSegmentIdentity: (anchor) => {
|
|
354
372
|
committedTextRows = [];
|
|
355
|
-
segmentWindowSerial += 1;
|
|
356
373
|
segmentWindowAnchor = anchor;
|
|
357
374
|
segmentIdCache = null;
|
|
358
375
|
},
|
|
@@ -1,25 +1,44 @@
|
|
|
1
1
|
import type { AdapterContext, AdapterOutput } from '../seam.js';
|
|
2
|
-
import { structuredToToolUseResult, type ToolResultBody } from '../toolResult.js';
|
|
2
|
+
import { structuredToToolUseResult, type ToolKillCause, type ToolResultBody } from '../toolResult.js';
|
|
3
3
|
import { type Frame, type IdOf } from './ids.js';
|
|
4
|
+
import type { EngineRowRef } from '../engineRowRef.js';
|
|
5
|
+
import { type GateOutcomeView } from '../gateOutcome.js';
|
|
4
6
|
type RichToolUseResult = NonNullable<ReturnType<typeof structuredToToolUseResult>>;
|
|
5
7
|
export interface ToolResultOutcome {
|
|
6
8
|
readonly body: ToolResultBody;
|
|
7
9
|
readonly rich: RichToolUseResult | null;
|
|
8
10
|
}
|
|
9
11
|
export type ToolResultOwner = 'leader' | 'subagent';
|
|
10
|
-
export declare function toolResultOutcomeOf(toolName: string, end: ToolEndPayload | undefined, rawInput: PendingToolUse['rawInput'], owner: ToolResultOwner, ledgerTier?: (isError: boolean) => RichToolUseResult | null): ToolResultOutcome;
|
|
12
|
+
export declare function toolResultOutcomeOf(toolName: string, end: ToolEndPayload | undefined, rawInput: PendingToolUse['rawInput'], owner: ToolResultOwner, ledgerTier?: (isError: boolean) => RichToolUseResult | null, killCauseOf?: () => ToolKillCause | undefined): ToolResultOutcome;
|
|
11
13
|
export interface ToolResultEnvelopeKeys {
|
|
12
14
|
readonly tool_use_result?: ToolResultBody['toolUseResult'];
|
|
13
15
|
readonly _sema_degraded?: ToolResultBody['degraded'];
|
|
14
16
|
}
|
|
15
17
|
export declare function toolResultEnvelopeParts(o: ToolResultOutcome): ToolResultEnvelopeKeys;
|
|
16
|
-
interface PendingToolUse {
|
|
18
|
+
export interface PendingToolUse {
|
|
17
19
|
id: string;
|
|
18
20
|
name: string;
|
|
19
|
-
rawInput:
|
|
21
|
+
rawInput: {} | null | undefined;
|
|
20
22
|
eventId?: string;
|
|
21
23
|
parentToolCallId?: string;
|
|
24
|
+
engineRef?: EngineRowRef | undefined;
|
|
25
|
+
rowUuid?: string | undefined;
|
|
22
26
|
}
|
|
27
|
+
export declare function toolResultRowIdentity(sources: readonly {
|
|
28
|
+
readonly eventId?: string | undefined;
|
|
29
|
+
readonly engineRef?: EngineRowRef | undefined;
|
|
30
|
+
}[], toolCallId: string, ctx: Pick<AdapterContext, 'uuid'>): {
|
|
31
|
+
readonly uuid: string;
|
|
32
|
+
readonly engineRef?: EngineRowRef;
|
|
33
|
+
};
|
|
34
|
+
export interface ToolResultRowFlagParts {
|
|
35
|
+
readonly _sema_not_executed?: true;
|
|
36
|
+
readonly _sema_collateral_abort?: true;
|
|
37
|
+
readonly _sema_interrupted_never_started?: true;
|
|
38
|
+
readonly _sema_approval_window_expired?: true;
|
|
39
|
+
readonly _sema_denial_limit_window_expired?: true;
|
|
40
|
+
}
|
|
41
|
+
export declare function toolResultRowFlagParts(arm: object | null | undefined): ToolResultRowFlagParts;
|
|
23
42
|
interface ToolEndPayload {
|
|
24
43
|
output?: unknown;
|
|
25
44
|
structured?: unknown;
|
|
@@ -28,7 +47,9 @@ interface ToolEndPayload {
|
|
|
28
47
|
eventId?: string | undefined;
|
|
29
48
|
parentToolCallId?: string | undefined;
|
|
30
49
|
denialKind?: string | undefined;
|
|
31
|
-
|
|
50
|
+
closeArm?: object | undefined;
|
|
51
|
+
engineRef?: EngineRowRef | undefined;
|
|
52
|
+
gate?: GateOutcomeView | undefined;
|
|
32
53
|
}
|
|
33
54
|
export interface OpenCardView {
|
|
34
55
|
has(id: string): boolean;
|
|
@@ -37,6 +58,7 @@ export interface OpenCardView {
|
|
|
37
58
|
}
|
|
38
59
|
export interface ToolCardLedger extends OpenCardView {
|
|
39
60
|
open(p: PendingToolUse): void;
|
|
61
|
+
detach(id: string): PendingToolUse | undefined;
|
|
40
62
|
close(p: PendingToolUse, end?: ToolEndPayload): Generator<AdapterOutput>;
|
|
41
63
|
sweep(): Generator<AdapterOutput>;
|
|
42
64
|
mintResponseId(frame: Frame): string;
|
package/dist/adapt/toolCards.js
CHANGED
|
@@ -5,14 +5,17 @@ import { flattenWireOutput } from './wireShapes.js';
|
|
|
5
5
|
import { toolResultBlocksOf } from '../toolResultContent.js';
|
|
6
6
|
import { bashExitOf, bashExitReadingFailed } from '../bashExitReading.js';
|
|
7
7
|
import { isCcToolDenialKind } from '../gateVocabulary.js';
|
|
8
|
+
import { guardedRead, readFrameStringKey, readFrameTrueMark } from '../ownKey.js';
|
|
9
|
+
import { gateOutcomeOf, isApprovalWindowExpiredGate, isDenialLimitAutoDeniedGate } from '../gateOutcome.js';
|
|
10
|
+
import { TOOL_END_INTERRUPTED_NEVER_STARTED } from '../engineErrorCodes.js';
|
|
8
11
|
function toolUseResultParts(v) {
|
|
9
12
|
return v !== undefined ? { tool_use_result: v } : {};
|
|
10
13
|
}
|
|
11
|
-
export function toolResultOutcomeOf(toolName, end, rawInput, owner, ledgerTier) {
|
|
14
|
+
export function toolResultOutcomeOf(toolName, end, rawInput, owner, ledgerTier, killCauseOf) {
|
|
12
15
|
const isError = end?.isError ?? false;
|
|
13
16
|
const leaderLedger = owner === 'leader';
|
|
14
17
|
const body = end && end.output !== undefined
|
|
15
|
-
? wireOutputToBody(toolName, end.output, isError, end.truncated === true, flattenWireOutput, end.structured, leaderLedger)
|
|
18
|
+
? wireOutputToBody(toolName, end.output, isError, end.truncated === true, flattenWireOutput, end.structured, leaderLedger, killCauseOf)
|
|
16
19
|
: degradedToolResultBody(isError);
|
|
17
20
|
let rich = end?.structured !== undefined
|
|
18
21
|
? structuredToToolUseResult(end.structured, end.output !== undefined ? flattenWireOutput(end.output) : undefined, leaderLedger)
|
|
@@ -40,6 +43,27 @@ export function toolResultEnvelopeParts(o) {
|
|
|
40
43
|
...(o.body.degraded !== undefined ? { _sema_degraded: o.body.degraded } : {}),
|
|
41
44
|
};
|
|
42
45
|
}
|
|
46
|
+
export function toolResultRowIdentity(sources, toolCallId, ctx) {
|
|
47
|
+
for (const src of sources) {
|
|
48
|
+
if (typeof src.eventId === 'string' && src.eventId.length > 0) {
|
|
49
|
+
const ref = src.engineRef;
|
|
50
|
+
return { uuid: src.eventId, ...(ref !== undefined && ref.eventId === src.eventId ? { engineRef: ref } : {}) };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { uuid: deriveTranscriptId({ toolCallId }, ctx) };
|
|
54
|
+
}
|
|
55
|
+
export function toolResultRowFlagParts(arm) {
|
|
56
|
+
if (arm === null || arm === undefined)
|
|
57
|
+
return {};
|
|
58
|
+
const gate = guardedRead(() => gateOutcomeOf(arm));
|
|
59
|
+
return {
|
|
60
|
+
...(readFrameTrueMark(arm, 'notExecuted') ? { _sema_not_executed: true } : {}),
|
|
61
|
+
...(readFrameTrueMark(arm, '_sema_collateral_abort') ? { _sema_collateral_abort: true } : {}),
|
|
62
|
+
...(readFrameStringKey(arm, 'errorCode') === TOOL_END_INTERRUPTED_NEVER_STARTED ? { _sema_interrupted_never_started: true } : {}),
|
|
63
|
+
...(isApprovalWindowExpiredGate(gate) ? { _sema_approval_window_expired: true } : {}),
|
|
64
|
+
...(isDenialLimitAutoDeniedGate(gate) ? { _sema_denial_limit_window_expired: true } : {}),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
43
67
|
export function createToolCardLedger(ctx, idOf) {
|
|
44
68
|
const pending = new Map();
|
|
45
69
|
let assistantResponseId = null;
|
|
@@ -63,9 +87,9 @@ export function createToolCardLedger(ctx, idOf) {
|
|
|
63
87
|
return null;
|
|
64
88
|
lastLiveTodos = todo.newTodos;
|
|
65
89
|
return { toolUseResult: todo.toolUseResult, isError: todo.isError };
|
|
66
|
-
});
|
|
90
|
+
}, () => ctx.toolKillCause?.({ toolCallId: p.id, toolName: p.name }));
|
|
67
91
|
const { body } = outcome;
|
|
68
|
-
const
|
|
92
|
+
const ident = toolResultRowIdentity([{ eventId: end?.eventId, engineRef: end?.engineRef }, { eventId: p.eventId, engineRef: p.engineRef }], p.id, ctx);
|
|
69
93
|
yield transcript({
|
|
70
94
|
type: 'user',
|
|
71
95
|
message: {
|
|
@@ -79,12 +103,13 @@ export function createToolCardLedger(ctx, idOf) {
|
|
|
79
103
|
},
|
|
80
104
|
],
|
|
81
105
|
},
|
|
82
|
-
uuid:
|
|
106
|
+
uuid: idOf.adopt(ident.uuid, ident.engineRef),
|
|
83
107
|
session_id: ctx.sessionId,
|
|
84
108
|
...(parentToolCallId !== undefined ? { parent_tool_use_id: parentToolCallId } : {}),
|
|
85
109
|
...toolResultEnvelopeParts(outcome),
|
|
86
110
|
...(isCcToolDenialKind(end?.denialKind) ? { _sema_denial_kind: end.denialKind } : {}),
|
|
87
|
-
...(end?.
|
|
111
|
+
...(end?.gate !== undefined ? { _sema_gate: end.gate } : {}),
|
|
112
|
+
...toolResultRowFlagParts(end?.closeArm),
|
|
88
113
|
}, ctx.now());
|
|
89
114
|
}
|
|
90
115
|
function* closeCard(p, end) {
|
|
@@ -99,6 +124,14 @@ export function createToolCardLedger(ctx, idOf) {
|
|
|
99
124
|
open: (p) => {
|
|
100
125
|
pending.set(p.id, p);
|
|
101
126
|
},
|
|
127
|
+
detach: (id) => {
|
|
128
|
+
const p = pending.get(id);
|
|
129
|
+
if (p === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
pending.delete(id);
|
|
132
|
+
assistantResponseId = null;
|
|
133
|
+
return p;
|
|
134
|
+
},
|
|
102
135
|
close: closeCard,
|
|
103
136
|
*sweep() {
|
|
104
137
|
for (const [, p] of pending) {
|
package/dist/adapt/wireShapes.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { frozenSet } from '../frozenSet.js';
|
|
2
|
+
import { CORE_BUILTIN_SUBAGENT_TYPES } from '../generated/engineFactTables.js';
|
|
2
3
|
import { stripToolUseSideChannels } from '../adapter/types.js';
|
|
3
4
|
import { toolEndOutputText } from '../toolResultContent.js';
|
|
4
5
|
export const FLUSH_INTERVAL_MS = 100;
|
|
5
6
|
export const IDLE_FLUSH_MS = 1500;
|
|
7
|
+
const SHELL_ROLE_SUBAGENT_TYPE = 'worker';
|
|
8
|
+
function isHonouredSubagentType(word) {
|
|
9
|
+
return word === SHELL_ROLE_SUBAGENT_TYPE || CORE_BUILTIN_SUBAGENT_TYPES.includes(word);
|
|
10
|
+
}
|
|
6
11
|
export const SUBAGENT_TOOL_NAMES = frozenSet(['Task', 'Agent', 'Fork']);
|
|
7
12
|
export const WORKFLOW_TOOL_NAMES = frozenSet(['Workflow', 'RunWorkflow', 'run_workflow']);
|
|
8
13
|
export const TASK_TOOL_NAMES = new Set(['TodoWrite', 'TaskCreate', 'TaskUpdate']);
|
|
@@ -61,8 +66,7 @@ export function sanitizeToolUseBlock(block) {
|
|
|
61
66
|
}
|
|
62
67
|
if (SUBAGENT_TOOL_NAMES.has(out.name) && out.input && typeof out.input === 'object') {
|
|
63
68
|
const inp = out.input;
|
|
64
|
-
if (typeof inp.subagent_type === 'string' &&
|
|
65
|
-
!['fork', 'general-purpose', 'worker'].includes(inp.subagent_type)) {
|
|
69
|
+
if (typeof inp.subagent_type === 'string' && !isHonouredSubagentType(inp.subagent_type)) {
|
|
66
70
|
delete inp.subagent_type;
|
|
67
71
|
}
|
|
68
72
|
}
|
package/dist/adapt.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { AdapterContext, AdapterOutput, WireToCcAdapter } from './seam.js';
|
|
2
2
|
export { CANCEL_MESSAGE, estimateCjkTokens, flattenWireOutput, FLUSH_INTERVAL_MS, IDLE_FLUSH_MS, REJECT_MESSAGE, sanitizeToolUseBlock, SUBAGENT_TOOL_NAMES, WORKFLOW_TOOL_NAMES, } from './adapt/wireShapes.js';
|
|
3
|
+
import { type ParkedToolRowSnapshot } from './adapt/instanceLedger.js';
|
|
3
4
|
export interface AdapterLedgerState {
|
|
4
5
|
version: 1;
|
|
5
6
|
renderedNotifications: string[];
|
|
6
7
|
notifiedRuns: string[];
|
|
7
8
|
cardEnqueuedRuns: string[];
|
|
9
|
+
parkedToolRows?: ParkedToolRowSnapshot[];
|
|
8
10
|
}
|
|
9
11
|
export declare const ADAPTER_COVERAGE: {
|
|
10
12
|
readonly frames: readonly ["assistant", "user", "stream_event", "turn_usage", "result", "system", "task_notification", "workflow_complete", "diagnostics", "steering_injected", "workspace_changed", "human_input", "message_committed", "engine_notice", "text_end", "prompt_suggestions", "retry_status", "task_progress", "tool_end_result(label 补位 + 关卡 settle + response-id 复位 + 开卡台账出栈 + 经 cards.close 铸 tool_result)"];
|
package/dist/adapt.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isEngineWorkflowNotified, isWorkflowCompletionCardEnqueued, listNotifiedRuns, listWorkflowCompletionCardsEnqueued, markEngineWorkflowNotified, noteWorkflowCompletionCardEnqueued, parseTranscriptNotificationSeeds, } from './notifications.js';
|
|
2
2
|
export { CANCEL_MESSAGE, estimateCjkTokens, flattenWireOutput, FLUSH_INTERVAL_MS, IDLE_FLUSH_MS, REJECT_MESSAGE, sanitizeToolUseBlock, SUBAGENT_TOOL_NAMES, WORKFLOW_TOOL_NAMES, } from './adapt/wireShapes.js';
|
|
3
3
|
import { IDLE_FLUSH_MS } from './adapt/wireShapes.js';
|
|
4
|
-
import { chrome, mainLane, makeIdOf } from './adapt/ids.js';
|
|
4
|
+
import { carryRowSidecars, chrome, mainLane, makeIdOf } from './adapt/ids.js';
|
|
5
5
|
import { createTextStream } from './adapt/textStream.js';
|
|
6
6
|
import { createToolCardLedger } from './adapt/toolCards.js';
|
|
7
7
|
import { createPanelTaskLedger } from './adapt/panelTasks.js';
|
|
@@ -122,6 +122,7 @@ class WireToCcAdapterImpl {
|
|
|
122
122
|
renderedNotifications: this.ledger.listRenderedNotifications(),
|
|
123
123
|
notifiedRuns: listNotifiedRuns(),
|
|
124
124
|
cardEnqueuedRuns: listWorkflowCompletionCardsEnqueued(),
|
|
125
|
+
...((rows) => (rows.length > 0 ? { parkedToolRows: rows } : {}))(this.ledger.listParkedToolRows()),
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
128
|
importLedger(state) {
|
|
@@ -142,6 +143,7 @@ class WireToCcAdapterImpl {
|
|
|
142
143
|
n += this.ledger.takeRenderedNotifications(rendered);
|
|
143
144
|
takeModule(s.notifiedRuns, isEngineWorkflowNotified, markEngineWorkflowNotified);
|
|
144
145
|
takeModule(s.cardEnqueuedRuns, isWorkflowCompletionCardEnqueued, noteWorkflowCompletionCardEnqueued);
|
|
146
|
+
n += this.ledger.takeParkedToolRows(s.parkedToolRows);
|
|
145
147
|
return n;
|
|
146
148
|
}
|
|
147
149
|
importLedgerFromTranscript(messages) {
|
|
@@ -159,19 +161,22 @@ class WireToCcAdapterImpl {
|
|
|
159
161
|
async *adapt(frames, ctx) {
|
|
160
162
|
const slot = {};
|
|
161
163
|
for await (const out of this.adaptUnstamped(frames, ctx, slot)) {
|
|
162
|
-
|
|
164
|
+
const segmented = slot.text === undefined ? out : slot.text.stampSegmentIdentity(out);
|
|
165
|
+
yield slot.idOf === undefined ? segmented : carryRowSidecars(segmented, slot.idOf);
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
async *adaptUnstamped(frames, ctx, slot) {
|
|
166
169
|
const inst = this.ledger;
|
|
167
170
|
const turnStartAt = ctx.now();
|
|
168
171
|
const idOf = makeIdOf(ctx);
|
|
172
|
+
slot.idOf = idOf;
|
|
169
173
|
const text = createTextStream(ctx, idOf);
|
|
170
174
|
slot.text = text;
|
|
171
175
|
const cards = createToolCardLedger(ctx, idOf);
|
|
172
176
|
const panel = createPanelTaskLedger(ctx, cards, inst);
|
|
173
177
|
const flags = createTurnFlags(ctx, turnStartAt);
|
|
174
|
-
const
|
|
178
|
+
const pass = inst.beginPass();
|
|
179
|
+
const deps = { ctx, idOf, text, cards, panel, flags, inst, pass };
|
|
175
180
|
yield chrome({ kind: 'retry_status', laneProof: mainLane(), status: null });
|
|
176
181
|
yield chrome({ kind: 'prompt_suggestions', laneProof: mainLane(), suggestions: null });
|
|
177
182
|
yield chrome({ kind: 'thinking_activity', laneProof: mainLane(), active: false });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UiLanguage } from '../env/uiLanguage.js';
|
|
1
2
|
import type { ActiveRunBusySignal } from './runStream.js';
|
|
2
3
|
import type { PlanReviewReopenTrigger } from '../hitl/planReviewWire.js';
|
|
3
4
|
import { atMostOnceFailureClass } from '../atMostOnce.js';
|
|
@@ -99,6 +100,7 @@ export type SelfHealOutcome = {
|
|
|
99
100
|
taskId: string;
|
|
100
101
|
status: string;
|
|
101
102
|
alreadyOffered?: true;
|
|
103
|
+
pendingGateKind?: string | null;
|
|
102
104
|
} | {
|
|
103
105
|
kind: 'running-not-found';
|
|
104
106
|
taskId: string;
|
|
@@ -159,6 +161,10 @@ export type SelfHealOutcome = {
|
|
|
159
161
|
} | {
|
|
160
162
|
kind: 'ask-run-not-found';
|
|
161
163
|
taskId: string;
|
|
164
|
+
} | {
|
|
165
|
+
kind: 'ask-run-settled';
|
|
166
|
+
taskId: string;
|
|
167
|
+
status: string;
|
|
162
168
|
} | {
|
|
163
169
|
kind: 'stale-park-cancelled';
|
|
164
170
|
taskId: string;
|
|
@@ -226,6 +232,6 @@ export interface ActiveRunSelfHealCopy {
|
|
|
226
232
|
rowFor?: (outcome: SelfHealOutcome, signal: ActiveRunBusySignal | null | undefined) => string | undefined;
|
|
227
233
|
headlessRowFor?: (signal: ActiveRunBusySignal) => string | undefined;
|
|
228
234
|
}
|
|
229
|
-
export declare const INTERACTIVE_WAY_OUT
|
|
230
|
-
export declare function activeRunSelfHealRow(outcome: SelfHealOutcome, signal?: ActiveRunBusySignal | null, copy?: ActiveRunSelfHealCopy, origin?: RejectedSubmissionOrigin, follow?: SelfHealFollowDeclaration): string;
|
|
231
|
-
export declare function activeRunBusyHeadlessRow(signal: ActiveRunBusySignal, copy?: ActiveRunSelfHealCopy): string;
|
|
235
|
+
export declare const INTERACTIVE_WAY_OUT: string;
|
|
236
|
+
export declare function activeRunSelfHealRow(outcome: SelfHealOutcome, signal?: ActiveRunBusySignal | null, copy?: ActiveRunSelfHealCopy, origin?: RejectedSubmissionOrigin, follow?: SelfHealFollowDeclaration, lang?: UiLanguage): string;
|
|
237
|
+
export declare function activeRunBusyHeadlessRow(signal: ActiveRunBusySignal, copy?: ActiveRunSelfHealCopy, lang?: UiLanguage): string;
|