openpets 1.0.5 → 1.0.7

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 (100) hide show
  1. package/dist/data/api.json +6658 -0
  2. package/dist/src/core/ai-client-base/index.d.ts +47 -0
  3. package/dist/src/core/ai-client-base/index.d.ts.map +1 -0
  4. package/dist/src/core/ai-client-base/index.js +168 -0
  5. package/dist/src/core/ai-client-base/index.js.map +1 -0
  6. package/dist/src/core/browser.d.ts +10 -0
  7. package/dist/src/core/browser.d.ts.map +1 -0
  8. package/{browser.ts → dist/src/core/browser.js} +4 -4
  9. package/dist/src/core/browser.js.map +1 -0
  10. package/dist/src/core/build-pet.d.ts +2 -0
  11. package/dist/src/core/build-pet.d.ts.map +1 -0
  12. package/dist/src/core/build-pet.js +392 -0
  13. package/dist/src/core/build-pet.js.map +1 -0
  14. package/dist/src/core/cli.d.ts +3 -0
  15. package/dist/src/core/cli.d.ts.map +1 -0
  16. package/dist/src/core/cli.js +244 -0
  17. package/dist/src/core/cli.js.map +1 -0
  18. package/dist/src/core/config-manager.d.ts +13 -0
  19. package/dist/src/core/config-manager.d.ts.map +1 -0
  20. package/dist/src/core/config-manager.js +59 -0
  21. package/dist/src/core/config-manager.js.map +1 -0
  22. package/dist/src/core/deploy-pet.d.ts +2 -0
  23. package/dist/src/core/deploy-pet.d.ts.map +1 -0
  24. package/dist/src/core/deploy-pet.js +66 -0
  25. package/dist/src/core/deploy-pet.js.map +1 -0
  26. package/dist/src/core/index.d.ts +12 -0
  27. package/dist/src/core/index.d.ts.map +1 -0
  28. package/dist/src/core/index.js +12 -0
  29. package/dist/src/core/index.js.map +1 -0
  30. package/dist/src/core/local-cache.d.ts +69 -0
  31. package/dist/src/core/local-cache.d.ts.map +1 -0
  32. package/dist/src/core/local-cache.js +212 -0
  33. package/dist/src/core/local-cache.js.map +1 -0
  34. package/dist/src/core/logger.d.ts.map +1 -0
  35. package/{logger.js → dist/src/core/logger.js} +8 -9
  36. package/dist/src/core/logger.js.map +1 -0
  37. package/dist/src/core/mautrix-bridge.d.ts +93 -0
  38. package/dist/src/core/mautrix-bridge.d.ts.map +1 -0
  39. package/dist/src/core/mautrix-bridge.js +1046 -0
  40. package/dist/src/core/mautrix-bridge.js.map +1 -0
  41. package/dist/src/core/mcp-factory.d.ts +12 -0
  42. package/dist/src/core/mcp-factory.d.ts.map +1 -0
  43. package/dist/src/core/mcp-factory.js +143 -0
  44. package/dist/src/core/mcp-factory.js.map +1 -0
  45. package/dist/src/core/mcp-server.d.ts +3 -0
  46. package/dist/src/core/mcp-server.d.ts.map +1 -0
  47. package/dist/src/core/mcp-server.js +55 -0
  48. package/dist/src/core/mcp-server.js.map +1 -0
  49. package/dist/src/core/migrate-plugin.d.ts +15 -0
  50. package/dist/src/core/migrate-plugin.d.ts.map +1 -0
  51. package/dist/src/core/migrate-plugin.js +181 -0
  52. package/dist/src/core/migrate-plugin.js.map +1 -0
  53. package/dist/src/core/pets-registry.d.ts +47 -0
  54. package/dist/src/core/pets-registry.d.ts.map +1 -0
  55. package/dist/src/core/pets-registry.js +109 -0
  56. package/dist/src/core/pets-registry.js.map +1 -0
  57. package/dist/src/core/plugin-factory.d.ts +58 -0
  58. package/dist/src/core/plugin-factory.d.ts.map +1 -0
  59. package/dist/src/core/plugin-factory.js +212 -0
  60. package/dist/src/core/plugin-factory.js.map +1 -0
  61. package/dist/src/core/prompt-utils.d.ts +14 -0
  62. package/dist/src/core/prompt-utils.d.ts.map +1 -0
  63. package/dist/src/core/prompt-utils.js +106 -0
  64. package/dist/src/core/prompt-utils.js.map +1 -0
  65. package/dist/src/core/schema-helpers.d.ts +30 -0
  66. package/dist/src/core/schema-helpers.d.ts.map +1 -0
  67. package/dist/src/core/schema-helpers.js +46 -0
  68. package/dist/src/core/schema-helpers.js.map +1 -0
  69. package/dist/src/core/search-pets.d.ts +29 -0
  70. package/dist/src/core/search-pets.d.ts.map +1 -0
  71. package/dist/src/core/search-pets.js +196 -0
  72. package/dist/src/core/search-pets.js.map +1 -0
  73. package/dist/src/core/types.d.ts +63 -0
  74. package/dist/src/core/types.d.ts.map +1 -0
  75. package/dist/src/core/types.js +2 -0
  76. package/dist/src/core/types.js.map +1 -0
  77. package/dist/src/core/validate-pet.d.ts +40 -0
  78. package/dist/src/core/validate-pet.d.ts.map +1 -0
  79. package/dist/src/core/validate-pet.js +650 -0
  80. package/dist/src/core/validate-pet.js.map +1 -0
  81. package/package.json +15 -28
  82. package/ai-client-base/index.ts +0 -229
  83. package/build-pet.ts +0 -429
  84. package/cli.ts +0 -268
  85. package/config-manager.ts +0 -82
  86. package/deploy-pet.ts +0 -91
  87. package/index.ts +0 -10
  88. package/local-cache.ts +0 -280
  89. package/logger.ts +0 -143
  90. package/mcp-factory.ts +0 -180
  91. package/mcp-server.ts +0 -69
  92. package/migrate-plugin.ts +0 -220
  93. package/pets-registry.ts +0 -160
  94. package/plugin-factory.ts +0 -300
  95. package/prompt-utils.ts +0 -130
  96. package/schema-helpers.ts +0 -59
  97. package/search-pets.ts +0 -267
  98. package/types.ts +0 -68
  99. package/validate-pet.ts +0 -749
  100. /package/{logger.d.ts → dist/src/core/logger.d.ts} +0 -0
