@framers/agentos 0.1.28 → 0.1.30

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 (46) hide show
  1. package/dist/cognitive_substrate/GMIManager.d.ts.map +1 -1
  2. package/dist/cognitive_substrate/GMIManager.js +0 -2
  3. package/dist/cognitive_substrate/GMIManager.js.map +1 -1
  4. package/dist/core/tools/IToolOrchestrator.d.ts +17 -0
  5. package/dist/core/tools/IToolOrchestrator.d.ts.map +1 -1
  6. package/dist/core/tools/ToolOrchestrator.d.ts +13 -0
  7. package/dist/core/tools/ToolOrchestrator.d.ts.map +1 -1
  8. package/dist/core/tools/ToolOrchestrator.js +28 -0
  9. package/dist/core/tools/ToolOrchestrator.js.map +1 -1
  10. package/dist/discovery/CapabilityContextAssembler.d.ts +54 -0
  11. package/dist/discovery/CapabilityContextAssembler.d.ts.map +1 -0
  12. package/dist/discovery/CapabilityContextAssembler.js +192 -0
  13. package/dist/discovery/CapabilityContextAssembler.js.map +1 -0
  14. package/dist/discovery/CapabilityDiscoveryEngine.d.ts +76 -0
  15. package/dist/discovery/CapabilityDiscoveryEngine.d.ts.map +1 -0
  16. package/dist/discovery/CapabilityDiscoveryEngine.js +197 -0
  17. package/dist/discovery/CapabilityDiscoveryEngine.js.map +1 -0
  18. package/dist/discovery/CapabilityEmbeddingStrategy.d.ts +45 -0
  19. package/dist/discovery/CapabilityEmbeddingStrategy.d.ts.map +1 -0
  20. package/dist/discovery/CapabilityEmbeddingStrategy.js +167 -0
  21. package/dist/discovery/CapabilityEmbeddingStrategy.js.map +1 -0
  22. package/dist/discovery/CapabilityGraph.d.ts +78 -0
  23. package/dist/discovery/CapabilityGraph.d.ts.map +1 -0
  24. package/dist/discovery/CapabilityGraph.js +263 -0
  25. package/dist/discovery/CapabilityGraph.js.map +1 -0
  26. package/dist/discovery/CapabilityIndex.d.ts +93 -0
  27. package/dist/discovery/CapabilityIndex.d.ts.map +1 -0
  28. package/dist/discovery/CapabilityIndex.js +324 -0
  29. package/dist/discovery/CapabilityIndex.js.map +1 -0
  30. package/dist/discovery/CapabilityManifestScanner.d.ts +66 -0
  31. package/dist/discovery/CapabilityManifestScanner.d.ts.map +1 -0
  32. package/dist/discovery/CapabilityManifestScanner.js +315 -0
  33. package/dist/discovery/CapabilityManifestScanner.js.map +1 -0
  34. package/dist/discovery/DiscoverCapabilitiesTool.d.ts +44 -0
  35. package/dist/discovery/DiscoverCapabilitiesTool.d.ts.map +1 -0
  36. package/dist/discovery/DiscoverCapabilitiesTool.js +118 -0
  37. package/dist/discovery/DiscoverCapabilitiesTool.js.map +1 -0
  38. package/dist/discovery/index.d.ts +39 -0
  39. package/dist/discovery/index.d.ts.map +1 -0
  40. package/dist/discovery/index.js +41 -0
  41. package/dist/discovery/index.js.map +1 -0
  42. package/dist/discovery/types.d.ts +357 -0
  43. package/dist/discovery/types.d.ts.map +1 -0
  44. package/dist/discovery/types.js +46 -0
  45. package/dist/discovery/types.js.map +1 -0
  46. package/package.json +6 -1
