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.
- package/dist/data/api.json +6658 -0
- package/dist/src/core/ai-client-base/index.d.ts +47 -0
- package/dist/src/core/ai-client-base/index.d.ts.map +1 -0
- package/dist/src/core/ai-client-base/index.js +168 -0
- package/dist/src/core/ai-client-base/index.js.map +1 -0
- package/dist/src/core/browser.d.ts +10 -0
- package/dist/src/core/browser.d.ts.map +1 -0
- package/{browser.ts → dist/src/core/browser.js} +4 -4
- package/dist/src/core/browser.js.map +1 -0
- package/dist/src/core/build-pet.d.ts +2 -0
- package/dist/src/core/build-pet.d.ts.map +1 -0
- package/dist/src/core/build-pet.js +392 -0
- package/dist/src/core/build-pet.js.map +1 -0
- package/dist/src/core/cli.d.ts +3 -0
- package/dist/src/core/cli.d.ts.map +1 -0
- package/dist/src/core/cli.js +244 -0
- package/dist/src/core/cli.js.map +1 -0
- package/dist/src/core/config-manager.d.ts +13 -0
- package/dist/src/core/config-manager.d.ts.map +1 -0
- package/dist/src/core/config-manager.js +59 -0
- package/dist/src/core/config-manager.js.map +1 -0
- package/dist/src/core/deploy-pet.d.ts +2 -0
- package/dist/src/core/deploy-pet.d.ts.map +1 -0
- package/dist/src/core/deploy-pet.js +66 -0
- package/dist/src/core/deploy-pet.js.map +1 -0
- package/dist/src/core/index.d.ts +12 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +12 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/local-cache.d.ts +69 -0
- package/dist/src/core/local-cache.d.ts.map +1 -0
- package/dist/src/core/local-cache.js +212 -0
- package/dist/src/core/local-cache.js.map +1 -0
- package/dist/src/core/logger.d.ts.map +1 -0
- package/{logger.js → dist/src/core/logger.js} +8 -9
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/mautrix-bridge.d.ts +93 -0
- package/dist/src/core/mautrix-bridge.d.ts.map +1 -0
- package/dist/src/core/mautrix-bridge.js +1046 -0
- package/dist/src/core/mautrix-bridge.js.map +1 -0
- package/dist/src/core/mcp-factory.d.ts +12 -0
- package/dist/src/core/mcp-factory.d.ts.map +1 -0
- package/dist/src/core/mcp-factory.js +143 -0
- package/dist/src/core/mcp-factory.js.map +1 -0
- package/dist/src/core/mcp-server.d.ts +3 -0
- package/dist/src/core/mcp-server.d.ts.map +1 -0
- package/dist/src/core/mcp-server.js +55 -0
- package/dist/src/core/mcp-server.js.map +1 -0
- package/dist/src/core/migrate-plugin.d.ts +15 -0
- package/dist/src/core/migrate-plugin.d.ts.map +1 -0
- package/dist/src/core/migrate-plugin.js +181 -0
- package/dist/src/core/migrate-plugin.js.map +1 -0
- package/dist/src/core/pets-registry.d.ts +47 -0
- package/dist/src/core/pets-registry.d.ts.map +1 -0
- package/dist/src/core/pets-registry.js +109 -0
- package/dist/src/core/pets-registry.js.map +1 -0
- package/dist/src/core/plugin-factory.d.ts +58 -0
- package/dist/src/core/plugin-factory.d.ts.map +1 -0
- package/dist/src/core/plugin-factory.js +212 -0
- package/dist/src/core/plugin-factory.js.map +1 -0
- package/dist/src/core/prompt-utils.d.ts +14 -0
- package/dist/src/core/prompt-utils.d.ts.map +1 -0
- package/dist/src/core/prompt-utils.js +106 -0
- package/dist/src/core/prompt-utils.js.map +1 -0
- package/dist/src/core/schema-helpers.d.ts +30 -0
- package/dist/src/core/schema-helpers.d.ts.map +1 -0
- package/dist/src/core/schema-helpers.js +46 -0
- package/dist/src/core/schema-helpers.js.map +1 -0
- package/dist/src/core/search-pets.d.ts +29 -0
- package/dist/src/core/search-pets.d.ts.map +1 -0
- package/dist/src/core/search-pets.js +196 -0
- package/dist/src/core/search-pets.js.map +1 -0
- package/dist/src/core/types.d.ts +63 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +2 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/core/validate-pet.d.ts +40 -0
- package/dist/src/core/validate-pet.d.ts.map +1 -0
- package/dist/src/core/validate-pet.js +650 -0
- package/dist/src/core/validate-pet.js.map +1 -0
- package/package.json +15 -28
- package/ai-client-base/index.ts +0 -229
- package/build-pet.ts +0 -429
- package/cli.ts +0 -268
- package/config-manager.ts +0 -82
- package/deploy-pet.ts +0 -91
- package/index.ts +0 -10
- package/local-cache.ts +0 -280
- package/logger.ts +0 -143
- package/mcp-factory.ts +0 -180
- package/mcp-server.ts +0 -69
- package/migrate-plugin.ts +0 -220
- package/pets-registry.ts +0 -160
- package/plugin-factory.ts +0 -300
- package/prompt-utils.ts +0 -130
- package/schema-helpers.ts +0 -59
- package/search-pets.ts +0 -267
- package/types.ts +0 -68
- package/validate-pet.ts +0 -749
- /package/{logger.d.ts → dist/src/core/logger.d.ts} +0 -0
package/search-pets.ts
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import type { Pet } from "./types";
|
|
2
|
-
|
|
3
|
-
const REMOTE_API_URL = "https://pets.studio/api.json";
|
|
4
|
-
|
|
5
|
-
function isDevMode(): boolean {
|
|
6
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
7
|
-
return process.env.PETS_DEV_MODE === "true" || process.env.PETS_DEV_MODE === "1";
|
|
8
|
-
}
|
|
9
|
-
if (typeof window !== 'undefined' && (window as any).PETS_DEV_MODE) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface SearchResult {
|
|
16
|
-
id: string;
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
keywords: string[];
|
|
20
|
-
matchReason: string;
|
|
21
|
-
matchScore: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface PetApiData {
|
|
25
|
-
name: string;
|
|
26
|
-
description: string;
|
|
27
|
-
keywords?: string[];
|
|
28
|
-
title: string;
|
|
29
|
-
version?: string;
|
|
30
|
-
source_code_url?: string;
|
|
31
|
-
tools?: Array<{ name: string; description: string }>;
|
|
32
|
-
queries?: string[];
|
|
33
|
-
scenarios?: Record<string, string | string[]>;
|
|
34
|
-
[key: string]: any;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type SearchIndex = {
|
|
38
|
-
id: string;
|
|
39
|
-
nameLower: string;
|
|
40
|
-
descLower: string;
|
|
41
|
-
keywordsLower: string[];
|
|
42
|
-
toolsText: string;
|
|
43
|
-
queriesText: string;
|
|
44
|
-
scenariosText: string;
|
|
45
|
-
data: PetApiData;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
let searchIndex: SearchIndex[] | null = null;
|
|
49
|
-
let apiDataCache: Record<string, PetApiData> | null = null;
|
|
50
|
-
|
|
51
|
-
async function fetchApiData(): Promise<Record<string, PetApiData>> {
|
|
52
|
-
if (apiDataCache) return apiDataCache;
|
|
53
|
-
|
|
54
|
-
if (isDevMode()) {
|
|
55
|
-
try {
|
|
56
|
-
const localApiData = await import("../../data/api.json");
|
|
57
|
-
apiDataCache = localApiData.default as Record<string, PetApiData>;
|
|
58
|
-
return apiDataCache;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.warn("Failed to load local api.json, falling back to remote:", error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
const response = await fetch(REMOTE_API_URL);
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
throw new Error(`Failed to fetch API data: ${response.status} ${response.statusText}`);
|
|
68
|
-
}
|
|
69
|
-
apiDataCache = await response.json();
|
|
70
|
-
return apiDataCache!;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.error("Failed to fetch remote API data:", error);
|
|
73
|
-
|
|
74
|
-
if (!isDevMode()) {
|
|
75
|
-
try {
|
|
76
|
-
const localApiData = await import("../../data/api.json");
|
|
77
|
-
console.warn("Using local api.json as fallback");
|
|
78
|
-
apiDataCache = localApiData.default as Record<string, PetApiData>;
|
|
79
|
-
return apiDataCache;
|
|
80
|
-
} catch (fallbackError) {
|
|
81
|
-
console.error("Failed to load local api.json as fallback:", fallbackError);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
throw new Error("Unable to load API data from remote or local sources");
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function buildSearchIndex(): Promise<SearchIndex[]> {
|
|
90
|
-
if (searchIndex) return searchIndex;
|
|
91
|
-
|
|
92
|
-
const apiData = await fetchApiData();
|
|
93
|
-
|
|
94
|
-
searchIndex = Object.entries(apiData).map(
|
|
95
|
-
([petId, petData]) => {
|
|
96
|
-
const toolsText = petData.tools
|
|
97
|
-
? petData.tools
|
|
98
|
-
.map((t) => `${t.name} ${t.description}`)
|
|
99
|
-
.join(" ")
|
|
100
|
-
.toLowerCase()
|
|
101
|
-
: "";
|
|
102
|
-
|
|
103
|
-
const queriesText = petData.queries
|
|
104
|
-
? petData.queries.join(" ").toLowerCase()
|
|
105
|
-
: "";
|
|
106
|
-
|
|
107
|
-
const scenariosText = petData.scenarios
|
|
108
|
-
? Object.values(petData.scenarios).flat().join(" ").toLowerCase()
|
|
109
|
-
: "";
|
|
110
|
-
|
|
111
|
-
const shortId = petId.replace("openpets/", "");
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
id: shortId,
|
|
115
|
-
nameLower: petData.name.toLowerCase(),
|
|
116
|
-
descLower: petData.description.toLowerCase(),
|
|
117
|
-
keywordsLower: petData.keywords?.map((k) => k.toLowerCase()) || [],
|
|
118
|
-
toolsText,
|
|
119
|
-
queriesText,
|
|
120
|
-
scenariosText,
|
|
121
|
-
data: petData,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
return searchIndex;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function calculateScore(
|
|
130
|
-
searchTerm: string,
|
|
131
|
-
index: SearchIndex
|
|
132
|
-
): { score: number; fields: string[] } | null {
|
|
133
|
-
const fields: string[] = [];
|
|
134
|
-
let maxScore = 0;
|
|
135
|
-
|
|
136
|
-
if (index.nameLower.includes(searchTerm)) {
|
|
137
|
-
const isExact = index.nameLower === searchTerm;
|
|
138
|
-
const startsWithSearch = index.nameLower.startsWith(searchTerm);
|
|
139
|
-
fields.push("name");
|
|
140
|
-
maxScore = isExact ? 100 : startsWithSearch ? 95 : 85;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (index.keywordsLower.some((k) => k.includes(searchTerm))) {
|
|
144
|
-
fields.push("keywords");
|
|
145
|
-
maxScore = Math.max(maxScore, 90);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (index.descLower.includes(searchTerm)) {
|
|
149
|
-
fields.push("description");
|
|
150
|
-
maxScore = Math.max(maxScore, 75);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (index.toolsText && index.toolsText.includes(searchTerm)) {
|
|
154
|
-
fields.push("tools");
|
|
155
|
-
maxScore = Math.max(maxScore, 70);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (index.queriesText && index.queriesText.includes(searchTerm)) {
|
|
159
|
-
fields.push("queries");
|
|
160
|
-
maxScore = Math.max(maxScore, 60);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (index.scenariosText && index.scenariosText.includes(searchTerm)) {
|
|
164
|
-
fields.push("scenarios");
|
|
165
|
-
maxScore = Math.max(maxScore, 50);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return fields.length > 0 ? { score: maxScore, fields } : null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export async function searchPets(query: string): Promise<SearchResult[]> {
|
|
172
|
-
if (!query || query.trim().length === 0) {
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const searchTerm = query.toLowerCase().trim();
|
|
177
|
-
const searchTerms = searchTerm.split(/\s+/).filter((t) => t.length > 0);
|
|
178
|
-
const index = await buildSearchIndex();
|
|
179
|
-
const results: SearchResult[] = [];
|
|
180
|
-
|
|
181
|
-
for (const item of index) {
|
|
182
|
-
let bestMatch: { score: number; fields: string[] } | null = null;
|
|
183
|
-
|
|
184
|
-
if (searchTerms.length === 1) {
|
|
185
|
-
bestMatch = calculateScore(searchTerm, item);
|
|
186
|
-
} else {
|
|
187
|
-
const matches = searchTerms
|
|
188
|
-
.map((term) => calculateScore(term, item))
|
|
189
|
-
.filter(Boolean);
|
|
190
|
-
|
|
191
|
-
if (matches.length === searchTerms.length) {
|
|
192
|
-
const allFields = new Set<string>();
|
|
193
|
-
let totalScore = 0;
|
|
194
|
-
|
|
195
|
-
matches.forEach((m) => {
|
|
196
|
-
if (m) {
|
|
197
|
-
m.fields.forEach((f) => allFields.add(f));
|
|
198
|
-
totalScore += m.score;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
bestMatch = {
|
|
203
|
-
score: Math.min(100, Math.floor(totalScore / searchTerms.length)),
|
|
204
|
-
fields: Array.from(allFields),
|
|
205
|
-
};
|
|
206
|
-
} else if (matches.length > 0) {
|
|
207
|
-
const allFields = new Set<string>();
|
|
208
|
-
let maxScore = 0;
|
|
209
|
-
|
|
210
|
-
matches.forEach((m) => {
|
|
211
|
-
if (m) {
|
|
212
|
-
m.fields.forEach((f) => allFields.add(f));
|
|
213
|
-
maxScore = Math.max(maxScore, m.score);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
bestMatch = {
|
|
218
|
-
score: Math.floor(maxScore * 0.7),
|
|
219
|
-
fields: Array.from(allFields),
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (bestMatch) {
|
|
225
|
-
results.push({
|
|
226
|
-
id: item.id,
|
|
227
|
-
name: item.data.name,
|
|
228
|
-
description: item.data.description,
|
|
229
|
-
keywords: item.data.keywords || [],
|
|
230
|
-
matchReason: `Matched in: ${bestMatch.fields.join(", ")}`,
|
|
231
|
-
matchScore: bestMatch.score,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return results.sort((a, b) => b.matchScore - a.matchScore);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export function clearSearchCache(): void {
|
|
240
|
-
searchIndex = null;
|
|
241
|
-
apiDataCache = null;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function createPetFromApiData(petId: string, petData: PetApiData): Pet {
|
|
245
|
-
const shortId = petId.replace("openpets/", "");
|
|
246
|
-
const { tools, ...restData } = petData;
|
|
247
|
-
return {
|
|
248
|
-
id: shortId,
|
|
249
|
-
...restData,
|
|
250
|
-
displayName: petData.title,
|
|
251
|
-
version: petData.version || "1.0.0",
|
|
252
|
-
source_code_url: petData.source_code_url || `https://github.com/raggle-ai/pets/tree/main/pets/${shortId}`,
|
|
253
|
-
queriesCount: petData.queries?.length || 0,
|
|
254
|
-
queries: petData.queries || [],
|
|
255
|
-
keywords: petData.keywords || [],
|
|
256
|
-
tools: tools?.map(t => ({ ...t, schema: {} })),
|
|
257
|
-
enabled: false,
|
|
258
|
-
opencodeJsonPath: "",
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export async function getAllPets(): Promise<Pet[]> {
|
|
263
|
-
const apiData = await fetchApiData();
|
|
264
|
-
return Object.entries(apiData).map(
|
|
265
|
-
([petId, petData]) => createPetFromApiData(petId, petData)
|
|
266
|
-
);
|
|
267
|
-
}
|
package/types.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
export interface EnvVariable {
|
|
2
|
-
name: string
|
|
3
|
-
description: string
|
|
4
|
-
provider: string
|
|
5
|
-
priority: number
|
|
6
|
-
url?: string
|
|
7
|
-
setupUrl?: string
|
|
8
|
-
default?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface Provider {
|
|
12
|
-
name: string
|
|
13
|
-
description: string
|
|
14
|
-
priority: number
|
|
15
|
-
homepage?: string
|
|
16
|
-
envVariables?: EnvVariable[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface EnvVariables {
|
|
20
|
-
required?: EnvVariable[]
|
|
21
|
-
optional?: EnvVariable[]
|
|
22
|
-
note?: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface PetData {
|
|
26
|
-
name: string
|
|
27
|
-
description: string
|
|
28
|
-
keywords: string[]
|
|
29
|
-
source_code_url: string
|
|
30
|
-
homepage?: string
|
|
31
|
-
icon?: string
|
|
32
|
-
envVariables?: EnvVariables
|
|
33
|
-
queries: string[]
|
|
34
|
-
scenarios?: Record<string, string | string[]>
|
|
35
|
-
providers?: Provider[]
|
|
36
|
-
connected_pets?: string[]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface Tool {
|
|
40
|
-
name: string
|
|
41
|
-
description: string
|
|
42
|
-
schema: Record<string, any>
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface Pet {
|
|
46
|
-
id: string
|
|
47
|
-
name: string
|
|
48
|
-
displayName: string
|
|
49
|
-
description: string
|
|
50
|
-
keywords: string[]
|
|
51
|
-
source_code_url: string
|
|
52
|
-
version: string
|
|
53
|
-
icon?: string
|
|
54
|
-
homepage?: string
|
|
55
|
-
envVariables?: EnvVariables
|
|
56
|
-
queries: string[]
|
|
57
|
-
queriesCount: number
|
|
58
|
-
tools?: Tool[]
|
|
59
|
-
scenarios?: Record<string, string | string[]>
|
|
60
|
-
providers?: Provider[]
|
|
61
|
-
connected_pets?: string[]
|
|
62
|
-
enabled: boolean
|
|
63
|
-
opencodeJsonPath: string
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface PetRegistry {
|
|
67
|
-
[key: string]: PetData
|
|
68
|
-
}
|