@@ -0,0 +1,47 @@
1
+ export interface AIImageResult {
2
+ success: boolean;
3
+ images?: Array<{
4
+ url: string;
5
+ width?: number;
6
+ height?: number;
7
+ }>;
8
+ error?: string;
9
+ metadata?: Record<string, any>;
10
+ requestId?: string;
11
+ credits?: Record<string, any>;
12
+ }
13
+ export interface AIVideoResult {
14
+ success: boolean;
15
+ videos?: Array<{
16
+ url: string;
17
+ duration?: number;
18
+ width?: number;
19
+ height?: number;
20
+ }>;
21
+ error?: string;
22
+ metadata?: Record<string, any>;
23
+ requestId?: string;
24
+ credits?: Record<string, any>;
25
+ }
26
+ export interface BaseAIClientConfig {
27
+ apiKey: string;
28
+ baseUrl?: string;
29
+ debug?: boolean;
30
+ }
31
+ export declare abstract class BaseAIClient {
32
+ protected apiKey: string;
33
+ protected baseUrl?: string;
34
+ protected debug: boolean;
35
+ constructor(config: BaseAIClientConfig);
36
+ abstract get providerName(): string;
37
+ protected log(message: string, level?: "info" | "warn" | "error" | "debug"): void;
38
+ protected ensureApiKey(envVarName: string): void;
39
+ protected downloadMedia(url: string, outputDir: string, prefix: string): Promise<string>;
40
+ protected openInDefaultViewer(filepath: string): Promise<void>;
41
+ protected getMimeType(filename: string): string;
42
+ protected downloadAndOpen<T extends AIImageResult | AIVideoResult>(result: T, mediaType: "image" | "video", fileExtension: string, openInViewer?: boolean): Promise<T & {
43
+ localPath?: string;
44
+ }>;
45
+ protected extractCreditsFromResponse(response: any): any;
46
+ }
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../ai-client-base/index.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAChE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC9B;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACnF,KAAK,CAAC,EAAE,MAAM,CAAA;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BAA0B,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;CA+BzD"}
@@ -0,0 +1,168 @@
1
+ import { createLogger } from "../logger";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import { exec } from "child_process";
5
+ import { promisify } from "util";
6
+ const execAsync = promisify(exec);
7
+ const logger = createLogger("base-ai-client");
8
+ export class BaseAIClient {
9
+ apiKey;
10
+ baseUrl;
11
+ debug;
12
+ constructor(config) {
13
+ this.apiKey = config.apiKey;
14
+ this.baseUrl = config.baseUrl;
15
+ this.debug = config.debug || false;
16
+ }
17
+ log(message, level = "info") {
18
+ if (!this.debug && level === "debug")
19
+ return;
20
+ const timestamp = new Date().toISOString();
21
+ const prefix = `[${this.providerName.toUpperCase()}] ${timestamp}`;
22
+ switch (level) {
23
+ case "error":
24
+ console.error(`${prefix} ERROR:`, message);
25
+ break;
26
+ case "warn":
27
+ console.warn(`${prefix} WARN:`, message);
28
+ break;
29
+ case "debug":
30
+ console.debug(`${prefix} DEBUG:`, message);
31
+ break;
32
+ default:
33
+ console.log(`${prefix} INFO:`, message);
34
+ }
35
+ }
36
+ ensureApiKey(envVarName) {
37
+ if (!this.apiKey || this.apiKey.trim() === "") {
38
+ throw new Error(`${envVarName} environment variable is required but not set`);
39
+ }
40
+ }
41
+ async downloadMedia(url, outputDir, prefix) {
42
+ try {
43
+ if (!fs.existsSync(outputDir)) {
44
+ fs.mkdirSync(outputDir, { recursive: true });
45
+ }
46
+ const timestamp = Date.now();
47
+ const extension = url.includes('.mp4') || url.includes('video') ? 'mp4' : 'png';
48
+ const filename = `${prefix}-${timestamp}.${extension}`;
49
+ const filepath = path.join(outputDir, filename);
50
+ logger.info(`Downloading media from ${url}`);
51
+ const response = await fetch(url);
52
+ if (!response.ok) {
53
+ throw new Error(`Failed to download: ${response.statusText}`);
54
+ }
55
+ const buffer = await response.arrayBuffer();
56
+ fs.writeFileSync(filepath, Buffer.from(buffer));
57
+ logger.info(`Media saved to ${filepath}`);
58
+ return filepath;
59
+ }
60
+ catch (error) {
61
+ logger.error(`Failed to download media: ${error.message}`);
62
+ throw error;
63
+ }
64
+ }
65
+ async openInDefaultViewer(filepath) {
66
+ try {
67
+ const platform = process.platform;
68
+ let command;
69
+ if (platform === "darwin") {
70
+ command = `open "${filepath}"`;
71
+ }
72
+ else if (platform === "win32") {
73
+ command = `start "" "${filepath}"`;
74
+ }
75
+ else {
76
+ command = `xdg-open "${filepath}"`;
77
+ }
78
+ await execAsync(command);
79
+ logger.info(`Opened ${filepath} in default viewer`);
80
+ }
81
+ catch (error) {
82
+ logger.warn(`Failed to open in viewer: ${error.message}`);
83
+ }
84
+ }
85
+ getMimeType(filename) {
86
+ const ext = path.extname(filename).toLowerCase();
87
+ const mimeTypes = {
88
+ '.jpg': 'image/jpeg',
89
+ '.jpeg': 'image/jpeg',
90
+ '.png': 'image/png',
91
+ '.gif': 'image/gif',
92
+ '.webp': 'image/webp',
93
+ '.mp4': 'video/mp4',
94
+ '.mov': 'video/quicktime',
95
+ '.avi': 'video/x-msvideo',
96
+ '.webm': 'video/webm'
97
+ };
98
+ return mimeTypes[ext] || 'application/octet-stream';
99
+ }
100
+ async downloadAndOpen(result, mediaType, fileExtension, openInViewer = true) {
101
+ if (!result.success) {
102
+ return result;
103
+ }
104
+ const mediaArray = mediaType === "image"
105
+ ? result.images
106
+ : result.videos;
107
+ if (!mediaArray || mediaArray.length === 0) {
108
+ return result;
109
+ }
110
+ try {
111
+ const downloadsDir = path.join(process.cwd(), "output");
112
+ if (!fs.existsSync(downloadsDir)) {
113
+ fs.mkdirSync(downloadsDir, { recursive: true });
114
+ }
115
+ const timestamp = Date.now();
116
+ const filename = `${this.providerName}-${mediaType}-${timestamp}.${fileExtension}`;
117
+ const localPath = path.join(downloadsDir, filename);
118
+ const response = await fetch(mediaArray[0].url);
119
+ if (!response.ok) {
120
+ throw new Error(`Failed to download: ${response.statusText}`);
121
+ }
122
+ const buffer = await response.arrayBuffer();
123
+ fs.writeFileSync(localPath, Buffer.from(buffer));
124
+ logger.info(`${mediaType} saved to ${localPath}`);
125
+ if (openInViewer) {
126
+ await this.openInDefaultViewer(localPath);
127
+ }
128
+ return {
129
+ ...result,
130
+ localPath
131
+ };
132
+ }
133
+ catch (error) {
134
+ this.log(`${mediaType.charAt(0).toUpperCase() + mediaType.slice(1)} generated successfully but post-processing failed: ${error.message}`, "error");
135
+ return {
136
+ ...result,
137
+ localPath: undefined
138
+ };
139
+ }
140
+ }
141
+ extractCreditsFromResponse(response) {
142
+ const credits = {};
143
+ if (response?.credits !== undefined) {
144
+ credits.balance = response.credits.balance;
145
+ credits.cost = response.credits.cost;
146
+ credits.currency = response.credits.currency;
147
+ credits.remaining = response.credits.remaining;
148
+ credits.limit = response.credits.limit;
149
+ credits.used = response.credits.used;
150
+ }
151
+ if (response?.billing !== undefined) {
152
+ credits.balance = response.billing.balance;
153
+ credits.cost = response.billing.cost;
154
+ credits.currency = response.billing.currency;
155
+ credits.remaining = response.billing.remaining;
156
+ }
157
+ if (response?.usage !== undefined) {
158
+ credits.used = response.usage.total_tokens || response.usage.used;
159
+ credits.limit = response.usage.limit;
160
+ credits.remaining = response.usage.remaining;
161
+ }
162
+ if (Object.keys(credits).length === 0) {
163
+ return undefined;
164
+ }
165
+ return credits;
166
+ }
167
+ }
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../ai-client-base/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAEhC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;AACjC,MAAM,MAAM,GAAG,YAAY,CAAC,g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C,IAAI,CAAA;YACpC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAA;YAC5C,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAA;QAChD,CAAC;QAED,IAAI,QAAQ,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAA;YACjE,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAA;YACpC,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAA;QAC9C,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtC,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Browser-safe exports from openpets
3
+ *
4
+ * This module only exports code that doesn't use Node.js APIs like fs, path, etc.
5
+ * Use this entry point when importing from browser/frontend code.
6
+ */
7
+ export * from './types';
8
+ export * from './search-pets';
9
+ export * from './schema-helpers';
10
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../browser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
@@ -4,7 +4,7 @@
4
4
  * This module only exports code that doesn't use Node.js APIs like fs, path, etc.
