@dbx-tools/shared-genie

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

Browser-safe Genie schemas, event vocabulary, and snapshot diff helpers

原始使用文档
文档目录9 节
  1. Quick start
  2. Choose between AppKit and shared Genie types
  3. Validate message snapshots
  4. Handle typed chat events
  5. Derive events from snapshots
  6. Work with status and attachments
  7. Event model
  8. Validate generated SDK shapes
  9. Package exports

@dbx-tools/shared-genie

Validate AI/BI Genie wire payloads and derive UI events from raw message snapshots without importing the Databricks SDK. Use the browser-safe schemas, event vocabulary, and snapshot diff helpers in clients, routes, and tests. The Node driver that calls Genie is @dbx-tools/genie.

Quick start

import { genieModel } from "@dbx-tools/shared-genie";

const response = genieModel.GenieResponseSchema.parse(await request.json());

Use the contracts for:

  • Runtime schemas for Genie messages, responses, spaces, attachments, and statuses, including fields observed on the live wire.
  • Forward-compatible Agent Mode SSE schemas plus a pure reducer that projects reasoning, SQL, Markdown output, statement IDs, visualization metadata, and terminal status into GenieMessage.
  • A flat GenieChatEvent vocabulary for thinking, SQL, rows, result, status, and error rendering.
  • Snapshot diff helpers that emit only newly observed semantic events.
  • Attachment and status helpers for UI display logic.
  • Browser-safe types that allow clients to validate Genie payloads without bundling Databricks SDK runtime code.
  • Generated Zod schemas for the upstream SDK Dashboard/Genie shapes, so validating an unwidened SDK payload needs no SDK import either.

Choose between AppKit and shared Genie types

Use AppKit's Genie plugin and UI types when you build directly against the native AppKit Genie routes. Use this package when you need a browser-safe event vocabulary independent of AppKit transport:

  • Validate raw Genie messages captured from the Databricks SDK.
  • Replay persisted snapshots as semantic events.
  • Share a flat event union between @dbx-tools/genie, @dbx-tools/appkit-mastra, and custom clients.
  • Detect attachment and status shapes that are present on the wire but aren't convenient in generated SDK types.

Validate message snapshots

import { genieModel } from "@dbx-tools/shared-genie";

const message = genieModel.GenieMessageSchema.parse(rawMessage);
const attachments = genieModel.GenieResponseSchema.parse(rawMessage);

The schemas extend generated Databricks SDK Genie types with fields observed on the wire, including query thoughts, visualization attachments, attachment discriminators, and serialized space data.

Handle typed chat events

import { type GenieChatEvent } from "@dbx-tools/shared-genie";

function render(event: GenieChatEvent) {
  switch (event.type) {
    case "thinking":
      return showThought(event.thought_type, event.text);
    case "query":
      return showSql(event.sql);
    case "result":
      return markDone(event.status);
  }
}

The event union is flat: every variant has type plus its own fields and shared location fields such as space_id, conversation_id, and message_id.

Derive events from snapshots

import { event } from "@dbx-tools/shared-genie";

for (const evt of event.eventsFromMessage(current, previous, spaceId)) {
  render(evt);
}

Use eventsFromMessage() when replaying persisted Genie messages, testing UI event handling, diffing Agent Mode or polling GenieMessage snapshots into the shared vocabulary, or building a custom polling loop. Individual detectors are also exported for targeted checks: detectStatus, detectThinking, detectQuery, detectRows, and the other event-specific helpers.

Work with status and attachments

import { genieModel } from "@dbx-tools/shared-genie";

export function describeMessage(input: unknown) {
  const message = genieModel.GenieMessageSchema.parse(input);
  const statusLabel = genieModel.isTerminalStatus(message.status)
    ? genieModel.humanizeStatus(message.status)
    : undefined;
  const attachmentType = genieModel.detectAttachmentType(message.attachments?.[0]);
  return { statusLabel, attachmentType };
}

humanizeStatus() is the shared display-label function. detectAttachmentType() lets consumers switch on query, text, suggested_questions, or viz instead of probing optional fields.

Event model

The event detector compares the current Genie message with the previous snapshot from the same turn. This keeps streaming UIs from re-rendering duplicate thought or query fragments while still allowing full history replay from persisted raw messages. Consumers can use the full eventsFromMessage() helper or individual detectors when a test needs to assert one specific behavior.

Validate generated SDK shapes

dashboards holds Zod schemas generated from the upstream @databricks/sdk-experimental dashboards declarations. Import it when code needs to validate a raw Databricks Genie/Dashboard payload against the SDK's own shape:

import { dashboards } from "@dbx-tools/shared-genie";

const space = dashboards.genieSpaceSchema.parse(rawSpace);

Use genieModel for schemas that include fields observed on the Genie wire. Use dashboards only when the unwidened Databricks SDK shape is the required contract. The SDK is a development dependency, so browser bundles include Zod but not the Databricks SDK runtime.

Package exports

  • agentMode: forward-compatible Zod schemas plus the pure Agent Mode event reducer and live/history GenieMessage projectors.
  • genieModel: Genie schemas, status helpers, attachment helpers, and event union schemas/types.
  • event: event detector factory, individual detectors, and eventsFromMessage().
  • dashboards: generated, read-only Zod schemas and inferred types for the upstream SDK Dashboard/Genie shapes that genieModel extends.

This package doesn't call Genie, manage credentials, or own conversation lifecycle. Server-side streaming is in @dbx-tools/genie.

版本与发布记录

@dbx-tools/shared-genie 共发布 358 个版本,首次发布于 2026/07/18;过去 12 个月发布了 358 个版本。最新版本附带 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-genie 的常见问题

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

Browser-safe Genie schemas, event vocabulary, and snapshot diff helpers

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

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

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

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

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

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

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

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

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

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

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

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