@mettlelabs/mettle 0.0.0-0 → 0.0.0-beta.1-linux-x64

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.
Files changed (59) hide show
  1. package/THIRD_PARTY_NOTICES.md +11479 -0
  2. package/bin/mettle +4 -0
  3. package/harness/audit-investigation.mjs +203 -0
  4. package/harness/chunk-13tgmdey.mjs +33761 -0
  5. package/harness/chunk-1sygmp11.mjs +18142 -0
  6. package/harness/chunk-1ykxpmaz.mjs +7887 -0
  7. package/harness/chunk-2gt4cy7x.mjs +2290 -0
  8. package/harness/chunk-2pm2sayw.mjs +248 -0
  9. package/harness/chunk-32y07kkp.mjs +3747 -0
  10. package/harness/chunk-3m7jn5ac.mjs +16242 -0
  11. package/harness/chunk-3wvjs93w.mjs +538 -0
  12. package/harness/chunk-4bepyxmq.mjs +113 -0
  13. package/harness/chunk-4jtnt9k5.mjs +95 -0
  14. package/harness/chunk-50sbrf09.mjs +18972 -0
  15. package/harness/chunk-56csr8sw.mjs +322 -0
  16. package/harness/chunk-5cvb1jnb.mjs +41 -0
  17. package/harness/chunk-5wgmv4np.mjs +585 -0
  18. package/harness/chunk-65eyq32y.mjs +225 -0
  19. package/harness/chunk-6fnh6qhk.mjs +195 -0
  20. package/harness/chunk-6kgqw9ny.mjs +32303 -0
  21. package/harness/chunk-7b242j0n.mjs +14 -0
  22. package/harness/chunk-7bg2gnv2.mjs +7540 -0
  23. package/harness/chunk-ageqxj9v.mjs +63008 -0
  24. package/harness/chunk-b0qbt5jd.mjs +14 -0
  25. package/harness/chunk-b5g1r3fz.mjs +4785 -0
  26. package/harness/chunk-b71gpkxg.mjs +1514 -0
  27. package/harness/chunk-bdv1rx4a.mjs +20364 -0
  28. package/harness/chunk-c1631s2x.mjs +12241 -0
  29. package/harness/chunk-d5xgxsnp.mjs +74 -0
  30. package/harness/chunk-erg1fbh0.mjs +0 -0
  31. package/harness/chunk-fh78v9vn.mjs +19366 -0
  32. package/harness/chunk-fjx29qvp.mjs +50 -0
  33. package/harness/chunk-gryka6kg.mjs +39 -0
  34. package/harness/chunk-jb0r19et.mjs +180 -0
  35. package/harness/chunk-mfn574ss.mjs +179 -0
  36. package/harness/chunk-msg872ea.mjs +334 -0
  37. package/harness/chunk-nz5sv9as.mjs +1642 -0
  38. package/harness/chunk-p9d3cgvq.mjs +452 -0
  39. package/harness/chunk-pq6wvwxr.mjs +12 -0
  40. package/harness/chunk-qcm9arf8.mjs +7736 -0
  41. package/harness/chunk-qr8zfqjd.mjs +24 -0
  42. package/harness/chunk-rz2tz6jp.mjs +26 -0
  43. package/harness/chunk-sbkgc3kn.mjs +8 -0
  44. package/harness/chunk-v66qvpnb.mjs +169 -0
  45. package/harness/chunk-vjaxzab3.mjs +136 -0
  46. package/harness/chunk-vr1n5nza.mjs +1045 -0
  47. package/harness/chunk-vsf2zajv.mjs +3867 -0
  48. package/harness/chunk-wq253fj4.mjs +19041 -0
  49. package/harness/chunk-wyv7ceq4.mjs +0 -0
  50. package/harness/chunk-xnqknk2r.mjs +198 -0
  51. package/harness/chunk-xqyc4ca2.mjs +1890 -0
  52. package/harness/chunk-z6n9thea.mjs +45146 -0
  53. package/harness/chunk-zty0d3bw.mjs +0 -0
  54. package/harness/chunk-zvkxtj82.mjs +42 -0
  55. package/harness/issue-api-token.mjs +35 -0
  56. package/harness/launcher.mjs +159 -0
  57. package/harness/sandbox.mjs +132 -0
  58. package/harness/server.mjs +66322 -0
  59. package/package.json +20 -3
