@dbx-tools/appkit-mastra 0.9.153 → 0.9.157

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.
Files changed (76) hide show
  1. package/README.md +4 -3
  2. package/index.ts +32 -24
  3. package/lib/index.d.ts +32 -24
  4. package/lib/index.js +32 -23
  5. package/lib/src/agents.d.ts +5 -6
  6. package/lib/src/agents.js +12 -15
  7. package/lib/src/chart.js +33 -33
  8. package/lib/src/chat.js +10 -13
  9. package/lib/src/config.d.ts +12 -13
  10. package/lib/src/config.js +4 -4
  11. package/lib/src/evaluation.js +7 -9
  12. package/lib/src/feedback-mode.d.ts +1 -1
  13. package/lib/src/feedback-mode.js +1 -1
  14. package/lib/src/filesystems.js +6 -6
  15. package/lib/src/follow-up-suggestions.js +10 -10
  16. package/lib/src/genie-chat.js +27 -29
  17. package/lib/src/genie.d.ts +2 -2
  18. package/lib/src/genie.js +29 -29
  19. package/lib/src/identity.d.ts +3 -30
  20. package/lib/src/identity.js +2 -27
  21. package/lib/src/memory.d.ts +1 -1
  22. package/lib/src/memory.js +24 -6
  23. package/lib/src/mlflow.d.ts +4 -4
  24. package/lib/src/mlflow.js +15 -18
  25. package/lib/src/model.d.ts +3 -3
  26. package/lib/src/model.js +6 -6
  27. package/lib/src/monty-sandbox.js +8 -8
  28. package/lib/src/observability.d.ts +6 -5
  29. package/lib/src/observability.js +8 -6
  30. package/lib/src/plugin.d.ts +1 -1
  31. package/lib/src/plugin.js +49 -51
  32. package/lib/src/remote-skills.d.ts +3 -4
  33. package/lib/src/remote-skills.js +46 -46
  34. package/lib/src/rest.d.ts +2 -2
  35. package/lib/src/rest.js +3 -3
  36. package/lib/src/server.js +17 -20
  37. package/lib/src/serving.js +10 -11
  38. package/lib/src/statement.js +7 -7
  39. package/lib/src/storage-schema.js +4 -4
  40. package/lib/src/summarize.js +5 -5
  41. package/lib/src/telemetry.d.ts +0 -6
  42. package/lib/src/telemetry.js +34 -41
  43. package/lib/src/validation.js +3 -4
  44. package/lib/src/workspaces.d.ts +2 -2
  45. package/lib/src/workspaces.js +34 -36
  46. package/lib/src/writer.d.ts +2 -2
  47. package/lib/src/writer.js +3 -3
  48. package/package.json +17 -305
  49. package/src/agents.ts +27 -21
  50. package/src/chart.ts +43 -37
  51. package/src/chat.ts +10 -12
  52. package/src/config.ts +14 -15
  53. package/src/evaluation.ts +6 -8
  54. package/src/feedback-mode.ts +1 -1
  55. package/src/filesystems.ts +5 -5
  56. package/src/follow-up-suggestions.ts +9 -9
  57. package/src/genie-chat.ts +32 -31
  58. package/src/genie.ts +29 -29
  59. package/src/identity.ts +3 -38
  60. package/src/memory.ts +24 -6
  61. package/src/mlflow.ts +21 -21
  62. package/src/model.ts +7 -7
  63. package/src/monty-sandbox.ts +7 -7
  64. package/src/observability.ts +8 -6
  65. package/src/plugin.ts +78 -65
  66. package/src/remote-skills.ts +63 -55
  67. package/src/rest.ts +4 -4
  68. package/src/server.ts +32 -20
  69. package/src/serving.ts +14 -11
  70. package/src/statement.ts +10 -6
  71. package/src/storage-schema.ts +3 -3
  72. package/src/summarize.ts +4 -4
  73. package/src/telemetry.ts +49 -55
  74. package/src/validation.ts +2 -3
  75. package/src/workspaces.ts +52 -42
  76. package/src/writer.ts +3 -3
