Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/adapters/kiro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { decodeEventStream } from "../lib/eventstream-decoder";
import { estimateTokens } from "../lib/token-estimate";
import { debugProviderDiagnostic } from "../lib/debug";
import { isDebugEnabled } from "../lib/debug-settings";
import { resolveKiroApiRegion, resolveKiroProfileArn } from "../oauth/kiro";
import { KIRO_MODEL_CONTEXT_WINDOWS, normalizeKiroModelId } from "../providers/kiro-models";
import { modelRecordValue } from "../reasoning-effort";
Expand Down Expand Up @@ -1755,17 +1756,19 @@ export function createKiroAdapter(provider: OcxProviderConfig): ProviderAdapter
await normalizeKiroImages(built.payload);
const contextInputEstimate = estimateKiroPayloadInputTokens(built.payload, parsed.modelId);
const body = JSON.stringify(built.payload);
debugProviderDiagnostic("kiro", "request", {
region,
requestedModel: parsed.modelId,
completionMode: built.completionMode,
bodyBytes: new TextEncoder().encode(body).length,
messageCount: kiroPayloadMessages(parsed).length,
toolCount: parsed.context.tools?.length ?? 0,
hasProfileArn: Boolean(profileArn),
wireClient,
hasPreviousResponseId: Boolean(parsed.previousResponseId),
});
if (isDebugEnabled()) {
debugProviderDiagnostic("kiro", "request", {
region,
requestedModel: parsed.modelId,
completionMode: built.completionMode,
bodyBytes: new TextEncoder().encode(body).length,
messageCount: kiroPayloadMessages(parsed).length,
toolCount: parsed.context.tools?.length ?? 0,
hasProfileArn: Boolean(profileArn),
wireClient,
hasPreviousResponseId: Boolean(parsed.previousResponseId),
});
}
return {
request: {
url: kiroRuntimeEndpoint(provider, region),
Expand Down
13 changes: 13 additions & 0 deletions tests/kiro-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,19 @@ describe("kiro adapter — parseStream", () => {
error.mockRestore();
}
});

test("buildRequest does not encode the request body for diagnostics when debug is disabled", async () => {
const encode = spyOn(TextEncoder.prototype, "encode").mockImplementation(() => {
throw new Error("diagnostic encoding must stay behind the debug gate");
Comment on lines +1732 to +1734

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Explicitly disable all provider-debug sources in this test

When the test suite is launched with the supported OCX_DEBUG=1 environment setting, this test enters the diagnostic branch and the mocked encoder throws; this is reproducible with OCX_DEBUG=1 bun test tests/kiro-stream.test.ts --test-name-pattern 'buildRequest does not encode'. The shared setup only deletes legacy OCX_DEBUG_FRAMES, while isDebugEnabled() also reads OCX_DEBUG and runtime overrides, so explicitly clear/reset those sources (or force the runtime debug setting off) before asserting that diagnostics are disabled.

AGENTS.md reference: AGENTS.md:L228-L230

Useful? React with 👍 / 👎.

});
try {
const request = await createKiroAdapter(provider).buildRequest(parsedWith([{ role: "user", content: "hello" }]));
expect(typeof request.body).toBe("string");
expect(encode).not.toHaveBeenCalled();
} finally {
encode.mockRestore();
}
});
});

describe("kiro adapter — parseResponse (web-search sidecar non-streaming path)", () => {
Expand Down
Loading