@decantr/registry 1.0.0-beta.8 → 1.0.0
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/README.md +56 -0
- package/dist/client.d.ts +115 -0
- package/dist/client.js +540 -0
- package/dist/client.js.map +1 -0
- package/dist/content-types-BJFuxWNj.d.ts +886 -0
- package/dist/content-types.d.ts +2 -0
- package/dist/content-types.js +44 -0
- package/dist/content-types.js.map +1 -0
- package/dist/index.d.ts +7 -289
- package/dist/index.js +384 -12
- package/dist/index.js.map +1 -1
- package/package.json +36 -11
- package/schema/archetype.v2.json +118 -0
- package/schema/blueprint.v1.json +166 -0
- package/schema/common.v1.json +271 -0
- package/schema/content-intelligence.v1.json +142 -0
- package/schema/pattern.v2.json +149 -0
- package/schema/public-content-list.v1.json +28 -0
- package/schema/public-content-record.v1.json +91 -0
- package/schema/public-content-summary.v1.json +67 -0
- package/schema/registry-intelligence-summary.v1.json +81 -0
- package/schema/search-response.v1.json +28 -0
- package/schema/shell.v1.json +69 -0
- package/schema/showcase-manifest-entry.v1.json +63 -0
- package/schema/showcase-manifest.v1.json +28 -0
- package/schema/showcase-shortlist.v1.json +36 -0
- package/schema/theme.v1.json +190 -0
- package/LICENSE +0 -21
package/dist/client.js
ADDED
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var CONTENT_TYPES = [
|
|
3
|
+
"pattern",
|
|
4
|
+
"theme",
|
|
5
|
+
"blueprint",
|
|
6
|
+
"archetype",
|
|
7
|
+
"shell"
|
|
8
|
+
];
|
|
9
|
+
var API_CONTENT_TYPES = [
|
|
10
|
+
"patterns",
|
|
11
|
+
"themes",
|
|
12
|
+
"blueprints",
|
|
13
|
+
"archetypes",
|
|
14
|
+
"shells"
|
|
15
|
+
];
|
|
16
|
+
var CONTENT_TYPE_TO_API_CONTENT_TYPE = {
|
|
17
|
+
pattern: "patterns",
|
|
18
|
+
theme: "themes",
|
|
19
|
+
blueprint: "blueprints",
|
|
20
|
+
archetype: "archetypes",
|
|
21
|
+
shell: "shells"
|
|
22
|
+
};
|
|
23
|
+
var API_CONTENT_TYPE_TO_CONTENT_TYPE = {
|
|
24
|
+
patterns: "pattern",
|
|
25
|
+
themes: "theme",
|
|
26
|
+
blueprints: "blueprint",
|
|
27
|
+
archetypes: "archetype",
|
|
28
|
+
shells: "shell"
|
|
29
|
+
};
|
|
30
|
+
function isContentType(value) {
|
|
31
|
+
return CONTENT_TYPES.includes(value);
|
|
32
|
+
}
|
|
33
|
+
function isApiContentType(value) {
|
|
34
|
+
return API_CONTENT_TYPES.includes(value);
|
|
35
|
+
}
|
|
36
|
+
var PUBLIC_CONTENT_SOURCES = [
|
|
37
|
+
"official",
|
|
38
|
+
"community",
|
|
39
|
+
"organization"
|
|
40
|
+
];
|
|
41
|
+
function isPublicContentSource(value) {
|
|
42
|
+
return PUBLIC_CONTENT_SOURCES.includes(value);
|
|
43
|
+
}
|
|
44
|
+
var CONTENT_INTELLIGENCE_SOURCES = [
|
|
45
|
+
"authored",
|
|
46
|
+
"benchmark",
|
|
47
|
+
"hybrid"
|
|
48
|
+
];
|
|
49
|
+
function isContentIntelligenceSource(value) {
|
|
50
|
+
return CONTENT_INTELLIGENCE_SOURCES.includes(value);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/api-client.ts
|
|
54
|
+
var DEFAULT_BASE_URL = "https://api.decantr.ai/v1";
|
|
55
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
56
|
+
var DEFAULT_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
57
|
+
function unwrapDataEnvelope(value) {
|
|
58
|
+
if (typeof value === "object" && value !== null && "data" in value) {
|
|
59
|
+
return value.data;
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
var RegistryAPIError = class extends Error {
|
|
64
|
+
status;
|
|
65
|
+
details;
|
|
66
|
+
constructor(status, message, details) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = "RegistryAPIError";
|
|
69
|
+
this.status = status;
|
|
70
|
+
this.details = details;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
function isRecord(value) {
|
|
74
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
|
+
}
|
|
76
|
+
var RegistryAPIClient = class {
|
|
77
|
+
baseUrl;
|
|
78
|
+
apiKey;
|
|
79
|
+
accessToken;
|
|
80
|
+
timeoutMs;
|
|
81
|
+
cacheTtlMs;
|
|
82
|
+
cache = /* @__PURE__ */ new Map();
|
|
83
|
+
constructor(options = {}) {
|
|
84
|
+
this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
85
|
+
this.apiKey = options.apiKey;
|
|
86
|
+
this.accessToken = options.accessToken;
|
|
87
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
88
|
+
this.cacheTtlMs = options.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
|
|
89
|
+
}
|
|
90
|
+
// ── HTTP helpers ──
|
|
91
|
+
buildHeaders() {
|
|
92
|
+
const headers = {
|
|
93
|
+
"Accept": "application/json"
|
|
94
|
+
};
|
|
95
|
+
if (this.apiKey) {
|
|
96
|
+
headers["X-API-Key"] = this.apiKey;
|
|
97
|
+
}
|
|
98
|
+
if (this.accessToken) {
|
|
99
|
+
headers["Authorization"] = `Bearer ${this.accessToken}`;
|
|
100
|
+
}
|
|
101
|
+
return headers;
|
|
102
|
+
}
|
|
103
|
+
async fetchWithTimeout(url, init) {
|
|
104
|
+
const controller = new AbortController();
|
|
105
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
106
|
+
try {
|
|
107
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
108
|
+
} finally {
|
|
109
|
+
clearTimeout(timeout);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async request(path, init) {
|
|
113
|
+
const url = `${this.baseUrl}${path}`;
|
|
114
|
+
const response = await this.fetchWithTimeout(url, {
|
|
115
|
+
...init,
|
|
116
|
+
headers: { ...this.buildHeaders(), ...init?.headers }
|
|
117
|
+
});
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
const bodyText = await response.text().catch(() => "");
|
|
120
|
+
let details;
|
|
121
|
+
let message = response.statusText;
|
|
122
|
+
if (bodyText) {
|
|
123
|
+
try {
|
|
124
|
+
details = JSON.parse(bodyText);
|
|
125
|
+
if (isRecord(details) && typeof details.error === "string") {
|
|
126
|
+
message = details.error;
|
|
127
|
+
} else {
|
|
128
|
+
message = bodyText;
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
message = bodyText;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
throw new RegistryAPIError(response.status, `API ${response.status}: ${message}`, details);
|
|
135
|
+
}
|
|
136
|
+
return response.json();
|
|
137
|
+
}
|
|
138
|
+
// ── Cache helpers ──
|
|
139
|
+
getCached(key) {
|
|
140
|
+
const entry = this.cache.get(key);
|
|
141
|
+
if (!entry) return null;
|
|
142
|
+
if (Date.now() - entry.timestamp > this.cacheTtlMs) {
|
|
143
|
+
this.cache.delete(key);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return entry.data;
|
|
147
|
+
}
|
|
148
|
+
setCache(key, data) {
|
|
149
|
+
this.cache.set(key, { data, timestamp: Date.now() });
|
|
150
|
+
}
|
|
151
|
+
clearCache() {
|
|
152
|
+
this.cache.clear();
|
|
153
|
+
}
|
|
154
|
+
// ── Health ──
|
|
155
|
+
async checkHealth() {
|
|
156
|
+
try {
|
|
157
|
+
const url = this.baseUrl.replace(/\/v1$/, "/health");
|
|
158
|
+
const response = await this.fetchWithTimeout(url);
|
|
159
|
+
return response.ok;
|
|
160
|
+
} catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// ── Content fetching (public) ──
|
|
165
|
+
async listContent(type, params) {
|
|
166
|
+
const cacheKey = `list:${type}:${JSON.stringify(params ?? {})}`;
|
|
167
|
+
const cached = this.getCached(cacheKey);
|
|
168
|
+
if (cached) return cached;
|
|
169
|
+
const searchParams = new URLSearchParams();
|
|
170
|
+
if (params?.namespace) searchParams.set("namespace", params.namespace);
|
|
171
|
+
if (params?.source) searchParams.set("source", params.source);
|
|
172
|
+
if (params?.sort) searchParams.set("sort", params.sort);
|
|
173
|
+
if (params?.recommended) searchParams.set("recommended", "true");
|
|
174
|
+
if (params?.intelligenceSource) searchParams.set("intelligence_source", params.intelligenceSource);
|
|
175
|
+
if (params?.limit) searchParams.set("limit", String(params.limit));
|
|
176
|
+
if (params?.offset) searchParams.set("offset", String(params.offset));
|
|
177
|
+
const query = searchParams.toString();
|
|
178
|
+
const path = `/${type}${query ? `?${query}` : ""}`;
|
|
179
|
+
const result = await this.request(path);
|
|
180
|
+
this.setCache(cacheKey, result);
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
async getContent(type, namespace, slug) {
|
|
184
|
+
const cacheKey = `get:${type}:${namespace}:${slug}`;
|
|
185
|
+
const cached = this.getCached(cacheKey);
|
|
186
|
+
if (cached) return cached;
|
|
187
|
+
const raw = await this.request(`/${type}/${namespace}/${slug}`);
|
|
188
|
+
const unwrapped = unwrapDataEnvelope(raw);
|
|
189
|
+
this.setCache(cacheKey, unwrapped);
|
|
190
|
+
return unwrapped;
|
|
191
|
+
}
|
|
192
|
+
async getPublicContentRecord(type, namespace, slug) {
|
|
193
|
+
const cacheKey = `public-record:${type}:${namespace}:${slug}`;
|
|
194
|
+
const cached = this.getCached(cacheKey);
|
|
195
|
+
if (cached) return cached;
|
|
196
|
+
const result = await this.request(`/${type}/${namespace}/${slug}`);
|
|
197
|
+
this.setCache(cacheKey, result);
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
async getContentRecord(type, namespace, slug) {
|
|
201
|
+
const cacheKey = `content-record:${type}:${namespace}:${slug}:${this.apiKey ?? ""}:${this.accessToken ?? ""}`;
|
|
202
|
+
const cached = this.getCached(cacheKey);
|
|
203
|
+
if (cached) return cached;
|
|
204
|
+
const result = await this.request(`/${type}/${namespace}/${slug}`);
|
|
205
|
+
this.setCache(cacheKey, result);
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
// ── Typed convenience methods ──
|
|
209
|
+
async getPattern(namespace, slug) {
|
|
210
|
+
return this.getContent("patterns", namespace, slug);
|
|
211
|
+
}
|
|
212
|
+
async getArchetype(namespace, slug) {
|
|
213
|
+
return this.getContent("archetypes", namespace, slug);
|
|
214
|
+
}
|
|
215
|
+
async getTheme(namespace, slug) {
|
|
216
|
+
return this.getContent("themes", namespace, slug);
|
|
217
|
+
}
|
|
218
|
+
async getBlueprint(namespace, slug) {
|
|
219
|
+
return this.getContent("blueprints", namespace, slug);
|
|
220
|
+
}
|
|
221
|
+
async getShell(namespace, slug) {
|
|
222
|
+
return this.getContent("shells", namespace, slug);
|
|
223
|
+
}
|
|
224
|
+
// ── Search ──
|
|
225
|
+
async search(params) {
|
|
226
|
+
const searchParams = new URLSearchParams({ q: params.q });
|
|
227
|
+
if (params.type) searchParams.set("type", params.type);
|
|
228
|
+
if (params.namespace) searchParams.set("namespace", params.namespace);
|
|
229
|
+
if (params.source) searchParams.set("source", params.source);
|
|
230
|
+
if (params.sort) searchParams.set("sort", params.sort);
|
|
231
|
+
if (params.recommended) searchParams.set("recommended", "true");
|
|
232
|
+
if (params.intelligenceSource) searchParams.set("intelligence_source", params.intelligenceSource);
|
|
233
|
+
if (params.limit) searchParams.set("limit", String(params.limit));
|
|
234
|
+
if (params.offset) searchParams.set("offset", String(params.offset));
|
|
235
|
+
return this.request(`/search?${searchParams}`);
|
|
236
|
+
}
|
|
237
|
+
async getPublicUserProfile(username) {
|
|
238
|
+
const cacheKey = `public-user:${username}`;
|
|
239
|
+
const cached = this.getCached(cacheKey);
|
|
240
|
+
if (cached) return cached;
|
|
241
|
+
const result = await this.request(`/users/${encodeURIComponent(username)}`);
|
|
242
|
+
this.setCache(cacheKey, result);
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
async getPublicUserContent(username, params) {
|
|
246
|
+
const cacheKey = `public-user-content:${username}:${JSON.stringify(params ?? {})}`;
|
|
247
|
+
const cached = this.getCached(cacheKey);
|
|
248
|
+
if (cached) return cached;
|
|
249
|
+
const searchParams = new URLSearchParams();
|
|
250
|
+
if (params?.type) searchParams.set("type", params.type);
|
|
251
|
+
if (params?.source) searchParams.set("source", params.source);
|
|
252
|
+
if (params?.sort) searchParams.set("sort", params.sort);
|
|
253
|
+
if (params?.recommended) searchParams.set("recommended", "true");
|
|
254
|
+
if (params?.intelligenceSource) searchParams.set("intelligence_source", params.intelligenceSource);
|
|
255
|
+
if (params?.limit != null) searchParams.set("limit", String(params.limit));
|
|
256
|
+
if (params?.offset != null) searchParams.set("offset", String(params.offset));
|
|
257
|
+
const query = searchParams.toString();
|
|
258
|
+
const result = await this.request(
|
|
259
|
+
`/users/${encodeURIComponent(username)}/content${query ? `?${query}` : ""}`
|
|
260
|
+
);
|
|
261
|
+
this.setCache(cacheKey, result);
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
// ── Authenticated endpoints ──
|
|
265
|
+
async getProfile() {
|
|
266
|
+
return this.request("/me");
|
|
267
|
+
}
|
|
268
|
+
async publishContent(payload) {
|
|
269
|
+
return this.request("/content", {
|
|
270
|
+
method: "POST",
|
|
271
|
+
headers: { "Content-Type": "application/json" },
|
|
272
|
+
body: JSON.stringify(payload)
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
async getMyContent() {
|
|
276
|
+
return this.request("/my/content");
|
|
277
|
+
}
|
|
278
|
+
async getAccessiblePrivateContent(params) {
|
|
279
|
+
const searchParams = new URLSearchParams();
|
|
280
|
+
if (params?.type) searchParams.set("type", params.type);
|
|
281
|
+
if (params?.scope) searchParams.set("scope", params.scope);
|
|
282
|
+
if (params?.q) searchParams.set("q", params.q);
|
|
283
|
+
if (params?.limit != null) searchParams.set("limit", String(params.limit));
|
|
284
|
+
if (params?.offset != null) searchParams.set("offset", String(params.offset));
|
|
285
|
+
const query = searchParams.toString();
|
|
286
|
+
return this.request(
|
|
287
|
+
`/private/content${query ? `?${query}` : ""}`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
// ── Schema ──
|
|
291
|
+
async getSchema(name = "essence.v3.json") {
|
|
292
|
+
return this.request(`/schema/${name}`);
|
|
293
|
+
}
|
|
294
|
+
// ── Showcase benchmarks ──
|
|
295
|
+
async getShowcaseManifest() {
|
|
296
|
+
const cacheKey = "showcase:manifest";
|
|
297
|
+
const cached = this.getCached(cacheKey);
|
|
298
|
+
if (cached) return cached;
|
|
299
|
+
const result = await this.request("/showcase/manifest");
|
|
300
|
+
this.setCache(cacheKey, result);
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
async getShowcaseShortlist() {
|
|
304
|
+
const cacheKey = "showcase:shortlist";
|
|
305
|
+
const cached = this.getCached(cacheKey);
|
|
306
|
+
if (cached) return cached;
|
|
307
|
+
const result = await this.request("/showcase/shortlist");
|
|
308
|
+
this.setCache(cacheKey, result);
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
async getShowcaseShortlistVerification() {
|
|
312
|
+
const cacheKey = "showcase:shortlist-verification";
|
|
313
|
+
const cached = this.getCached(cacheKey);
|
|
314
|
+
if (cached) return cached;
|
|
315
|
+
const result = await this.request("/showcase/shortlist-verification");
|
|
316
|
+
this.setCache(cacheKey, result);
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
async getRegistryIntelligenceSummary(params) {
|
|
320
|
+
const cacheKey = `registry-intelligence-summary:${JSON.stringify(params ?? {})}`;
|
|
321
|
+
const cached = this.getCached(cacheKey);
|
|
322
|
+
if (cached) return cached;
|
|
323
|
+
const searchParams = new URLSearchParams();
|
|
324
|
+
if (params?.namespace) searchParams.set("namespace", params.namespace);
|
|
325
|
+
const query = searchParams.toString();
|
|
326
|
+
const result = await this.request(
|
|
327
|
+
`/intelligence/summary${query ? `?${query}` : ""}`
|
|
328
|
+
);
|
|
329
|
+
this.setCache(cacheKey, result);
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
async compileExecutionPacks(essence, params) {
|
|
333
|
+
const searchParams = new URLSearchParams();
|
|
334
|
+
if (params?.namespace) searchParams.set("namespace", params.namespace);
|
|
335
|
+
const query = searchParams.toString();
|
|
336
|
+
return this.request(
|
|
337
|
+
`/packs/compile${query ? `?${query}` : ""}`,
|
|
338
|
+
{
|
|
339
|
+
method: "POST",
|
|
340
|
+
headers: { "Content-Type": "application/json" },
|
|
341
|
+
body: JSON.stringify(essence)
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
async selectExecutionPack(input, params) {
|
|
346
|
+
const searchParams = new URLSearchParams();
|
|
347
|
+
if (params?.namespace) searchParams.set("namespace", params.namespace);
|
|
348
|
+
const query = searchParams.toString();
|
|
349
|
+
return this.request(
|
|
350
|
+
`/packs/select${query ? `?${query}` : ""}`,
|
|
351
|
+
{
|
|
352
|
+
method: "POST",
|
|
353
|
+
headers: { "Content-Type": "application/json" },
|
|
354
|
+
body: JSON.stringify(input)
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
async getExecutionPackManifest(essence, params) {
|
|
359
|
+
const selected = await this.selectExecutionPack(
|
|
360
|
+
{
|
|
361
|
+
essence,
|
|
362
|
+
pack_type: "scaffold"
|
|
363
|
+
},
|
|
364
|
+
params
|
|
365
|
+
);
|
|
366
|
+
return selected.manifest;
|
|
367
|
+
}
|
|
368
|
+
async critiqueFile(input, params) {
|
|
369
|
+
const searchParams = new URLSearchParams();
|
|
370
|
+
if (params?.namespace) searchParams.set("namespace", params.namespace);
|
|
371
|
+
const query = searchParams.toString();
|
|
372
|
+
return this.request(
|
|
373
|
+
`/critique/file${query ? `?${query}` : ""}`,
|
|
374
|
+
{
|
|
375
|
+
method: "POST",
|
|
376
|
+
headers: { "Content-Type": "application/json" },
|
|
377
|
+
body: JSON.stringify(input)
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
async auditProject(input, params) {
|
|
382
|
+
const searchParams = new URLSearchParams();
|
|
383
|
+
if (params?.namespace) searchParams.set("namespace", params.namespace);
|
|
384
|
+
const query = searchParams.toString();
|
|
385
|
+
return this.request(
|
|
386
|
+
`/audit/project${query ? `?${query}` : ""}`,
|
|
387
|
+
{
|
|
388
|
+
method: "POST",
|
|
389
|
+
headers: { "Content-Type": "application/json" },
|
|
390
|
+
body: JSON.stringify(input)
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
function createRegistryClient(options = {}) {
|
|
396
|
+
const baseUrl = options.baseUrl ?? "https://api.decantr.ai/v1";
|
|
397
|
+
return {
|
|
398
|
+
async search(query, type) {
|
|
399
|
+
const params = new URLSearchParams({ q: query });
|
|
400
|
+
if (type) params.set("type", type);
|
|
401
|
+
const res = await fetch(`${baseUrl}/search?${params}`);
|
|
402
|
+
if (!res.ok) return [];
|
|
403
|
+
const data = await res.json();
|
|
404
|
+
if (Array.isArray(data)) return data;
|
|
405
|
+
return data.results ?? [];
|
|
406
|
+
},
|
|
407
|
+
async fetch(type, id, version) {
|
|
408
|
+
const url = version ? `${baseUrl}/content/${type}/${id}/${version}` : `${baseUrl}/content/${type}/${id}`;
|
|
409
|
+
const res = await fetch(url);
|
|
410
|
+
if (!res.ok) return null;
|
|
411
|
+
return res.json();
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/ranking.ts
|
|
417
|
+
function verificationScore(status) {
|
|
418
|
+
switch (status) {
|
|
419
|
+
case "smoke-green":
|
|
420
|
+
return 200;
|
|
421
|
+
case "build-green":
|
|
422
|
+
return 120;
|
|
423
|
+
case "pending":
|
|
424
|
+
return 20;
|
|
425
|
+
case "smoke-red":
|
|
426
|
+
case "build-red":
|
|
427
|
+
return -40;
|
|
428
|
+
default:
|
|
429
|
+
return 0;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function confidenceScore(level) {
|
|
433
|
+
switch (level) {
|
|
434
|
+
case "high":
|
|
435
|
+
return 120;
|
|
436
|
+
case "medium":
|
|
437
|
+
return 70;
|
|
438
|
+
case "low":
|
|
439
|
+
return 30;
|
|
440
|
+
default:
|
|
441
|
+
return 0;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function confidenceTierScore(tier) {
|
|
445
|
+
switch (tier) {
|
|
446
|
+
case "verified":
|
|
447
|
+
return 180;
|
|
448
|
+
case "high":
|
|
449
|
+
return 120;
|
|
450
|
+
case "medium":
|
|
451
|
+
return 60;
|
|
452
|
+
case "low":
|
|
453
|
+
return 10;
|
|
454
|
+
default:
|
|
455
|
+
return 0;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function getRecommendedPriority(item) {
|
|
459
|
+
const intelligence = item.intelligence;
|
|
460
|
+
let score = 0;
|
|
461
|
+
if (!intelligence) {
|
|
462
|
+
return score;
|
|
463
|
+
}
|
|
464
|
+
if (intelligence.recommended) {
|
|
465
|
+
score += 500;
|
|
466
|
+
}
|
|
467
|
+
if (intelligence.golden_usage === "shortlisted") {
|
|
468
|
+
score += 160;
|
|
469
|
+
} else if (intelligence.golden_usage === "showcase") {
|
|
470
|
+
score += 80;
|
|
471
|
+
}
|
|
472
|
+
score += verificationScore(intelligence.verification_status);
|
|
473
|
+
score += confidenceScore(intelligence.benchmark_confidence);
|
|
474
|
+
score += confidenceTierScore(intelligence.confidence_tier);
|
|
475
|
+
score += Math.round((intelligence.confidence_score ?? 0) / 2);
|
|
476
|
+
score += intelligence.quality_score ?? 0;
|
|
477
|
+
return score;
|
|
478
|
+
}
|
|
479
|
+
function normalizePublicContentSort(value) {
|
|
480
|
+
switch (value) {
|
|
481
|
+
case "popular":
|
|
482
|
+
case "recommended":
|
|
483
|
+
return "recommended";
|
|
484
|
+
case "newest":
|
|
485
|
+
case "recent":
|
|
486
|
+
case "published":
|
|
487
|
+
return "recent";
|
|
488
|
+
case "name":
|
|
489
|
+
return "name";
|
|
490
|
+
default:
|
|
491
|
+
return "recommended";
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function comparePublicContent(a, b, sort = "recommended") {
|
|
495
|
+
if (sort === "name") {
|
|
496
|
+
return (a.name ?? a.slug).localeCompare(b.name ?? b.slug);
|
|
497
|
+
}
|
|
498
|
+
if (sort === "recent") {
|
|
499
|
+
const publishedDelta2 = new Date(b.published_at ?? 0).getTime() - new Date(a.published_at ?? 0).getTime();
|
|
500
|
+
if (publishedDelta2 !== 0) {
|
|
501
|
+
return publishedDelta2;
|
|
502
|
+
}
|
|
503
|
+
return a.slug.localeCompare(b.slug);
|
|
504
|
+
}
|
|
505
|
+
const priorityDelta = getRecommendedPriority(b) - getRecommendedPriority(a);
|
|
506
|
+
if (priorityDelta !== 0) {
|
|
507
|
+
return priorityDelta;
|
|
508
|
+
}
|
|
509
|
+
if (a.namespace !== b.namespace) {
|
|
510
|
+
if (a.namespace === "@official") return -1;
|
|
511
|
+
if (b.namespace === "@official") return 1;
|
|
512
|
+
}
|
|
513
|
+
const publishedDelta = new Date(b.published_at ?? 0).getTime() - new Date(a.published_at ?? 0).getTime();
|
|
514
|
+
if (publishedDelta !== 0) {
|
|
515
|
+
return publishedDelta;
|
|
516
|
+
}
|
|
517
|
+
return (a.name ?? a.slug).localeCompare(b.name ?? b.slug);
|
|
518
|
+
}
|
|
519
|
+
function sortPublicContent(items, sort = "recommended") {
|
|
520
|
+
return [...items].sort((left, right) => comparePublicContent(left, right, sort));
|
|
521
|
+
}
|
|
522
|
+
export {
|
|
523
|
+
API_CONTENT_TYPES,
|
|
524
|
+
API_CONTENT_TYPE_TO_CONTENT_TYPE,
|
|
525
|
+
CONTENT_INTELLIGENCE_SOURCES,
|
|
526
|
+
CONTENT_TYPES,
|
|
527
|
+
CONTENT_TYPE_TO_API_CONTENT_TYPE,
|
|
528
|
+
PUBLIC_CONTENT_SOURCES,
|
|
529
|
+
RegistryAPIClient,
|
|
530
|
+
RegistryAPIError,
|
|
531
|
+
comparePublicContent,
|
|
532
|
+
createRegistryClient,
|
|
533
|
+
isApiContentType,
|
|
534
|
+
isContentIntelligenceSource,
|
|
535
|
+
isContentType,
|
|
536
|
+
isPublicContentSource,
|
|
537
|
+
normalizePublicContentSort,
|
|
538
|
+
sortPublicContent
|
|
539
|
+
};
|
|
540
|
+
//# sourceMappingURL=client.js.map
|