@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
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type EngineHistoryJson = string | number | boolean | null | readonly EngineHistoryJson[] | {
|
|
2
|
+
readonly [key: string]: EngineHistoryJson;
|
|
3
|
+
};
|
|
4
|
+
export interface EngineHistoryTextBlock {
|
|
5
|
+
readonly type: 'text';
|
|
6
|
+
readonly text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface EngineHistoryThinkingBlock {
|
|
9
|
+
readonly type: 'thinking';
|
|
10
|
+
readonly thinking: string;
|
|
11
|
+
readonly signature?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface EngineHistoryToolUseBlock {
|
|
14
|
+
readonly type: 'tool_use';
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly input: {
|
|
18
|
+
readonly [key: string]: EngineHistoryJson;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface EngineHistoryBase64Source {
|
|
22
|
+
readonly type: 'base64';
|
|
23
|
+
readonly media_type: string;
|
|
24
|
+
readonly data: string;
|
|
25
|
+
}
|
|
26
|
+
export interface EngineHistoryMediaBlock {
|
|
27
|
+
readonly type: 'image' | 'document';
|
|
28
|
+
readonly source: EngineHistoryBase64Source;
|
|
29
|
+
}
|
|
30
|
+
export interface EngineHistoryToolResultBlock {
|
|
31
|
+
readonly type: 'tool_result';
|
|
32
|
+
readonly tool_use_id: string;
|
|
33
|
+
readonly content: readonly EngineHistoryBlock[];
|
|
34
|
+
readonly is_error: boolean;
|
|
35
|
+
readonly _sema_gate_parked?: true;
|
|
36
|
+
}
|
|
37
|
+
export interface EngineHistoryOpaqueBlock {
|
|
38
|
+
readonly type: string;
|
|
39
|
+
readonly [key: string]: EngineHistoryJson;
|
|
40
|
+
}
|
|
41
|
+
export type EngineHistoryBlock = EngineHistoryTextBlock | EngineHistoryThinkingBlock | EngineHistoryToolUseBlock | EngineHistoryMediaBlock | EngineHistoryToolResultBlock | EngineHistoryOpaqueBlock;
|
|
42
|
+
export interface EngineHistoryMessageBody {
|
|
43
|
+
readonly role: 'user' | 'assistant';
|
|
44
|
+
readonly content: string | readonly EngineHistoryBlock[];
|
|
45
|
+
readonly model?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface EngineHistoryMessage {
|
|
48
|
+
readonly type: 'user' | 'assistant';
|
|
49
|
+
readonly uuid: string;
|
|
50
|
+
readonly session_id: string;
|
|
51
|
+
readonly timestamp?: string;
|
|
52
|
+
readonly message: EngineHistoryMessageBody;
|
|
53
|
+
readonly parent_tool_use_id: null;
|
|
54
|
+
}
|
|
55
|
+
export interface EngineHistorySkipped {
|
|
56
|
+
readonly unreadable: number;
|
|
57
|
+
readonly unknownRole: number;
|
|
58
|
+
readonly noVisibleContent: number;
|
|
59
|
+
readonly droppedBlocks: number;
|
|
60
|
+
}
|
|
61
|
+
export interface EngineHistoryProjection {
|
|
62
|
+
readonly messages: readonly EngineHistoryMessage[];
|
|
63
|
+
readonly skipped: EngineHistorySkipped;
|
|
64
|
+
}
|
|
65
|
+
export interface EngineHistoryProjectionOpts {
|
|
66
|
+
readonly sessionId: string;
|
|
67
|
+
}
|
|
68
|
+
export declare function projectEngineSessionMessages<Row>(rows: readonly Row[], opts: EngineHistoryProjectionOpts): EngineHistoryProjection;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { isGateParkedToolEnd } from './gateOutcome.js';
|
|
2
|
+
import { ownDataField, ownSendableField } from './ownKey.js';
|
|
3
|
+
const isObjectLike = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
4
|
+
function optionalOwn(o, key) {
|
|
5
|
+
try {
|
|
6
|
+
return ownDataField(o, key);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function itemsOf(a) {
|
|
13
|
+
if (!Array.isArray(a))
|
|
14
|
+
return undefined;
|
|
15
|
+
const n = ownDataField(a, 'length');
|
|
16
|
+
if (typeof n !== 'number' || !Number.isSafeInteger(n) || n < 0)
|
|
17
|
+
return undefined;
|
|
18
|
+
const out = [];
|
|
19
|
+
for (let i = 0; i < n; i += 1)
|
|
20
|
+
out.push(ownDataField(a, String(i)));
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
const JSON_MAX_DEPTH = 64;
|
|
24
|
+
const JSON_MAX_NODES = 200_000;
|
|
25
|
+
const NOT_JSON = Symbol('not-json');
|
|
26
|
+
function isPlainShape(o) {
|
|
27
|
+
const proto = Object.getPrototypeOf(o);
|
|
28
|
+
return proto === null || (typeof proto === 'object' && Object.getPrototypeOf(proto) === null);
|
|
29
|
+
}
|
|
30
|
+
function jsonSnapshot(v, depth, budget) {
|
|
31
|
+
budget.nodes += 1;
|
|
32
|
+
if (budget.nodes > JSON_MAX_NODES || depth > JSON_MAX_DEPTH)
|
|
33
|
+
return NOT_JSON;
|
|
34
|
+
if (v === null || typeof v === 'string' || typeof v === 'boolean')
|
|
35
|
+
return v;
|
|
36
|
+
if (typeof v === 'number')
|
|
37
|
+
return Number.isFinite(v) ? v : NOT_JSON;
|
|
38
|
+
if (typeof v !== 'object')
|
|
39
|
+
return NOT_JSON;
|
|
40
|
+
if (Array.isArray(v)) {
|
|
41
|
+
const n = ownDataField(v, 'length');
|
|
42
|
+
if (typeof n !== 'number' || !Number.isSafeInteger(n) || n < 0)
|
|
43
|
+
return NOT_JSON;
|
|
44
|
+
const out = [];
|
|
45
|
+
for (let i = 0; i < n; i += 1) {
|
|
46
|
+
const item = jsonSnapshot(ownSendableField(v, String(i)), depth + 1, budget);
|
|
47
|
+
if (item === NOT_JSON)
|
|
48
|
+
return NOT_JSON;
|
|
49
|
+
out.push(item);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
if (!isPlainShape(v))
|
|
54
|
+
return NOT_JSON;
|
|
55
|
+
const out = {};
|
|
56
|
+
for (const k of Reflect.ownKeys(v)) {
|
|
57
|
+
if (typeof k !== 'string')
|
|
58
|
+
continue;
|
|
59
|
+
const item = jsonSnapshot(ownSendableField(v, k), depth + 1, budget);
|
|
60
|
+
if (item === NOT_JSON)
|
|
61
|
+
return NOT_JSON;
|
|
62
|
+
Object.defineProperty(out, k, { value: item, enumerable: true, writable: true, configurable: true });
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
function jsonSnapshotOf(v) {
|
|
67
|
+
try {
|
|
68
|
+
const snap = jsonSnapshot(v, 0, { nodes: 0 });
|
|
69
|
+
return snap === NOT_JSON ? undefined : snap;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function mapBlock(b) {
|
|
76
|
+
if (!isObjectLike(b))
|
|
77
|
+
return undefined;
|
|
78
|
+
const type = ownDataField(b, 'type');
|
|
79
|
+
if (typeof type !== 'string')
|
|
80
|
+
return undefined;
|
|
81
|
+
switch (type) {
|
|
82
|
+
case 'text': {
|
|
83
|
+
const text = ownDataField(b, 'text');
|
|
84
|
+
return typeof text === 'string' ? { type: 'text', text } : undefined;
|
|
85
|
+
}
|
|
86
|
+
case 'thinking': {
|
|
87
|
+
const thinking = ownDataField(b, 'thinking');
|
|
88
|
+
if (typeof thinking !== 'string')
|
|
89
|
+
return undefined;
|
|
90
|
+
const signature = optionalOwn(b, 'thinkingSignature');
|
|
91
|
+
return typeof signature === 'string' ? { type: 'thinking', thinking, signature } : { type: 'thinking', thinking };
|
|
92
|
+
}
|
|
93
|
+
case 'toolCall': {
|
|
94
|
+
const id = ownDataField(b, 'id');
|
|
95
|
+
const name = ownDataField(b, 'name');
|
|
96
|
+
if (typeof id !== 'string' || id.length === 0 || typeof name !== 'string' || name.length === 0)
|
|
97
|
+
return undefined;
|
|
98
|
+
const args = ownDataField(b, 'arguments');
|
|
99
|
+
if (!isObjectLike(args))
|
|
100
|
+
return { type: 'tool_use', id, name, input: {} };
|
|
101
|
+
const input = jsonSnapshotOf(args);
|
|
102
|
+
if (input === undefined || input === null || typeof input !== 'object' || Array.isArray(input))
|
|
103
|
+
return undefined;
|
|
104
|
+
return { type: 'tool_use', id, name, input: input };
|
|
105
|
+
}
|
|
106
|
+
case 'image':
|
|
107
|
+
case 'document': {
|
|
108
|
+
const data = ownDataField(b, 'data');
|
|
109
|
+
const mimeType = ownDataField(b, 'mimeType');
|
|
110
|
+
if (typeof data !== 'string' || typeof mimeType !== 'string' || mimeType.length === 0)
|
|
111
|
+
return undefined;
|
|
112
|
+
return { type, source: { type: 'base64', media_type: mimeType, data } };
|
|
113
|
+
}
|
|
114
|
+
default: {
|
|
115
|
+
const opaque = jsonSnapshotOf(b);
|
|
116
|
+
return opaque !== undefined && opaque !== null && typeof opaque === 'object' && !Array.isArray(opaque) ? opaque : undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function mapBlockCounted(raw, tally) {
|
|
121
|
+
let mapped;
|
|
122
|
+
try {
|
|
123
|
+
mapped = mapBlock(raw);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
mapped = undefined;
|
|
127
|
+
}
|
|
128
|
+
if (mapped === undefined)
|
|
129
|
+
tally.droppedBlocks += 1;
|
|
130
|
+
return mapped;
|
|
131
|
+
}
|
|
132
|
+
function mapBlocks(items, tally) {
|
|
133
|
+
const out = [];
|
|
134
|
+
for (const raw of items) {
|
|
135
|
+
const mapped = mapBlockCounted(raw, tally);
|
|
136
|
+
if (mapped !== undefined)
|
|
137
|
+
out.push(mapped);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
function engineRegionsOf(row, flatLength) {
|
|
142
|
+
if (optionalOwn(row, 'engineMinted') === true)
|
|
143
|
+
return 'whole';
|
|
144
|
+
const segments = optionalOwn(row, 'engineSegments');
|
|
145
|
+
if (segments !== undefined) {
|
|
146
|
+
let items;
|
|
147
|
+
try {
|
|
148
|
+
items = itemsOf(segments);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
items = undefined;
|
|
152
|
+
}
|
|
153
|
+
if (items === undefined)
|
|
154
|
+
return 'verbatim';
|
|
155
|
+
const out = [];
|
|
156
|
+
let floor = 0;
|
|
157
|
+
for (const item of items) {
|
|
158
|
+
if (!isObjectLike(item))
|
|
159
|
+
return 'verbatim';
|
|
160
|
+
const start = optionalOwn(item, 'start');
|
|
161
|
+
const end = optionalOwn(item, 'end');
|
|
162
|
+
if (typeof start !== 'number' || typeof end !== 'number' || !Number.isInteger(start) || !Number.isInteger(end))
|
|
163
|
+
return 'verbatim';
|
|
164
|
+
if (start < floor || end <= start || end > flatLength)
|
|
165
|
+
return 'verbatim';
|
|
166
|
+
out.push([start, end]);
|
|
167
|
+
floor = end;
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
const prefix = optionalOwn(row, 'enginePrefixChars');
|
|
172
|
+
if (prefix === undefined)
|
|
173
|
+
return 'verbatim';
|
|
174
|
+
if (typeof prefix !== 'number' || !Number.isInteger(prefix) || prefix <= 0 || prefix > flatLength)
|
|
175
|
+
return 'verbatim';
|
|
176
|
+
return [[0, prefix]];
|
|
177
|
+
}
|
|
178
|
+
function cutRegions(text, offset, regions) {
|
|
179
|
+
const end = offset + text.length;
|
|
180
|
+
let out = '';
|
|
181
|
+
let cursor = offset;
|
|
182
|
+
let touched = false;
|
|
183
|
+
for (const [rs, re] of regions) {
|
|
184
|
+
if (re <= offset || rs >= end)
|
|
185
|
+
continue;
|
|
186
|
+
touched = true;
|
|
187
|
+
const cutStart = Math.max(rs, offset);
|
|
188
|
+
const cutEnd = Math.min(re, end);
|
|
189
|
+
out += text.slice(cursor - offset, cutStart - offset);
|
|
190
|
+
cursor = cutEnd;
|
|
191
|
+
}
|
|
192
|
+
if (!touched)
|
|
193
|
+
return text;
|
|
194
|
+
out += text.slice(cursor - offset);
|
|
195
|
+
const kept = out.trim();
|
|
196
|
+
return kept === '' ? undefined : kept;
|
|
197
|
+
}
|
|
198
|
+
const unreadable = () => ({ kind: 'skip', why: 'unreadable' });
|
|
199
|
+
const invisible = () => ({ kind: 'skip', why: 'noVisibleContent' });
|
|
200
|
+
function flatTextOf(item) {
|
|
201
|
+
if (!isObjectLike(item))
|
|
202
|
+
return '';
|
|
203
|
+
const type = optionalOwn(item, 'type');
|
|
204
|
+
if (type !== 'text')
|
|
205
|
+
return '';
|
|
206
|
+
const text = optionalOwn(item, 'text');
|
|
207
|
+
return text === undefined || text === null ? '' : String(text);
|
|
208
|
+
}
|
|
209
|
+
function userBody(row, tally) {
|
|
210
|
+
const content = ownDataField(row, 'content');
|
|
211
|
+
if (typeof content === 'string') {
|
|
212
|
+
if (content === '')
|
|
213
|
+
return invisible();
|
|
214
|
+
const regions = engineRegionsOf(row, content.length);
|
|
215
|
+
if (regions === 'whole')
|
|
216
|
+
return invisible();
|
|
217
|
+
if (regions === 'verbatim')
|
|
218
|
+
return { kind: 'message', role: 'user', body: { role: 'user', content } };
|
|
219
|
+
const kept = cutRegions(content, 0, regions);
|
|
220
|
+
return kept === undefined ? invisible() : { kind: 'message', role: 'user', body: { role: 'user', content: kept } };
|
|
221
|
+
}
|
|
222
|
+
const items = itemsOf(content);
|
|
223
|
+
if (items === undefined)
|
|
224
|
+
return unreadable();
|
|
225
|
+
if (items.length === 0)
|
|
226
|
+
return invisible();
|
|
227
|
+
const texts = items.map(flatTextOf);
|
|
228
|
+
const flatLength = texts.reduce((n, t) => n + t.length, 0) + (items.length - 1);
|
|
229
|
+
const regions = engineRegionsOf(row, flatLength);
|
|
230
|
+
if (regions === 'whole')
|
|
231
|
+
return invisible();
|
|
232
|
+
const out = [];
|
|
233
|
+
let offset = 0;
|
|
234
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
235
|
+
const text = texts[i];
|
|
236
|
+
const at = offset;
|
|
237
|
+
offset += text.length + 1;
|
|
238
|
+
const mapped = mapBlockCounted(items[i], tally);
|
|
239
|
+
if (mapped === undefined)
|
|
240
|
+
continue;
|
|
241
|
+
if (mapped.type === 'text' && regions !== 'verbatim') {
|
|
242
|
+
const kept = cutRegions(text, at, regions);
|
|
243
|
+
if (kept === undefined)
|
|
244
|
+
continue;
|
|
245
|
+
out.push(kept === text ? mapped : { type: 'text', text: kept });
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
out.push(mapped);
|
|
249
|
+
}
|
|
250
|
+
return out.length === 0 ? invisible() : { kind: 'message', role: 'user', body: { role: 'user', content: out } };
|
|
251
|
+
}
|
|
252
|
+
function assistantBody(row, tally) {
|
|
253
|
+
const content = ownDataField(row, 'content');
|
|
254
|
+
let blocks;
|
|
255
|
+
if (typeof content === 'string') {
|
|
256
|
+
blocks = [{ type: 'text', text: content }];
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const items = itemsOf(content);
|
|
260
|
+
if (items === undefined)
|
|
261
|
+
return unreadable();
|
|
262
|
+
blocks = mapBlocks(items, tally);
|
|
263
|
+
}
|
|
264
|
+
const model = optionalOwn(row, 'model');
|
|
265
|
+
return {
|
|
266
|
+
kind: 'message',
|
|
267
|
+
role: 'assistant',
|
|
268
|
+
body: typeof model === 'string' && model.length > 0 ? { role: 'assistant', content: blocks, model } : { role: 'assistant', content: blocks },
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function toolResultBody(row, tally) {
|
|
272
|
+
const id = ownDataField(row, 'toolCallId');
|
|
273
|
+
if (typeof id !== 'string' || id.length === 0)
|
|
274
|
+
return unreadable();
|
|
275
|
+
const content = ownDataField(row, 'content');
|
|
276
|
+
let blocks;
|
|
277
|
+
if (content === undefined) {
|
|
278
|
+
blocks = [];
|
|
279
|
+
}
|
|
280
|
+
else if (typeof content === 'string') {
|
|
281
|
+
blocks = [{ type: 'text', text: content }];
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const items = itemsOf(content);
|
|
285
|
+
if (items === undefined)
|
|
286
|
+
return unreadable();
|
|
287
|
+
blocks = mapBlocks(items, tally);
|
|
288
|
+
}
|
|
289
|
+
const isError = ownDataField(row, 'isError') === true;
|
|
290
|
+
const parked = isGateParkedToolEnd(row);
|
|
291
|
+
return {
|
|
292
|
+
kind: 'message',
|
|
293
|
+
role: 'user',
|
|
294
|
+
body: { role: 'user', content: [{ type: 'tool_result', tool_use_id: id, content: blocks, is_error: isError, ...(parked ? { _sema_gate_parked: true } : {}) }] },
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function projectRow(row, tally) {
|
|
298
|
+
if (!isObjectLike(row))
|
|
299
|
+
return unreadable();
|
|
300
|
+
const role = ownDataField(row, 'role');
|
|
301
|
+
if (role === 'user')
|
|
302
|
+
return userBody(row, tally);
|
|
303
|
+
if (role === 'assistant')
|
|
304
|
+
return assistantBody(row, tally);
|
|
305
|
+
if (role === 'toolResult')
|
|
306
|
+
return toolResultBody(row, tally);
|
|
307
|
+
return { kind: 'skip', why: 'unknownRole' };
|
|
308
|
+
}
|
|
309
|
+
function timestampOf(row) {
|
|
310
|
+
const ms = optionalOwn(row, 'timestamp');
|
|
311
|
+
if (typeof ms !== 'number' || !Number.isFinite(ms))
|
|
312
|
+
return undefined;
|
|
313
|
+
const at = new Date(ms);
|
|
314
|
+
return Number.isNaN(at.getTime()) ? undefined : at.toISOString();
|
|
315
|
+
}
|
|
316
|
+
function sessionIdOf(opts) {
|
|
317
|
+
let sessionId;
|
|
318
|
+
try {
|
|
319
|
+
sessionId = typeof opts === 'object' && opts !== null ? ownDataField(opts, 'sessionId') : undefined;
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
sessionId = undefined;
|
|
323
|
+
}
|
|
324
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
325
|
+
throw new TypeError('projectEngineSessionMessages: opts.sessionId must be a non-empty string (the engine session id)');
|
|
326
|
+
}
|
|
327
|
+
return sessionId;
|
|
328
|
+
}
|
|
329
|
+
export function projectEngineSessionMessages(rows, opts) {
|
|
330
|
+
if (!Array.isArray(rows))
|
|
331
|
+
throw new TypeError('projectEngineSessionMessages: rows must be an array');
|
|
332
|
+
const sessionId = sessionIdOf(opts);
|
|
333
|
+
let count;
|
|
334
|
+
try {
|
|
335
|
+
count = ownDataField(rows, 'length');
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
count = undefined;
|
|
339
|
+
}
|
|
340
|
+
if (typeof count !== 'number' || !Number.isSafeInteger(count) || count < 0)
|
|
341
|
+
throw new TypeError('projectEngineSessionMessages: rows length could not be read');
|
|
342
|
+
const tally = { unreadable: 0, unknownRole: 0, noVisibleContent: 0, droppedBlocks: 0 };
|
|
343
|
+
const messages = [];
|
|
344
|
+
for (let i = 0; i < count; i += 1) {
|
|
345
|
+
let outcome;
|
|
346
|
+
let timestamp;
|
|
347
|
+
try {
|
|
348
|
+
const row = ownDataField(rows, String(i));
|
|
349
|
+
outcome = projectRow(row, tally);
|
|
350
|
+
timestamp = outcome.kind === 'message' && isObjectLike(row) ? timestampOf(row) : undefined;
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
outcome = unreadable();
|
|
354
|
+
timestamp = undefined;
|
|
355
|
+
}
|
|
356
|
+
if (outcome.kind === 'skip') {
|
|
357
|
+
tally[outcome.why] += 1;
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
messages.push({
|
|
361
|
+
type: outcome.role,
|
|
362
|
+
uuid: `restored-${sessionId}-${messages.length + 1}`,
|
|
363
|
+
session_id: sessionId,
|
|
364
|
+
...(timestamp !== undefined ? { timestamp } : {}),
|
|
365
|
+
message: outcome.body,
|
|
366
|
+
parent_tool_use_id: null,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
return Object.freeze({ messages, skipped: Object.freeze({ ...tally }) });
|
|
370
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CloudLoginFailure, CloudLoginFailureReading, EipcStoreClient, EngineTargetRefusal, EngineTargetRefused, EngineTargetState, SeatLocalMcpReading } from './seatContract.js';
|
|
2
|
+
import type { McpProbeOutcome } from './mcpProbeWire.js';
|
|
3
|
+
import type { UiLanguage } from './env/uiLanguage.js';
|
|
4
|
+
export interface CloudLoginFailureContext {
|
|
5
|
+
readonly deadlineReached?: boolean;
|
|
6
|
+
readonly cancelled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function cloudLoginFailureOf(err: {} | null | undefined, ctx?: CloudLoginFailureContext): CloudLoginFailureReading;
|
|
9
|
+
export declare function cloudLoginFailureText(failure: CloudLoginFailure | CloudLoginFailureReading, lang?: UiLanguage): string;
|
|
10
|
+
export declare function engineTargetRefusalText(refused: EngineTargetRefusal | EngineTargetRefused, lang?: UiLanguage): string;
|
|
11
|
+
export type EngineTargetReading = {
|
|
12
|
+
readonly kind: 'state';
|
|
13
|
+
readonly state: EngineTargetState;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'not_reported';
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'malformed';
|
|
18
|
+
};
|
|
19
|
+
export interface EngineTargetWatch {
|
|
20
|
+
stop(): void;
|
|
21
|
+
isCurrent(generation: number): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function watchEngineTarget(store: EipcStoreClient<EngineTargetState> | undefined, onState: (reading: EngineTargetReading, switched: boolean) => void): EngineTargetWatch;
|
|
24
|
+
export declare function seatMcpReadingOf(outcome: McpProbeOutcome, readAt: string, extra?: {
|
|
25
|
+
readonly restartRequired?: true;
|
|
26
|
+
readonly forcedAsk?: Readonly<Record<string, readonly string[]>>;
|
|
27
|
+
}): SeatLocalMcpReading;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { CLOUD_LOGIN_FAILURES, ENGINE_TARGET_REFUSALS, LOCAL_SESSIONS_SPEC } from './seatContract.js';
|
|
2
|
+
import { ownDataField } from './ownKey.js';
|
|
3
|
+
import { readThrownSlot, readThrownStatusSlot } from './wireFailureShape.js';
|
|
4
|
+
import { displayUntrusted } from './displayUntrusted.js';
|
|
5
|
+
import { msg, renderMessage } from './i18n/translate.js';
|
|
6
|
+
const field = (v, key) => {
|
|
7
|
+
if (v === null || typeof v !== 'object')
|
|
8
|
+
return undefined;
|
|
9
|
+
try {
|
|
10
|
+
return ownDataField(v, key);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const OAUTH_WORDS = ['access_denied', 'expired_token', 'invalid_grant'];
|
|
17
|
+
export function cloudLoginFailureOf(err, ctx) {
|
|
18
|
+
if (field(ctx, 'cancelled') === true)
|
|
19
|
+
return Object.freeze({ failure: 'cancelled' });
|
|
20
|
+
if (field(ctx, 'deadlineReached') === true)
|
|
21
|
+
return Object.freeze({ failure: 'expired_token' });
|
|
22
|
+
if (err !== null && typeof err === 'object') {
|
|
23
|
+
const code = readThrownSlot(err, 'code', 'data');
|
|
24
|
+
if (typeof code === 'string' && code.length > 0) {
|
|
25
|
+
const word = OAUTH_WORDS.find((w) => w === code);
|
|
26
|
+
return Object.freeze({ failure: word ?? 'other' });
|
|
27
|
+
}
|
|
28
|
+
const status = readThrownStatusSlot(err);
|
|
29
|
+
if (typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599)
|
|
30
|
+
return Object.freeze({ failure: 'refused', status });
|
|
31
|
+
}
|
|
32
|
+
return Object.freeze({ failure: 'transport' });
|
|
33
|
+
}
|
|
34
|
+
const LOGIN_KEYS = {
|
|
35
|
+
access_denied: 'config.cloudLogin.accessDenied',
|
|
36
|
+
expired_token: 'config.cloudLogin.expiredToken',
|
|
37
|
+
invalid_grant: 'config.cloudLogin.invalidGrant',
|
|
38
|
+
cancelled: 'config.cloudLogin.cancelled',
|
|
39
|
+
transport: 'config.cloudLogin.transport',
|
|
40
|
+
refused: 'config.cloudLogin.refused',
|
|
41
|
+
no_tokens: 'config.cloudLogin.noTokens',
|
|
42
|
+
other: 'config.cloudLogin.other',
|
|
43
|
+
};
|
|
44
|
+
export function cloudLoginFailureText(failure, lang) {
|
|
45
|
+
const word = typeof failure === 'string' ? failure : field(failure, 'failure');
|
|
46
|
+
const known = CLOUD_LOGIN_FAILURES.find((w) => w === word) ?? 'other';
|
|
47
|
+
if (known === 'refused') {
|
|
48
|
+
const status = typeof failure === 'string' ? undefined : field(failure, 'status');
|
|
49
|
+
if (typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599) {
|
|
50
|
+
return renderMessage(msg('config.cloudLogin.refusedStatus', { status }), lang);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return renderMessage(msg(LOGIN_KEYS[known]), lang);
|
|
54
|
+
}
|
|
55
|
+
const REFUSAL_KEYS = {
|
|
56
|
+
busy: 'config.engineTarget.busy',
|
|
57
|
+
switching: 'config.engineTarget.switching',
|
|
58
|
+
not_configured: 'config.engineTarget.notConfigured',
|
|
59
|
+
not_signed_in: 'config.engineTarget.notSignedIn',
|
|
60
|
+
probe_failed: 'config.engineTarget.probeFailed',
|
|
61
|
+
org_policy: 'config.engineTarget.orgPolicy',
|
|
62
|
+
url_refused: 'config.engineTarget.urlRefused',
|
|
63
|
+
login_failed: 'config.engineTarget.loginFailed',
|
|
64
|
+
storage_unavailable: 'config.engineTarget.storageUnavailable',
|
|
65
|
+
no_local_runtime: 'config.engineTarget.noLocalRuntime',
|
|
66
|
+
input: 'config.engineTarget.input',
|
|
67
|
+
};
|
|
68
|
+
export function engineTargetRefusalText(refused, lang) {
|
|
69
|
+
const word = typeof refused === 'string' ? refused : field(refused, 'refusal');
|
|
70
|
+
const known = ENGINE_TARGET_REFUSALS.find((w) => w === word);
|
|
71
|
+
if (known === undefined)
|
|
72
|
+
return renderMessage(msg('config.engineTarget.unknown'), lang);
|
|
73
|
+
if (known === 'login_failed' && typeof refused !== 'string') {
|
|
74
|
+
const failure = field(refused, 'failure');
|
|
75
|
+
if (CLOUD_LOGIN_FAILURES.some((w) => w === failure)) {
|
|
76
|
+
const status = field(refused, 'status');
|
|
77
|
+
return cloudLoginFailureText({ failure: failure, ...(typeof status === 'number' ? { status } : {}) }, lang);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return renderMessage(msg(REFUSAL_KEYS[known]), lang);
|
|
81
|
+
}
|
|
82
|
+
const checkState = (v) => {
|
|
83
|
+
const check = LOCAL_SESSIONS_SPEC.stores?.['engineTargetState']?.check;
|
|
84
|
+
return typeof check === 'function' && check(v) === true;
|
|
85
|
+
};
|
|
86
|
+
export function watchEngineTarget(store, onState) {
|
|
87
|
+
let current;
|
|
88
|
+
let trusted = false;
|
|
89
|
+
let active = true;
|
|
90
|
+
let off;
|
|
91
|
+
const deliver = (state) => {
|
|
92
|
+
if (!active)
|
|
93
|
+
return;
|
|
94
|
+
let ok = false;
|
|
95
|
+
try {
|
|
96
|
+
ok = checkState(state);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
ok = false;
|
|
100
|
+
}
|
|
101
|
+
if (!ok) {
|
|
102
|
+
trusted = false;
|
|
103
|
+
onState(Object.freeze({ kind: 'malformed' }), false);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const s = state;
|
|
107
|
+
const switched = current !== undefined && s.generation !== current;
|
|
108
|
+
current = s.generation;
|
|
109
|
+
trusted = true;
|
|
110
|
+
onState(Object.freeze({ kind: 'state', state: s }), switched);
|
|
111
|
+
};
|
|
112
|
+
const handle = {
|
|
113
|
+
stop: () => {
|
|
114
|
+
if (!active)
|
|
115
|
+
return;
|
|
116
|
+
active = false;
|
|
117
|
+
try {
|
|
118
|
+
if (typeof off === 'function')
|
|
119
|
+
off();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
off = undefined;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
isCurrent: (generation) => active && trusted && current !== undefined && generation === current,
|
|
126
|
+
};
|
|
127
|
+
if (store === undefined || store === null) {
|
|
128
|
+
onState(Object.freeze({ kind: 'not_reported' }), false);
|
|
129
|
+
active = false;
|
|
130
|
+
return handle;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
if (typeof store !== 'object' || typeof store.onStateChange !== 'function' || typeof store.getStateSync !== 'function') {
|
|
134
|
+
onState(Object.freeze({ kind: 'malformed' }), false);
|
|
135
|
+
active = false;
|
|
136
|
+
return handle;
|
|
137
|
+
}
|
|
138
|
+
off = store.onStateChange((state) => deliver(state));
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
onState(Object.freeze({ kind: 'malformed' }), false);
|
|
142
|
+
active = false;
|
|
143
|
+
return handle;
|
|
144
|
+
}
|
|
145
|
+
let now;
|
|
146
|
+
try {
|
|
147
|
+
now = store.getStateSync();
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
trusted = false;
|
|
151
|
+
if (active)
|
|
152
|
+
onState(Object.freeze({ kind: 'malformed' }), false);
|
|
153
|
+
return handle;
|
|
154
|
+
}
|
|
155
|
+
deliver(now);
|
|
156
|
+
return handle;
|
|
157
|
+
}
|
|
158
|
+
const MCP_DETAIL_MAX = 200;
|
|
159
|
+
export function seatMcpReadingOf(outcome, readAt, extra) {
|
|
160
|
+
const restart = field(extra, 'restartRequired') === true ? { restartRequired: true } : {};
|
|
161
|
+
const status = field(outcome, 'status');
|
|
162
|
+
if (status === 'face') {
|
|
163
|
+
const face = field(outcome, 'face');
|
|
164
|
+
const servers = field(face, 'servers');
|
|
165
|
+
if (Array.isArray(servers)) {
|
|
166
|
+
const forced = field(extra, 'forcedAsk');
|
|
167
|
+
const rows = [];
|
|
168
|
+
for (const row of servers) {
|
|
169
|
+
const name = field(row, 'name');
|
|
170
|
+
const st = field(row, 'status');
|
|
171
|
+
if (typeof name !== 'string' || name.length === 0 || typeof st !== 'string')
|
|
172
|
+
continue;
|
|
173
|
+
const tc = field(row, 'toolCount');
|
|
174
|
+
const liveness = field(field(row, 'liveness'), 'state');
|
|
175
|
+
const ec = field(row, 'errorCode');
|
|
176
|
+
const fa = field(forced, name);
|
|
177
|
+
const forcedAsk = Array.isArray(fa) ? fa.filter((n) => typeof n === 'string' && n.length > 0) : [];
|
|
178
|
+
rows.push(Object.freeze({
|
|
179
|
+
name,
|
|
180
|
+
status: st,
|
|
181
|
+
...(typeof tc === 'number' && Number.isSafeInteger(tc) && tc >= 0 ? { toolCount: tc } : {}),
|
|
182
|
+
...(typeof liveness === 'string' && liveness.length > 0 ? { liveness } : {}),
|
|
183
|
+
...(typeof ec === 'string' && ec.length > 0 ? { errorCode: ec } : {}),
|
|
184
|
+
...(forcedAsk.length > 0 ? { forcedAsk: [...forcedAsk] } : {}),
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
return Object.freeze({ status: 'listed', servers: rows, readAt, ...restart });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const cause = status === 'refused' ? field(outcome, 'cause') : status === 'unknown' ? field(outcome, 'why') : undefined;
|
|
191
|
+
const message = field(outcome, 'message');
|
|
192
|
+
return Object.freeze({
|
|
193
|
+
status: 'unreadable',
|
|
194
|
+
cause: typeof cause === 'string' && cause.length > 0 ? cause : 'no_verdict',
|
|
195
|
+
...(typeof message === 'string' && message.length > 0 ? { detail: displayUntrusted(message, { max: MCP_DETAIL_MAX }) } : {}),
|
|
196
|
+
readAt,
|
|
197
|
+
...restart,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -15,13 +15,4 @@ export type EngineToolDirectory = {
|
|
|
15
15
|
readonly mcpServerPrefixes: ReadonlySet<string>;
|
|
16
16
|
};
|
|
17
17
|
export declare function engineToolDirectoryOf(source: EngineToolDirectorySource | null | undefined): EngineToolDirectory;
|
|
18
|
-
export type McpEntryReading = 'outside' | 'unchecked' | 'unparsable' | 'answers' | 'unanswered';
|
|
19
|
-
export declare function mcpEntryReadingOf(toolName: string, directory: EngineToolDirectory | undefined): McpEntryReading;
|
|
20
18
|
export declare function deniedEntryToolName(entry: string): string | undefined;
|
|
21
|
-
export interface ExcludeToolsAgainstDirectory {
|
|
22
|
-
readonly send: string[];
|
|
23
|
-
readonly omitted: string[];
|
|
24
|
-
readonly verdict: 'directory_absent' | 'filtered';
|
|
25
|
-
readonly disclosure?: string;
|
|
26
|
-
}
|
|
27
|
-
export declare function excludeToolsAgainstDirectory(exclude: readonly string[], directory: EngineToolDirectory | undefined): ExcludeToolsAgainstDirectory;
|