mesedi 0.1.0 → 0.6.0
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 +81 -31
- package/dist/_errorClassesGenerated.d.ts +18 -0
- package/dist/_errorClassesGenerated.d.ts.map +1 -0
- package/dist/_errorClassesGenerated.js +24 -0
- package/dist/_errorClassesGenerated.js.map +1 -0
- package/dist/anthropic_integration.d.ts +9 -9
- package/dist/anthropic_integration.d.ts.map +1 -1
- package/dist/anthropic_integration.js +67 -26
- package/dist/anthropic_integration.js.map +1 -1
- package/dist/client.d.ts +32 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +46 -18
- package/dist/client.js.map +1 -1
- package/dist/cohere_integration.d.ts +42 -0
- package/dist/cohere_integration.d.ts.map +1 -0
- package/dist/cohere_integration.js +456 -0
- package/dist/cohere_integration.js.map +1 -0
- package/dist/compress.d.ts +69 -0
- package/dist/compress.d.ts.map +1 -0
- package/dist/compress.js +75 -0
- package/dist/compress.js.map +1 -0
- package/dist/context.d.ts +13 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +15 -5
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +137 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +462 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +19 -6
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +31 -6
- package/dist/events.js.map +1 -1
- package/dist/gemini_integration.d.ts +33 -0
- package/dist/gemini_integration.d.ts.map +1 -0
- package/dist/gemini_integration.js +334 -0
- package/dist/gemini_integration.js.map +1 -0
- package/dist/halt.d.ts +12 -12
- package/dist/halt.js +16 -16
- package/dist/halt.js.map +1 -1
- package/dist/halt_stream.d.ts +6 -6
- package/dist/halt_stream.d.ts.map +1 -1
- package/dist/halt_stream.js +22 -12
- package/dist/halt_stream.js.map +1 -1
- package/dist/index.d.ts +26 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/integrations/langgraph.d.ts +99 -0
- package/dist/integrations/langgraph.d.ts.map +1 -0
- package/dist/integrations/langgraph.js +572 -0
- package/dist/integrations/langgraph.js.map +1 -0
- package/dist/integrations/mastra.d.ts +114 -0
- package/dist/integrations/mastra.d.ts.map +1 -0
- package/dist/integrations/mastra.js +354 -0
- package/dist/integrations/mastra.js.map +1 -0
- package/dist/integrations/openai_agents.d.ts +66 -0
- package/dist/integrations/openai_agents.d.ts.map +1 -0
- package/dist/integrations/openai_agents.js +243 -0
- package/dist/integrations/openai_agents.js.map +1 -0
- package/dist/integrations/promptfoo.d.ts +62 -0
- package/dist/integrations/promptfoo.d.ts.map +1 -0
- package/dist/integrations/promptfoo.js +76 -0
- package/dist/integrations/promptfoo.js.map +1 -0
- package/dist/integrations/ragas.d.ts +65 -0
- package/dist/integrations/ragas.d.ts.map +1 -0
- package/dist/integrations/ragas.js +78 -0
- package/dist/integrations/ragas.js.map +1 -0
- package/dist/integrations/vectara.d.ts +60 -0
- package/dist/integrations/vectara.d.ts.map +1 -0
- package/dist/integrations/vectara.js +59 -0
- package/dist/integrations/vectara.js.map +1 -0
- package/dist/integrations/vercel_ai.d.ts +6 -6
- package/dist/integrations/vercel_ai.js +10 -10
- package/dist/integrations/vercel_ai.js.map +1 -1
- package/dist/observe.d.ts +358 -3
- package/dist/observe.d.ts.map +1 -1
- package/dist/observe.js +536 -4
- package/dist/observe.js.map +1 -1
- package/dist/ollama_integration.d.ts +126 -0
- package/dist/ollama_integration.d.ts.map +1 -0
- package/dist/ollama_integration.js +404 -0
- package/dist/ollama_integration.js.map +1 -0
- package/dist/openai_integration.d.ts +67 -0
- package/dist/openai_integration.d.ts.map +1 -0
- package/dist/openai_integration.js +574 -0
- package/dist/openai_integration.js.map +1 -0
- package/dist/tool.d.ts +1 -1
- package/dist/tool.d.ts.map +1 -1
- package/dist/tool.js +193 -10
- package/dist/tool.js.map +1 -1
- package/dist/truncate.d.ts +84 -0
- package/dist/truncate.d.ts.map +1 -0
- package/dist/truncate.js +134 -0
- package/dist/truncate.js.map +1 -0
- package/dist/vertex_gemini_integration.d.ts +27 -0
- package/dist/vertex_gemini_integration.d.ts.map +1 -0
- package/dist/vertex_gemini_integration.js +229 -0
- package/dist/vertex_gemini_integration.js.map +1 -0
- package/dist/wrap.d.ts +39 -3
- package/dist/wrap.d.ts.map +1 -1
- package/dist/wrap.js +15 -12
- package/dist/wrap.js.map +1 -1
- package/package.json +28 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mastra integration for Mesedi (Wave 4.B).
|
|
3
|
+
*
|
|
4
|
+
* Ships as a Mastra Observability exporter. Consumes Mastra's built-in
|
|
5
|
+
* tracing events and translates them into Mesedi's execution / event
|
|
6
|
+
* schema, then hands off to the standard SDK shipper.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* import { configure } from "mesedi";
|
|
11
|
+
* import { MesediExporter } from "mesedi/integrations/mastra";
|
|
12
|
+
* import { Mastra } from "@mastra/core";
|
|
13
|
+
* import { Observability } from "@mastra/observability";
|
|
14
|
+
*
|
|
15
|
+
* // Once, on Mesedi setup.
|
|
16
|
+
* configure({ apiKey: process.env.MESEDI_API_KEY });
|
|
17
|
+
*
|
|
18
|
+
* // Then wire the exporter into Mastra.
|
|
19
|
+
* const mastra = new Mastra({
|
|
20
|
+
* observability: new Observability({
|
|
21
|
+
* exporters: {
|
|
22
|
+
* mesedi: new MesediExporter(),
|
|
23
|
+
* },
|
|
24
|
+
* }),
|
|
25
|
+
* // ...your agents / workflows
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* Architectural notes.
|
|
29
|
+
*
|
|
30
|
+
* Mastra is OpenTelemetry-first: every agent run, workflow run, LLM
|
|
31
|
+
* call, and tool call emits an OTel-shaped span, and the sanctioned
|
|
32
|
+
* observability integration is to implement an Observability exporter
|
|
33
|
+
* that consumes those spans. Unlike the other Mesedi integrations
|
|
34
|
+
* (LangGraph, OpenAI Agents, Vercel AI SDK), the customer does NOT
|
|
35
|
+
* need to wrap their entry function with `mesedi.wrap()` — Mastra's
|
|
36
|
+
* AGENT_RUN / WORKFLOW_RUN root span is the execution boundary. The
|
|
37
|
+
* exporter opens a Mesedi execution on root-span-start and closes it
|
|
38
|
+
* on root-span-end. All descendant spans on the same trace flow into
|
|
39
|
+
* that execution via an internal trace-id → execution-id map.
|
|
40
|
+
*
|
|
41
|
+
* What the exporter emits:
|
|
42
|
+
*
|
|
43
|
+
* - AGENT_RUN / WORKFLOW_RUN → open Mesedi execution + emit
|
|
44
|
+
* checkpoint events at entry and exit.
|
|
45
|
+
* - MODEL_GENERATION → llm_call event (model, provider, tokens).
|
|
46
|
+
* - TOOL_CALL / MCP_TOOL_CALL / CLIENT_TOOL_CALL → tool_call event.
|
|
47
|
+
* - WORKFLOW_STEP → checkpoint event carrying the step name.
|
|
48
|
+
* - Other span types (RAG_*, MEMORY_OPERATION, WORKSPACE_ACTION,
|
|
49
|
+
* SCORER_*, MAPPING, PROCESSOR_RUN, MODEL_STEP / MODEL_INFERENCE /
|
|
50
|
+
* MODEL_CHUNK) are silently ignored in v1. MODEL_GENERATION is
|
|
51
|
+
* the aggregating span for a full model call — the finer-grained
|
|
52
|
+
* step / inference / chunk spans are noise for Mesedi's detectors
|
|
53
|
+
* and are already rolled up by Mastra.
|
|
54
|
+
*
|
|
55
|
+
* Fail-open posture matches the rest of the SDK: any exception inside
|
|
56
|
+
* the exporter is swallowed and logged via console.warn. Never blocks
|
|
57
|
+
* or breaks the customer's Mastra pipeline.
|
|
58
|
+
*/
|
|
59
|
+
import { BaseExporter } from "@mastra/observability";
|
|
60
|
+
import type { TracingEvent } from "@mastra/core/observability";
|
|
61
|
+
/**
|
|
62
|
+
* Configuration accepted by `new MesediExporter(...)`. Kept tiny on
|
|
63
|
+
* purpose — the SDK's `configure()` already owns apiKey / baseUrl /
|
|
64
|
+
* shipper knobs globally; passing them per-exporter would produce two
|
|
65
|
+
* shippers if the customer ever instantiates two Mastra apps in the
|
|
66
|
+
* same process.
|
|
67
|
+
*/
|
|
68
|
+
export interface MesediExporterConfig {
|
|
69
|
+
/**
|
|
70
|
+
* Optional Mastra tenant identifier attached to every Mesedi
|
|
71
|
+
* execution the exporter opens. Surfaces on the dashboard's
|
|
72
|
+
* cost-by-tenant report and enables provider_incident's cross-
|
|
73
|
+
* tenant clustering. Absent means "unattributed."
|
|
74
|
+
*/
|
|
75
|
+
tenantId?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Mesedi observability exporter for Mastra. Attach an instance via
|
|
79
|
+
* `Observability({ exporters: { mesedi: new MesediExporter() } })` on
|
|
80
|
+
* your `new Mastra(...)` call.
|
|
81
|
+
*/
|
|
82
|
+
export declare class MesediExporter extends BaseExporter {
|
|
83
|
+
name: string;
|
|
84
|
+
private readonly tenantId?;
|
|
85
|
+
/**
|
|
86
|
+
* Maps Mastra traceId → Mesedi executionId. Populated when a root
|
|
87
|
+
* span (AGENT_RUN or WORKFLOW_RUN) starts; removed when it ends.
|
|
88
|
+
* Descendant spans on the same trace look up their execution here.
|
|
89
|
+
*/
|
|
90
|
+
private readonly traceToExecution;
|
|
91
|
+
/**
|
|
92
|
+
* Sequence counter per execution, ticked once per emitted event.
|
|
93
|
+
* Mesedi's backend relies on monotonic sequences to reconstruct
|
|
94
|
+
* event order at ingest.
|
|
95
|
+
*/
|
|
96
|
+
private readonly sequences;
|
|
97
|
+
/**
|
|
98
|
+
* Tracks execution start time in ms epoch so we can compute
|
|
99
|
+
* duration_ms on execution end. Removed when execution closes.
|
|
100
|
+
*/
|
|
101
|
+
private readonly executionStarts;
|
|
102
|
+
constructor(config?: MesediExporterConfig);
|
|
103
|
+
/**
|
|
104
|
+
* Called by @mastra/observability's ObservabilityBus for every
|
|
105
|
+
* span lifecycle event. Base class routes through
|
|
106
|
+
* `applySpanFormatter` first if the customer supplied one.
|
|
107
|
+
*/
|
|
108
|
+
protected _exportTracingEvent(event: TracingEvent): Promise<void>;
|
|
109
|
+
private handleSpanStarted;
|
|
110
|
+
private handleSpanEnded;
|
|
111
|
+
private closeExecution;
|
|
112
|
+
private emitEvent;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=mastra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.d.ts","sourceRoot":"","sources":["../../src/integrations/mastra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAoBH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,4BAA4B,CAAC;AAyBpC;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,IAAI,SAAY;IAEhB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAS;IAEnC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkC;IAEnE;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkC;IAE5D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkC;gBAEtD,MAAM,GAAE,oBAAyB;IAK7C;;;;OAIG;cACa,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBvE,OAAO,CAAC,iBAAiB;IAmCzB,OAAO,CAAC,eAAe;IAgDvB,OAAO,CAAC,cAAc;IAwBtB,OAAO,CAAC,SAAS;CAwBlB"}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mastra integration for Mesedi (Wave 4.B).
|
|
3
|
+
*
|
|
4
|
+
* Ships as a Mastra Observability exporter. Consumes Mastra's built-in
|
|
5
|
+
* tracing events and translates them into Mesedi's execution / event
|
|
6
|
+
* schema, then hands off to the standard SDK shipper.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* import { configure } from "mesedi";
|
|
11
|
+
* import { MesediExporter } from "mesedi/integrations/mastra";
|
|
12
|
+
* import { Mastra } from "@mastra/core";
|
|
13
|
+
* import { Observability } from "@mastra/observability";
|
|
14
|
+
*
|
|
15
|
+
* // Once, on Mesedi setup.
|
|
16
|
+
* configure({ apiKey: process.env.MESEDI_API_KEY });
|
|
17
|
+
*
|
|
18
|
+
* // Then wire the exporter into Mastra.
|
|
19
|
+
* const mastra = new Mastra({
|
|
20
|
+
* observability: new Observability({
|
|
21
|
+
* exporters: {
|
|
22
|
+
* mesedi: new MesediExporter(),
|
|
23
|
+
* },
|
|
24
|
+
* }),
|
|
25
|
+
* // ...your agents / workflows
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* Architectural notes.
|
|
29
|
+
*
|
|
30
|
+
* Mastra is OpenTelemetry-first: every agent run, workflow run, LLM
|
|
31
|
+
* call, and tool call emits an OTel-shaped span, and the sanctioned
|
|
32
|
+
* observability integration is to implement an Observability exporter
|
|
33
|
+
* that consumes those spans. Unlike the other Mesedi integrations
|
|
34
|
+
* (LangGraph, OpenAI Agents, Vercel AI SDK), the customer does NOT
|
|
35
|
+
* need to wrap their entry function with `mesedi.wrap()` — Mastra's
|
|
36
|
+
* AGENT_RUN / WORKFLOW_RUN root span is the execution boundary. The
|
|
37
|
+
* exporter opens a Mesedi execution on root-span-start and closes it
|
|
38
|
+
* on root-span-end. All descendant spans on the same trace flow into
|
|
39
|
+
* that execution via an internal trace-id → execution-id map.
|
|
40
|
+
*
|
|
41
|
+
* What the exporter emits:
|
|
42
|
+
*
|
|
43
|
+
* - AGENT_RUN / WORKFLOW_RUN → open Mesedi execution + emit
|
|
44
|
+
* checkpoint events at entry and exit.
|
|
45
|
+
* - MODEL_GENERATION → llm_call event (model, provider, tokens).
|
|
46
|
+
* - TOOL_CALL / MCP_TOOL_CALL / CLIENT_TOOL_CALL → tool_call event.
|
|
47
|
+
* - WORKFLOW_STEP → checkpoint event carrying the step name.
|
|
48
|
+
* - Other span types (RAG_*, MEMORY_OPERATION, WORKSPACE_ACTION,
|
|
49
|
+
* SCORER_*, MAPPING, PROCESSOR_RUN, MODEL_STEP / MODEL_INFERENCE /
|
|
50
|
+
* MODEL_CHUNK) are silently ignored in v1. MODEL_GENERATION is
|
|
51
|
+
* the aggregating span for a full model call — the finer-grained
|
|
52
|
+
* step / inference / chunk spans are noise for Mesedi's detectors
|
|
53
|
+
* and are already rolled up by Mastra.
|
|
54
|
+
*
|
|
55
|
+
* Fail-open posture matches the rest of the SDK: any exception inside
|
|
56
|
+
* the exporter is swallowed and logged via console.warn. Never blocks
|
|
57
|
+
* or breaks the customer's Mastra pipeline.
|
|
58
|
+
*/
|
|
59
|
+
import { getClient } from "../client.js";
|
|
60
|
+
import { newEventId, newExecutionId } from "../context.js";
|
|
61
|
+
import { EventType, Status, utcNowRfc3339, } from "../events.js";
|
|
62
|
+
// ── Peer-dep imports ─────────────────────────────────────────────────
|
|
63
|
+
//
|
|
64
|
+
// @mastra/observability's BaseExporter is a runtime dep of this
|
|
65
|
+
// module. @mastra/core provides the TracingEvent shape and SpanType
|
|
66
|
+
// discriminator strings. Both are declared as OPTIONAL peer
|
|
67
|
+
// dependencies in package.json — customers who never import this
|
|
68
|
+
// module never pay the install cost.
|
|
69
|
+
import { BaseExporter } from "@mastra/observability";
|
|
70
|
+
// ── Span-type literals ───────────────────────────────────────────────
|
|
71
|
+
//
|
|
72
|
+
// Mastra's SpanType is a runtime enum. We use its VALUES (which are
|
|
73
|
+
// stable string literals like "agent_run", "tool_call") in switch
|
|
74
|
+
// cases below rather than importing the enum object itself. This
|
|
75
|
+
// keeps the enum a compile-time-only concern and avoids pulling the
|
|
76
|
+
// enum's runtime bindings into our output. Matches Mastra's stable
|
|
77
|
+
// wire strings; if Mastra ever renames one, tsc catches it because
|
|
78
|
+
// AnyExportedSpan['type'] is a union of the same string literals.
|
|
79
|
+
const SPAN_AGENT_RUN = "agent_run";
|
|
80
|
+
const SPAN_WORKFLOW_RUN = "workflow_run";
|
|
81
|
+
const SPAN_MODEL_GENERATION = "model_generation";
|
|
82
|
+
const SPAN_TOOL_CALL = "tool_call";
|
|
83
|
+
const SPAN_MCP_TOOL_CALL = "mcp_tool_call";
|
|
84
|
+
const SPAN_CLIENT_TOOL_CALL = "client_tool_call";
|
|
85
|
+
const SPAN_WORKFLOW_STEP = "workflow_step";
|
|
86
|
+
// Truncation budgets, matching the OpenAI Agents integration.
|
|
87
|
+
const MAX_STATE_REPR = 1000;
|
|
88
|
+
const MAX_TOOL_INPUT_REPR = 200;
|
|
89
|
+
const MAX_TOOL_OUTPUT_REPR = 500;
|
|
90
|
+
/**
|
|
91
|
+
* Mesedi observability exporter for Mastra. Attach an instance via
|
|
92
|
+
* `Observability({ exporters: { mesedi: new MesediExporter() } })` on
|
|
93
|
+
* your `new Mastra(...)` call.
|
|
94
|
+
*/
|
|
95
|
+
export class MesediExporter extends BaseExporter {
|
|
96
|
+
name = "mesedi";
|
|
97
|
+
tenantId;
|
|
98
|
+
/**
|
|
99
|
+
* Maps Mastra traceId → Mesedi executionId. Populated when a root
|
|
100
|
+
* span (AGENT_RUN or WORKFLOW_RUN) starts; removed when it ends.
|
|
101
|
+
* Descendant spans on the same trace look up their execution here.
|
|
102
|
+
*/
|
|
103
|
+
traceToExecution = new Map();
|
|
104
|
+
/**
|
|
105
|
+
* Sequence counter per execution, ticked once per emitted event.
|
|
106
|
+
* Mesedi's backend relies on monotonic sequences to reconstruct
|
|
107
|
+
* event order at ingest.
|
|
108
|
+
*/
|
|
109
|
+
sequences = new Map();
|
|
110
|
+
/**
|
|
111
|
+
* Tracks execution start time in ms epoch so we can compute
|
|
112
|
+
* duration_ms on execution end. Removed when execution closes.
|
|
113
|
+
*/
|
|
114
|
+
executionStarts = new Map();
|
|
115
|
+
constructor(config = {}) {
|
|
116
|
+
super({});
|
|
117
|
+
this.tenantId = config.tenantId;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Called by @mastra/observability's ObservabilityBus for every
|
|
121
|
+
* span lifecycle event. Base class routes through
|
|
122
|
+
* `applySpanFormatter` first if the customer supplied one.
|
|
123
|
+
*/
|
|
124
|
+
async _exportTracingEvent(event) {
|
|
125
|
+
try {
|
|
126
|
+
const span = event.exportedSpan;
|
|
127
|
+
switch (event.type) {
|
|
128
|
+
case "span_started":
|
|
129
|
+
this.handleSpanStarted(span);
|
|
130
|
+
break;
|
|
131
|
+
case "span_ended":
|
|
132
|
+
this.handleSpanEnded(span);
|
|
133
|
+
break;
|
|
134
|
+
case "span_updated":
|
|
135
|
+
// Updates are ignored in v1. The relevant fields (tokens,
|
|
136
|
+
// status, output) are re-emitted on SPAN_ENDED, which is
|
|
137
|
+
// when we snapshot state into Mesedi's event schema.
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
// Fail-open: never break the customer's Mastra pipeline.
|
|
143
|
+
console.warn("mesedi mastra exporter: swallowed error", err);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// ── Span-start ─────────────────────────────────────────────────────
|
|
147
|
+
handleSpanStarted(span) {
|
|
148
|
+
if (!isRootSpan(span))
|
|
149
|
+
return;
|
|
150
|
+
// Root span. Open a Mesedi execution.
|
|
151
|
+
const traceId = extractTraceId(span);
|
|
152
|
+
if (!traceId)
|
|
153
|
+
return;
|
|
154
|
+
if (this.traceToExecution.has(traceId))
|
|
155
|
+
return;
|
|
156
|
+
const executionId = newExecutionId();
|
|
157
|
+
this.traceToExecution.set(traceId, executionId);
|
|
158
|
+
this.sequences.set(executionId, 0);
|
|
159
|
+
this.executionStarts.set(executionId, Date.now());
|
|
160
|
+
const execution = {
|
|
161
|
+
execution_id: executionId,
|
|
162
|
+
status: Status.STARTED,
|
|
163
|
+
started_at: utcNowRfc3339(),
|
|
164
|
+
sdk_language: "typescript",
|
|
165
|
+
sdk_version: "0.6.0",
|
|
166
|
+
};
|
|
167
|
+
if (this.tenantId !== undefined)
|
|
168
|
+
execution.tenant_id = this.tenantId;
|
|
169
|
+
const client = getClient();
|
|
170
|
+
client.submitExecutionStart(execution);
|
|
171
|
+
// Also emit an enter checkpoint so semantic_loop / drift see the
|
|
172
|
+
// execution boundary.
|
|
173
|
+
this.emitEvent(executionId, EventType.CHECKPOINT, {
|
|
174
|
+
name: `mastra.${span.type}.enter`,
|
|
175
|
+
agent: extractAgentName(span),
|
|
176
|
+
agent_event: "enter",
|
|
177
|
+
state_repr: summarize(inputRepr(span)),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
// ── Span-end ───────────────────────────────────────────────────────
|
|
181
|
+
handleSpanEnded(span) {
|
|
182
|
+
const traceId = extractTraceId(span);
|
|
183
|
+
if (!traceId)
|
|
184
|
+
return;
|
|
185
|
+
const executionId = this.traceToExecution.get(traceId);
|
|
186
|
+
if (!executionId)
|
|
187
|
+
return;
|
|
188
|
+
switch (span.type) {
|
|
189
|
+
case SPAN_AGENT_RUN:
|
|
190
|
+
case SPAN_WORKFLOW_RUN:
|
|
191
|
+
this.emitEvent(executionId, EventType.CHECKPOINT, {
|
|
192
|
+
name: `mastra.${span.type}.exit`,
|
|
193
|
+
agent: extractAgentName(span),
|
|
194
|
+
agent_event: "exit",
|
|
195
|
+
state_repr: summarize(outputRepr(span)),
|
|
196
|
+
});
|
|
197
|
+
this.closeExecution(traceId, executionId, span);
|
|
198
|
+
break;
|
|
199
|
+
case SPAN_MODEL_GENERATION:
|
|
200
|
+
this.emitEvent(executionId, EventType.LLM_CALL, modelPayload(span));
|
|
201
|
+
break;
|
|
202
|
+
case SPAN_TOOL_CALL:
|
|
203
|
+
case SPAN_MCP_TOOL_CALL:
|
|
204
|
+
case SPAN_CLIENT_TOOL_CALL:
|
|
205
|
+
this.emitEvent(executionId, span.type === SPAN_MCP_TOOL_CALL
|
|
206
|
+
? EventType.MCP_CALL
|
|
207
|
+
: EventType.TOOL_CALL, toolPayload(span));
|
|
208
|
+
break;
|
|
209
|
+
case SPAN_WORKFLOW_STEP:
|
|
210
|
+
this.emitEvent(executionId, EventType.CHECKPOINT, {
|
|
211
|
+
name: `mastra.workflow_step.${extractName(span) ?? "unknown"}`,
|
|
212
|
+
state_repr: summarize(outputRepr(span)),
|
|
213
|
+
});
|
|
214
|
+
break;
|
|
215
|
+
// All other span types are ignored in v1. See the file header
|
|
216
|
+
// comment for rationale.
|
|
217
|
+
default:
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
closeExecution(traceId, executionId, span) {
|
|
222
|
+
const startedAtMs = this.executionStarts.get(executionId);
|
|
223
|
+
const durationMs = startedAtMs != null ? Math.max(0, Date.now() - startedAtMs) : undefined;
|
|
224
|
+
const execution = {
|
|
225
|
+
execution_id: executionId,
|
|
226
|
+
status: mapStatus(span),
|
|
227
|
+
started_at: utcNowRfc3339(),
|
|
228
|
+
sdk_language: "typescript",
|
|
229
|
+
sdk_version: "0.6.0",
|
|
230
|
+
ended_at: utcNowRfc3339(),
|
|
231
|
+
};
|
|
232
|
+
if (durationMs !== undefined)
|
|
233
|
+
execution.duration_ms = durationMs;
|
|
234
|
+
getClient().submitExecutionEnd(execution);
|
|
235
|
+
this.traceToExecution.delete(traceId);
|
|
236
|
+
this.sequences.delete(executionId);
|
|
237
|
+
this.executionStarts.delete(executionId);
|
|
238
|
+
}
|
|
239
|
+
emitEvent(executionId, eventType, payload) {
|
|
240
|
+
const nextSeq = (this.sequences.get(executionId) ?? 0) + 1;
|
|
241
|
+
this.sequences.set(executionId, nextSeq);
|
|
242
|
+
const event = {
|
|
243
|
+
event_id: newEventId(),
|
|
244
|
+
execution_id: executionId,
|
|
245
|
+
event_type: eventType,
|
|
246
|
+
sequence: nextSeq,
|
|
247
|
+
timestamp: utcNowRfc3339(),
|
|
248
|
+
payload,
|
|
249
|
+
};
|
|
250
|
+
getClient().submitEvent(event);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// ── Helpers ──────────────────────────────────────────────────────────
|
|
254
|
+
function isRootSpan(span) {
|
|
255
|
+
// A root span has no parent. Mastra encodes this as either
|
|
256
|
+
// parentSpanId being undefined or explicitly null. We check for
|
|
257
|
+
// both. AGENT_RUN and WORKFLOW_RUN with no parent are treated as
|
|
258
|
+
// the execution boundary.
|
|
259
|
+
if (span.type !== SPAN_AGENT_RUN && span.type !== SPAN_WORKFLOW_RUN) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
const s = span;
|
|
263
|
+
return s.parentSpanId == null;
|
|
264
|
+
}
|
|
265
|
+
function extractTraceId(span) {
|
|
266
|
+
const s = span;
|
|
267
|
+
return typeof s.traceId === "string" && s.traceId.length > 0
|
|
268
|
+
? s.traceId
|
|
269
|
+
: undefined;
|
|
270
|
+
}
|
|
271
|
+
function extractAgentName(span) {
|
|
272
|
+
const s = span;
|
|
273
|
+
if (typeof s.attributes?.agentName === "string" && s.attributes.agentName) {
|
|
274
|
+
return s.attributes.agentName;
|
|
275
|
+
}
|
|
276
|
+
if (typeof s.attributes?.name === "string" && s.attributes.name) {
|
|
277
|
+
return s.attributes.name;
|
|
278
|
+
}
|
|
279
|
+
if (typeof s.name === "string" && s.name)
|
|
280
|
+
return s.name;
|
|
281
|
+
return "unknown";
|
|
282
|
+
}
|
|
283
|
+
function extractName(span) {
|
|
284
|
+
const s = span;
|
|
285
|
+
if (typeof s.attributes?.stepId === "string" && s.attributes.stepId) {
|
|
286
|
+
return s.attributes.stepId;
|
|
287
|
+
}
|
|
288
|
+
if (typeof s.attributes?.name === "string" && s.attributes.name) {
|
|
289
|
+
return s.attributes.name;
|
|
290
|
+
}
|
|
291
|
+
if (typeof s.name === "string" && s.name)
|
|
292
|
+
return s.name;
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
function inputRepr(span) {
|
|
296
|
+
const s = span;
|
|
297
|
+
return s.attributes?.prompt ?? s.attributes?.input ?? s.input ?? "";
|
|
298
|
+
}
|
|
299
|
+
function outputRepr(span) {
|
|
300
|
+
const s = span;
|
|
301
|
+
return s.attributes?.output ?? s.attributes?.result ?? s.output ?? "";
|
|
302
|
+
}
|
|
303
|
+
function modelPayload(span) {
|
|
304
|
+
const s = span;
|
|
305
|
+
const model = s.attributes?.model ?? "unknown";
|
|
306
|
+
const provider = s.attributes?.provider ?? "unknown";
|
|
307
|
+
const tokensIn = s.attributes?.internalUsage?.inputTokens;
|
|
308
|
+
const tokensOut = s.attributes?.internalUsage?.outputTokens;
|
|
309
|
+
const payload = {
|
|
310
|
+
model,
|
|
311
|
+
provider,
|
|
312
|
+
user_message: summarize(inputRepr(span), MAX_STATE_REPR),
|
|
313
|
+
response_text: summarize(outputRepr(span), MAX_STATE_REPR),
|
|
314
|
+
};
|
|
315
|
+
if (tokensIn !== undefined)
|
|
316
|
+
payload["input_tokens"] = tokensIn;
|
|
317
|
+
if (tokensOut !== undefined)
|
|
318
|
+
payload["output_tokens"] = tokensOut;
|
|
319
|
+
return payload;
|
|
320
|
+
}
|
|
321
|
+
function toolPayload(span) {
|
|
322
|
+
const name = extractName(span) ?? "unknown";
|
|
323
|
+
const s = span;
|
|
324
|
+
const status = s.attributes?.error ? "error" : "ok";
|
|
325
|
+
return {
|
|
326
|
+
tool_name: name,
|
|
327
|
+
arguments: summarize(s.attributes?.input, MAX_TOOL_INPUT_REPR),
|
|
328
|
+
return_value: summarize(s.attributes?.output, MAX_TOOL_OUTPUT_REPR),
|
|
329
|
+
status,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function mapStatus(span) {
|
|
333
|
+
const s = span;
|
|
334
|
+
if (s.attributes?.tripwireAbort)
|
|
335
|
+
return Status.HALTED;
|
|
336
|
+
if (s.attributes?.error)
|
|
337
|
+
return Status.CRASHED;
|
|
338
|
+
return Status.COMPLETED;
|
|
339
|
+
}
|
|
340
|
+
function summarize(value, maxLen = MAX_STATE_REPR) {
|
|
341
|
+
if (value == null)
|
|
342
|
+
return "";
|
|
343
|
+
let r;
|
|
344
|
+
try {
|
|
345
|
+
r = typeof value === "string" ? value : JSON.stringify(value);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
r = String(value);
|
|
349
|
+
}
|
|
350
|
+
if (r.length > maxLen)
|
|
351
|
+
r = r.slice(0, maxLen - 3) + "...";
|
|
352
|
+
return r;
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=mastra.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mastra.js","sourceRoot":"","sources":["../../src/integrations/mastra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAEL,SAAS,EAET,MAAM,EACN,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,wEAAwE;AACxE,EAAE;AACF,gEAAgE;AAChE,oEAAoE;AACpE,4DAA4D;AAC5D,iEAAiE;AACjE,qCAAqC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAMrD,wEAAwE;AACxE,EAAE;AACF,oEAAoE;AACpE,kEAAkE;AAClE,iEAAiE;AACjE,oEAAoE;AACpE,mEAAmE;AACnE,mEAAmE;AACnE,kEAAkE;AAElE,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AACjD,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,MAAM,kBAAkB,GAAG,eAAe,CAAC;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AI,CAAC,CAAC,UAAU,EAAE,KAAK;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC;IAC/C,OAAO,MAAM,CAAC,SAAS,CAAC;AAC1B,CAAC;AAED,SAAS,SAAS,CAAC,KAAc,EAAE,SAAiB,cAAc;IAChE,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7B,IAAI,CAAS,CAAC;IACd,IAAI,CAAC;QACH,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,GAAG,MAAM;QAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;IAC1D,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Agents SDK integration for Mesedi (Mesedi #28).
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
*
|
|
6
|
+
* import { wrap } from "mesedi";
|
|
7
|
+
* import { MesediRunHooks } from "mesedi/integrations/openai_agents";
|
|
8
|
+
* import { Agent, Runner } from "@openai/agents";
|
|
9
|
+
*
|
|
10
|
+
* const triage = new Agent({ name: "triage", ...});
|
|
11
|
+
* const planner = new Agent({ name: "planner", ...});
|
|
12
|
+
*
|
|
13
|
+
* export const runUserRequest = wrap(async (question: string) => {
|
|
14
|
+
* const result = await Runner.run(
|
|
15
|
+
* triage,
|
|
16
|
+
* question,
|
|
17
|
+
* { hooks: new MesediRunHooks() },
|
|
18
|
+
* );
|
|
19
|
+
* return result.finalOutput;
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* What the hooks emit:
|
|
23
|
+
*
|
|
24
|
+
* - `checkpoint` events at every agent start AND end with the
|
|
25
|
+
* agent name and a truncated input/output repr. Feeds the
|
|
26
|
+
* semantic_loop detector (#6).
|
|
27
|
+
* - `agent_handoff` events on every handoff between agents.
|
|
28
|
+
* from_agent / to_agent come straight from the hook arguments,
|
|
29
|
+
* handoff_kind defaults to `"transfer"`. Feeds cascading_failure
|
|
30
|
+
* (#12) and coordination_deadlock (#13).
|
|
31
|
+
* - `tool_call` events for every tool invocation, mirroring
|
|
32
|
+
* `mesedi.tool()` wire format.
|
|
33
|
+
*
|
|
34
|
+
* Out of scope for v1:
|
|
35
|
+
*
|
|
36
|
+
* - `llm_call` events. The OAI Agents SDK does not expose
|
|
37
|
+
* per-LLM-call hooks in its public RunHooks surface as of the
|
|
38
|
+
* version this integration was written against. For
|
|
39
|
+
* Anthropic-backed runs use the existing
|
|
40
|
+
* `instrumentAnthropic()` patch; an OpenAI-backed equivalent
|
|
41
|
+
* is not currently provided.
|
|
42
|
+
* - Streaming hooks (`Runner.runStreamed`). Not currently
|
|
43
|
+
* instrumented.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Mesedi-emitting implementation of the `@openai/agents` RunHooks
|
|
47
|
+
* interface. Pass an instance to `Runner.run(..., { hooks: ... })`.
|
|
48
|
+
*
|
|
49
|
+
* All emissions go through Mesedi's standard event submitter, which
|
|
50
|
+
* is non-blocking (events are batched on a background shipper). The
|
|
51
|
+
* OAI Agents SDK's async runner is therefore never blocked on
|
|
52
|
+
* Mesedi I/O.
|
|
53
|
+
*
|
|
54
|
+
* Outside a `wrap()` execution context, all emissions silently
|
|
55
|
+
* no-op (matching the rest of Mesedi's observe layer).
|
|
56
|
+
*/
|
|
57
|
+
export declare class MesediRunHooks {
|
|
58
|
+
readonly name = "mesedi-openai-agents";
|
|
59
|
+
private toolStarts;
|
|
60
|
+
onAgentStart(_context: unknown, agent: unknown): Promise<void>;
|
|
61
|
+
onAgentEnd(_context: unknown, agent: unknown, output: unknown): Promise<void>;
|
|
62
|
+
onHandoff(context: unknown, fromAgent: unknown, toAgent: unknown): Promise<void>;
|
|
63
|
+
onToolStart(_context: unknown, _agent: unknown, tool: unknown): Promise<void>;
|
|
64
|
+
onToolEnd(_context: unknown, _agent: unknown, tool: unknown, result: unknown): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=openai_agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai_agents.d.ts","sourceRoot":"","sources":["../../src/integrations/openai_agents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAcH;;;;;;;;;;;GAWG;AACH,qBAAa,cAAc;IAIzB,QAAQ,CAAC,IAAI,0BAA0B;IAMvC,OAAO,CAAC,UAAU,CAAkC;IAI9C,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9D,UAAU,CACd,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC;IAOV,SAAS,CACb,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC;IAWV,WAAW,CACf,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,CAAC;IAKV,SAAS,CACb,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,IAAI,CAAC;CAajB"}
|