package/src/mlflow.ts CHANGED
@@ -26,9 +26,13 @@
26
26
  */
27
27
 
28
28
  import { ConfigurationError, createWorkspaceClient } from "@databricks/appkit";
29
- import { appkit } from "@dbx-tools/appkit";
30
- import { asyncUtils, environmentUtils, errorUtils, log, object } from "@dbx-tools/shared-core";
31
- import { feedback } from "@dbx-tools/shared-mastra";
29
+ import { type WorkspaceClientLike } from "@dbx-tools/appkit";
30
+ import { log, sleep, isDatabricksAppEnv, toError, isRecord } from "@dbx-tools/shared-core";
31
+ import {
32
+ type MlflowFeedbackRequest,
33
+ DEFAULT_FEEDBACK_NAME,
34
+ DEFAULT_COMMENT_NAME,
35
+ } from "@dbx-tools/shared-mastra";
32
36
  import { TraceLocationType, TraceMetadataKey } from "@mlflow/core";
33
37
  import { TraceInfo } from "@mlflow/core/dist/core/entities/trace_info.js";
34
38
  import { TraceState } from "@mlflow/core/dist/core/entities/trace_state.js";
@@ -118,7 +122,7 @@ export class AgentTraceSpanProcessor implements SpanProcessor {
118
122
  }
119
123
 
120
124
  /** Workspace client carried on an AppKit execution context. */
121
- type WorkspaceClient = appkit.WorkspaceClientLike;
125
+ type WorkspaceClient = WorkspaceClientLike;
122
126
 
123
127
  /** Experiment tag Databricks stores as `catalog.schema.table_prefix`. */
124
128
  const TRACE_DESTINATION_PATH_TAG = "mlflow.experiment.databricksTraceDestinationPath";
