@mastra/deployer 0.2.8 → 0.2.9-alpha.1

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.
@@ -1,4 +1,6 @@
1
- Elastic License 2.0 (ELv2)
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
2
4
 
3
5
  **Acceptance**
4
6
  By using the software, you agree to all of the terms and conditions below.
@@ -1,6 +1,7 @@
1
1
  import { default as babel_2 } from '@babel/core';
2
2
  import { BlankSchema } from 'hono/types';
3
3
  import type { Config } from '@mastra/core';
4
+ import { Container } from '@mastra/core/di';
4
5
  import { ContentfulStatusCode } from 'hono/utils/http-status';
5
6
  import type { Context } from 'hono';
6
7
  import { Hono } from 'hono';
@@ -459,6 +460,7 @@ export declare function validateBody(body: Record<string, unknown>): void;
459
460
 
460
461
  declare type Variables = {
461
462
  mastra: Mastra;
463
+ container: Container;
462
464
  clients: Set<{
463
465
  controller: ReadableStreamDefaultController;
464
466
  }>;
@@ -1,6 +1,7 @@
1
1
  import { default as babel_2 } from '@babel/core';
2
2
  import { BlankSchema } from 'hono/types';
3
3
  import type { Config } from '@mastra/core';
4
+ import { Container } from '@mastra/core/di';
4
5
  import { ContentfulStatusCode } from 'hono/utils/http-status';
5
6
  import type { Context } from 'hono';
6
7
  import { Hono } from 'hono';
@@ -459,6 +460,7 @@ export declare function validateBody(body: Record<string, unknown>): void;
459
460
 
460
461
  declare type Variables = {
461
462
  mastra: Mastra;
463
+ container: Container;
462
464
  clients: Set<{
463
465
  controller: ReadableStreamDefaultController;
464
466
  }>;
@@ -12,6 +12,7 @@ var mime = require('hono/utils/mime');
12
12
  var fs = require('fs');
13
13
  var html = require('hono/html');
14
14
  var core = require('@mastra/core');
15
+ var di = require('@mastra/core/di');
15
16
  var hono = require('hono');
16
17
  var bodyLimit = require('hono/body-limit');
17
18
  var cors = require('hono/cors');
@@ -898,10 +899,12 @@ async function generateHandler(c2) {
898
899
  try {
899
900
  const mastra = c2.get("mastra");
900
901
  const agentId = c2.req.param("agentId");
902
+ const container = c2.get("container");
901
903
  const body = await c2.req.json();
902
904
  const result = await agents.generateHandler({
903
905
  mastra,
904
906
  agentId,
907
+ container,
905
908
  body
906
909
  });
907
910
  return c2.json(result);
@@ -913,10 +916,12 @@ async function streamGenerateHandler(c2) {
913
916
  try {
914
917
  const mastra = c2.get("mastra");
915
918
  const agentId = c2.req.param("agentId");
919
+ const container = c2.get("container");
916
920
  const body = await c2.req.json();
917
921
  const streamResponse = await agents.streamGenerateHandler({
918
922
  mastra,
919
923
  agentId,
924
+ container,
920
925
  body
921
926
  });
922
927
  return streamResponse;
@@ -1169,10 +1174,12 @@ async function getNetworkByIdHandler(c2) {
1169
1174
  async function generateHandler2(c2) {
1170
1175
  try {
1171
1176
  const mastra = c2.get("mastra");
1177
+ const container = c2.get("container");
1172
1178
  const networkId = c2.req.param("networkId");
1173
1179
  const body = await c2.req.json();
1174
1180
  const result = await network.generateHandler({
1175
1181
  mastra,
1182
+ container,
1176
1183
  networkId,
1177
1184
  body
1178
1185
  });
@@ -1184,10 +1191,12 @@ async function generateHandler2(c2) {
1184
1191
  async function streamGenerateHandler2(c2) {
1185
1192
  try {
1186
1193
  const mastra = c2.get("mastra");
1194
+ const container = c2.get("container");
1187
1195
  const networkId = c2.req.param("networkId");
1188
1196
  const body = await c2.req.json();
1189
1197
  const streamResponse = await network.streamGenerateHandler({
1190
1198
  mastra,
1199
+ container,
1191
1200
  networkId,
1192
1201
  body
1193
1202
  });
@@ -1579,11 +1588,13 @@ async function getWorkflowByIdHandler(c2) {
1579
1588
  async function startAsyncWorkflowHandler(c2) {
1580
1589
  try {
1581
1590
  const mastra = c2.get("mastra");
1591
+ const container = c2.get("container");
1582
1592
  const workflowId = c2.req.param("workflowId");
1583
1593
  const triggerData = await c2.req.json();
1584
1594
  const runId = c2.req.query("runId");
1585
1595
  const result = await workflows.startAsyncWorkflowHandler({
1586
1596
  mastra,
1597
+ container,
1587
1598
  workflowId,
1588
1599
  runId,
1589
1600
  triggerData
@@ -1611,11 +1622,13 @@ async function createRunHandler(c2) {
1611
1622
  async function startWorkflowRunHandler(c2) {
1612
1623
  try {
1613
1624
  const mastra = c2.get("mastra");
1625
+ const container = c2.get("container");
1614
1626
  const workflowId = c2.req.param("workflowId");
1615
1627
  const triggerData = await c2.req.json();
1616
1628
  const runId = c2.req.query("runId");
1617
1629
  await workflows.startWorkflowRunHandler({
1618
1630
  mastra,
1631
+ container,
1619
1632
  workflowId,
1620
1633
  runId,
1621
1634
  triggerData
@@ -1666,6 +1679,7 @@ function watchWorkflowHandler(c2) {
1666
1679
  async function resumeAsyncWorkflowHandler(c2) {
1667
1680
  try {
1668
1681
  const mastra = c2.get("mastra");
1682
+ const container = c2.get("container");
1669
1683
  const workflowId = c2.req.param("workflowId");
1670
1684
  const runId = c2.req.query("runId");
1671
1685
  const { stepId, context } = await c2.req.json();
@@ -1674,6 +1688,7 @@ async function resumeAsyncWorkflowHandler(c2) {
1674
1688
  }
1675
1689
  const result = await workflows.resumeAsyncWorkflowHandler({
1676
1690
  mastra,
1691
+ container,
1677
1692
  workflowId,
1678
1693
  runId,
1679
1694
  body: { stepId, context }
@@ -1686,6 +1701,7 @@ async function resumeAsyncWorkflowHandler(c2) {
1686
1701
  async function resumeWorkflowHandler(c2) {
1687
1702
  try {
1688
1703
  const mastra = c2.get("mastra");
1704
+ const container = c2.get("container");
1689
1705
  const workflowId = c2.req.param("workflowId");
1690
1706
  const runId = c2.req.query("runId");
1691
1707
  const { stepId, context } = await c2.req.json();
@@ -1694,6 +1710,7 @@ async function resumeWorkflowHandler(c2) {
1694
1710
  }
1695
1711
  await workflows.resumeWorkflowHandler({
1696
1712
  mastra,
1713
+ container,
1697
1714
  workflowId,
1698
1715
  runId,
1699
1716
  body: { stepId, context }
@@ -1840,10 +1857,37 @@ async function createHonoServer(mastra, options = {}) {
1840
1857
  });
1841
1858
  return acc;
1842
1859
  }, {});
1860
+ app.use("*", async function setTelemetryInfo(c2, next) {
1861
+ const requestId = c2.req.header("x-request-id") ?? crypto.randomUUID();
1862
+ const span = core.Telemetry.getActiveSpan();
1863
+ if (span) {
1864
+ span.setAttribute("http.request_id", requestId);
1865
+ span.updateName(`${c2.req.method} ${c2.req.path}`);
1866
+ const newCtx = core.Telemetry.setBaggage({
1867
+ "http.request_id": requestId
1868
+ });
1869
+ await new Promise((resolve) => {
1870
+ core.Telemetry.withContext(newCtx, async () => {
1871
+ await next();
1872
+ resolve(true);
1873
+ });
1874
+ });
1875
+ } else {
1876
+ await next();
1877
+ }
1878
+ });
1843
1879
  if (options.apiReqLogs) {
1844
1880
  app.use(logger.logger());
1845
1881
  }
1846
1882
  app.onError(errorHandler);
1883
+ app.use("*", function setContext(c2, next) {
1884
+ const container = new di.Container();
1885
+ c2.set("container", container);
1886
+ c2.set("mastra", mastra);
1887
+ c2.set("tools", tools);
1888
+ c2.set("playground", options.playground === true);
1889
+ return next();
1890
+ });
1847
1891
  const serverMiddleware = mastra.getServerMiddleware?.();
1848
1892
  if (serverMiddleware && serverMiddleware.length > 0) {
1849
1893
  for (const m2 of serverMiddleware) {
@@ -1854,37 +1898,16 @@ async function createHonoServer(mastra, options = {}) {
1854
1898
  app.use("*", timeout.timeout(server?.timeout ?? 1e3 * 30));
1855
1899
  } else {
1856
1900
  const corsConfig = {
1857
- origin: server?.cors?.origin ?? "*",
1858
- allowMethods: server?.cors?.allowMethods ?? ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
1859
- credentials: server?.cors?.credentials ?? false,
1860
- maxAge: server?.cors?.maxAge ?? 3600,
1901
+ origin: "*",
1902
+ allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
1903
+ credentials: false,
1904
+ maxAge: 3600,
1905
+ ...server?.cors,
1861
1906
  allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type", ...server?.cors?.allowHeaders ?? []],
1862
1907
  exposeHeaders: ["Content-Length", "X-Requested-With", ...server?.cors?.exposeHeaders ?? []]
1863
1908
  };
1864
1909
  app.use("*", timeout.timeout(server?.timeout ?? 1e3 * 30), cors.cors(corsConfig));
1865
1910
  }
1866
- app.use("*", async (c2, next) => {
1867
- c2.set("mastra", mastra);
1868
- c2.set("tools", tools);
1869
- c2.set("playground", options.playground === true);
1870
- const requestId = c2.req.header("x-request-id") ?? crypto.randomUUID();
1871
- const span = core.Telemetry.getActiveSpan();
1872
- if (span) {
1873
- span.setAttribute("http.request_id", requestId);
1874
- span.updateName(`${c2.req.method} ${c2.req.path}`);
1875
- const newCtx = core.Telemetry.setBaggage({
1876
- "http.request_id": requestId
1877
- });
1878
- await new Promise((resolve) => {
1879
- core.Telemetry.withContext(newCtx, async () => {
1880
- await next();
1881
- resolve(true);
1882
- });
1883
- });
1884
- } else {
1885
- await next();
1886
- }
1887
- });
1888
1911
  const bodyLimitOptions = {
1889
1912
  maxSize: 4.5 * 1024 * 1024,
1890
1913
  // 4.5 MB,
@@ -1915,7 +1938,6 @@ async function createHonoServer(mastra, options = {}) {
1915
1938
  if (route.openapi) {
1916
1939
  middlewares.push(h(route.openapi));
1917
1940
  }
1918
- console.log({ path: route.path, middlewares });
1919
1941
  if (route.method === "GET") {
1920
1942
  app.get(route.path, ...middlewares, route.handler);
1921
1943
  } else if (route.method === "POST") {
@@ -10,6 +10,7 @@ import { getMimeType } from 'hono/utils/mime';
10
10
  import { createReadStream, lstatSync } from 'fs';
11
11
  import { html } from 'hono/html';
12
12
  import { Telemetry } from '@mastra/core';
13
+ import { Container } from '@mastra/core/di';
13
14
  import { Hono } from 'hono';
14
15
  import { bodyLimit } from 'hono/body-limit';
15
16
  import { cors } from 'hono/cors';
@@ -892,10 +893,12 @@ async function generateHandler(c2) {
892
893
  try {
893
894
  const mastra = c2.get("mastra");
894
895
  const agentId = c2.req.param("agentId");
896
+ const container = c2.get("container");
895
897
  const body = await c2.req.json();
896
898
  const result = await generateHandler$2({
897
899
  mastra,
898
900
  agentId,
901
+ container,
899
902
  body
900
903
  });
901
904
  return c2.json(result);
@@ -907,10 +910,12 @@ async function streamGenerateHandler(c2) {
907
910
  try {
908
911
  const mastra = c2.get("mastra");
909
912
  const agentId = c2.req.param("agentId");
913
+ const container = c2.get("container");
910
914
  const body = await c2.req.json();
911
915
  const streamResponse = await streamGenerateHandler$2({
912
916
  mastra,
913
917
  agentId,
918
+ container,
914
919
  body
915
920
  });
916
921
  return streamResponse;
@@ -1163,10 +1168,12 @@ async function getNetworkByIdHandler(c2) {
1163
1168
  async function generateHandler2(c2) {
1164
1169
  try {
1165
1170
  const mastra = c2.get("mastra");
1171
+ const container = c2.get("container");
1166
1172
  const networkId = c2.req.param("networkId");
1167
1173
  const body = await c2.req.json();
1168
1174
  const result = await generateHandler$1({
1169
1175
  mastra,
1176
+ container,
1170
1177
  networkId,
1171
1178
  body
1172
1179
  });
@@ -1178,10 +1185,12 @@ async function generateHandler2(c2) {
1178
1185
  async function streamGenerateHandler2(c2) {
1179
1186
  try {
1180
1187
  const mastra = c2.get("mastra");
1188
+ const container = c2.get("container");
1181
1189
  const networkId = c2.req.param("networkId");
1182
1190
  const body = await c2.req.json();
1183
1191
  const streamResponse = await streamGenerateHandler$1({
1184
1192
  mastra,
1193
+ container,
1185
1194
  networkId,
1186
1195
  body
1187
1196
  });
@@ -1573,11 +1582,13 @@ async function getWorkflowByIdHandler(c2) {
1573
1582
  async function startAsyncWorkflowHandler(c2) {
1574
1583
  try {
1575
1584
  const mastra = c2.get("mastra");
1585
+ const container = c2.get("container");
1576
1586
  const workflowId = c2.req.param("workflowId");
1577
1587
  const triggerData = await c2.req.json();
1578
1588
  const runId = c2.req.query("runId");
1579
1589
  const result = await startAsyncWorkflowHandler$1({
1580
1590
  mastra,
1591
+ container,
1581
1592
  workflowId,
1582
1593
  runId,
1583
1594
  triggerData
@@ -1605,11 +1616,13 @@ async function createRunHandler(c2) {
1605
1616
  async function startWorkflowRunHandler(c2) {
1606
1617
  try {
1607
1618
  const mastra = c2.get("mastra");
1619
+ const container = c2.get("container");
1608
1620
  const workflowId = c2.req.param("workflowId");
1609
1621
  const triggerData = await c2.req.json();
1610
1622
  const runId = c2.req.query("runId");
1611
1623
  await startWorkflowRunHandler$1({
1612
1624
  mastra,
1625
+ container,
1613
1626
  workflowId,
1614
1627
  runId,
1615
1628
  triggerData
@@ -1660,6 +1673,7 @@ function watchWorkflowHandler(c2) {
1660
1673
  async function resumeAsyncWorkflowHandler(c2) {
1661
1674
  try {
1662
1675
  const mastra = c2.get("mastra");
1676
+ const container = c2.get("container");
1663
1677
  const workflowId = c2.req.param("workflowId");
1664
1678
  const runId = c2.req.query("runId");
1665
1679
  const { stepId, context } = await c2.req.json();
@@ -1668,6 +1682,7 @@ async function resumeAsyncWorkflowHandler(c2) {
1668
1682
  }
1669
1683
  const result = await resumeAsyncWorkflowHandler$1({
1670
1684
  mastra,
1685
+ container,
1671
1686
  workflowId,
1672
1687
  runId,
1673
1688
  body: { stepId, context }
@@ -1680,6 +1695,7 @@ async function resumeAsyncWorkflowHandler(c2) {
1680
1695
  async function resumeWorkflowHandler(c2) {
1681
1696
  try {
1682
1697
  const mastra = c2.get("mastra");
1698
+ const container = c2.get("container");
1683
1699
  const workflowId = c2.req.param("workflowId");
1684
1700
  const runId = c2.req.query("runId");
1685
1701
  const { stepId, context } = await c2.req.json();
@@ -1688,6 +1704,7 @@ async function resumeWorkflowHandler(c2) {
1688
1704
  }
1689
1705
  await resumeWorkflowHandler$1({
1690
1706
  mastra,
1707
+ container,
1691
1708
  workflowId,
1692
1709
  runId,
1693
1710
  body: { stepId, context }
@@ -1834,10 +1851,37 @@ async function createHonoServer(mastra, options = {}) {
1834
1851
  });
1835
1852
  return acc;
1836
1853
  }, {});
1854
+ app.use("*", async function setTelemetryInfo(c2, next) {
1855
+ const requestId = c2.req.header("x-request-id") ?? randomUUID();
1856
+ const span = Telemetry.getActiveSpan();
1857
+ if (span) {
1858
+ span.setAttribute("http.request_id", requestId);
1859
+ span.updateName(`${c2.req.method} ${c2.req.path}`);
1860
+ const newCtx = Telemetry.setBaggage({
1861
+ "http.request_id": requestId
1862
+ });
1863
+ await new Promise((resolve) => {
1864
+ Telemetry.withContext(newCtx, async () => {
1865
+ await next();
1866
+ resolve(true);
1867
+ });
1868
+ });
1869
+ } else {
1870
+ await next();
1871
+ }
1872
+ });
1837
1873
  if (options.apiReqLogs) {
1838
1874
  app.use(logger());
1839
1875
  }
1840
1876
  app.onError(errorHandler);
1877
+ app.use("*", function setContext(c2, next) {
1878
+ const container = new Container();
1879
+ c2.set("container", container);
1880
+ c2.set("mastra", mastra);
1881
+ c2.set("tools", tools);
1882
+ c2.set("playground", options.playground === true);
1883
+ return next();
1884
+ });
1841
1885
  const serverMiddleware = mastra.getServerMiddleware?.();
1842
1886
  if (serverMiddleware && serverMiddleware.length > 0) {
1843
1887
  for (const m2 of serverMiddleware) {
@@ -1848,37 +1892,16 @@ async function createHonoServer(mastra, options = {}) {
1848
1892
  app.use("*", timeout(server?.timeout ?? 1e3 * 30));
1849
1893
  } else {
1850
1894
  const corsConfig = {
1851
- origin: server?.cors?.origin ?? "*",
1852
- allowMethods: server?.cors?.allowMethods ?? ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
1853
- credentials: server?.cors?.credentials ?? false,
1854
- maxAge: server?.cors?.maxAge ?? 3600,
1895
+ origin: "*",
1896
+ allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
1897
+ credentials: false,
1898
+ maxAge: 3600,
1899
+ ...server?.cors,
1855
1900
  allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type", ...server?.cors?.allowHeaders ?? []],
1856
1901
  exposeHeaders: ["Content-Length", "X-Requested-With", ...server?.cors?.exposeHeaders ?? []]
1857
1902
  };
1858
1903
  app.use("*", timeout(server?.timeout ?? 1e3 * 30), cors(corsConfig));
1859
1904
  }
1860
- app.use("*", async (c2, next) => {
1861
- c2.set("mastra", mastra);
1862
- c2.set("tools", tools);
1863
- c2.set("playground", options.playground === true);
1864
- const requestId = c2.req.header("x-request-id") ?? randomUUID();
1865
- const span = Telemetry.getActiveSpan();
1866
- if (span) {
1867
- span.setAttribute("http.request_id", requestId);
1868
- span.updateName(`${c2.req.method} ${c2.req.path}`);
1869
- const newCtx = Telemetry.setBaggage({
1870
- "http.request_id": requestId
1871
- });
1872
- await new Promise((resolve) => {
1873
- Telemetry.withContext(newCtx, async () => {
1874
- await next();
1875
- resolve(true);
1876
- });
1877
- });
1878
- } else {
1879
- await next();
1880
- }
1881
- });
1882
1905
  const bodyLimitOptions = {
1883
1906
  maxSize: 4.5 * 1024 * 1024,
1884
1907
  // 4.5 MB,
@@ -1909,7 +1932,6 @@ async function createHonoServer(mastra, options = {}) {
1909
1932
  if (route.openapi) {
1910
1933
  middlewares.push(h(route.openapi));
1911
1934
  }
1912
- console.log({ path: route.path, middlewares });
1913
1935
  if (route.method === "GET") {
1914
1936
  app.get(route.path, ...middlewares, route.handler);
1915
1937
  } else if (route.method === "POST") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer",
3
- "version": "0.2.8",
3
+ "version": "0.2.9-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "keywords": [],
85
85
  "author": "",
86
- "license": "ISC",
86
+ "license": "Elastic-2.0",
87
87
  "dependencies": {
88
88
  "@babel/core": "^7.26.10",
89
89
  "@babel/helper-module-imports": "^7.25.9",
@@ -105,8 +105,8 @@
105
105
  "rollup-plugin-node-externals": "^8.0.0",
106
106
  "typescript-paths": "^1.5.1",
107
107
  "zod": "^3.24.2",
108
- "@mastra/core": "^0.8.2",
109
- "@mastra/server": "^1.0.2"
108
+ "@mastra/core": "^0.8.3-alpha.1",
109
+ "@mastra/server": "^1.0.3-alpha.1"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@hono/node-server": "^1.13.8",
@@ -126,7 +126,7 @@
126
126
  "typescript": "^5.8.2",
127
127
  "vitest": "^2.1.9",
128
128
  "zod-to-json-schema": "^3.24.3",
129
- "@internal/lint": "0.0.1"
129
+ "@internal/lint": "0.0.2-alpha.0"
130
130
  },
131
131
  "scripts": {
132
132
  "build": "tsup src/index.ts src/build/index.ts src/server/index.ts src/build/bundler.ts src/build/analyze.ts src/bundler/index.ts src/services/index.ts src/validator/loader.ts src/validator/custom-resolver.ts --format esm,cjs --clean --experimental-dts --treeshake=smallest --splitting --publicDir",