@johnhenry/browsermesh-apps 0.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/LICENSE +21 -0
- package/README.md +63 -0
- package/package.json +36 -0
- package/src/apps.mjs +1351 -0
- package/src/audit.mjs +622 -0
- package/src/chat.mjs +595 -0
- package/src/compat.mjs +30 -0
- package/src/consensus.mjs +784 -0
- package/src/devtools.mjs +255 -0
- package/src/gpu.mjs +732 -0
- package/src/index.mjs +44 -0
- package/src/marketplace-ui.mjs +245 -0
- package/src/marketplace.mjs +754 -0
- package/src/orchestrator.mjs +1575 -0
- package/src/payments.mjs +909 -0
- package/src/peer-agent-swarm.mjs +569 -0
- package/src/peer-agent.mjs +547 -0
- package/src/peer-chat.mjs +381 -0
- package/src/peer-compute.mjs +687 -0
- package/src/peer-encrypted-store.mjs +514 -0
- package/src/peer-escrow.mjs +573 -0
- package/src/peer-files.mjs +470 -0
- package/src/peer-health.mjs +727 -0
- package/src/peer-ipfs.mjs +374 -0
- package/src/peer-node.mjs +793 -0
- package/src/peer-payments.mjs +613 -0
- package/src/peer-registry.mjs +595 -0
- package/src/peer-routing.mjs +555 -0
- package/src/peer-services.mjs +478 -0
- package/src/peer-session.mjs +917 -0
- package/src/peer-terminal.mjs +500 -0
- package/src/peer-timestamp.mjs +403 -0
- package/src/peer-torrent.mjs +628 -0
- package/src/peer-verification.mjs +522 -0
- package/src/quotas.mjs +621 -0
- package/src/resources.mjs +679 -0
- package/src/scheduler.mjs +846 -0
- package/src/silent-catch.mjs +55 -0
- package/src/tools.mjs +668 -0
- package/src/visualizations.mjs +902 -0
package/src/index.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// browsermesh-apps — Applications layer
|
|
2
|
+
export * from './apps.mjs';
|
|
3
|
+
export * from './marketplace.mjs';
|
|
4
|
+
export * from './chat.mjs';
|
|
5
|
+
export * from './payments.mjs';
|
|
6
|
+
export * from './quotas.mjs';
|
|
7
|
+
export * from './resources.mjs';
|
|
8
|
+
export * from './gpu.mjs';
|
|
9
|
+
export * from './scheduler.mjs';
|
|
10
|
+
export * from './consensus.mjs';
|
|
11
|
+
export * from './orchestrator.mjs';
|
|
12
|
+
export * from './audit.mjs';
|
|
13
|
+
export * from './visualizations.mjs';
|
|
14
|
+
export * from './devtools.mjs';
|
|
15
|
+
export * from './tools.mjs';
|
|
16
|
+
export * from './peer-agent.mjs';
|
|
17
|
+
export * from './peer-agent-swarm.mjs';
|
|
18
|
+
export * from './peer-chat.mjs';
|
|
19
|
+
export * from './peer-compute.mjs';
|
|
20
|
+
export * from './peer-encrypted-store.mjs';
|
|
21
|
+
export * from './peer-escrow.mjs';
|
|
22
|
+
export * from './peer-files.mjs';
|
|
23
|
+
export * from './peer-health.mjs';
|
|
24
|
+
export * from './peer-ipfs.mjs';
|
|
25
|
+
export * from './peer-node.mjs';
|
|
26
|
+
export * from './peer-payments.mjs';
|
|
27
|
+
export * from './peer-registry.mjs';
|
|
28
|
+
export * from './peer-routing.mjs';
|
|
29
|
+
export * from './peer-services.mjs';
|
|
30
|
+
export * from './peer-session.mjs';
|
|
31
|
+
export * from './peer-terminal.mjs';
|
|
32
|
+
export * from './peer-timestamp.mjs';
|
|
33
|
+
export * from './peer-torrent.mjs';
|
|
34
|
+
export * from './peer-verification.mjs';
|
|
35
|
+
export * from './marketplace-ui.mjs';
|
|
36
|
+
export { BrowserTool } from './compat.mjs';
|
|
37
|
+
|
|
38
|
+
// `CreditLedger` is defined in both payments.mjs and peer-payments.mjs;
|
|
39
|
+
// `EscrowManager` is defined in both payments.mjs and peer-escrow.mjs.
|
|
40
|
+
// Ambiguous `export *` bindings are silently dropped, so disambiguate
|
|
41
|
+
// explicitly in favor of the pair actually used together (mesh-level
|
|
42
|
+
// payments.mjs's CreditLedger + peer-escrow.mjs's opts-based EscrowManager).
|
|
43
|
+
export { CreditLedger } from './payments.mjs';
|
|
44
|
+
export { EscrowManager } from './peer-escrow.mjs';
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clawser Skill Marketplace
|
|
3
|
+
*
|
|
4
|
+
* Browse, search, rate, and install agent skills from a catalog.
|
|
5
|
+
* The catalog is loaded from a JSON source (local or remote).
|
|
6
|
+
* Installed skills are tracked in memory and can be persisted
|
|
7
|
+
* to localStorage or OPFS by the caller.
|
|
8
|
+
*
|
|
9
|
+
* Catalog format:
|
|
10
|
+
* {
|
|
11
|
+
* skills: [{ id, name, description, author, version, category, tags, rating, ratingCount, downloads }],
|
|
12
|
+
* categories: string[]
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// ── SkillMarketplace ─────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
export class SkillMarketplace {
|
|
19
|
+
/** @type {{ skills: object[], categories: string[] }} */
|
|
20
|
+
#catalog;
|
|
21
|
+
|
|
22
|
+
/** @type {Set<string>} */
|
|
23
|
+
#installed = new Set();
|
|
24
|
+
|
|
25
|
+
/** @type {Map<string, number>} User's ratings: skillId → stars */
|
|
26
|
+
#userRatings = new Map();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} [catalog] - Initial catalog data
|
|
30
|
+
* @param {object[]} [catalog.skills] - Array of skill entries
|
|
31
|
+
* @param {string[]} [catalog.categories] - Available category names
|
|
32
|
+
*/
|
|
33
|
+
constructor(catalog = null) {
|
|
34
|
+
this.#catalog = catalog
|
|
35
|
+
? { skills: [...catalog.skills.map(s => ({ ...s }))], categories: [...(catalog.categories || [])] }
|
|
36
|
+
: { skills: [], categories: [] };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Load or replace the catalog from a JSON object.
|
|
41
|
+
* @param {object} catalogData
|
|
42
|
+
*/
|
|
43
|
+
loadCatalog(catalogData) {
|
|
44
|
+
this.#catalog = {
|
|
45
|
+
skills: [...catalogData.skills.map(s => ({ ...s }))],
|
|
46
|
+
categories: [...(catalogData.categories || [])],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Load catalog from a URL (fetches JSON).
|
|
52
|
+
* @param {string} url
|
|
53
|
+
* @returns {Promise<void>}
|
|
54
|
+
*/
|
|
55
|
+
async loadCatalogFromUrl(url) {
|
|
56
|
+
const resp = await fetch(url);
|
|
57
|
+
if (!resp.ok) throw new Error(`Failed to fetch catalog: ${resp.status}`);
|
|
58
|
+
const data = await resp.json();
|
|
59
|
+
this.loadCatalog(data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get the full catalog.
|
|
64
|
+
* @returns {{ skills: object[], categories: string[] }}
|
|
65
|
+
*/
|
|
66
|
+
getCatalog() {
|
|
67
|
+
return {
|
|
68
|
+
skills: this.#catalog.skills.map(s => ({ ...s })),
|
|
69
|
+
categories: [...this.#catalog.categories],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Browse / search skills.
|
|
75
|
+
* @param {string} query - Text query (matches name, description, tags)
|
|
76
|
+
* @param {object} [opts]
|
|
77
|
+
* @param {string} [opts.category] - Filter by category
|
|
78
|
+
* @param {string} [opts.author] - Filter by author
|
|
79
|
+
* @param {string} [opts.sort='downloads'] - Sort by: 'downloads' | 'rating' | 'name'
|
|
80
|
+
* @param {number} [opts.limit=50] - Max results
|
|
81
|
+
* @returns {object[]}
|
|
82
|
+
*/
|
|
83
|
+
browse(query = '', opts = {}) {
|
|
84
|
+
let results = [...this.#catalog.skills];
|
|
85
|
+
|
|
86
|
+
// Text search
|
|
87
|
+
if (query) {
|
|
88
|
+
const q = query.toLowerCase();
|
|
89
|
+
results = results.filter(s => {
|
|
90
|
+
const haystack = [
|
|
91
|
+
s.name,
|
|
92
|
+
s.description,
|
|
93
|
+
s.author,
|
|
94
|
+
...(s.tags || []),
|
|
95
|
+
].join(' ').toLowerCase();
|
|
96
|
+
return haystack.includes(q);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Category filter
|
|
101
|
+
if (opts.category) {
|
|
102
|
+
results = results.filter(s => s.category === opts.category);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Author filter
|
|
106
|
+
if (opts.author) {
|
|
107
|
+
results = results.filter(s => s.author === opts.author);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Sort
|
|
111
|
+
const sortField = opts.sort || 'downloads';
|
|
112
|
+
switch (sortField) {
|
|
113
|
+
case 'rating':
|
|
114
|
+
results.sort((a, b) => (b.rating || 0) - (a.rating || 0));
|
|
115
|
+
break;
|
|
116
|
+
case 'name':
|
|
117
|
+
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
118
|
+
break;
|
|
119
|
+
case 'downloads':
|
|
120
|
+
default:
|
|
121
|
+
results.sort((a, b) => (b.downloads || 0) - (a.downloads || 0));
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Limit
|
|
126
|
+
const limit = opts.limit || 50;
|
|
127
|
+
return results.slice(0, limit);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Rate a skill. Computes a weighted average incorporating the new rating.
|
|
132
|
+
* @param {string} skillId
|
|
133
|
+
* @param {number} stars - 1 to 5
|
|
134
|
+
* @returns {object|null} Updated skill entry, or null if not found
|
|
135
|
+
*/
|
|
136
|
+
rate(skillId, stars) {
|
|
137
|
+
const clamped = Math.max(1, Math.min(5, stars));
|
|
138
|
+
const skill = this.#catalog.skills.find(s => s.id === skillId);
|
|
139
|
+
if (!skill) return null;
|
|
140
|
+
|
|
141
|
+
// Weighted average: (oldRating * oldCount + newRating) / (oldCount + 1)
|
|
142
|
+
const oldRating = skill.rating || 0;
|
|
143
|
+
const oldCount = skill.ratingCount || 0;
|
|
144
|
+
skill.ratingCount = oldCount + 1;
|
|
145
|
+
skill.rating = Math.round(((oldRating * oldCount + clamped) / skill.ratingCount) * 100) / 100;
|
|
146
|
+
|
|
147
|
+
this.#userRatings.set(skillId, clamped);
|
|
148
|
+
|
|
149
|
+
return { ...skill };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Mark a skill as installed. Increments the download counter.
|
|
154
|
+
* @param {string} skillId
|
|
155
|
+
* @returns {{ installed: boolean, skillId: string, error?: string }}
|
|
156
|
+
*/
|
|
157
|
+
install(skillId) {
|
|
158
|
+
const skill = this.#catalog.skills.find(s => s.id === skillId);
|
|
159
|
+
if (!skill) {
|
|
160
|
+
return { installed: false, skillId, error: `Skill not found: ${skillId}` };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.#installed.add(skillId);
|
|
164
|
+
skill.downloads = (skill.downloads || 0) + 1;
|
|
165
|
+
|
|
166
|
+
return { installed: true, skillId, name: skill.name, version: skill.version };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Uninstall (remove from installed set).
|
|
171
|
+
* @param {string} skillId
|
|
172
|
+
* @returns {{ uninstalled: boolean, skillId: string }}
|
|
173
|
+
*/
|
|
174
|
+
uninstall(skillId) {
|
|
175
|
+
const removed = this.#installed.delete(skillId);
|
|
176
|
+
return { uninstalled: removed, skillId };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Get list of installed skill IDs.
|
|
181
|
+
* @returns {string[]}
|
|
182
|
+
*/
|
|
183
|
+
getInstalled() {
|
|
184
|
+
return [...this.#installed];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Check if a specific skill is installed.
|
|
189
|
+
* @param {string} skillId
|
|
190
|
+
* @returns {boolean}
|
|
191
|
+
*/
|
|
192
|
+
isInstalled(skillId) {
|
|
193
|
+
return this.#installed.has(skillId);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get a single skill by ID.
|
|
198
|
+
* @param {string} skillId
|
|
199
|
+
* @returns {object|null}
|
|
200
|
+
*/
|
|
201
|
+
getSkill(skillId) {
|
|
202
|
+
const skill = this.#catalog.skills.find(s => s.id === skillId);
|
|
203
|
+
return skill ? { ...skill, installed: this.#installed.has(skillId) } : null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Get the user's rating for a skill.
|
|
208
|
+
* @param {string} skillId
|
|
209
|
+
* @returns {number|null}
|
|
210
|
+
*/
|
|
211
|
+
getUserRating(skillId) {
|
|
212
|
+
return this.#userRatings.get(skillId) ?? null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get all categories.
|
|
217
|
+
* @returns {string[]}
|
|
218
|
+
*/
|
|
219
|
+
getCategories() {
|
|
220
|
+
return [...this.#catalog.categories];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Export installed list as JSON (for persistence).
|
|
225
|
+
* @returns {string}
|
|
226
|
+
*/
|
|
227
|
+
exportInstalledJSON() {
|
|
228
|
+
return JSON.stringify([...this.#installed]);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Import installed list from JSON.
|
|
233
|
+
* @param {string} json
|
|
234
|
+
*/
|
|
235
|
+
importInstalledJSON(json) {
|
|
236
|
+
try {
|
|
237
|
+
const ids = JSON.parse(json);
|
|
238
|
+
if (Array.isArray(ids)) {
|
|
239
|
+
for (const id of ids) this.#installed.add(id);
|
|
240
|
+
}
|
|
241
|
+
} catch {
|
|
242
|
+
// ignore malformed JSON
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|