@aparte/provider-ai-sdk

中文文档
1.0.0发布于 2026/11/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 5699

Bridge any Vercel AI SDK model into aparté — bring your own @ai-sdk/* package (Anthropic, Google, OpenAI, 25+ vendors) and aparté renders it.

原始使用文档

@aparte/provider-ai-sdk

Bridge any Vercel AI SDK model into aparté. aparté's own wire concern is deliberately tiny — @aparte/provider-openai-compat covers the one de-facto-standard format; everything else (Anthropic, Google, Bedrock, 25+ vendors) rides the AI SDK ecosystem through this bridge. You bring your @ai-sdk/* package, hand its model to createAiSdkProvider, and the bridge maps streamText's fullStream to aparté's events.

npm install @aparte/provider-ai-sdk @aparte/core ai @ai-sdk/anthropic

ai and your chosen @ai-sdk/* vendor package are peer dependencies — you pick the versions, and only the vendors you actually use end up in your bundle. @aparte/core is a peer too.

import { createAnthropic } from '@ai-sdk/anthropic';
import { createAiSdkProvider } from '@aparte/provider-ai-sdk';
import { aparteGlobalConfig } from '@aparte/core';

aparteGlobalConfig.registerAIProvider(createAiSdkProvider({
    id: 'anthropic',
    name: 'Anthropic',
    models: [{ id: 'claude-sonnet-4-5', name: 'Claude Sonnet 4.5' }],
    languageModel: (modelId, auth) =>
        createAnthropic({ apiKey: typeof auth === 'string' ? auth : auth?.['apiKey'] })(modelId),
}));

ai is a peerDependency pinned to the verified major (^7) — this bridge is the only aparté module touching the SDK's types. @aparte/core is a peer dependency.

Sources and citations

A model that searches the web or reads documents reports what it drew on as source parts in the SDK's stream. The bridge collects them and ends the turn with one sources event, just before done: aparté lists the sources under the reply, and puts a chip in the text wherever the vendor says a passage is cited. Nothing to configure — a model that reports no source leaves the stream as it was.

import { createPerplexity } from '@ai-sdk/perplexity';
import { createAiSdkProvider } from '@aparte/provider-ai-sdk';
import { aparteGlobalConfig } from '@aparte/core';

// Sonar searches the web: each page it reads arrives as a `source` part.
aparteGlobalConfig.registerAIProvider(createAiSdkProvider({
    id: 'perplexity',
    name: 'Perplexity',
    models: [{ id: 'sonar', name: 'Sonar' }],
    languageModel: (modelId, auth) =>
        createPerplexity({ apiKey: typeof auth === 'string' ? auth : auth?.['apiKey'] })(modelId),
}));
  • A url source becomes { id, url, title }; a document source { id, title } (its filename when it has no title) and no link. The same URL reported twice is one source.
  • From ai 7.0.138 a text-end part may carry citations: each names a source and, when the vendor says so, the passage it supports, with offsets relative to that text part. The bridge rebases them onto the whole reply, so the chip lands after the right sentence. A citation with no offsets supports its whole text part; a vendor's citedText becomes the source's snippet. On an older ai the field is simply absent and only the list of sources is shown.
  • A non-streamed request (stream: false) that cites sources returns the stream [text, sources, done] instead of a bare string; one that cites nothing still returns the string.

Works on the server too. This bridge touches no DOM, and core resolves its DOM-free entry under Node's export condition — so it runs in a backend, an Electron main process or an SSR pass as well as in the browser.

Part of the aparté monorepo. ESM-only. See the Providers guide in the docs for the full usage.

版本与发布记录

@aparte/provider-ai-sdk 共发布 66 个版本,首次发布于 2026/07/24;过去 12 个月发布了 66 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0latest2026/11/07今天
0.32.12026/11/025 天前
0.32.02026/11/025 天前
0.31.02026/11/026 天前
0.30.12026/11/016 天前
0.30.02026/11/016 天前

其他发布通道:alpha → 0.17.0。

关于 @aparte/provider-ai-sdk 的常见问题

@aparte/provider-ai-sdk 是什么?

Bridge any Vercel AI SDK model into aparté — bring your own @ai-sdk/* package (Anthropic, Google, OpenAI, 25+ vendors) and aparté renders it.

如何安装 @aparte/provider-ai-sdk?

在项目目录运行 npm install @aparte/provider-ai-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ai(^7.0.0)、@aparte/core(>=1.0.0 <2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aparte/provider-ai-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aparte/provider-ai-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aparte/provider-ai-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aparte/provider-ai-sdk 可以商用吗?

@aparte/provider-ai-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aparte/provider-ai-sdk 的下载量有多少?

根据 npm 官方下载统计,@aparte/provider-ai-sdk 在 2026/10/06 – 2026/11/04 这 30 天内被下载 5,699 次,日均约 190 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aparte/provider-ai-sdk 还在维护吗?

最新版本 1.0.0 发布于 2026/11/07(今天);至今共发布 66 个版本,其中过去 12 个月发布了 66 个;首次发布于 2026/07/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。