Skip to content

Commit c8b1507

Browse files
Merge pull request #394 from cloudflare/changeset-release/main
Version Packages
2 parents 6d04476 + 87d8a2a commit c8b1507

3 files changed

Lines changed: 55 additions & 61 deletions

File tree

.changeset/workers-ai-provider-cleanup.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

packages/workers-ai-provider/CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
# workers-ai-provider
22

3+
## 3.0.5
4+
5+
### Patch Changes
6+
7+
- [#393](https://github.com/cloudflare/ai/pull/393) [`91b32e0`](https://github.com/cloudflare/ai/commit/91b32e0b0ef543fd198ddf387b9521ac3bd9650a) Thanks [@threepointone](https://github.com/threepointone)! - Comprehensive cleanup of the workers-ai-provider package.
8+
9+
**Bug fixes:**
10+
- Fixed phantom dependency on `fetch-event-stream` that caused runtime crashes when installed outside the monorepo. Replaced with a built-in SSE parser.
11+
- Fixed streaming buffering: responses now stream token-by-token instead of arriving all at once. The root cause was twofold — an eager `ReadableStream` `start()` pattern that buffered all chunks, and a heuristic that silently fell back to non-streaming `doGenerate` whenever tools were defined. Both are fixed. Streaming now uses a proper `TransformStream` pipeline with backpressure.
12+
- Fixed `reasoning-delta` ID mismatch in simulated streaming — was using `generateId()` instead of the `reasoningId` from the preceding `reasoning-start` event, causing the AI SDK to drop reasoning content.
13+
- Fixed REST API client (`createRun`) silently swallowing HTTP errors. Non-200 responses now throw with status code and response body.
14+
- Fixed `response_format` being sent as `undefined` on every non-JSON request. Now only included when actually set.
15+
- Fixed `json_schema` field evaluating to `false` (a boolean) instead of `undefined` when schema was missing.
16+
17+
**Workers AI quirk workarounds:**
18+
- Added `sanitizeToolCallId()` — strips non-alphanumeric characters and pads/truncates to 9 chars, fixing tool call round-trips through the binding which rejects its own generated IDs.
19+
- Added `normalizeMessagesForBinding()` — converts `content: null` to `""` and sanitizes tool call IDs before every binding call. Only applied on the binding path (REST preserves original IDs).
20+
- Added null-finalization chunk filtering for streaming tool calls.
21+
- Added numeric value coercion in native-format streams (Workers AI sometimes returns numbers instead of strings for the `response` field).
22+
- Improved image model to handle all output types from `binding.run()`: `ReadableStream`, `Uint8Array`, `ArrayBuffer`, `Response`, and `{ image: base64 }` objects.
23+
- Graceful degradation: if `binding.run()` returns a non-streaming response despite `stream: true`, it wraps the complete response as a simulated stream instead of throwing.
24+
25+
**Premature stream termination detection:**
26+
- Streams that end without a `[DONE]` sentinel now report `finishReason: "error"` with `raw: "stream-truncated"` instead of silently reporting `"stop"`.
27+
- Stream read errors are caught and emit `finishReason: "error"` with `raw: "stream-error"`.
28+
29+
**AI Search (formerly AutoRAG):**
30+
- Added `createAISearch` and `AISearchChatLanguageModel` as the canonical exports, reflecting the rename from AutoRAG to AI Search.
31+
- `createAutoRAG` still works but emits a one-time deprecation warning pointing to `createAISearch`.
32+
- `createAutoRAG` preserves `"autorag.chat"` as the provider name for backward compatibility.
33+
- AI Search now warns when tools or JSON response format are provided (unsupported by the `aiSearch` API).
34+
- Simplified AI Search internals — removed dead tool/response-format processing code.
35+
36+
**Code quality:**
37+
- Removed dead code: `workersai-error.ts` (never imported), `workersai-image-config.ts` (inlined).
38+
- Consistent file naming: renamed `workers-ai-embedding-model.ts` to `workersai-embedding-model.ts`.
39+
- Replaced `StringLike` catch-all index signatures with `[key: string]: unknown` on settings types.
40+
- Replaced `any` types with proper interfaces (`FlatToolCall`, `OpenAIToolCall`, `PartialToolCall`).
41+
- Tightened `processToolCall` format detection to check `function.name` instead of just the presence of a `function` property.
42+
- Removed `@ai-sdk/provider-utils` and `zod` peer dependencies (no longer used in source).
43+
- Added `imageModel` to the `WorkersAI` interface type for consistency.
44+
45+
**Tests:**
46+
- 149 unit tests across 10 test files (up from 82).
47+
- New test coverage: `sanitizeToolCallId`, `normalizeMessagesForBinding`, `prepareToolsAndToolChoice`, `processText`, `mapWorkersAIUsage`, image model output types, streaming error scenarios (malformed SSE, premature termination, empty stream), backpressure verification, graceful degradation (non-streaming fallback with text/tools/reasoning), REST API error handling (401/404/500), AI Search warnings, embedding `TooManyEmbeddingValuesForCallError`, message conversion with images and reasoning.
48+
- Integration tests for REST API and binding across 12 models and 7 categories (chat, streaming, multi-turn, tool calling, tool round-trip, structured output, image generation, embeddings).
49+
- All tests use the AI SDK's public APIs (`generateText`, `streamText`, `generateImage`, `embedMany`) instead of internal `.doGenerate()`/`.doStream()` methods.
50+
51+
**README:**
52+
- Rewritten from scratch with concise examples, model recommendations, configuration guide, and known limitations section.
53+
- Updated to use current AI SDK v6 APIs (`generateText` + `Output.object` instead of deprecated `generateObject`, `generateImage` instead of `experimental_generateImage`, `stopWhen: stepCountIs(2)` instead of `maxSteps`).
54+
- Added sections for tool calling, structured output, embeddings, image generation, and AI Search.
55+
- Uses `wrangler.jsonc` format for configuration examples.
56+
357
## 3.0.4
458

559
### Patch Changes

packages/workers-ai-provider/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workers-ai-provider",
3-
"version": "3.0.4",
3+
"version": "3.0.5",
44
"description": "Workers AI Provider for the vercel AI SDK",
55
"keywords": [
66
"ai",

0 commit comments

Comments
 (0)