Skip to content
Closed
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
28 changes: 6 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,47 +390,31 @@ jobs:
working-directory: bindings/flutter/example
run: flutter test

# ── Contract tests: shared JSON fixtures (catches cross-language type drift) ──
# Generated files must match their generators.
contract-tests:
name: Contract tests
name: Generator drift checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Providers doc generator drift (docs/api/providers.md must match generator output)
run: python3 scripts/gen_providers_doc.py --check
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Run Rust contract tests
run: cargo test --test contract_test -p aimux-core
- name: ts-rs export drift (checked-in types must match generator output)
run: python3 scripts/gen_ts_types.py --check
- name: Build Node binding
working-directory: bindings/node
run: |
npm ci
npx napi build --platform
- name: Run Node contract tests
working-directory: contract-tests
run: |
node --experimental-strip-types run-node.ts

# ── Swift contract tests: the eighth binding joins the shared fixtures ─────
# Needs macOS (XCTest) and the FFI cdylib, which the Swift package links via
# the CAimuxFFI system module. The Dart side needs no job here: flutter-binding
# already runs `flutter test`, which picks up bindings/flutter/test/contract_test.dart.
# Swift tests need macOS (XCTest) and the FFI cdylib, which the Swift package
# links via the CAimuxFFI system module.
swift-contract-tests:
name: Swift contract tests
name: Swift tests
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build the FFI library the Swift package links against
run: cargo build -p aimux-ffi --release
- name: Run Swift contract tests
- name: Run Swift tests
working-directory: bindings/swift
env:
DYLD_LIBRARY_PATH: ${{ github.workspace }}/target/release
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking

- Tool-call and tool-result types are unified, one per protocol layer
(`aimux-core`). A provider emits `tool::RawToolCall` (`input` is the raw
argument text) in `GenerateContent::ToolCall(..)` and
`StreamPart::ToolCall(..)`, and `tool::ToolResult` in the `ToolResult`
variants; these variants are newtype variants now. `StreamPart` is generic
over the tool-call type: a provider's `do_stream` yields `StreamPart`
(= `StreamPart<RawToolCall>`), `stream_text` and everything after it yield
`TextStreamPart` (= `StreamPart<ToolCall>`, parsed input with `invalid` /
`error`). `RawToolCall` moved from `parse_tool_call` to `tool`. Wire format:
enum variants keep their JSON shape; a provider-layer `StreamPart::ToolCall`
has a string `input` and no `invalid` / `error`; a
`GenerateContent::ToolCall` with a non-string `input` no longer
deserializes; the standalone `tool::ToolResult` gains a required
`tool_name` and optional `dynamic` / `provider_metadata`.

- Removed the generated `ProviderName` type in every binding (Rust enum, TS
const object, Go/Java/Kotlin consts, Swift enum, Dart consts, Python
`Literal`) and `scripts/gen_provider_names.py`. Provider names are plain
Expand Down
7 changes: 1 addition & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ aimux/
├── aimux-provider-utils/ # HTTP utilities: retry, backoff, error parsing, API-key loading, streamed tool-call tracking
├── aimux-ffi/ # C ABI (opaque handle + JSON + push callback) for non-native bindings
├── bindings/ # Node, Python, Swift, Kotlin, Flutter, Go, C — share one Rust core
├── contract-tests/ # Shared JSON fixtures exercised across languages
├── rfc/ # Design docs (RFCs)
├── docs/ # Public product docs (see docs/README.md)
└── scripts/ # Code-generation and maintenance scripts
Expand Down Expand Up @@ -50,9 +49,6 @@ cargo test --workspace

# A single crate
cargo test -p aimux-providers --tests

