-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompute-stats.mjs
More file actions
141 lines (123 loc) · 4.98 KB
/
Copy pathcompute-stats.mjs
File metadata and controls
141 lines (123 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env node
/**
* Canonical derivation of AgentsKit ecosystem counts from the real monorepo.
*
* This is THE single source for every "N packages / N adapters / ..." number on
* agentskit.io. The derivation rules below ARE the definition of each count —
* change a rule here, never a number in a page. Plain JS so it runs without a
* build step and can be copied verbatim into sibling repos.
*
* Consumed by scripts/gen-ecosystem-stats.mjs (writes the committed snapshots
* both Next apps import) and by scripts/check-count-drift.mjs (the gate).
*/
import { readdirSync, readFileSync, existsSync, statSync } from 'node:fs'
import { join, resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
export const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const FRAMEWORK_BINDINGS = ['react', 'vue', 'svelte', 'solid', 'angular', 'ink', 'react-native']
const ADAPTER_NON_PROVIDERS = new Set([
'generic', 'types', 'utils', 'util', 'router', 'carbon', 'ensemble',
'fallback', 'mock', 'embedders', 'deprecation', 'credential-rotation', 'bail',
])
const MEMORY_NON_BACKENDS = new Set([
'index', 'types', 'utils', 'util', 'contract', 'base',
'forget', 'redaction', 'personalization', 'redis-client',
])
const SKILL_NON_SKILLS = ['index', 'compose', 'marketplace', 'types', 'registry']
function listDirs(p) {
if (!existsSync(p)) return []
return readdirSync(p).filter((n) => {
try { return statSync(join(p, n)).isDirectory() } catch { return false }
})
}
function listTs(p) {
if (!existsSync(p)) return []
return readdirSync(p)
.filter((n) => n.endsWith('.ts') && !n.endsWith('.d.ts') && !n.includes('.test.'))
.map((n) => n.replace(/\.ts$/, ''))
}
export function computeStats(root = REPO_ROOT) {
const pkgRoot = join(root, 'packages')
let packages = 0
const published = new Set()
const packageList = []
for (const dir of listDirs(pkgRoot)) {
const pj = join(pkgRoot, dir, 'package.json')
if (!existsSync(pj)) continue
try {
const json = JSON.parse(readFileSync(pj, 'utf8'))
if (json.name?.startsWith('@agentskit/') && !json.private) {
packages++
published.add(json.name.replace('@agentskit/', ''))
packageList.push({
name: json.name,
description: json.description ?? '',
stability: json.agentskit?.stability ?? 'unlisted',
})
}
} catch { /* skip */ }
}
packageList.sort((a, b) => a.name.localeCompare(b.name))
const frameworkBindings = FRAMEWORK_BINDINGS.filter((f) => published.has(f)).length
let nativeAdapters = 0
const adaptersIndex = join(pkgRoot, 'adapters', 'src', 'index.ts')
if (existsSync(adaptersIndex)) {
const src = readFileSync(adaptersIndex, 'utf8')
const names = new Set()
for (const m of src.matchAll(/from\s+['"]\.\/([a-z0-9-]+)['"]/g)) names.add(m[1])
for (const n of names) if (!ADAPTER_NON_PROVIDERS.has(n)) nativeAdapters++
}
const integrationList = listDirs(join(pkgRoot, 'integrations', 'src', 'services'))
.filter((n) => !n.startsWith('_'))
.sort()
const integrations = integrationList.length
let catalogProviders = 0
let catalogModels = 0
let providerList = []
const catalogSnap = join(pkgRoot, 'adapters', 'src', 'catalog', 'snapshot.json')
if (existsSync(catalogSnap)) {
try {
const c = JSON.parse(readFileSync(catalogSnap, 'utf8'))
const arr = Array.isArray(c.providers) ? c.providers : c.providers ? Object.values(c.providers) : []
catalogProviders = arr.length
providerList = arr.map((pr) => pr.id).filter(Boolean).sort()
for (const pr of arr) {
const m = pr.models
if (Array.isArray(m)) catalogModels += m.length
else if (m && typeof m === 'object') catalogModels += Object.keys(m).length
}
} catch { /* zero */ }
}
const skills = listTs(join(pkgRoot, 'skills', 'src'))
.filter((n) => !SKILL_NON_SKILLS.includes(n)).length
const memoryBackends = listTs(join(pkgRoot, 'memory', 'src'))
.filter((n) => !MEMORY_NON_BACKENDS.has(n)).length
const recipesDir = join(root, 'apps', 'docs-next', 'content', 'docs', 'reference', 'recipes')
const recipes = existsSync(recipesDir)
? readdirSync(recipesDir).filter((n) => n.endsWith('.mdx') && !/^(index|meta)/.test(n)).length
: 0
let coreSizeKbGzip = 10
const sizeLimit = join(root, '.size-limit.json')
if (existsSync(sizeLimit)) {
try {
const arr = JSON.parse(readFileSync(sizeLimit, 'utf8'))
const core = arr.find((x) => /core.*ESM/i.test(x.name ?? ''))
const kb = core?.limit?.match(/([\d.]+)\s*KB/i)
if (kb) coreSizeKbGzip = Number(kb[1])
} catch { /* default */ }
}
return {
schemaVersion: 1,
property: 'agentskit',
counts: {
packages, frameworkBindings, nativeAdapters, integrations,
catalogProviders, catalogModels, skills, memoryBackends, recipes,
},
lists: {
packages: packageList,
integrations: integrationList,
providers: providerList,
},
coreSizeKbGzip,
}
}