@mastra/deployer-cloudflare 0.0.0-vnextWorkflows-20250422142014 → 0.0.0-workflow-deno-20250616130925

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,19 +27,22 @@ 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
36
  getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
33
37
  bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
34
- deploy(outputDirectory: string): Promise<void>;
38
+ deploy(): Promise<void>;
35
39
  tagWorker({ workerName, namespace, tags, scope, }: {
36
40
  scope: string;
37
41
  workerName: string;
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,19 +27,22 @@ 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
36
  getBundlerOptions(serverFile: string, mastraEntryFile: string, analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>, toolsPaths: string[]): Promise<InputOptions>;
33
37
  bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
34
- deploy(outputDirectory: string): Promise<void>;
38
+ deploy(): Promise<void>;
35
39
  tagWorker({ workerName, namespace, tags, scope, }: {
36
40
  scope: string;
37
41
  workerName: string;
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,20 +61,68 @@ 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) {
@@ -93,22 +147,8 @@ process.versions.node = '${process.versions.node}';
93
147
  async bundle(entryFile, outputDirectory, toolsPaths) {
94
148
  return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
95
149
  }
96
- async deploy(outputDirectory) {
97
- const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
98
- const cpLogger = deployer.createChildProcessLogger({
99
- logger: this.logger,
100
- root: path.join(outputDirectory, this.outputDir)
101
- });
102
- await cpLogger({
103
- cmd,
104
- args: [],
105
- env: {
106
- CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
107
- CLOUDFLARE_ACCOUNT_ID: this.scope,
108
- ...this.env,
109
- PATH: process.env.PATH
110
- }
111
- });
150
+ async deploy() {
151
+ this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
112
152
  }
113
153
  async tagWorker({
114
154
  workerName,
@@ -124,6 +164,16 @@ process.versions.node = '${process.versions.node}';
124
164
  body: tags
125
165
  });
126
166
  }
167
+ async lint(entryFile, outputDirectory, toolsPaths) {
168
+ await super.lint(entryFile, outputDirectory, toolsPaths);
169
+ const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
170
+ if (hasLibsql) {
171
+ this.logger.error(
172
+ "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"
173
+ );
174
+ process.exit(1);
175
+ }
176
+ }
127
177
  };
128
178
 
129
179
  exports.CloudflareDeployer = CloudflareDeployer;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { writeFile } from 'fs/promises';
2
2
  import { join } from 'path';
3
- import { Deployer, createChildProcessLogger } from '@mastra/deployer';
3
+ import { Deployer } from '@mastra/deployer';
4
4
  import virtual from '@rollup/plugin-virtual';
5
5
  import { Cloudflare } from 'cloudflare';
6
6
 
@@ -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,20 +55,68 @@ 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) {
@@ -87,22 +141,8 @@ process.versions.node = '${process.versions.node}';
87
141
  async bundle(entryFile, outputDirectory, toolsPaths) {
88
142
  return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
89
143
  }
90
- async deploy(outputDirectory) {
91
- const cmd = this.workerNamespace ? `npm exec -- wrangler@latest deploy --dispatch-namespace ${this.workerNamespace}` : "npm exec -- wrangler@latest deploy";
92
- const cpLogger = createChildProcessLogger({
93
- logger: this.logger,
94
- root: join(outputDirectory, this.outputDir)
95
- });
96
- await cpLogger({
97
- cmd,
98
- args: [],
99
- env: {
100
- CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
101
- CLOUDFLARE_ACCOUNT_ID: this.scope,
102
- ...this.env,
103
- PATH: process.env.PATH
104
- }
105
- });
144
+ async deploy() {
145
+ this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
106
146
  }
107
147
  async tagWorker({
108
148
  workerName,
@@ -118,6 +158,16 @@ process.versions.node = '${process.versions.node}';
118
158
  body: tags
119
159
  });
120
160
  }
161
+ async lint(entryFile, outputDirectory, toolsPaths) {
162
+ await super.lint(entryFile, outputDirectory, toolsPaths);
163
+ const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
164
+ if (hasLibsql) {
165
+ this.logger.error(
166
+ "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"
167
+ );
168
+ process.exit(1);
169
+ }
170
+ }
121
171
  };
122
172
 
123
173
  export { CloudflareDeployer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer-cloudflare",
3
- "version": "0.0.0-vnextWorkflows-20250422142014",
3
+ "version": "0.0.0-workflow-deno-20250616130925",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -35,25 +35,25 @@
35
35
  "author": "",
36
36
  "license": "Elastic-2.0",
37
37
  "dependencies": {
38
+ "@babel/core": "^7.27.4",
38
39
  "@rollup/plugin-virtual": "^3.0.2",
39
- "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",
44
- "wrangler": "^4.4.0",
45
- "zod": "^3.24.2",
46
- "@mastra/core": "0.0.0-vnextWorkflows-20250422142014",
47
- "@mastra/deployer": "0.0.0-vnextWorkflows-20250422142014"
40
+ "cloudflare": "^4.3.0",
41
+ "rollup": "^4.43.0",
42
+ "zod": "^3.25.57",
43
+ "@mastra/deployer": "0.0.0-workflow-deno-20250616130925"
48
44
  },
49
45
  "devDependencies": {
50
- "@microsoft/api-extractor": "^7.52.1",
51
- "@types/node": "^20.17.27",
52
- "eslint": "^9.23.0",
53
- "tsup": "^8.4.0",
54
- "typescript": "^5.8.2",
55
- "vitest": "^3.0.9",
56
- "@internal/lint": "0.0.2"
46
+ "@microsoft/api-extractor": "^7.52.8",
47
+ "@types/node": "^20.19.0",
48
+ "eslint": "^9.28.0",
49
+ "tsup": "^8.5.0",
50
+ "typescript": "^5.8.3",
51
+ "vitest": "^3.2.3",
52
+ "@internal/lint": "0.0.0-workflow-deno-20250616130925",
53
+ "@mastra/core": "0.0.0-workflow-deno-20250616130925"
54
+ },
55
+ "peerDependencies": {
56
+ "@mastra/core": "^0.10.1-alpha.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup src/index.ts src/secrets-manager/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",