From 063b7e0f11b0a6a414594246d6c46b3edbeb3903 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 17 Nov 2025 12:46:59 +0100 Subject: [PATCH] chore: bump coding-agent to 0.7.14 - fix Anthropic OAuth and Mistral API compatibility --- packages/ai/src/agent/agent-loop.ts | 3 + .../ai/src/providers/openai-completions.ts | 22 +- packages/coding-agent/CHANGELOG.md | 9 + packages/coding-agent/package.json | 2 +- packages/coding-agent/src/model-config.ts | 8 + .../coding-agent/src/tui/assistant-message.ts | 3 +- test.html | 9 + threejs-demo.html | 199 ++++++++++++++++++ threejs-scene.html | 55 +++++ 9 files changed, 303 insertions(+), 7 deletions(-) create mode 100644 test.html create mode 100644 threejs-demo.html create mode 100644 threejs-scene.html diff --git a/packages/ai/src/agent/agent-loop.ts b/packages/ai/src/agent/agent-loop.ts index e93d5f7d..32d727d0 100644 --- a/packages/ai/src/agent/agent-loop.ts +++ b/packages/ai/src/agent/agent-loop.ts @@ -164,6 +164,9 @@ async function streamAssistantResponse( } else { context.messages.push(finalMessage); } + if (!addedPartial) { + stream.push({ type: "message_start", message: { ...finalMessage } }); + } stream.push({ type: "message_end", message: finalMessage }); return finalMessage; } diff --git a/packages/ai/src/providers/openai-completions.ts b/packages/ai/src/providers/openai-completions.ts index 8740d0fe..7f45d28d 100644 --- a/packages/ai/src/providers/openai-completions.ts +++ b/packages/ai/src/providers/openai-completions.ts @@ -273,13 +273,22 @@ function buildParams(model: Model<"openai-completions">, context: Context, optio stream_options: { include_usage: true }, }; - // Cerebras/xAI dont like the "store" field - if (!model.baseUrl.includes("cerebras.ai") && !model.baseUrl.includes("api.x.ai")) { + // Cerebras/xAI/Mistral dont like the "store" field + if ( + !model.baseUrl.includes("cerebras.ai") && + !model.baseUrl.includes("api.x.ai") && + !model.baseUrl.includes("mistral.ai") + ) { params.store = false; } if (options?.maxTokens) { - params.max_completion_tokens = options?.maxTokens; + // Mistral uses max_tokens instead of max_completion_tokens + if (model.baseUrl.includes("mistral.ai")) { + (params as any).max_tokens = options?.maxTokens; + } else { + params.max_completion_tokens = options?.maxTokens; + } } if (options?.temperature !== undefined) { @@ -308,9 +317,12 @@ function convertMessages(model: Model<"openai-completions">, context: Context): const transformedMessages = transformMessages(context.messages, model); if (context.systemPrompt) { - // Cerebras/xAi don't like the "developer" role + // Cerebras/xAi/Mistral don't like the "developer" role const useDeveloperRole = - model.reasoning && !model.baseUrl.includes("cerebras.ai") && !model.baseUrl.includes("api.x.ai"); + model.reasoning && + !model.baseUrl.includes("cerebras.ai") && + !model.baseUrl.includes("api.x.ai") && + !model.baseUrl.includes("mistral.ai"); const role = useDeveloperRole ? "developer" : "system"; params.push({ role: role, content: sanitizeSurrogates(context.systemPrompt) }); } diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 4178b1b5..7189c833 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -2,6 +2,15 @@ ## [Unreleased] +## [0.7.14] - 2025-11-17 + +### Fixed + +- **Anthropic OAuth Support**: Added support for `ANTHROPIC_OAUTH_TOKEN` environment variable. The agent now checks for OAuth tokens before falling back to API keys for Anthropic models, enabling OAuth-based authentication. +- **Mistral API Compatibility**: Fixed compatibility with Mistral API by excluding the `store` field and using `max_tokens` instead of `max_completion_tokens`, and avoiding the `developer` role in system prompts. +- **Error Display**: Fixed error message display in assistant messages to include proper spacing before the error text. +- **Message Streaming**: Fixed missing `message_start` event when no partial message chunks were received during streaming. + ## [0.7.13] - 2025-11-16 ### Fixed diff --git a/packages/coding-agent/package.json b/packages/coding-agent/package.json index ee76c2aa..9ac4034e 100644 --- a/packages/coding-agent/package.json +++ b/packages/coding-agent/package.json @@ -1,6 +1,6 @@ { "name": "@mariozechner/pi-coding-agent", - "version": "0.7.13", + "version": "0.7.14", "description": "Coding agent CLI with read, bash, edit, write tools and session management", "type": "module", "bin": { diff --git a/packages/coding-agent/src/model-config.ts b/packages/coding-agent/src/model-config.ts index 981895dc..b82a701e 100644 --- a/packages/coding-agent/src/model-config.ts +++ b/packages/coding-agent/src/model-config.ts @@ -226,6 +226,14 @@ export function getApiKeyForModel(model: Model): string | undefined { return resolveApiKey(customKeyConfig); } + // For Anthropic, check ANTHROPIC_OAUTH_KEY first + if (model.provider === "anthropic") { + const oauthKey = process.env.ANTHROPIC_OAUTH_TOKEN; + if (oauthKey) { + return oauthKey; + } + } + // For built-in providers, use getApiKey from @mariozechner/pi-ai return getApiKey(model.provider as KnownProvider); } diff --git a/packages/coding-agent/src/tui/assistant-message.ts b/packages/coding-agent/src/tui/assistant-message.ts index 450418fd..587a2b92 100644 --- a/packages/coding-agent/src/tui/assistant-message.ts +++ b/packages/coding-agent/src/tui/assistant-message.ts @@ -56,7 +56,8 @@ export class AssistantMessageComponent extends Container { this.contentContainer.addChild(new Text(chalk.red("\nAborted"), 1, 0)); } else if (message.stopReason === "error") { const errorMsg = message.errorMessage || "Unknown error"; - this.contentContainer.addChild(new Text(chalk.red(`Error: ${errorMsg}`))); + this.contentContainer.addChild(new Spacer(1)); + this.contentContainer.addChild(new Text(chalk.red(`Error: ${errorMsg}`), 1, 0)); } } } diff --git a/test.html b/test.html new file mode 100644 index 00000000..f237c4ff --- /dev/null +++ b/test.html @@ -0,0 +1,9 @@ + + + + Test Page + + +

Hello, World!

+ + \ No newline at end of file diff --git a/threejs-demo.html b/threejs-demo.html new file mode 100644 index 00000000..fb7ff1e1 --- /dev/null +++ b/threejs-demo.html @@ -0,0 +1,199 @@ + + + + + + Three.js Interactive Demo + + + +
+

Three.js Interactive Demo

+

🖱️ Click & drag to rotate

+

🔄 Scroll to zoom in/out

+

✨ Multiple interactive objects

+
+ + + + + + \ No newline at end of file diff --git a/threejs-scene.html b/threejs-scene.html new file mode 100644 index 00000000..a8886c2b --- /dev/null +++ b/threejs-scene.html @@ -0,0 +1,55 @@ + + + + + + Three.js 3D Scene + + + + + + + \ No newline at end of file