@oscharko-dev/keiko 1.1.11 → 1.1.12
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/dist/ui/csp-hashes.json +7 -7
- package/dist/ui/static/404.html +1 -1
- package/dist/ui/static/__next.__PAGE__.txt +1 -1
- package/dist/ui/static/__next._full.txt +1 -1
- package/dist/ui/static/__next._tree.txt +1 -1
- package/dist/ui/static/_not-found/__next._full.txt +1 -1
- package/dist/ui/static/_not-found/__next._not-found.__PAGE__.txt +1 -1
- package/dist/ui/static/_not-found/__next._tree.txt +1 -1
- package/dist/ui/static/_not-found.html +1 -1
- package/dist/ui/static/_not-found.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next._full.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next._tree.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next.atlassian-connectors.__PAGE__.txt +1 -1
- package/dist/ui/static/atlassian-connectors.html +1 -1
- package/dist/ui/static/atlassian-connectors.txt +1 -1
- package/dist/ui/static/index.html +1 -1
- package/dist/ui/static/index.txt +1 -1
- package/dist/ui/static/launch/__next._full.txt +1 -1
- package/dist/ui/static/launch/__next._tree.txt +1 -1
- package/dist/ui/static/launch/__next.launch.__PAGE__.txt +1 -1
- package/dist/ui/static/launch.html +1 -1
- package/dist/ui/static/launch.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._full.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._tree.txt +1 -1
- package/dist/ui/static/local-knowledge/__next.local-knowledge.__PAGE__.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._full.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._tree.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.__PAGE__.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule.html +1 -1
- package/dist/ui/static/local-knowledge/capsule.txt +1 -1
- package/dist/ui/static/local-knowledge.html +1 -1
- package/dist/ui/static/local-knowledge.txt +1 -1
- package/node_modules/@oscharko-dev/keiko-activity-log/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-cli/package.json +15 -15
- package/node_modules/@oscharko-dev/keiko-connectors/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-connectors/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-connectors/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-failure-class-contracts.d.ts +45 -5
- package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-failure-class-contracts.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-failure-class-contracts.js +86 -5
- package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-registry.generated.d.ts +811 -5
- package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-registry.generated.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-registry.generated.js +921 -5
- package/node_modules/@oscharko-dev/keiko-contracts/dist/context-engineering.js +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/version.d.ts +2 -2
- package/node_modules/@oscharko-dev/keiko-contracts/dist/version.js +2 -2
- package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-evaluations/package.json +9 -9
- package/node_modules/@oscharko-dev/keiko-evidence/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/package.json +4 -4
- package/node_modules/@oscharko-dev/keiko-git/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-git/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-git/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/package.json +7 -7
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/config.js +6 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway-prompt-admission.d.ts +34 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway-prompt-admission.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway-prompt-admission.js +165 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.d.ts +4 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.js +85 -42
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.d.ts +23 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.js +27 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/prompt-admission.d.ts +7 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/prompt-admission.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/prompt-admission.js +151 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/prompt-token-accounting.d.ts +12 -4
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/prompt-token-accounting.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/prompt-token-accounting.js +42 -9
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/provider-token-counter.d.ts +13 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/provider-token-counter.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/provider-token-counter.js +121 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/toolCatalogBridge.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/toolCatalogBridge.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/toolCatalogBridge.js +13 -12
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/types.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +4 -4
- package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-sandbox/package.json +2 -2
- package/node_modules/@oscharko-dev/keiko-sdk/package.json +9 -9
- package/node_modules/@oscharko-dev/keiko-security/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-security/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-security/package.json +2 -2
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-activity.d.ts +3 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-activity.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-activity.js +57 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-handlers.js +29 -29
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-prompt-budget-token-summary.d.ts +6 -12
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-prompt-budget-token-summary.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-prompt-budget-token-summary.js +42 -64
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-prompt-budget.d.ts +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-prompt-budget.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-prompt-budget.js +16 -10
- package/node_modules/@oscharko-dev/keiko-server/dist/chat-stream-handlers.js +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/conversation-compaction.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/conversation-compaction.js +37 -24
- package/node_modules/@oscharko-dev/keiko-server/dist/conversation-gateway.d.ts +3 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/conversation-gateway.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/conversation-gateway.js +14 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts +3 -2
- package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-discovery-log.d.ts +11 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-discovery-log.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-discovery-log.js +49 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.js +138 -27
- package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitDraftQuality.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/gitDelivery/commitDraftQuality.js +2 -5
- package/node_modules/@oscharko-dev/keiko-server/dist/process-log-sink.d.ts +4 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/process-log-sink.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/process-log-sink.js +3 -29
- package/node_modules/@oscharko-dev/keiko-server/package.json +23 -23
- package/node_modules/@oscharko-dev/keiko-tool-catalog/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-tools/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/package.json +7 -7
- package/node_modules/@oscharko-dev/keiko-verification/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-workflows/package.json +10 -10
- package/node_modules/@oscharko-dev/keiko-workspace/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/package.json +3 -3
- package/package.json +27 -27
- package/release-impact.catalog.json +62 -0
- package/vendor/{oscharko-dev-keiko-activity-log-1.1.11.tgz → oscharko-dev-keiko-activity-log-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-cli-1.1.11.tgz → oscharko-dev-keiko-cli-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-connectors-1.1.11.tgz → oscharko-dev-keiko-connectors-1.1.12.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-contracts-1.1.12.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-evaluations-1.1.11.tgz → oscharko-dev-keiko-evaluations-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-evidence-1.1.11.tgz → oscharko-dev-keiko-evidence-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-git-1.1.11.tgz → oscharko-dev-keiko-git-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-harness-1.1.11.tgz → oscharko-dev-keiko-harness-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-local-knowledge-1.1.11.tgz → oscharko-dev-keiko-local-knowledge-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-capture-1.1.11.tgz → oscharko-dev-keiko-memory-capture-1.1.12.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-memory-consolidation-1.1.12.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-memory-governance-1.1.11.tgz → oscharko-dev-keiko-memory-governance-1.1.12.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-memory-retrieval-1.1.12.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-memory-vault-1.1.11.tgz → oscharko-dev-keiko-memory-vault-1.1.12.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-model-gateway-1.1.12.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-quality-intelligence-1.1.11.tgz → oscharko-dev-keiko-quality-intelligence-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-sandbox-1.1.11.tgz → oscharko-dev-keiko-sandbox-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-sdk-1.1.11.tgz → oscharko-dev-keiko-sdk-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-security-1.1.11.tgz → oscharko-dev-keiko-security-1.1.12.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-server-1.1.12.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-tool-catalog-1.1.11.tgz → oscharko-dev-keiko-tool-catalog-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-tools-1.1.11.tgz → oscharko-dev-keiko-tools-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-verification-1.1.11.tgz → oscharko-dev-keiko-verification-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-workflows-1.1.11.tgz → oscharko-dev-keiko-workflows-1.1.12.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-workspace-1.1.11.tgz → oscharko-dev-keiko-workspace-1.1.12.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-contracts-1.1.11.tgz +0 -0
- package/vendor/oscharko-dev-keiko-memory-consolidation-1.1.11.tgz +0 -0
- package/vendor/oscharko-dev-keiko-memory-retrieval-1.1.11.tgz +0 -0
- package/vendor/oscharko-dev-keiko-model-gateway-1.1.11.tgz +0 -0
- package/vendor/oscharko-dev-keiko-server-1.1.11.tgz +0 -0
- /package/dist/ui/static/_next/static/{GX41Kg0XC2e1CF4PEQCfA → __kGQcCW6ht5xSodXZZBj}/_buildManifest.js +0 -0
- /package/dist/ui/static/_next/static/{GX41Kg0XC2e1CF4PEQCfA → __kGQcCW6ht5xSodXZZBj}/_clientMiddlewareManifest.js +0 -0
- /package/dist/ui/static/_next/static/{GX41Kg0XC2e1CF4PEQCfA → __kGQcCW6ht5xSodXZZBj}/_ssgManifest.js +0 -0
|
@@ -52,7 +52,7 @@ import { recordMemoryAudit } from "./memory-audit-handler.js";
|
|
|
52
52
|
import { recordAutoAcceptedMemoryCaptureDecision } from "./memory-capture-audit.js";
|
|
53
53
|
import { scheduleMemorySalienceCapture } from "./memory-salience.js";
|
|
54
54
|
import { UNKNOWN_CORRELATION_ID } from "./correlation.js";
|
|
55
|
-
import { logChatCreationRejectionEvent, logChatRejectionEvent, logChatTurnStartedEvent, logChatResponse, logGitChangeApply, logGitChangeDescriptionTargetDenied, logGitChangeTurnAuthorityEvent, } from "./chat-activity.js";
|
|
55
|
+
import { logChatCreationRejectionEvent, logChatRejectionEvent, logChatTurnStartedEvent, logChatContextSelection, logChatResponse, logGitChangeApply, logGitChangeDescriptionTargetDenied, logGitChangeTurnAuthorityEvent, } from "./chat-activity.js";
|
|
56
56
|
// #3557 review finding A: the one owning projection from a candidate model id to Activity Log
|
|
57
57
|
// evidence. `chatCapability` below delegates its resolution here too, so the "is this configured"
|
|
58
58
|
// answer a 400 response relies on and the answer the log line relies on can never drift apart.
|
|
@@ -68,7 +68,7 @@ import { createRequestCancellation } from "./request-cancellation.js";
|
|
|
68
68
|
import { readBoundedRequestBody, RequestBodyCancelledError, RequestBodyTooLargeError, } from "./bounded-request-body.js";
|
|
69
69
|
import { userFacingProjects } from "./workspace-root-membership.js";
|
|
70
70
|
import { buildChatCompactionContextText, selectGatewayPromptAssembly, } from "./chat-prompt-budget.js";
|
|
71
|
-
import { MAX_CONTEXT_MESSAGES, usableGatewayMessages } from "./conversation-gateway.js";
|
|
71
|
+
import { MAX_CONTEXT_MESSAGES, usableGatewayMessages, withGatewayConversationImages, } from "./conversation-gateway.js";
|
|
72
72
|
import { resolveAppSessionReadAuthority } from "./coding-app-session/appSessionReadAuthority.js";
|
|
73
73
|
import { ConversationAttachmentStoreError } from "./conversation-attachment-store.js";
|
|
74
74
|
export { MAX_CONTEXT_MESSAGES, conversationForGateway, usableGatewayMessages, } from "./conversation-gateway.js";
|
|
@@ -1158,7 +1158,14 @@ export function captureGatewayTurnSnapshot(deps, request, userMessage) {
|
|
|
1158
1158
|
currentUserMessageId: userMessage.id,
|
|
1159
1159
|
};
|
|
1160
1160
|
}
|
|
1161
|
-
|
|
1161
|
+
function finalizeGatewayAssembly(selected, request, correlationId) {
|
|
1162
|
+
if (selected === undefined) {
|
|
1163
|
+
throw new ContextOverflowError("conversation prompt exceeds the effective input budget and cannot be assembled without overflow.");
|
|
1164
|
+
}
|
|
1165
|
+
logChatContextSelection(correlationId, selected, request.attachments.filter((attachment) => attachment.kind === "image").length);
|
|
1166
|
+
return selected;
|
|
1167
|
+
}
|
|
1168
|
+
export function buildGatewayAssembly(deps, request, memory, modelId, snapshot, correlationId) {
|
|
1162
1169
|
const currentUserIndex = snapshot.history.findIndex((message) => message.id === snapshot.currentUserMessageId);
|
|
1163
1170
|
if (currentUserIndex < 0) {
|
|
1164
1171
|
throw new UiStoreError("INTERNAL", "Admitted chat turn is missing from its history.", 500);
|
|
@@ -1170,6 +1177,7 @@ export function buildGatewayAssembly(deps, request, memory, modelId, snapshot) {
|
|
|
1170
1177
|
request: {
|
|
1171
1178
|
content: request.content,
|
|
1172
1179
|
discussionMode: request.discussionMode,
|
|
1180
|
+
imageCount: request.attachments.filter((attachment) => attachment.kind === "image").length,
|
|
1173
1181
|
},
|
|
1174
1182
|
profile: currentContextProfileForModel(deps, modelId) ?? DEFAULT_CONTEXT_PROFILE,
|
|
1175
1183
|
memoryEntries: memory.context.memories,
|
|
@@ -1177,10 +1185,7 @@ export function buildGatewayAssembly(deps, request, memory, modelId, snapshot) {
|
|
|
1177
1185
|
documentContext: request.documentContext,
|
|
1178
1186
|
redactionSecrets: currentRedactionSecrets(deps),
|
|
1179
1187
|
});
|
|
1180
|
-
|
|
1181
|
-
throw new ContextOverflowError("conversation prompt exceeds the effective input budget and cannot be assembled without overflow.");
|
|
1182
|
-
}
|
|
1183
|
-
return selected;
|
|
1188
|
+
return finalizeGatewayAssembly(selected, request, correlationId);
|
|
1184
1189
|
}
|
|
1185
1190
|
// ADR-0173 D5 g9 — the INPUT shape of a chat turn, never its content: how many messages the
|
|
1186
1191
|
// assembled prompt carries (split by role) and how many image attachments rode along (count +
|
|
@@ -1269,7 +1274,7 @@ function logCompactionSummaryFailure(deps, correlationId, error) {
|
|
|
1269
1274
|
redact: (message) => String(deps.redactor(message)),
|
|
1270
1275
|
}));
|
|
1271
1276
|
}
|
|
1272
|
-
function buildRegenerateGatewayAssembly(deps, request, memory, modelId, historyBeforeAssistant) {
|
|
1277
|
+
function buildRegenerateGatewayAssembly(deps, request, memory, modelId, historyBeforeAssistant, correlationId) {
|
|
1273
1278
|
let latestUserIndex = -1;
|
|
1274
1279
|
for (let index = historyBeforeAssistant.length - 1; index >= 0; index -= 1) {
|
|
1275
1280
|
if (historyBeforeAssistant[index]?.role === "user") {
|
|
@@ -1284,6 +1289,7 @@ function buildRegenerateGatewayAssembly(deps, request, memory, modelId, historyB
|
|
|
1284
1289
|
request: {
|
|
1285
1290
|
content: request.content,
|
|
1286
1291
|
discussionMode: request.discussionMode,
|
|
1292
|
+
imageCount: request.attachments.filter((attachment) => attachment.kind === "image").length,
|
|
1287
1293
|
},
|
|
1288
1294
|
profile: currentContextProfileForModel(deps, modelId) ?? DEFAULT_CONTEXT_PROFILE,
|
|
1289
1295
|
memoryEntries: memory.context.memories,
|
|
@@ -1291,10 +1297,7 @@ function buildRegenerateGatewayAssembly(deps, request, memory, modelId, historyB
|
|
|
1291
1297
|
documentContext: request.documentContext,
|
|
1292
1298
|
redactionSecrets: currentRedactionSecrets(deps),
|
|
1293
1299
|
});
|
|
1294
|
-
|
|
1295
|
-
throw new ContextOverflowError("conversation prompt exceeds the effective input budget and cannot be assembled without overflow.");
|
|
1296
|
-
}
|
|
1297
|
-
return selected;
|
|
1300
|
+
return finalizeGatewayAssembly(selected, request, correlationId);
|
|
1298
1301
|
}
|
|
1299
1302
|
function latestRegenerableTurn(messages, assistantMessageId) {
|
|
1300
1303
|
const targetIndex = messages.findIndex((message) => message.id === assistantMessageId);
|
|
@@ -1450,6 +1453,15 @@ async function persistModelChatTurn(deps, prepared, abortSignal, correlationId)
|
|
|
1450
1453
|
: desktopChatErrorResult(error, deps, correlationId);
|
|
1451
1454
|
}
|
|
1452
1455
|
}
|
|
1456
|
+
function buildBufferedGatewayAssembly(deps, request, memory, modelId, gatewayTurn, correlationId) {
|
|
1457
|
+
const baseAssembly = buildGatewayAssembly(deps, request, memory, modelId, gatewayTurn, correlationId);
|
|
1458
|
+
// Logged from the base assembly, BEFORE image content parts are spliced in: image delivery can
|
|
1459
|
+
// still fail its own (unrelated) authority/session check below, and this shape evidence must
|
|
1460
|
+
// exist either way. Splicing only augments the final message's contentParts, never message
|
|
1461
|
+
// count or role — so the counted shape is identical from either assembly.
|
|
1462
|
+
logChatTurnStarted(correlationId, baseAssembly.messages, request.attachments);
|
|
1463
|
+
return assemblyWithConversationImages(deps, request, modelId, baseAssembly);
|
|
1464
|
+
}
|
|
1453
1465
|
async function executeBufferedModelTurn(deps, prepared, abortSignal, messageCountBeforeTurn, startedAt, correlationId) {
|
|
1454
1466
|
const { request, modelId } = prepared;
|
|
1455
1467
|
const outcome = admitBufferedModelTurn(deps, prepared, correlationId);
|
|
@@ -1461,13 +1473,7 @@ async function executeBufferedModelTurn(deps, prepared, abortSignal, messageCoun
|
|
|
1461
1473
|
const memory = await resolveBufferedMemory(deps, prepared, admitted, abortSignal, correlationId);
|
|
1462
1474
|
if (isRouteResult(memory))
|
|
1463
1475
|
return memory;
|
|
1464
|
-
const
|
|
1465
|
-
// Logged from the base assembly, BEFORE image content parts are spliced in: image delivery can
|
|
1466
|
-
// still fail its own (unrelated) authority/session check below, and this shape evidence must
|
|
1467
|
-
// exist either way. Splicing only augments the final message's contentParts, never message
|
|
1468
|
-
// count or role — so the counted shape is identical from either assembly.
|
|
1469
|
-
logChatTurnStarted(correlationId, baseAssembly.messages, request.attachments);
|
|
1470
|
-
const assembly = assemblyWithConversationImages(deps, request, modelId, baseAssembly);
|
|
1476
|
+
const assembly = buildBufferedGatewayAssembly(deps, request, memory, modelId, gatewayTurn, correlationId);
|
|
1471
1477
|
const model = bufferedModelAtProviderBoundary(deps, modelId, executionAdmission, correlationId);
|
|
1472
1478
|
if (isRouteResult(model)) {
|
|
1473
1479
|
settleRejectedDesktopChatTurn(deps, prepared, admitted);
|
|
@@ -2286,13 +2292,7 @@ export function assemblyWithConversationImages(deps, request, modelId, assembly)
|
|
|
2286
2292
|
const imageParts = conversationImageParts(deps, request, modelId);
|
|
2287
2293
|
if (imageParts.length === 0)
|
|
2288
2294
|
return assembly;
|
|
2289
|
-
const
|
|
2290
|
-
const messages = assembly.messages.map((message, index) => index === lastIndex
|
|
2291
|
-
? {
|
|
2292
|
-
...message,
|
|
2293
|
-
contentParts: [{ type: "text", text: message.content }, ...imageParts],
|
|
2294
|
-
}
|
|
2295
|
-
: message);
|
|
2295
|
+
const messages = withGatewayConversationImages(assembly.messages, imageParts);
|
|
2296
2296
|
return { ...assembly, messages };
|
|
2297
2297
|
}
|
|
2298
2298
|
export function conversationImageDeliveries(request) {
|
|
@@ -2409,12 +2409,12 @@ function invalidRegenerationModelResult(modelId, deps, correlationId) {
|
|
|
2409
2409
|
function captureGatewayGeneration(deps) {
|
|
2410
2410
|
return { gatewayConfigGeneration: deps.gatewayConfig?.generation() };
|
|
2411
2411
|
}
|
|
2412
|
-
async function
|
|
2412
|
+
async function buildRegenerateContext(deps, prepared, correlationId) {
|
|
2413
2413
|
const { modelId, turn, memoryRequest, memoryContext } = prepared;
|
|
2414
2414
|
const memory = memoryContext === undefined
|
|
2415
2415
|
? emptyMemoryResult(false)
|
|
2416
2416
|
: await buildMemoryResult(memoryRequest, deps, memoryContext);
|
|
2417
|
-
const assembly = buildRegenerateGatewayAssembly(deps, memoryRequest, memory, modelId, turn.beforeAssistant);
|
|
2417
|
+
const assembly = buildRegenerateGatewayAssembly(deps, memoryRequest, memory, modelId, turn.beforeAssistant, correlationId);
|
|
2418
2418
|
return { memory, messages: assembly.messages };
|
|
2419
2419
|
}
|
|
2420
2420
|
function validateRegenerateCommit(deps, prepared) {
|
|
@@ -2433,7 +2433,7 @@ function validateRegenerateCommit(deps, prepared) {
|
|
|
2433
2433
|
async function persistRegeneratedChatTurn(deps, prepared, signal, correlationId) {
|
|
2434
2434
|
const { chat, modelId, memoryRequest, executionAdmission } = prepared;
|
|
2435
2435
|
try {
|
|
2436
|
-
const { memory, messages } = await
|
|
2436
|
+
const { memory, messages } = await buildRegenerateContext(deps, prepared, correlationId);
|
|
2437
2437
|
if (requestSignalAborted(signal))
|
|
2438
2438
|
return requestCancelledResult();
|
|
2439
2439
|
const model = bufferedModelAtProviderBoundary(deps, modelId, executionAdmission, correlationId, "chat.regeneration.rejected");
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import type { ContextProfile, ContextTokenAccounting, ConversationDocumentContextWire, DiscussionMode } from "@oscharko-dev/keiko-contracts";
|
|
2
2
|
import type { ConversationMemoryContextEntryWire } from "@oscharko-dev/keiko-contracts/bff-wire";
|
|
3
|
-
import type
|
|
3
|
+
import { type GatewayConversationMessage } from "./conversation-gateway.js";
|
|
4
4
|
import type { ConversationCompactionOutcome } from "./conversation-compaction.js";
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function renderMemoryContextText(memories: readonly ConversationMemoryContextEntryWire[], compactionContextText: string | undefined): string | undefined;
|
|
7
|
-
export declare function renderDocumentContextText(documentContext: readonly ConversationDocumentContextWire[]): string | undefined;
|
|
8
|
-
export declare function estimateUserTaskTokens(input: {
|
|
9
|
-
readonly content: string;
|
|
10
|
-
readonly discussionMode: DiscussionMode | undefined;
|
|
11
|
-
readonly tokenAccounting: ContextTokenAccounting | undefined;
|
|
12
|
-
}): number;
|
|
13
|
-
export declare function estimateFinalPromptTokens(finalMessages: readonly GatewayConversationMessage[], tokenAccounting: ContextTokenAccounting | undefined): number;
|
|
5
|
+
export declare function estimateFinalPromptTokens(finalMessages: readonly GatewayConversationMessage[], tokenAccounting: ContextTokenAccounting | undefined, contextWindow?: number): number;
|
|
14
6
|
export declare function estimateHistoryLaneTokens(input: {
|
|
15
7
|
readonly historyOutcome: ConversationCompactionOutcome;
|
|
16
8
|
readonly systemTokens: number;
|
|
17
9
|
readonly tokenAccounting: ContextTokenAccounting | undefined;
|
|
18
10
|
}): number;
|
|
19
|
-
|
|
11
|
+
interface TokenSummaryInput {
|
|
20
12
|
readonly historyOutcome: ConversationCompactionOutcome;
|
|
21
13
|
readonly memoryEntries: readonly ConversationMemoryContextEntryWire[];
|
|
22
14
|
readonly compactionContextText?: string | undefined;
|
|
@@ -27,7 +19,8 @@ export declare function buildPromptAssemblyTokenSummary(input: {
|
|
|
27
19
|
};
|
|
28
20
|
readonly finalMessages: readonly GatewayConversationMessage[];
|
|
29
21
|
readonly profile: ContextProfile;
|
|
30
|
-
}
|
|
22
|
+
}
|
|
23
|
+
export declare function buildPromptAssemblyTokenSummary(input: TokenSummaryInput): {
|
|
31
24
|
readonly historyTokens: number;
|
|
32
25
|
readonly memoryTokens: number;
|
|
33
26
|
readonly documentTokens: number;
|
|
@@ -35,4 +28,5 @@ export declare function buildPromptAssemblyTokenSummary(input: {
|
|
|
35
28
|
readonly systemTokens: number;
|
|
36
29
|
readonly totalEstimatedTokens: number;
|
|
37
30
|
};
|
|
31
|
+
export {};
|
|
38
32
|
//# sourceMappingURL=chat-prompt-budget-token-summary.d.ts.map
|
package/node_modules/@oscharko-dev/keiko-server/dist/chat-prompt-budget-token-summary.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-prompt-budget-token-summary.d.ts","sourceRoot":"","sources":["../src/chat-prompt-budget-token-summary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,+BAA+B,EAC/B,cAAc,EACf,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-prompt-budget-token-summary.d.ts","sourceRoot":"","sources":["../src/chat-prompt-budget-token-summary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,+BAA+B,EAC/B,cAAc,EACf,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AAEjG,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAElF,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,SAAS,0BAA0B,EAAE,EACpD,eAAe,EAAE,sBAAsB,GAAG,SAAS,EACnD,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,CAER;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,QAAQ,CAAC,cAAc,EAAE,6BAA6B,CAAC;IACvD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,sBAAsB,GAAG,SAAS,CAAC;CAC9D,GAAG,MAAM,CAQT;AAED,UAAU,iBAAiB;IACzB,QAAQ,CAAC,cAAc,EAAE,6BAA6B,CAAC;IACvD,QAAQ,CAAC,aAAa,EAAE,SAAS,kCAAkC,EAAE,CAAC;IACtE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpD,QAAQ,CAAC,eAAe,EAAE,SAAS,+BAA+B,EAAE,CAAC;IACrE,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,CAAC;KACrD,CAAC;IACF,QAAQ,CAAC,aAAa,EAAE,SAAS,0BAA0B,EAAE,CAAC;IAC9D,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;CAClC;AA2DD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,iBAAiB,GAAG;IACzE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;CACvC,CAoBA"}
|
|
@@ -1,75 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { countGatewayPromptTokens } from "@oscharko-dev/keiko-model-gateway/internal/prompt-token-accounting";
|
|
2
|
+
import { CONVERSATION_SYSTEM_PROMPT, composeConversationPrompt } from "./conversation-prompt.js";
|
|
3
|
+
import { withGatewayConversationImages, } from "./conversation-gateway.js";
|
|
4
|
+
export function estimateFinalPromptTokens(finalMessages, tokenAccounting, contextWindow) {
|
|
5
|
+
return countGatewayPromptTokens({ messages: finalMessages }, tokenAccounting, { contextWindow });
|
|
5
6
|
}
|
|
6
|
-
export function renderMemoryContextText(memories, compactionContextText) {
|
|
7
|
-
if (memories.length === 0 && compactionContextText === undefined) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
const lines = [];
|
|
11
|
-
if (memories.length > 0) {
|
|
12
|
-
lines.push("# Relevant memories");
|
|
13
|
-
for (const memory of memories) {
|
|
14
|
-
lines.push(`- (${memory.inclusionReason}) ${memory.bodyExcerpt}`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (compactionContextText !== undefined) {
|
|
18
|
-
if (lines.length > 0) {
|
|
19
|
-
lines.push("");
|
|
20
|
-
}
|
|
21
|
-
lines.push(compactionContextText);
|
|
22
|
-
}
|
|
23
|
-
return lines.join("\n");
|
|
24
|
-
}
|
|
25
|
-
export function renderDocumentContextText(documentContext) {
|
|
26
|
-
if (documentContext.length === 0) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const blocks = documentContext.map(renderConversationDocumentContextBlock);
|
|
30
|
-
return `${CONVERSATION_CONTEXT_BLOCK_HEADER}\n${blocks.join("\n")}`;
|
|
31
|
-
}
|
|
32
|
-
export function estimateUserTaskTokens(input) {
|
|
33
|
-
return countContextTokensForSegments([composeConversationPrompt(input.content, [], undefined, input.discussionMode)], input.tokenAccounting);
|
|
34
|
-
}
|
|
35
|
-
export function estimateFinalPromptTokens(finalMessages, tokenAccounting) {
|
|
36
|
-
return countContextTokensForSegments(finalMessages.map((message) => message.content), tokenAccounting);
|
|
37
|
-
}
|
|
38
|
-
// The compaction summary is physically embedded in the retained system message (see
|
|
39
|
-
// buildSystemScopedCompactionContent in conversation-compaction.ts), but its tokens are
|
|
40
|
-
// deliberately attributed to the history-summary lane rather than system-contract: that lane
|
|
41
|
-
// counts the summary as its "+1" included item and reports the compaction provenance (see
|
|
42
|
-
// buildHistorySummaryLane in chat-prompt-budget-diagnostics.ts), while system-contract
|
|
43
|
-
// intentionally reports only the bare canonical CONVERSATION_SYSTEM_PROMPT tokens. Subtracting
|
|
44
|
-
// systemTokens here keeps each lane's item-count consistent with its token-count and keeps the
|
|
45
|
-
// lane sum equal to totalEstimatedTokens.
|
|
46
7
|
export function estimateHistoryLaneTokens(input) {
|
|
47
|
-
const historyMessageTokens =
|
|
48
|
-
|
|
49
|
-
return systemPromptIsEmbedded
|
|
8
|
+
const historyMessageTokens = estimateFinalPromptTokens(input.historyOutcome.messages, input.tokenAccounting);
|
|
9
|
+
return input.historyOutcome.messages.at(0)?.role === "system"
|
|
50
10
|
? Math.max(0, historyMessageTokens - input.systemTokens)
|
|
51
11
|
: historyMessageTokens;
|
|
52
12
|
}
|
|
13
|
+
function userProjectionTokens(input, includeMemory) {
|
|
14
|
+
const memory = includeMemory && input.memoryEntries.length > 0
|
|
15
|
+
? [
|
|
16
|
+
"# Relevant memories",
|
|
17
|
+
...input.memoryEntries.map((entry) => `- (${entry.inclusionReason}) ${entry.bodyExcerpt}`),
|
|
18
|
+
].join("\n")
|
|
19
|
+
: undefined;
|
|
20
|
+
const content = composeConversationPrompt(input.request.content, [], memory, input.request.discussionMode);
|
|
21
|
+
const images = input.finalMessages.at(-1)?.contentParts?.filter((part) => part.type === "image_url") ?? [];
|
|
22
|
+
return estimateFinalPromptTokens(withGatewayConversationImages([{ role: "user", content }], images), input.profile.tokenAccounting, input.profile.maxInputTokens);
|
|
23
|
+
}
|
|
24
|
+
function currentTurnLaneTokens(input) {
|
|
25
|
+
const current = input.finalMessages.at(-1);
|
|
26
|
+
const total = estimateFinalPromptTokens(current === undefined ? [] : [current], input.profile.tokenAccounting, input.profile.maxInputTokens);
|
|
27
|
+
// Attribute incremental serialization costs in assembly order. Bounds keep lane sums exact even
|
|
28
|
+
// when calibrated token estimates are not additive across the text blocks of one message.
|
|
29
|
+
const latestTurnTokens = Math.min(total, userProjectionTokens(input, false));
|
|
30
|
+
const memoryTokens = Math.min(total - latestTurnTokens, Math.max(0, userProjectionTokens(input, true) - latestTurnTokens));
|
|
31
|
+
const resurfacedTokens = estimateFinalPromptTokens(input.compactionContextText === undefined
|
|
32
|
+
? []
|
|
33
|
+
: [{ role: "system", content: input.compactionContextText }], input.profile.tokenAccounting, input.profile.maxInputTokens);
|
|
34
|
+
return {
|
|
35
|
+
latestTurnTokens,
|
|
36
|
+
memoryTokens: memoryTokens + resurfacedTokens,
|
|
37
|
+
documentTokens: total - latestTurnTokens - memoryTokens,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
53
40
|
export function buildPromptAssemblyTokenSummary(input) {
|
|
54
41
|
const tokenAccounting = input.profile.tokenAccounting;
|
|
55
|
-
const systemTokens =
|
|
56
|
-
const historyTokens = estimateHistoryLaneTokens({
|
|
57
|
-
historyOutcome: input.historyOutcome,
|
|
58
|
-
systemTokens,
|
|
59
|
-
tokenAccounting,
|
|
60
|
-
});
|
|
61
|
-
const memoryTokens = textTokens(renderMemoryContextText(input.memoryEntries, input.compactionContextText), tokenAccounting);
|
|
62
|
-
const documentTokens = textTokens(renderDocumentContextText(input.documentContext), tokenAccounting);
|
|
63
|
-
const latestTurnTokens = estimateUserTaskTokens({
|
|
64
|
-
...input.request,
|
|
65
|
-
tokenAccounting,
|
|
66
|
-
});
|
|
42
|
+
const systemTokens = estimateFinalPromptTokens([{ role: "system", content: CONVERSATION_SYSTEM_PROMPT }], tokenAccounting);
|
|
67
43
|
return {
|
|
68
|
-
historyTokens,
|
|
69
|
-
memoryTokens,
|
|
70
|
-
documentTokens,
|
|
71
|
-
latestTurnTokens,
|
|
72
44
|
systemTokens,
|
|
73
|
-
|
|
45
|
+
historyTokens: estimateHistoryLaneTokens({
|
|
46
|
+
historyOutcome: input.historyOutcome,
|
|
47
|
+
systemTokens,
|
|
48
|
+
tokenAccounting,
|
|
49
|
+
}),
|
|
50
|
+
...currentTurnLaneTokens(input),
|
|
51
|
+
totalEstimatedTokens: estimateFinalPromptTokens(input.finalMessages, tokenAccounting, input.profile.maxInputTokens),
|
|
74
52
|
};
|
|
75
53
|
}
|
|
@@ -22,6 +22,7 @@ export declare function selectGatewayPromptAssembly(input: {
|
|
|
22
22
|
readonly request: {
|
|
23
23
|
readonly content: string;
|
|
24
24
|
readonly discussionMode: DiscussionMode | undefined;
|
|
25
|
+
readonly imageCount?: number;
|
|
25
26
|
};
|
|
26
27
|
readonly profile: ContextProfile;
|
|
27
28
|
readonly memoryEntries: readonly ConversationMemoryContextEntryWire[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-prompt-budget.d.ts","sourceRoot":"","sources":["../src/chat-prompt-budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,cAAc,EACd,+BAA+B,EAC/B,cAAc,EACf,MAAM,+BAA+B,CAAC;AASvC,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-prompt-budget.d.ts","sourceRoot":"","sources":["../src/chat-prompt-budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,cAAc,EACd,+BAA+B,EAC/B,cAAc,EACf,MAAM,+BAA+B,CAAC;AASvC,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAcpD,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,YAAY,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAE5E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,OAAO,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IACpF,QAAQ,CAAC,UAAU,EAAE,6BAA6B,CAAC,YAAY,CAAC,CAAC;IACjE,QAAQ,CAAC,WAAW,EAAE,OAAO,+BAA+B,EAAE,0BAA0B,CAAC;CAC1F;AAqBD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,aAAa,EAAE,SAAS,kCAAkC,EAAE,CAAC;IACtE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpD,QAAQ,CAAC,eAAe,EAAE,SAAS,+BAA+B,EAAE,CAAC;IACrE,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAC;CAClD;AAyPD,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,mBAAmB,GAC7B,SAAS,mBAAmB,EAAE,CAoBhC;AAwGD,wBAAgB,2BAA2B,CAAC,KAAK,EAAE;IACjD,QAAQ,CAAC,aAAa,EAAE,SAAS,WAAW,EAAE,CAAC;IAC/C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,CAAC;QACpD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,SAAS,kCAAkC,EAAE,CAAC;IACtE,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpD,QAAQ,CAAC,eAAe,EAAE,SAAS,+BAA+B,EAAE,CAAC;IACrE,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C,GAAG,qBAAqB,GAAG,SAAS,CAiCpC;AAED,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { countGatewayPromptTokens } from "@oscharko-dev/keiko-model-gateway/internal/prompt-token-accounting";
|
|
2
2
|
import { allocateContext, DEFAULT_CONTEXT_BUDGET, } from "@oscharko-dev/keiko-workflows/context-budget";
|
|
3
3
|
import { ContextOverflowError } from "@oscharko-dev/keiko-security/errors/gateway";
|
|
4
|
-
import { usableGatewayMessages } from "./conversation-gateway.js";
|
|
4
|
+
import { usableGatewayMessages, gatewayConversationImageAccounting, } from "./conversation-gateway.js";
|
|
5
5
|
import { CONVERSATION_CONTEXT_BLOCK_HEADER, CONVERSATION_MEMORY_BLOCK_HEADER, CONVERSATION_SYSTEM_PROMPT, CONVERSATION_USER_BLOCK_HEADER, composeConversationPrompt, renderConversationDocumentContextBlock, } from "./conversation-prompt.js";
|
|
6
6
|
import { composeDiscussionDirectiveBlock } from "./discussion-prompt.js";
|
|
7
7
|
import { conversationForGatewayWithCompaction, } from "./conversation-compaction.js";
|
|
@@ -224,11 +224,14 @@ function compactHistoryForBudget(input, historyBudget) {
|
|
|
224
224
|
function buildLatestUserTurn(input) {
|
|
225
225
|
return composeConversationPrompt(input.request.content, input.documentContext, renderMemoryContextText(input.memoryEntries, undefined), input.request.discussionMode);
|
|
226
226
|
}
|
|
227
|
-
function promptScaffoldTokens(latestTurn, compactionContextText,
|
|
228
|
-
|
|
229
|
-
...systemScopedCompactionContextMessage(compactionContextText)
|
|
230
|
-
latestTurn,
|
|
231
|
-
],
|
|
227
|
+
function promptScaffoldTokens(latestTurn, compactionContextText, profile, imageCount) {
|
|
228
|
+
const messages = gatewayConversationImageAccounting([
|
|
229
|
+
...systemScopedCompactionContextMessage(compactionContextText),
|
|
230
|
+
{ role: "user", content: latestTurn },
|
|
231
|
+
], imageCount);
|
|
232
|
+
return countGatewayPromptTokens({ messages }, profile.tokenAccounting, {
|
|
233
|
+
contextWindow: profile.maxInputTokens,
|
|
234
|
+
});
|
|
232
235
|
}
|
|
233
236
|
function buildPromptMessages(historyOutcome, latestTurn, compactionContextText) {
|
|
234
237
|
return [
|
|
@@ -238,7 +241,7 @@ function buildPromptMessages(historyOutcome, latestTurn, compactionContextText)
|
|
|
238
241
|
}
|
|
239
242
|
function assembleGatewayPromptCandidate(input) {
|
|
240
243
|
const latestTurn = buildLatestUserTurn(input);
|
|
241
|
-
const scaffoldTokens = promptScaffoldTokens(latestTurn, input.compactionContextText, input.profile.
|
|
244
|
+
const scaffoldTokens = promptScaffoldTokens(latestTurn, input.compactionContextText, input.profile, input.request.imageCount);
|
|
242
245
|
if (scaffoldTokens > input.profile.effectiveInputBudget) {
|
|
243
246
|
return undefined;
|
|
244
247
|
}
|
|
@@ -247,7 +250,10 @@ function assembleGatewayPromptCandidate(input) {
|
|
|
247
250
|
if (historyOutcome === undefined)
|
|
248
251
|
return undefined;
|
|
249
252
|
const messages = buildPromptMessages(historyOutcome, latestTurn, input.compactionContextText);
|
|
250
|
-
|
|
253
|
+
const accountedMessages = gatewayConversationImageAccounting(messages, input.request.imageCount);
|
|
254
|
+
if (countGatewayPromptTokens({ messages: accountedMessages }, input.profile.tokenAccounting, {
|
|
255
|
+
contextWindow: input.profile.maxInputTokens,
|
|
256
|
+
}) > input.profile.effectiveInputBudget) {
|
|
251
257
|
return undefined;
|
|
252
258
|
}
|
|
253
259
|
return {
|
|
@@ -263,7 +269,7 @@ function assembleGatewayPromptCandidate(input) {
|
|
|
263
269
|
documentContext: input.documentContext,
|
|
264
270
|
totalDocumentEntries: input.totalDocumentEntries,
|
|
265
271
|
request: input.request,
|
|
266
|
-
finalMessages:
|
|
272
|
+
finalMessages: accountedMessages,
|
|
267
273
|
compactionContextText: input.compactionContextText,
|
|
268
274
|
allocatorDiagnostics: input.allocatorDiagnostics,
|
|
269
275
|
}),
|
|
@@ -179,7 +179,7 @@ async function streamAndPersist(ctx, deps, admitted, controller) {
|
|
|
179
179
|
failCancelledStreamTurn(ctx, deps, request, true);
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
|
-
const assembly = assemblyWithConversationImages(deps, request, modelId, buildGatewayAssembly(deps, request, memory, modelId, gatewayTurn));
|
|
182
|
+
const assembly = assemblyWithConversationImages(deps, request, modelId, buildGatewayAssembly(deps, request, memory, modelId, gatewayTurn, ctx.correlationId));
|
|
183
183
|
const stream = callStream({ modelId, messages: assembly.messages, logContext: { correlationId: ctx.correlationId } }, controller.signal);
|
|
184
184
|
const termination = { backpressure: false };
|
|
185
185
|
const turn = await streamConversation(ctx, deps, stream, controller, termination);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-compaction.d.ts","sourceRoot":"","sources":["../src/conversation-compaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversation-compaction.d.ts","sourceRoot":"","sources":["../src/conversation-compaction.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,uBAAuB,EACvB,cAAc,EAEf,MAAM,+BAA+B,CAAC;AAQvC,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAGL,KAAK,0BAA0B,EAChC,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAC1D,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACnD;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,QAAQ,EAAE,0BAA0B,EAAE,CAAC;IAChD,QAAQ,CAAC,UAAU,CAAC,EAAE,uBAAuB,GAAG,SAAS,CAAC;CAC3D;AAuBD,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,IAAI,GAAE,6BAAkC,GACvC,6BAA6B,CA+B/B;AA4LD,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,gBAAgB,GACvB,SAAS,MAAM,EAAE,CAwCnB"}
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
// ContextCompactionRecord. This function is the deterministic in-prompt safety layer; post-turn
|
|
16
16
|
// model-written enrichment is handled by chat-compaction-model-summary.ts and resurfaced on later
|
|
17
17
|
// turns through chat-compaction-resurfacing.ts.
|
|
18
|
-
import {
|
|
18
|
+
import { countGatewayPromptTokens } from "@oscharko-dev/keiko-model-gateway/internal/prompt-token-accounting";
|
|
19
|
+
import { CONTEXT_ENGINEERING_SCHEMA_VERSION, DEFAULT_CONTEXT_PROFILE, partitionContextPreservedFacts, } from "@oscharko-dev/keiko-contracts/runtime/context-engineering";
|
|
19
20
|
import { validateContextCompactionRecord } from "@oscharko-dev/keiko-contracts/runtime/context-engineering-compaction-validation";
|
|
20
21
|
import { ContextOverflowError } from "@oscharko-dev/keiko-security/errors/gateway";
|
|
21
22
|
import { buildStructuredCompactionDigest, } from "@oscharko-dev/keiko-workflows/context-budget";
|
|
@@ -31,7 +32,7 @@ export function conversationForGatewayWithCompaction(messages, opts = {}) {
|
|
|
31
32
|
const effectiveInputBudget = opts.effectiveInputBudget ?? activeProfile.effectiveInputBudget;
|
|
32
33
|
const tokenAccounting = activeProfile.tokenAccounting;
|
|
33
34
|
const fullVerbatimMessages = buildVerbatimMessages(systemMessage, filtered);
|
|
34
|
-
const fullVerbatimTokens =
|
|
35
|
+
const fullVerbatimTokens = countGatewayPromptTokens({ messages: fullVerbatimMessages }, tokenAccounting);
|
|
35
36
|
if (fullVerbatimTokens <= effectiveInputBudget) {
|
|
36
37
|
return { messages: fullVerbatimMessages };
|
|
37
38
|
}
|
|
@@ -49,7 +50,7 @@ function buildVerbatimMessages(systemMessage, filtered) {
|
|
|
49
50
|
function buildCompactedOutcome(prepared, systemMessage, selection, tokenAccounting) {
|
|
50
51
|
const dropped = prepared.slice(0, selection.dropCount);
|
|
51
52
|
const retained = prepared.slice(selection.dropCount);
|
|
52
|
-
const record = buildRecord(dropped, selection
|
|
53
|
+
const record = buildRecord(dropped, selection, tokenAccounting, systemMessage);
|
|
53
54
|
return {
|
|
54
55
|
messages: buildCompactedMessages(systemMessage, selection.summaryContent, retained),
|
|
55
56
|
compaction: record,
|
|
@@ -85,29 +86,28 @@ function buildTokenPrefix(prepared) {
|
|
|
85
86
|
const tokenPrefix = [0];
|
|
86
87
|
for (const turn of prepared) {
|
|
87
88
|
const previousTotal = tokenPrefix.at(-1) ?? 0;
|
|
88
|
-
tokenPrefix.push(previousTotal + turn.
|
|
89
|
+
tokenPrefix.push(previousTotal + turn.gatewayTokens);
|
|
89
90
|
}
|
|
90
91
|
return tokenPrefix;
|
|
91
92
|
}
|
|
92
93
|
function selectCompactionCandidate(prepared, tokenPrefix, dropCount, systemContent, effectiveInputBudget, redactionSecrets, tokenAccounting) {
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (systemTokens +
|
|
94
|
+
const retainedMessageTokens = (tokenPrefix.at(-1) ?? 0) - (tokenPrefix[dropCount] ?? 0);
|
|
95
|
+
const systemTokens = systemContent === undefined
|
|
96
|
+
? 0
|
|
97
|
+
: countGatewayPromptTokens({ messages: [{ role: "system", content: systemContent }] }, tokenAccounting);
|
|
98
|
+
if (systemTokens + retainedMessageTokens > effectiveInputBudget) {
|
|
98
99
|
return undefined;
|
|
99
100
|
}
|
|
100
|
-
const
|
|
101
|
-
const retainedTokens = countContextTokensForSegments([systemSummaryScaffold, ...retainedContents], tokenAccounting);
|
|
102
|
-
const summaryBudget = effectiveInputBudget - retainedTokens;
|
|
101
|
+
const summaryBudget = effectiveInputBudget - retainedMessageTokens;
|
|
103
102
|
if (summaryBudget < 2) {
|
|
104
103
|
return undefined;
|
|
105
104
|
}
|
|
106
|
-
const summary = buildSummaryContent(prepared.slice(0, dropCount), summaryBudget, redactionSecrets, tokenAccounting);
|
|
105
|
+
const summary = buildSummaryContent(prepared.slice(0, dropCount), summaryBudget, redactionSecrets, tokenAccounting, systemContent);
|
|
107
106
|
if (summary === undefined) {
|
|
108
107
|
return undefined;
|
|
109
108
|
}
|
|
110
|
-
const candidateTokens =
|
|
109
|
+
const candidateTokens = retainedMessageTokens +
|
|
110
|
+
countSystemSummaryTokens(systemContent, summary.content, tokenAccounting);
|
|
111
111
|
return candidateTokens <= effectiveInputBudget
|
|
112
112
|
? { dropCount, summaryContent: summary.content, digest: summary.digest }
|
|
113
113
|
: undefined;
|
|
@@ -117,7 +117,7 @@ function prepareDroppedTurns(prefix, tokenAccounting) {
|
|
|
117
117
|
role: turn.role,
|
|
118
118
|
content: turn.content,
|
|
119
119
|
stableId: `history-msg-${String(index)}`,
|
|
120
|
-
|
|
120
|
+
gatewayTokens: countGatewayPromptTokens({ messages: [turn] }, tokenAccounting),
|
|
121
121
|
}));
|
|
122
122
|
}
|
|
123
123
|
const SUMMARY_HEADER = "[Automated structured summary of earlier conversation turns — older messages were compacted " +
|
|
@@ -134,7 +134,7 @@ function buildSystemScopedCompactionContent(systemContent, summaryContent) {
|
|
|
134
134
|
parts.push([SYSTEM_SCOPED_SUMMARY_HEADER, summaryContent, SYSTEM_SCOPED_SUMMARY_FOOTER].join("\n"));
|
|
135
135
|
return parts.join("\n\n");
|
|
136
136
|
}
|
|
137
|
-
function buildSummaryContent(dropped, summaryTokenBudget, redactionSecrets, tokenAccounting) {
|
|
137
|
+
function buildSummaryContent(dropped, summaryTokenBudget, redactionSecrets, tokenAccounting, systemContent) {
|
|
138
138
|
if (summaryTokenBudget <= 2) {
|
|
139
139
|
return undefined;
|
|
140
140
|
}
|
|
@@ -146,7 +146,7 @@ function buildSummaryContent(dropped, summaryTokenBudget, redactionSecrets, toke
|
|
|
146
146
|
})),
|
|
147
147
|
redactionSecrets,
|
|
148
148
|
});
|
|
149
|
-
const content = fitSummaryLines(renderStructuredSummaryLines(dropped.length, digest), summaryTokenBudget, tokenAccounting);
|
|
149
|
+
const content = fitSummaryLines(renderStructuredSummaryLines(dropped.length, digest), summaryTokenBudget, tokenAccounting, systemContent);
|
|
150
150
|
return content === undefined ? undefined : { content, digest };
|
|
151
151
|
}
|
|
152
152
|
export function renderStructuredSummaryLines(droppedCount, digest) {
|
|
@@ -183,25 +183,37 @@ function addSection(lines, title, values) {
|
|
|
183
183
|
function isSafeListItem(value) {
|
|
184
184
|
return !/[\r\n]/u.test(value);
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function countSystemSummaryTokens(systemContent, summaryContent, tokenAccounting) {
|
|
187
|
+
return countGatewayPromptTokens({
|
|
188
|
+
messages: [
|
|
189
|
+
{
|
|
190
|
+
role: "system",
|
|
191
|
+
content: buildSystemScopedCompactionContent(systemContent, summaryContent),
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
}, tokenAccounting);
|
|
195
|
+
}
|
|
196
|
+
function fitSummaryLines(lines, summaryTokenBudget, tokenAccounting, systemContent) {
|
|
187
197
|
const fitted = [];
|
|
188
198
|
for (const line of lines) {
|
|
189
199
|
const candidate = [...fitted, line].join("\n");
|
|
190
|
-
if (
|
|
200
|
+
if (countSystemSummaryTokens(systemContent, candidate, tokenAccounting) > summaryTokenBudget) {
|
|
191
201
|
break;
|
|
192
202
|
}
|
|
193
203
|
fitted.push(line);
|
|
194
204
|
}
|
|
195
205
|
const summary = fitted.join("\n");
|
|
196
|
-
return summary.length > 0 &&
|
|
206
|
+
return summary.length > 0 &&
|
|
207
|
+
countSystemSummaryTokens(systemContent, summary, tokenAccounting) <= summaryTokenBudget
|
|
197
208
|
? summary
|
|
198
209
|
: undefined;
|
|
199
210
|
}
|
|
200
|
-
function buildRecord(dropped,
|
|
211
|
+
function buildRecord(dropped, selection, tokenAccounting, systemMessage) {
|
|
201
212
|
if (dropped.length === 0) {
|
|
202
213
|
throw new Error("conversation-compaction cannot emit a zero-item summary record");
|
|
203
214
|
}
|
|
204
|
-
const tokensBefore = dropped.reduce((sum, turn) => sum + turn.
|
|
215
|
+
const tokensBefore = dropped.reduce((sum, turn) => sum + turn.gatewayTokens, 0);
|
|
216
|
+
const systemTokens = countGatewayPromptTokens({ messages: systemMessage === undefined ? [] : [systemMessage] }, tokenAccounting);
|
|
205
217
|
const record = {
|
|
206
218
|
schemaVersion: CONTEXT_ENGINEERING_SCHEMA_VERSION,
|
|
207
219
|
laneId: "history-summary",
|
|
@@ -209,10 +221,11 @@ function buildRecord(dropped, summaryContent, digest, tokenAccounting) {
|
|
|
209
221
|
itemsBefore: dropped.length,
|
|
210
222
|
itemsAfter: 1,
|
|
211
223
|
tokensBefore,
|
|
212
|
-
tokensAfter:
|
|
224
|
+
tokensAfter: Math.max(0, countSystemSummaryTokens(systemMessage?.content, selection.summaryContent, tokenAccounting) -
|
|
225
|
+
systemTokens),
|
|
213
226
|
orderedAt: dropped.length,
|
|
214
227
|
sourceSpans: dropped.map((turn) => ({ kind: "message", stableId: turn.stableId })),
|
|
215
|
-
...digest,
|
|
228
|
+
...selection.digest,
|
|
216
229
|
};
|
|
217
230
|
const validation = validateContextCompactionRecord(record);
|
|
218
231
|
if (!validation.ok) {
|
|
@@ -6,6 +6,9 @@ export interface GatewayConversationMessage {
|
|
|
6
6
|
readonly contentParts?: readonly ChatMessageContentPart[] | undefined;
|
|
7
7
|
}
|
|
8
8
|
export declare const MAX_CONTEXT_MESSAGES = 24;
|
|
9
|
+
export declare function withGatewayConversationImages(messages: GatewayConversationMessage[], imageParts: readonly ChatMessageContentPart[]): GatewayConversationMessage[];
|
|
10
|
+
/** Accounting-only shape; attachment bytes are resolved at the authorized provider boundary. */
|
|
11
|
+
export declare function gatewayConversationImageAccounting(messages: GatewayConversationMessage[], imageCount?: number): GatewayConversationMessage[];
|
|
9
12
|
export declare function usableGatewayMessages(messages: readonly ChatMessage[]): {
|
|
10
13
|
role: "user" | "assistant";
|
|
11
14
|
content: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-gateway.d.ts","sourceRoot":"","sources":["../src/conversation-gateway.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,sBAAsB,EAAE,GAAG,SAAS,CAAC;CACvE;AAED,eAAO,MAAM,oBAAoB,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation-gateway.d.ts","sourceRoot":"","sources":["../src/conversation-gateway.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,sBAAsB,EAAE,GAAG,SAAS,CAAC;CACvE;AAED,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,0BAA0B,EAAE,EACtC,UAAU,EAAE,SAAS,sBAAsB,EAAE,GAC5C,0BAA0B,EAAE,CAO9B;AAED,gGAAgG;AAChG,wBAAgB,kCAAkC,CAChD,QAAQ,EAAE,0BAA0B,EAAE,EACtC,UAAU,SAAI,GACb,0BAA0B,EAAE,CAQ9B;AAcD,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,CAMnD;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B,0BAA0B,EAAE,CAS9B"}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { CONVERSATION_SYSTEM_PROMPT } from "./conversation-prompt.js";
|
|
2
2
|
import { isLegacyEmptyAssistantPlaceholder } from "./assistant-response.js";
|
|
3
3
|
export const MAX_CONTEXT_MESSAGES = 24;
|
|
4
|
+
export function withGatewayConversationImages(messages, imageParts) {
|
|
5
|
+
if (imageParts.length === 0)
|
|
6
|
+
return messages;
|
|
7
|
+
return messages.map((message, index) => index === messages.length - 1
|
|
8
|
+
? { ...message, contentParts: [{ type: "text", text: message.content }, ...imageParts] }
|
|
9
|
+
: message);
|
|
10
|
+
}
|
|
11
|
+
/** Accounting-only shape; attachment bytes are resolved at the authorized provider boundary. */
|
|
12
|
+
export function gatewayConversationImageAccounting(messages, imageCount = 0) {
|
|
13
|
+
return withGatewayConversationImages(messages, Array.from({ length: imageCount }, () => ({
|
|
14
|
+
type: "image_url",
|
|
15
|
+
image_url: { url: "" },
|
|
16
|
+
})));
|
|
17
|
+
}
|
|
4
18
|
function messageForGateway(message) {
|
|
5
19
|
if (isLegacyEmptyAssistantPlaceholder(message)) {
|
|
6
20
|
return null;
|