@dbx-tools/model-protocol

中文文档
0.9.206发布于 2026/11/11Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 8011

Vercel AI SDK providers and model protocol transforms for Databricks serving

原始使用文档
文档目录3 节
  1. Invoke a Databricks model
  2. Translate a gateway request
  3. Protocol coverage and limits

@dbx-tools/model-protocol

Construct Vercel AI SDK ProviderV4 models for Databricks endpoints and translate gateway traffic between supported model protocols.

Invoke a Databricks model

Construct the AI SDK model after resolving the endpoint protocol and fresh authentication headers for the current request:

import { createDatabricksLanguageModel } from "@dbx-tools/model-protocol/provider";
import { generateText } from "ai";

const model = createDatabricksLanguageModel({
  host: process.env.DATABRICKS_HOST!,
  modelId: "databricks-gpt-5-6-sol",
  protocol: "responses",
  headers: { authorization: `Bearer ${process.env.DATABRICKS_TOKEN}` },
});

const result = await generateText({ model, prompt: "Summarize the incident." });
console.log(result.text);

Use this package when a Node service needs to:

  • construct a request-scoped AI SDK model for Databricks Chat Completions, Responses, or Anthropic Messages.
  • translate OpenAI or Anthropic gateway messages to and from AI SDK messages.
  • normalize Databricks Chat Completions request and response wire shapes.

Model discovery and capability policy remain in @dbx-tools/model. Browser-safe model and gateway contracts remain in @dbx-tools/shared-model and @dbx-tools/shared-model-gateway.

Use chat, responses, or anthropic according to the model-owned protocol selection. The chat provider applies Databricks serving-wire repairs through a provider-local fetch. It does not patch globalThis.fetch.

Translate a gateway request

Decode an OpenAI or Anthropic request into AI SDK messages and encode the completed generation back into the caller's protocol:

import { decodeGatewayRequest } from "@dbx-tools/model-protocol/gateway-decode";
import { encodeGatewayResponse } from "@dbx-tools/model-protocol/gateway-encode";
import { createDatabricksLanguageModel } from "@dbx-tools/model-protocol/provider";
import { generateText } from "ai";

const protocol = "openai-chat" as const;
const decoded = decodeGatewayRequest(protocol, {
  messages: [{ role: "user", content: "Hello" }],
});
const model = createDatabricksLanguageModel({
  host: process.env.DATABRICKS_HOST!,
  modelId: "databricks-gpt-5-6-sol",
  protocol: "responses",
  headers: { authorization: `Bearer ${process.env.DATABRICKS_TOKEN}` },
});
const generated = await generateText({ model, ...decoded });

const response = encodeGatewayResponse(protocol, "databricks-gpt-5-6-sol", {
  text: generated.text,
  toolCalls: generated.toolCalls,
  usage: generated.usage,
  finishReason: generated.finishReason,
});

Use encodeGatewayStream() instead when forwarding streamText().fullStream. The decoder and encoders share tool-call, reasoning, usage, and finish-reason handling between Mastra and the model gateway.

Protocol coverage and limits

The provider side supports Databricks Chat Completions, Responses, and Anthropic Messages. The gateway decoder and encoders support OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages for buffered and streaming text and function-tool traffic. The model gateway sends embeddings directly and doesn't translate them through this package.

Fallback translation preserves text, function tools, tool results, reasoning events, token usage, and finish reasons. It doesn't implement stateful Responses features such as previous_response_id, store: true, or background: true.

The Chat provider's request-scoped fetch removes unsupported fields, applies GPT 5.6 tool-call reasoning compatibility, strips provider reasoning blocks that can't be replayed, repairs assistant prefill after tool results, and flattens array-valued response content while preserving returned thinking as AI SDK reasoning events. It doesn't modify globalThis.fetch.

版本与发布记录

@dbx-tools/model-protocol 共发布 71 个版本,首次发布于 2026/10/10;过去 12 个月发布了 71 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.9.206latest2026/11/11今天
0.9.2052026/11/111 天前
0.9.2032026/11/074 天前
0.9.2022026/11/065 天前
0.9.2012026/11/056 天前
0.9.2002026/11/056 天前

关于 @dbx-tools/model-protocol 的常见问题

@dbx-tools/model-protocol 是什么?

Vercel AI SDK providers and model protocol transforms for Databricks serving

如何安装 @dbx-tools/model-protocol?

在项目目录运行 npm install @dbx-tools/model-protocol,或使用 pnpm add / yarn add / bun add。

@dbx-tools/model-protocol 支持 TypeScript 吗?

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

@dbx-tools/model-protocol 支持 ESM 还是 CommonJS?

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

@dbx-tools/model-protocol 可以商用吗?

@dbx-tools/model-protocol 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dbx-tools/model-protocol 的下载量有多少?

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

@dbx-tools/model-protocol 还在维护吗?

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