@dbx-tools/appkit-mastra 0.1.82 → 0.1.84
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 +19 -1
- package/dist/index.js +67 -13
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -474,6 +474,19 @@ interface MastraPluginConfig extends BasePluginConfig {
|
|
|
474
474
|
* to drill deep into a dataset within a single turn.
|
|
475
475
|
*/
|
|
476
476
|
agentMaxSteps?: number;
|
|
477
|
+
/**
|
|
478
|
+
* Wire Mastra spans into AppKit's global OTel pipeline via
|
|
479
|
+
* `@mastra/otel-bridge`.
|
|
480
|
+
*
|
|
481
|
+
* - `undefined` (default, auto): on only when
|
|
482
|
+
* `OTEL_EXPORTER_OTLP_ENDPOINT` or
|
|
483
|
+
* `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` is set. When unset, the
|
|
484
|
+
* bridge is skipped so Mastra does not log
|
|
485
|
+
* `[OtelBridge] No OTEL span found` on the noop tracer.
|
|
486
|
+
* - `true`: force on even without an OTLP endpoint.
|
|
487
|
+
* - `false`: force off.
|
|
488
|
+
*/
|
|
489
|
+
observability?: boolean;
|
|
477
490
|
/**
|
|
478
491
|
* Log user feedback (thumbs up/down + freeform comments) to MLflow as
|
|
479
492
|
* trace assessments, and surface the feedback controls in the chat UI.
|
|
@@ -889,6 +902,11 @@ declare function buildAgents(opts: {
|
|
|
889
902
|
memoryBuilder?: MemoryBuilder;
|
|
890
903
|
log: logUtils.Logger;
|
|
891
904
|
}): Promise<BuiltAgents>;
|
|
905
|
+
/**
|
|
906
|
+
* Tool ids on `tools` that are approval-gated (`requireApproval: true`).
|
|
907
|
+
* Keys are used as a fallback when a tool omits an explicit `id`.
|
|
908
|
+
*/
|
|
909
|
+
declare function approvalGatedToolIds(tools: MastraTools): string[];
|
|
892
910
|
//#endregion
|
|
893
911
|
//#region packages/appkit-mastra/src/chart.d.ts
|
|
894
912
|
/**
|
|
@@ -1386,4 +1404,4 @@ declare function buildSummarizeTool(config: MastraPluginConfig): _mastra_core_to
|
|
|
1386
1404
|
maxWords?: number | undefined;
|
|
1387
1405
|
}, unknown, unknown, unknown, _mastra_core_tools0.ToolExecutionContext<unknown, unknown, unknown>, "summarize", unknown>;
|
|
1388
1406
|
//#endregion
|
|
1389
|
-
export { AppKitToolOptions, BuiltAgents, ChartPlannerRequest, DEFAULT_AGENT_MAX_STEPS, DEFAULT_GENIE_ALIAS, DEFAULT_STYLE_INSTRUCTIONS, FALLBACK_AGENT_ID, FetchChartOptions, GENIE_INSTRUCTIONS, GenieSpaceConfig, GenieSpacesConfig, MASTRA_MODEL_OVERRIDE_KEY, MASTRA_REQUEST_ID_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, MastraAgentDefinition, MastraMcpConfig, MastraMemoryConfig, MastraMemoryConfigOverride, MastraPlugin, MastraPluginConfig, MastraPluginToolkitProvider, MastraPlugins, MastraStorageConfigOverride, MastraTools, MastraToolsFn, type ModelOverrideRequest, PrepareChartOptions, ResolvedMcp, type SummarizeOptions, TRACE_REQUEST_CONTEXT_KEYS, ToolkitOptions, User, buildAgents, buildGenieToolkitProvider, buildGenieTools, buildMcpServer, buildRenderDataTool, buildSummarizeTool, chartPlannerRequestSchema, collectSpaceSuggestions, createAgent, createTool, extractModelOverride, fetchChart, mastra, normalizeGenieSpaces, prepareChart, resolveGenieSpaces, summarizeText, tool };
|
|
1407
|
+
export { AppKitToolOptions, BuiltAgents, ChartPlannerRequest, DEFAULT_AGENT_MAX_STEPS, DEFAULT_GENIE_ALIAS, DEFAULT_STYLE_INSTRUCTIONS, FALLBACK_AGENT_ID, FetchChartOptions, GENIE_INSTRUCTIONS, GenieSpaceConfig, GenieSpacesConfig, MASTRA_MODEL_OVERRIDE_KEY, MASTRA_REQUEST_ID_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, MastraAgentDefinition, MastraMcpConfig, MastraMemoryConfig, MastraMemoryConfigOverride, MastraPlugin, MastraPluginConfig, MastraPluginToolkitProvider, MastraPlugins, MastraStorageConfigOverride, MastraTools, MastraToolsFn, type ModelOverrideRequest, PrepareChartOptions, ResolvedMcp, type SummarizeOptions, TRACE_REQUEST_CONTEXT_KEYS, ToolkitOptions, User, approvalGatedToolIds, buildAgents, buildGenieToolkitProvider, buildGenieTools, buildMcpServer, buildRenderDataTool, buildSummarizeTool, chartPlannerRequestSchema, collectSpaceSuggestions, createAgent, createTool, extractModelOverride, fetchChart, mastra, normalizeGenieSpaces, prepareChart, resolveGenieSpaces, summarizeText, tool };
|
package/dist/index.js
CHANGED
|
@@ -2188,8 +2188,14 @@ async function buildAgents(opts) {
|
|
|
2188
2188
|
const outputProcessors = [new ResultProcessor()];
|
|
2189
2189
|
const inputProcessors = [...config.stripStaleCharts === false ? [] : [stripStaleChartsProcessor]];
|
|
2190
2190
|
const agents = {};
|
|
2191
|
+
const approvalGatedByAgent = [];
|
|
2191
2192
|
for (const [id, def] of Object.entries(definitions)) {
|
|
2192
2193
|
const tools = await resolveTools(def.tools, plugins, ambientTools);
|
|
2194
|
+
const gated = approvalGatedToolIds(tools);
|
|
2195
|
+
if (gated.length > 0) approvalGatedByAgent.push({
|
|
2196
|
+
agentId: id,
|
|
2197
|
+
toolIds: gated
|
|
2198
|
+
});
|
|
2193
2199
|
const memory = memoryBuilder?.forAgent(id, def);
|
|
2194
2200
|
agents[id] = new Agent({
|
|
2195
2201
|
id,
|
|
@@ -2211,6 +2217,7 @@ async function buildAgents(opts) {
|
|
|
2211
2217
|
});
|
|
2212
2218
|
}
|
|
2213
2219
|
if (!agents[defaultAgentId]) throw new Error(`mastra: defaultAgent "${defaultAgentId}" not found in registered agents (${ids.join(", ") || "none"})`);
|
|
2220
|
+
assertApprovalGatedToolsHaveStorage(approvalGatedByAgent, memoryBuilder);
|
|
2214
2221
|
log.info("agents ready", {
|
|
2215
2222
|
ids,
|
|
2216
2223
|
defaultAgentId
|
|
@@ -2222,6 +2229,40 @@ async function buildAgents(opts) {
|
|
|
2222
2229
|
};
|
|
2223
2230
|
}
|
|
2224
2231
|
/**
|
|
2232
|
+
* Tool ids on `tools` that are approval-gated (`requireApproval: true`).
|
|
2233
|
+
* Keys are used as a fallback when a tool omits an explicit `id`.
|
|
2234
|
+
*/
|
|
2235
|
+
function approvalGatedToolIds(tools) {
|
|
2236
|
+
if (!tools || typeof tools !== "object") return [];
|
|
2237
|
+
const ids = [];
|
|
2238
|
+
for (const [key, tool] of Object.entries(tools)) {
|
|
2239
|
+
if (!isApprovalGatedTool(tool)) continue;
|
|
2240
|
+
ids.push(resolveToolId(tool, key));
|
|
2241
|
+
}
|
|
2242
|
+
return ids;
|
|
2243
|
+
}
|
|
2244
|
+
/** True when a Mastra / AI SDK tool pauses for human approval before execute. */
|
|
2245
|
+
function isApprovalGatedTool(tool) {
|
|
2246
|
+
if (!tool || typeof tool !== "object") return false;
|
|
2247
|
+
return tool.requireApproval === true;
|
|
2248
|
+
}
|
|
2249
|
+
function resolveToolId(tool, fallbackKey) {
|
|
2250
|
+
if (tool && typeof tool === "object" && typeof tool.id === "string") return tool.id;
|
|
2251
|
+
return fallbackKey;
|
|
2252
|
+
}
|
|
2253
|
+
/**
|
|
2254
|
+
* Approval-gated tools suspend the agent loop until a human approves.
|
|
2255
|
+
* Mastra persists those suspended runs in Mastra-instance-level storage
|
|
2256
|
+
* (`memoryBuilder.instanceStorage()`), not per-agent memory - so boot
|
|
2257
|
+
* must fail fast when such a tool is registered without storage.
|
|
2258
|
+
*/
|
|
2259
|
+
function assertApprovalGatedToolsHaveStorage(gated, memoryBuilder) {
|
|
2260
|
+
if (gated.length === 0) return;
|
|
2261
|
+
if (memoryBuilder?.instanceStorage()) return;
|
|
2262
|
+
const detail = gated.map(({ agentId, toolIds }) => `${agentId}: ${toolIds.join(", ")}`).join("; ");
|
|
2263
|
+
throw new Error(`mastra: approval-gated tools require plugin storage (PostgresStore) to persist suspended runs. Affected agents/tools: ${detail}. Register lakebase() before mastra() so storage auto-enables, or pass storage: true explicitly.`);
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2225
2266
|
* Best-effort description of the *static* default model an agent will
|
|
2226
2267
|
* resolve to at call time. Walks the same precedence ladder as
|
|
2227
2268
|
* {@link resolveModel} / {@link buildModel}:
|
|
@@ -2917,6 +2958,7 @@ var MemoryBuilder = class {
|
|
|
2917
2958
|
function buildSharedPgVector(pool) {
|
|
2918
2959
|
const vector = new PgVector({
|
|
2919
2960
|
id: `pg${randomUUID()}`,
|
|
2961
|
+
schemaName: "mastra_instance",
|
|
2920
2962
|
host: "-1",
|
|
2921
2963
|
port: -1,
|
|
2922
2964
|
database: "_",
|
|
@@ -3129,33 +3171,42 @@ async function logFeedback(client, params) {
|
|
|
3129
3171
|
* by AppKit's `TelemetryManager`. Set those once and both AppKit and
|
|
3130
3172
|
* Mastra spans end up at the same backend.
|
|
3131
3173
|
*
|
|
3132
|
-
* When `OTEL_EXPORTER_OTLP_ENDPOINT` is unset the bridge
|
|
3133
|
-
*
|
|
3134
|
-
*
|
|
3174
|
+
* When `OTEL_EXPORTER_OTLP_ENDPOINT` is unset the bridge is not
|
|
3175
|
+
* registered at all (unless `observability: true` forces it on), so
|
|
3176
|
+
* Mastra does not emit `[OtelBridge] No OTEL span found` warnings.
|
|
3135
3177
|
*/
|
|
3136
3178
|
const log$1 = logUtils.logger("mastra/observability");
|
|
3137
3179
|
const DEFAULT_SERVICE_NAME = "mastra";
|
|
3180
|
+
/** True when AppKit's global OTel pipeline is configured to export traces. */
|
|
3181
|
+
function isOtlpTracingConfigured() {
|
|
3182
|
+
return Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT);
|
|
3183
|
+
}
|
|
3138
3184
|
/**
|
|
3139
3185
|
* Build a Mastra `Observability` whose spans ride AppKit's global
|
|
3140
3186
|
* OTel pipeline via `@mastra/otel-bridge`.
|
|
3141
3187
|
*
|
|
3142
|
-
* Returns `undefined`
|
|
3143
|
-
*
|
|
3144
|
-
* bridge
|
|
3145
|
-
*
|
|
3146
|
-
*
|
|
3188
|
+
* Returns `undefined` when tracing is off: either the caller passed
|
|
3189
|
+
* `enabled: false`, or auto mode finds no OTLP endpoint (the default).
|
|
3190
|
+
* Skipping the bridge in that case avoids `[OtelBridge] No OTEL span
|
|
3191
|
+
* found` log spam from Mastra spans that have no parent on the noop
|
|
3192
|
+
* tracer.
|
|
3147
3193
|
*/
|
|
3148
3194
|
async function buildObservability(options) {
|
|
3149
|
-
const serviceName = options?.serviceName ?? await projectUtils.name() ?? DEFAULT_SERVICE_NAME;
|
|
3150
|
-
const requestContextKeys = [...options?.requestContextKeys ?? TRACE_REQUEST_CONTEXT_KEYS];
|
|
3151
3195
|
const otelBase = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
3152
3196
|
const otelTracesOverride = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
|
|
3197
|
+
const otlpConfigured = isOtlpTracingConfigured();
|
|
3198
|
+
if (options?.enabled === false || options?.enabled !== true && !otlpConfigured) {
|
|
3199
|
+
log$1.info("Mastra observability off", { reason: options?.enabled === false ? "disabled in plugin config" : "OTEL_EXPORTER_OTLP_ENDPOINT unset" });
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3202
|
+
const serviceName = options?.serviceName ?? await projectUtils.name() ?? DEFAULT_SERVICE_NAME;
|
|
3203
|
+
const requestContextKeys = [...options?.requestContextKeys ?? TRACE_REQUEST_CONTEXT_KEYS];
|
|
3153
3204
|
const resolvedTracesUrl = otelTracesOverride ? otelTracesOverride : otelBase ? `${otelBase.replace(/\/+$/, "")}/v1/traces` : void 0;
|
|
3154
3205
|
log$1.info("Mastra observability wired through OTel bridge", {
|
|
3155
3206
|
serviceName,
|
|
3156
3207
|
requestContextKeys,
|
|
3157
3208
|
otelBase: otelBase ?? "<unset>",
|
|
3158
|
-
resolvedTracesUrl: resolvedTracesUrl ?? "<
|
|
3209
|
+
resolvedTracesUrl: resolvedTracesUrl ?? "<unset>"
|
|
3159
3210
|
});
|
|
3160
3211
|
return new Observability({ configs: { serviceName: {
|
|
3161
3212
|
serviceName,
|
|
@@ -4042,7 +4093,10 @@ var MastraPlugin = class MastraPlugin extends Plugin {
|
|
|
4042
4093
|
log: this.log
|
|
4043
4094
|
});
|
|
4044
4095
|
const instanceStorage = memoryBuilder?.instanceStorage();
|
|
4045
|
-
const observability = await buildObservability({
|
|
4096
|
+
const observability = await buildObservability({
|
|
4097
|
+
serviceName: this.name,
|
|
4098
|
+
enabled: this.config.observability
|
|
4099
|
+
});
|
|
4046
4100
|
this.mcp = buildMcpServer({
|
|
4047
4101
|
config: this.config,
|
|
4048
4102
|
pluginName: this.name,
|
|
@@ -4125,4 +4179,4 @@ function parseStatementLimit(raw) {
|
|
|
4125
4179
|
const mastra = toPlugin(MastraPlugin);
|
|
4126
4180
|
|
|
4127
4181
|
//#endregion
|
|
4128
|
-
export { DEFAULT_AGENT_MAX_STEPS, DEFAULT_GENIE_ALIAS, DEFAULT_STYLE_INSTRUCTIONS, FALLBACK_AGENT_ID, GENIE_INSTRUCTIONS, MASTRA_MODEL_OVERRIDE_KEY, MASTRA_REQUEST_ID_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, MastraPlugin, TRACE_REQUEST_CONTEXT_KEYS, buildAgents, buildGenieToolkitProvider, buildGenieTools, buildMcpServer, buildRenderDataTool, buildSummarizeTool, chartPlannerRequestSchema, collectSpaceSuggestions, createAgent, createTool, extractModelOverride, fetchChart, mastra, normalizeGenieSpaces, prepareChart, resolveGenieSpaces, summarizeText, tool };
|
|
4182
|
+
export { DEFAULT_AGENT_MAX_STEPS, DEFAULT_GENIE_ALIAS, DEFAULT_STYLE_INSTRUCTIONS, FALLBACK_AGENT_ID, GENIE_INSTRUCTIONS, MASTRA_MODEL_OVERRIDE_KEY, MASTRA_REQUEST_ID_KEY, MASTRA_USER_EMAIL_KEY, MASTRA_USER_KEY, MASTRA_USER_NAME_KEY, MastraPlugin, TRACE_REQUEST_CONTEXT_KEYS, approvalGatedToolIds, buildAgents, buildGenieToolkitProvider, buildGenieTools, buildMcpServer, buildRenderDataTool, buildSummarizeTool, chartPlannerRequestSchema, collectSpaceSuggestions, createAgent, createTool, extractModelOverride, fetchChart, mastra, normalizeGenieSpaces, prepareChart, resolveGenieSpaces, summarizeText, tool };
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbx-tools/appkit-mastra",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.84",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@databricks/sdk-experimental": "^0.17",
|
|
6
|
-
"@dbx-tools/appkit-mastra-shared": "0.1.
|
|
7
|
-
"@dbx-tools/genie": "0.1.
|
|
8
|
-
"@dbx-tools/genie-shared": "0.1.
|
|
9
|
-
"@dbx-tools/model": "0.1.
|
|
10
|
-
"@dbx-tools/shared": "0.1.
|
|
6
|
+
"@dbx-tools/appkit-mastra-shared": "0.1.84",
|
|
7
|
+
"@dbx-tools/genie": "0.1.84",
|
|
8
|
+
"@dbx-tools/genie-shared": "0.1.84",
|
|
9
|
+
"@dbx-tools/model": "0.1.84",
|
|
10
|
+
"@dbx-tools/shared": "0.1.84",
|
|
11
11
|
"@mastra/ai-sdk": "^1",
|
|
12
12
|
"@mastra/core": "^1",
|
|
13
13
|
"@mastra/express": "^1",
|