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
4 changes: 4 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ composable integration value:
| `streamfold/langchain` | `langchain` |
| `streamfold/ag-ui` | `agUI` |

The Anthropic integration accepts both `client.messages.create({ ..., stream: true })`
and `client.beta.messages.create({ ..., stream: true })` directly. Text, thinking,
and other non-tool SDK events can remain in the stream and are ignored.

The OpenAI integration accepts `client.responses.create({ ..., stream: true })`
directly, including SDK event interfaces for text and other non-tool events.
Non-tool events are ignored; callers do not need to cast or filter the stream.
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Accept Anthropic stable and beta SDK message event interfaces directly in
the Anthropic adapter and managed reader.
- Accept OpenAI SDK response stream event types directly in the OpenAI adapter
and managed reader, including non-tool events.
- Preserve Gemini Interactions tool arguments from `arguments_delta` events
Expand Down
2 changes: 1 addition & 1 deletion examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"checkJs": true,
"skipLibCheck": true
},
"files": ["assistant-ui.mjs", "vercel-ai.mjs", "custom.mjs", "../tests/langchain-sdk.ts", "../tests/gemini-sdk.ts", "../tests/openai-sdk.ts"]
"files": ["assistant-ui.mjs", "vercel-ai.mjs", "custom.mjs", "../tests/langchain-sdk.ts", "../tests/gemini-sdk.ts", "../tests/openai-sdk.ts", "../tests/anthropic-sdk.ts"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"verify": "pnpm check && pnpm pack:check && pnpm bench && pnpm bench:sdk"
},
"devDependencies": {
"@anthropic-ai/sdk": "1.3.0",
"@google/genai": "2.31.0",
"@langchain/core": "1.3.0",
"ai": "7.0.152",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/anthropic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type AnthropicToolInputEvent =
readonly type: "content_block_stop";
readonly index: number;
}
| { readonly type: string }
| {
readonly type: string;
readonly index?: number;
Expand Down
73 changes: 69 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/anthropic-sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Anthropic from "@anthropic-ai/sdk";
import { readStructured } from "streamfold";
import { anthropic } from "streamfold/anthropic";

const client = new Anthropic({ apiKey: "typecheck-only" });
const request = {
model: "fixture", max_tokens: 32,
messages: [{ role: "user" as const, content: "Weather in Paris?" }],
stream: true as const,
};
const events = await client.messages.create(request);
readStructured(events, { integration: anthropic });
const stream = anthropic();
for await (const event of events) stream.pushAll(event);

const betaEvents = await client.beta.messages.create(request);
readStructured(betaEvents, { integration: anthropic });
const betaStream = anthropic();
for await (const event of betaEvents) betaStream.push(event);
stream.pushAll({ type: "provider_metadata", metadata: { region: "test" } });
Loading