@mastra/deployer-cloudflare 0.0.0-storage-20250225005900 → 0.0.0-support-d1-client-20250701191943
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/{LICENSE → LICENSE.md} +3 -1
- package/dist/_tsup-dts-rollup.d.cts +85 -0
- package/dist/_tsup-dts-rollup.d.ts +23 -3
- package/dist/index.cjs +179 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.js +101 -39
- package/{src/secrets-manager/index.ts → dist/secrets-manager/index.cjs} +31 -52
- package/dist/secrets-manager/index.d.cts +1 -0
- package/package.json +40 -22
- package/.turbo/turbo-build.log +0 -20
- package/CHANGELOG.md +0 -939
- package/global.d.ts +0 -1
- package/src/index.ts +0 -148
- package/src/secrets-manager/index.test.ts +0 -230
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -8
package/{LICENSE → LICENSE.md}
RENAMED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { analyzeBundle } from '@mastra/deployer/analyze';
|
|
2
|
+
import { Deployer } from '@mastra/deployer';
|
|
3
|
+
import { InputOptions } from 'rollup';
|
|
4
|
+
|
|
5
|
+
declare interface CFRoute {
|
|
6
|
+
pattern: string;
|
|
7
|
+
zone_name: string;
|
|
8
|
+
custom_domain?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare class CloudflareDeployer extends Deployer {
|
|
12
|
+
private cloudflare;
|
|
13
|
+
routes?: CFRoute[];
|
|
14
|
+
workerNamespace?: string;
|
|
15
|
+
scope: string;
|
|
16
|
+
env?: Record<string, any>;
|
|
17
|
+
projectName?: string;
|
|
18
|
+
d1Databases?: D1DatabaseBinding[];
|
|
19
|
+
kvNamespaces?: KVNamespaceBinding[];
|
|
20
|
+
constructor({ scope, env, projectName, routes, workerNamespace, auth, d1Databases, kvNamespaces, }: {
|
|
21
|
+
env?: Record<string, any>;
|
|
22
|
+
scope: string;
|
|
23
|
+
projectName?: string;
|
|
24
|
+
routes?: CFRoute[];
|
|
25
|
+
workerNamespace?: string;
|
|
26
|
+
auth: {
|
|
27
|
+
apiToken: string;
|
|
28
|
+
apiEmail?: string;
|
|
29
|
+
};
|
|
30
|
+
d1Databases?: D1DatabaseBinding[];
|
|
31
|
+
kvNamespaces?: KVNamespaceBinding[];
|
|
32
|
+
});
|
|
33
|
+
writeFiles(outputDirectory: string): Promise<void>;
|
|
34
|
+
private getEntry;
|
|
35
|
+
prepare(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>;
|
|
38
|
+
deploy(): Promise<void>;
|
|
39
|
+
tagWorker({ workerName, namespace, tags, scope, }: {
|
|
40
|
+
scope: string;
|
|
41
|
+
workerName: string;
|
|
42
|
+
namespace: string;
|
|
43
|
+
tags: string[];
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export declare class CloudflareSecretsManager {
|
|
49
|
+
accountId: string;
|
|
50
|
+
apiToken: string;
|
|
51
|
+
baseUrl: string;
|
|
52
|
+
constructor({ accountId, apiToken }: {
|
|
53
|
+
accountId: string;
|
|
54
|
+
apiToken: string;
|
|
55
|
+
});
|
|
56
|
+
createSecret({ workerId, secretName, secretValue, }: {
|
|
57
|
+
workerId: string;
|
|
58
|
+
secretName: string;
|
|
59
|
+
secretValue: string;
|
|
60
|
+
}): Promise<any>;
|
|
61
|
+
createProjectSecrets({ workerId, customerId, envVars, }: {
|
|
62
|
+
workerId: string;
|
|
63
|
+
customerId: string;
|
|
64
|
+
envVars: Record<string, string>;
|
|
65
|
+
}): Promise<any>;
|
|
66
|
+
deleteSecret({ workerId, secretName }: {
|
|
67
|
+
workerId: string;
|
|
68
|
+
secretName: string;
|
|
69
|
+
}): Promise<any>;
|
|
70
|
+
listSecrets(workerId: string): Promise<any>;
|
|
71
|
+
}
|
|
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
|
+
|
|
85
|
+
export { }
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { analyzeBundle } from '@mastra/deployer/analyze';
|
|
1
2
|
import { Deployer } from '@mastra/deployer';
|
|
3
|
+
import { InputOptions } from 'rollup';
|
|
2
4
|
|
|
3
5
|
declare interface CFRoute {
|
|
4
6
|
pattern: string;
|
|
@@ -13,7 +15,9 @@ export declare class CloudflareDeployer extends Deployer {
|
|
|
13
15
|
scope: string;
|
|
14
16
|
env?: Record<string, any>;
|
|
15
17
|
projectName?: string;
|
|
16
|
-
|
|
18
|
+
d1Databases?: D1DatabaseBinding[];
|
|
19
|
+
kvNamespaces?: KVNamespaceBinding[];
|
|
20
|
+
constructor({ scope, env, projectName, routes, workerNamespace, auth, d1Databases, kvNamespaces, }: {
|
|
17
21
|
env?: Record<string, any>;
|
|
18
22
|
scope: string;
|
|
19
23
|
projectName?: string;
|
|
@@ -23,18 +27,22 @@ export declare class CloudflareDeployer extends Deployer {
|
|
|
23
27
|
apiToken: string;
|
|
24
28
|
apiEmail?: string;
|
|
25
29
|
};
|
|
30
|
+
d1Databases?: D1DatabaseBinding[];
|
|
31
|
+
kvNamespaces?: KVNamespaceBinding[];
|
|
26
32
|
});
|
|
27
33
|
writeFiles(outputDirectory: string): Promise<void>;
|
|
28
34
|
private getEntry;
|
|
29
35
|
prepare(outputDirectory: string): Promise<void>;
|
|
30
|
-
|
|
31
|
-
|
|
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>;
|
|
38
|
+
deploy(): Promise<void>;
|
|
32
39
|
tagWorker({ workerName, namespace, tags, scope, }: {
|
|
33
40
|
scope: string;
|
|
34
41
|
workerName: string;
|
|
35
42
|
namespace: string;
|
|
36
43
|
tags: string[];
|
|
37
44
|
}): Promise<void>;
|
|
45
|
+
lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
export declare class CloudflareSecretsManager {
|
|
@@ -62,4 +70,16 @@ export declare class CloudflareSecretsManager {
|
|
|
62
70
|
listSecrets(workerId: string): Promise<any>;
|
|
63
71
|
}
|
|
64
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
|
+
|
|
65
85
|
export { }
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('fs/promises');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var deployer = require('@mastra/deployer');
|
|
6
|
+
var virtual = require('@rollup/plugin-virtual');
|
|
7
|
+
var cloudflare = require('cloudflare');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var virtual__default = /*#__PURE__*/_interopDefault(virtual);
|
|
12
|
+
|
|
13
|
+
// src/index.ts
|
|
14
|
+
var CloudflareDeployer = class extends deployer.Deployer {
|
|
15
|
+
cloudflare;
|
|
16
|
+
routes = [];
|
|
17
|
+
workerNamespace;
|
|
18
|
+
scope;
|
|
19
|
+
env;
|
|
20
|
+
projectName;
|
|
21
|
+
d1Databases;
|
|
22
|
+
kvNamespaces;
|
|
23
|
+
constructor({
|
|
24
|
+
scope,
|
|
25
|
+
env,
|
|
26
|
+
projectName = "mastra",
|
|
27
|
+
routes,
|
|
28
|
+
workerNamespace,
|
|
29
|
+
auth,
|
|
30
|
+
d1Databases,
|
|
31
|
+
kvNamespaces
|
|
32
|
+
}) {
|
|
33
|
+
super({ name: "CLOUDFLARE" });
|
|
34
|
+
this.scope = scope;
|
|
35
|
+
this.projectName = projectName;
|
|
36
|
+
this.routes = routes;
|
|
37
|
+
this.workerNamespace = workerNamespace;
|
|
38
|
+
if (env) {
|
|
39
|
+
this.env = env;
|
|
40
|
+
}
|
|
41
|
+
if (d1Databases) this.d1Databases = d1Databases;
|
|
42
|
+
if (kvNamespaces) this.kvNamespaces = kvNamespaces;
|
|
43
|
+
this.cloudflare = new cloudflare.Cloudflare(auth);
|
|
44
|
+
}
|
|
45
|
+
async writeFiles(outputDirectory) {
|
|
46
|
+
const env = await this.loadEnvVars();
|
|
47
|
+
const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
|
|
48
|
+
const cfWorkerName = this.projectName;
|
|
49
|
+
const wranglerConfig = {
|
|
50
|
+
name: cfWorkerName,
|
|
51
|
+
main: "./index.mjs",
|
|
52
|
+
compatibility_date: "2025-04-01",
|
|
53
|
+
compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
|
|
54
|
+
observability: {
|
|
55
|
+
logs: {
|
|
56
|
+
enabled: true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
vars: envsAsObject
|
|
60
|
+
};
|
|
61
|
+
if (!this.workerNamespace && this.routes) {
|
|
62
|
+
wranglerConfig.routes = this.routes;
|
|
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
|
+
}
|
|
70
|
+
await promises.writeFile(path.join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
|
|
71
|
+
}
|
|
72
|
+
getEntry() {
|
|
73
|
+
return `
|
|
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';
|
|
81
|
+
|
|
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
|
+
}
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
async prepare(outputDirectory) {
|
|
129
|
+
await super.prepare(outputDirectory);
|
|
130
|
+
await this.writeFiles(outputDirectory);
|
|
131
|
+
}
|
|
132
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
|
|
133
|
+
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths);
|
|
134
|
+
if (Array.isArray(inputOptions.plugins)) {
|
|
135
|
+
inputOptions.plugins = [
|
|
136
|
+
virtual__default.default({
|
|
137
|
+
"#polyfills": `
|
|
138
|
+
process.versions = process.versions || {};
|
|
139
|
+
process.versions.node = '${process.versions.node}';
|
|
140
|
+
`
|
|
141
|
+
}),
|
|
142
|
+
...inputOptions.plugins
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
return inputOptions;
|
|
146
|
+
}
|
|
147
|
+
async bundle(entryFile, outputDirectory, toolsPaths) {
|
|
148
|
+
return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
|
|
149
|
+
}
|
|
150
|
+
async deploy() {
|
|
151
|
+
this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
|
|
152
|
+
}
|
|
153
|
+
async tagWorker({
|
|
154
|
+
workerName,
|
|
155
|
+
namespace,
|
|
156
|
+
tags,
|
|
157
|
+
scope
|
|
158
|
+
}) {
|
|
159
|
+
if (!this.cloudflare) {
|
|
160
|
+
throw new Error("Cloudflare Deployer not initialized");
|
|
161
|
+
}
|
|
162
|
+
await this.cloudflare.workersForPlatforms.dispatch.namespaces.scripts.tags.update(namespace, workerName, {
|
|
163
|
+
account_id: scope,
|
|
164
|
+
body: tags
|
|
165
|
+
});
|
|
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
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
exports.CloudflareDeployer = CloudflareDeployer;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CloudflareDeployer } from './_tsup-dts-rollup.cjs';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '@mastra/deployer/build';
|
|
3
|
-
import '@rollup/plugin-virtual';
|
|
4
|
-
import { Cloudflare } from 'cloudflare';
|
|
5
|
-
import { writeFileSync } from 'fs';
|
|
1
|
+
import { writeFile } from 'fs/promises';
|
|
6
2
|
import { join } from 'path';
|
|
3
|
+
import { Deployer } from '@mastra/deployer';
|
|
4
|
+
import virtual from '@rollup/plugin-virtual';
|
|
5
|
+
import { Cloudflare } from 'cloudflare';
|
|
7
6
|
|
|
8
7
|
// src/index.ts
|
|
9
8
|
var CloudflareDeployer = class extends Deployer {
|
|
@@ -13,13 +12,17 @@ var CloudflareDeployer = class extends Deployer {
|
|
|
13
12
|
scope;
|
|
14
13
|
env;
|
|
15
14
|
projectName;
|
|
15
|
+
d1Databases;
|
|
16
|
+
kvNamespaces;
|
|
16
17
|
constructor({
|
|
17
18
|
scope,
|
|
18
19
|
env,
|
|
19
20
|
projectName = "mastra",
|
|
20
21
|
routes,
|
|
21
22
|
workerNamespace,
|
|
22
|
-
auth
|
|
23
|
+
auth,
|
|
24
|
+
d1Databases,
|
|
25
|
+
kvNamespaces
|
|
23
26
|
}) {
|
|
24
27
|
super({ name: "CLOUDFLARE" });
|
|
25
28
|
this.scope = scope;
|
|
@@ -29,6 +32,8 @@ var CloudflareDeployer = class extends Deployer {
|
|
|
29
32
|
if (env) {
|
|
30
33
|
this.env = env;
|
|
31
34
|
}
|
|
35
|
+
if (d1Databases) this.d1Databases = d1Databases;
|
|
36
|
+
if (kvNamespaces) this.kvNamespaces = kvNamespaces;
|
|
32
37
|
this.cloudflare = new Cloudflare(auth);
|
|
33
38
|
}
|
|
34
39
|
async writeFiles(outputDirectory) {
|
|
@@ -37,9 +42,9 @@ var CloudflareDeployer = class extends Deployer {
|
|
|
37
42
|
const cfWorkerName = this.projectName;
|
|
38
43
|
const wranglerConfig = {
|
|
39
44
|
name: cfWorkerName,
|
|
40
|
-
main: "index.mjs",
|
|
41
|
-
compatibility_date: "
|
|
42
|
-
compatibility_flags: ["nodejs_compat"],
|
|
45
|
+
main: "./index.mjs",
|
|
46
|
+
compatibility_date: "2025-04-01",
|
|
47
|
+
compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
|
|
43
48
|
observability: {
|
|
44
49
|
logs: {
|
|
45
50
|
enabled: true
|
|
@@ -50,47 +55,94 @@ var CloudflareDeployer = class extends Deployer {
|
|
|
50
55
|
if (!this.workerNamespace && this.routes) {
|
|
51
56
|
wranglerConfig.routes = this.routes;
|
|
52
57
|
}
|
|
53
|
-
|
|
58
|
+
if (this.d1Databases?.length) {
|
|
59
|
+
wranglerConfig.d1_databases = this.d1Databases;
|
|
60
|
+
}
|
|
61
|
+
if (this.kvNamespaces?.length) {
|
|
62
|
+
wranglerConfig.kv_namespaces = this.kvNamespaces;
|
|
63
|
+
}
|
|
64
|
+
await writeFile(join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
|
|
54
65
|
}
|
|
55
66
|
getEntry() {
|
|
56
67
|
return `
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
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';
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
}
|
|
69
120
|
`;
|
|
70
121
|
}
|
|
71
122
|
async prepare(outputDirectory) {
|
|
72
123
|
await super.prepare(outputDirectory);
|
|
73
124
|
await this.writeFiles(outputDirectory);
|
|
74
125
|
}
|
|
75
|
-
async
|
|
76
|
-
|
|
126
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
|
|
127
|
+
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths);
|
|
128
|
+
if (Array.isArray(inputOptions.plugins)) {
|
|
129
|
+
inputOptions.plugins = [
|
|
130
|
+
virtual({
|
|
131
|
+
"#polyfills": `
|
|
132
|
+
process.versions = process.versions || {};
|
|
133
|
+
process.versions.node = '${process.versions.node}';
|
|
134
|
+
`
|
|
135
|
+
}),
|
|
136
|
+
...inputOptions.plugins
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
return inputOptions;
|
|
77
140
|
}
|
|
78
|
-
async
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
await cpLogger({
|
|
85
|
-
cmd,
|
|
86
|
-
args: [],
|
|
87
|
-
env: {
|
|
88
|
-
CLOUDFLARE_API_TOKEN: this.cloudflare.apiToken,
|
|
89
|
-
CLOUDFLARE_ACCOUNT_ID: this.scope,
|
|
90
|
-
...this.env,
|
|
91
|
-
PATH: process.env.PATH
|
|
92
|
-
}
|
|
93
|
-
});
|
|
141
|
+
async bundle(entryFile, outputDirectory, toolsPaths) {
|
|
142
|
+
return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
|
|
143
|
+
}
|
|
144
|
+
async deploy() {
|
|
145
|
+
this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
|
|
94
146
|
}
|
|
95
147
|
async tagWorker({
|
|
96
148
|
workerName,
|
|
@@ -106,6 +158,16 @@ export default {
|
|
|
106
158
|
body: tags
|
|
107
159
|
});
|
|
108
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
|
+
}
|
|
109
171
|
};
|
|
110
172
|
|
|
111
173
|
export { CloudflareDeployer };
|
|
@@ -1,110 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/secrets-manager/index.ts
|
|
4
|
+
var CloudflareSecretsManager = class {
|
|
5
|
+
accountId;
|
|
6
|
+
apiToken;
|
|
7
|
+
baseUrl;
|
|
8
|
+
constructor({ accountId, apiToken }) {
|
|
7
9
|
this.accountId = accountId;
|
|
8
10
|
this.apiToken = apiToken;
|
|
9
|
-
this.baseUrl =
|
|
11
|
+
this.baseUrl = "https://api.cloudflare.com/client/v4";
|
|
10
12
|
}
|
|
11
|
-
|
|
12
13
|
async createSecret({
|
|
13
14
|
workerId,
|
|
14
15
|
secretName,
|
|
15
|
-
secretValue
|
|
16
|
-
}: {
|
|
17
|
-
workerId: string;
|
|
18
|
-
secretName: string;
|
|
19
|
-
secretValue: string;
|
|
16
|
+
secretValue
|
|
20
17
|
}) {
|
|
21
18
|
const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
|
|
22
|
-
|
|
23
19
|
try {
|
|
24
20
|
const response = await fetch(url, {
|
|
25
|
-
method:
|
|
21
|
+
method: "PUT",
|
|
26
22
|
headers: {
|
|
27
23
|
Authorization: `Bearer ${this.apiToken}`,
|
|
28
|
-
|
|
24
|
+
"Content-Type": "application/json"
|
|
29
25
|
},
|
|
30
26
|
body: JSON.stringify({
|
|
31
27
|
name: secretName,
|
|
32
|
-
text: secretValue
|
|
33
|
-
})
|
|
28
|
+
text: secretValue
|
|
29
|
+
})
|
|
34
30
|
});
|
|
35
|
-
|
|
36
|
-
const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
|
|
37
|
-
|
|
31
|
+
const data = await response.json();
|
|
38
32
|
if (!data.success) {
|
|
39
33
|
throw new Error(data.errors[0].message);
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
return data.result;
|
|
43
36
|
} catch (error) {
|
|
44
|
-
console.error(
|
|
37
|
+
console.error("Failed to create secret:", error);
|
|
45
38
|
throw error;
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
async createProjectSecrets({
|
|
50
42
|
workerId,
|
|
51
43
|
customerId,
|
|
52
|
-
envVars
|
|
53
|
-
}: {
|
|
54
|
-
workerId: string;
|
|
55
|
-
customerId: string;
|
|
56
|
-
envVars: Record<string, string>;
|
|
44
|
+
envVars
|
|
57
45
|
}) {
|
|
58
46
|
const secretName = `PROJECT_${customerId.toUpperCase()}`;
|
|
59
47
|
const secretValue = JSON.stringify(envVars);
|
|
60
|
-
|
|
61
48
|
return this.createSecret({ workerId, secretName, secretValue });
|
|
62
49
|
}
|
|
63
|
-
|
|
64
|
-
async deleteSecret({ workerId, secretName }: { workerId: string; secretName: string }) {
|
|
50
|
+
async deleteSecret({ workerId, secretName }) {
|
|
65
51
|
const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets/${secretName}`;
|
|
66
|
-
|
|
67
52
|
try {
|
|
68
53
|
const response = await fetch(url, {
|
|
69
|
-
method:
|
|
54
|
+
method: "DELETE",
|
|
70
55
|
headers: {
|
|
71
|
-
Authorization: `Bearer ${this.apiToken}
|
|
72
|
-
}
|
|
56
|
+
Authorization: `Bearer ${this.apiToken}`
|
|
57
|
+
}
|
|
73
58
|
});
|
|
74
|
-
|
|
75
|
-
const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
|
|
76
|
-
|
|
59
|
+
const data = await response.json();
|
|
77
60
|
if (!data.success) {
|
|
78
61
|
throw new Error(data.errors[0].message);
|
|
79
62
|
}
|
|
80
|
-
|
|
81
63
|
return data.result;
|
|
82
64
|
} catch (error) {
|
|
83
|
-
console.error(
|
|
65
|
+
console.error("Failed to delete secret:", error);
|
|
84
66
|
throw error;
|
|
85
67
|
}
|
|
86
68
|
}
|
|
87
|
-
|
|
88
|
-
async listSecrets(workerId: string) {
|
|
69
|
+
async listSecrets(workerId) {
|
|
89
70
|
const url = `${this.baseUrl}/accounts/${this.accountId}/workers/scripts/${workerId}/secrets`;
|
|
90
|
-
|
|
91
71
|
try {
|
|
92
72
|
const response = await fetch(url, {
|
|
93
73
|
headers: {
|
|
94
|
-
Authorization: `Bearer ${this.apiToken}
|
|
95
|
-
}
|
|
74
|
+
Authorization: `Bearer ${this.apiToken}`
|
|
75
|
+
}
|
|
96
76
|
});
|
|
97
|
-
|
|
98
|
-
const data = (await response.json()) as { success: boolean; result: any; errors: any[] };
|
|
99
|
-
|
|
77
|
+
const data = await response.json();
|
|
100
78
|
if (!data.success) {
|
|
101
79
|
throw new Error(data.errors[0].message);
|
|
102
80
|
}
|
|
103
|
-
|
|
104
81
|
return data.result;
|
|
105
82
|
} catch (error) {
|
|
106
|
-
console.error(
|
|
83
|
+
console.error("Failed to list secrets:", error);
|
|
107
84
|
throw error;
|
|
108
85
|
}
|
|
109
86
|
}
|
|
110
|
-
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
exports.CloudflareSecretsManager = CloudflareSecretsManager;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CloudflareSecretsManager } from '../_tsup-dts-rollup.cjs';
|