agentikit 0.0.9 → 0.0.13
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 +139 -208
- package/dist/index.d.ts +8 -2
- package/dist/index.js +4 -1
- package/dist/src/asset-spec.d.ts +2 -0
- package/dist/src/asset-spec.js +22 -3
- package/dist/src/asset-type-handler.d.ts +27 -0
- package/dist/src/asset-type-handler.js +33 -0
- package/dist/src/cli.js +201 -75
- package/dist/src/common.d.ts +6 -1
- package/dist/src/common.js +18 -4
- package/dist/src/config-cli.d.ts +9 -0
- package/dist/src/config-cli.js +473 -0
- package/dist/src/config.d.ts +19 -6
- package/dist/src/config.js +139 -29
- package/dist/src/db.d.ts +46 -0
- package/dist/src/db.js +299 -0
- package/dist/src/embedder.js +12 -7
- package/dist/src/github.d.ts +4 -0
- package/dist/src/github.js +19 -0
- package/dist/src/handlers/agent-handler.d.ts +2 -0
- package/dist/src/handlers/agent-handler.js +26 -0
- package/dist/src/handlers/command-handler.d.ts +2 -0
- package/dist/src/handlers/command-handler.js +23 -0
- package/dist/src/handlers/index.d.ts +6 -0
- package/dist/src/handlers/index.js +23 -0
- package/dist/src/handlers/knowledge-handler.d.ts +2 -0
- package/dist/src/handlers/knowledge-handler.js +56 -0
- package/dist/src/handlers/markdown-helpers.d.ts +7 -0
- package/dist/src/handlers/markdown-helpers.js +15 -0
- package/dist/src/handlers/script-handler.d.ts +2 -0
- package/dist/src/handlers/script-handler.js +78 -0
- package/dist/src/handlers/skill-handler.d.ts +2 -0
- package/dist/src/handlers/skill-handler.js +30 -0
- package/dist/src/handlers/tool-handler.d.ts +2 -0
- package/dist/src/handlers/tool-handler.js +58 -0
- package/dist/src/indexer.d.ts +1 -23
- package/dist/src/indexer.js +162 -155
- package/dist/src/init.d.ts +2 -2
- package/dist/src/init.js +21 -9
- package/dist/src/llm.js +4 -3
- package/dist/src/metadata.d.ts +0 -1
- package/dist/src/metadata.js +6 -64
- package/dist/src/origin-resolve.d.ts +19 -0
- package/dist/src/origin-resolve.js +53 -0
- package/dist/src/registry-install.d.ts +2 -2
- package/dist/src/registry-install.js +142 -35
- package/dist/src/registry-resolve.js +90 -22
- package/dist/src/registry-search.d.ts +22 -0
- package/dist/src/registry-search.js +231 -97
- package/dist/src/registry-types.d.ts +9 -2
- package/dist/src/stash-add.js +4 -4
- package/dist/src/stash-clone.d.ts +22 -0
- package/dist/src/stash-clone.js +83 -0
- package/dist/src/stash-ref.d.ts +27 -3
- package/dist/src/stash-ref.js +63 -24
- package/dist/src/stash-registry.js +12 -12
- package/dist/src/stash-resolve.js +3 -0
- package/dist/src/stash-search.js +168 -164
- package/dist/src/stash-show.d.ts +1 -1
- package/dist/src/stash-show.js +28 -96
- package/dist/src/stash-source.d.ts +24 -0
- package/dist/src/stash-source.js +81 -0
- package/dist/src/stash-types.d.ts +14 -4
- package/dist/src/stash.d.ts +6 -0
- package/dist/src/stash.js +3 -0
- package/dist/src/tool-runner.d.ts +1 -1
- package/dist/src/tool-runner.js +18 -5
- package/package.json +7 -2
- package/src/asset-spec.ts +20 -4
- package/src/asset-type-handler.ts +77 -0
- package/src/cli.ts +213 -82
- package/src/common.ts +23 -5
- package/src/config-cli.ts +499 -0
- package/src/config.ts +160 -38
- package/src/db.ts +411 -0
- package/src/embedder.ts +22 -11
- package/src/github.ts +21 -0
- package/src/handlers/agent-handler.ts +32 -0
- package/src/handlers/command-handler.ts +29 -0
- package/src/handlers/index.ts +25 -0
- package/src/handlers/knowledge-handler.ts +62 -0
- package/src/handlers/markdown-helpers.ts +19 -0
- package/src/handlers/script-handler.ts +92 -0
- package/src/handlers/skill-handler.ts +37 -0
- package/src/handlers/tool-handler.ts +71 -0
- package/src/indexer.ts +208 -187
- package/src/init.ts +17 -9
- package/src/llm.ts +4 -3
- package/src/metadata.ts +5 -65
- package/src/origin-resolve.ts +67 -0
- package/src/registry-install.ts +158 -42
- package/src/registry-resolve.ts +92 -23
- package/src/registry-search.ts +288 -98
- package/src/registry-types.ts +10 -2
- package/src/stash-add.ts +14 -17
- package/src/stash-clone.ts +127 -0
- package/src/stash-ref.ts +84 -26
- package/src/stash-registry.ts +12 -12
- package/src/stash-resolve.ts +3 -0
- package/src/stash-search.ts +202 -184
- package/src/stash-show.ts +33 -90
- package/src/stash-source.ts +103 -0
- package/src/stash-types.ts +14 -4
- package/src/stash.ts +8 -0
- package/src/tool-runner.ts +18 -5
- package/dist/src/similarity.d.ts +0 -34
- package/dist/src/similarity.js +0 -211
- package/src/similarity.ts +0 -271
package/src/similarity.ts
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import type { StashEntry } from "./metadata"
|
|
2
|
-
|
|
3
|
-
// ── Adapter Interface ───────────────────────────────────────────────────────
|
|
4
|
-
|
|
5
|
-
export interface ScoredEntry {
|
|
6
|
-
id: string
|
|
7
|
-
text: string
|
|
8
|
-
entry: StashEntry
|
|
9
|
-
path: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface ScoredResult {
|
|
13
|
-
entry: StashEntry
|
|
14
|
-
path: string
|
|
15
|
-
score: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface SearchAdapter {
|
|
19
|
-
buildIndex(entries: ScoredEntry[]): void
|
|
20
|
-
search(query: string, limit: number, typeFilter?: string): ScoredResult[]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// ── TF-IDF Implementation ───────────────────────────────────────────────────
|
|
24
|
-
|
|
25
|
-
interface TfIdfDocument {
|
|
26
|
-
entry: ScoredEntry
|
|
27
|
-
termFreqs: Map<string, number>
|
|
28
|
-
magnitude: number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface SerializedTfIdf {
|
|
32
|
-
idf: Record<string, number>
|
|
33
|
-
docs: Array<{
|
|
34
|
-
id: string
|
|
35
|
-
termFreqs: Record<string, number>
|
|
36
|
-
magnitude: number
|
|
37
|
-
}>
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export class TfIdfAdapter implements SearchAdapter {
|
|
41
|
-
private documents: TfIdfDocument[] = []
|
|
42
|
-
private idf: Map<string, number> = new Map()
|
|
43
|
-
private entries: ScoredEntry[] = []
|
|
44
|
-
|
|
45
|
-
buildIndex(entries: ScoredEntry[]): void {
|
|
46
|
-
this.entries = entries
|
|
47
|
-
const docCount = entries.length
|
|
48
|
-
if (docCount === 0) return
|
|
49
|
-
|
|
50
|
-
// Compute term frequencies per document
|
|
51
|
-
const docFreqs = new Map<string, number>()
|
|
52
|
-
this.documents = entries.map((entry) => {
|
|
53
|
-
const tokens = tokenize(entry.text)
|
|
54
|
-
const termFreqs = new Map<string, number>()
|
|
55
|
-
|
|
56
|
-
for (const token of tokens) {
|
|
57
|
-
termFreqs.set(token, (termFreqs.get(token) || 0) + 1)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Track document frequency for IDF
|
|
61
|
-
for (const term of termFreqs.keys()) {
|
|
62
|
-
docFreqs.set(term, (docFreqs.get(term) || 0) + 1)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return { entry, termFreqs, magnitude: 0 }
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
// Compute IDF: log(N / df)
|
|
69
|
-
this.idf = new Map()
|
|
70
|
-
for (const [term, df] of docFreqs) {
|
|
71
|
-
this.idf.set(term, Math.log(docCount / df))
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Compute document magnitudes for cosine similarity
|
|
75
|
-
for (const doc of this.documents) {
|
|
76
|
-
let sumSq = 0
|
|
77
|
-
for (const [term, tf] of doc.termFreqs) {
|
|
78
|
-
const idf = this.idf.get(term) || 0
|
|
79
|
-
const tfidf = tf * idf
|
|
80
|
-
sumSq += tfidf * tfidf
|
|
81
|
-
}
|
|
82
|
-
doc.magnitude = Math.sqrt(sumSq)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
search(query: string, limit: number, typeFilter?: string): ScoredResult[] {
|
|
87
|
-
if (this.documents.length === 0) return []
|
|
88
|
-
|
|
89
|
-
const queryTokens = tokenize(query.toLowerCase())
|
|
90
|
-
if (queryTokens.length === 0) {
|
|
91
|
-
// Empty query: return all, sorted by type
|
|
92
|
-
return this.documents
|
|
93
|
-
.filter((d) => !typeFilter || typeFilter === "any" || d.entry.entry.type === typeFilter)
|
|
94
|
-
.slice(0, limit)
|
|
95
|
-
.map((d) => ({
|
|
96
|
-
entry: d.entry.entry,
|
|
97
|
-
path: d.entry.path,
|
|
98
|
-
score: 1,
|
|
99
|
-
}))
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Build query TF-IDF vector
|
|
103
|
-
const queryTermFreqs = new Map<string, number>()
|
|
104
|
-
for (const token of queryTokens) {
|
|
105
|
-
queryTermFreqs.set(token, (queryTermFreqs.get(token) || 0) + 1)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
let queryMagnitude = 0
|
|
109
|
-
const queryVector = new Map<string, number>()
|
|
110
|
-
for (const [term, tf] of queryTermFreqs) {
|
|
111
|
-
const idf = this.idf.get(term) || 0
|
|
112
|
-
const tfidf = tf * idf
|
|
113
|
-
queryVector.set(term, tfidf)
|
|
114
|
-
queryMagnitude += tfidf * tfidf
|
|
115
|
-
}
|
|
116
|
-
queryMagnitude = Math.sqrt(queryMagnitude)
|
|
117
|
-
|
|
118
|
-
if (queryMagnitude === 0) {
|
|
119
|
-
// All query terms are unknown — fallback to substring match
|
|
120
|
-
return this.substringFallback(query, limit, typeFilter)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const results: ScoredResult[] = []
|
|
124
|
-
const querySet = new Set(queryTokens)
|
|
125
|
-
|
|
126
|
-
for (const doc of this.documents) {
|
|
127
|
-
if (typeFilter && typeFilter !== "any" && doc.entry.entry.type !== typeFilter) continue
|
|
128
|
-
|
|
129
|
-
// Cosine similarity
|
|
130
|
-
let dotProduct = 0
|
|
131
|
-
for (const [term, queryTfidf] of queryVector) {
|
|
132
|
-
const docTf = doc.termFreqs.get(term) || 0
|
|
133
|
-
if (docTf === 0) continue
|
|
134
|
-
const docIdf = this.idf.get(term) || 0
|
|
135
|
-
dotProduct += queryTfidf * (docTf * docIdf)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
let score = doc.magnitude > 0 && queryMagnitude > 0
|
|
139
|
-
? dotProduct / (doc.magnitude * queryMagnitude)
|
|
140
|
-
: 0
|
|
141
|
-
|
|
142
|
-
// Boost: tag exact match
|
|
143
|
-
const tags = doc.entry.entry.tags || []
|
|
144
|
-
for (const tag of tags) {
|
|
145
|
-
if (querySet.has(tag.toLowerCase())) {
|
|
146
|
-
score += 0.15
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Boost: intent phrase contains query token
|
|
151
|
-
const intents = doc.entry.entry.intents || []
|
|
152
|
-
for (const intent of intents) {
|
|
153
|
-
const intentLower = intent.toLowerCase()
|
|
154
|
-
for (const token of queryTokens) {
|
|
155
|
-
if (intentLower.includes(token)) {
|
|
156
|
-
score += 0.12
|
|
157
|
-
break // one boost per intent phrase
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Boost: name contains query token
|
|
163
|
-
const nameLower = doc.entry.entry.name.toLowerCase().replace(/[-_]/g, " ")
|
|
164
|
-
for (const token of queryTokens) {
|
|
165
|
-
if (nameLower.includes(token)) {
|
|
166
|
-
score += 0.1
|
|
167
|
-
break
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (score > 0) {
|
|
172
|
-
results.push({
|
|
173
|
-
entry: doc.entry.entry,
|
|
174
|
-
path: doc.entry.path,
|
|
175
|
-
score: Math.round(score * 1000) / 1000,
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
results.sort((a, b) => b.score - a.score)
|
|
181
|
-
return results.slice(0, limit)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
serialize(): SerializedTfIdf {
|
|
185
|
-
const idf: Record<string, number> = {}
|
|
186
|
-
for (const [term, val] of this.idf) {
|
|
187
|
-
idf[term] = val
|
|
188
|
-
}
|
|
189
|
-
const docs = this.documents.map((d) => {
|
|
190
|
-
const termFreqs: Record<string, number> = {}
|
|
191
|
-
for (const [term, tf] of d.termFreqs) {
|
|
192
|
-
termFreqs[term] = tf
|
|
193
|
-
}
|
|
194
|
-
return { id: d.entry.id, termFreqs, magnitude: d.magnitude }
|
|
195
|
-
})
|
|
196
|
-
return { idf, docs }
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
static deserialize(data: SerializedTfIdf, entries: ScoredEntry[]): TfIdfAdapter {
|
|
200
|
-
const adapter = new TfIdfAdapter()
|
|
201
|
-
adapter.entries = entries
|
|
202
|
-
|
|
203
|
-
adapter.idf = new Map(Object.entries(data.idf))
|
|
204
|
-
|
|
205
|
-
const entryMap = new Map(entries.map((e) => [e.id, e]))
|
|
206
|
-
adapter.documents = data.docs
|
|
207
|
-
.map((d) => {
|
|
208
|
-
const entry = entryMap.get(d.id)
|
|
209
|
-
if (!entry) return null
|
|
210
|
-
return {
|
|
211
|
-
entry,
|
|
212
|
-
termFreqs: new Map(Object.entries(d.termFreqs)),
|
|
213
|
-
magnitude: d.magnitude,
|
|
214
|
-
}
|
|
215
|
-
})
|
|
216
|
-
.filter((d): d is TfIdfDocument => d !== null)
|
|
217
|
-
|
|
218
|
-
return adapter
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
private substringFallback(query: string, limit: number, typeFilter?: string): ScoredResult[] {
|
|
222
|
-
const q = query.toLowerCase()
|
|
223
|
-
const tokens = tokenize(q)
|
|
224
|
-
return this.documents
|
|
225
|
-
.map((d) => {
|
|
226
|
-
if (typeFilter && typeFilter !== "any" && d.entry.entry.type !== typeFilter) return null
|
|
227
|
-
// Check if any query token matches the document text or name
|
|
228
|
-
const text = d.entry.text
|
|
229
|
-
const name = d.entry.entry.name.toLowerCase()
|
|
230
|
-
let matchCount = 0
|
|
231
|
-
for (const token of tokens) {
|
|
232
|
-
if (text.includes(token) || name.includes(token)) matchCount++
|
|
233
|
-
}
|
|
234
|
-
// Also check full substring match
|
|
235
|
-
if (text.includes(q) || name.includes(q)) matchCount = Math.max(matchCount, tokens.length)
|
|
236
|
-
if (matchCount === 0) return null
|
|
237
|
-
return {
|
|
238
|
-
entry: d.entry.entry,
|
|
239
|
-
path: d.entry.path,
|
|
240
|
-
score: Math.round((matchCount / Math.max(tokens.length, 1)) * 500) / 1000,
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
|
-
.filter((d): d is ScoredResult => d !== null)
|
|
244
|
-
.sort((a, b) => b.score - a.score)
|
|
245
|
-
.slice(0, limit)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ── Tokenization ────────────────────────────────────────────────────────────
|
|
250
|
-
|
|
251
|
-
const STOP_WORDS = new Set([
|
|
252
|
-
"a", "an", "the", "is", "are", "was", "were", "be", "been", "being",
|
|
253
|
-
"have", "has", "had", "do", "does", "did", "will", "would", "could",
|
|
254
|
-
"should", "may", "might", "shall", "can", "need", "dare", "ought",
|
|
255
|
-
"to", "of", "in", "for", "on", "with", "at", "by", "from", "as",
|
|
256
|
-
"into", "through", "during", "before", "after", "above", "below",
|
|
257
|
-
"and", "but", "or", "nor", "not", "so", "yet", "both", "either",
|
|
258
|
-
"neither", "each", "every", "all", "any", "few", "more", "most",
|
|
259
|
-
"other", "some", "such", "no", "only", "own", "same", "than",
|
|
260
|
-
"too", "very", "just", "because", "if", "when", "where", "how",
|
|
261
|
-
"what", "which", "who", "whom", "this", "that", "these", "those",
|
|
262
|
-
"it", "its",
|
|
263
|
-
])
|
|
264
|
-
|
|
265
|
-
function tokenize(text: string): string[] {
|
|
266
|
-
return text
|
|
267
|
-
.toLowerCase()
|
|
268
|
-
.replace(/[^a-z0-9]+/g, " ")
|
|
269
|
-
.split(/\s+/)
|
|
270
|
-
.filter((t) => t.length > 1 && !STOP_WORDS.has(t))
|
|
271
|
-
}
|