@mastra/deployer-cloudflare 0.0.0-support-monorepos-20250415183219 → 0.0.0-taofeeqInngest-20250603090617

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.
@@ -15,7 +15,9 @@ export declare class CloudflareDeployer extends Deployer {
15
15
  scope: string;
16
16
  env?: Record<string, any>;
17
17
  projectName?: string;
18
- constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
18
+ d1Databases?: D1DatabaseBinding[];
19
+ kvNamespaces?: KVNamespaceBinding[];
20
+ constructor({ scope, env, projectName, routes, workerNamespace, auth, d1Databases, kvNamespaces, }: {
19
21
  env?: Record<string, any>;
20
22
  scope: string;
21
23
  projectName?: string;
@@ -25,12 +27,14 @@ export declare class CloudflareDeployer extends Deployer {
25
27
  apiToken: string;
26
28
  apiEmail?: string;
27
29
  };
30
+ d1Databases?: D1DatabaseBinding[];
31
+ kvNamespaces?: KVNamespaceBinding[];
28
32
  });
29
33
  writeFiles(outputDirectory: string): Promise<void>;
30
34
  private getEntry;
31
35
  prepare(outputDirectory: string): Promise<void>;
32
- getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>): Promise<InputOptions>;
33
- bundle(entryFile: string, outputDirectory: string): Promise<void>;
36
+ getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
37
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
34
38
  deploy(outputDirectory: string): Promise<void>;
35
39
  tagWorker({ workerName, namespace, tags, scope, }: {
36
40
  scope: string;
@@ -38,6 +42,7 @@ export declare class CloudflareDeployer extends Deployer {
38
42
  namespace: string;
39
43
  tags: string[];
40
44
  }): Promise<void>;
45
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
41
46
  }
42
47
 
