@oscharko-dev/keiko 1.1.5 → 1.1.6
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 +10 -10
- package/dist/ui/static/__next._full.txt +12 -12
- package/dist/ui/static/__next._tree.txt +1 -1
- package/dist/ui/static/_next/static/chunks/{0xqxs7rppw_o5.css → 0xxx56s32tn9r.css} +1 -1
- package/dist/ui/static/_next/static/chunks/{3pfnjbbr6jydb.js → 182b4sf3i-krz.js} +1 -1
- package/dist/ui/static/_next/static/chunks/1k6f6m-u2q69-.js +1 -0
- package/dist/ui/static/_next/static/chunks/28mbnwl9g65al.js +1 -0
- package/dist/ui/static/_next/static/chunks/{1r6n6x3-e27ud.js → 2t2wftn5liinr.js} +1 -1
- package/dist/ui/static/_next/static/chunks/{2onl4czrdod2d.js → 3-5_wuwrev-8c.js} +1 -1
- package/dist/ui/static/_next/static/chunks/3doin5vaz4zjs.js +1 -0
- package/dist/ui/static/_not-found/__next._full.txt +9 -9
- package/dist/ui/static/_not-found/__next._not-found.__PAGE__.txt +8 -8
- 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 +9 -9
- package/dist/ui/static/atlassian-connectors/__next._full.txt +11 -11
- package/dist/ui/static/atlassian-connectors/__next._tree.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next.atlassian-connectors.__PAGE__.txt +10 -10
- package/dist/ui/static/atlassian-connectors.html +1 -1
- package/dist/ui/static/atlassian-connectors.txt +11 -11
- package/dist/ui/static/index.html +1 -1
- package/dist/ui/static/index.txt +12 -12
- package/dist/ui/static/launch/__next._full.txt +12 -12
- package/dist/ui/static/launch/__next._tree.txt +1 -1
- package/dist/ui/static/launch/__next.launch.__PAGE__.txt +10 -10
- package/dist/ui/static/launch.html +1 -1
- package/dist/ui/static/launch.txt +12 -12
- package/dist/ui/static/local-knowledge/__next._full.txt +12 -12
- package/dist/ui/static/local-knowledge/__next._tree.txt +1 -1
- package/dist/ui/static/local-knowledge/__next.local-knowledge.__PAGE__.txt +10 -10
- package/dist/ui/static/local-knowledge/capsule/__next._full.txt +11 -11
- 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 +10 -10
- package/dist/ui/static/local-knowledge/capsule.html +1 -1
- package/dist/ui/static/local-knowledge/capsule.txt +11 -11
- package/dist/ui/static/local-knowledge.html +1 -1
- package/dist/ui/static/local-knowledge.txt +12 -12
- package/node_modules/@oscharko-dev/keiko-cli/dist/support-analyze.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-cli/dist/support-analyze.js +52 -11
- package/node_modules/@oscharko-dev/keiko-cli/package.json +14 -14
- 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 +29 -9
- 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 +54 -9
- package/node_modules/@oscharko-dev/keiko-contracts/dist/activity-log-registry.generated.d.ts +459 -9
- 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 +551 -9
- package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api-validation.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api-validation.js +14 -8
- package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api.d.ts +3 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-api.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-constants.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-contracts/dist/coding-workbench-runtime-constants.d.ts.map +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/gateway.d.ts +3 -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 +21 -8
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.js +7 -6
- 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 +1 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-adapter.d.ts +7 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-adapter.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-adapter.js +253 -18
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.js +4 -0
- 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/dist/darwin-git.d.ts +3 -0
- package/node_modules/@oscharko-dev/keiko-sandbox/dist/darwin-git.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-sandbox/dist/darwin-git.js +30 -6
- 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/coding-runtime/codingRuntimeActivityOperations.d.ts +24 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeActivityOperations.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeActivityOperations.js +22 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeEventHub.d.ts +8 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeEventHub.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/codingRuntimeEventHub.js +28 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/devLaneRuntimeProcessBackend.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/devLaneRuntimeProcessBackend.js +39 -13
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/opencodeFunctionalHarness/_governedTools.d.ts +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/opencodeFunctionalHarness/_governedTools.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-runtime/opencodeFunctionalHarness/_governedTools.js +59 -8
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-sidecar-gateway.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/coding-sidecar-gateway.js +324 -46
- package/node_modules/@oscharko-dev/keiko-server/package.json +22 -22
- 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 -26
- package/release-impact.catalog.json +51 -0
- package/vendor/oscharko-dev-keiko-cli-1.1.6.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-connectors-1.1.5.tgz → oscharko-dev-keiko-connectors-1.1.6.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-contracts-1.1.6.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-evaluations-1.1.5.tgz → oscharko-dev-keiko-evaluations-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-evidence-1.1.5.tgz → oscharko-dev-keiko-evidence-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-git-1.1.5.tgz → oscharko-dev-keiko-git-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-harness-1.1.5.tgz → oscharko-dev-keiko-harness-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-local-knowledge-1.1.5.tgz → oscharko-dev-keiko-local-knowledge-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-capture-1.1.5.tgz → oscharko-dev-keiko-memory-capture-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-consolidation-1.1.5.tgz → oscharko-dev-keiko-memory-consolidation-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-governance-1.1.5.tgz → oscharko-dev-keiko-memory-governance-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-retrieval-1.1.5.tgz → oscharko-dev-keiko-memory-retrieval-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-vault-1.1.5.tgz → oscharko-dev-keiko-memory-vault-1.1.6.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-model-gateway-1.1.6.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-quality-intelligence-1.1.5.tgz → oscharko-dev-keiko-quality-intelligence-1.1.6.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-sandbox-1.1.6.tgz +0 -0
- package/vendor/oscharko-dev-keiko-sdk-1.1.6.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-security-1.1.5.tgz → oscharko-dev-keiko-security-1.1.6.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-server-1.1.6.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-tool-catalog-1.1.5.tgz → oscharko-dev-keiko-tool-catalog-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-tools-1.1.5.tgz → oscharko-dev-keiko-tools-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-verification-1.1.5.tgz → oscharko-dev-keiko-verification-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-workflows-1.1.5.tgz → oscharko-dev-keiko-workflows-1.1.6.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-workspace-1.1.5.tgz → oscharko-dev-keiko-workspace-1.1.6.tgz} +0 -0
- package/dist/ui/static/_next/static/chunks/0fbt5i1tfqbr3.js +0 -1
- package/dist/ui/static/_next/static/chunks/0nmcnzva3p40l.js +0 -1
- package/dist/ui/static/_next/static/chunks/2thq7sr8sysu-.js +0 -1
- package/vendor/oscharko-dev-keiko-cli-1.1.5.tgz +0 -0
- package/vendor/oscharko-dev-keiko-contracts-1.1.5.tgz +0 -0
- package/vendor/oscharko-dev-keiko-model-gateway-1.1.5.tgz +0 -0
- package/vendor/oscharko-dev-keiko-sandbox-1.1.5.tgz +0 -0
- package/vendor/oscharko-dev-keiko-sdk-1.1.5.tgz +0 -0
- package/vendor/oscharko-dev-keiko-server-1.1.5.tgz +0 -0
- /package/dist/ui/static/_next/static/{IH07azjG4tKvS8qRk-uMI → ytpWXc-OicMB-rH2zX5b3}/_buildManifest.js +0 -0
- /package/dist/ui/static/_next/static/{IH07azjG4tKvS8qRk-uMI → ytpWXc-OicMB-rH2zX5b3}/_clientMiddlewareManifest.js +0 -0
- /package/dist/ui/static/_next/static/{IH07azjG4tKvS8qRk-uMI → ytpWXc-OicMB-rH2zX5b3}/_ssgManifest.js +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { gatewaySpendRejectionReason } from "./gateway-spend-budget.js";
|
|
2
|
+
import { AuthenticationError, CircuitOpenError, ContextOverflowError, ModelRefusalError, ProviderError, RateLimitError, TimeoutError, TransportError, } from "@oscharko-dev/keiko-security/errors/gateway";
|
|
2
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
4
|
import { findConfiguredCapability, resolveCodingSafeSidecarGatewayProfile, } from "@oscharko-dev/keiko-model-gateway";
|
|
4
5
|
import { countGatewayPromptTokens, } from "@oscharko-dev/keiko-model-gateway/internal/prompt-token-accounting";
|
|
5
|
-
import { providerRequestBudgetMs } from "@oscharko-dev/keiko-model-gateway/internal/resilience";
|
|
6
|
+
import { codingWorkbenchProviderTimeoutMs, providerRequestBudgetMs, } from "@oscharko-dev/keiko-model-gateway/internal/resilience";
|
|
6
7
|
import { MAX_TIMER_DELAY_MS } from "./abort-race.js";
|
|
7
8
|
import { compareStrings } from "@oscharko-dev/keiko-contracts/runtime/comparators";
|
|
8
9
|
import { CODING_WORKBENCH_MINIMUM_CODING_CONTEXT_PROMPT_TOKENS } from "@oscharko-dev/keiko-contracts/runtime/coding-workbench";
|
|
@@ -43,6 +44,15 @@ function maxActiveCodingGatewayRequests(env = process.env) {
|
|
|
43
44
|
export function _resetActiveCodingGatewayRequestsForTests() {
|
|
44
45
|
activeCodingGatewayRequests = 0;
|
|
45
46
|
}
|
|
47
|
+
function observedPromptSettlement(outcome, selected, unverified) {
|
|
48
|
+
if (!isRecord(outcome))
|
|
49
|
+
return unverified;
|
|
50
|
+
if (outcome.ok === true)
|
|
51
|
+
return selected;
|
|
52
|
+
if (outcome.ok === false)
|
|
53
|
+
return { ...unverified, status: "retained-after-refusal" };
|
|
54
|
+
return unverified;
|
|
55
|
+
}
|
|
46
56
|
/**
|
|
47
57
|
* Settles a runtime prompt-token reservation. `actualPromptTokens` is the provider's real reported
|
|
48
58
|
* usage when known; when the outcome is uncertain (dispatched but no usage was ever observed — a
|
|
@@ -52,10 +62,33 @@ export function _resetActiveCodingGatewayRequestsForTests() {
|
|
|
52
62
|
* authenticator (not every deployment wires it) is a silent no-op, never a failure.
|
|
53
63
|
*/
|
|
54
64
|
function settlePromptTokenReservation(deps, reservation, actualPromptTokens) {
|
|
55
|
-
if (reservation.settled)
|
|
56
|
-
|
|
65
|
+
if (reservation.settled) {
|
|
66
|
+
if (reservation.settlement === undefined)
|
|
67
|
+
throw new TypeError("missing prompt settlement");
|
|
68
|
+
return reservation.settlement;
|
|
69
|
+
}
|
|
57
70
|
reservation.settled = true;
|
|
58
|
-
|
|
71
|
+
const providerReported = actualPromptTokens !== undefined && actualPromptTokens > 0;
|
|
72
|
+
const promptTokens = providerReported ? actualPromptTokens : reservation.reservedPromptTokens;
|
|
73
|
+
const unverified = {
|
|
74
|
+
promptTokens: reservation.reservedPromptTokens,
|
|
75
|
+
source: "reserved-estimate",
|
|
76
|
+
status: "unverified",
|
|
77
|
+
};
|
|
78
|
+
const selected = {
|
|
79
|
+
promptTokens,
|
|
80
|
+
source: providerReported ? "provider-reported" : "reserved-estimate",
|
|
81
|
+
status: "settled",
|
|
82
|
+
};
|
|
83
|
+
reservation.settlement = unverified;
|
|
84
|
+
const authenticator = runtimeCapabilityAuthenticator(deps);
|
|
85
|
+
if (authenticator?.settlePromptTokens === undefined) {
|
|
86
|
+
reservation.settlement = { ...selected, status: "not-wired" };
|
|
87
|
+
return reservation.settlement;
|
|
88
|
+
}
|
|
89
|
+
const outcome = authenticator.settlePromptTokens(reservation.capability, reservation.reservedPromptTokens, promptTokens);
|
|
90
|
+
reservation.settlement = observedPromptSettlement(outcome, selected, unverified);
|
|
91
|
+
return reservation.settlement;
|
|
59
92
|
}
|
|
60
93
|
const CODING_SIDECAR_GATEWAY_ERROR_CODE = "CODING_SIDECAR_UNAVAILABLE";
|
|
61
94
|
const CODING_SIDECAR_GATEWAY_ROUTE = "POST /api/coding-sidecar/gateway/chat/completions";
|
|
@@ -219,6 +252,119 @@ const CODING_SIDECAR_GATEWAY_REJECTED_OPERATION = defineActivityLogOperation({
|
|
|
219
252
|
proofIds: ["coding-sidecar.gateway.rejected.line"],
|
|
220
253
|
releaseImpact: "patch",
|
|
221
254
|
});
|
|
255
|
+
const CODING_SIDECAR_GATEWAY_TURN_FAILED_OPERATION = defineActivityLogOperation({
|
|
256
|
+
contractKind: "activity-log-operation",
|
|
257
|
+
schemaVersion: 1,
|
|
258
|
+
op: "coding-sidecar.gateway.turn-failed",
|
|
259
|
+
category: "gateway",
|
|
260
|
+
owner: "keiko-server",
|
|
261
|
+
emitter: "coding-sidecar-gateway.reportGatewayTurnFailure",
|
|
262
|
+
fields: {
|
|
263
|
+
runId: { type: "string", dataClass: "opaque-id", required: true, maxLength: 128 },
|
|
264
|
+
revision: { type: "integer", dataClass: "count", required: true },
|
|
265
|
+
state: {
|
|
266
|
+
type: "string",
|
|
267
|
+
dataClass: "closed-enum",
|
|
268
|
+
required: true,
|
|
269
|
+
values: ["running", "paused"],
|
|
270
|
+
},
|
|
271
|
+
failureCode: {
|
|
272
|
+
type: "string",
|
|
273
|
+
dataClass: "closed-enum",
|
|
274
|
+
required: true,
|
|
275
|
+
values: ["provider-failed", "stream-incomplete", "turn-rejected"],
|
|
276
|
+
},
|
|
277
|
+
published: { type: "boolean", dataClass: "closed-enum", required: true },
|
|
278
|
+
publicationReason: {
|
|
279
|
+
type: "string",
|
|
280
|
+
dataClass: "closed-enum",
|
|
281
|
+
required: true,
|
|
282
|
+
values: [
|
|
283
|
+
"published",
|
|
284
|
+
"event-hub-unavailable",
|
|
285
|
+
"terminal-run",
|
|
286
|
+
"invalid-event",
|
|
287
|
+
"sequence-exhausted",
|
|
288
|
+
"capacity-pressure",
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
completeness: { type: "string", dataClass: "completeness-state", required: true },
|
|
292
|
+
loss: { type: "string", dataClass: "loss-state", required: true },
|
|
293
|
+
},
|
|
294
|
+
causal: "correlation",
|
|
295
|
+
lifecycle: "failure",
|
|
296
|
+
analyzerProjection: "failure-cluster",
|
|
297
|
+
failureClasses: ["coding-sidecar-gateway-turn-failure"],
|
|
298
|
+
proofIds: ["coding-sidecar.gateway.turn-failed.emitted-line"],
|
|
299
|
+
releaseImpact: "patch",
|
|
300
|
+
});
|
|
301
|
+
const CODING_SIDECAR_GATEWAY_USAGE_SETTLED_OPERATION = defineActivityLogOperation({
|
|
302
|
+
contractKind: "activity-log-operation",
|
|
303
|
+
schemaVersion: 1,
|
|
304
|
+
op: "coding-sidecar.gateway.usage-settled",
|
|
305
|
+
category: "gateway",
|
|
306
|
+
owner: "keiko-server",
|
|
307
|
+
emitter: "coding-sidecar-gateway.logGatewayCompletionUsage",
|
|
308
|
+
fields: {
|
|
309
|
+
runId: { type: "string", dataClass: "opaque-id", required: true, maxLength: 128 },
|
|
310
|
+
completionTokens: { type: "integer", dataClass: "count", required: true },
|
|
311
|
+
promptTokens: { type: "integer", dataClass: "count", required: true },
|
|
312
|
+
promptSource: {
|
|
313
|
+
type: "string",
|
|
314
|
+
dataClass: "closed-enum",
|
|
315
|
+
required: true,
|
|
316
|
+
values: ["provider-reported", "reserved-estimate"],
|
|
317
|
+
},
|
|
318
|
+
promptSettlementStatus: {
|
|
319
|
+
type: "string",
|
|
320
|
+
dataClass: "closed-enum",
|
|
321
|
+
required: true,
|
|
322
|
+
values: ["settled", "retained-after-refusal", "unverified", "not-wired"],
|
|
323
|
+
},
|
|
324
|
+
outputBytes: { type: "integer", dataClass: "count", required: true },
|
|
325
|
+
source: {
|
|
326
|
+
type: "string",
|
|
327
|
+
dataClass: "closed-enum",
|
|
328
|
+
required: true,
|
|
329
|
+
values: ["provider-reported", "streamed-byte-estimate", "output-byte-estimate"],
|
|
330
|
+
},
|
|
331
|
+
completeness: { type: "string", dataClass: "completeness-state", required: true },
|
|
332
|
+
loss: { type: "string", dataClass: "loss-state", required: true },
|
|
333
|
+
},
|
|
334
|
+
causal: "correlation",
|
|
335
|
+
lifecycle: "end",
|
|
336
|
+
analyzerProjection: "timeline",
|
|
337
|
+
failureClasses: ["coding-sidecar-gateway-request"],
|
|
338
|
+
proofIds: ["coding-sidecar.gateway.usage-settled.line"],
|
|
339
|
+
releaseImpact: "patch",
|
|
340
|
+
});
|
|
341
|
+
const CODING_SIDECAR_GATEWAY_OUTCOME_OPERATION = defineActivityLogOperation({
|
|
342
|
+
contractKind: "activity-log-operation",
|
|
343
|
+
schemaVersion: 1,
|
|
344
|
+
op: "coding-sidecar.gateway.outcome",
|
|
345
|
+
category: "gateway",
|
|
346
|
+
owner: "keiko-server",
|
|
347
|
+
emitter: "coding-sidecar-gateway.recordGatewayOutcome",
|
|
348
|
+
fields: {
|
|
349
|
+
runId: { type: "string", dataClass: "opaque-id", required: true, maxLength: 128 },
|
|
350
|
+
outcome: {
|
|
351
|
+
type: "string",
|
|
352
|
+
dataClass: "closed-enum",
|
|
353
|
+
required: true,
|
|
354
|
+
values: ["accepted", "cancelled", "failed", "output-limit"],
|
|
355
|
+
},
|
|
356
|
+
completionTokens: { type: "integer", dataClass: "count", required: true },
|
|
357
|
+
outputBytes: { type: "integer", dataClass: "count", required: true },
|
|
358
|
+
completeness: { type: "string", dataClass: "completeness-state", required: true },
|
|
359
|
+
loss: { type: "string", dataClass: "loss-state", required: true },
|
|
360
|
+
},
|
|
361
|
+
causal: "correlation",
|
|
362
|
+
lifecycle: "end",
|
|
363
|
+
analyzerProjection: "timeline",
|
|
364
|
+
failureClasses: ["coding-sidecar-gateway-request"],
|
|
365
|
+
proofIds: ["coding-sidecar.gateway.outcome.line"],
|
|
366
|
+
releaseImpact: "patch",
|
|
367
|
+
});
|
|
222
368
|
function gatewayRejectionErrorKind(reason) {
|
|
223
369
|
if (reason === "capability-missing" || reason === "capability-invalid") {
|
|
224
370
|
return "permission-denied";
|
|
@@ -238,6 +384,7 @@ function gatewayRejectionErrorKind(reason) {
|
|
|
238
384
|
function logGatewayRejection(ctx, runId, status, reason, evidence = {}) {
|
|
239
385
|
getServerLogger().warn(activityLogEvent(CODING_SIDECAR_GATEWAY_REJECTED_OPERATION, {
|
|
240
386
|
correlationId: correlationIdOrUnknown(ctx.correlationId),
|
|
387
|
+
...(runId === undefined ? {} : { parentCorrelationId: runId }),
|
|
241
388
|
status,
|
|
242
389
|
errorKind: gatewayRejectionErrorKind(reason),
|
|
243
390
|
}, {
|
|
@@ -389,12 +536,12 @@ function chatFactoryFor(deps, gateway) {
|
|
|
389
536
|
}
|
|
390
537
|
function defaultChatFactoryFor(gateway) {
|
|
391
538
|
return (_config, modelId) => {
|
|
392
|
-
return (request) => gateway.chat({ ...request, modelId });
|
|
539
|
+
return (request) => gateway.chat({ ...request, modelId, latencyProfile: "coding-workbench" });
|
|
393
540
|
};
|
|
394
541
|
}
|
|
395
542
|
function defaultChatStreamFactoryFor(gateway) {
|
|
396
543
|
return (_config, modelId) => {
|
|
397
|
-
return (request) => gateway.chatStream({ ...request, modelId });
|
|
544
|
+
return (request) => gateway.chatStream({ ...request, modelId, latencyProfile: "coding-workbench" });
|
|
398
545
|
};
|
|
399
546
|
}
|
|
400
547
|
function chatStreamFactoryFor(deps, gateway) {
|
|
@@ -748,7 +895,8 @@ function emitGatewayEvidenceAggregationDiagnostic(deps, runId) {
|
|
|
748
895
|
message: "sidecar-gateway-evidence-aggregation-failed",
|
|
749
896
|
});
|
|
750
897
|
}
|
|
751
|
-
function recordGatewayOutcome(deps, runId, outcome, completionTokens, outputBytes) {
|
|
898
|
+
function recordGatewayOutcome(ctx, deps, runId, outcome, completionTokens, outputBytes) {
|
|
899
|
+
getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_OUTCOME_OPERATION, { correlationId: correlationIdOrUnknown(ctx.correlationId), parentCorrelationId: runId }, { runId, outcome, completionTokens, outputBytes, completeness: "complete", loss: "none" }));
|
|
752
900
|
try {
|
|
753
901
|
void Promise.resolve(evidenceAggregator(deps)?.record({ runId, outcome, completionTokens, outputBytes })).catch(() => {
|
|
754
902
|
emitGatewayEvidenceAggregationDiagnostic(deps, runId);
|
|
@@ -859,27 +1007,81 @@ function validationErrorForChatRequest(parsed, modelAlias, runMetadata, runtimeA
|
|
|
859
1007
|
}
|
|
860
1008
|
return undefined;
|
|
861
1009
|
}
|
|
862
|
-
function
|
|
1010
|
+
function gatewayDiagnosticCorrelation(ctx, runId) {
|
|
1011
|
+
const correlationId = ctx.correlationId ?? runId;
|
|
1012
|
+
return correlationId === runId
|
|
1013
|
+
? { correlationId }
|
|
1014
|
+
: { correlationId, parentCorrelationId: runId };
|
|
1015
|
+
}
|
|
1016
|
+
function emitGatewayFailureDiagnostic(ctx, deps, error, runId) {
|
|
863
1017
|
emitServerDiagnostic(deps.diagnostics, serverDiagnosticFromError({
|
|
864
|
-
|
|
1018
|
+
...gatewayDiagnosticCorrelation(ctx, runId),
|
|
865
1019
|
operation: CODING_SIDECAR_GATEWAY_ROUTE,
|
|
866
1020
|
source: "coding-sidecar-gateway.chat",
|
|
867
1021
|
error,
|
|
868
1022
|
redact: (message) => String(deps.redactor(message)),
|
|
869
1023
|
}));
|
|
870
1024
|
}
|
|
1025
|
+
function reportGatewayTurnFailure(ctx, deps, runId, failureCode) {
|
|
1026
|
+
const snapshot = deps.codingRuntimeOrchestrator?.getSnapshot(runId);
|
|
1027
|
+
if (snapshot?.state !== "running" && snapshot?.state !== "paused")
|
|
1028
|
+
return;
|
|
1029
|
+
const publicationReason = gatewayTurnFailurePublication(deps, runId, snapshot, failureCode);
|
|
1030
|
+
logGatewayTurnFailure(ctx, runId, snapshot.revision, snapshot.state, failureCode, publicationReason);
|
|
1031
|
+
}
|
|
1032
|
+
function gatewayTurnFailurePublication(deps, runId, snapshot, failureCode) {
|
|
1033
|
+
const publication = deps.codingRuntimeEventHub?.publishTurnFailure(runId, snapshot.state, snapshot.revision, failureCode);
|
|
1034
|
+
const publicationReason = publication?.ok === true ? "published" : (publication?.reason ?? "event-hub-unavailable");
|
|
1035
|
+
return publicationReason;
|
|
1036
|
+
}
|
|
1037
|
+
function logGatewayTurnFailure(ctx, runId, revision, state, failureCode, publicationReason) {
|
|
1038
|
+
getServerLogger().warn(activityLogEvent(CODING_SIDECAR_GATEWAY_TURN_FAILED_OPERATION, {
|
|
1039
|
+
...gatewayDiagnosticCorrelation(ctx, runId),
|
|
1040
|
+
errorKind: failureCode === "turn-rejected" ? "validation-failed" : "unavailable",
|
|
1041
|
+
}, {
|
|
1042
|
+
runId,
|
|
1043
|
+
revision,
|
|
1044
|
+
state,
|
|
1045
|
+
failureCode,
|
|
1046
|
+
published: publicationReason === "published",
|
|
1047
|
+
publicationReason,
|
|
1048
|
+
completeness: "complete",
|
|
1049
|
+
loss: "none",
|
|
1050
|
+
}));
|
|
1051
|
+
}
|
|
1052
|
+
function gatewayTurnFailureCode(error) {
|
|
1053
|
+
if (error instanceof ContextOverflowError || error instanceof ModelRefusalError)
|
|
1054
|
+
return "turn-rejected";
|
|
1055
|
+
if (error instanceof TimeoutError ||
|
|
1056
|
+
error instanceof TransportError ||
|
|
1057
|
+
(error instanceof ProviderError && error.httpStatus === 200))
|
|
1058
|
+
return "stream-incomplete";
|
|
1059
|
+
return "provider-failed";
|
|
1060
|
+
}
|
|
1061
|
+
function gatewayStreamFailureCode(error) {
|
|
1062
|
+
if (gatewaySpendRejectionReason(error) !== undefined)
|
|
1063
|
+
return "turn-rejected";
|
|
1064
|
+
if (error instanceof ContextOverflowError || error instanceof ModelRefusalError)
|
|
1065
|
+
return "turn-rejected";
|
|
1066
|
+
if (error instanceof AuthenticationError ||
|
|
1067
|
+
error instanceof RateLimitError ||
|
|
1068
|
+
error instanceof CircuitOpenError ||
|
|
1069
|
+
(error instanceof ProviderError && error.httpStatus !== 200))
|
|
1070
|
+
return "provider-failed";
|
|
1071
|
+
return "stream-incomplete";
|
|
1072
|
+
}
|
|
871
1073
|
/**
|
|
872
1074
|
* A mid-stream failure aborts an in-flight coding turn. Before this the cause went into a bare
|
|
873
1075
|
* `catch {}` — the pattern AGENTS.md §7 forbids — leaving `settleGatewayStreamError` to emit the SSE
|
|
874
1076
|
* error frame with nothing recorded anywhere, on the coding path. The frame and the run outcome are
|
|
875
|
-
* unchanged; only the redacted cause is added, keyed by the request
|
|
876
|
-
* the pre-stream failure by `source` so an operator can tell "the stream never opened" from "the
|
|
1077
|
+
* unchanged; only the redacted cause is added, keyed by the request and linked to its run,
|
|
1078
|
+
* separated from the pre-stream failure by `source` so an operator can tell "the stream never opened" from "the
|
|
877
1079
|
* stream died after N deltas". `partialUsage` rides along through `serverDiagnosticFromError`, so an
|
|
878
1080
|
* interrupted turn's accumulated token counts stay visible instead of vanishing with the error.
|
|
879
1081
|
*/
|
|
880
|
-
function emitGatewayStreamFailureDiagnostic(ctx, deps, error) {
|
|
1082
|
+
function emitGatewayStreamFailureDiagnostic(ctx, deps, error, runId) {
|
|
881
1083
|
emitServerDiagnostic(deps.diagnostics, serverDiagnosticFromError({
|
|
882
|
-
|
|
1084
|
+
...gatewayDiagnosticCorrelation(ctx, runId),
|
|
883
1085
|
operation: CODING_SIDECAR_GATEWAY_ROUTE,
|
|
884
1086
|
source: "coding-sidecar-gateway.stream",
|
|
885
1087
|
error,
|
|
@@ -985,6 +1187,7 @@ function emitGatewayToolContractDiagnostic(ctx, deps, runId, tools) {
|
|
|
985
1187
|
const { code, reason } = toolContractRejectionReason(tools);
|
|
986
1188
|
emitServerDiagnostic(deps.diagnostics, {
|
|
987
1189
|
correlationId: ctx.correlationId ?? UNKNOWN_CORRELATION_ID,
|
|
1190
|
+
parentCorrelationId: runId,
|
|
988
1191
|
timestamp: new Date(Date.now()).toISOString(),
|
|
989
1192
|
operation: CODING_SIDECAR_GATEWAY_ROUTE,
|
|
990
1193
|
source: "coding-sidecar-gateway.tool-contract",
|
|
@@ -993,6 +1196,7 @@ function emitGatewayToolContractDiagnostic(ctx, deps, runId, tools) {
|
|
|
993
1196
|
code,
|
|
994
1197
|
});
|
|
995
1198
|
logGatewayRejection(ctx, runId, 403, reason, toolContractMismatch(tools));
|
|
1199
|
+
reportGatewayTurnFailure(ctx, deps, runId, "turn-rejected");
|
|
996
1200
|
}
|
|
997
1201
|
/**
|
|
998
1202
|
* True when a long managed-tool-set history never invoked one governed keiko_* tool: the model is
|
|
@@ -1114,6 +1318,7 @@ function unavailableGatewayProfile(ctx, deps, resolved, authentication) {
|
|
|
1114
1318
|
message: "coding-sidecar-gateway-profile-unavailable",
|
|
1115
1319
|
code: unavailableGatewayProfileCode(resolved, selectedModelId, authentication),
|
|
1116
1320
|
});
|
|
1321
|
+
reportGatewayTurnFailure(ctx, deps, authentication.runId, "turn-rejected");
|
|
1117
1322
|
return unavailableError();
|
|
1118
1323
|
}
|
|
1119
1324
|
function unavailableGatewayProfileCode(resolved, selectedModelId, authentication) {
|
|
@@ -1156,7 +1361,12 @@ const GATEWAY_ROUTE_DEADLINE_GRACE_MS = 1_000;
|
|
|
1156
1361
|
export function codingSidecarGatewayRequestDeadlineMs(config, modelId) {
|
|
1157
1362
|
const provider = config.providers.find((candidate) => candidate.modelId === modelId);
|
|
1158
1363
|
// An unconfigured model is refused before any provider call; 30 s only bounds that refusal.
|
|
1159
|
-
const budget = provider === undefined
|
|
1364
|
+
const budget = provider === undefined
|
|
1365
|
+
? 30_000
|
|
1366
|
+
: providerRequestBudgetMs({
|
|
1367
|
+
...provider,
|
|
1368
|
+
timeoutMs: codingWorkbenchProviderTimeoutMs(provider.timeoutMs),
|
|
1369
|
+
});
|
|
1160
1370
|
// Armed with AbortSignal.timeout, which fires at once past 2^31 - 1 ms: an absurd budget must not
|
|
1161
1371
|
// turn the backstop into an immediate abort.
|
|
1162
1372
|
return Math.min(budget + GATEWAY_ROUTE_DEADLINE_GRACE_MS, MAX_TIMER_DELAY_MS);
|
|
@@ -1211,7 +1421,7 @@ async function dispatchGatewayChat(ctx, deps, binding, parsed, runId, delivery,
|
|
|
1211
1421
|
}
|
|
1212
1422
|
if (parsed.stream)
|
|
1213
1423
|
bufferedStream = beginBufferedOpenAiStream(ctx, modelAlias);
|
|
1214
|
-
return await executeBufferedGatewayChat(dispatch, bufferedStream);
|
|
1424
|
+
return await executeBufferedGatewayChat(ctx, dispatch, bufferedStream);
|
|
1215
1425
|
}
|
|
1216
1426
|
catch (error) {
|
|
1217
1427
|
return settleFailedGatewayChat(ctx, deps, runId, cancellationSignal, error, delivery, bufferedStream);
|
|
@@ -1219,10 +1429,12 @@ async function dispatchGatewayChat(ctx, deps, binding, parsed, runId, delivery,
|
|
|
1219
1429
|
}
|
|
1220
1430
|
// Extracted so `executeGatewayChat` stays under AGENTS.md §6's 50-line ceiling.
|
|
1221
1431
|
function settleFailedGatewayChat(ctx, deps, runId, cancellationSignal, error, delivery, bufferedStream) {
|
|
1222
|
-
recordGatewayOutcome(deps, runId, cancellationSignal.aborted ? "cancelled" : "failed", 0, 0);
|
|
1223
|
-
emitGatewayFailureDiagnostic(ctx, deps, error);
|
|
1224
|
-
settlePromptTokenReservation(deps, delivery.promptTokenReservation);
|
|
1432
|
+
recordGatewayOutcome(ctx, deps, runId, cancellationSignal.aborted ? "cancelled" : "failed", 0, 0);
|
|
1433
|
+
emitGatewayFailureDiagnostic(ctx, deps, error, runId);
|
|
1225
1434
|
const spendReason = gatewaySpendRejectionReason(error);
|
|
1435
|
+
if (!cancellationSignal.aborted)
|
|
1436
|
+
reportGatewayTurnFailure(ctx, deps, runId, spendReason === undefined ? gatewayTurnFailureCode(error) : "turn-rejected");
|
|
1437
|
+
settlePromptTokenReservation(deps, delivery.promptTokenReservation);
|
|
1226
1438
|
if (spendReason !== undefined && bufferedStream === undefined) {
|
|
1227
1439
|
logGatewayRejection(ctx, runId, 403, spendReason);
|
|
1228
1440
|
return forbiddenGatewayRequest();
|
|
@@ -1231,27 +1443,43 @@ function settleFailedGatewayChat(ctx, deps, runId, cancellationSignal, error, de
|
|
|
1231
1443
|
? unavailableError()
|
|
1232
1444
|
: settleBufferedOpenAiStreamError(bufferedStream, "error");
|
|
1233
1445
|
}
|
|
1234
|
-
async function executeBufferedGatewayChat(dispatch, stream) {
|
|
1446
|
+
async function executeBufferedGatewayChat(ctx, dispatch, stream) {
|
|
1235
1447
|
const { deps, binding, modelAlias, request, runId, cancellationSignal, promptTokenReservation } = dispatch;
|
|
1236
1448
|
const response = await chatFactoryFor(deps, binding.gateway)(binding.config, modelAlias)(request);
|
|
1237
|
-
settlePromptTokenReservation(deps, promptTokenReservation, response.usage.promptTokens);
|
|
1238
|
-
const
|
|
1449
|
+
const promptSettlement = settlePromptTokenReservation(deps, promptTokenReservation, response.usage.promptTokens);
|
|
1450
|
+
const output = outputMetrics(response);
|
|
1451
|
+
const usage = completionUsage(response, output.outputBytes, 0);
|
|
1452
|
+
const metrics = { ...output, completionTokens: usage.completionTokens };
|
|
1453
|
+
const settledResponse = {
|
|
1454
|
+
...response,
|
|
1455
|
+
usage: { ...response.usage, completionTokens: usage.completionTokens },
|
|
1456
|
+
};
|
|
1457
|
+
logGatewayCompletionUsage(ctx, runId, metrics, usage.source, promptSettlement);
|
|
1458
|
+
const record = (outcome) => {
|
|
1459
|
+
recordGatewayOutcome(ctx, deps, runId, outcome, metrics.completionTokens, metrics.outputBytes);
|
|
1460
|
+
};
|
|
1239
1461
|
if (cancellationSignal.aborted) {
|
|
1240
|
-
|
|
1462
|
+
record("cancelled");
|
|
1241
1463
|
return stream === undefined
|
|
1242
1464
|
? unavailableError()
|
|
1243
1465
|
: settleBufferedOpenAiStreamError(stream, "error");
|
|
1244
1466
|
}
|
|
1245
1467
|
if (exceedsOutputBudget(metrics, request.maxOutputTokens ?? 1)) {
|
|
1246
|
-
|
|
1468
|
+
record("output-limit");
|
|
1247
1469
|
return stream === undefined
|
|
1248
1470
|
? unavailableError()
|
|
1249
1471
|
: settleBufferedOpenAiStreamError(stream, "length");
|
|
1250
1472
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1473
|
+
return deliverBufferedGatewayAnswer(ctx, deps, runId, stream, modelAlias, settledResponse, metrics);
|
|
1474
|
+
}
|
|
1475
|
+
function deliverBufferedGatewayAnswer(ctx, deps, runId, stream, modelAlias, response, metrics) {
|
|
1476
|
+
if (stream === undefined) {
|
|
1477
|
+
recordGatewayOutcome(ctx, deps, runId, "accepted", metrics.completionTokens, metrics.outputBytes);
|
|
1478
|
+
return openAiResponse(modelAlias, response);
|
|
1479
|
+
}
|
|
1480
|
+
completeBufferedOpenAiStream(stream, response);
|
|
1481
|
+
recordGatewayOutcome(ctx, deps, runId, ctx.res.writableEnded && !ctx.res.destroyed ? "accepted" : "cancelled", metrics.completionTokens, metrics.outputBytes);
|
|
1482
|
+
return STREAMING;
|
|
1255
1483
|
}
|
|
1256
1484
|
// Closed stream state machine keeps iterator, cancellation, and SSE backpressure transitions together.
|
|
1257
1485
|
async function streamGatewayChat(ctx, dispatch) {
|
|
@@ -1261,15 +1489,16 @@ async function streamGatewayChat(ctx, dispatch) {
|
|
|
1261
1489
|
iterator = chatStreamFactoryFor(deps, binding.gateway)(binding.config, modelAlias)(request)[Symbol.asyncIterator]();
|
|
1262
1490
|
}
|
|
1263
1491
|
catch (error) {
|
|
1264
|
-
recordGatewayOutcome(deps, runId, "failed", 0, 0);
|
|
1265
|
-
emitGatewayFailureDiagnostic(ctx, deps, error);
|
|
1492
|
+
recordGatewayOutcome(ctx, deps, runId, "failed", 0, 0);
|
|
1493
|
+
emitGatewayFailureDiagnostic(ctx, deps, error, runId);
|
|
1494
|
+
reportGatewayTurnFailure(ctx, deps, runId, gatewayTurnFailureCode(error));
|
|
1266
1495
|
settlePromptTokenReservation(deps, promptTokenReservation);
|
|
1267
1496
|
return unavailableError();
|
|
1268
1497
|
}
|
|
1269
1498
|
const session = createGatewayStreamSession(ctx, dispatch, iterator);
|
|
1270
1499
|
try {
|
|
1271
1500
|
if (beginGatewayStream(session))
|
|
1272
|
-
await pumpGatewayStreamWithCancellation(
|
|
1501
|
+
await pumpGatewayStreamWithCancellation(deps, session);
|
|
1273
1502
|
return STREAMING;
|
|
1274
1503
|
}
|
|
1275
1504
|
finally {
|
|
@@ -1279,7 +1508,7 @@ async function streamGatewayChat(ctx, dispatch) {
|
|
|
1279
1508
|
settlePromptTokenReservation(session.deps, session.promptTokenReservation);
|
|
1280
1509
|
}
|
|
1281
1510
|
}
|
|
1282
|
-
async function pumpGatewayStreamWithCancellation(
|
|
1511
|
+
async function pumpGatewayStreamWithCancellation(deps, session) {
|
|
1283
1512
|
const { cancellationSignal, iterator } = session;
|
|
1284
1513
|
const cancelIterator = () => {
|
|
1285
1514
|
void iterator.return?.();
|
|
@@ -1289,7 +1518,10 @@ async function pumpGatewayStreamWithCancellation(ctx, deps, session) {
|
|
|
1289
1518
|
await pumpGatewayStream(session);
|
|
1290
1519
|
}
|
|
1291
1520
|
catch (error) {
|
|
1292
|
-
emitGatewayStreamFailureDiagnostic(ctx, deps, error);
|
|
1521
|
+
emitGatewayStreamFailureDiagnostic(session.ctx, deps, error, session.runId);
|
|
1522
|
+
if (!session.cancellationSignal.aborted) {
|
|
1523
|
+
reportGatewayTurnFailure(session.ctx, deps, session.runId, gatewayStreamFailureCode(error));
|
|
1524
|
+
}
|
|
1293
1525
|
settleGatewayStreamError(session);
|
|
1294
1526
|
}
|
|
1295
1527
|
finally {
|
|
@@ -1333,8 +1565,8 @@ function beginGatewayStream(session) {
|
|
|
1333
1565
|
return true;
|
|
1334
1566
|
}
|
|
1335
1567
|
function recordSessionOutcome(session, outcome) {
|
|
1336
|
-
const { deps, runId, metrics } = session;
|
|
1337
|
-
recordGatewayOutcome(deps, runId, outcome, metrics.completionTokens, metrics.outputBytes);
|
|
1568
|
+
const { ctx, deps, runId, metrics } = session;
|
|
1569
|
+
recordGatewayOutcome(ctx, deps, runId, outcome, metrics.completionTokens, metrics.outputBytes);
|
|
1338
1570
|
}
|
|
1339
1571
|
function writeSessionTerminal(session, finishReason) {
|
|
1340
1572
|
const { ctx, id, created, modelId, metrics } = session;
|
|
@@ -1364,8 +1596,8 @@ async function pumpGatewayStream(session) {
|
|
|
1364
1596
|
await streamGatewayResponse(session, chunk.response);
|
|
1365
1597
|
return;
|
|
1366
1598
|
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1599
|
+
// A stream without a terminal response must reach the shared diagnostic and turn-event path.
|
|
1600
|
+
throw new ProviderError("provider stream ended without a terminal response", 200);
|
|
1369
1601
|
}
|
|
1370
1602
|
/** Returns true when the stream may continue with the next chunk. */
|
|
1371
1603
|
async function streamGatewayDelta(session, token) {
|
|
@@ -1392,11 +1624,11 @@ async function streamGatewayDelta(session, token) {
|
|
|
1392
1624
|
async function streamGatewayResponse(session, response) {
|
|
1393
1625
|
const { ctx, id, created, modelId, request, iterator, metrics, promptTokenReservation } = session;
|
|
1394
1626
|
const outcome = outputMetrics(response);
|
|
1395
|
-
metrics.
|
|
1396
|
-
metrics.outputBytes = outcome.outputBytes;
|
|
1627
|
+
metrics.outputBytes = Math.max(outcome.outputBytes, metrics.outputBytes);
|
|
1397
1628
|
metrics.promptTokens = response.usage.promptTokens;
|
|
1398
|
-
settlePromptTokenReservation(session.deps, promptTokenReservation, response.usage.promptTokens);
|
|
1399
|
-
|
|
1629
|
+
const promptSettlement = settlePromptTokenReservation(session.deps, promptTokenReservation, response.usage.promptTokens);
|
|
1630
|
+
settleStreamCompletionUsage(session, response, outcome, promptSettlement);
|
|
1631
|
+
if (exceedsOutputBudget(metrics, request.maxOutputTokens ?? 1)) {
|
|
1400
1632
|
await iterator.return?.();
|
|
1401
1633
|
recordSessionOutcome(session, "output-limit");
|
|
1402
1634
|
writeSessionTerminal(session, "length");
|
|
@@ -1411,8 +1643,49 @@ async function streamGatewayResponse(session, response) {
|
|
|
1411
1643
|
return;
|
|
1412
1644
|
}
|
|
1413
1645
|
}
|
|
1414
|
-
recordSessionOutcome(session, "accepted");
|
|
1415
1646
|
writeSessionTerminal(session, response.finishReason);
|
|
1647
|
+
recordSessionOutcome(session, ctx.res.writableEnded && !ctx.res.destroyed ? "accepted" : "cancelled");
|
|
1648
|
+
}
|
|
1649
|
+
function settleStreamCompletionUsage(session, response, outcome, promptSettlement) {
|
|
1650
|
+
const { metrics, ctx, runId } = session;
|
|
1651
|
+
const usage = completionUsage(response, outcome.outputBytes, metrics.completionTokens);
|
|
1652
|
+
metrics.completionTokens = usage.completionTokens;
|
|
1653
|
+
logGatewayCompletionUsage(ctx, runId, {
|
|
1654
|
+
completionTokens: metrics.completionTokens,
|
|
1655
|
+
outputBytes: Math.max(outcome.outputBytes, metrics.outputBytes),
|
|
1656
|
+
}, usage.source, promptSettlement);
|
|
1657
|
+
}
|
|
1658
|
+
function completionUsage(response, outputBytes, streamedCompletionTokens) {
|
|
1659
|
+
if (response.usage.completionTokens > 0) {
|
|
1660
|
+
return { completionTokens: response.usage.completionTokens, source: "provider-reported" };
|
|
1661
|
+
}
|
|
1662
|
+
if (response.toolCalls.length > 0 || response.structuredOutput !== null) {
|
|
1663
|
+
return {
|
|
1664
|
+
completionTokens: Math.ceil(outputBytes / OUTPUT_BYTES_PER_TOKEN_LIMIT),
|
|
1665
|
+
source: "output-byte-estimate",
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
if (streamedCompletionTokens > 0) {
|
|
1669
|
+
return { completionTokens: streamedCompletionTokens, source: "streamed-byte-estimate" };
|
|
1670
|
+
}
|
|
1671
|
+
const hasOutput = response.content.length > 0;
|
|
1672
|
+
return {
|
|
1673
|
+
completionTokens: hasOutput ? Math.ceil(outputBytes / OUTPUT_BYTES_PER_TOKEN_LIMIT) : 0,
|
|
1674
|
+
source: "output-byte-estimate",
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
function logGatewayCompletionUsage(ctx, runId, metrics, source, promptSettlement) {
|
|
1678
|
+
getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_USAGE_SETTLED_OPERATION, { correlationId: correlationIdOrUnknown(ctx.correlationId), parentCorrelationId: runId }, {
|
|
1679
|
+
runId,
|
|
1680
|
+
completionTokens: metrics.completionTokens,
|
|
1681
|
+
promptTokens: promptSettlement.promptTokens,
|
|
1682
|
+
promptSource: promptSettlement.source,
|
|
1683
|
+
promptSettlementStatus: promptSettlement.status,
|
|
1684
|
+
outputBytes: metrics.outputBytes,
|
|
1685
|
+
source,
|
|
1686
|
+
completeness: "complete",
|
|
1687
|
+
loss: "none",
|
|
1688
|
+
}));
|
|
1416
1689
|
}
|
|
1417
1690
|
function settleGatewayStreamError(session) {
|
|
1418
1691
|
if (!session.cancellationSignal.aborted) {
|
|
@@ -1613,7 +1886,7 @@ export async function handleCodingSidecarGatewayChatCompletions(ctx, deps) {
|
|
|
1613
1886
|
activeCodingGatewayRequests -= 1;
|
|
1614
1887
|
}
|
|
1615
1888
|
}
|
|
1616
|
-
function logChatRequestRejection(ctx, runId, validationError, observed) {
|
|
1889
|
+
function logChatRequestRejection(ctx, deps, runId, validationError, observed) {
|
|
1617
1890
|
const reason = classifyBadRequestReason(validationError);
|
|
1618
1891
|
const boundedEvidence = observed !== undefined &&
|
|
1619
1892
|
(reason === "input-messages-exceeded" || reason === "prompt-tokens-exceeded")
|
|
@@ -1625,15 +1898,16 @@ function logChatRequestRejection(ctx, runId, validationError, observed) {
|
|
|
1625
1898
|
}
|
|
1626
1899
|
: undefined;
|
|
1627
1900
|
logGatewayRejection(ctx, runId, validationError.status, reason, boundedEvidence);
|
|
1901
|
+
reportGatewayTurnFailure(ctx, deps, runId, "turn-rejected");
|
|
1628
1902
|
}
|
|
1629
|
-
async function readValidatedChatRequest(ctx, resolved, authentication) {
|
|
1903
|
+
async function readValidatedChatRequest(ctx, deps, resolved, authentication) {
|
|
1630
1904
|
const parsed = await readChatCompletionRequest(ctx, resolved.result.runMetadata.maxRequestBytes);
|
|
1631
1905
|
const estimatedPromptTokens = isRouteResult(parsed)
|
|
1632
1906
|
? 0
|
|
1633
1907
|
: promptTokenEstimate(parsed, promptTokenAccounting(resolved));
|
|
1634
1908
|
const validationError = validationErrorForChatRequest(parsed, resolved.result.modelAlias, resolved.result.runMetadata, authentication.runtimeAuthenticated, estimatedPromptTokens);
|
|
1635
1909
|
if (validationError !== undefined) {
|
|
1636
|
-
logChatRequestRejection(ctx, authentication.runId, validationError, isRouteResult(parsed)
|
|
1910
|
+
logChatRequestRejection(ctx, deps, authentication.runId, validationError, isRouteResult(parsed)
|
|
1637
1911
|
? undefined
|
|
1638
1912
|
: { parsed, bounds: resolved.result.runMetadata, estimatedPromptTokens });
|
|
1639
1913
|
return validationError;
|
|
@@ -1649,7 +1923,7 @@ async function runHandleCodingSidecarGatewayChatCompletions(ctx, deps) {
|
|
|
1649
1923
|
const resolved = resolveAuthenticatedGatewayProfile(deps, authentication);
|
|
1650
1924
|
if (!isAvailableGatewayProfile(resolved))
|
|
1651
1925
|
return unavailableGatewayProfile(ctx, deps, resolved, authentication);
|
|
1652
|
-
const validated = await readValidatedChatRequest(ctx, resolved, authentication);
|
|
1926
|
+
const validated = await readValidatedChatRequest(ctx, deps, resolved, authentication);
|
|
1653
1927
|
if (isRouteResult(validated))
|
|
1654
1928
|
return validated;
|
|
1655
1929
|
const { parsed, estimatedPromptTokens } = validated;
|
|
@@ -1667,7 +1941,10 @@ async function runHandleCodingSidecarGatewayChatCompletions(ctx, deps) {
|
|
|
1667
1941
|
});
|
|
1668
1942
|
}
|
|
1669
1943
|
function logValidatedRequestBounds(ctx, runId, request, bounds, estimatedPromptTokens) {
|
|
1670
|
-
getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_REQUEST_VALIDATED_OPERATION, {
|
|
1944
|
+
getServerLogger().info(activityLogEvent(CODING_SIDECAR_GATEWAY_REQUEST_VALIDATED_OPERATION, {
|
|
1945
|
+
correlationId: correlationIdOrUnknown(ctx.correlationId),
|
|
1946
|
+
parentCorrelationId: runId,
|
|
1947
|
+
}, {
|
|
1671
1948
|
runId,
|
|
1672
1949
|
maxRequestBytes: bounds.maxRequestBytes,
|
|
1673
1950
|
maxPromptTokens: bounds.maxPromptTokens,
|
|
@@ -1681,6 +1958,7 @@ function executeBudgetedGatewayChat(ctx, deps, binding, parsed, authentication,
|
|
|
1681
1958
|
const promptTokenReservation = reserveGatewayPromptBudget(deps, authentication.capability, authentication.runId, estimatedPromptTokens);
|
|
1682
1959
|
if (promptTokenReservation === undefined) {
|
|
1683
1960
|
logGatewayRejection(ctx, authentication.runId, 403, "runtime-prompt-budget-denied");
|
|
1961
|
+
reportGatewayTurnFailure(ctx, deps, authentication.runId, "turn-rejected");
|
|
1684
1962
|
return Promise.resolve(forbiddenGatewayRequest());
|
|
1685
1963
|
}
|
|
1686
1964
|
return executeGatewayChat(ctx, deps, binding, parsed, authentication.runId, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscharko-dev/keiko-server",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Internal server package: local loopback BFF runtime (HTTP/SSE/WebSocket router, CSP, host check, CSRF gate, terminal, browser, files, run engine, SQLite-backed UI store) that mediates the browser presentation tier and the Node-side domain packages (ADR-0019). Not published independently.",
|
|
@@ -55,26 +55,26 @@
|
|
|
55
55
|
},
|
|
56
56
|
"private": true,
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@oscharko-dev/keiko-connectors": "1.1.
|
|
59
|
-
"@oscharko-dev/keiko-contracts": "1.1.
|
|
60
|
-
"@oscharko-dev/keiko-evidence": "1.1.
|
|
61
|
-
"@oscharko-dev/keiko-git": "1.1.
|
|
62
|
-
"@oscharko-dev/keiko-harness": "1.1.
|
|
63
|
-
"@oscharko-dev/keiko-local-knowledge": "1.1.
|
|
64
|
-
"@oscharko-dev/keiko-memory-capture": "1.1.
|
|
65
|
-
"@oscharko-dev/keiko-memory-consolidation": "1.1.
|
|
66
|
-
"@oscharko-dev/keiko-memory-governance": "1.1.
|
|
67
|
-
"@oscharko-dev/keiko-memory-retrieval": "1.1.
|
|
68
|
-
"@oscharko-dev/keiko-memory-vault": "1.1.
|
|
69
|
-
"@oscharko-dev/keiko-model-gateway": "1.1.
|
|
70
|
-
"@oscharko-dev/keiko-quality-intelligence": "1.1.
|
|
71
|
-
"@oscharko-dev/keiko-sandbox": "1.1.
|
|
72
|
-
"@oscharko-dev/keiko-sdk": "1.1.
|
|
73
|
-
"@oscharko-dev/keiko-security": "1.1.
|
|
74
|
-
"@oscharko-dev/keiko-tool-catalog": "1.1.
|
|
75
|
-
"@oscharko-dev/keiko-tools": "1.1.
|
|
76
|
-
"@oscharko-dev/keiko-verification": "1.1.
|
|
77
|
-
"@oscharko-dev/keiko-workflows": "1.1.
|
|
78
|
-
"@oscharko-dev/keiko-workspace": "1.1.
|
|
58
|
+
"@oscharko-dev/keiko-connectors": "1.1.6",
|
|
59
|
+
"@oscharko-dev/keiko-contracts": "1.1.6",
|
|
60
|
+
"@oscharko-dev/keiko-evidence": "1.1.6",
|
|
61
|
+
"@oscharko-dev/keiko-git": "1.1.6",
|
|
62
|
+
"@oscharko-dev/keiko-harness": "1.1.6",
|
|
63
|
+
"@oscharko-dev/keiko-local-knowledge": "1.1.6",
|
|
64
|
+
"@oscharko-dev/keiko-memory-capture": "1.1.6",
|
|
65
|
+
"@oscharko-dev/keiko-memory-consolidation": "1.1.6",
|
|
66
|
+
"@oscharko-dev/keiko-memory-governance": "1.1.6",
|
|
67
|
+
"@oscharko-dev/keiko-memory-retrieval": "1.1.6",
|
|
68
|
+
"@oscharko-dev/keiko-memory-vault": "1.1.6",
|
|
69
|
+
"@oscharko-dev/keiko-model-gateway": "1.1.6",
|
|
70
|
+
"@oscharko-dev/keiko-quality-intelligence": "1.1.6",
|
|
71
|
+
"@oscharko-dev/keiko-sandbox": "1.1.6",
|
|
72
|
+
"@oscharko-dev/keiko-sdk": "1.1.6",
|
|
73
|
+
"@oscharko-dev/keiko-security": "1.1.6",
|
|
74
|
+
"@oscharko-dev/keiko-tool-catalog": "1.1.6",
|
|
75
|
+
"@oscharko-dev/keiko-tools": "1.1.6",
|
|
76
|
+
"@oscharko-dev/keiko-verification": "1.1.6",
|
|
77
|
+
"@oscharko-dev/keiko-workflows": "1.1.6",
|
|
78
|
+
"@oscharko-dev/keiko-workspace": "1.1.6"
|
|
79
79
|
}
|
|
80
80
|
}
|