agentikit 0.0.13 → 0.0.15
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 +385 -0
- package/README.md +187 -110
- package/dist/{src/asset-spec.js → asset-spec.js} +11 -2
- package/dist/{src/asset-type-handler.js → asset-type-handler.js} +4 -3
- package/dist/cli.js +709 -0
- package/dist/common.js +192 -0
- package/dist/{src/config-cli.js → config-cli.js} +36 -30
- package/dist/{src/config.js → config.js} +95 -25
- package/dist/{src/db.js → db.js} +123 -51
- package/dist/{src/embedder.js → embedder.js} +57 -2
- package/dist/errors.js +28 -0
- package/dist/file-context.js +188 -0
- package/dist/{src/frontmatter.js → frontmatter.js} +1 -1
- package/dist/{src/github.js → github.js} +1 -3
- package/dist/handlers/agent-handler.js +19 -0
- package/dist/handlers/command-handler.js +20 -0
- package/dist/handlers/handler-bridge.js +51 -0
- package/dist/handlers/index.js +19 -0
- package/dist/handlers/knowledge-handler.js +32 -0
- package/dist/handlers/script-handler.js +42 -0
- package/dist/{src/handlers → handlers}/skill-handler.js +5 -6
- package/dist/{src/handlers → handlers}/tool-handler.js +8 -24
- package/dist/{src/indexer.js → indexer.js} +50 -26
- package/dist/init.js +43 -0
- package/dist/{src/llm.js → llm.js} +6 -11
- package/dist/lockfile.js +60 -0
- package/dist/matchers.js +163 -0
- package/dist/{src/metadata.js → metadata.js} +36 -16
- package/dist/{src/origin-resolve.js → origin-resolve.js} +10 -9
- package/dist/paths.js +83 -0
- package/dist/{src/registry-install.js → registry-install.js} +151 -19
- package/dist/{src/registry-resolve.js → registry-resolve.js} +190 -26
- package/dist/{src/registry-search.js → registry-search.js} +13 -21
- package/dist/renderers.js +286 -0
- package/dist/{src/ripgrep-install.js → ripgrep-install.js} +8 -27
- package/dist/{src/ripgrep-resolve.js → ripgrep-resolve.js} +21 -11
- package/dist/ripgrep.js +2 -0
- package/dist/self-update.js +226 -0
- package/dist/{src/stash-add.js → stash-add.js} +14 -4
- package/dist/stash-clone.js +115 -0
- package/dist/{src/stash-ref.js → stash-ref.js} +10 -9
- package/dist/{src/stash-registry.js → stash-registry.js} +21 -46
- package/dist/{src/stash-resolve.js → stash-resolve.js} +10 -9
- package/dist/{src/stash-search.js → stash-search.js} +89 -74
- package/dist/stash-show.js +74 -0
- package/dist/stash-source.js +127 -0
- package/dist/submit.js +557 -0
- package/dist/{src/tool-runner.js → tool-runner.js} +1 -5
- package/dist/{src/walker.js → walker.js} +38 -0
- package/dist/warn.js +20 -0
- package/package.json +13 -18
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -15
- package/dist/src/asset-spec.d.ts +0 -16
- package/dist/src/asset-type-handler.d.ts +0 -27
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.js +0 -399
- package/dist/src/common.d.ts +0 -13
- package/dist/src/common.js +0 -60
- package/dist/src/config-cli.d.ts +0 -9
- package/dist/src/config.d.ts +0 -50
- package/dist/src/db.d.ts +0 -46
- package/dist/src/embedder.d.ts +0 -10
- package/dist/src/frontmatter.d.ts +0 -30
- package/dist/src/github.d.ts +0 -4
- package/dist/src/handlers/agent-handler.d.ts +0 -2
- package/dist/src/handlers/agent-handler.js +0 -26
- package/dist/src/handlers/command-handler.d.ts +0 -2
- package/dist/src/handlers/command-handler.js +0 -23
- package/dist/src/handlers/index.d.ts +0 -6
- package/dist/src/handlers/index.js +0 -23
- package/dist/src/handlers/knowledge-handler.d.ts +0 -2
- package/dist/src/handlers/knowledge-handler.js +0 -56
- package/dist/src/handlers/markdown-helpers.d.ts +0 -7
- package/dist/src/handlers/script-handler.d.ts +0 -2
- package/dist/src/handlers/script-handler.js +0 -78
- package/dist/src/handlers/skill-handler.d.ts +0 -2
- package/dist/src/handlers/tool-handler.d.ts +0 -2
- package/dist/src/indexer.d.ts +0 -22
- package/dist/src/init.d.ts +0 -19
- package/dist/src/init.js +0 -99
- package/dist/src/llm.d.ts +0 -15
- package/dist/src/markdown.d.ts +0 -18
- package/dist/src/metadata.d.ts +0 -41
- package/dist/src/origin-resolve.d.ts +0 -19
- package/dist/src/registry-install.d.ts +0 -11
- package/dist/src/registry-resolve.d.ts +0 -3
- package/dist/src/registry-search.d.ts +0 -27
- package/dist/src/registry-types.d.ts +0 -62
- package/dist/src/ripgrep-install.d.ts +0 -12
- package/dist/src/ripgrep-resolve.d.ts +0 -13
- package/dist/src/ripgrep.d.ts +0 -3
- package/dist/src/ripgrep.js +0 -2
- package/dist/src/stash-add.d.ts +0 -4
- package/dist/src/stash-clone.d.ts +0 -22
- package/dist/src/stash-clone.js +0 -83
- package/dist/src/stash-ref.d.ts +0 -31
- package/dist/src/stash-registry.d.ts +0 -18
- package/dist/src/stash-resolve.d.ts +0 -2
- package/dist/src/stash-search.d.ts +0 -8
- package/dist/src/stash-show.d.ts +0 -5
- package/dist/src/stash-show.js +0 -46
- package/dist/src/stash-source.d.ts +0 -24
- package/dist/src/stash-source.js +0 -81
- package/dist/src/stash-types.d.ts +0 -227
- package/dist/src/stash.d.ts +0 -16
- package/dist/src/stash.js +0 -9
- package/dist/src/tool-runner.d.ts +0 -35
- package/dist/src/walker.d.ts +0 -19
- package/src/asset-spec.ts +0 -85
- package/src/asset-type-handler.ts +0 -77
- package/src/cli.ts +0 -427
- package/src/common.ts +0 -76
- package/src/config-cli.ts +0 -499
- package/src/config.ts +0 -305
- package/src/db.ts +0 -411
- package/src/embedder.ts +0 -128
- package/src/frontmatter.ts +0 -95
- package/src/github.ts +0 -21
- package/src/handlers/agent-handler.ts +0 -32
- package/src/handlers/command-handler.ts +0 -29
- package/src/handlers/index.ts +0 -25
- package/src/handlers/knowledge-handler.ts +0 -62
- package/src/handlers/markdown-helpers.ts +0 -19
- package/src/handlers/script-handler.ts +0 -92
- package/src/handlers/skill-handler.ts +0 -37
- package/src/handlers/tool-handler.ts +0 -71
- package/src/indexer.ts +0 -392
- package/src/init.ts +0 -114
- package/src/llm.ts +0 -125
- package/src/markdown.ts +0 -106
- package/src/metadata.ts +0 -333
- package/src/origin-resolve.ts +0 -67
- package/src/registry-install.ts +0 -361
- package/src/registry-resolve.ts +0 -341
- package/src/registry-search.ts +0 -335
- package/src/registry-types.ts +0 -72
- package/src/ripgrep-install.ts +0 -200
- package/src/ripgrep-resolve.ts +0 -72
- package/src/ripgrep.ts +0 -3
- package/src/stash-add.ts +0 -63
- package/src/stash-clone.ts +0 -127
- package/src/stash-ref.ts +0 -99
- package/src/stash-registry.ts +0 -259
- package/src/stash-resolve.ts +0 -50
- package/src/stash-search.ts +0 -613
- package/src/stash-show.ts +0 -55
- package/src/stash-source.ts +0 -103
- package/src/stash-types.ts +0 -231
- package/src/stash.ts +0 -39
- package/src/tool-runner.ts +0 -142
- package/src/walker.ts +0 -53
- /package/dist/{src/handlers → handlers}/markdown-helpers.js +0 -0
- /package/dist/{src/markdown.js → markdown.js} +0 -0
- /package/dist/{src/registry-types.js → registry-types.js} +0 -0
- /package/dist/{src/stash-types.js → stash-types.js} +0 -0
package/src/config.ts
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs"
|
|
2
|
-
import path from "node:path"
|
|
3
|
-
import type { RegistryInstalledEntry, RegistrySource } from "./registry-types"
|
|
4
|
-
|
|
5
|
-
// ── Types ───────────────────────────────────────────────────────────────────
|
|
6
|
-
|
|
7
|
-
export interface EmbeddingConnectionConfig {
|
|
8
|
-
/** Provider name for display/CLI switching (e.g. "openai", "ollama") */
|
|
9
|
-
provider?: string
|
|
10
|
-
/** OpenAI-compatible embeddings endpoint (e.g. "http://localhost:11434/v1/embeddings") */
|
|
11
|
-
endpoint: string
|
|
12
|
-
/** Model name to use for embeddings (e.g. "nomic-embed-text") */
|
|
13
|
-
model: string
|
|
14
|
-
/** Optional output dimension for providers that support it */
|
|
15
|
-
dimension?: number
|
|
16
|
-
/** Optional API key for authenticated endpoints */
|
|
17
|
-
apiKey?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface LlmConnectionConfig {
|
|
21
|
-
/** Provider name for display/CLI switching (e.g. "openai", "ollama") */
|
|
22
|
-
provider?: string
|
|
23
|
-
/** OpenAI-compatible chat completions endpoint (e.g. "http://localhost:11434/v1/chat/completions") */
|
|
24
|
-
endpoint: string
|
|
25
|
-
/** Model name to use (e.g. "llama3.2") */
|
|
26
|
-
model: string
|
|
27
|
-
/** Optional sampling temperature */
|
|
28
|
-
temperature?: number
|
|
29
|
-
/** Optional response token limit */
|
|
30
|
-
maxTokens?: number
|
|
31
|
-
/** Optional API key for authenticated endpoints */
|
|
32
|
-
apiKey?: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface AgentikitConfig {
|
|
36
|
-
/** Whether semantic search is enabled. Default: true */
|
|
37
|
-
semanticSearch: boolean
|
|
38
|
-
/** User-mounted read-only stash directories */
|
|
39
|
-
mountedStashDirs: string[]
|
|
40
|
-
/** OpenAI-compatible embedding endpoint config. If not set, uses local @xenova/transformers */
|
|
41
|
-
embedding?: EmbeddingConnectionConfig
|
|
42
|
-
/** OpenAI-compatible LLM endpoint config for metadata generation. If not set, uses heuristic generation */
|
|
43
|
-
llm?: LlmConnectionConfig
|
|
44
|
-
/** Installed registry sources and local cache metadata */
|
|
45
|
-
registry?: RegistryConfig
|
|
46
|
-
/** Registry index URLs for kit discovery. Default: official agentikit-registry on GitHub */
|
|
47
|
-
registryUrls?: string[]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface RegistryConfig {
|
|
51
|
-
installed: RegistryInstalledEntry[]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// ── Defaults ────────────────────────────────────────────────────────────────
|
|
55
|
-
|
|
56
|
-
export const DEFAULT_CONFIG: AgentikitConfig = {
|
|
57
|
-
semanticSearch: true,
|
|
58
|
-
mountedStashDirs: [],
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ── Paths ───────────────────────────────────────────────────────────────────
|
|
62
|
-
|
|
63
|
-
export function getConfigDir(
|
|
64
|
-
env: NodeJS.ProcessEnv = process.env,
|
|
65
|
-
platform = process.platform,
|
|
66
|
-
): string {
|
|
67
|
-
if (platform === "win32") {
|
|
68
|
-
const appData = env.APPDATA?.trim()
|
|
69
|
-
if (appData) return path.join(appData, "agentikit")
|
|
70
|
-
|
|
71
|
-
const userProfile = env.USERPROFILE?.trim()
|
|
72
|
-
if (!userProfile) {
|
|
73
|
-
throw new Error("Unable to determine config directory. Set APPDATA or USERPROFILE.")
|
|
74
|
-
}
|
|
75
|
-
return path.join(userProfile, "AppData", "Roaming", "agentikit")
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const xdgConfigHome = env.XDG_CONFIG_HOME?.trim()
|
|
79
|
-
if (xdgConfigHome) return path.join(xdgConfigHome, "agentikit")
|
|
80
|
-
|
|
81
|
-
const home = env.HOME?.trim()
|
|
82
|
-
if (!home) {
|
|
83
|
-
throw new Error("Unable to determine config directory. Set XDG_CONFIG_HOME or HOME.")
|
|
84
|
-
}
|
|
85
|
-
return path.join(home, ".config", "agentikit")
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function getConfigPath(): string {
|
|
89
|
-
return path.join(getConfigDir(), "config.json")
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// ── Load / Save / Update ────────────────────────────────────────────────────
|
|
93
|
-
|
|
94
|
-
export function loadConfig(): AgentikitConfig {
|
|
95
|
-
const configPath = getConfigPath()
|
|
96
|
-
const raw = readConfigObject(configPath)
|
|
97
|
-
const config = raw ? pickKnownKeys(raw) : { ...DEFAULT_CONFIG }
|
|
98
|
-
|
|
99
|
-
// Inject API keys from environment variables.
|
|
100
|
-
// API keys should be provided via AKM_EMBED_API_KEY and AKM_LLM_API_KEY
|
|
101
|
-
// rather than stored in the config file.
|
|
102
|
-
if (config.embedding && !config.embedding.apiKey) {
|
|
103
|
-
const envKey = process.env.AKM_EMBED_API_KEY?.trim()
|
|
104
|
-
if (envKey) config.embedding.apiKey = envKey
|
|
105
|
-
}
|
|
106
|
-
if (config.llm && !config.llm.apiKey) {
|
|
107
|
-
const envKey = process.env.AKM_LLM_API_KEY?.trim()
|
|
108
|
-
if (envKey) config.llm.apiKey = envKey
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return config
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function saveConfig(config: AgentikitConfig): void {
|
|
115
|
-
const configPath = getConfigPath()
|
|
116
|
-
const dir = path.dirname(configPath)
|
|
117
|
-
fs.mkdirSync(dir, { recursive: true })
|
|
118
|
-
const sanitized = sanitizeConfigForWrite(config)
|
|
119
|
-
const tmpPath = configPath + `.tmp.${process.pid}`
|
|
120
|
-
try {
|
|
121
|
-
fs.writeFileSync(tmpPath, JSON.stringify(sanitized, null, 2) + "\n", "utf8")
|
|
122
|
-
fs.renameSync(tmpPath, configPath)
|
|
123
|
-
} catch (err) {
|
|
124
|
-
try { fs.unlinkSync(tmpPath) } catch { /* ignore cleanup failure */ }
|
|
125
|
-
throw err
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Strip apiKey fields before writing config to disk.
|
|
131
|
-
* API keys should be provided via environment variables
|
|
132
|
-
* AKM_EMBED_API_KEY and AKM_LLM_API_KEY.
|
|
133
|
-
*/
|
|
134
|
-
function sanitizeConfigForWrite(config: AgentikitConfig): AgentikitConfig {
|
|
135
|
-
const sanitized = { ...config }
|
|
136
|
-
if (sanitized.embedding) {
|
|
137
|
-
const { apiKey, ...rest } = sanitized.embedding
|
|
138
|
-
sanitized.embedding = rest as EmbeddingConnectionConfig
|
|
139
|
-
}
|
|
140
|
-
if (sanitized.llm) {
|
|
141
|
-
const { apiKey, ...rest } = sanitized.llm
|
|
142
|
-
sanitized.llm = rest as LlmConnectionConfig
|
|
143
|
-
}
|
|
144
|
-
return sanitized
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function updateConfig(partial: Partial<AgentikitConfig>): AgentikitConfig {
|
|
148
|
-
const current = loadConfig()
|
|
149
|
-
const merged: AgentikitConfig = { ...current, ...partial }
|
|
150
|
-
saveConfig(merged)
|
|
151
|
-
return merged
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
155
|
-
|
|
156
|
-
function pickKnownKeys(raw: Record<string, unknown>): AgentikitConfig {
|
|
157
|
-
const config: AgentikitConfig = { ...DEFAULT_CONFIG }
|
|
158
|
-
|
|
159
|
-
if (typeof raw.semanticSearch === "boolean") {
|
|
160
|
-
config.semanticSearch = raw.semanticSearch
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (Array.isArray(raw.mountedStashDirs)) {
|
|
164
|
-
config.mountedStashDirs = raw.mountedStashDirs.filter(
|
|
165
|
-
(d): d is string => typeof d === "string",
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const embedding = parseEmbeddingConfig(raw.embedding)
|
|
170
|
-
if (embedding) config.embedding = embedding
|
|
171
|
-
|
|
172
|
-
const llm = parseLlmConfig(raw.llm)
|
|
173
|
-
if (llm) config.llm = llm
|
|
174
|
-
|
|
175
|
-
const registry = parseRegistryConfig(raw.registry)
|
|
176
|
-
if (registry) config.registry = registry
|
|
177
|
-
|
|
178
|
-
if (Array.isArray(raw.registryUrls)) {
|
|
179
|
-
config.registryUrls = raw.registryUrls.filter(
|
|
180
|
-
(u): u is string => typeof u === "string" && u.startsWith("http"),
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return config
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function readConfigObject(configPath: string): Record<string, unknown> | undefined {
|
|
188
|
-
try {
|
|
189
|
-
const raw = JSON.parse(fs.readFileSync(configPath, "utf8"))
|
|
190
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return undefined
|
|
191
|
-
return raw
|
|
192
|
-
} catch {
|
|
193
|
-
return undefined
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function parseEmbeddingConfig(value: unknown): EmbeddingConnectionConfig | undefined {
|
|
198
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
|
|
199
|
-
const obj = value as Record<string, unknown>
|
|
200
|
-
if (typeof obj.endpoint !== "string" || !obj.endpoint) return undefined
|
|
201
|
-
if (typeof obj.model !== "string" || !obj.model) return undefined
|
|
202
|
-
const result: EmbeddingConnectionConfig = {
|
|
203
|
-
endpoint: obj.endpoint,
|
|
204
|
-
model: obj.model,
|
|
205
|
-
}
|
|
206
|
-
if (typeof obj.provider === "string" && obj.provider) {
|
|
207
|
-
result.provider = obj.provider
|
|
208
|
-
}
|
|
209
|
-
if ("dimension" in obj) {
|
|
210
|
-
if (
|
|
211
|
-
typeof obj.dimension !== "number" ||
|
|
212
|
-
!Number.isFinite(obj.dimension) ||
|
|
213
|
-
!Number.isInteger(obj.dimension) ||
|
|
214
|
-
obj.dimension <= 0
|
|
215
|
-
) {
|
|
216
|
-
return undefined
|
|
217
|
-
}
|
|
218
|
-
result.dimension = obj.dimension
|
|
219
|
-
}
|
|
220
|
-
if (typeof obj.apiKey === "string" && obj.apiKey) {
|
|
221
|
-
result.apiKey = obj.apiKey
|
|
222
|
-
}
|
|
223
|
-
return result
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function parseLlmConfig(value: unknown): LlmConnectionConfig | undefined {
|
|
227
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
|
|
228
|
-
const obj = value as Record<string, unknown>
|
|
229
|
-
if (typeof obj.endpoint !== "string" || !obj.endpoint) return undefined
|
|
230
|
-
if (typeof obj.model !== "string" || !obj.model) return undefined
|
|
231
|
-
const result: LlmConnectionConfig = {
|
|
232
|
-
endpoint: obj.endpoint,
|
|
233
|
-
model: obj.model,
|
|
234
|
-
}
|
|
235
|
-
if (typeof obj.provider === "string" && obj.provider) {
|
|
236
|
-
result.provider = obj.provider
|
|
237
|
-
}
|
|
238
|
-
if (typeof obj.temperature === "number" && Number.isFinite(obj.temperature)) {
|
|
239
|
-
result.temperature = obj.temperature
|
|
240
|
-
}
|
|
241
|
-
if ("maxTokens" in obj) {
|
|
242
|
-
if (
|
|
243
|
-
typeof obj.maxTokens !== "number" ||
|
|
244
|
-
!Number.isFinite(obj.maxTokens) ||
|
|
245
|
-
!Number.isInteger(obj.maxTokens) ||
|
|
246
|
-
obj.maxTokens <= 0
|
|
247
|
-
) {
|
|
248
|
-
return undefined
|
|
249
|
-
}
|
|
250
|
-
result.maxTokens = obj.maxTokens
|
|
251
|
-
}
|
|
252
|
-
if (typeof obj.apiKey === "string" && obj.apiKey) {
|
|
253
|
-
result.apiKey = obj.apiKey
|
|
254
|
-
}
|
|
255
|
-
return result
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function parseRegistryConfig(value: unknown): RegistryConfig | undefined {
|
|
259
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
|
|
260
|
-
const obj = value as Record<string, unknown>
|
|
261
|
-
if (!Array.isArray(obj.installed)) return undefined
|
|
262
|
-
|
|
263
|
-
const installed = obj.installed
|
|
264
|
-
.map((entry) => parseRegistryInstalledEntry(entry))
|
|
265
|
-
.filter((entry): entry is RegistryInstalledEntry => entry !== undefined)
|
|
266
|
-
|
|
267
|
-
return { installed }
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function parseRegistryInstalledEntry(value: unknown): RegistryInstalledEntry | undefined {
|
|
271
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined
|
|
272
|
-
const obj = value as Record<string, unknown>
|
|
273
|
-
|
|
274
|
-
const id = asNonEmptyString(obj.id)
|
|
275
|
-
const source = asRegistrySource(obj.source)
|
|
276
|
-
const ref = asNonEmptyString(obj.ref)
|
|
277
|
-
const artifactUrl = asNonEmptyString(obj.artifactUrl)
|
|
278
|
-
const stashRoot = asNonEmptyString(obj.stashRoot)
|
|
279
|
-
const cacheDir = asNonEmptyString(obj.cacheDir)
|
|
280
|
-
const installedAt = asNonEmptyString(obj.installedAt)
|
|
281
|
-
if (!id || !source || !ref || !artifactUrl || !stashRoot || !cacheDir || !installedAt) return undefined
|
|
282
|
-
|
|
283
|
-
const entry: RegistryInstalledEntry = {
|
|
284
|
-
id,
|
|
285
|
-
source,
|
|
286
|
-
ref,
|
|
287
|
-
artifactUrl,
|
|
288
|
-
stashRoot,
|
|
289
|
-
cacheDir,
|
|
290
|
-
installedAt,
|
|
291
|
-
}
|
|
292
|
-
const resolvedVersion = asNonEmptyString(obj.resolvedVersion)
|
|
293
|
-
if (resolvedVersion) entry.resolvedVersion = resolvedVersion
|
|
294
|
-
const resolvedRevision = asNonEmptyString(obj.resolvedRevision)
|
|
295
|
-
if (resolvedRevision) entry.resolvedRevision = resolvedRevision
|
|
296
|
-
return entry
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function asNonEmptyString(value: unknown): string | undefined {
|
|
300
|
-
return typeof value === "string" && value ? value : undefined
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function asRegistrySource(value: unknown): RegistrySource | undefined {
|
|
304
|
-
return value === "npm" || value === "github" || value === "git" ? value : undefined
|
|
305
|
-
}
|