@@ -157,14 +161,14 @@ function experimentTagMap(raw: unknown): Map<string, string> {
157
161
  const tags = new Map<string, string>();
158
162
  if (Array.isArray(raw)) {
159
163
  for (const tag of raw) {
160
- if (!object.isRecord(tag) || typeof tag.key !== "string" || typeof tag.value !== "string") {
164
+ if (!isRecord(tag) || typeof tag.key !== "string" || typeof tag.value !== "string") {
161
165
  continue;
162
166
  }
163
167
  tags.set(tag.key, tag.value);
164
168
  }
165
169
  return tags;
166
170
  }
167
- if (!object.isRecord(raw)) return tags;
171
+ if (!isRecord(raw)) return tags;
168
172
  for (const [key, value] of Object.entries(raw)) {
169
173
  if (typeof value === "string") tags.set(key, value);
170
174
  }
@@ -327,7 +331,7 @@ function configuredExperiment(): { id?: string; name?: string } {
327
331
 
328
332
  /** Tracking URI for direct local MLflow tracing, with CLI-profile auth injected. */
329
333
  export function directMlflowTrackingUri(): string | undefined {
330
- if (environmentUtils.isDatabricksAppEnv()) return undefined;
334
+ if (isDatabricksAppEnv()) return undefined;
331
335
  const configured = process.env.MLFLOW_TRACKING_URI?.trim();
332
336
  if (configured && configured !== "databricks") return configured;
333
337
  const profile = process.env.DATABRICKS_CONFIG_PROFILE?.trim();
@@ -360,16 +364,14 @@ export function directMlflowTraceLocation():
360
364
  /** Whether the local direct-to-experiment MLflow SDK has enough configuration. */
361
365
  export function directMlflowTracingConfigured(): boolean {
362
366
  return Boolean(
363
- !environmentUtils.isDatabricksAppEnv() &&
364
- process.env.MLFLOW_EXPERIMENT_ID?.trim() &&
365
- directMlflowTrackingUri(),
367
+ !isDatabricksAppEnv() && process.env.MLFLOW_EXPERIMENT_ID?.trim() && directMlflowTrackingUri(),
366
368
  );
367
369
  }
368
370
 
369
371
  /** Whether a Databricks App can promote OTLP spans into full MLflow trace info. */
370
372
  export function appMlflowTraceInfoConfigured(): boolean {
371
373
  return Boolean(
372
- environmentUtils.isDatabricksAppEnv() &&
374
+ isDatabricksAppEnv() &&
373
375
  (process.env.MLFLOW_EXPERIMENT_ID?.trim() || process.env.MLFLOW_EXPERIMENT_NAME?.trim()) &&
374
376
  (process.env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim() ||
375
377
  process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT?.trim()),
@@ -395,7 +397,7 @@ export async function initializeAppMlflowTraceInfo(client?: WorkspaceClient): Pr
395
397
  return true;
396
398
  } catch (err) {
397
399
  logger.warn("Databricks Apps MLflow trace-info promotion disabled", {
398
- error: errorUtils.toError(err),
400
+ error: toError(err),
399
401
  });
400
402
  // Startup uses the service principal. Permit one later request-scoped
401
403
  // client to resolve experiment metadata when that principal cannot read it.
@@ -468,7 +470,7 @@ export function persistAppMlflowTraceInfo(params: AppMlflowTraceInfo): void {
468
470
  .catch((err) => {
469
471
  logger.warn("Databricks Apps MLflow trace-info promotion failed", {
470
472
  traceId: params.traceId,
471
- error: errorUtils.toError(err),
473
+ error: toError(err),
472
474
  });
473
475
  })
474
476
  .finally(() => pendingAppMlflowTraceInfo.delete(pending));
@@ -511,7 +513,7 @@ async function detectedDirectMlflowTraceLocation(
511
513
  } catch (err) {
512
514
  logger.warn("direct MLflow UC trace-location detection failed", {
513
515
  experimentId,
514
- error: errorUtils.toError(err),
516
+ error: toError(err),
515
517
  });
516
518
  return undefined;
517
519
  }
@@ -575,7 +577,7 @@ export async function initializeDirectMlflowTracing(): Promise<boolean> {
575
577
  return true;
576
578
  } catch (err) {
577
579
  logger.warn("direct MLflow tracing disabled", {
578
- error: errorUtils.toError(err),
580
+ error: toError(err),
579
581
  });
580
582
  return false;
581
583
  }
@@ -712,7 +714,7 @@ async function resolveExperimentId(client: WorkspaceClient): Promise<string | un
712
714
  }
713
715
 
714
716
  /** Parameters for {@link logFeedback}. */
715
- export type LogFeedbackParams = feedback.MlflowFeedbackRequest & {
717
+ export type LogFeedbackParams = MlflowFeedbackRequest & {
716
718
  /** Identity the feedback is attributed to (user email / id). */
717
719
  sourceId?: string;
718
720
  };
@@ -731,9 +733,7 @@ export async function logFeedback(
731
733
  // A comment with no thumbs value is logged as text feedback; a value
732
734
  // (with an optional comment as the rationale) is the thumbs path.
733
735
  const hasValue = params.value !== undefined;
734
- const name =
735
- params.name?.trim() ||
736
- (hasValue ? feedback.DEFAULT_FEEDBACK_NAME : feedback.DEFAULT_COMMENT_NAME);
736
+ const name = params.name?.trim() || (hasValue ? DEFAULT_FEEDBACK_NAME : DEFAULT_COMMENT_NAME);
737
737
  const value = hasValue ? params.value : params.comment;
738
738
  const assessmentTraceId = mlflowAssessmentTraceId(
739
739
  params.traceId,
@@ -762,7 +762,7 @@ export async function logFeedback(
762
762
  logger.warn("feedback request failed", {
763
763
  traceId: params.traceId,
764
764
  assessmentTraceId,
765
- error: errorUtils.toError(err),
765
+ error: toError(err),
766
766
  });
767
767
  return undefined;
768
768
  }
@@ -776,7 +776,7 @@ export async function logFeedback(
776
776
  // Trace export is async; a fresh trace may not exist yet. Retry a
777
777
  // few times with a short backoff before giving up softly.
778
778
  if (res.status === 404 && attempt < NOT_FOUND_RETRIES) {
779
- await asyncUtils.sleep(NOT_FOUND_BACKOFF_MS * (attempt + 1));
779
+ await sleep(NOT_FOUND_BACKOFF_MS * (attempt + 1));
780
780
  continue;
781
781
  }
782
782
  logger.warn("feedback not recorded", {
package/src/model.ts CHANGED
@@ -23,14 +23,14 @@
23
23
  */
24
24
 
25
25
  import { createWorkspaceClient, type WorkspaceClient } from "@databricks/appkit";
26
- import { appkit } from "@dbx-tools/appkit";
27
- import { classes, policy, resolve } from "@dbx-tools/model";
26
+ import { tryGetExecutionContext } from "@dbx-tools/appkit";
27
+ import { classes, policy, resolve, selection } from "@dbx-tools/model";
28
28
  import {
29
29
  createDatabricksLanguageModel,
30
30
  type DatabricksLanguageModel,
31
- } from "@dbx-tools/model-protocol/provider";
31
+ } from "@dbx-tools/model-protocol";
32
32
  import { log } from "@dbx-tools/shared-core";
33
- import { model, type ServingEndpointSummary } from "@dbx-tools/shared-model";
33
+ import { contracts, type ServingEndpointSummary } from "@dbx-tools/shared-model";
34
34
  import { RequestContext } from "@mastra/core/request-context";
35
35
 
36
36
  import { MASTRA_USER_KEY, type MastraPluginConfig, type User } from "./config.ts";
@@ -41,7 +41,7 @@ import {
41
41
  } from "./serving.ts";
42
42
  import { recordActiveTraceAuth, recordActiveTraceModel } from "./telemetry.ts";
43
43
 
44
- type ModelClass = model.ModelClass;
44
+ type ModelClass = contracts.ModelClass;
45
45
  const { parseModelClass } = classes;
46
46
  const { selectModel } = resolve;
47
47
 
@@ -89,7 +89,7 @@ function resolveModelWorkspaceContext(
89
89
  requestContext?: RequestContext,
90
90
  ): ResolvedModelWorkspaceClient {
91
91
  const user = requestContext?.get(MASTRA_USER_KEY) as User | undefined;
92
- const executionContext = user?.executionContext ?? appkit.tryGetExecutionContext();
92
+ const executionContext = user?.executionContext ?? tryGetExecutionContext();
93
93
  if (executionContext?.client.config) {
94
94
  return {
95
95
  client: executionContext.client,
@@ -137,7 +137,7 @@ export function resolveDefaultModelId(
137
137
  overrides: BuildModelOverrides = {},
138
138
  ): string {
139
139
  const requested = overrides.modelId ?? process.env.DATABRICKS_SERVING_ENDPOINT_NAME;
140
- return resolve.resolveModel(endpoints, selectionInput(config, requested, overrides.modelClass))
140
+ return selection.resolveModel(endpoints, selectionInput(config, requested, overrides.modelClass))
141
141
  .modelId;
142
142
  }
143
143
 
@@ -10,8 +10,8 @@
10
10
  */
11
11
 
12
12
  import { availableParallelism } from "node:os";
13
- import { configUtils } from "@dbx-tools/core";
14
- import { errorUtils, functionUtils, log } from "@dbx-tools/shared-core";
13
+ import { boolean } from "@dbx-tools/core";
14
+ import { log, toError, errorMessage, memoize } from "@dbx-tools/shared-core";
15
15
  import {
16
16
  MastraSandbox,
17
17
  type CommandResult,
@@ -45,9 +45,9 @@ export function montyMaxProcesses(parallelism: number = availableParallelism()):
45
45
  return Math.max(4, Math.floor(parallelism) * 2);
46
46
  }
47
47
 
48
- const montyContext = functionUtils.memoize(async (): Promise<MontyContext> => {
48
+ const montyContext = memoize(async (): Promise<MontyContext> => {
49
49
  const errors: Error[] = [];
50
- const targets = configUtils.boolean(undefined, "MONTY_FORCE_WASM")
50
+ const targets = boolean(undefined, "MONTY_FORCE_WASM")
51
51
  ? [WASM_MONTY_TARGET]
52
52
  : [NATIVE_MONTY_TARGET, WASM_MONTY_TARGET];
53
53
  for (const target of targets) {
@@ -66,9 +66,9 @@ const montyContext = functionUtils.memoize(async (): Promise<MontyContext> => {
66
66
  pool,
67
67
  };
68
68
  } catch (error) {
69
- errors.push(errorUtils.toError(error));
69
+ errors.push(toError(error));
70
70
  logger.debug(`${target.name} unavailable`, {
71
- error: errorUtils.toError(error),
71
+ error: toError(error),
72
72
  });
73
73
  }
74
74
  }
@@ -208,7 +208,7 @@ export class MontySandbox extends MastraSandbox {
208
208
  if (aborted || options.abortSignal?.aborted) {
209
209
  throw abortReason(options.abortSignal);
210
210
  }
211
- const message = errorUtils.errorMessage(caught);
211
+ const message = errorMessage(caught);
212
212
  output.emit("stderr", output.stderr.value ? `\n${message}` : message);
213
213
  const { crashedError } = await montyContext();
214
214
  const timedOut = caught instanceof crashedError && caught.timedOut;
@@ -17,10 +17,11 @@
17
17
  * ambient OTel context, so when Mastra is invoked from inside an
18
18
  * AppKit HTTP span the trace stays connected.
19
19
  *
20
- * Net effect: Mastra spans get exactly the treatment AppKit's
21
- * `agents` plugin gets. No custom OTLP pipeline lives in this
22
- * package; the OTLP endpoint, headers, and resource attributes are
23
- * driven by the standard OTel env vars
20
+ * Net effect: deployed Mastra spans get exactly the treatment AppKit's
21
+ * `agents` plugin gets. Local direct MLflow tracing uses its own global
22
+ * provider because AppKit has no OTLP processor to start there. No custom
23
+ * OTLP pipeline lives in this package; the OTLP endpoint, headers, and resource
24
+ * attributes are driven by the standard OTel env vars
24
25
  * (`OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_HEADERS`,
25
26
  * `OTEL_SERVICE_NAME`, `OTEL_RESOURCE_ATTRIBUTES`, ...) and consumed
26
27
  * by AppKit's `TelemetryManager`. Set those once and both AppKit and
@@ -92,7 +93,7 @@ export interface BuildObservabilityOptions {
92
93
  * Supports dot notation for nested values per the Mastra docs.
93
94
  */
94
95
  requestContextKeys?: readonly string[];
95
- /** AppKit-owned tracer provider used by the Mastra OTel bridge. */
96
+ /** AppKit-owned provider used unless local direct MLflow tracing owns the global provider. */
96
97
  tracerProvider?: TracerProvider;
97
98
  }
98
99
 
@@ -140,6 +141,7 @@ export async function buildObservability(
140
141
  const directMlflowConfigured =
141
142
  options?.enabled === false || otlpConfigured ? false : await initializeDirectMlflowTracing();
142
143
  if (directMlflowConfigured) configureOtelPropagation();
144
+ const bridgeTracerProvider = directMlflowConfigured ? undefined : options?.tracerProvider;
143
145
  const tracingConfigured = otlpConfigured || directMlflowConfigured;
144
146
 
145
147
  if (options?.enabled === false || (options?.enabled !== true && !tracingConfigured)) {
@@ -190,7 +192,7 @@ export async function buildObservability(
190
192
  serviceName: {
191
193
  serviceName,
192
194
  bridge: new OtelBridge(
193
- options?.tracerProvider ? { tracerProvider: options.tracerProvider } : undefined,
195
+ bridgeTracerProvider ? { tracerProvider: bridgeTracerProvider } : undefined,
194
196
  ),
195
197
  requestContextKeys,
196
198
  },