43
48
  export declare class CloudflareSecretsManager {
@@ -65,4 +70,16 @@ export declare class CloudflareSecretsManager {
65
70
  listSecrets(workerId: string): Promise<any>;
66
71
  }
67
72
 
73
+ declare interface D1DatabaseBinding {
74
+ binding: string;
75
+ database_name: string;
76
+ database_id: string;
77
+ preview_database_id?: string;
78
+ }
79
+
80
+ declare interface KVNamespaceBinding {
81
+ binding: string;
82
+ id: string;
83
+ }
84
+
68
85
  export { }
@@ -15,7 +15,9 @@ export declare class CloudflareDeployer extends Deployer {
15
15
  scope: string;
16
16
  env?: Record<string, any>;
17
17
  projectName?: string;
18
- constructor({ scope, env, projectName, routes, workerNamespace, auth, }: {
18
+ d1Databases?: D1DatabaseBinding[];
19
+ kvNamespaces?: KVNamespaceBinding[];
20
+ constructor({ scope, env, projectName, routes, workerNamespace, auth, d1Databases, kvNamespaces, }: {
19
21
  env?: Record<string, any>;
20
22
  scope: string;
21
23
  projectName?: string;
@@ -25,12 +27,14 @@ export declare class CloudflareDeployer extends Deployer {
25
27
  apiToken: string;
26
28
  apiEmail?: string;
27
29
  };
30
+ d1Databases?: D1DatabaseBinding[];
31
+ kvNamespaces?: KVNamespaceBinding[];
28
32
  });
29
33
  writeFiles(outputDirectory: string): Promise<void>;
30
34
  private getEntry;
31
35
  prepare(outputDirectory: string): Promise<void>;
32
- getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>): Promise<InputOptions>;
33
- bundle(entryFile: string, outputDirectory: string): Promise<void>;
36
+ getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
37
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
34
38
  deploy(outputDirectory: string): Promise<void>;
35
39
  tagWorker({ workerName, namespace, tags, scope, }: {
36
40
  scope: string;
@@ -38,6 +42,7 @@ export declare class CloudflareDeployer extends Deployer {
38
42
  namespace: string;
39
43
  tags: string[];
40
44
  }): Promise<void>;
45
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
41
46
  }
42
47
 
43
48
  export declare class CloudflareSecretsManager {
@@ -65,4 +70,16 @@ export declare class CloudflareSecretsManager {
65
70
  listSecrets(workerId: string): Promise<any>;
66
71
  }
67
72
 
73
+ declare interface D1DatabaseBinding {
74
+ binding: string;
75
+ database_name: string;
76
+ database_id: string;
77
+ preview_database_id?: string;
78
+ }
79
+
80
+ declare interface KVNamespaceBinding {
81
+ binding: string;
82
+ id: string;
83
+ }
84
+
68
85
  export { }
package/dist/index.cjs CHANGED
@@ -18,13 +18,17 @@ var CloudflareDeployer = class extends deployer.Deployer {
18
18
  scope;
19
19
  env;
20
20
  projectName;
21
+ d1Databases;
22
+ kvNamespaces;
21
23
  constructor({
22
24
  scope,
23
25
  env,
24
26
  projectName = "mastra",
25
27
  routes,
26
28
  workerNamespace,
27
- auth
29
+ auth,
30
+ d1Databases,
31
+ kvNamespaces
28
32
  }) {
29
33
  super({ name: "CLOUDFLARE" });
30
34
  this.scope = scope;
@@ -34,6 +38,8 @@ var CloudflareDeployer = class extends deployer.Deployer {
34
38
  if (env) {
35
39
  this.env = env;
36
40
  }
41
+ if (d1Databases) this.d1Databases = d1Databases;
42
+ if (kvNamespaces) this.kvNamespaces = kvNamespaces;
37
43
  this.cloudflare = new cloudflare.Cloudflare(auth);
38
44
  }
39
45
  async writeFiles(outputDirectory) {
@@ -55,28 +61,76 @@ var CloudflareDeployer = class extends deployer.Deployer {
55
61
  if (!this.workerNamespace && this.routes) {
56
62
  wranglerConfig.routes = this.routes;
57
63
  }
64
+ if (this.d1Databases?.length) {
65
+ wranglerConfig.d1_databases = this.d1Databases;
66
+ }
67
+ if (this.kvNamespaces?.length) {
68
+ wranglerConfig.kv_namespaces = this.kvNamespaces;
69
+ }
58
70
  await promises.writeFile(path.join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
59
71
  }
60
72
  getEntry() {
61
73
  return `
62
- import '#polyfills';
63
- import { mastra } from '#mastra';
64
- import { createHonoServer } from '#server';
74
+ import '#polyfills';
75
+ import { mastra } from '#mastra';
76
+ import { createHonoServer } from '#server';
77
+ import { evaluate } from '@mastra/core/eval';
78
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
79
+ import { TABLE_EVALS } from '@mastra/core/storage';
80
+ import { checkEvalStorageFields } from '@mastra/core/utils';
65
81
 
66
- export default {
67
- fetch: async (request, env, context) => {
68
- const app = await createHonoServer(mastra)
69
- return app.fetch(request, env, context);
70
- }
71
- }
82
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
83
+ evaluate({
84
+ agentName,
85
+ input,
86
+ metric,
87
+ output,
88
+ runId,
89
+ globalRunId: runId,
90
+ instructions,
91
+ });
92
+ });
93
+
94
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
95
+ const storage = mastra.getStorage();
96
+ if (storage) {
97
+ // Check for required fields
98
+ const logger = mastra?.getLogger();
99
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
100
+ if (!areFieldsValid) return;
101
+
102
+ await storage.insert({
103
+ tableName: TABLE_EVALS,
104
+ record: {
105
+ input: traceObject.input,
106
+ output: traceObject.output,
107
+ result: JSON.stringify(traceObject.result || {}),
108
+ agent_name: traceObject.agentName,
109
+ metric_name: traceObject.metricName,
110
+ instructions: traceObject.instructions,
111
+ test_info: null,
112
+ global_run_id: traceObject.globalRunId,
113
+ run_id: traceObject.runId,
114
+ created_at: new Date().toISOString(),
115
+ },
116
+ });
117
+ }
118
+ });
119
+
120
+ export default {
121
+ fetch: async (request, env, context) => {
122
+ const app = await createHonoServer(mastra)
123
+ return app.fetch(request, env, context);
124
+ }
125
+ }
72
126
  `;
73
127
  }
74
128
  async prepare(outputDirectory) {
75
129
  await super.prepare(outputDirectory);
76
130
  await this.writeFiles(outputDirectory);
77
131
  }
78
- async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo) {
79
- const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo);
132
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
133
+ const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths);
80
134
  if (Array.isArray(inputOptions.plugins)) {
81
135
  inputOptions.plugins = [
82
136
  virtual__default.default({
@@ -90,8 +144,8 @@ process.versions.node = '${process.versions.node}';
90
144
  }
91
145
  return inputOptions;
92
146
  }
93
- async bundle(entryFile, outputDirectory) {
94
- return this._bundle(this.getEntry(), entryFile, outputDirectory);
147
+ async bundle(entryFile, outputDirectory, toolsPaths) {
148
+ return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
95
149
  }
96
150
  async deploy(outputDirectory) {
97
151
  const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
@@ -124,6 +178,16 @@ process.versions.node = '${process.versions.node}';
124
178
  body: tags
125
179
  });
126
180
  }
181
+ async lint(entryFile, outputDirectory, toolsPaths) {
182
+ await super.lint(entryFile, outputDirectory, toolsPaths);
183
+ const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
184
+ if (hasLibsql) {
185
+ this.logger.error(
186
+ "Cloudflare Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency. Please use Cloudflare D1 instead @mastra/cloudflare-d1"
187
+ );
188
+ process.exit(1);
189
+ }
190
+ }
127
191
  };
128
192
 
129
193
  exports.CloudflareDeployer = CloudflareDeployer;
package/dist/index.js CHANGED
@@ -12,13 +12,17 @@ var CloudflareDeployer = class extends Deployer {
12
12
  scope;
13
13
  env;
14
14
  projectName;
15
+ d1Databases;
16
+ kvNamespaces;
15
17
  constructor({
16
18
  scope,
17
19
  env,
18
20
  projectName = "mastra",
19
21
  routes,
20
22
  workerNamespace,
21
- auth
23
+ auth,
24
+ d1Databases,
25
+ kvNamespaces
22
26
  }) {
23
27
  super({ name: "CLOUDFLARE" });
24
28
  this.scope = scope;
@@ -28,6 +32,8 @@ var CloudflareDeployer = class extends Deployer {
28
32
  if (env) {
29
33
  this.env = env;
30
34
  }
35
+ if (d1Databases) this.d1Databases = d1Databases;
36
+ if (kvNamespaces) this.kvNamespaces = kvNamespaces;
31
37
  this.cloudflare = new Cloudflare(auth);
32
38
  }
33
39
  async writeFiles(outputDirectory) {
@@ -49,28 +55,76 @@ var CloudflareDeployer = class extends Deployer {
49
55
  if (!this.workerNamespace && this.routes) {
50
56
  wranglerConfig.routes = this.routes;
51
57
  }
58
+ if (this.d1Databases?.length) {
59
+ wranglerConfig.d1_databases = this.d1Databases;
60
+ }
61
+ if (this.kvNamespaces?.length) {
62
+ wranglerConfig.kv_namespaces = this.kvNamespaces;
63
+ }
52
64
  await writeFile(join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
53
65
  }
54
66
  getEntry() {
55
67
  return `
56
- import '#polyfills';
57
- import { mastra } from '#mastra';
58
- import { createHonoServer } from '#server';
68
+ import '#polyfills';
69
+ import { mastra } from '#mastra';
70
+ import { createHonoServer } from '#server';
71
+ import { evaluate } from '@mastra/core/eval';
72
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
73
+ import { TABLE_EVALS } from '@mastra/core/storage';
74
+ import { checkEvalStorageFields } from '@mastra/core/utils';
59
75
 
60
- export default {
61
- fetch: async (request, env, context) => {
62
- const app = await createHonoServer(mastra)
63
- return app.fetch(request, env, context);
64
- }
65
- }
76
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
77
+ evaluate({
78
+ agentName,
79
+ input,
80
+ metric,
81
+ output,
82
+ runId,
83
+ globalRunId: runId,
84
+ instructions,
85
+ });
86
+ });
87
+
88
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
89
+ const storage = mastra.getStorage();
90
+ if (storage) {
91
+ // Check for required fields
92
+ const logger = mastra?.getLogger();
93
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
94
+ if (!areFieldsValid) return;
95
+
96
+ await storage.insert({
97
+ tableName: TABLE_EVALS,
98
+ record: {
99
+ input: traceObject.input,
100
+ output: traceObject.output,
101
+ result: JSON.stringify(traceObject.result || {}),
102
+ agent_name: traceObject.agentName,
103
+ metric_name: traceObject.metricName,
104
+ instructions: traceObject.instructions,
105
+ test_info: null,
106
+ global_run_id: traceObject.globalRunId,
107
+ run_id: traceObject.runId,
108
+ created_at: new Date().toISOString(),
109
+ },
110
+ });
111
+ }
112
+ });
113
+
114
+ export default {
115
+ fetch: async (request, env, context) => {
116
+ const app = await createHonoServer(mastra)
117
+ return app.fetch(request, env, context);
118
+ }
119
+ }
66
120
  `;
67
121
  }
68
122
  async prepare(outputDirectory) {
69
123
  await super.prepare(outputDirectory);
70
124
  await this.writeFiles(outputDirectory);
71
125
  }
72
- async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo) {
73
- const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo);
126
+ async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
127
+ const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths);
74
128
  if (Array.isArray(inputOptions.plugins)) {
75
129
  inputOptions.plugins = [
76
130
  virtual({
@@ -84,8 +138,8 @@ process.versions.node = '${process.versions.node}';
84
138
  }
85
139
  return inputOptions;
86
140
  }
87
- async bundle(entryFile, outputDirectory) {
88
- return this._bundle(this.getEntry(), entryFile, outputDirectory);
141
+ async bundle(entryFile, outputDirectory, toolsPaths) {
142
+ return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
89
143
  }
90
144
  async deploy(outputDirectory) {
91
145
  const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
@@ -118,6 +172,16 @@ process.versions.node = '${process.versions.node}';
118
172
  body: tags
119
173
  });
120
174
  }
175
+ async lint(entryFile, outputDirectory, toolsPaths) {
176
+ await super.lint(entryFile, outputDirectory, toolsPaths);
177
+ const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
178
+ if (hasLibsql) {
179
+ this.logger.error(
180
+ "Cloudflare Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency. Please use Cloudflare D1 instead @mastra/cloudflare-d1"
181
+ );
182
+ process.exit(1);
183
+ }
184
+ }
121
185
  };
122
186
 
123
187
  export { CloudflareDeployer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.0.0-support-monorepos-20250415183219",
3
+ "version": "0.0.0-taofeeqInngest-20250603090617",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -35,25 +35,26 @@
35
35
  "author": "",
36
36
  "license": "Elastic-2.0",
37
37
  "dependencies": {
38
+ "@babel/core": "^7.26.10",
38
39
  "@rollup/plugin-virtual": "^3.0.2",
39
40
  "cloudflare": "^4.1.0",
40
- "date-fns": "^4.1.0",
41
- "execa": "^9.5.2",
42
- "rollup-plugin-polyfill-node": "^0.13.0",
43
- "rollup-plugin-shim": "^1.0.0",
41
+ "rollup": "^4.35.0",
44
42
  "wrangler": "^4.4.0",
45
- "zod": "^3.24.2",
46
- "@mastra/core": "0.8.3",
47
- "@mastra/deployer": "0.0.0-support-monorepos-20250415183219"
43
+ "zod": "^3.24.3",
44
+ "@mastra/deployer": "0.0.0-taofeeqInngest-20250603090617"
48
45
  },
49
46
  "devDependencies": {
50
- "@microsoft/api-extractor": "^7.52.1",
47
+ "@microsoft/api-extractor": "^7.52.5",
51
48
  "@types/node": "^20.17.27",
52
49
  "eslint": "^9.23.0",
53
50
  "tsup": "^8.4.0",
54
51
  "typescript": "^5.8.2",
55
- "vitest": "^3.0.9",
56
- "@internal/lint": "0.0.2"
52
+ "vitest": "^3.1.2",
53
+ "@internal/lint": "0.0.0-taofeeqInngest-20250603090617",
54
+ "@mastra/core": "0.0.0-taofeeqInngest-20250603090617"
55
+ },
56
+ "peerDependencies": {
57
+ "@mastra/core": "^0.10.1-alpha.0"
57
58
  },
58
59
  "scripts": {
59
60
  "build": "tsup src/index.ts src/secrets-manager/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",