@dbx-tools/appkit-mastra 0.1.27 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/src/agents.js +4 -1
- package/dist/src/chart.d.ts +3 -12
- package/dist/src/chart.js +3 -12
- package/dist/src/genie.d.ts +13 -35
- package/dist/src/genie.js +13 -35
- package/dist/src/model.js +2 -2
- package/dist/src/plugin.js +1 -39
- package/dist/src/processor.d.ts +8 -0
- package/dist/src/processor.js +40 -0
- package/dist/src/serving.d.ts +10 -17
- package/dist/src/serving.js +10 -17
- package/dist/src/statement.d.ts +11 -18
- package/dist/src/statement.js +11 -18
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/index.ts +4 -3
- package/package.json +5 -5
- package/src/agents.ts +4 -1
- package/src/chart.ts +3 -12
- package/src/genie.ts +13 -35
- package/src/model.ts +2 -7
- package/src/plugin.ts +1 -41
- package/src/processor.ts +52 -0
- package/src/serving.ts +10 -17
- package/src/statement.ts +11 -18
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* plugin
|
|
4
|
-
*
|
|
2
|
+
* Server-side entry point for the AppKit Mastra integration. Mounts
|
|
3
|
+
* the plugin via {@link mastra} and re-exports the full server surface
|
|
4
|
+
* (config, agent wiring, Genie and chart tooling, and dynamic Model
|
|
5
|
+
* Serving resolution) so apps build agent backends from one import.
|
|
5
6
|
*
|
|
6
7
|
* Client-side consumers should import URL helpers and the
|
|
7
8
|
* {@link MastraClientConfig} type from `@dbx-tools/appkit-mastra-shared`
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* plugin
|
|
4
|
-
*
|
|
2
|
+
* Server-side entry point for the AppKit Mastra integration. Mounts
|
|
3
|
+
* the plugin via {@link mastra} and re-exports the full server surface
|
|
4
|
+
* (config, agent wiring, Genie and chart tooling, and dynamic Model
|
|
5
|
+
* Serving resolution) so apps build agent backends from one import.
|
|
5
6
|
*
|
|
6
7
|
* Client-side consumers should import URL helpers and the
|
|
7
8
|
* {@link MastraClientConfig} type from `@dbx-tools/appkit-mastra-shared`
|
package/dist/src/agents.js
CHANGED
|
@@ -19,6 +19,7 @@ import { buildGenieToolkitProvider, resolveGenieSpaces } from "./genie.js";
|
|
|
19
19
|
import { buildModel, FALLBACK_MODEL_IDS } from "./model.js";
|
|
20
20
|
import { stripStaleChartsProcessor } from "./processors/strip-stale-charts.js";
|
|
21
21
|
import { buildRenderDataTool } from "./chart.js";
|
|
22
|
+
import { ResultProcessor } from "./processor.js";
|
|
22
23
|
/** Re-export of Mastra's native `createTool` for full-feature access. */
|
|
23
24
|
export { createTool } from "@mastra/core/tools";
|
|
24
25
|
/**
|
|
@@ -190,6 +191,7 @@ export async function buildAgents(opts) {
|
|
|
190
191
|
// chartIds from prior assistant tool results into the new
|
|
191
192
|
// turn's `[chart:<id>]` markers. Opt out per-plugin via
|
|
192
193
|
// `config.stripStaleCharts: false`.
|
|
194
|
+
const outputProcessors = [new ResultProcessor()];
|
|
193
195
|
const inputProcessors = config.stripStaleCharts === false ? [] : [stripStaleChartsProcessor];
|
|
194
196
|
const agents = {};
|
|
195
197
|
for (const [id, def] of Object.entries(definitions)) {
|
|
@@ -206,7 +208,8 @@ export async function buildAgents(opts) {
|
|
|
206
208
|
},
|
|
207
209
|
tools,
|
|
208
210
|
...(memory ? { memory } : {}),
|
|
209
|
-
|
|
211
|
+
inputProcessors,
|
|
212
|
+
outputProcessors,
|
|
210
213
|
});
|
|
211
214
|
// Surface the effective default model per agent so operators can
|
|
212
215
|
// see at a glance which endpoint each agent points at without
|
package/dist/src/chart.d.ts
CHANGED
|
@@ -20,18 +20,9 @@
|
|
|
20
20
|
* dataset, custom API). The module has no knowledge of Genie or
|
|
21
21
|
* statement ids; those concerns live in the tools that wrap it.
|
|
22
22
|
*
|
|
23
|
-
* Wire-format schemas
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* other UI consumer share the exact same shape this module reads
|
|
27
|
-
* and writes.
|
|
28
|
-
*
|
|
29
|
-
* Public surface (everything else is module-private):
|
|
30
|
-
* - {@link chartPlannerRequestSchema} / {@link ChartPlannerRequest}
|
|
31
|
-
* - {@link prepareChart} / {@link PrepareChartOptions}
|
|
32
|
-
* - {@link fetchChart} / {@link FetchChartOptions}
|
|
33
|
-
* - {@link buildRenderDataTool} (the `render_data` Mastra tool
|
|
34
|
-
* auto-wired on every agent in `agents.ts`)
|
|
23
|
+
* Wire-format schemas live in `@dbx-tools/appkit-mastra-shared` so
|
|
24
|
+
* the demo client and any other UI consumer share the exact same
|
|
25
|
+
* shape this module reads and writes.
|
|
35
26
|
*/
|
|
36
27
|
import { type Chart } from "@dbx-tools/appkit-mastra-shared";
|
|
37
28
|
import type { RequestContext } from "@mastra/core/request-context";
|
package/dist/src/chart.js
CHANGED
|
@@ -20,18 +20,9 @@
|
|
|
20
20
|
* dataset, custom API). The module has no knowledge of Genie or
|
|
21
21
|
* statement ids; those concerns live in the tools that wrap it.
|
|
22
22
|
*
|
|
23
|
-
* Wire-format schemas
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* other UI consumer share the exact same shape this module reads
|
|
27
|
-
* and writes.
|
|
28
|
-
*
|
|
29
|
-
* Public surface (everything else is module-private):
|
|
30
|
-
* - {@link chartPlannerRequestSchema} / {@link ChartPlannerRequest}
|
|
31
|
-
* - {@link prepareChart} / {@link PrepareChartOptions}
|
|
32
|
-
* - {@link fetchChart} / {@link FetchChartOptions}
|
|
33
|
-
* - {@link buildRenderDataTool} (the `render_data` Mastra tool
|
|
34
|
-
* auto-wired on every agent in `agents.ts`)
|
|
23
|
+
* Wire-format schemas live in `@dbx-tools/appkit-mastra-shared` so
|
|
24
|
+
* the demo client and any other UI consumer share the exact same
|
|
25
|
+
* shape this module reads and writes.
|
|
35
26
|
*/
|
|
36
27
|
import { CacheManager } from "@databricks/appkit";
|
|
37
28
|
import { ChartSchema, ChartTypeSchema, } from "@dbx-tools/appkit-mastra-shared";
|
package/dist/src/genie.d.ts
CHANGED
|
@@ -1,41 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Genie tools for Mastra.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* - `get_space_description`: cheap title / description /
|
|
18
|
-
* warehouse id lookup for grounding.
|
|
19
|
-
* - `get_space_serialized`: full `GenieSpace` JSON for
|
|
20
|
-
* column-level grounding when the description isn't enough.
|
|
21
|
-
*
|
|
22
|
-
* Space-agnostic shared tools (registered once, regardless of
|
|
23
|
-
* how many spaces are wired):
|
|
24
|
-
*
|
|
25
|
-
* - `get_statement`: opt-in lookup of a Genie statement's rows
|
|
26
|
-
* by `statement_id` (with a row `limit`). The agent calls
|
|
27
|
-
* this only when it needs to read values to reason about
|
|
28
|
-
* them; if the data is just being displayed, it embeds a
|
|
29
|
-
* `[data:<statement_id>]` marker in prose instead and lets
|
|
30
|
-
* the host UI resolve it.
|
|
31
|
-
* - `prepare_chart`: mints a short `chartId`, kicks off a
|
|
32
|
-
* background task that fetches the statement's rows and
|
|
33
|
-
* runs the chart-planner, and caches the resolved Echarts
|
|
34
|
-
* spec under the id (1h TTL). Returns the `chartId`
|
|
35
|
-
* synchronously so the agent embeds `[chart:<chartId>]`
|
|
36
|
-
* markers in prose without blocking on chart generation;
|
|
37
|
-
* the host UI fetches the cached chart by id once it's
|
|
38
|
-
* ready (see {@link fetchChart}).
|
|
4
|
+
* Surfaces each configured Genie space as a small set of flat Mastra
|
|
5
|
+
* tools the calling agent drives directly - no inner orchestrator
|
|
6
|
+
* agent. The central agent decomposes user questions, picks which
|
|
7
|
+
* space to ask, streams the per-turn wire events (status, thinking,
|
|
8
|
+
* sql, rows) through `ctx.writer`, and composes the final reply.
|
|
9
|
+
* Rows are never fetched eagerly: the agent reads a statement's
|
|
10
|
+
* values only when it needs to reason about them, otherwise it embeds
|
|
11
|
+
* a `[data:<statement_id>]` marker in prose and lets the host UI
|
|
12
|
+
* resolve the data. Charts are minted asynchronously and referenced
|
|
13
|
+
* by `[chart:<chartId>]` markers so prose isn't blocked on chart
|
|
14
|
+
* generation; the host UI fetches the cached spec by id once ready.
|
|
15
|
+
* Space description and serialized-space lookups are available for
|
|
16
|
+
* grounding when the agent needs schema context.
|
|
39
17
|
*
|
|
40
18
|
* Each tool's `execute` pulls the per-request
|
|
41
19
|
* {@link WorkspaceClient} off `ctx.requestContext` (stamped by
|
package/dist/src/genie.js
CHANGED
|
@@ -1,41 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Genie tools for Mastra.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* - `get_space_description`: cheap title / description /
|
|
18
|
-
* warehouse id lookup for grounding.
|
|
19
|
-
* - `get_space_serialized`: full `GenieSpace` JSON for
|
|
20
|
-
* column-level grounding when the description isn't enough.
|
|
21
|
-
*
|
|
22
|
-
* Space-agnostic shared tools (registered once, regardless of
|
|
23
|
-
* how many spaces are wired):
|
|
24
|
-
*
|
|
25
|
-
* - `get_statement`: opt-in lookup of a Genie statement's rows
|
|
26
|
-
* by `statement_id` (with a row `limit`). The agent calls
|
|
27
|
-
* this only when it needs to read values to reason about
|
|
28
|
-
* them; if the data is just being displayed, it embeds a
|
|
29
|
-
* `[data:<statement_id>]` marker in prose instead and lets
|
|
30
|
-
* the host UI resolve it.
|
|
31
|
-
* - `prepare_chart`: mints a short `chartId`, kicks off a
|
|
32
|
-
* background task that fetches the statement's rows and
|
|
33
|
-
* runs the chart-planner, and caches the resolved Echarts
|
|
34
|
-
* spec under the id (1h TTL). Returns the `chartId`
|
|
35
|
-
* synchronously so the agent embeds `[chart:<chartId>]`
|
|
36
|
-
* markers in prose without blocking on chart generation;
|
|
37
|
-
* the host UI fetches the cached chart by id once it's
|
|
38
|
-
* ready (see {@link fetchChart}).
|
|
4
|
+
* Surfaces each configured Genie space as a small set of flat Mastra
|
|
5
|
+
* tools the calling agent drives directly - no inner orchestrator
|
|
6
|
+
* agent. The central agent decomposes user questions, picks which
|
|
7
|
+
* space to ask, streams the per-turn wire events (status, thinking,
|
|
8
|
+
* sql, rows) through `ctx.writer`, and composes the final reply.
|
|
9
|
+
* Rows are never fetched eagerly: the agent reads a statement's
|
|
10
|
+
* values only when it needs to reason about them, otherwise it embeds
|
|
11
|
+
* a `[data:<statement_id>]` marker in prose and lets the host UI
|
|
12
|
+
* resolve the data. Charts are minted asynchronously and referenced
|
|
13
|
+
* by `[chart:<chartId>]` markers so prose isn't blocked on chart
|
|
14
|
+
* generation; the host UI fetches the cached spec by id once ready.
|
|
15
|
+
* Space description and serialized-space lookups are available for
|
|
16
|
+
* grounding when the agent needs schema context.
|
|
39
17
|
*
|
|
40
18
|
* Each tool's `execute` pulls the per-request
|
|
41
19
|
* {@link WorkspaceClient} off `ctx.requestContext` (stamped by
|
package/dist/src/model.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* (network blip, expired token at cache-fill time) we fall back to
|
|
25
25
|
* the input verbatim and let Databricks return the canonical error.
|
|
26
26
|
*/
|
|
27
|
-
import { commonUtils, logUtils, netUtils, stringUtils
|
|
27
|
+
import { commonUtils, logUtils, netUtils, stringUtils } from "@dbx-tools/shared";
|
|
28
28
|
import { MASTRA_USER_KEY } from "./config.js";
|
|
29
29
|
import { listServingEndpoints, MASTRA_MODEL_OVERRIDE_KEY, resolveModelId, resolveServingConfig, } from "./serving.js";
|
|
30
30
|
/**
|
|
@@ -325,7 +325,7 @@ const setupFetchInterceptor = commonUtils.memoize(() => {
|
|
|
325
325
|
const log = logUtils.logger("mastra/llm");
|
|
326
326
|
const original = globalThis.fetch.bind(globalThis);
|
|
327
327
|
globalThis.fetch = (async (input, init) => {
|
|
328
|
-
const url = netUtils.
|
|
328
|
+
const url = netUtils.urlBuilder(input);
|
|
329
329
|
if (!url ||
|
|
330
330
|
!url.pathname.startsWith(SERVING_ENDPOINTS_PATH_PREFIX) ||
|
|
331
331
|
typeof init?.body !== "string") {
|
package/dist/src/plugin.js
CHANGED
|
@@ -37,9 +37,9 @@ import { historyRoute } from "./history.js";
|
|
|
37
37
|
import { createMemoryBuilder, needsLakebase } from "./memory.js";
|
|
38
38
|
import { buildObservability } from "./observability.js";
|
|
39
39
|
import { attachRoutePatchMiddleware, MastraServer } from "./server.js";
|
|
40
|
-
import { installStreamEventInterceptor, } from "./intercept.js";
|
|
41
40
|
import { clearServingEndpointsCache, listServingEndpoints, resolveServingConfig, } from "./serving.js";
|
|
42
41
|
import { fetchStatementData, isStatementNotFoundError, STATEMENT_ROW_CAP, } from "./statement.js";
|
|
42
|
+
import { ResultProcessor } from "./processor.js";
|
|
43
43
|
const GENIE_MANIFEST = appkitUtils.data(genie).plugin.manifest;
|
|
44
44
|
const LAKEBASE_MANIFEST = appkitUtils.data(lakebase).plugin.manifest;
|
|
45
45
|
/**
|
|
@@ -270,11 +270,6 @@ export class MastraPlugin extends Plugin {
|
|
|
270
270
|
router.use("", (req, res, next) => {
|
|
271
271
|
if (!this.mastraApp)
|
|
272
272
|
return res.status(503).end();
|
|
273
|
-
// Run each Mastra `/stream` SSE frame through the interceptor
|
|
274
|
-
// (keep / rewrite / drop). Only engages on a
|
|
275
|
-
// `200 text/event-stream` body, so the JSON routes above and any
|
|
276
|
-
// error response are untouched.
|
|
277
|
-
installStreamEventInterceptor(res, interceptStreamFrame);
|
|
278
273
|
return this.userScopedSelf(req).mastraApp(req, res, next);
|
|
279
274
|
});
|
|
280
275
|
}
|
|
@@ -441,37 +436,4 @@ function parseStatementLimit(raw) {
|
|
|
441
436
|
return undefined;
|
|
442
437
|
return Math.floor(n);
|
|
443
438
|
}
|
|
444
|
-
/**
|
|
445
|
-
* {@link StreamFrameInterceptor} for Mastra `/stream` responses.
|
|
446
|
-
*
|
|
447
|
-
* Removes large, redundant payloads from terminal `step-finish`,
|
|
448
|
-
* `finish`, and `tool-result` frames before they reach the browser.
|
|
449
|
-
* These frames often repeat information already delivered incrementally
|
|
450
|
-
* via streamed text and tool events, including full tool outputs,
|
|
451
|
-
* accumulated responses, message history, SQL results, chart data, and
|
|
452
|
-
* other large result payloads.
|
|
453
|
-
*
|
|
454
|
-
* The interceptor deletes heavyweight payload properties
|
|
455
|
-
* (`output`, `messages`, `response`, and `result`) while preserving the
|
|
456
|
-
* event envelope and lifecycle metadata required by the client.
|
|
457
|
-
*
|
|
458
|
-
* Deletion is key based, so streams that do not contain these
|
|
459
|
-
* fields are passed through unchanged.
|
|
460
|
-
*/
|
|
461
|
-
const interceptStreamFrame = (chunk) => {
|
|
462
|
-
if (!commonUtils.isRecord(chunk))
|
|
463
|
-
return true;
|
|
464
|
-
if (!["step-finish", "finish", "tool-result"].find((type) => type === chunk.type))
|
|
465
|
-
return true;
|
|
466
|
-
const payload = chunk.payload;
|
|
467
|
-
if (!commonUtils.isRecord(payload))
|
|
468
|
-
return true;
|
|
469
|
-
const trimmedPayload = commonUtils.deleteKeys(payload, [
|
|
470
|
-
"output",
|
|
471
|
-
"messages",
|
|
472
|
-
"response",
|
|
473
|
-
"result",
|
|
474
|
-
]);
|
|
475
|
-
return trimmedPayload ? { replace: chunk } : true;
|
|
476
|
-
};
|
|
477
439
|
export const mastra = toPlugin(MastraPlugin);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export class ResultProcessor {
|
|
2
|
+
id = "result-processor";
|
|
3
|
+
// Tell Mastra to also route tool/data parts to this processor method
|
|
4
|
+
processDataParts = true;
|
|
5
|
+
async processOutputStream({ part }) {
|
|
6
|
+
// 1. Guard clause: Ensure the chunk is a valid object
|
|
7
|
+
if (!part || typeof part !== "object") {
|
|
8
|
+
return part;
|
|
9
|
+
}
|
|
10
|
+
// 2. Filter for the targeted frame types
|
|
11
|
+
const targetedTypes = ["step-finish", "finish", "tool-result", "data-tool-agent"];
|
|
12
|
+
if (!targetedTypes.includes(part.type)) {
|
|
13
|
+
return part; // Return unchanged to pass-through
|
|
14
|
+
}
|
|
15
|
+
// 3. Check for the presence of a payload object
|
|
16
|
+
const payload = part.payload;
|
|
17
|
+
if (!payload || typeof payload !== "object") {
|
|
18
|
+
return part;
|
|
19
|
+
}
|
|
20
|
+
// 4. Safely delete the unwanted keys from the payload reference
|
|
21
|
+
const keysToDelete = ["output", "messages", "response", "result"];
|
|
22
|
+
for (const key of keysToDelete) {
|
|
23
|
+
if (key in payload) {
|
|
24
|
+
const value = payload[key];
|
|
25
|
+
if (typeof value === "object") {
|
|
26
|
+
payload[key] = {};
|
|
27
|
+
}
|
|
28
|
+
else if (Array.isArray(value)) {
|
|
29
|
+
payload[key] = [];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
delete payload[key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// 5. Return the modified part object. Mastra handles re-serialization
|
|
37
|
+
// for the outbound SSE client stream automatically.
|
|
38
|
+
return part;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dist/src/serving.d.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Dynamic model resolution against Databricks Model Serving.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* 3. **Per-request override** - {@link extractModelOverride} pulls a
|
|
15
|
-
* model name from the `X-Mastra-Model` header, `?model=` query
|
|
16
|
-
* string, or `model` body field so the same agent can be exercised
|
|
17
|
-
* against different endpoints without redeploying.
|
|
18
|
-
*
|
|
19
|
-
* `model.ts` glues these together inside the per-step model resolver;
|
|
20
|
-
* `plugin.ts` exposes the cached list at `GET /models`.
|
|
4
|
+
* Turns loose, human-typed model names into real serving-endpoint ids
|
|
5
|
+
* so the same agent can target different endpoints without code
|
|
6
|
+
* changes. The workspace's `/serving-endpoints` list is fetched once
|
|
7
|
+
* per host and cached with a TTL, with concurrent callers sharing one
|
|
8
|
+
* in-flight promise (the coalescing pattern of Python's
|
|
9
|
+
* `cachetools-async`). Names are matched through `fuse.js` extended
|
|
10
|
+
* search so tokens like `"claude sonnet"` snap to
|
|
11
|
+
* `databricks-claude-sonnet-4-6`, and a per-request override can be
|
|
12
|
+
* pulled from the request header, query string, or body so a model
|
|
13
|
+
* can be swapped per call without redeploying.
|
|
21
14
|
*/
|
|
22
15
|
import { type getExecutionContext } from "@databricks/appkit";
|
|
23
16
|
import type { ServingEndpointSummary } from "@dbx-tools/appkit-mastra-shared";
|
package/dist/src/serving.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Dynamic model resolution against Databricks Model Serving.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* 3. **Per-request override** - {@link extractModelOverride} pulls a
|
|
15
|
-
* model name from the `X-Mastra-Model` header, `?model=` query
|
|
16
|
-
* string, or `model` body field so the same agent can be exercised
|
|
17
|
-
* against different endpoints without redeploying.
|
|
18
|
-
*
|
|
19
|
-
* `model.ts` glues these together inside the per-step model resolver;
|
|
20
|
-
* `plugin.ts` exposes the cached list at `GET /models`.
|
|
4
|
+
* Turns loose, human-typed model names into real serving-endpoint ids
|
|
5
|
+
* so the same agent can target different endpoints without code
|
|
6
|
+
* changes. The workspace's `/serving-endpoints` list is fetched once
|
|
7
|
+
* per host and cached with a TTL, with concurrent callers sharing one
|
|
8
|
+
* in-flight promise (the coalescing pattern of Python's
|
|
9
|
+
* `cachetools-async`). Names are matched through `fuse.js` extended
|
|
10
|
+
* search so tokens like `"claude sonnet"` snap to
|
|
11
|
+
* `databricks-claude-sonnet-4-6`, and a per-request override can be
|
|
12
|
+
* pulled from the request header, query string, or body so a model
|
|
13
|
+
* can be swapped per call without redeploying.
|
|
21
14
|
*/
|
|
22
15
|
import { CacheManager } from "@databricks/appkit";
|
|
23
16
|
import { logUtils, stringUtils } from "@dbx-tools/shared";
|
package/dist/src/statement.d.ts
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Databricks Statement Execution helpers for the Mastra plugin.
|
|
3
3
|
*
|
|
4
|
-
* Wraps `client.statementExecution.getStatement` with the shape
|
|
5
|
-
*
|
|
6
|
-
* `/embed/data/:id` route both need:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `/embed/data/:id` route) clamp `limit` to so a
|
|
16
|
-
* runaway result set can't hose a response.
|
|
17
|
-
* - {@link isStatementNotFoundError}: structural detector that
|
|
18
|
-
* normalizes the SDK's two error classes plus the loose
|
|
19
|
-
* `does not exist` / `not found` message shapes into a single
|
|
20
|
-
* boolean - lets the route map upstream 404s to a clean
|
|
21
|
-
* HTTP 404 without coupling to SDK error-class identity.
|
|
4
|
+
* Wraps `client.statementExecution.getStatement` with the shape,
|
|
5
|
+
* size, and error handling the plugin's tools and the
|
|
6
|
+
* `/embed/data/:id` route both need: a low-level fetch that returns a
|
|
7
|
+
* raw `{columns, rows, rowCount}` shape and coerces numeric strings
|
|
8
|
+
* to numbers so downstream charts and aggregations don't have to, a
|
|
9
|
+
* hard row cap callers clamp `limit` to so a runaway result set can't
|
|
10
|
+
* hose a response, and a structural not-found detector that
|
|
11
|
+
* normalizes the SDK's error classes and loose `does not exist` /
|
|
12
|
+
* `not found` message shapes into one boolean so the route can map
|
|
13
|
+
* upstream 404s to a clean HTTP 404 without coupling to SDK
|
|
14
|
+
* error-class identity.
|
|
22
15
|
*
|
|
23
16
|
* Not Genie-specific: a Databricks `statement_id` is workspace
|
|
24
17
|
* scoped and lives in the Statement Execution API regardless of
|
package/dist/src/statement.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Databricks Statement Execution helpers for the Mastra plugin.
|
|
3
3
|
*
|
|
4
|
-
* Wraps `client.statementExecution.getStatement` with the shape
|
|
5
|
-
*
|
|
6
|
-
* `/embed/data/:id` route both need:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `/embed/data/:id` route) clamp `limit` to so a
|
|
16
|
-
* runaway result set can't hose a response.
|
|
17
|
-
* - {@link isStatementNotFoundError}: structural detector that
|
|
18
|
-
* normalizes the SDK's two error classes plus the loose
|
|
19
|
-
* `does not exist` / `not found` message shapes into a single
|
|
20
|
-
* boolean - lets the route map upstream 404s to a clean
|
|
21
|
-
* HTTP 404 without coupling to SDK error-class identity.
|
|
4
|
+
* Wraps `client.statementExecution.getStatement` with the shape,
|
|
5
|
+
* size, and error handling the plugin's tools and the
|
|
6
|
+
* `/embed/data/:id` route both need: a low-level fetch that returns a
|
|
7
|
+
* raw `{columns, rows, rowCount}` shape and coerces numeric strings
|
|
8
|
+
* to numbers so downstream charts and aggregations don't have to, a
|
|
9
|
+
* hard row cap callers clamp `limit` to so a runaway result set can't
|
|
10
|
+
* hose a response, and a structural not-found detector that
|
|
11
|
+
* normalizes the SDK's error classes and loose `does not exist` /
|
|
12
|
+
* `not found` message shapes into one boolean so the route can map
|
|
13
|
+
* upstream 404s to a clean HTTP 404 without coupling to SDK
|
|
14
|
+
* error-class identity.
|
|
22
15
|
*
|
|
23
16
|
* Not Genie-specific: a Databricks `statement_id` is workspace
|
|
24
17
|
* scoped and lives in the Statement Execution API regardless of
|