@sema-agent/client-core 0.100.0 → 0.101.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 +395 -0
- package/README.md +164 -117
- package/dist/adapt/arms.js +51 -16
- package/dist/adapt/textStream.js +7 -4
- package/dist/adapt/toolCards.js +9 -8
- package/dist/adapt.js +7 -1
- package/dist/adapter/activeRunSelfHeal.d.ts +24 -2
- package/dist/adapter/activeRunSelfHeal.js +108 -6
- package/dist/adapter/downstream/eventToSdkMessage.js +33 -12
- package/dist/adapter/downstream/terminalToSdkResult.d.ts +60 -1
- package/dist/adapter/downstream/terminalToSdkResult.js +209 -39
- package/dist/adapter/runStream.d.ts +4 -4
- package/dist/adapter/runStream.js +158 -43
- package/dist/agentsWireCaps.d.ts +2 -7
- package/dist/agentsWireCaps.js +1 -2
- package/dist/approvalDecidedByCapability.js +2 -2
- package/dist/approvalFrameFamilies.d.ts +33 -0
- package/dist/approvalFrameFamilies.js +120 -0
- package/dist/approvalsStreamLiveCapability.js +2 -2
- package/dist/attachmentsWireCaps.js +41 -13
- package/dist/callerCwdCapability.js +2 -2
- package/dist/centerWiringCapability.js +2 -2
- package/dist/clockReading.d.ts +2 -0
- package/dist/clockReading.js +4 -0
- package/dist/cloudConfigWireCaps.d.ts +19 -5
- package/dist/cloudConfigWireCaps.js +193 -56
- package/dist/coreValuePorts.d.ts +12 -2
- package/dist/coreValuePorts.js +9 -0
- package/dist/decideFailureNote.js +5 -3
- package/dist/decideReceipt.js +2 -2
- package/dist/deviceExecutorManagementCapability.js +2 -2
- package/dist/deviceFlowPolling.js +1 -1
- package/dist/disableSkillsWire.d.ts +1 -1
- package/dist/disableSkillsWire.js +4 -3
- package/dist/displayUntrusted.d.ts +1 -0
- package/dist/displayUntrusted.js +65 -8
- package/dist/engineCapReader.js +1 -1
- package/dist/engineConfigDrift.js +1 -1
- package/dist/engineErrorCodes.d.ts +14 -5
- package/dist/engineErrorCodes.js +27 -6
- package/dist/engineGenerationConvergence.d.ts +39 -0
- package/dist/engineGenerationConvergence.js +95 -0
- package/dist/engineGenerationPort.d.ts +61 -0
- package/dist/engineGenerationPort.js +144 -0
- package/dist/engineHealthFacts.d.ts +23 -0
- package/dist/engineHealthFacts.js +92 -0
- package/dist/engineIdentity.d.ts +4 -0
- package/dist/engineIdentity.js +11 -0
- package/dist/engineNoticeCodes.d.ts +2 -5
- package/dist/engineRowRef.js +3 -0
- package/dist/engineSessionMessages.js +2 -2
- package/dist/engineToolDirectory.js +2 -2
- package/dist/engineWireFor.d.ts +99 -0
- package/dist/engineWireFor.js +248 -6
- package/dist/engineWireTarget.d.ts +1 -0
- package/dist/engineWireTarget.js +8 -0
- package/dist/env/uiLanguage.js +1 -1
- package/dist/errorSupplementRoles.d.ts +3 -0
- package/dist/errorSupplementRoles.js +37 -0
- package/dist/executionLaneCapability.js +2 -2
- package/dist/fileHistoryCaptureCapability.js +3 -3
- package/dist/finalVerifyWire.d.ts +6 -3
- package/dist/finalVerifyWire.js +6 -23
- package/dist/flagInput.d.ts +4 -0
- package/dist/flagInput.js +24 -0
- package/dist/fleet/fleetLedger.js +5 -2
- package/dist/fleet/fleetProjection.d.ts +1 -0
- package/dist/fleet/fleetProjection.js +15 -2
- package/dist/gateVocabulary.js +3 -0
- package/dist/generated/engineFactTables.d.ts +7 -3
- package/dist/generated/engineFactTables.js +52 -0
- package/dist/generated/engineNoticeTables.js +12 -0
- package/dist/generated/settingsSchemaActiveTiers.d.ts +1 -0
- package/dist/generated/settingsSchemaActiveTiers.js +14 -0
- package/dist/generated/settingsSchemaCallerTextEcho.d.ts +1 -0
- package/dist/generated/settingsSchemaCallerTextEcho.js +8 -0
- package/dist/generated/settingsSchemaControlAndBidi.d.ts +1 -0
- package/dist/generated/settingsSchemaControlAndBidi.js +8 -0
- package/dist/generated/settingsSchemaDefaultModel.d.ts +11 -0
- package/dist/generated/settingsSchemaDefaultModel.js +25 -0
- package/dist/generated/settingsSchemaFns.d.ts +54 -0
- package/dist/generated/settingsSchemaFns.js +26 -1
- package/dist/generated/settingsSchemaMcpRequestEntry.d.ts +1 -1
- package/dist/generated/settingsSchemaMcpRequestEntry.js +1 -7
- package/dist/generated/settingsSchemaSafetyMergeSpec.d.ts +1 -0
- package/dist/generated/settingsSchemaSafetyMergeSpec.js +95 -0
- package/dist/generated/settingsSchemaSettingsSources.d.ts +1 -0
- package/dist/generated/settingsSchemaSettingsSources.js +58 -0
- package/dist/generated/settingsSchemaTables.d.ts +2 -0
- package/dist/generated/settingsSchemaTables.js +13 -0
- package/dist/generated/settingsSchemaUrlPattern.d.ts +1 -0
- package/dist/generated/settingsSchemaUrlPattern.js +183 -0
- package/dist/headlessPermissionModeWire.d.ts +18 -2
- package/dist/headlessPermissionModeWire.js +30 -19
- package/dist/hitl/allowRuleShadow.js +7 -5
- package/dist/hitl/approvalCardReading.d.ts +3 -0
- package/dist/hitl/approvalCardReading.js +17 -0
- package/dist/hitl/approvalCompleteParked.js +1 -1
- package/dist/hitl/approvalDelivery.d.ts +87 -0
- package/dist/hitl/approvalDelivery.js +193 -0
- package/dist/hitl/approvalResolution.d.ts +11 -0
- package/dist/hitl/approvalResolution.js +50 -11
- package/dist/hitl/askClassPair.d.ts +6 -0
- package/dist/hitl/askClassPair.js +30 -3
- package/dist/hitl/askParkAutoReopenBlock.d.ts +30 -0
- package/dist/hitl/askParkAutoReopenBlock.js +117 -0
- package/dist/hitl/askParkRowRouting.js +4 -1
- package/dist/hitl/attributionLadder.d.ts +42 -3
- package/dist/hitl/attributionLadder.js +79 -8
- package/dist/hitl/automaticAnswerVerdict.d.ts +6 -1
- package/dist/hitl/automaticAnswerVerdict.js +46 -11
- package/dist/hitl/crashConverged.js +2 -2
- package/dist/hitl/decisionConflict.d.ts +6 -2
- package/dist/hitl/decisionConflict.js +24 -9
- package/dist/hitl/decisionRefusal.d.ts +20 -10
- package/dist/hitl/decisionRefusal.js +99 -54
- package/dist/hitl/decisionSend.d.ts +3 -0
- package/dist/hitl/decisionSend.js +87 -103
- package/dist/hitl/frameRouter.d.ts +1 -0
- package/dist/hitl/frameRouter.js +9 -2
- package/dist/hitl/hitlBridge.d.ts +18 -6
- package/dist/hitl/hitlBridge.js +41 -37
- package/dist/hitl/livePendingAsk.js +4 -3
- package/dist/hitl/noAllowCause.js +1 -1
- package/dist/hitl/parkResolver.js +3 -2
- package/dist/hitl/persistedRulesWire.js +1 -0
- package/dist/hitl/planReviewWire.d.ts +4 -0
- package/dist/hitl/planReviewWire.js +59 -30
- package/dist/hitl/resumeRunningCard.d.ts +3 -2
- package/dist/hitl/resumeRunningCard.js +17 -11
- package/dist/hitl/sessionPolicyDeliverable.d.ts +5 -2
- package/dist/hitl/sessionPolicyDeliverable.js +62 -29
- package/dist/hitl/sessionPolicyWire.d.ts +13 -3
- package/dist/hitl/sessionPolicyWire.js +81 -16
- package/dist/hitl/standingRows.js +1 -1
- package/dist/hitl/toolApprovalWire.d.ts +9 -10
- package/dist/hitl/toolApprovalWire.js +72 -54
- package/dist/hookMatcherVerdict.d.ts +2 -0
- package/dist/hookMatcherVerdict.js +12 -0
- package/dist/hooksCompactTransition.d.ts +19 -0
- package/dist/hooksCompactTransition.js +41 -0
- package/dist/hooksWireCaps.d.ts +1 -1
- package/dist/hooksWireCaps.js +202 -203
- package/dist/host.d.ts +1 -14
- package/dist/host.js +0 -8
- package/dist/hostCallbackGuard.d.ts +1 -0
- package/dist/hostCallbackGuard.js +1 -1
- package/dist/hostSettingsSource.d.ts +172 -0
- package/dist/hostSettingsSource.js +675 -0
- package/dist/hostTurnSettings.d.ts +73 -17
- package/dist/hostTurnSettings.js +594 -97
- package/dist/httpHookPolicy.d.ts +37 -0
- package/dist/httpHookPolicy.js +176 -0
- package/dist/humanTurn.d.ts +2 -1
- package/dist/humanTurn.js +37 -7
- package/dist/humanTurnRead.js +4 -3
- package/dist/humanTurnSentences.d.ts +10 -0
- package/dist/humanTurnSentences.js +74 -0
- package/dist/i18n/messages.en.d.ts +184 -2
- package/dist/i18n/messages.en.js +187 -5
- package/dist/i18n/messages.zh.js +197 -5
- package/dist/i18n/translate.js +3 -3
- package/dist/index.d.ts +69 -15
- package/dist/index.js +45 -13
- package/dist/inheritEnvCapability.d.ts +3 -1
- package/dist/inheritEnvCapability.js +31 -17
- package/dist/inheritEnvWire.d.ts +2 -1
- package/dist/inheritEnvWire.js +11 -5
- package/dist/interactiveToolsWire.d.ts +4 -2
- package/dist/interactiveToolsWire.js +5 -5
- package/dist/jsonFaithful.d.ts +20 -0
- package/dist/jsonFaithful.js +152 -0
- package/dist/limitsWire.d.ts +7 -2
- package/dist/limitsWire.js +19 -13
- package/dist/liveInitToolFace.d.ts +6 -1
- package/dist/liveInitToolFace.js +5 -3
- package/dist/liveModelCatalog.d.ts +22 -0
- package/dist/liveModelCatalog.js +132 -18
- package/dist/mcpPanel.js +1 -1
- package/dist/mcpProbeCapability.js +2 -2
- package/dist/mcpStatusSupersetKeys.d.ts +24 -0
- package/dist/mcpStatusSupersetKeys.js +45 -0
- package/dist/mcpToolToggles.js +2 -1
- package/dist/mcpWireCaps.d.ts +39 -1
- package/dist/mcpWireCaps.js +254 -50
- package/dist/memoryComplianceCapability.js +2 -2
- package/dist/memoryOriginCapability.js +2 -2
- package/dist/model/catalogDefault.d.ts +24 -0
- package/dist/model/catalogDefault.js +4 -0
- package/dist/model/liveCatalogShape.js +5 -4
- package/dist/model/modelsPolicy.js +4 -3
- package/dist/model/onboardJudgement.d.ts +1 -0
- package/dist/model/onboardJudgement.js +1 -1
- package/dist/model/subagentModelWord.js +2 -2
- package/dist/modelCapabilityProbe.js +6 -6
- package/dist/modelIdentityResolvability.d.ts +10 -1
- package/dist/modelIdentityResolvability.js +62 -39
- package/dist/modsKernelIdentity.d.ts +10 -0
- package/dist/modsKernelIdentity.js +103 -0
- package/dist/modsKernelTransit.d.ts +8 -0
- package/dist/modsKernelTransit.js +6 -0
- package/dist/notifications.d.ts +30 -12
- package/dist/notifications.js +241 -53
- package/dist/outputStyleSeatCapability.js +2 -2
- package/dist/ownKey.d.ts +11 -0
- package/dist/ownKey.js +164 -3
- package/dist/panelReduce.js +1 -1
- package/dist/peerFrames.d.ts +1 -1
- package/dist/peerFrames.js +6 -2
- package/dist/peerLaneCapability.js +2 -2
- package/dist/permissionModesCapability.js +4 -4
- package/dist/permissionRuleIssue.js +2 -0
- package/dist/permissionRulesWriteCapability.js +2 -2
- package/dist/permissionsAllowGrantCapability.js +2 -2
- package/dist/permissionsDeclaration.d.ts +43 -4
- package/dist/permissionsDeclaration.js +102 -35
- package/dist/pluginHooksWire.d.ts +20 -4
- package/dist/pluginHooksWire.js +92 -53
- package/dist/prepareRefusal.d.ts +3 -2
- package/dist/prepareRefusal.js +27 -9
- package/dist/printInitToolFace.js +2 -2
- package/dist/printModelStatus.js +1 -1
- package/dist/projectMemory.d.ts +32 -0
- package/dist/projectMemory.js +70 -0
- package/dist/promptBlockedCopy.d.ts +2 -1
- package/dist/promptBlockedCopy.js +2 -1
- package/dist/promptDelivery.d.ts +23 -3
- package/dist/promptDelivery.js +169 -30
- package/dist/providerRejection.d.ts +19 -1
- package/dist/providerRejection.js +75 -4
- package/dist/queuedDelivery.d.ts +48 -0
- package/dist/queuedDelivery.js +233 -0
- package/dist/reattachWindow.d.ts +94 -0
- package/dist/reattachWindow.js +127 -0
- package/dist/request/printNotification.d.ts +1 -1
- package/dist/request/printNotification.js +5 -1
- package/dist/request/submissionIdentity.d.ts +37 -0
- package/dist/request/submissionIdentity.js +65 -0
- package/dist/request/taskRequest.d.ts +12 -4
- package/dist/request/taskRequest.js +221 -152
- package/dist/resultFrameKeys.d.ts +1 -0
- package/dist/resultFrameKeys.js +4 -1
- package/dist/retryStatus.d.ts +8 -0
- package/dist/retryStatus.js +57 -9
- package/dist/rewindArchiveCapability.js +2 -2
- package/dist/rewindEngineAction.d.ts +2 -0
- package/dist/rewindEngineAction.js +23 -1
- package/dist/rowKind.d.ts +36 -0
- package/dist/rowKind.js +97 -0
- package/dist/ruleCompileVerdict.d.ts +18 -0
- package/dist/ruleCompileVerdict.js +67 -2
- package/dist/ruleReadings.d.ts +58 -0
- package/dist/ruleReadings.js +132 -0
- package/dist/ruleRefusalSentence.d.ts +4 -0
- package/dist/ruleRefusalSentence.js +9 -3
- package/dist/runCancelContext.d.ts +0 -1
- package/dist/runCancelContext.js +1 -2
- package/dist/runTerminal.d.ts +5 -0
- package/dist/runTerminal.js +52 -17
- package/dist/sandboxWire.d.ts +1 -1
- package/dist/sandboxWire.js +4 -6
- package/dist/scenarioRefusal.js +1 -1
- package/dist/scenarioSkills.d.ts +20 -0
- package/dist/scenarioSkills.js +72 -0
- package/dist/scenarioWire.d.ts +5 -2
- package/dist/scenarioWire.js +9 -9
- package/dist/sealedKeyCapability.js +2 -2
- package/dist/seam.d.ts +2 -0
- package/dist/seam.js +2 -2
- package/dist/seatContract.d.ts +46 -1
- package/dist/seatContract.js +49 -19
- package/dist/selfOrchestrationDenial.js +1 -1
- package/dist/sessionPolicyCapability.js +2 -2
- package/dist/sessionRulesChildrenReadLive.d.ts +6 -0
- package/dist/sessionRulesChildrenReadLive.js +5 -0
- package/dist/sessionRulesNamespaceFormsCapability.d.ts +12 -0
- package/dist/sessionRulesNamespaceFormsCapability.js +29 -0
- package/dist/sessionSyncFileHistoryCapability.js +2 -2
- package/dist/settingsCredentialKeyPaths.js +60 -5
- package/dist/settingsHooksSalvage.d.ts +1 -0
- package/dist/settingsHooksSalvage.js +7 -1
- package/dist/settingsLayerAdmission.d.ts +4 -0
- package/dist/settingsLayerAdmission.js +16 -0
- package/dist/skillToolListsCapability.js +6 -5
- package/dist/skillsWireCaps.d.ts +14 -0
- package/dist/skillsWireCaps.js +47 -16
- package/dist/slashCommandGate.d.ts +24 -0
- package/dist/slashCommandGate.js +74 -0
- package/dist/slashCommandTable.d.ts +14 -0
- package/dist/slashCommandTable.js +99 -0
- package/dist/sqlEngineCapability.js +2 -2
- package/dist/steerPriorityCapability.js +2 -2
- package/dist/storePostureCapability.js +2 -2
- package/dist/subagent/agentStateDetail.js +1 -1
- package/dist/subagent/engineDelegatedPrompt.d.ts +9 -0
- package/dist/subagent/engineDelegatedPrompt.js +38 -7
- package/dist/subagent/engineRowStopGate.js +2 -2
- package/dist/subagent/engineSubagentResume.js +3 -3
- package/dist/subagent/engineTaskHandleWire.d.ts +1 -0
- package/dist/subagent/engineTaskHandleWire.js +10 -0
- package/dist/submitFailure.d.ts +8 -0
- package/dist/submitFailure.js +17 -0
- package/dist/supportFloor.d.ts +1 -0
- package/dist/supportFloor.js +7 -0
- package/dist/terminationIntent.d.ts +55 -0
- package/dist/terminationIntent.js +352 -0
- package/dist/toolHistoryMismatch.d.ts +8 -0
- package/dist/toolHistoryMismatch.js +37 -6
- package/dist/toolResult.d.ts +13 -3
- package/dist/toolResult.js +158 -9
- package/dist/toolResultContent.d.ts +13 -0
- package/dist/toolResultContent.js +82 -7
- package/dist/toolRoster.d.ts +18 -0
- package/dist/toolRoster.js +64 -0
- package/dist/turnFailurePresentation.js +27 -90
- package/dist/usageLimitAutoResume.d.ts +74 -0
- package/dist/usageLimitAutoResume.js +227 -0
- package/dist/userAttachmentEnvelope.js +1 -1
- package/dist/userAttachmentSeat.js +5 -5
- package/dist/userInvokedSkillsCapability.js +2 -2
- package/dist/webSearchBackendCapability.js +2 -2
- package/dist/wireErrorTriage.js +99 -50
- package/dist/wireFailureShape.d.ts +25 -1
- package/dist/wireFailureShape.js +92 -5
- package/dist/wireRefusalCopy.d.ts +24 -1
- package/dist/wireRefusalCopy.js +253 -32
- package/dist/wiringFleetDoctor.d.ts +3 -0
- package/dist/wiringFleetDoctor.js +21 -0
- package/dist/workflow.d.ts +2 -1
- package/dist/workflow.js +38 -1
- package/dist/workflowClient.d.ts +2 -7
- package/dist/workflowsJournalCapability.js +2 -2
- package/dist/writeProtectionCapability.js +2 -2
- package/docs/INTEGRATION-CLIENTS.md +607 -181
- package/package.json +14 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { engineCapValue } from './engineCapsCache.js';
|
|
2
|
+
import { engineWireTargetBaseUrl } from './engineWireTarget.js';
|
|
3
|
+
import { msg, renderMessage } from './i18n/translate.js';
|
|
4
|
+
import { guardedRead, readOwnDataValue } from './ownKey.js';
|
|
5
|
+
export const PROJECT_MEMORY_DISABLED = 'disabled';
|
|
6
|
+
export const PROJECT_MEMORY_WORDS = Object.freeze(['on', PROJECT_MEMORY_DISABLED, 'absent']);
|
|
7
|
+
export function projectMemoryOf(manifest) {
|
|
8
|
+
const raw = guardedRead(() => readOwnDataValue(manifest, 'projectMemory'));
|
|
9
|
+
return typeof raw === 'string' ? PROJECT_MEMORY_WORDS.find((w) => w === raw) : undefined;
|
|
10
|
+
}
|
|
11
|
+
const PROJECT_MEMORY_CAPABILITY_KEY = 'projectMemory';
|
|
12
|
+
const CAP_CONFIRMED = Object.freeze({ kind: 'confirmed' });
|
|
13
|
+
const CAP_ABSENT = Object.freeze({ kind: 'absent' });
|
|
14
|
+
const CAP_DECLINED = Object.freeze({ kind: 'declined' });
|
|
15
|
+
const CAP_UNREADABLE = Object.freeze({ kind: 'unreadable' });
|
|
16
|
+
const CAP_UNOBSERVED = Object.freeze({ kind: 'unobserved' });
|
|
17
|
+
export function observedProjectMemoryCapability(baseUrl) {
|
|
18
|
+
try {
|
|
19
|
+
const picked = baseUrl === undefined ? engineWireTargetBaseUrl() : baseUrl;
|
|
20
|
+
const slot = engineCapValue(typeof picked === 'string' ? picked : undefined, PROJECT_MEMORY_CAPABILITY_KEY);
|
|
21
|
+
switch (slot.kind) {
|
|
22
|
+
case 'unobserved':
|
|
23
|
+
return CAP_UNOBSERVED;
|
|
24
|
+
case 'not_reported':
|
|
25
|
+
return CAP_ABSENT;
|
|
26
|
+
case 'unreadable':
|
|
27
|
+
return CAP_UNREADABLE;
|
|
28
|
+
case 'null':
|
|
29
|
+
return CAP_DECLINED;
|
|
30
|
+
case 'value':
|
|
31
|
+
return slot.value === true ? CAP_CONFIRMED : CAP_DECLINED;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return CAP_UNOBSERVED;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const EMPTY_DECLARATION = Object.freeze({ field: Object.freeze({}) });
|
|
39
|
+
function readingClassOf(reading) {
|
|
40
|
+
const kind = guardedRead(() => (typeof reading === 'object' && reading !== null ? readOwnDataValue(reading, 'kind') : undefined));
|
|
41
|
+
return kind === 'confirmed' || kind === 'absent' || kind === 'declined' ? kind : 'unreadable';
|
|
42
|
+
}
|
|
43
|
+
export function projectMemoryDeclaration(intent, reading) {
|
|
44
|
+
if (intent === undefined || intent === null)
|
|
45
|
+
return EMPTY_DECLARATION;
|
|
46
|
+
if (intent !== PROJECT_MEMORY_DISABLED) {
|
|
47
|
+
throw new TypeError(`projectMemoryDeclaration: projectMemory 只接受字面量 '${PROJECT_MEMORY_DISABLED}' 或缺席 —— 收到 ${Array.isArray(intent) ? 'typeof=object / array' : `typeof=${typeof intent}`}。坏词在读数判定之前就拒:「这一次不发」不许顺手吞掉一个打错字的声明。错误文本只报形状,不回显值。`);
|
|
48
|
+
}
|
|
49
|
+
const cls = readingClassOf(reading);
|
|
50
|
+
if (cls === 'confirmed')
|
|
51
|
+
return Object.freeze({ field: Object.freeze({ projectMemory: PROJECT_MEMORY_DISABLED }) });
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
field: Object.freeze({}),
|
|
54
|
+
withheld: Object.freeze({ cause: (cls === 'absent' ? 'capability_absent' : cls === 'declined' ? 'capability_declined' : 'capability_unreadable') }),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const WITHHELD_KEYS = Object.freeze({
|
|
58
|
+
capability_absent: 'session.projectMemory.withheld.absent',
|
|
59
|
+
capability_declined: 'session.projectMemory.withheld.declined',
|
|
60
|
+
capability_unreadable: 'session.projectMemory.withheld.unreadable',
|
|
61
|
+
});
|
|
62
|
+
const WITHHELD_UNKNOWN_KEY = 'session.projectMemory.withheld.unknown';
|
|
63
|
+
export function projectMemoryWithheldNotice(withheld, lang) {
|
|
64
|
+
const cause = withheldCauseOf(withheld);
|
|
65
|
+
return renderMessage(msg(cause === undefined ? WITHHELD_UNKNOWN_KEY : WITHHELD_KEYS[cause]), lang);
|
|
66
|
+
}
|
|
67
|
+
function withheldCauseOf(withheld) {
|
|
68
|
+
const cause = guardedRead(() => (typeof withheld === 'object' && withheld !== null ? readOwnDataValue(withheld, 'cause') : undefined));
|
|
69
|
+
return typeof cause === 'string' && Object.hasOwn(WITHHELD_KEYS, cause) ? cause : undefined;
|
|
70
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RunTerminalRead } from './runTerminal.js';
|
|
2
|
-
|
|
2
|
+
import { PROMPT_BLOCKED_BY_HOOK_ROW_LEAD } from './rowKind.js';
|
|
3
|
+
export { PROMPT_BLOCKED_BY_HOOK_ROW_LEAD };
|
|
3
4
|
export declare function runBlockedText(blocked: Extract<RunTerminalRead, {
|
|
4
5
|
kind: 'blocked';
|
|
5
6
|
}>): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { displayUntrusted } from './displayUntrusted.js';
|
|
2
2
|
import { stripSystemReminderTagTokens, unwrapSystemReminder } from './systemReminderTag.js';
|
|
3
|
-
|
|
3
|
+
import { PROMPT_BLOCKED_BY_HOOK_ROW_LEAD } from './rowKind.js';
|
|
4
|
+
export { PROMPT_BLOCKED_BY_HOOK_ROW_LEAD };
|
|
4
5
|
const RUN_BLOCKED_REASONED = 'Run blocked';
|
|
5
6
|
const RUN_BLOCKED_NO_REASON = 'Run blocked (the agent reported it cannot proceed)';
|
|
6
7
|
const HOOK_WORDS_SHOWN_MAX = 1000;
|
package/dist/promptDelivery.d.ts
CHANGED
|
@@ -3,16 +3,35 @@ import { type SelfHealOutcome } from './adapter/activeRunSelfHeal.js';
|
|
|
3
3
|
import type { HumanTurnDelivered } from './humanTurn.js';
|
|
4
4
|
export interface PromptDeliveryRecord {
|
|
5
5
|
readonly u: string;
|
|
6
|
-
readonly s: 'a' | 'd';
|
|
6
|
+
readonly s: 'a' | 'd' | 'r';
|
|
7
7
|
readonly by?: 'frame' | 'steer_receipt';
|
|
8
8
|
readonly share?: 'full' | 'partial';
|
|
9
|
+
readonly n?: string;
|
|
10
|
+
readonly why?: NotDeliveredWhy;
|
|
9
11
|
}
|
|
12
|
+
export type NotDeliveredWhy = 'pre_send' | 'engine_rejected' | 'encoder_refused';
|
|
13
|
+
export type DeliveryState = 'delivered' | 'refused' | 'unknown';
|
|
10
14
|
export interface PromptDeliveryLedger {
|
|
11
15
|
attempted(batchUuids: readonly string[], opts?: {
|
|
12
16
|
readonly generation?: number;
|
|
17
|
+
readonly attemptId?: string;
|
|
13
18
|
}): readonly PromptDeliveryRecord[];
|
|
14
|
-
deliveredByFrame(batchUuids: readonly string[] | HumanTurnDelivered, event: AgentEvent
|
|
15
|
-
|
|
19
|
+
deliveredByFrame(batchUuids: readonly string[] | HumanTurnDelivered, event: AgentEvent, opts?: {
|
|
20
|
+
readonly attemptId?: string;
|
|
21
|
+
}): readonly PromptDeliveryRecord[];
|
|
22
|
+
deliveredBySteerReceipt(batchUuids: readonly string[] | HumanTurnDelivered, outcome: SelfHealOutcome, opts?: {
|
|
23
|
+
readonly attemptId?: string;
|
|
24
|
+
}): readonly PromptDeliveryRecord[];
|
|
25
|
+
notDelivered(batchUuids: readonly string[], opts: {
|
|
26
|
+
readonly attemptId: string;
|
|
27
|
+
readonly why: NotDeliveredWhy;
|
|
28
|
+
}): readonly PromptDeliveryRecord[];
|
|
29
|
+
deliveryStateOf(uuid: string): DeliveryState;
|
|
30
|
+
attemptedItems(groups: readonly (readonly string[])[], opts?: {
|
|
31
|
+
readonly generation?: number;
|
|
32
|
+
readonly attemptId?: string;
|
|
33
|
+
}): readonly PromptDeliveryRecord[];
|
|
34
|
+
batchGroupsOf(uuid: string): readonly (readonly string[])[] | undefined;
|
|
16
35
|
isAttempted(uuid: string): boolean;
|
|
17
36
|
isDelivered(uuid: string): boolean;
|
|
18
37
|
knownUndelivered(uuid: string): boolean;
|
|
@@ -23,6 +42,7 @@ export interface PromptDeliveryLedger {
|
|
|
23
42
|
toRecords(): readonly PromptDeliveryRecord[];
|
|
24
43
|
fromRecords(records: readonly PromptDeliveryRecord[]): readonly PromptDeliveryRecord[];
|
|
25
44
|
knownUndeliveredMessage(message: object | null | undefined): boolean;
|
|
45
|
+
deliveryStateOfMessage(message: object | null | undefined): DeliveryState;
|
|
26
46
|
withoutUndelivered<T>(messages: readonly T[]): T[];
|
|
27
47
|
}
|
|
28
48
|
export declare function frameProvesDelivery(event: object | null | undefined): boolean;
|
package/dist/promptDelivery.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { activeRunBusySignal } from './adapter/runStream.js';
|
|
2
2
|
import { selfHealSubmissionDisposition } from './adapter/activeRunSelfHeal.js';
|
|
3
|
+
import { guardedRead, readOwnDataValue } from './ownKey.js';
|
|
3
4
|
const uuidOk = (u) => typeof u === 'string' && u.length > 0;
|
|
4
5
|
function isArraySafe(v) {
|
|
5
6
|
try {
|
|
@@ -21,6 +22,15 @@ function generationOpt(opts) {
|
|
|
21
22
|
return undefined;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
function attemptIdOpt(opts) {
|
|
26
|
+
const v = ownDataOf(opts, 'attemptId');
|
|
27
|
+
return typeof v === 'string' && v.length > 0 ? v : undefined;
|
|
28
|
+
}
|
|
29
|
+
const ownDataOf = (o, key) => guardedRead(() => readOwnDataValue(o, key));
|
|
30
|
+
function notDeliveredWhyWord(v) {
|
|
31
|
+
const words = { pre_send: true, engine_rejected: true, encoder_refused: true };
|
|
32
|
+
return typeof v === 'string' && Object.hasOwn(words, v) ? v : undefined;
|
|
33
|
+
}
|
|
24
34
|
const levelOf = (rec) => !Object.hasOwn(rec, 'by') ? 1 : Object.hasOwn(rec, 'share') && rec.share === 'partial' ? 2 : 3;
|
|
25
35
|
function deliveredByWord(v) {
|
|
26
36
|
const words = { frame: true, steer_receipt: true };
|
|
@@ -34,7 +44,7 @@ function ownExtension(rec, key) {
|
|
|
34
44
|
const desc = Object.getOwnPropertyDescriptor(rec, key);
|
|
35
45
|
if (desc === undefined)
|
|
36
46
|
return key in rec ? { kind: 'unreadable' } : { kind: 'absent' };
|
|
37
|
-
return 'value'
|
|
47
|
+
return Object.hasOwn(desc, 'value') ? { kind: 'value', value: desc.value } : { kind: 'unreadable' };
|
|
38
48
|
}
|
|
39
49
|
function cleanBatch(batch) {
|
|
40
50
|
if (!isArraySafe(batch))
|
|
@@ -68,24 +78,41 @@ function readRecord(raw) {
|
|
|
68
78
|
catch {
|
|
69
79
|
return undefined;
|
|
70
80
|
}
|
|
71
|
-
if (!uuidOk(u) || (s !== 'a' && s !== 'd'))
|
|
81
|
+
if (!uuidOk(u) || (s !== 'a' && s !== 'd' && s !== 'r'))
|
|
72
82
|
return undefined;
|
|
73
83
|
const legacy = { u, s };
|
|
74
84
|
try {
|
|
75
85
|
let rec = legacy;
|
|
76
|
-
if (s === '
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
82
|
-
|
|
86
|
+
if (s === 'r') {
|
|
87
|
+
const nExt = ownExtension(raw, 'n');
|
|
88
|
+
const whyExt = ownExtension(raw, 'why');
|
|
89
|
+
const n = nExt.kind === 'value' && typeof nExt.value === 'string' && nExt.value.length > 0 ? nExt.value : undefined;
|
|
90
|
+
const why = whyExt.kind === 'value' ? notDeliveredWhyWord(whyExt.value) : undefined;
|
|
91
|
+
if (n === undefined || why === undefined)
|
|
92
|
+
return undefined;
|
|
93
|
+
rec = { u, s, n, why };
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const nExt = ownExtension(raw, 'n');
|
|
97
|
+
const n = nExt.kind === 'value' && typeof nExt.value === 'string' && nExt.value.length > 0 ? nExt.value : undefined;
|
|
98
|
+
if (s === 'd') {
|
|
99
|
+
const byExt = ownExtension(raw, 'by');
|
|
100
|
+
const shareExt = ownExtension(raw, 'share');
|
|
101
|
+
const by = byExt.kind === 'value' ? deliveredByWord(byExt.value) : undefined;
|
|
102
|
+
const share = shareExt.kind === 'value' ? deliveredShareWord(shareExt.value) : undefined;
|
|
103
|
+
if (by !== undefined && (shareExt.kind === 'absent' || share !== undefined)) {
|
|
104
|
+
rec = { u, s, by, ...(share !== undefined ? { share } : {}), ...(n !== undefined ? { n } : {}) };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if (n !== undefined) {
|
|
108
|
+
rec = { u, s, n };
|
|
109
|
+
}
|
|
83
110
|
}
|
|
84
111
|
const dropped = Object.keys(raw).filter((k) => !Object.hasOwn(rec, k)).length;
|
|
85
112
|
return { rec, dropped };
|
|
86
113
|
}
|
|
87
114
|
catch {
|
|
88
|
-
return { rec: legacy, dropped: 0 };
|
|
115
|
+
return s === 'r' ? undefined : { rec: legacy, dropped: 0 };
|
|
89
116
|
}
|
|
90
117
|
}
|
|
91
118
|
function readTierStrict(holder, key) {
|
|
@@ -154,9 +181,22 @@ export function createPromptDeliveryLedger() {
|
|
|
154
181
|
const attemptedSet = new Set();
|
|
155
182
|
const deliveredLevel = new Map();
|
|
156
183
|
const batchOfMap = new Map();
|
|
184
|
+
const groupsOfMap = new Map();
|
|
157
185
|
const generationOf = new Map();
|
|
186
|
+
const attempts = new Map();
|
|
187
|
+
const startedAttempts = new Map();
|
|
188
|
+
const legacyOpen = new Set();
|
|
158
189
|
const log = [];
|
|
159
190
|
let droppedKeys = 0;
|
|
191
|
+
const attemptStateOf = (u, n) => attempts.get(u)?.get(n);
|
|
192
|
+
const setAttempt = (u, n, st) => {
|
|
193
|
+
let m = attempts.get(u);
|
|
194
|
+
if (m === undefined) {
|
|
195
|
+
m = new Map();
|
|
196
|
+
attempts.set(u, m);
|
|
197
|
+
}
|
|
198
|
+
m.set(n, st);
|
|
199
|
+
};
|
|
160
200
|
const keep = (rec, into) => {
|
|
161
201
|
const frozen = Object.freeze(rec);
|
|
162
202
|
log.push(frozen);
|
|
@@ -164,50 +204,149 @@ export function createPromptDeliveryLedger() {
|
|
|
164
204
|
};
|
|
165
205
|
const add = (rec, into) => {
|
|
166
206
|
if (rec.s === 'a') {
|
|
167
|
-
if (
|
|
207
|
+
if (rec.n === undefined) {
|
|
208
|
+
if (legacyOpen.has(rec.u))
|
|
209
|
+
return;
|
|
210
|
+
attemptedSet.add(rec.u);
|
|
211
|
+
legacyOpen.add(rec.u);
|
|
212
|
+
keep(rec, into);
|
|
168
213
|
return;
|
|
214
|
+
}
|
|
215
|
+
let started = startedAttempts.get(rec.u);
|
|
216
|
+
if (started === undefined) {
|
|
217
|
+
started = new Set();
|
|
218
|
+
startedAttempts.set(rec.u, started);
|
|
219
|
+
}
|
|
220
|
+
if (started.has(rec.n))
|
|
221
|
+
return;
|
|
222
|
+
started.add(rec.n);
|
|
223
|
+
if (attemptStateOf(rec.u, rec.n) === undefined)
|
|
224
|
+
setAttempt(rec.u, rec.n, 'open');
|
|
225
|
+
attemptedSet.add(rec.u);
|
|
226
|
+
keep(rec, into);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (rec.s === 'r') {
|
|
230
|
+
if (rec.n === undefined)
|
|
231
|
+
return;
|
|
232
|
+
const st = attemptStateOf(rec.u, rec.n);
|
|
233
|
+
if (st === 'refused' || st === 'delivered')
|
|
234
|
+
return;
|
|
235
|
+
setAttempt(rec.u, rec.n, 'refused');
|
|
169
236
|
attemptedSet.add(rec.u);
|
|
170
237
|
keep(rec, into);
|
|
171
238
|
return;
|
|
172
239
|
}
|
|
173
240
|
const level = levelOf(rec);
|
|
174
|
-
|
|
241
|
+
const had = deliveredLevel.get(rec.u) ?? 0;
|
|
242
|
+
const settles = rec.n !== undefined && attemptStateOf(rec.u, rec.n) !== 'delivered';
|
|
243
|
+
if (had >= level && !settles)
|
|
175
244
|
return;
|
|
176
|
-
|
|
245
|
+
if (level > had)
|
|
246
|
+
deliveredLevel.set(rec.u, level);
|
|
247
|
+
if (rec.n !== undefined)
|
|
248
|
+
setAttempt(rec.u, rec.n, 'delivered');
|
|
177
249
|
keep(rec, into);
|
|
178
250
|
};
|
|
179
|
-
const markDelivered = (batch, by) => {
|
|
251
|
+
const markDelivered = (batch, by, attemptId) => {
|
|
180
252
|
const added = [];
|
|
181
253
|
const { full, partial } = batchTiers(batch);
|
|
254
|
+
const n = attemptId === undefined ? {} : { n: attemptId };
|
|
182
255
|
for (const u of full)
|
|
183
|
-
add({ u, s: 'd', by }, added);
|
|
256
|
+
add({ u, s: 'd', by, ...n }, added);
|
|
184
257
|
for (const u of partial)
|
|
185
|
-
add({ u, s: 'd', by, share: 'partial' }, added);
|
|
258
|
+
add({ u, s: 'd', by, share: 'partial', ...n }, added);
|
|
186
259
|
return Object.freeze(added);
|
|
187
260
|
};
|
|
188
261
|
const levelNow = (uuid) => (uuidOk(uuid) ? (deliveredLevel.get(uuid) ?? 0) : 0);
|
|
189
262
|
const knownUndeliveredUuid = (uuid) => uuidOk(uuid) && attemptedSet.has(uuid) && !deliveredLevel.has(uuid);
|
|
263
|
+
const deliveryStateUuid = (uuid) => {
|
|
264
|
+
if (!uuidOk(uuid))
|
|
265
|
+
return 'unknown';
|
|
266
|
+
if (levelNow(uuid) >= 2)
|
|
267
|
+
return 'delivered';
|
|
268
|
+
if (levelNow(uuid) === 1)
|
|
269
|
+
return 'unknown';
|
|
270
|
+
const m = attempts.get(uuid);
|
|
271
|
+
if (m === undefined || m.size === 0 || legacyOpen.has(uuid))
|
|
272
|
+
return 'unknown';
|
|
273
|
+
for (const st of m.values())
|
|
274
|
+
if (st !== 'refused')
|
|
275
|
+
return 'unknown';
|
|
276
|
+
return 'refused';
|
|
277
|
+
};
|
|
278
|
+
const attemptedImpl = (batchUuids, opts) => {
|
|
279
|
+
const generation = generationOpt(opts);
|
|
280
|
+
const attemptId = attemptIdOpt(opts);
|
|
281
|
+
const batch = Object.freeze(cleanBatch(batchUuids));
|
|
282
|
+
const added = [];
|
|
283
|
+
for (const u of batch) {
|
|
284
|
+
batchOfMap.set(u, batch);
|
|
285
|
+
groupsOfMap.delete(u);
|
|
286
|
+
if (generation !== undefined) {
|
|
287
|
+
generationOf.delete(u);
|
|
288
|
+
generationOf.set(u, generation);
|
|
289
|
+
}
|
|
290
|
+
add(attemptId === undefined ? { u, s: 'a' } : { u, s: 'a', n: attemptId }, added);
|
|
291
|
+
}
|
|
292
|
+
return Object.freeze(added);
|
|
293
|
+
};
|
|
190
294
|
const ledger = Object.freeze({
|
|
191
295
|
attempted(batchUuids, opts) {
|
|
192
|
-
|
|
193
|
-
|
|
296
|
+
return attemptedImpl(batchUuids, opts);
|
|
297
|
+
},
|
|
298
|
+
deliveredByFrame(batchUuids, event, opts) {
|
|
299
|
+
return frameProvesDelivery(event) ? markDelivered(batchUuids, 'frame', attemptIdOpt(opts)) : Object.freeze([]);
|
|
300
|
+
},
|
|
301
|
+
deliveredBySteerReceipt(batchUuids, outcome, opts) {
|
|
302
|
+
return outcomeProvesDelivery(outcome) ? markDelivered(batchUuids, 'steer_receipt', attemptIdOpt(opts)) : Object.freeze([]);
|
|
303
|
+
},
|
|
304
|
+
notDelivered(batchUuids, opts) {
|
|
194
305
|
const added = [];
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
306
|
+
const n = attemptIdOpt(opts);
|
|
307
|
+
const why = notDeliveredWhyWord(ownDataOf(opts, 'why'));
|
|
308
|
+
if (n === undefined || why === undefined)
|
|
309
|
+
return Object.freeze(added);
|
|
310
|
+
for (const u of cleanBatch(batchUuids)) {
|
|
311
|
+
if (attemptStateOf(u, n) !== 'open')
|
|
312
|
+
continue;
|
|
313
|
+
add({ u, s: 'r', n, why }, added);
|
|
202
314
|
}
|
|
203
315
|
return Object.freeze(added);
|
|
204
316
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
317
|
+
deliveryStateOf: (uuid) => deliveryStateUuid(uuid),
|
|
318
|
+
deliveryStateOfMessage: (message) => deliveryStateUuid(uuidOfMessage(message)),
|
|
319
|
+
attemptedItems(groups, opts) {
|
|
320
|
+
const clean = [];
|
|
321
|
+
if (isArraySafe(groups)) {
|
|
322
|
+
try {
|
|
323
|
+
for (const g of groups) {
|
|
324
|
+
const one = cleanBatch(g);
|
|
325
|
+
if (one.length > 0)
|
|
326
|
+
clean.push(Object.freeze(one));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
clean.length = 0;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const flat = [];
|
|
334
|
+
const seen = new Set();
|
|
335
|
+
for (const g of clean) {
|
|
336
|
+
for (const u of g) {
|
|
337
|
+
if (seen.has(u))
|
|
338
|
+
continue;
|
|
339
|
+
seen.add(u);
|
|
340
|
+
flat.push(u);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const added = attemptedImpl(flat, opts);
|
|
344
|
+
const frozenGroups = Object.freeze(clean);
|
|
345
|
+
for (const u of flat)
|
|
346
|
+
groupsOfMap.set(u, frozenGroups);
|
|
347
|
+
return added;
|
|
210
348
|
},
|
|
349
|
+
batchGroupsOf: (uuid) => (uuidOk(uuid) ? groupsOfMap.get(uuid) : undefined),
|
|
211
350
|
isAttempted: (uuid) => uuidOk(uuid) && attemptedSet.has(uuid),
|
|
212
351
|
isDelivered: (uuid) => levelNow(uuid) >= 2,
|
|
213
352
|
knownUndelivered: (uuid) => knownUndeliveredUuid(uuid),
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
+
import type { SDKAssistantMessageError } from '@sema-agent/agent-types';
|
|
1
2
|
import { type RunTerminalFailureDetail } from './runTerminal.js';
|
|
2
3
|
import { type ToolHistoryErrorCarrier } from './toolHistoryMismatch.js';
|
|
3
|
-
export declare
|
|
4
|
+
export declare function ccErrorOfProviderStatus(status: number): SDKAssistantMessageError | undefined;
|
|
5
|
+
export declare function isMintedRowCcError(v: {} | null | undefined): v is SDKAssistantMessageError;
|
|
6
|
+
export declare const PROVIDER_REJECTION_KINDS: readonly ["schema_invalid", "auth", "rate_limited", "resend_eligible", "unknown", "quota_exhausted"];
|
|
4
7
|
export type ProviderRejectionKind = (typeof PROVIDER_REJECTION_KINDS)[number];
|
|
8
|
+
export type ProviderRecourse = 'check_credentials' | 'switch_model' | 'fix_request';
|
|
9
|
+
export declare function conditionRecourseOf(word: string | undefined): 'switch_model' | 'fix_request' | undefined;
|
|
10
|
+
export declare function isServiceSideStatus(http: number): boolean;
|
|
11
|
+
export declare function isHttpStatus(n: number | undefined): n is number;
|
|
12
|
+
export declare function terminalRecourseOf(status: number | undefined, providerCondition: string | undefined): ProviderRecourse | undefined;
|
|
13
|
+
export interface ResultWayOutFacts {
|
|
14
|
+
readonly status?: number;
|
|
15
|
+
readonly providerCondition?: string;
|
|
16
|
+
readonly credentialSource?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ProviderWayOut {
|
|
19
|
+
readonly word: ProviderRecourse;
|
|
20
|
+
readonly keySource?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function wayOutOfApiErrorFacts(facts: ResultWayOutFacts | undefined): ProviderWayOut | undefined;
|
|
5
23
|
export interface ProviderRejectionResend {
|
|
6
24
|
resend: 'edit_and_resend' | 'not_by_editing';
|
|
7
25
|
text: string;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { readOwnDataValue } from './ownKey.js';
|
|
2
|
+
import { msg, renderMessage } from './i18n/translate.js';
|
|
1
3
|
import { readRunTerminal } from './runTerminal.js';
|
|
2
4
|
import { classifyToolHistoryMismatch } from './toolHistoryMismatch.js';
|
|
3
5
|
const PROVIDER_STATUS_TIERS = Object.freeze([
|
|
@@ -17,8 +19,19 @@ function providerStatusTier(status) {
|
|
|
17
19
|
return tier;
|
|
18
20
|
return UNTIERED;
|
|
19
21
|
}
|
|
22
|
+
export function ccErrorOfProviderStatus(status) {
|
|
23
|
+
if (typeof status !== 'number' || !Number.isInteger(status) || status < 100 || status > 999)
|
|
24
|
+
return undefined;
|
|
25
|
+
for (const [lo, hi, tier] of PROVIDER_STATUS_TIERS)
|
|
26
|
+
if (status >= lo && status <= hi)
|
|
27
|
+
return tier;
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
export function isMintedRowCcError(v) {
|
|
31
|
+
return typeof v === 'string' && PROVIDER_STATUS_TIERS.some((t) => t[2] === v);
|
|
32
|
+
}
|
|
20
33
|
const EDITABLE_TIER = 'invalid_request';
|
|
21
|
-
export const PROVIDER_REJECTION_KINDS = Object.freeze(['schema_invalid', 'auth', 'rate_limited', 'resend_eligible', 'unknown']);
|
|
34
|
+
export const PROVIDER_REJECTION_KINDS = Object.freeze(['schema_invalid', 'auth', 'rate_limited', 'resend_eligible', 'unknown', 'quota_exhausted']);
|
|
22
35
|
const SCHEMA_INVALID_CODES = new Set([
|
|
23
36
|
'invalid_type',
|
|
24
37
|
'missing_required_parameter',
|
|
@@ -30,6 +43,51 @@ const SCHEMA_INVALID_CODES = new Set([
|
|
|
30
43
|
function schemaTierStatus(status) {
|
|
31
44
|
return status === 400 || status === 422;
|
|
32
45
|
}
|
|
46
|
+
const CONDITION_RECOURSE = Object.freeze({
|
|
47
|
+
quota_exhausted: 'switch_model',
|
|
48
|
+
throttled: 'switch_model',
|
|
49
|
+
overloaded: 'switch_model',
|
|
50
|
+
stop_other: 'fix_request',
|
|
51
|
+
unknown: null,
|
|
52
|
+
});
|
|
53
|
+
export function conditionRecourseOf(word) {
|
|
54
|
+
if (word === undefined || !Object.hasOwn(CONDITION_RECOURSE, word))
|
|
55
|
+
return undefined;
|
|
56
|
+
return CONDITION_RECOURSE[word] ?? undefined;
|
|
57
|
+
}
|
|
58
|
+
export function isServiceSideStatus(http) {
|
|
59
|
+
return http === 429 || (http >= 500 && http <= 599);
|
|
60
|
+
}
|
|
61
|
+
export function isHttpStatus(n) {
|
|
62
|
+
return typeof n === 'number' && Number.isInteger(n) && n >= 100 && n <= 999;
|
|
63
|
+
}
|
|
64
|
+
export function terminalRecourseOf(status, providerCondition) {
|
|
65
|
+
const http = isHttpStatus(status) ? status : undefined;
|
|
66
|
+
const byCondition = conditionRecourseOf(providerCondition);
|
|
67
|
+
if (http === undefined && byCondition === undefined)
|
|
68
|
+
return undefined;
|
|
69
|
+
if (http === 401 || http === 403)
|
|
70
|
+
return 'check_credentials';
|
|
71
|
+
return byCondition ?? (http !== undefined && isServiceSideStatus(http) ? 'switch_model' : undefined);
|
|
72
|
+
}
|
|
73
|
+
export function wayOutOfApiErrorFacts(facts) {
|
|
74
|
+
try {
|
|
75
|
+
if (typeof facts !== 'object' || facts === null)
|
|
76
|
+
return undefined;
|
|
77
|
+
const status = readOwnDataValue(facts, 'status');
|
|
78
|
+
const providerCondition = readOwnDataValue(facts, 'providerCondition');
|
|
79
|
+
const word = terminalRecourseOf(typeof status === 'number' ? status : undefined, typeof providerCondition === 'string' && providerCondition !== '' ? providerCondition : undefined);
|
|
80
|
+
if (word === undefined)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (word !== 'check_credentials')
|
|
83
|
+
return Object.freeze({ word });
|
|
84
|
+
const credentialSource = readOwnDataValue(facts, 'credentialSource');
|
|
85
|
+
return Object.freeze(typeof credentialSource === 'string' && credentialSource !== '' ? { word, keySource: credentialSource } : { word });
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
33
91
|
function kindOfStatus(status, code) {
|
|
34
92
|
const tier = providerStatusTier(status);
|
|
35
93
|
if (tier === 'authentication_failed')
|
|
@@ -40,6 +98,14 @@ function kindOfStatus(status, code) {
|
|
|
40
98
|
return code !== undefined && schemaTierStatus(status) && SCHEMA_INVALID_CODES.has(code) ? 'schema_invalid' : 'resend_eligible';
|
|
41
99
|
return 'unknown';
|
|
42
100
|
}
|
|
101
|
+
const QUOTA_CONDITION = 'quota_exhausted';
|
|
102
|
+
function quotaOverridesTier(status) {
|
|
103
|
+
const tier = providerStatusTier(status);
|
|
104
|
+
return tier === EDITABLE_TIER || tier === 'rate_limit' || tier === UNTIERED;
|
|
105
|
+
}
|
|
106
|
+
function kindOfRejection(status, code, condition) {
|
|
107
|
+
return condition === QUOTA_CONDITION && quotaOverridesTier(status) ? 'quota_exhausted' : kindOfStatus(status, code);
|
|
108
|
+
}
|
|
43
109
|
const NOT_BY_EDITING_TAIL = new Map([
|
|
44
110
|
['authentication_failed', ': check the provider credentials or access for this account.'],
|
|
45
111
|
['model_not_found', ': the model is not available from this provider — choose another model.'],
|
|
@@ -99,12 +165,17 @@ function readRejection(detail) {
|
|
|
99
165
|
const status = Object.hasOwn(read, 'status') ? read.status : undefined;
|
|
100
166
|
if (status === undefined)
|
|
101
167
|
return undefined;
|
|
102
|
-
return { status, code: Object.hasOwn(read, 'code') ? read.code : undefined };
|
|
168
|
+
return { status, code: Object.hasOwn(read, 'code') ? read.code : undefined, providerCondition: Object.hasOwn(read, 'providerCondition') ? read.providerCondition : undefined };
|
|
103
169
|
}
|
|
104
170
|
function schemaInvalidText(status) {
|
|
105
171
|
return `The model provider rejected the structure of this request (HTTP ${status}) — rewording the message will not fix this. Check that the configured model and endpoint accept this kind of request, or report the problem to whoever runs the engine.`;
|
|
106
172
|
}
|
|
107
173
|
function verdictOf(status, kind) {
|
|
174
|
+
if (kind === 'quota_exhausted') {
|
|
175
|
+
if (!quotaOverridesTier(status))
|
|
176
|
+
return undefined;
|
|
177
|
+
return { resend: 'not_by_editing', text: renderMessage(msg('notice.providerRejection.quotaExhausted', { status })), kind };
|
|
178
|
+
}
|
|
108
179
|
if (kind === 'schema_invalid') {
|
|
109
180
|
if (providerStatusTier(status) !== EDITABLE_TIER || !schemaTierStatus(status))
|
|
110
181
|
return undefined;
|
|
@@ -131,9 +202,9 @@ export function providerRejectionResend(detail, carrier) {
|
|
|
131
202
|
return undefined;
|
|
132
203
|
if (toolHistoryMismatchCarrier(carrier))
|
|
133
204
|
return undefined;
|
|
134
|
-
return verdictOf(r.status,
|
|
205
|
+
return verdictOf(r.status, kindOfRejection(r.status, r.code, r.providerCondition));
|
|
135
206
|
}
|
|
136
207
|
export function providerRejectionKind(detail) {
|
|
137
208
|
const r = readRejection(detail);
|
|
138
|
-
return r === undefined ? 'unknown' :
|
|
209
|
+
return r === undefined ? 'unknown' : kindOfRejection(r.status, r.code, r.providerCondition);
|
|
139
210
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { encodeHumanTurn, type HumanTurnCaps, type HumanTurnItem } from './humanTurn.js';
|
|
2
|
+
import { type LiveModelCatalog } from './liveModelCatalog.js';
|
|
3
|
+
import type { HooksWirePlan } from './pluginHooksWire.js';
|
|
4
|
+
export type QueueEntryKind = 'prompt' | 'bash' | 'slash' | 'injected' | 'other';
|
|
5
|
+
export type QueueShellBlock = 'origin' | 'subagent' | 'replay' | 'structured';
|
|
6
|
+
export interface QueueEntry {
|
|
7
|
+
readonly uuid: string;
|
|
8
|
+
readonly kind: QueueEntryKind;
|
|
9
|
+
readonly shellBlock?: QueueShellBlock;
|
|
10
|
+
readonly item: HumanTurnItem;
|
|
11
|
+
readonly steerState: 'none' | 'in_flight' | 'attempted';
|
|
12
|
+
readonly held?: boolean;
|
|
13
|
+
readonly injection?: string;
|
|
14
|
+
readonly hidden?: boolean;
|
|
15
|
+
readonly intentKey?: string;
|
|
16
|
+
readonly screening?: 'pending' | 'result';
|
|
17
|
+
readonly upsExecutor?: 'shell' | 'engine' | 'unknown' | 'none';
|
|
18
|
+
}
|
|
19
|
+
export type QueuedHoldReason = 'barrier' | 'share_incomplete' | 'not_steerable' | 'in_flight' | 'attempted' | 'no_run';
|
|
20
|
+
export interface QueuedDeliveryPlan {
|
|
21
|
+
readonly steerNow: readonly {
|
|
22
|
+
readonly uuid: string;
|
|
23
|
+
readonly payload: Extract<ReturnType<typeof encodeHumanTurn>, {
|
|
24
|
+
ok: true;
|
|
25
|
+
lane: 'steer';
|
|
26
|
+
}>;
|
|
27
|
+
}[];
|
|
28
|
+
readonly held: readonly {
|
|
29
|
+
readonly uuid: string;
|
|
30
|
+
readonly reason: QueuedHoldReason;
|
|
31
|
+
}[];
|
|
32
|
+
readonly canSendNow: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function batchCompatible(head: QueueEntry, follower: QueueEntry, plan: HooksWirePlan | undefined): boolean;
|
|
35
|
+
export declare function planQueuedDelivery(entries: readonly QueueEntry[], run: {
|
|
36
|
+
readonly live: boolean;
|
|
37
|
+
readonly steerVerb: boolean;
|
|
38
|
+
}, caps: HumanTurnCaps, policy?: {
|
|
39
|
+
readonly overtakeBashHead?: boolean;
|
|
40
|
+
}): QueuedDeliveryPlan;
|
|
41
|
+
export declare function selfHealSteerEligible(items: readonly HumanTurnItem[], caps: HumanTurnCaps): boolean;
|
|
42
|
+
export interface HumanTurnCapsFacts {
|
|
43
|
+
readonly model?: string;
|
|
44
|
+
readonly baseUrl?: string;
|
|
45
|
+
readonly catalog?: LiveModelCatalog | null;
|
|
46
|
+
}
|
|
47
|
+
export declare function humanTurnCapsOf(facts?: HumanTurnCapsFacts): HumanTurnCaps;
|
|
48
|
+
export declare function humanTextForKeywordScan(items: readonly HumanTurnItem[]): string;
|