@dbx-tools/appkit-mastra 0.1.82 → 0.1.83

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 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}:
@@ -3129,33 +3170,42 @@ async function logFeedback(client, params) {
3129
3170
  * by AppKit's `TelemetryManager`. Set those once and both AppKit and
3130
3171
  * Mastra spans end up at the same backend.
3131
3172
  *
3132
- * When `OTEL_EXPORTER_OTLP_ENDPOINT` is unset the bridge's spans go
3133
- * to the global noop tracer, mirroring how the `agents` plugin
3134
- * silently no-ops in the same situation.
3173
+ * When `OTEL_EXPORTER_OTLP_ENDPOINT` is unset the bridge is not
3174
+ * registered at all (unless `observability: true` forces it on), so
3175
+ * Mastra does not emit `[OtelBridge] No OTEL span found` warnings.
3135
3176
  */
3136
3177
  const log$1 = logUtils.logger("mastra/observability");
3137
3178
  const DEFAULT_SERVICE_NAME = "mastra";
3179
+ /** True when AppKit's global OTel pipeline is configured to export traces. */
3180
+ function isOtlpTracingConfigured() {
3181
+ return Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT);
3182
+ }
3138
3183
  /**
3139
3184
  * Build a Mastra `Observability` whose spans ride AppKit's global
3140
3185
  * OTel pipeline via `@mastra/otel-bridge`.
3141
3186
  *
3142
- * Returns `undefined` only if someone explicitly opts out in the
3143
- * future; today it always returns an `Observability` because the
3144
- * bridge degrades gracefully (no-op tracer) when no global OTel SDK
3145
- * is registered. Callers can spread `...(observability ? { observability } : {})`
3146
- * either way to stay forward-compatible.
3187
+ * Returns `undefined` when tracing is off: either the caller passed
3188
+ * `enabled: false`, or auto mode finds no OTLP endpoint (the default).
3189
+ * Skipping the bridge in that case avoids `[OtelBridge] No OTEL span
3190
+ * found` log spam from Mastra spans that have no parent on the noop
3191
+ * tracer.
3147
3192
  */
3148
3193
  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
3194
  const otelBase = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
3152
3195
  const otelTracesOverride = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
3196
+ const otlpConfigured = isOtlpTracingConfigured();
3197
+ if (options?.enabled === false || options?.enabled !== true && !otlpConfigured) {
3198
+ log$1.info("Mastra observability off", { reason: options?.enabled === false ? "disabled in plugin config" : "OTEL_EXPORTER_OTLP_ENDPOINT unset" });
3199
+ return;
3200
+ }
3201
+ const serviceName = options?.serviceName ?? await projectUtils.name() ?? DEFAULT_SERVICE_NAME;
3202
+ const requestContextKeys = [...options?.requestContextKeys ?? TRACE_REQUEST_CONTEXT_KEYS];
3153
3203
  const resolvedTracesUrl = otelTracesOverride ? otelTracesOverride : otelBase ? `${otelBase.replace(/\/+$/, "")}/v1/traces` : void 0;
3154
3204
  log$1.info("Mastra observability wired through OTel bridge", {
3155
3205
  serviceName,
3156
3206
  requestContextKeys,
3157
3207
  otelBase: otelBase ?? "<unset>",
3158
- resolvedTracesUrl: resolvedTracesUrl ?? "<noop; OTLP endpoint unset>"
3208
+ resolvedTracesUrl: resolvedTracesUrl ?? "<unset>"
3159
3209
  });
3160
3210
  return new Observability({ configs: { serviceName: {
3161
3211
  serviceName,
@@ -4042,7 +4092,10 @@ var MastraPlugin = class MastraPlugin extends Plugin {
4042
4092
  log: this.log
4043
4093
  });
4044
4094
  const instanceStorage = memoryBuilder?.instanceStorage();
4045
- const observability = await buildObservability({ serviceName: this.name });
4095
+ const observability = await buildObservability({
4096
+ serviceName: this.name,
4097
+ enabled: this.config.observability
4098
+ });
4046
4099
  this.mcp = buildMcpServer({
4047
4100
  config: this.config,
4048
4101
  pluginName: this.name,
@@ -4125,4 +4178,4 @@ function parseStatementLimit(raw) {
4125
4178
  const mastra = toPlugin(MastraPlugin);
4126
4179
 
4127
4180
  //#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 };
4181
+ 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.82",
3
+ "version": "0.1.83",
4
4
  "dependencies": {
5
5
  "@databricks/sdk-experimental": "^0.17",
6
- "@dbx-tools/appkit-mastra-shared": "0.1.82",
7
- "@dbx-tools/genie": "0.1.82",
8
- "@dbx-tools/genie-shared": "0.1.82",
9
- "@dbx-tools/model": "0.1.82",
10
- "@dbx-tools/shared": "0.1.82",
6
+ "@dbx-tools/appkit-mastra-shared": "0.1.83",
7
+ "@dbx-tools/genie": "0.1.83",
8
+ "@dbx-tools/genie-shared": "0.1.83",
9
+ "@dbx-tools/model": "0.1.83",
10
+ "@dbx-tools/shared": "0.1.83",
11
11
  "@mastra/ai-sdk": "^1",
12
12
  "@mastra/core": "^1",
13
13
  "@mastra/express": "^1",