Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/ai-proxy/lib/chat-to-responses-body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("chat-to-responses-body", () => {
"responses"
);

const parsed = SafeJSON.parse(rewritten) as { input?: unknown[]; messages?: unknown; model: string };
const parsed = SafeJSON.parse(rewritten.bodyText) as { input?: unknown[]; messages?: unknown; model: string };
expect(parsed.model).toBe("grok-composer-2.5-fast");
expect(parsed.input?.length).toBe(1);
expect(parsed.messages).toBeUndefined();
Expand Down
4 changes: 2 additions & 2 deletions src/ai-proxy/lib/config-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ describe("config-store migration", () => {
expect(config.public?.tunnelName).toBeUndefined();
});

it("defaults thinking presentation to raw", () => {
it("defaults thinking presentation to cursor", () => {
const config = parseConfigJson(SafeJSON.stringify({}));
expect(config.translation.thinking).toBe("raw");
expect(config.translation.thinking).toBe("cursor");
});

it("loadFresh reads disk without stale in-process cache", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/ai-proxy/lib/config-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getDefaultConfig(): AiProxyConfig {
return {
listen: { host: "127.0.0.1", port: 8317 },
proxyApiKey: `aipx-${crypto.randomUUID().replace(/-/g, "")}`,
translation: { cursorAgent: "auto", thinking: "raw" },
translation: { cursorAgent: "auto", thinking: "cursor" },
public: { mode: "none", basePath: "/ai" },
accounts: [],
};
Expand Down
53 changes: 53 additions & 0 deletions src/ai-proxy/lib/grok-chat-sse-enricher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from "bun:test";
import { enrichGrokChatResponse } from "@app/ai-proxy/lib/grok-chat-sse-enricher";

describe("grok-chat-sse-enricher", () => {
it("cursor mode rewrites model to proxy id and adds reasoning_items on first thinking delta", async () => {
const sse = [
'data: {"model":"grok-build-0.1","choices":[{"index":0,"delta":{"reasoning_content":"Hmm","role":"assistant"}}]}',
'data: {"model":"grok-build-0.1","choices":[{"index":0,"delta":{"content":"Answer"}}]}',
"",
"data: [DONE]\r",
"",
].join("\n");

const response = await enrichGrokChatResponse(
new Response(sse, {
headers: { "Content-Type": "text/event-stream" },
}),
"martin/grok/grok-build-0.1",
"cursor"
);

const body = await response.text();

expect(body).toContain('"model":"martin/grok/grok-build-0.1"');
expect(body).toContain('"reasoning_content":"Hmm"');
expect(body).toContain('"reasoning_items"');
expect(body).toContain('"type":"reasoning"');
expect(body).toContain('"content":"Answer"');
expect(body).not.toContain("<details>");
});

it("folded mode moves reasoning into content only", async () => {
const sse = [
'data: {"model":"grok-composer-2.5-fast","choices":[{"delta":{"reasoning_content":"Hmm","role":"assistant"}}]}',
"",
"data: [DONE]",
"",
].join("\n");

const response = await enrichGrokChatResponse(
new Response(sse, {
headers: { "Content-Type": "text/event-stream" },
}),
"martin/grok/grok-composer-2.5-fast",
"folded"
);

const body = await response.text();

expect(body).toContain("<details>");
expect(body).not.toContain("reasoning_content");
});
});
Loading
Loading