5
5
  * Use this entry point when importing from browser/frontend code.
6
6
  */
7
-
8
- export * from './types'
9
- export * from './search-pets'
10
- export * from './schema-helpers'
7
+ export * from './types';
8
+ export * from './search-pets';
9
+ export * from './schema-helpers';
10
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../browser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function buildPet(petName?: string): Promise<void>;
2
+ //# sourceMappingURL=build-pet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-pet.d.ts","sourceRoot":"","sources":["../../../build-pet.ts"],"names":[],"mappings":"AAkSA,wBAAsB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0K9D"}
@@ -0,0 +1,392 @@
1
+ import { join, dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'fs';
4
+ import { pathToFileURL } from 'url';
5
+ import { PluginValidator } from './validate-pet.js';
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+ function findProjectRoot() {
9
+ let currentDir = process.cwd();
10
+ for (let i = 0; i < 20; i++) {
11
+ const petsDir = join(currentDir, 'pets');
12
+ const packageJson = join(currentDir, 'package.json');
13
+ if (existsSync(petsDir) && existsSync(packageJson) && !currentDir.includes('node_modules')) {
14
+ try {
15
+ const pkg = JSON.parse(readFileSync(packageJson, 'utf8'));
16
+ if (pkg.workspaces && Array.isArray(pkg.workspaces) && pkg.workspaces.includes('pets/*')) {
17
+ return currentDir;
18
+ }
19
+ }
20
+ catch { }
21
+ }
22
+ const parent = dirname(currentDir);
23
+ if (parent === currentDir)
24
+ break;
25
+ currentDir = parent;
26
+ }
27
+ throw new Error(`Could not find project root from ${process.cwd()}. Make sure you're running from within a pets workspace.`);
28
+ }
29
+ let _projectRoot = null;
30
+ function getProjectRoot() {
31
+ if (_projectRoot === null) {
32
+ _projectRoot = findProjectRoot();
33
+ }
34
+ return _projectRoot;
35
+ }
36
+ const DEBUG = process.env.PETS_DEBUG === 'true';
37
+ function debug(...msgs) {
38
+ if (DEBUG) {
39
+ console.log('[BUILD-PET]', ...msgs);
40
+ }
41
+ }
42
+ async function extractToolsFromIndexFile(indexPath) {
43
+ debug('=== EXTRACTING TOOLS FROM INDEX FILE ===');
44
+ debug('Index path:', indexPath);
45
+ debug('File exists:', existsSync(indexPath));
46
+ try {
47
+ const indexUrl = pathToFileURL(indexPath).href;
48
+ debug('Index URL:', indexUrl);
49
+ debug('Attempting dynamic import...');
50
+ const indexModule = await import(/* @vite-ignore */ indexUrl);
51
+ debug('Import successful');
52
+ debug('Module keys:', Object.keys(indexModule));
53
+ if (indexModule.toolsMetadata && Array.isArray(indexModule.toolsMetadata)) {
54
+ console.log(` Found ${indexModule.toolsMetadata.length} tools from exported toolsMetadata`);
55
+ debug('Tools metadata:', JSON.stringify(indexModule.toolsMetadata, null, 2));
56
+ return indexModule.toolsMetadata;
57
+ }
58
+ else {
59
+ debug('toolsMetadata not found or not an array');
60
+ debug('indexModule.toolsMetadata:', indexModule.toolsMetadata);
61
+ }
62
+ }
63
+ catch (error) {
64
+ console.warn(` ⚠️ Could not import toolsMetadata, falling back to file parsing`);
65
+ console.warn(` Error: ${error instanceof Error ? error.message : String(error)}`);
66
+ debug('Import error details:', {
67
+ name: error instanceof Error ? error.name : 'Unknown',
68
+ message: error instanceof Error ? error.message : String(error),
69
+ stack: error instanceof Error ? error.stack : 'No stack trace'
70
+ });
71
+ }
72
+ debug('Falling back to file parsing');
73
+ return extractToolsFromIndexFileByParsing(indexPath);
74
+ }
75
+ function extractToolsFromIndexFileByParsing(indexPath) {
76
+ const content = readFileSync(indexPath, 'utf8');
77
+ const toolsMatch = content.match(/const\s+tools:\s*ToolDefinition\[\]\s*=\s*\[([\s\S]*?)\n\s*\]/m);
78
+ if (!toolsMatch) {
79
+ console.warn('⚠️ Could not find tools array in index.ts');
80
+ return [];
81
+ }
82
+ const toolsArray = toolsMatch[1];
83
+ const toolNames = [];
84
+ const toolsSeparated = toolsArray.split(/\n\s*\{/).filter(part => part.includes('name:'));
85
+ const toolBlocks = toolsSeparated.map((part, idx) => {
86
+ if (idx === 0)
87
+ return part;
88
+ return '{' + part;
89
+ });
90
+ for (const block of toolBlocks) {
91
+ const nameMatch = block.match(/name:\s*["']([^"']+)["']/);
92
+ const descMatch = block.match(/description:\s*["']([^"']+)["']/);
93
+ const schemaMatch = block.match(/schema:\s*z\.object\(\{([\s\S]*?)\}\),?\s*(?:async\s+execute|$)/);
94
+ if (nameMatch && descMatch) {
95
+ let schemaProperties = {};
96
+ if (schemaMatch) {
97
+ const schemaContent = schemaMatch[1];
98
+ const lines = schemaContent.split('\n').filter(l => l.trim() && !l.trim().startsWith('//'));
99
+ for (const line of lines) {
100
+ const propMatch = line.match(/^\s*(\w+):\s*z\.(.+?),?\s*$/);
101
+ if (!propMatch)
102
+ continue;
103
+ const [, propName, zodDef] = propMatch;
104
+ let propSchema = {};
105
+ if (zodDef.includes('string(')) {
106
+ propSchema.type = 'string';
107
+ }
108
+ else if (zodDef.includes('number(')) {
109
+ propSchema.type = 'number';
110
+ const minMatch = zodDef.match(/\.min\((\d+)\)/);
111
+ const maxMatch = zodDef.match(/\.max\((\d+)\)/);
112
+ if (minMatch)
113
+ propSchema.minimum = parseInt(minMatch[1]);
114
+ if (maxMatch)
115
+ propSchema.maximum = parseInt(maxMatch[1]);
116
+ }
117
+ else if (zodDef.includes('boolean(')) {
118
+ propSchema.type = 'boolean';
119
+ }
120
+ else if (zodDef.includes('enum(')) {
121
+ propSchema.type = 'string';
122
+ const enumMatch = zodDef.match(/enum\(\[([^\]]+)\]\)/);
123
+ if (enumMatch) {
124
+ const enumValues = enumMatch[1].match(/["']([^"']+)["']/g)?.map(v => v.replace(/["']/g, ''));
125
+ if (enumValues)
126
+ propSchema.enum = enumValues;
127
+ }
128
+ }
129
+ else if (zodDef.includes('array(')) {
130
+ propSchema.type = 'array';
131
+ const arrayTypeMatch = zodDef.match(/array\(z\.(\w+)\(\)\)/);
132
+ if (arrayTypeMatch) {
133
+ propSchema.items = { type: arrayTypeMatch[1].toLowerCase() };
134
+ }
135
+ }
136
+ if (zodDef.includes('.optional()')) {
137
+ propSchema.optional = true;
138
+ }
139
+ const descMatch = zodDef.match(/\.describe\(["']([^"']+)["']\)/);
140
+ if (descMatch) {
141
+ propSchema.description = descMatch[1];
142
+ }
143
+ schemaProperties[propName] = propSchema;
144
+ }
145
+ }
146
+ toolNames.push({
147
+ name: nameMatch[1],
148
+ description: descMatch[1],
149
+ schema: {
150
+ type: 'object',
151
+ properties: schemaProperties
152
+ }
153
+ });
154
+ }
155
+ }
156
+ console.log(` Found ${toolNames.length} tools in index.ts`);
157
+ return toolNames;
158
+ }
159
+ function formatZodSchema(schema, depth = 0) {
160
+ if (!schema || !schema._def) {
161
+ return { type: 'object', properties: {} };
162
+ }
163
+ const def = schema._def;
164
+ const zodType = def.typeName || def.type || schema.constructor?.name || 'unknown';
165
+ if (zodType === 'ZodObject' || zodType === 'object') {
166
+ const properties = {};
167
+ const shapeObj = typeof def.shape === 'function' ? def.shape() : def.shape || {};
168
+ for (const [key, value] of Object.entries(shapeObj)) {
169
+ properties[key] = formatZodSchema(value, depth + 1);
170
+ }
171
+ return {
172
+ type: 'object',
173
+ properties
174
+ };
175
+ }
176
+ if (zodType === 'ZodString' || zodType === 'string') {
177
+ return { type: 'string' };
178
+ }
179
+ if (zodType === 'ZodNumber' || zodType === 'number') {
180
+ const result = { type: 'number' };
181
+ if (def.checks) {
182
+ for (const check of def.checks) {
183
+ if (check.kind === 'min')
184
+ result.minimum = check.value;
185
+ if (check.kind === 'max')
186
+ result.maximum = check.value;
187
+ }
188
+ }
189
+ return result;
190
+ }
191
+ if (zodType === 'ZodBoolean' || zodType === 'boolean') {
192
+ return { type: 'boolean' };
193
+ }
194
+ if (zodType === 'ZodArray' || zodType === 'array') {
195
+ return {
196
+ type: 'array',
197
+ items: formatZodSchema(def.type, depth + 1)
198
+ };
199
+ }
200
+ if (zodType === 'ZodEnum' || zodType === 'enum') {
201
+ let values = def.values;
202
+ if (!values && schema._def?.values) {
203
+ values = schema._def.values;
204
+ }
205
+ if (!values && schema.options) {
206
+ values = schema.options;
207
+ }
208
+ const enumArray = Array.isArray(values) ? values : Object.values(values || {});
209
+ return {
210
+ type: 'string',
211
+ enum: enumArray
212
+ };
213
+ }
214
+ if (zodType === 'ZodOptional' || zodType === 'optional') {
215
+ return {
216
+ ...formatZodSchema(def.innerType, depth + 1),
217
+ optional: true
218
+ };
219
+ }
220
+ return { type: zodType };
221
+ }
222
+ function generateToolsMetadata(tools) {
223
+ return tools.map(tool => ({
224
+ name: tool.name,
225
+ description: tool.description,
226
+ schema: tool.schema._def ? formatZodSchema(tool.schema) : tool.schema
227
+ }));
228
+ }
229
+ function generateScriptsFromTools(tools, petName) {
230
+ const scripts = {
231
+ build: 'pets build',
232
+ 'build:tsc': 'tsc',
233
+ quickstart: `opencode run "list available ${petName} commands"`,
234
+ };
235
+ for (const tool of tools) {
236
+ let scriptName = tool.name;
237
+ if (scriptName.startsWith(`${petName}-`)) {
238
+ scriptName = scriptName.replace(new RegExp(`^${petName}-`), 'test:');
239
+ }
240
+ else {
241
+ scriptName = `test:${scriptName}`;
242
+ }
243
+ const command = `opencode run "${tool.description}"`;
244
+ scripts[scriptName] = command;
245
+ }
246
+ scripts['test:all'] = 'echo "Run individual test scripts to test specific tools"';
247
+ return scripts;
248
+ }
249
+ export async function buildPet(petName) {
250
+ const projectRoot = getProjectRoot();
251
+ debug('=== BUILD PET STARTING ===');
252
+ debug('Initial petName:', petName);
253
+ debug('CWD:', process.cwd());
254
+ debug('Project root:', projectRoot);
255
+ if (!petName) {
256
+ const cwd = process.cwd();
257
+ const petsDir = join(projectRoot, 'pets');
258
+ debug('Auto-detecting pet from CWD:', cwd);
259
+ debug('Pets directory:', petsDir);
260
+ if (cwd.includes('/pets/')) {
261
+ petName = cwd.split('/pets/')[1].split('/')[0];
262
+ console.log(`📦 Auto-detected pet: ${petName}`);
263
+ debug('Auto-detected pet:', petName);
264
+ }
265
+ if (!petName) {
266
+ console.error('Usage: pets build <pet-name>');
267
+ console.error('Example: pets build postgres');
268
+ console.error('');
269
+ console.error('Available pets:');
270
+ if (existsSync(petsDir)) {
271
+ const pets = readdirSync(petsDir).filter(dir => {
272
+ const petPath = join(petsDir, dir);
273
+ return statSync(petPath).isDirectory() && dir !== '_TEMPLATE_';
274
+ });
275
+ pets.forEach(pet => console.error(` - ${pet}`));
276
+ debug('Available pets:', pets);
277
+ }
278
+ else {
279
+ debug('Pets directory does not exist:', petsDir);
280
+ }
281
+ process.exit(1);
282
+ }
283
+ }
284
+ const petDir = join(projectRoot, 'pets', petName);
285
+ const packageJsonPath = join(petDir, 'package.json');
286
+ const indexPath = join(petDir, 'index.ts');
287
+ debug('Pet directory:', petDir);
288
+ debug('Package.json path:', packageJsonPath);
289
+ debug('Index.ts path:', indexPath);
290
+ if (!existsSync(petDir)) {
291
+ console.error(`❌ Pet '${petName}' not found in pets/ directory`);
292
+ debug('Pet directory does not exist:', petDir);
293
+ process.exit(1);
294
+ }
295
+ if (!existsSync(packageJsonPath)) {
296
+ console.error(`❌ package.json not found for pet '${petName}'`);
297
+ debug('Package.json does not exist:', packageJsonPath);
298
+ process.exit(1);
299
+ }
300
+ if (!existsSync(indexPath)) {
301
+ console.error(`❌ index.ts not found for pet '${petName}'`);
302
+ debug('Index.ts does not exist:', indexPath);
303
+ process.exit(1);
304
+ }
305
+ console.log(`🔨 Building ${petName}...`);
306
+ debug('All required files found, proceeding with build');
307
+ const packageJsonContent = readFileSync(packageJsonPath, 'utf8');
308
+ debug('Package.json content length:', packageJsonContent.length);
309
+ const packageJson = JSON.parse(packageJsonContent);
310
+ debug('Package.json parsed successfully');
311
+ debug('Package name:', packageJson.name);
312
+ debug('Package version:', packageJson.version);
313
+ // Auto-generate repository field if missing
314
+ if (!packageJson.repository) {
315
+ packageJson.repository = {
316
+ type: 'git',
317
+ url: `https://github.com/raggle-ai/pets/pets/${petName}`
318
+ };
319
+ debug('Auto-generated repository field:', packageJson.repository.url);
320
+ }
321
+ console.log(` Name: ${packageJson.name}`);
322
+ console.log(` Version: ${packageJson.version}`);
323
+ console.log(` Description: ${packageJson.description || 'No description'}`);
324
+ console.log(`\n🔍 Validating plugin structure...`);
325
+ const validator = new PluginValidator();
326
+ const validation = validator.validatePlugin(petDir);
327
+ if (validation.result.errors.length > 0) {
328
+ console.log(`\n❌ Validation failed with ${validation.result.errors.length} error(s):`);
329
+ validation.result.errors.forEach(error => {
330
+ console.log(` ❌ ${error}`);
331
+ });
332
+ console.log(`\n💥 Build aborted due to validation errors.`);
333
+ process.exit(1);
334
+ }
335
+ if (validation.result.warnings.length > 0) {
336
+ console.log(`\n⚠️ Found ${validation.result.warnings.length} warning(s):`);
337
+ validation.result.warnings.forEach(warning => {
338
+ console.log(` ⚠️ ${warning}`);
339
+ });
340
+ }
341
+ if (validation.result.codePatternWarnings && validation.result.codePatternWarnings.length > 0) {
342
+ console.log(`\n📋 Code pattern analysis:`);
343
+ validation.result.codePatternWarnings.forEach(warning => {
344
+ console.log(` ${warning}`);
345
+ });
346
+ }
347
+ if (validation.result.errors.length === 0 && validation.result.warnings.length === 0 && (!validation.result.codePatternWarnings || validation.result.codePatternWarnings.length === 0)) {
348
+ console.log(` ✓ All validation checks passed`);
349
+ }
350
+ debug('Extracting tools from index file...');
351
+ const tools = await extractToolsFromIndexFile(indexPath);
352
+ debug(`Extracted ${tools.length} tools`);
353
+ if (tools.length > 0) {
354
+ console.log(`\n📝 Generating scripts and metadata for ${tools.length} tools...`);
355
+ debug('Tools extracted:', tools.map(t => t.name));
356
+ const scripts = generateScriptsFromTools(tools, petName);
357
+ debug('Generated scripts:', Object.keys(scripts));
358
+ const toolsMetadata = generateToolsMetadata(tools);
359
+ debug('Generated tools metadata count:', toolsMetadata.length);
360
+ packageJson.scripts = scripts;
361
+ delete packageJson.tools;
362
+ const commandsJsonPath = join(petDir, 'commands.json');
363
+ debug('Commands.json path:', commandsJsonPath);
364
+ const commandsData = {
365
+ name: packageJson.name,
366
+ version: packageJson.version,
367
+ description: packageJson.description,
368
+ tools: toolsMetadata,
369
+ generatedAt: new Date().toISOString()
370
+ };
371
+ debug('Writing package.json...');
372
+ writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8');
373
+ debug('Package.json written successfully');
374
+ debug('Writing commands.json...');
375
+ writeFileSync(commandsJsonPath, JSON.stringify(commandsData, null, 2) + '\n', 'utf8');
376
+ debug('Commands.json written successfully');
377
+ console.log(` ✓ Updated package.json with ${Object.keys(scripts).length} scripts`);
378
+ console.log(` ✓ Generated commands.json with ${tools.length} tools`);
379
+ console.log(`\n🔧 Generated test scripts:`);
380
+ Object.entries(scripts).forEach(([name, cmd]) => {
381
+ if (name.startsWith('test:')) {
382
+ console.log(` - npm run ${name}`);
383
+ }
384
+ });
385
+ }
386
+ else {
387
+ debug('No tools found in index file');
388
+ }
389
+ console.log(`\n✅ ${petName} built successfully!`);
390
+ debug('=== BUILD COMPLETE ===');
391
+ }
392
+ //# sourceMappingURL=build-pet.js.map