# Contract tests (cross-language shared fixtures)
cargo test --test contract_test -p aimux-core
```

If you add or change a provider's request/response shapes, record a new
Expand Down Expand Up @@ -108,8 +104,7 @@ Keep the subject line imperative and ≤ 72 characters.
2. Make your change with focused commits.
3. Ensure `cargo fmt`, `cargo clippy -D warnings`, and `cargo test --workspace`
all pass locally. CI runs the same.
4. If you add a provider or binding, include cassette tests or contract
fixtures as appropriate.
4. If you add a provider or binding, include cassette tests.
5. Update the relevant doc (README, `docs/`, or `rfc/`) if your change affects
the public surface.
6. Open a PR against `master` and fill in the template.
Expand Down
6 changes: 0 additions & 6 deletions aimux-core/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ pub enum ContentPart {
/// need it to replay server tool calls on a later turn.
#[serde(default, skip_serializing_if = "Option::is_none")]
provider_executed: Option<bool>,
/// Provider-assigned thought signature (e.g. Google Gemini
/// `thoughtSignature`). Must be echoed back verbatim on the follow-up
/// turn when the tool result is sent.
#[serde(default, skip_serializing_if = "Option::is_none")]
thought_signature: Option<String>,
/// Provider-specific options for this part (e.g.
/// `anthropic.cacheControl`).
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -167,7 +162,6 @@ impl ContentPart {
tool_name: tool_name.into(),
input,
provider_executed: None,
thought_signature: None,
provider_options: None,
}
}
Expand Down
147 changes: 27 additions & 120 deletions aimux-core/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ use crate::language_model::LanguageModel;
use crate::language_model_message::convert_to_language_model_prompt;
use crate::message::{ModelMessage, ModelPrompt};
use crate::options::{CallOptions, ResponseFormat, ToolChoice};
use crate::parse_tool_call::{RawToolCall, ToolCallRepair, parse_tool_call};
use crate::parse_tool_call::{ToolCallRepair, parse_tool_call};
use crate::result::{
FilePart, GenerateContent, GenerateResult, ReasoningPart, SourcePart, StreamResult,
StreamTextResultAggregated,
};
use crate::stream_part::StreamPart;
use crate::stream_part::{StreamPart, TextStreamPart};
use crate::tool::Tool;
use crate::types::{FinishReason, ReasoningEffort, Usage, Warning};
use crate::{AbortSignal, retry, timeout};

/// Matches the AI SDK's `isOutputChunk`: only chunks containing model output
/// start or reset the first/chunk output timers.
fn is_output_chunk(part: &StreamPart) -> bool {
fn is_output_chunk<C>(part: &StreamPart<C>) -> bool {
match part {
StreamPart::TextDelta { delta, .. }
| StreamPart::ReasoningDelta { delta, .. }
| StreamPart::ToolInputDelta { delta, .. } => !delta.is_empty(),
StreamPart::ToolCall { .. } | StreamPart::File { .. } => true,
StreamPart::ToolCall(_) | StreamPart::File { .. } => true,
_ => false,
}
}
Expand Down Expand Up @@ -107,6 +107,12 @@ impl GenerateTextOptions {
self,
prompt: crate::language_model_message::LanguageModelPrompt,
) -> CallOptions {
let tool_choice = self.tool_choice.or_else(|| {
self.tools
.as_ref()
.filter(|tools| !tools.is_empty())
.map(|_| ToolChoice::Auto)
});
CallOptions {
prompt,
max_output_tokens: self.max_output_tokens,
Expand All @@ -119,7 +125,7 @@ impl GenerateTextOptions {
response_format: self.response_format,
seed: self.seed,
tools: self.tools,
tool_choice: self.tool_choice.unwrap_or_default(),
tool_choice,
headers: self.headers,
provider_options: self.provider_options,
reasoning: self.reasoning,
Expand Down Expand Up @@ -221,8 +227,8 @@ pub struct GenerateObjectResult {

/// Result of `stream_text` (user-facing).
pub struct StreamTextResult {
/// The stream of `StreamPart` items.
pub stream: Pin<Box<dyn Stream<Item = Result<StreamPart, AiMuxError>> + Send>>,
/// The stream of `TextStreamPart` items.
pub stream: Pin<Box<dyn Stream<Item = Result<TextStreamPart, AiMuxError>> + Send>>,
/// The request body that was sent (for debugging / cache probing, RFC-0015).
pub request_body: Option<serde_json::Value>,
/// Response headers.
Expand Down Expand Up @@ -373,49 +379,11 @@ impl StreamTextResult {
StreamPart::ReasoningEnd {
provider_metadata, ..
} => rm.reasoning_end(provider_metadata),
StreamPart::ToolCall {
tool_call_id,
tool_name,
input,
provider_executed,
dynamic,
thought_signature,
provider_metadata,
invalid,
error,
..
} => {
let call = crate::tool::ToolCall {
tool_call_id,
tool_name,
input,
provider_executed,
dynamic,
thought_signature,
provider_metadata,
invalid,
error,
};
StreamPart::ToolCall(call) => {
rm.tool_call(&call);
tool_calls.push(call);
}
StreamPart::ToolResult {
tool_call_id,
tool_name,
result,
is_error,
preliminary,
dynamic,
provider_metadata,
} => rm.tool_result(
tool_call_id,
tool_name,
result,
is_error,
preliminary,
dynamic,
provider_metadata,
),
StreamPart::ToolResult(result) => rm.tool_result(result),
StreamPart::Source {
id,
source_type,
Expand Down Expand Up @@ -656,26 +624,9 @@ pub async fn generate_text(
text.push_str(t);
rm.text(t, provider_metadata.as_ref());
}
GenerateContent::ToolCall {
tool_call_id,
tool_name,
input,
provider_executed,
dynamic,
thought_signature,
provider_metadata,
..
} => {
GenerateContent::ToolCall(call) => {
let parsed = parse_tool_call(
RawToolCall {
tool_call_id: tool_call_id.clone(),
tool_name: tool_name.clone(),
input: input.clone(),
provider_executed: *provider_executed,
dynamic: *dynamic,
thought_signature: thought_signature.clone(),
provider_metadata: provider_metadata.clone(),
},
call.clone(),
tools.as_deref(),
repair_tool_call.as_ref(),
&messages,
Expand Down Expand Up @@ -715,25 +666,7 @@ pub async fn generate_text(
}
// Provider-executed results stay in the assistant message so the
// provider can replay its own server-tool transcript next turn.
GenerateContent::ToolResult {
tool_call_id,
tool_name,
result,
is_error,
preliminary,
dynamic,
provider_metadata,
} => {
rm.tool_result(
tool_call_id.clone(),
tool_name.clone(),
result.clone(),
*is_error,
*preliminary,
*dynamic,
provider_metadata.clone(),
);
}
GenerateContent::ToolResult(result) => rm.tool_result(result.clone()),
}
}

Expand Down Expand Up @@ -1097,48 +1030,22 @@ pub async fn stream_text(
})
};
let mut stream = stream;
let stream: Pin<Box<dyn Stream<Item = Result<StreamPart, AiMuxError>> + Send>> =
let stream: Pin<Box<dyn Stream<Item = Result<TextStreamPart, AiMuxError>> + Send>> =
Box::pin(async_stream::stream! {
while let Some(item) = stream.next().await {
match item {
Ok(StreamPart::ToolCall {
tool_call_id,
tool_name,
input,
provider_executed,
dynamic,
thought_signature,
provider_metadata,
..
}) => {
Ok(StreamPart::ToolCall(raw)) => {
let parsed = parse_tool_call(
RawToolCall {
tool_call_id,
tool_name,
input: crate::parse_tool_call::raw_tool_input(&input),
provider_executed,
dynamic,
thought_signature,
provider_metadata,
},
raw,
tools.as_deref(),
repair_tool_call.as_ref(),
&messages,
operation_instructions.as_deref(),
).await;
yield Ok(StreamPart::ToolCall {
tool_call_id: parsed.tool_call_id,
tool_name: parsed.tool_name,
input: parsed.input,
provider_executed: parsed.provider_executed,
dynamic: parsed.dynamic,
thought_signature: parsed.thought_signature,
invalid: parsed.invalid,
error: parsed.error,
provider_metadata: parsed.provider_metadata,
});
yield Ok(StreamPart::ToolCall(parsed));
}
item => yield item,
Ok(part) => yield Ok(part.map_tool_call(|_| unreachable!("matched above"))),
Err(error) => yield Err(error),
}
}
});
Expand Down Expand Up @@ -1749,23 +1656,23 @@ mod stream_aggregation_tests {
use super::*;
use crate::types::FinishReasonUnified;

fn result_from(parts: Vec<Result<StreamPart, AiMuxError>>) -> StreamTextResult {
fn result_from(parts: Vec<Result<TextStreamPart, AiMuxError>>) -> StreamTextResult {
StreamTextResult {
stream: Box::pin(futures::stream::iter(parts)),
request_body: None,
response_headers: None,
}
}

fn delta(text: &str) -> StreamPart {
fn delta(text: &str) -> TextStreamPart {
StreamPart::TextDelta {
id: "text-1".into(),
delta: text.into(),
provider_metadata: None,
}
}

fn finish() -> StreamPart {
fn finish() -> TextStreamPart {
StreamPart::Finish {
finish_reason: FinishReason {
unified: FinishReasonUnified::Stop,
Expand Down
Loading