@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.
- package/README.md +4 -3
- package/index.ts +32 -24
- package/lib/index.d.ts +32 -24
- package/lib/index.js +32 -23
- package/lib/src/agents.d.ts +5 -6
- package/lib/src/agents.js +12 -15
- package/lib/src/chart.js +33 -33
- package/lib/src/chat.js +10 -13
- package/lib/src/config.d.ts +12 -13
- package/lib/src/config.js +4 -4
- package/lib/src/evaluation.js +7 -9
- package/lib/src/feedback-mode.d.ts +1 -1
- package/lib/src/feedback-mode.js +1 -1
- package/lib/src/filesystems.js +6 -6
- package/lib/src/follow-up-suggestions.js +10 -10
- package/lib/src/genie-chat.js +27 -29
- package/lib/src/genie.d.ts +2 -2
- package/lib/src/genie.js +29 -29
- package/lib/src/identity.d.ts +3 -30
- package/lib/src/identity.js +2 -27
- package/lib/src/memory.d.ts +1 -1
- package/lib/src/memory.js +24 -6
- package/lib/src/mlflow.d.ts +4 -4
- package/lib/src/mlflow.js +15 -18
- package/lib/src/model.d.ts +3 -3
- package/lib/src/model.js +6 -6
- package/lib/src/monty-sandbox.js +8 -8
- package/lib/src/observability.d.ts +6 -5
- package/lib/src/observability.js +8 -6
- package/lib/src/plugin.d.ts +1 -1
- package/lib/src/plugin.js +49 -51
- package/lib/src/remote-skills.d.ts +3 -4
- package/lib/src/remote-skills.js +46 -46
- package/lib/src/rest.d.ts +2 -2
- package/lib/src/rest.js +3 -3
- package/lib/src/server.js +17 -20
- package/lib/src/serving.js +10 -11
- package/lib/src/statement.js +7 -7
- package/lib/src/storage-schema.js +4 -4
- package/lib/src/summarize.js +5 -5
- package/lib/src/telemetry.d.ts +0 -6
- package/lib/src/telemetry.js +34 -41
- package/lib/src/validation.js +3 -4
- package/lib/src/workspaces.d.ts +2 -2
- package/lib/src/workspaces.js +34 -36
- package/lib/src/writer.d.ts +2 -2
- package/lib/src/writer.js +3 -3
- package/package.json +17 -305
- package/src/agents.ts +27 -21
- package/src/chart.ts +43 -37
- package/src/chat.ts +10 -12
- package/src/config.ts +14 -15
- package/src/evaluation.ts +6 -8
- package/src/feedback-mode.ts +1 -1
- package/src/filesystems.ts +5 -5
- package/src/follow-up-suggestions.ts +9 -9
- package/src/genie-chat.ts +32 -31
- package/src/genie.ts +29 -29
- package/src/identity.ts +3 -38
- package/src/memory.ts +24 -6
- package/src/mlflow.ts +21 -21
- package/src/model.ts +7 -7
- package/src/monty-sandbox.ts +7 -7
- package/src/observability.ts +8 -6
- package/src/plugin.ts +78 -65
- package/src/remote-skills.ts +63 -55
- package/src/rest.ts +4 -4
- package/src/server.ts +32 -20
- package/src/serving.ts +14 -11
- package/src/statement.ts +10 -6
- package/src/storage-schema.ts +3 -3
- package/src/summarize.ts +4 -4
- package/src/telemetry.ts +49 -55
- package/src/validation.ts +2 -3
- package/src/workspaces.ts +52 -42
- 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 {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
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 =
|
|
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 (!
|
|
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 (!
|
|
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 (
|
|
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
|
-
!
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 =
|
|
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:
|
|
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
|
|
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 {
|
|
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
|
|
31
|
+
} from "@dbx-tools/model-protocol";
|
|
32
32
|
import { log } from "@dbx-tools/shared-core";
|
|
33
|
-
import {
|
|
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 =
|
|
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 ??
|
|
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
|
|
140
|
+
return selection.resolveModel(endpoints, selectionInput(config, requested, overrides.modelClass))
|
|
141
141
|
.modelId;
|
|
142
142
|
}
|
|
143
143
|
|
package/src/monty-sandbox.ts
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { availableParallelism } from "node:os";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
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 =
|
|
48
|
+
const montyContext = memoize(async (): Promise<MontyContext> => {
|
|
49
49
|
const errors: Error[] = [];
|
|
50
|
-
const targets =
|
|
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(
|
|
69
|
+
errors.push(toError(error));
|
|
70
70
|
logger.debug(`${target.name} unavailable`, {
|
|
71
|
-
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 =
|
|
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;
|
package/src/observability.ts
CHANGED
|
@@ -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.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
|
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
|
-
|
|
195
|
+
bridgeTracerProvider ? { tracerProvider: bridgeTracerProvider } : undefined,
|
|
194
196
|
),
|
|
195
197
|
requestContextKeys,
|
|
196
198
|
},
|