@dbx-tools/shared-mastra

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

Browser-safe contracts for the AppKit Mastra plugin

原始使用文档
文档目录9 节
  1. Quick start
  2. Runtime boundary
  3. Validate published client configuration
  4. Use route constants
  5. Select threads and models
  6. Parse embed markers
  7. Validate feedback
  8. Validate plugin responses
  9. Package exports

@dbx-tools/shared-mastra

Validate browser-facing data exchanged with @dbx-tools/appkit-mastra. It defines the shared route constants, headers, embed markers, feedback schemas, thread selection fields, published client configuration, and response schemas.

Quick start

import { wire } from "@dbx-tools/shared-mastra";

const config = wire.MastraClientConfigSchema.parse(await response.json());

The shared contract includes:

  • Route constants for the official AI SDK chat mount and AppKit-Mastra additions, including suggestions, model lists, the per-agent default-model lookup, embeds, feedback, and direct Genie chat. Agent history and threads use Mastra's native client API. Direct mode maps Genie conversations and messages onto the same UI contracts.
  • Header/query/body constants for thread selection and model override requests.
  • Embed-marker parsing for delayed chart and statement-data payloads in streaming assistant text.
  • Zod schemas for plugin-published client config and route responses.
  • MLflow feedback request/response schemas and trace-header constants.
  • Browser-safe types that let UI packages stay aligned with the server without importing Node or Mastra runtime code.

Runtime boundary

This package contains contracts and pure helpers. It doesn't register AppKit plugins, call Databricks services, run Mastra agents, or persist conversation state. Use @dbx-tools/appkit-mastra for server workflows and @dbx-tools/ui-mastra for React chat.

Validate published client configuration

import { wire } from "@dbx-tools/shared-mastra";

const config = wire.MastraClientConfigSchema.parse(await response.json());

wire.MastraClientConfigSchema validates the plugin-published client configuration, including the mount path, default agent, agent roster, feedback availability, background-turn support, and chat identity behavior. Use the published configuration instead of hard-coding server paths.

Use route constants

import { routes } from "@dbx-tools/shared-mastra";

const suggestionsUrl = `${basePath}${routes.MASTRA_ROUTES.suggestions}`;
const chatUrl = `${basePath}${routes.MASTRA_ROUTES.chat}/${agentId}`;

routes.MASTRA_ROUTES keeps client fetch calls aligned with plugin route names for chat, models, the default-model lookup, suggestions, feedback, and embeds.

Select threads and models

import { override, thread } from "@dbx-tools/shared-mastra";

await fetch(chatUrl, {
  method: "POST",
  headers: {
    [thread.THREAD_ID_HEADER]: activeThreadId,
    [override.MODEL_OVERRIDE_HEADER]: "claude sonnet",
  },
  body: JSON.stringify({ messages }),
});

Use the header/query constants instead of string literals so browser code, server middleware, and tests agree on how a request selects the active conversation and model.

Parse embed markers

import { markers } from "@dbx-tools/shared-mastra";

const parts = markers.parseMarkers("Here is the chart:\n[chart:abc123]");
const safeText = markers.stripIncompleteMarkerTail(streamingText);

Markers let an agent mention large or delayed artifacts by id, such as [chart:<id>], [data:<statement_id>], and [visualization:<statement_id>]. The visualization marker selects AppKit UI's native Genie Chart/Table renderer after Genie requested a chart.

Validate feedback

import { feedback } from "@dbx-tools/shared-mastra";

const body = feedback.MastraFeedbackRequestSchema.parse({
  traceId: "tr-abc",
  value: true,
  comment: "Helpful",
});

Feedback constants include the MLflow trace header and default assessment names. The schemas validate thumbs/comment payloads before they are sent to the plugin.

Validate plugin responses

const chart = wire.ChartSchema.parse(await chartRes.json());
const event = wire.GenieWriterEventSchema.parse(writerPayload);

The wire module contains response schemas for suggestions, model lists, charts, statement data, direct Genie threads/history, and Genie writer events. It also defines the browser visualization payload consumed by AppKit UI.

Package exports

  • wire: Zod schemas and types for client config, model lists, suggestions, charts, statement data, and writer events.
  • routes: plugin route segment constants and direct Genie route builder.
  • markers: embed-marker parsing and incomplete-tail stripping.
  • feedback: MLflow feedback headers, assessment names, request/response schemas.
  • override: model override header/query/body constants.
  • thread: thread ID header/query constants.

版本与发布记录

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

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

关于 @dbx-tools/shared-mastra 的常见问题

@dbx-tools/shared-mastra 是什么?

Browser-safe contracts for the AppKit Mastra plugin

如何安装 @dbx-tools/shared-mastra?

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

@dbx-tools/shared-mastra 支持 TypeScript 吗?

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

@dbx-tools/shared-mastra 支持 ESM 还是 CommonJS?

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

@dbx-tools/shared-mastra 可以商用吗?

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

@dbx-tools/shared-mastra 的下载量有多少?

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

@dbx-tools/shared-mastra 还在维护吗?

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