File without changes
@@ -0,0 +1,198 @@
1
+ import {
2
+ getCapabilityFileName,
3
+ getGatewayId,
4
+ shouldEnableGateway
5
+ } from "./chunk-gryka6kg.mjs";
6
+
7
+ // node_modules/.bun/@mastra+core@1.71.0+95d98e20cbc6e6e1/node_modules/@mastra/core/dist/registry-generator-DTVbvs_S.js
8
+ import path from "path";
9
+ import fs from "fs/promises";
10
+ var WINDOWS_RENAME_RETRY_DELAYS_MS = [
11
+ 25,
12
+ 50,
13
+ 100,
14
+ 200,
15
+ 400
16
+ ];
17
+ function hasAttachmentCapabilities(gateway) {
18
+ return "getAttachmentCapabilities" in gateway && typeof gateway.getAttachmentCapabilities === "function";
19
+ }
20
+ function hasTemperatureCapabilities(gateway) {
21
+ return "getTemperatureCapabilities" in gateway && typeof gateway.getTemperatureCapabilities === "function";
22
+ }
23
+ function hasStructuredOutputCapabilities(gateway) {
24
+ return "getStructuredOutputCapabilities" in gateway && typeof gateway.getStructuredOutputCapabilities === "function";
25
+ }
26
+ async function atomicWriteFile(filePath, content, encoding = "utf-8") {
27
+ const randomSuffix = Math.random().toString(36).substring(2, 15);
28
+ const tempPath = `${filePath}.${process.pid}.${Date.now()}.${randomSuffix}.tmp`;
29
+ try {
30
+ await fs.writeFile(tempPath, content, encoding);
31
+ for (let attempt = 0;; attempt += 1)
32
+ try {
33
+ await fs.rename(tempPath, filePath);
34
+ break;
35
+ } catch (error) {
36
+ const delayMs = WINDOWS_RENAME_RETRY_DELAYS_MS[attempt];
37
+ if (!(process.platform === "win32" && error instanceof Error && ("code" in error) && (error.code === "EPERM" || error.code === "EBUSY")) || delayMs === undefined)
38
+ throw error;
39
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
40
+ }
41
+ } catch (error) {
42
+ try {
43
+ await fs.unlink(tempPath);
44
+ } catch {}
45
+ throw error;
46
+ }
47
+ }
48
+ async function fetchProvidersFromGateways(gateways) {
49
+ const enabledGateways = [];
50
+ for (const gateway of gateways)
51
+ if (shouldEnableGateway(gateway))
52
+ enabledGateways.push(gateway);
53
+ const allProviders = {};
54
+ const allModels = {};
55
+ const allAttachmentCapabilities = {};
56
+ const allTemperatureCapabilities = {};
57
+ const allStructuredOutputCapabilities = {};
58
+ const failedGateways = [];
59
+ const maxRetries = 3;
60
+ for (const gateway of enabledGateways) {
61
+ let providers = null;
62
+ for (let attempt = 1;attempt <= maxRetries; attempt++)
63
+ try {
64
+ providers = await gateway.fetchProviders();
65
+ break;
66
+ } catch {
67
+ if (attempt < maxRetries) {
68
+ const delayMs = Math.min(1000 * Math.pow(2, attempt - 1), 5000);
69
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
70
+ }
71
+ }
72
+ if (!providers) {
73
+ failedGateways.push(getGatewayId(gateway));
74
+ continue;
75
+ }
76
+ const gatewayId = getGatewayId(gateway);
77
+ const isProviderRegistry = gatewayId === "models.dev";
78
+ const gatewayAttachmentCaps = hasAttachmentCapabilities(gateway) ? gateway.getAttachmentCapabilities() : undefined;
79
+ const gatewayTemperatureCaps = hasTemperatureCapabilities(gateway) ? gateway.getTemperatureCapabilities() : undefined;
80
+ const gatewayStructuredOutputCaps = hasStructuredOutputCapabilities(gateway) ? gateway.getStructuredOutputCapabilities() : undefined;
81
+ for (const [providerId, config] of Object.entries(providers)) {
82
+ const typeProviderId = isProviderRegistry ? providerId : providerId === gatewayId ? gatewayId : `${gatewayId}/${providerId}`;
83
+ allProviders[typeProviderId] = config;
84
+ allModels[typeProviderId] = config.models.sort();
85
+ if (gatewayAttachmentCaps?.[providerId])
86
+ allAttachmentCapabilities[typeProviderId] = gatewayAttachmentCaps[providerId];
87
+ if (gatewayTemperatureCaps?.[providerId])
88
+ allTemperatureCapabilities[typeProviderId] = gatewayTemperatureCaps[providerId];
89
+ if (gatewayStructuredOutputCaps?.[providerId])
90
+ allStructuredOutputCapabilities[typeProviderId] = gatewayStructuredOutputCaps[providerId];
91
+ }
92
+ }
93
+ return {
94
+ providers: allProviders,
95
+ models: allModels,
96
+ attachmentCapabilities: allAttachmentCapabilities,
97
+ temperatureCapabilities: allTemperatureCapabilities,
98
+ structuredOutputCapabilities: allStructuredOutputCapabilities,
99
+ failedGateways
100
+ };
101
+ }
102
+ function generateTypesContent(models) {
103
+ return `/**
104
+ * THIS FILE IS AUTO-GENERATED - DO NOT EDIT
105
+ * Generated from model gateway providers
106
+ */
107
+
108
+ /**
109
+ * Provider models mapping type
110
+ * This is derived from the JSON data and provides type-safe access
111
+ */
112
+ export type ProviderModelsMap = {
113
+ ${Object.entries(models).map(([provider, modelList]) => {
114
+ const modelsList = modelList.map((m) => `'${m}'`);
115
+ const providerKey = !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(provider) ? `'${provider}'` : provider;
116
+ const singleLine = ` readonly ${providerKey}: readonly [${modelsList.join(", ")}];`;
117
+ if (singleLine.length > 120)
118
+ return ` readonly ${providerKey}: readonly [
119
+ ${modelList.map((m) => ` '${m}',`).join(`
120
+ `)}
121
+ ];`;
122
+ return singleLine;
123
+ }).join(`
124
+ `)}
125
+ };
126
+
127
+ /**
128
+ * Union type of all registered provider IDs
129
+ */
130
+ export type Provider = keyof ProviderModelsMap;
131
+
132
+ /**
133
+ * Provider models mapping interface
134
+ */
135
+ export interface ProviderModels {
136
+ [key: string]: string[];
137
+ }
138
+
139
+ /**
140
+ * OpenAI-compatible model ID type
141
+ * Dynamically derived from ProviderModelsMap
142
+ * Full provider/model paths (e.g., "openai/gpt-4o", "anthropic/claude-3-5-sonnet-20241022")
143
+ */
144
+ export type ModelRouterModelId =
145
+ | {
146
+ [P in Provider]: \`\${P}/\${ProviderModelsMap[P][number]}\`;
147
+ }[Provider]
148
+ | \`mastra/\${ProviderModelsMap['openrouter'][number]}\`
149
+ | (string & {});
150
+
151
+ /**
152
+ * Extract the model part from a ModelRouterModelId for a specific provider
153
+ * Dynamically derived from ProviderModelsMap
154
+ * Example: ModelForProvider<'openai'> = 'gpt-4o' | 'gpt-4-turbo' | ...
155
+ */
156
+ export type ModelForProvider<P extends Provider> = ProviderModelsMap[P][number];
157
+ `;
158
+ }
159
+ async function writeRegistryFiles(jsonPath, typesPath, providers, models, attachmentCapabilities, temperatureCapabilities, structuredOutputCapabilities) {
160
+ const jsonDir = path.dirname(jsonPath);
161
+ const typesDir = path.dirname(typesPath);
162
+ await fs.mkdir(jsonDir, { recursive: true });
163
+ await fs.mkdir(typesDir, { recursive: true });
164
+ await atomicWriteFile(jsonPath, JSON.stringify({
165
+ providers,
166
+ models,
167
+ version: "1.0.0"
168
+ }, null, 2), "utf-8");
169
+ await atomicWriteFile(typesPath, generateTypesContent(models), "utf-8");
170
+ const capDir = path.join(jsonDir, "capabilities");
171
+ const hasCapabilities = attachmentCapabilities && Object.keys(attachmentCapabilities).length > 0 || temperatureCapabilities && Object.keys(temperatureCapabilities).length > 0 || structuredOutputCapabilities && Object.keys(structuredOutputCapabilities).length > 0;
172
+ await fs.rm(capDir, {
173
+ recursive: true,
174
+ force: true
175
+ });
176
+ if (hasCapabilities) {
177
+ await fs.mkdir(capDir, { recursive: true });
178
+ const allProviderIds = /* @__PURE__ */ new Set([
179
+ ...attachmentCapabilities ? Object.keys(attachmentCapabilities) : [],
180
+ ...temperatureCapabilities ? Object.keys(temperatureCapabilities) : [],
181
+ ...structuredOutputCapabilities ? Object.keys(structuredOutputCapabilities) : []
182
+ ]);
183
+ for (const provider of allProviderIds) {
184
+ const capData = {};
185
+ if (attachmentCapabilities?.[provider])
186
+ capData.attachment = attachmentCapabilities[provider];
187
+ if (temperatureCapabilities?.[provider])
188
+ capData.temperature = temperatureCapabilities[provider];
189
+ if (structuredOutputCapabilities?.[provider])
190
+ capData.structuredOutput = structuredOutputCapabilities[provider];
191
+ await atomicWriteFile(path.join(capDir, getCapabilityFileName(provider)), JSON.stringify(capData, null, 2), "utf-8");
192
+ }
193
+ }
194
+ }
195
+ export {
196
+ fetchProvidersFromGateways,
197
+ writeRegistryFiles
198
+ };