@@ -0,0 +1,263 @@
1
+ /**
2
+ * @fileoverview Capability Relationship Graph
3
+ * @module @framers/agentos/discovery/CapabilityGraph
4
+ *
5
+ * Lightweight, deterministic relationship graph over capabilities.
6
+ * Built from metadata (SKILL.md frontmatter, preset co-occurrence),
7
+ * NOT from LLM extraction.
8
+ *
9
+ * Uses graphology (already in codebase via GraphRAGEngine) for:
10
+ * - O(1) neighbor lookups
11
+ * - Edge attributes (type, weight)
12
+ * - Sub-millisecond traversal for ~100 nodes
13
+ *
14
+ * Implements ICapabilityGraph so Neo4j can be swapped in later
15
+ * if capabilities scale to 1000+.
16
+ *
17
+ * Edge types:
18
+ * - DEPENDS_ON: Skill → Tool (from requiredTools)
19
+ * - COMPOSED_WITH: Co-occur in agent presets (suggestedSkills + suggestedExtensions)
20
+ * - SAME_CATEGORY: Shared category (weak signal, low weight)
21
+ * - TAGGED_WITH: Shared tags (weighted by overlap count, ≥2 tags)
22
+ */
23
+ import Graph from 'graphology';
24
+ // ============================================================================
25
+ // GRAPHOLOGY-BASED CAPABILITY GRAPH
26
+ // ============================================================================
27
+ export class CapabilityGraph {
28
+ constructor() {
29
+ this.graph = new Graph({ multi: false, type: 'undirected' });
30
+ }
31
+ // ============================================================================
32
+ // BUILD
33
+ // ============================================================================
34
+ /**
35
+ * Build the graph from capability descriptors and preset co-occurrence data.
36
+ *
37
+ * Construction order:
38
+ * 1. Add all capabilities as nodes
39
+ * 2. Add DEPENDS_ON edges (skill → tool dependencies)
40
+ * 3. Add COMPOSED_WITH edges (preset co-occurrence)
41
+ * 4. Add TAGGED_WITH edges (shared tags, ≥2 overlap)
42
+ * 5. Add SAME_CATEGORY edges (weak signal)
43
+ */
44
+ buildGraph(capabilities, presetCoOccurrences) {
45
+ // Clear any existing graph
46
+ this.graph.clear();
47
+ // 1. Add all capabilities as nodes
48
+ for (const cap of capabilities) {
49
+ this.graph.addNode(cap.id, {
50
+ kind: cap.kind,
51
+ category: cap.category,
52
+ name: cap.name,
53
+ });
54
+ }
55
+ // 2. Add DEPENDS_ON edges (skill → tool)
56
+ for (const cap of capabilities) {
57
+ if (cap.requiredTools.length > 0) {
58
+ for (const toolName of cap.requiredTools) {
59
+ // Try both tool:name and skill:name patterns
60
+ const toolId = `tool:${toolName}`;
61
+ if (this.graph.hasNode(cap.id) && this.graph.hasNode(toolId)) {
62
+ this.safeAddEdge(cap.id, toolId, 'DEPENDS_ON', 1.0);
63
+ }
64
+ }
65
+ }
66
+ }
67
+ // 3. Add COMPOSED_WITH edges from preset co-occurrence
68
+ if (presetCoOccurrences) {
69
+ for (const preset of presetCoOccurrences) {
70
+ const validIds = preset.capabilityIds.filter((id) => this.graph.hasNode(id));
71
+ for (let i = 0; i < validIds.length; i++) {
72
+ for (let j = i + 1; j < validIds.length; j++) {
73
+ this.safeAddEdge(validIds[i], validIds[j], 'COMPOSED_WITH', 0.5);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ // 4. Add TAGGED_WITH edges (shared tags, ≥2 overlap)
79
+ const tagIndex = new Map();
80
+ for (const cap of capabilities) {
81
+ for (const tag of cap.tags) {
82
+ const list = tagIndex.get(tag) ?? [];
83
+ list.push(cap.id);
84
+ tagIndex.set(tag, list);
85
+ }
86
+ }
87
+ // Count tag overlaps between capability pairs
88
+ const pairOverlaps = new Map();
89
+ for (const [, capIds] of tagIndex) {
90
+ for (let i = 0; i < capIds.length; i++) {
91
+ for (let j = i + 1; j < capIds.length; j++) {
92
+ const key = [capIds[i], capIds[j]].sort().join('||');
93
+ pairOverlaps.set(key, (pairOverlaps.get(key) ?? 0) + 1);
94
+ }
95
+ }
96
+ }
97
+ for (const [key, count] of pairOverlaps) {
98
+ if (count >= 2) {
99
+ const [a, b] = key.split('||');
100
+ this.safeAddEdge(a, b, 'TAGGED_WITH', count * 0.3);
101
+ }
102
+ }
103
+ // 5. Add SAME_CATEGORY edges (weak signal — only between same-kind capabilities)
104
+ const categoryIndex = new Map();
105
+ for (const cap of capabilities) {
106
+ const key = `${cap.kind}:${cap.category}`;
107
+ const list = categoryIndex.get(key) ?? [];
108
+ list.push(cap.id);
109
+ categoryIndex.set(key, list);
110
+ }
111
+ for (const [, capIds] of categoryIndex) {
112
+ // Only add category edges for groups of 2-8 (avoid massive cliques)
113
+ if (capIds.length >= 2 && capIds.length <= 8) {
114
+ for (let i = 0; i < capIds.length; i++) {
115
+ for (let j = i + 1; j < capIds.length; j++) {
116
+ this.safeAddEdge(capIds[i], capIds[j], 'SAME_CATEGORY', 0.1);
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ // ============================================================================
123
+ // QUERY
124
+ // ============================================================================
125
+ /**
126
+ * Get capabilities related to a given capability (1-hop neighbors).
127
+ * Returns neighbors with edge weights, sorted by weight descending.
128
+ */
129
+ getRelated(capabilityId) {
130
+ if (!this.graph.hasNode(capabilityId))
131
+ return [];
132
+ const related = [];
133
+ this.graph.forEachEdge(capabilityId, (_edge, attrs, source, target) => {
134
+ const neighborId = source === capabilityId ? target : source;
135
+ related.push({
136
+ id: neighborId,
137
+ weight: attrs.weight,
138
+ relationType: attrs.type,
139
+ });
140
+ });
141
+ // Sort by weight descending
142
+ related.sort((a, b) => b.weight - a.weight);
143
+ return related;
144
+ }
145
+ /**
146
+ * Get the subgraph for a set of capability IDs.
147
+ * Returns all nodes and edges within the induced subgraph.
148
+ */
149
+ getSubgraph(capabilityIds) {
150
+ const nodeSet = new Set(capabilityIds.filter((id) => this.graph.hasNode(id)));
151
+ const edges = [];
152
+ for (const nodeId of nodeSet) {
153
+ this.graph.forEachEdge(nodeId, (_edge, attrs, source, target) => {
154
+ // Only include edges where both endpoints are in the subgraph
155
+ if (nodeSet.has(source) && nodeSet.has(target)) {
156
+ // Avoid duplicates (undirected graph)
157
+ const edgeKey = [source, target].sort().join('||');
158
+ if (!edges.some((e) => [e.sourceId, e.targetId].sort().join('||') === edgeKey)) {
159
+ edges.push({
160
+ sourceId: source,
161
+ targetId: target,
162
+ type: attrs.type,
163
+ weight: attrs.weight,
164
+ });
165
+ }
166
+ }
167
+ });
168
+ }
169
+ return {
170
+ nodes: Array.from(nodeSet),
171
+ edges,
172
+ };
173
+ }
174
+ /**
175
+ * Apply graph-based re-ranking boost to search results.
176
+ *
177
+ * For each result in the search results:
178
+ * 1. Look up its graph neighbors
179
+ * 2. If a neighbor is also in the results, boost both by graphBoostFactor * edge weight
180
+ * 3. If a neighbor is NOT in results but has a DEPENDS_ON edge, add it as a candidate
181
+ *
182
+ * Returns re-ranked results with potentially new candidates added.
183
+ */
184
+ rerank(searchResults, graphBoostFactor) {
185
+ const resultMap = new Map();
186
+ // Initialize with original scores
187
+ for (const r of searchResults) {
188
+ resultMap.set(r.id, { score: r.score, boosted: false });
189
+ }
190
+ // Apply graph boosts
191
+ for (const r of searchResults) {
192
+ const related = this.getRelated(r.id);
193
+ for (const rel of related) {
194
+ if (resultMap.has(rel.id)) {
195
+ // Both in results — mutual boost
196
+ const existing = resultMap.get(rel.id);
197
+ existing.score += graphBoostFactor * rel.weight;
198
+ existing.boosted = true;
199
+ }
200
+ else if (rel.relationType === 'DEPENDS_ON' || rel.relationType === 'COMPOSED_WITH') {
201
+ // Not in results but has strong relationship — pull in as candidate
202
+ resultMap.set(rel.id, {
203
+ score: r.score * graphBoostFactor * rel.weight,
204
+ boosted: true,
205
+ });
206
+ }
207
+ }
208
+ }
209
+ // Sort by score descending
210
+ return Array.from(resultMap.entries())
211
+ .map(([id, { score, boosted }]) => ({ id, score, boosted }))
212
+ .sort((a, b) => b.score - a.score);
213
+ }
214
+ // ============================================================================
215
+ // ACCESSORS
216
+ // ============================================================================
217
+ nodeCount() {
218
+ return this.graph.order;
219
+ }
220
+ edgeCount() {
221
+ return this.graph.size;
222
+ }
223
+ clear() {
224
+ this.graph.clear();
225
+ }
226
+ // ============================================================================
227
+ // INTERNAL HELPERS
228
+ // ============================================================================
229
+ /**
230
+ * Safely add an edge, handling the case where it already exists.
231
+ * If the edge already exists, update to the higher weight.
232
+ */
233
+ safeAddEdge(source, target, type, weight) {
234
+ if (!this.graph.hasNode(source) || !this.graph.hasNode(target))
235
+ return;
236
+ if (source === target)
237
+ return;
238
+ try {
239
+ const existingEdge = this.graph.edge(source, target);
240
+ if (existingEdge) {
241
+ // Edge exists — keep the one with higher weight or stronger type
242
+ const existing = this.graph.getEdgeAttributes(existingEdge);
243
+ if (weight > existing.weight) {
244
+ this.graph.setEdgeAttribute(existingEdge, 'weight', weight);
245
+ this.graph.setEdgeAttribute(existingEdge, 'type', type);
246
+ }
247
+ }
248
+ else {
249
+ this.graph.addEdge(source, target, { type, weight });
250
+ }
251
+ }
252
+ catch {
253
+ // Edge might already exist in the other direction for undirected
254
+ try {
255
+ this.graph.addEdge(source, target, { type, weight });
256
+ }
257
+ catch {
258
+ // Silently ignore — edge already exists
259
+ }
260
+ }
261
+ }
262
+ }
263
+ //# sourceMappingURL=CapabilityGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CapabilityGraph.js","sourceRoot":"","sources":["../../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oBAC7B,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAC5D,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC1D,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,iEAAiE;YACjE,IAAI,CAAC;gBACH,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YACvD,CAAC;YAAC,MAAM,CAAC;gBACP,wCAAwC;YAC1C,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @fileoverview Capability Index — vector index over all capabilities.
3
+ * @module @framers/agentos/discovery/CapabilityIndex
4
+ *
5
+ * Normalizes tools, skills, extensions, and channels into unified
6
+ * CapabilityDescriptor objects, embeds them, and stores them in a
7
+ * vector index for semantic search.
8
+ *
9
+ * Reuses existing infrastructure:
10
+ * - IEmbeddingManager for embedding generation (with LRU cache)
11
+ * - IVectorStore for vector storage (InMemory, HNSW, Qdrant, SQL)
12
+ *
13
+ * Performance targets:
14
+ * - Index build: ~3s for ~100 capabilities (one-time, embedding API calls)
15
+ * - Search: <1ms HNSW lookup + ~50ms embedding cold / <5ms warm
16
+ */
17
+ import type { IEmbeddingManager } from '../rag/IEmbeddingManager.js';
18
+ import type { IVectorStore } from '../rag/IVectorStore.js';
19
+ import type { CapabilityDescriptor, CapabilityKind, CapabilitySearchResult, CapabilityIndexSources } from './types.js';
20
+ import { CapabilityEmbeddingStrategy } from './CapabilityEmbeddingStrategy.js';
21
+ export declare class CapabilityIndex {
22
+ private readonly embeddingManager;
23
+ private readonly vectorStore;
24
+ private readonly collectionName;
25
+ private readonly embeddingModelId?;
26
+ private readonly descriptors;
27
+ private readonly embeddingStrategy;
28
+ private built;
29
+ constructor(embeddingManager: IEmbeddingManager, vectorStore: IVectorStore, collectionName: string, embeddingModelId?: string | undefined);
30
+ /**
31
+ * Build the index from all capability sources.
32
+ * Normalizes sources into CapabilityDescriptors, embeds them, and stores
33
+ * in the vector store.
34
+ */
35
+ buildIndex(sources: CapabilityIndexSources): Promise<void>;
36
+ /**
37
+ * Incrementally add or update a single capability.
38
+ */
39
+ upsertCapability(cap: CapabilityDescriptor): Promise<void>;
40
+ /**
41
+ * Remove a capability from the index.
42
+ */
43
+ removeCapability(id: string): Promise<void>;
44
+ /**
45
+ * Semantic search for capabilities matching a query.
46
+ *
47
+ * @param query - Natural language query (e.g., "search the web for news")
48
+ * @param topK - Number of results to return
49
+ * @param filters - Optional filters by kind, category, availability
50
+ */
51
+ search(query: string, topK: number, filters?: {
52
+ kind?: CapabilityKind | 'any';
53
+ category?: string;
54
+ onlyAvailable?: boolean;
55
+ }): Promise<CapabilitySearchResult[]>;
56
+ /**
57
+ * Get a capability by ID.
58
+ */
59
+ getCapability(id: string): CapabilityDescriptor | undefined;
60
+ /**
61
+ * Get all registered capabilities.
62
+ */
63
+ getAllCapabilities(): CapabilityDescriptor[];
64
+ /**
65
+ * Get all capability IDs.
66
+ */
67
+ listIds(): string[];
68
+ /**
69
+ * Get capabilities grouped by category.
70
+ */
71
+ getByCategory(): Map<string, CapabilityDescriptor[]>;
72
+ /**
73
+ * Whether the index has been built.
74
+ */
75
+ isBuilt(): boolean;
76
+ /**
77
+ * Number of indexed capabilities.
78
+ */
79
+ size(): number;
80
+ /**
81
+ * Get the embedding strategy (for external use by assembler).
82
+ */
83
+ getEmbeddingStrategy(): CapabilityEmbeddingStrategy;
84
+ /**
85
+ * Normalize all sources into CapabilityDescriptor objects.
86
+ */
87
+ normalizeSources(sources: CapabilityIndexSources): CapabilityDescriptor[];
88
+ private normalizeToolSource;
89
+ private normalizeSkillSource;
90
+ private normalizeExtensionSource;
91
+ private normalizeChannelSource;
92
+ }
93
+ //# sourceMappingURL=CapabilityIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CapabilityIndex.d.ts","sourceRoot":"","sources":["../../src/discovery/CapabilityIndex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAkC,MAAM,wBAAwB,CAAC;AAC3F,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAM/E,qBAAa,eAAe;IAMxB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IARpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgD;IAC5E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA8B;IAChE,OAAO,CAAC,KAAK,CAAS;gBAGH,gBAAgB,EAAE,iBAAiB,EACnC,WAAW,EAAE,YAAY,EACzB,cAAc,EAAE,MAAM,EACtB,gBAAgB,CAAC,EAAE,MAAM,YAAA;IAS5C;;;;OAIG;IACG,UAAU,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DhE;;OAEG;IACG,gBAAgB,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBhE;;OAEG;IACG,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASjD;;;;;;OAM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