@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
|
@@ -286,6 +286,18 @@ function ownDataMember(o, k) {
|
|
|
286
286
|
return undefined;
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
+
export const SEMA_TOOL_HISTORY_ACCEPTED_KEY = '_sema_tool_history_accepted';
|
|
290
|
+
export function readToolHistoryAcceptedKey(frame) {
|
|
291
|
+
try {
|
|
292
|
+
if (typeof frame !== 'object' || frame === null)
|
|
293
|
+
return undefined;
|
|
294
|
+
const d = Object.getOwnPropertyDescriptor(frame, SEMA_TOOL_HISTORY_ACCEPTED_KEY);
|
|
295
|
+
return d !== undefined && Object.hasOwn(d, 'value') && d.value === true ? true : undefined;
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
289
301
|
export const TOOL_HISTORY_LEDGER_CAP = 64;
|
|
290
302
|
const PRIOR_RUN_IDS_CAP = 16;
|
|
291
303
|
const ECHOED_SESSION_IDS_CAP = TOOL_HISTORY_LEDGER_CAP * 4;
|
|
@@ -308,16 +320,30 @@ export function openToolHistoryGeneration() {
|
|
|
308
320
|
return toolHistoryGenerationSeq;
|
|
309
321
|
}
|
|
310
322
|
const fingerprintOf = (m) => `${m.kind}\u0000${m.toolUseId ?? ''}`;
|
|
323
|
+
function acceptanceStep(prev, note, attributed) {
|
|
324
|
+
if (note.replay)
|
|
325
|
+
return { awaiting: prev, accepted: undefined };
|
|
326
|
+
if (note.mismatch !== null)
|
|
327
|
+
return { awaiting: true, accepted: undefined };
|
|
328
|
+
if (note.accepted === true)
|
|
329
|
+
return attributed ? { awaiting: false, accepted: prev ? true : undefined } : { awaiting: prev, accepted: undefined };
|
|
330
|
+
return { awaiting: prev, accepted: undefined };
|
|
331
|
+
}
|
|
311
332
|
export function noteToolHistoryTerminal(note) {
|
|
333
|
+
return noteToolHistoryTerminalFacts(note).consecutive;
|
|
334
|
+
}
|
|
335
|
+
export function noteToolHistoryTerminalFacts(note) {
|
|
336
|
+
const none = { consecutive: undefined, acceptedSinceMismatch: undefined };
|
|
312
337
|
const { sessionId, generation, runId, replay, mismatch } = note;
|
|
313
338
|
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
314
339
|
unattributedTerminalSeq += 1;
|
|
315
|
-
return
|
|
340
|
+
return none;
|
|
316
341
|
}
|
|
317
342
|
if (note.sessionEchoed === true)
|
|
318
343
|
rememberEchoedSession(sessionId);
|
|
319
344
|
else if (!echoedSessionIds.has(sessionId))
|
|
320
345
|
unattributedTerminalSeq += 1;
|
|
346
|
+
const attributed = note.sessionEchoed === true || echoedSessionIds.has(sessionId);
|
|
321
347
|
const row = toolHistoryLedger.get(sessionId);
|
|
322
348
|
const fingerprint = mismatch === null ? null : fingerprintOf(mismatch);
|
|
323
349
|
const run = !replay && typeof runId === 'string' && runId.length > 0 ? runId : undefined;
|
|
@@ -330,25 +356,29 @@ export function noteToolHistoryTerminal(note) {
|
|
|
330
356
|
unattributedMark: unattributedTerminalSeq,
|
|
331
357
|
lastRunId: undefined,
|
|
332
358
|
recentRunIds: run !== undefined ? [...row.recentRunIds, run].slice(-PRIOR_RUN_IDS_CAP) : row.recentRunIds,
|
|
359
|
+
awaitingAcceptance: row.awaitingAcceptance,
|
|
333
360
|
});
|
|
334
361
|
}
|
|
335
|
-
return
|
|
362
|
+
return none;
|
|
336
363
|
}
|
|
337
364
|
if (row !== undefined)
|
|
338
365
|
row.writtenGeneration = generation;
|
|
339
366
|
const interrupted = row !== undefined && row.unattributedMark < unattributedTerminalSeq;
|
|
340
367
|
if (run !== undefined && row !== undefined && (row.segmentRunIds.has(run) || row.recentRunIds.includes(run))) {
|
|
341
|
-
|
|
368
|
+
const repeated = !interrupted && row.lastRunId === run && fingerprint !== null && row.fingerprint === fingerprint ? row.segmentRunIds.size : undefined;
|
|
369
|
+
return { consecutive: repeated, acceptedSinceMismatch: undefined };
|
|
342
370
|
}
|
|
371
|
+
const acceptance = acceptanceStep(row?.awaitingAcceptance ?? false, note, attributed);
|
|
343
372
|
if (row !== undefined && row.fingerprint === fingerprint && !(interrupted && fingerprint !== null && run !== undefined)) {
|
|
373
|
+
row.awaitingAcceptance = acceptance.awaiting;
|
|
344
374
|
if (run === undefined)
|
|
345
|
-
return undefined;
|
|
375
|
+
return { consecutive: undefined, acceptedSinceMismatch: acceptance.accepted };
|
|
346
376
|
if (fingerprint !== null)
|
|
347
377
|
row.segmentRunIds.add(run);
|
|
348
378
|
row.lastRunId = run;
|
|
349
379
|
row.recentRunIds = [...row.recentRunIds, run].slice(-PRIOR_RUN_IDS_CAP);
|
|
350
380
|
touchLedgerRow(sessionId, row);
|
|
351
|
-
return fingerprint === null ? undefined : row.segmentRunIds.size;
|
|
381
|
+
return { consecutive: fingerprint === null ? undefined : row.segmentRunIds.size, acceptedSinceMismatch: acceptance.accepted };
|
|
352
382
|
}
|
|
353
383
|
touchLedgerRow(sessionId, {
|
|
354
384
|
fingerprint,
|
|
@@ -357,8 +387,9 @@ export function noteToolHistoryTerminal(note) {
|
|
|
357
387
|
unattributedMark: unattributedTerminalSeq,
|
|
358
388
|
lastRunId: run,
|
|
359
389
|
recentRunIds: run !== undefined ? [...(row?.recentRunIds ?? []), run].slice(-PRIOR_RUN_IDS_CAP) : [...(row?.recentRunIds ?? [])],
|
|
390
|
+
awaitingAcceptance: acceptance.awaiting,
|
|
360
391
|
});
|
|
361
|
-
return fingerprint !== null && run !== undefined ? 1 : undefined;
|
|
392
|
+
return { consecutive: fingerprint !== null && run !== undefined ? 1 : undefined, acceptedSinceMismatch: acceptance.accepted };
|
|
362
393
|
}
|
|
363
394
|
function touchLedgerRow(sessionId, row) {
|
|
364
395
|
toolHistoryLedger.delete(sessionId);
|
package/dist/toolResult.d.ts
CHANGED
|
@@ -112,21 +112,31 @@ export interface ToolResultRowFlags {
|
|
|
112
112
|
}
|
|
113
113
|
export declare function toolResultRowFlagsOf(row: object | null | undefined): ToolResultRowFlags;
|
|
114
114
|
export type ToolKillCause = NonNullable<ReturnType<typeof toolKillCauseAcrossEngineIdentity>> | 'memory_pressure';
|
|
115
|
-
export declare function wireOutputToBody(toolName: string, output: unknown, isError: boolean, truncated: boolean, flatten: FlattenWireOutput,
|
|
115
|
+
export declare function wireOutputToBody(toolName: string, output: unknown, isError: boolean, truncated: boolean, flatten: FlattenWireOutput, structuredIn?: unknown, leaderLedger?: boolean, killCauseOf?: () => ToolKillCause | undefined): ToolResultBody;
|
|
116
116
|
export declare function structuredToToolUseResult(structured: unknown, modelText?: string, leaderLedger?: boolean): {
|
|
117
117
|
toolUseResult: unknown;
|
|
118
118
|
isError?: boolean;
|
|
119
119
|
} | null;
|
|
120
|
+
export interface WebSearchSource {
|
|
121
|
+
readonly title: string;
|
|
122
|
+
readonly url: string;
|
|
123
|
+
}
|
|
124
|
+
export type WebSearchSources = readonly WebSearchSource[] & {
|
|
125
|
+
readonly droppedCount: number;
|
|
126
|
+
};
|
|
127
|
+
export declare function webSearchSourcesOf(toolEnd: {} | null | undefined): WebSearchSources | undefined;
|
|
120
128
|
export interface EngineBgShellRegistration {
|
|
121
129
|
kind: 'register';
|
|
122
130
|
taskId: string;
|
|
131
|
+
toolUseId?: string;
|
|
123
132
|
command: string;
|
|
124
133
|
description?: string;
|
|
125
134
|
receipt: string;
|
|
135
|
+
outputFile?: string;
|
|
126
136
|
source: 'bash' | 'monitor';
|
|
127
137
|
}
|
|
128
|
-
export declare function detectEngineBgShellReceipt(toolName: string, rawInput: unknown, outputText: string | undefined, structured?: unknown): EngineBgShellRegistration | null;
|
|
129
|
-
export declare function detectEngineBgShellDetach(toolName: string, rawInput: unknown, structured: unknown, outputText: string | undefined): EngineBgShellRegistration | null;
|
|
138
|
+
export declare function detectEngineBgShellReceipt(toolName: string, rawInput: unknown, outputText: string | undefined, structured?: unknown, toolUseId?: string): EngineBgShellRegistration | null;
|
|
139
|
+
export declare function detectEngineBgShellDetach(toolName: string, rawInput: unknown, structured: unknown, outputText: string | undefined, toolUseId?: string): EngineBgShellRegistration | null;
|
|
130
140
|
export declare function todoWriteToolUseResult(rawInput: unknown, oldTodos: unknown[], isError: boolean): {
|
|
131
141
|
toolUseResult: unknown;
|
|
132
142
|
isError: boolean;
|
package/dist/toolResult.js
CHANGED
|
@@ -4,7 +4,8 @@ import { parseWorkflowPollEnvelope, projectWorkflowTaskOutput } from './workflow
|
|
|
4
4
|
import { asModelFallbackReason } from './engineErrorCodes.js';
|
|
5
5
|
import { frozenSet } from './frozenSet.js';
|
|
6
6
|
import { bashExitOf, bashExitReadingFailed } from './bashExitReading.js';
|
|
7
|
-
import { readFrameTrueMark, readFrameTrueMarkReading } from './ownKey.js';
|
|
7
|
+
import { guardedRead, ownSnapshotWhenTyped, readFrameTrueMark, readFrameTrueMarkReading, readOwnDataFiniteNumber, readOwnDataNonEmptyString, readOwnDataValue, } from './ownKey.js';
|
|
8
|
+
import { displayUntrusted } from './displayUntrusted.js';
|
|
8
9
|
import { isCoreSemaTaskTerminal } from './terminalStatuses.js';
|
|
9
10
|
import { CORE_ENGINE_CARD_TYPES } from './generated/engineFactTables.js';
|
|
10
11
|
export const STRUCTURED_DETAIL_TYPES = frozenSet(CORE_ENGINE_CARD_TYPES);
|
|
@@ -356,7 +357,8 @@ const killedBySignalSentence = (killCauseOf) => {
|
|
|
356
357
|
}
|
|
357
358
|
return TOOL_KILL_TEXT[isToolKillCause(cause) ? cause : 'unknown'];
|
|
358
359
|
};
|
|
359
|
-
export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
360
|
+
export function wireOutputToBody(toolName, output, isError, truncated, flatten, structuredIn, leaderLedger = true, killCauseOf) {
|
|
361
|
+
const structured = ownSnapshotWhenTyped(structuredIn, 'task-output');
|
|
360
362
|
const text = flatten(output);
|
|
361
363
|
const name = (toolName || '').toLowerCase();
|
|
362
364
|
const sType = structuredDetailType(structured);
|
|
@@ -473,9 +475,12 @@ export function wireOutputToBody(toolName, output, isError, truncated, flatten,
|
|
|
473
475
|
return { content: truncated ? `${text}\n…(truncated)` : text, isError };
|
|
474
476
|
}
|
|
475
477
|
export function structuredToToolUseResult(structured, modelText, leaderLedger = true) {
|
|
476
|
-
|
|
478
|
+
const sampled = ownSnapshotWhenTyped(structured, 'task-output');
|
|
479
|
+
if (typeof sampled !== 'object' || sampled === null)
|
|
477
480
|
return null;
|
|
478
|
-
const s =
|
|
481
|
+
const s = sampled;
|
|
482
|
+
if (guardedRead(() => readOwnDataValue(s, 'type')) === 'web-search')
|
|
483
|
+
return webSearchToolUseResult(s);
|
|
479
484
|
for (const k of ['originalFile', 'content', 'stdout', 'stderr']) {
|
|
480
485
|
if (typeof s[k] === 'string' && s[k].length > MAX_STRUCTURED_FIELD_CHARS)
|
|
481
486
|
return null;
|
|
@@ -748,6 +753,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
748
753
|
: (parsed?.status ?? (engineSaidNotReady ? 'running' : 'unknown'));
|
|
749
754
|
const bodyText = hasContent ? s.content : parsed && parsed.kind !== 'unknown' ? parsed.output : undefined;
|
|
750
755
|
const error = typeof s.error === 'string' ? s.error : undefined;
|
|
756
|
+
const completionId = terminalCardCompletionIdOf(s, engineSaidNotReady);
|
|
751
757
|
if (taskType === 'background_bash') {
|
|
752
758
|
const exitCode = typeof inner?.exitCode === 'number' ? inner.exitCode : undefined;
|
|
753
759
|
return {
|
|
@@ -761,6 +767,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
761
767
|
output: bodyText ?? '',
|
|
762
768
|
...(exitCode !== undefined ? { exitCode } : {}),
|
|
763
769
|
...(error !== undefined ? { error } : {}),
|
|
770
|
+
...(completionId !== undefined ? { _sema_completion_id: completionId } : {}),
|
|
764
771
|
},
|
|
765
772
|
},
|
|
766
773
|
};
|
|
@@ -777,6 +784,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
777
784
|
output: bodyText ?? '',
|
|
778
785
|
result: bodyText ?? '',
|
|
779
786
|
...(error !== undefined ? { error } : {}),
|
|
787
|
+
...(completionId !== undefined ? { _sema_completion_id: completionId } : {}),
|
|
780
788
|
},
|
|
781
789
|
},
|
|
782
790
|
};
|
|
@@ -801,6 +809,7 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
801
809
|
output,
|
|
802
810
|
...(error !== undefined ? { error } : {}),
|
|
803
811
|
...(runErrorCode !== undefined ? { _sema_error_code: runErrorCode } : {}),
|
|
812
|
+
...(completionId !== undefined ? { _sema_completion_id: completionId } : {}),
|
|
804
813
|
},
|
|
805
814
|
},
|
|
806
815
|
};
|
|
@@ -809,7 +818,143 @@ export function structuredToToolUseResult(structured, modelText, leaderLedger =
|
|
|
809
818
|
return null;
|
|
810
819
|
}
|
|
811
820
|
}
|
|
812
|
-
|
|
821
|
+
const WEB_SEARCH_ENTRIES_MAX = 1024;
|
|
822
|
+
const WEB_SEARCH_HITS_MAX = 4096;
|
|
823
|
+
const WEB_SEARCH_FIELD_CHARS_MAX = 8192;
|
|
824
|
+
function isArrayLength(n) {
|
|
825
|
+
return Number.isInteger(n) && n >= 0 && n <= 4_294_967_295;
|
|
826
|
+
}
|
|
827
|
+
function isWebSearchRecord(v) {
|
|
828
|
+
return typeof v === 'object' && v !== null && guardedRead(() => !Array.isArray(v)) === true;
|
|
829
|
+
}
|
|
830
|
+
function readWebSearchHit(raw) {
|
|
831
|
+
if (!isWebSearchRecord(raw))
|
|
832
|
+
return undefined;
|
|
833
|
+
const title = readOwnDataValue(raw, 'title');
|
|
834
|
+
const url = readOwnDataValue(raw, 'url');
|
|
835
|
+
if (typeof title !== 'string' || typeof url !== 'string' || url === '')
|
|
836
|
+
return undefined;
|
|
837
|
+
if (title.length > WEB_SEARCH_FIELD_CHARS_MAX || url.length > WEB_SEARCH_FIELD_CHARS_MAX)
|
|
838
|
+
return undefined;
|
|
839
|
+
return { title, url };
|
|
840
|
+
}
|
|
841
|
+
function readWebSearchEntry(raw, hitBudget) {
|
|
842
|
+
if (!isWebSearchRecord(raw))
|
|
843
|
+
return undefined;
|
|
844
|
+
const toolUseId = readOwnDataValue(raw, 'tool_use_id');
|
|
845
|
+
const content = readOwnDataValue(raw, 'content');
|
|
846
|
+
if (typeof toolUseId !== 'string' || typeof content !== 'object' || content === null || !Array.isArray(content))
|
|
847
|
+
return undefined;
|
|
848
|
+
const n = readOwnDataFiniteNumber(content, 'length');
|
|
849
|
+
if (n === undefined || !isArrayLength(n))
|
|
850
|
+
return undefined;
|
|
851
|
+
const limit = Math.min(n, Math.max(0, hitBudget));
|
|
852
|
+
const hits = [];
|
|
853
|
+
let dropped = n - limit;
|
|
854
|
+
for (let j = 0; j < limit; j++) {
|
|
855
|
+
const hit = guardedRead(() => readWebSearchHit(readOwnDataValue(content, String(j))));
|
|
856
|
+
if (hit === undefined)
|
|
857
|
+
dropped++;
|
|
858
|
+
else
|
|
859
|
+
hits.push(hit);
|
|
860
|
+
}
|
|
861
|
+
return { entry: { tool_use_id: toolUseId, content: hits }, visited: limit, dropped };
|
|
862
|
+
}
|
|
863
|
+
function readWebSearchEntries(card) {
|
|
864
|
+
const results = guardedRead(() => readOwnDataValue(card, 'results'));
|
|
865
|
+
if (typeof results !== 'object' || results === null || guardedRead(() => Array.isArray(results)) !== true)
|
|
866
|
+
return undefined;
|
|
867
|
+
const length = guardedRead(() => readOwnDataFiniteNumber(results, 'length'));
|
|
868
|
+
if (length === undefined || !isArrayLength(length))
|
|
869
|
+
return undefined;
|
|
870
|
+
const entries = [];
|
|
871
|
+
let dropped = Math.max(0, length - WEB_SEARCH_ENTRIES_MAX);
|
|
872
|
+
let hitsLeft = WEB_SEARCH_HITS_MAX;
|
|
873
|
+
for (let i = 0; i < Math.min(length, WEB_SEARCH_ENTRIES_MAX); i++) {
|
|
874
|
+
const raw = guardedRead(() => readOwnDataValue(results, String(i)));
|
|
875
|
+
if (typeof raw === 'string') {
|
|
876
|
+
entries.push(raw);
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
const one = guardedRead(() => readWebSearchEntry(raw, hitsLeft));
|
|
880
|
+
if (one === undefined) {
|
|
881
|
+
dropped++;
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
entries.push(one.entry);
|
|
885
|
+
hitsLeft -= one.visited;
|
|
886
|
+
dropped += one.dropped;
|
|
887
|
+
}
|
|
888
|
+
const usable = entries.some(e => typeof e !== 'string' && e.content.length > 0);
|
|
889
|
+
if (dropped > 0 && !usable)
|
|
890
|
+
return undefined;
|
|
891
|
+
return { entries, dropped };
|
|
892
|
+
}
|
|
893
|
+
function webSearchToolUseResult(card) {
|
|
894
|
+
try {
|
|
895
|
+
const query = readOwnDataValue(card, 'query');
|
|
896
|
+
const durationSeconds = readOwnDataFiniteNumber(card, 'durationSeconds');
|
|
897
|
+
if (typeof query !== 'string' || durationSeconds === undefined || durationSeconds < 0)
|
|
898
|
+
return null;
|
|
899
|
+
const read = readWebSearchEntries(card);
|
|
900
|
+
if (read === undefined)
|
|
901
|
+
return null;
|
|
902
|
+
const searchCount = readOwnDataFiniteNumber(card, 'searchCount');
|
|
903
|
+
return {
|
|
904
|
+
toolUseResult: {
|
|
905
|
+
query,
|
|
906
|
+
results: read.entries.map(e => (typeof e === 'string' ? e : { tool_use_id: e.tool_use_id, content: e.content.map(h => ({ title: h.title, url: h.url })) })),
|
|
907
|
+
durationSeconds,
|
|
908
|
+
...(searchCount !== undefined && Number.isInteger(searchCount) && searchCount >= 0 ? { searchCount } : {}),
|
|
909
|
+
},
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
catch {
|
|
913
|
+
return null;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
export function webSearchSourcesOf(toolEnd) {
|
|
917
|
+
try {
|
|
918
|
+
if (!isWebSearchRecord(toolEnd))
|
|
919
|
+
return undefined;
|
|
920
|
+
const structured = readOwnDataValue(toolEnd, 'structured');
|
|
921
|
+
if (!isWebSearchRecord(structured) || readOwnDataValue(structured, 'type') !== 'web-search')
|
|
922
|
+
return undefined;
|
|
923
|
+
const read = readWebSearchEntries(structured);
|
|
924
|
+
if (read === undefined)
|
|
925
|
+
return undefined;
|
|
926
|
+
let dropped = read.dropped;
|
|
927
|
+
const out = [];
|
|
928
|
+
for (const e of read.entries) {
|
|
929
|
+
if (typeof e === 'string')
|
|
930
|
+
continue;
|
|
931
|
+
for (const h of e.content) {
|
|
932
|
+
const url = guardedRead(() => displayUntrusted(h.url));
|
|
933
|
+
const title = guardedRead(() => displayUntrusted(h.title));
|
|
934
|
+
if (url === undefined || url === '' || title === undefined)
|
|
935
|
+
dropped++;
|
|
936
|
+
else
|
|
937
|
+
out.push(Object.freeze({ title, url }));
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
if (out.length === 0 && dropped > 0)
|
|
941
|
+
return undefined;
|
|
942
|
+
Object.defineProperty(out, 'droppedCount', { value: dropped, enumerable: false });
|
|
943
|
+
return Object.freeze(out);
|
|
944
|
+
}
|
|
945
|
+
catch {
|
|
946
|
+
return undefined;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
function terminalCardCompletionIdOf(s, engineSaidNotReady) {
|
|
950
|
+
if (engineSaidNotReady)
|
|
951
|
+
return undefined;
|
|
952
|
+
const status = guardedRead(() => readOwnDataNonEmptyString(s, 'status'));
|
|
953
|
+
if (!isCoreSemaTaskTerminal(status))
|
|
954
|
+
return undefined;
|
|
955
|
+
return guardedRead(() => readOwnDataNonEmptyString(s, 'completionId'));
|
|
956
|
+
}
|
|
957
|
+
export function detectEngineBgShellReceipt(toolName, rawInput, outputText, structured, toolUseId) {
|
|
813
958
|
if (typeof outputText !== 'string')
|
|
814
959
|
return null;
|
|
815
960
|
const input = (rawInput ?? {});
|
|
@@ -832,28 +977,30 @@ export function detectEngineBgShellReceipt(toolName, rawInput, outputText, struc
|
|
|
832
977
|
}
|
|
833
978
|
if (!m?.[1])
|
|
834
979
|
return null;
|
|
835
|
-
return engineBgShellRegistrationBody(m[1], input, outputText, source);
|
|
980
|
+
return engineBgShellRegistrationBody(m[1], input, outputText, source, toolUseId, undefined);
|
|
836
981
|
}
|
|
837
|
-
function engineBgShellRegistrationBody(taskId, rawInput, receipt, source) {
|
|
982
|
+
function engineBgShellRegistrationBody(taskId, rawInput, receipt, source, toolUseId, outputFile) {
|
|
838
983
|
const input = (rawInput ?? {});
|
|
839
984
|
const command = typeof input.command === 'string' ? input.command : '(engine bash)';
|
|
840
985
|
const description = typeof input.description === 'string' ? input.description : undefined;
|
|
841
986
|
return {
|
|
842
987
|
kind: 'register',
|
|
843
988
|
taskId,
|
|
989
|
+
...(typeof toolUseId === 'string' && toolUseId.length > 0 ? { toolUseId } : {}),
|
|
844
990
|
command,
|
|
845
991
|
...(description !== undefined ? { description } : {}),
|
|
846
992
|
receipt,
|
|
993
|
+
...(typeof outputFile === 'string' && outputFile.length > 0 ? { outputFile } : {}),
|
|
847
994
|
source,
|
|
848
995
|
};
|
|
849
996
|
}
|
|
850
|
-
export function detectEngineBgShellDetach(toolName, rawInput, structured, outputText) {
|
|
997
|
+
export function detectEngineBgShellDetach(toolName, rawInput, structured, outputText, toolUseId) {
|
|
851
998
|
if (toolName !== 'Bash')
|
|
852
999
|
return null;
|
|
853
1000
|
const view = readBashDetachView(structured);
|
|
854
1001
|
if (view === null || view.registerFailed || view.handoffTaskId === undefined)
|
|
855
1002
|
return null;
|
|
856
|
-
return engineBgShellRegistrationBody(view.handoffTaskId, rawInput, typeof outputText === 'string' ? outputText : '', 'bash');
|
|
1003
|
+
return engineBgShellRegistrationBody(view.handoffTaskId, rawInput, typeof outputText === 'string' ? outputText : '', 'bash', toolUseId, view.outputFile);
|
|
857
1004
|
}
|
|
858
1005
|
function readBashDetachView(structured) {
|
|
859
1006
|
if (typeof structured !== 'object' || structured === null)
|
|
@@ -865,9 +1012,11 @@ function readBashDetachView(structured) {
|
|
|
865
1012
|
const detached = s.detached;
|
|
866
1013
|
const registerFailed = s.registerFailed;
|
|
867
1014
|
const taskId = s.task_id;
|
|
1015
|
+
const outputFile = s.output_file;
|
|
868
1016
|
return {
|
|
869
1017
|
handoffTaskId: detached === true && typeof taskId === 'string' && taskId.length > 0 ? taskId : undefined,
|
|
870
1018
|
registerFailed: registerFailed === true,
|
|
1019
|
+
outputFile: typeof outputFile === 'string' && outputFile.length > 0 ? outputFile : undefined,
|
|
871
1020
|
};
|
|
872
1021
|
}
|
|
873
1022
|
export function todoWriteToolUseResult(rawInput, oldTodos, isError) {
|
|
@@ -1,2 +1,15 @@
|
|
|
1
|
+
import type { UiLanguage } from './env/uiLanguage.js';
|
|
2
|
+
export type ToolOutputMediaAbsence = {
|
|
3
|
+
readonly kind: 'descriptor';
|
|
4
|
+
readonly mediaType: 'image' | 'document';
|
|
5
|
+
readonly mimeType?: string;
|
|
6
|
+
readonly bytes: number;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'omitted';
|
|
9
|
+
readonly blocks: number;
|
|
10
|
+
readonly bytes: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function toolOutputMediaAbsenceOf(block: object | null | undefined): ToolOutputMediaAbsence | undefined;
|
|
13
|
+
export declare function toolOutputMediaAbsenceSentence(view: ToolOutputMediaAbsence | null | undefined, lang?: UiLanguage): string;
|
|
1
14
|
export declare function toolResultBlocksOf(output: unknown, truncated: boolean): unknown[] | undefined;
|
|
2
15
|
export declare function toolEndOutputText(output: unknown): string | undefined;
|
|
@@ -1,12 +1,78 @@
|
|
|
1
|
+
import { msg, renderMessage } from './i18n/translate.js';
|
|
2
|
+
import { readOwnDataValue } from './ownKey.js';
|
|
1
3
|
const IMAGE_MEDIA_TYPES = Object.freeze(['image/jpeg', 'image/png', 'image/gif', 'image/webp']);
|
|
2
4
|
const OMITTED_CONTENT_NOTE = '[unsupported content omitted]';
|
|
3
5
|
const IMAGE_TEXT_PLACEHOLDER = '[image]';
|
|
6
|
+
const ECHOABLE_MIME_TYPE = /^[\x21-\x7e][\x20-\x7e]{0,254}$/;
|
|
7
|
+
function countOf(v, min) {
|
|
8
|
+
return typeof v === 'number' && Number.isSafeInteger(v) && v >= min ? (v === 0 ? 0 : v) : undefined;
|
|
9
|
+
}
|
|
10
|
+
function mimeTypeSlot(o) {
|
|
11
|
+
return Object.hasOwn(o, 'mimeType') ? (readOwnDataValue(o, 'mimeType') ?? null) : undefined;
|
|
12
|
+
}
|
|
13
|
+
function mintAbsence(kind, mediaType, mimeType, blocks, bytes) {
|
|
14
|
+
const size = countOf(bytes, 0);
|
|
15
|
+
if (size === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (kind === 'omitted') {
|
|
18
|
+
const n = countOf(blocks, 1);
|
|
19
|
+
return n === undefined ? undefined : Object.freeze({ kind: 'omitted', blocks: n, bytes: size });
|
|
20
|
+
}
|
|
21
|
+
if (kind !== 'descriptor' || (mediaType !== 'image' && mediaType !== 'document'))
|
|
22
|
+
return undefined;
|
|
23
|
+
if (mimeType !== undefined && typeof mimeType !== 'string')
|
|
24
|
+
return undefined;
|
|
25
|
+
return Object.freeze(typeof mimeType === 'string' && ECHOABLE_MIME_TYPE.test(mimeType) ? { kind, mediaType, mimeType, bytes: size } : { kind, mediaType, bytes: size });
|
|
26
|
+
}
|
|
27
|
+
export function toolOutputMediaAbsenceOf(block) {
|
|
28
|
+
try {
|
|
29
|
+
if (typeof block !== 'object' || block === null || Array.isArray(block))
|
|
30
|
+
return undefined;
|
|
31
|
+
if (readOwnDataValue(block, 'truncated') !== true)
|
|
32
|
+
return undefined;
|
|
33
|
+
const type = readOwnDataValue(block, 'type');
|
|
34
|
+
const bytes = readOwnDataValue(block, 'bytes');
|
|
35
|
+
if (type === 'omitted')
|
|
36
|
+
return mintAbsence('omitted', undefined, undefined, readOwnDataValue(block, 'blocks'), bytes);
|
|
37
|
+
if (type !== 'image' && type !== 'document')
|
|
38
|
+
return undefined;
|
|
39
|
+
if ('data' in block)
|
|
40
|
+
return undefined;
|
|
41
|
+
return mintAbsence('descriptor', type, mimeTypeSlot(block), undefined, bytes);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function absenceRefOf(a) {
|
|
48
|
+
if (a.kind === 'omitted') {
|
|
49
|
+
return msg(a.blocks === 1 ? 'session.toolResult.media.notDelivered.omitted.one' : 'session.toolResult.media.notDelivered.omitted.other', { blocks: a.blocks, bytes: a.bytes });
|
|
50
|
+
}
|
|
51
|
+
const kind = msg(a.mediaType === 'image' ? 'session.toolResult.media.kind.image' : 'session.toolResult.media.kind.document');
|
|
52
|
+
return a.mimeType === undefined
|
|
53
|
+
? msg('session.toolResult.media.notDelivered.descriptorNoMime', { kind, bytes: a.bytes })
|
|
54
|
+
: msg('session.toolResult.media.notDelivered.descriptor', { kind, mimeType: a.mimeType, bytes: a.bytes });
|
|
55
|
+
}
|
|
56
|
+
export function toolOutputMediaAbsenceSentence(view, lang) {
|
|
57
|
+
try {
|
|
58
|
+
if (typeof view !== 'object' || view === null || Array.isArray(view))
|
|
59
|
+
return '';
|
|
60
|
+
const a = mintAbsence(readOwnDataValue(view, 'kind'), readOwnDataValue(view, 'mediaType'), mimeTypeSlot(view), readOwnDataValue(view, 'blocks'), readOwnDataValue(view, 'bytes'));
|
|
61
|
+
return a === undefined ? '' : renderMessage(absenceRefOf(a), lang);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
4
67
|
function blockOf(raw) {
|
|
5
68
|
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
|
6
69
|
return null;
|
|
7
70
|
const b = raw;
|
|
8
71
|
if (b.type === 'text')
|
|
9
|
-
return typeof b.text === 'string' ? { type: 'text', text: b.text } : null;
|
|
72
|
+
return typeof b.text === 'string' ? { block: { type: 'text', text: b.text }, undelivered: false } : null;
|
|
73
|
+
const absence = toolOutputMediaAbsenceOf(b);
|
|
74
|
+
if (absence !== undefined)
|
|
75
|
+
return { block: { type: 'text', text: renderMessage(absenceRefOf(absence)) }, undelivered: true };
|
|
10
76
|
if (b.type !== 'image')
|
|
11
77
|
return null;
|
|
12
78
|
const data = b.data;
|
|
@@ -15,7 +81,7 @@ function blockOf(raw) {
|
|
|
15
81
|
return null;
|
|
16
82
|
if (typeof mediaType !== 'string' || !IMAGE_MEDIA_TYPES.includes(mediaType))
|
|
17
83
|
return null;
|
|
18
|
-
return { type: 'image', source: { type: 'base64', media_type: mediaType, data } };
|
|
84
|
+
return { block: { type: 'image', source: { type: 'base64', media_type: mediaType, data } }, undelivered: false };
|
|
19
85
|
}
|
|
20
86
|
const TRUNCATED_NOTE = '…(truncated)';
|
|
21
87
|
function toolResultContentOf(output) {
|
|
@@ -26,17 +92,26 @@ function toolResultContentOf(output) {
|
|
|
26
92
|
const blocks = [];
|
|
27
93
|
let omitted = 0;
|
|
28
94
|
let images = 0;
|
|
95
|
+
let undelivered = 0;
|
|
29
96
|
for (const raw of output) {
|
|
30
|
-
|
|
31
|
-
|
|
97
|
+
let read = null;
|
|
98
|
+
try {
|
|
99
|
+
read = blockOf(raw);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
read = null;
|
|
103
|
+
}
|
|
104
|
+
if (read === null)
|
|
32
105
|
omitted++;
|
|
33
106
|
else {
|
|
34
|
-
if (block.type === 'image')
|
|
107
|
+
if (read.block.type === 'image')
|
|
35
108
|
images++;
|
|
36
|
-
|
|
109
|
+
if (read.undelivered)
|
|
110
|
+
undelivered++;
|
|
111
|
+
blocks.push(read.block);
|
|
37
112
|
}
|
|
38
113
|
}
|
|
39
|
-
if (images === 0 && omitted === 0)
|
|
114
|
+
if (images === 0 && omitted === 0 && undelivered === 0)
|
|
40
115
|
return blocks.map((b) => b.text).join('');
|
|
41
116
|
if (omitted > 0)
|
|
42
117
|
blocks.push({ type: 'text', text: OMITTED_CONTENT_NOTE });
|
package/dist/toolRoster.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ export declare function handsMountedDetail(reading: HandsMountedReading, lang?:
|
|
|
83
83
|
export declare function toolRosterNames(roster: ToolRosterView | undefined): readonly string[];
|
|
84
84
|
export interface ToolShim {
|
|
85
85
|
name: string;
|
|
86
|
+
aliases?: readonly string[];
|
|
86
87
|
source: string;
|
|
87
88
|
family?: string;
|
|
88
89
|
userFacingName?: string;
|
|
@@ -97,6 +98,23 @@ export interface ToolShim {
|
|
|
97
98
|
capabilityId?: string;
|
|
98
99
|
}
|
|
99
100
|
export declare function toolShimFromRoster(entry: unknown): ToolShim | undefined;
|
|
101
|
+
export interface EngineRosterPeerTool {
|
|
102
|
+
name: string;
|
|
103
|
+
aliases?: readonly string[];
|
|
104
|
+
cardId?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface EngineRosterPeerGroup {
|
|
107
|
+
peer: string;
|
|
108
|
+
declaredBy?: readonly string[];
|
|
109
|
+
tools: readonly EngineRosterPeerTool[];
|
|
110
|
+
count: number;
|
|
111
|
+
}
|
|
112
|
+
export interface EngineRosterPeersView {
|
|
113
|
+
groups: readonly EngineRosterPeerGroup[];
|
|
114
|
+
unattributed: readonly EngineRosterPeerTool[];
|
|
115
|
+
}
|
|
116
|
+
export declare function projectEngineRosterPeers(roster: ToolRosterView | undefined, source: string): EngineRosterPeersView | undefined;
|
|
117
|
+
export declare function projectEngineA2aPeers(roster: ToolRosterView | undefined): EngineRosterPeersView | undefined;
|
|
100
118
|
export interface ToolRosterDeltaApplication {
|
|
101
119
|
roster: ToolRosterView | undefined;
|
|
102
120
|
applied: boolean;
|
package/dist/toolRoster.js
CHANGED
|
@@ -205,6 +205,7 @@ export function toolShimFromRoster(entry) {
|
|
|
205
205
|
return {
|
|
206
206
|
name: e.name,
|
|
207
207
|
source: e.source,
|
|
208
|
+
...(e.aliases !== undefined ? { aliases: copyStrings(e.aliases) } : {}),
|
|
208
209
|
...(e.family !== undefined ? { family: e.family } : {}),
|
|
209
210
|
...(e.renderHints?.userFacingName !== undefined ? { userFacingName: e.renderHints.userFacingName } : {}),
|
|
210
211
|
...(e.renderHints?.activity !== undefined ? { activity: e.renderHints.activity } : {}),
|
|
@@ -218,6 +219,69 @@ export function toolShimFromRoster(entry) {
|
|
|
218
219
|
...(e.capabilityId !== undefined ? { capabilityId: e.capabilityId } : {}),
|
|
219
220
|
};
|
|
220
221
|
}
|
|
222
|
+
const compareCodeUnits = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
223
|
+
function copyStrings(src) {
|
|
224
|
+
const out = [];
|
|
225
|
+
const n = src.length;
|
|
226
|
+
for (let i = 0; i < n; i++) {
|
|
227
|
+
const v = src[i];
|
|
228
|
+
if (typeof v === 'string')
|
|
229
|
+
out.push(v);
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
function rosterPeerToolOf(e) {
|
|
234
|
+
return {
|
|
235
|
+
name: e.name,
|
|
236
|
+
...(e.aliases !== undefined ? { aliases: copyStrings(e.aliases) } : {}),
|
|
237
|
+
...(e.cardId !== undefined ? { cardId: e.cardId } : {}),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
export function projectEngineRosterPeers(roster, source) {
|
|
241
|
+
if (typeof roster !== 'object' || roster === null)
|
|
242
|
+
return undefined;
|
|
243
|
+
if (typeof source !== 'string' || source.length === 0)
|
|
244
|
+
return undefined;
|
|
245
|
+
try {
|
|
246
|
+
const view = readRoster(roster);
|
|
247
|
+
if (view === undefined || view.entries.length !== view.count)
|
|
248
|
+
return undefined;
|
|
249
|
+
const slots = new Map();
|
|
250
|
+
const unattributed = [];
|
|
251
|
+
for (const e of view.entries) {
|
|
252
|
+
if (e.source !== source)
|
|
253
|
+
continue;
|
|
254
|
+
const peer = e.origin?.peer;
|
|
255
|
+
if (peer === undefined) {
|
|
256
|
+
unattributed.push(rosterPeerToolOf(e));
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
let slot = slots.get(peer);
|
|
260
|
+
if (slot === undefined) {
|
|
261
|
+
slot = { tools: [], declaredBy: new Set() };
|
|
262
|
+
slots.set(peer, slot);
|
|
263
|
+
}
|
|
264
|
+
slot.tools.push(rosterPeerToolOf(e));
|
|
265
|
+
if (e.origin?.declaredBy !== undefined)
|
|
266
|
+
slot.declaredBy.add(e.origin.declaredBy);
|
|
267
|
+
}
|
|
268
|
+
const groups = [...slots.entries()]
|
|
269
|
+
.sort((a, b) => compareCodeUnits(a[0], b[0]))
|
|
270
|
+
.map(([peer, slot]) => ({
|
|
271
|
+
peer,
|
|
272
|
+
...(slot.declaredBy.size > 0 ? { declaredBy: [...slot.declaredBy].sort(compareCodeUnits) } : {}),
|
|
273
|
+
tools: slot.tools,
|
|
274
|
+
count: slot.tools.length,
|
|
275
|
+
}));
|
|
276
|
+
return { groups, unattributed };
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
export function projectEngineA2aPeers(roster) {
|
|
283
|
+
return projectEngineRosterPeers(roster, 'a2a');
|
|
284
|
+
}
|
|
221
285
|
function readSummary(raw) {
|
|
222
286
|
const o = obj(raw);
|
|
223
287
|
if (o === undefined)
|