@arcforge/platform 2.0.166
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 +31 -0
- package/package.json +69 -0
- package/src/bin/supervisor.ts +102 -0
- package/src/bin/test-api.ts +30 -0
- package/src/bin/test-preload.ts +308 -0
- package/src/bin/update-helper.ts +32 -0
- package/src/build/bench/CLAUDE.md +106 -0
- package/src/build/bench/SPEC.md +209 -0
- package/src/build/bench/agents.ts +105 -0
- package/src/build/bench/axes.ts +84 -0
- package/src/build/bench/bench.ts +96 -0
- package/src/build/bench/discover.ts +147 -0
- package/src/build/bench/index.ts +7 -0
- package/src/build/bench/log.ts +47 -0
- package/src/build/bench/matrix.ts +23 -0
- package/src/build/bench/preload.ts +440 -0
- package/src/build/bench/prepare.ts +61 -0
- package/src/build/bench/projection.ts +112 -0
- package/src/build/bench/resolve.ts +54 -0
- package/src/build/bench/runner.ts +309 -0
- package/src/build/bench/schema/extract.ts +148 -0
- package/src/build/bench/schema/index.ts +2 -0
- package/src/build/bench/schema/schema.ts +95 -0
- package/src/build/bench/schema/worker.ts +30 -0
- package/src/build/bench/typegen.ts +119 -0
- package/src/build/bench/workspace/files.ts +139 -0
- package/src/build/bench/workspace/handle.ts +133 -0
- package/src/build/bench/workspace/index.ts +11 -0
- package/src/build/bench/workspace/workspace.ts +14 -0
- package/src/build/blueprint/blueprint.ts +398 -0
- package/src/build/blueprint/cognet/abi.ts +207 -0
- package/src/build/blueprint/cognet/bundle-worker.ts +93 -0
- package/src/build/blueprint/cognet/bundle.ts +664 -0
- package/src/build/blueprint/cognet/cognet.ts +249 -0
- package/src/build/blueprint/cognet/index.ts +10 -0
- package/src/build/blueprint/cognet/manifest.ts +38 -0
- package/src/build/blueprint/cognet/resolve.ts +113 -0
- package/src/build/blueprint/collisions.ts +51 -0
- package/src/build/blueprint/index.ts +29 -0
- package/src/build/blueprint/modules/entries.ts +117 -0
- package/src/build/blueprint/modules/index.ts +300 -0
- package/src/build/blueprint/modules/meta.ts +174 -0
- package/src/build/blueprint/scan/boot.ts +34 -0
- package/src/build/blueprint/scan/cognetImports.ts +56 -0
- package/src/build/blueprint/scan/components.ts +45 -0
- package/src/build/blueprint/scan/config.ts +234 -0
- package/src/build/blueprint/scan/configImports.ts +232 -0
- package/src/build/blueprint/scan/declare-worker.ts +61 -0
- package/src/build/blueprint/scan/declare.ts +393 -0
- package/src/build/blueprint/scan/h3-globals.ts +137 -0
- package/src/build/blueprint/scan/knowledge.ts +101 -0
- package/src/build/blueprint/scan/middleware.ts +110 -0
- package/src/build/blueprint/scan/moduleImports.ts +79 -0
- package/src/build/blueprint/scan/plugins.ts +93 -0
- package/src/build/blueprint/scan/promptPackages.ts +45 -0
- package/src/build/blueprint/scan/prompts.ts +164 -0
- package/src/build/blueprint/scan/published.ts +131 -0
- package/src/build/blueprint/scan/resolve.ts +398 -0
- package/src/build/blueprint/scan/routes.ts +109 -0
- package/src/build/blueprint/scan/scripts.ts +119 -0
- package/src/build/blueprint/scan/tool-bundle-worker.ts +69 -0
- package/src/build/blueprint/scan/tools.ts +610 -0
- package/src/build/blueprint/types.ts +28 -0
- package/src/build/extensions/config.ts +261 -0
- package/src/build/extensions/edit.ts +684 -0
- package/src/build/extensions/extensions.ts +731 -0
- package/src/build/extensions/index.ts +10 -0
- package/src/build/extensions/load.ts +350 -0
- package/src/build/extensions/registrations.ts +189 -0
- package/src/build/extensions/store.ts +200 -0
- package/src/build/frame/frame.ts +145 -0
- package/src/build/frame/index.ts +5 -0
- package/src/build/frame/migrate.ts +246 -0
- package/src/build/project/bundle/agent.ts +382 -0
- package/src/build/project/bundle/artifacts.ts +88 -0
- package/src/build/project/bundle/assets.ts +385 -0
- package/src/build/project/bundle/bundle.ts +160 -0
- package/src/build/project/bundle/imports.ts +102 -0
- package/src/build/project/bundle/index.ts +16 -0
- package/src/build/project/bundle/module.ts +130 -0
- package/src/build/project/bundle/source.ts +136 -0
- package/src/build/project/bundle/stage.ts +97 -0
- package/src/build/project/bundle/types.ts +111 -0
- package/src/build/project/cognet.ts +156 -0
- package/src/build/project/create/agent.ts +52 -0
- package/src/build/project/create/bench.ts +81 -0
- package/src/build/project/create/cognet.ts +102 -0
- package/src/build/project/create/extension.ts +63 -0
- package/src/build/project/create/module.ts +43 -0
- package/src/build/project/create/profile.ts +102 -0
- package/src/build/project/create/prompt.ts +68 -0
- package/src/build/project/create/templates.ts +88 -0
- package/src/build/project/deploy.ts +96 -0
- package/src/build/project/index.ts +40 -0
- package/src/build/project/installer.ts +616 -0
- package/src/build/project/kinds.ts +374 -0
- package/src/build/project/links.ts +33 -0
- package/src/build/project/manifest/bunfig.ts +139 -0
- package/src/build/project/manifest/config.ts +246 -0
- package/src/build/project/manifest/env.ts +184 -0
- package/src/build/project/manifest/index.ts +9 -0
- package/src/build/project/manifest/manifest.ts +49 -0
- package/src/build/project/manifest/model.ts +124 -0
- package/src/build/project/manifest/package.ts +386 -0
- package/src/build/project/manifest/text.ts +19 -0
- package/src/build/project/models/fetch.ts +123 -0
- package/src/build/project/models/index.ts +8 -0
- package/src/build/project/models/models.ts +111 -0
- package/src/build/project/models/specifier.ts +106 -0
- package/src/build/project/models/store.ts +202 -0
- package/src/build/project/modules/hash.ts +31 -0
- package/src/build/project/modules/index.ts +5 -0
- package/src/build/project/modules/lock.ts +78 -0
- package/src/build/project/modules/modules.ts +155 -0
- package/src/build/project/prepare.ts +709 -0
- package/src/build/project/project.ts +253 -0
- package/src/build/project/projects.ts +164 -0
- package/src/build/project/propagation.ts +120 -0
- package/src/build/project/publish/verify.ts +312 -0
- package/src/build/project/publish.ts +155 -0
- package/src/build/project/reconcile.ts +93 -0
- package/src/build/project/specifier.ts +42 -0
- package/src/build/project/tree.ts +615 -0
- package/src/build/project/treecache.ts +356 -0
- package/src/build/project/typegen/axon-dts.ts +362 -0
- package/src/build/project/typegen/cognet-dts.ts +91 -0
- package/src/build/project/typegen/components.ts +45 -0
- package/src/build/project/typegen/env.ts +59 -0
- package/src/build/project/typegen/generators.ts +108 -0
- package/src/build/project/typegen/hooks.ts +71 -0
- package/src/build/project/typegen/index.ts +137 -0
- package/src/build/project/typegen/prompt-dts.ts +40 -0
- package/src/build/project/typegen/prompts.ts +36 -0
- package/src/build/project/typegen/registry-dts.ts +109 -0
- package/src/build/project/typegen/scripts.ts +37 -0
- package/src/build/project/typegen/tools.ts +31 -0
- package/src/build/project/typegen/tsconfig.ts +243 -0
- package/src/build/project/typegen/tui-dts.ts +120 -0
- package/src/build/project/typegen/write.ts +40 -0
- package/src/build/project/verify.ts +268 -0
- package/src/build/project/watcher.ts +266 -0
- package/src/build/runtime/agent.ts +550 -0
- package/src/build/runtime/escalations.ts +159 -0
- package/src/build/runtime/index.ts +15 -0
- package/src/build/runtime/instances.ts +604 -0
- package/src/build/runtime/profile.ts +91 -0
- package/src/build/runtime/progress.ts +143 -0
- package/src/build/runtime/requests.ts +167 -0
- package/src/build/runtime/resolve.ts +159 -0
- package/src/build/runtime/runtime.ts +233 -0
- package/src/build/runtime/sessions/index.ts +5 -0
- package/src/build/runtime/sessions/record.ts +145 -0
- package/src/build/runtime/sessions/sessions.ts +240 -0
- package/src/build/runtime/zeno.ts +120 -0
- package/src/index.ts +11 -0
- package/src/link/agent-main.ts +395 -0
- package/src/link/index.ts +70 -0
- package/src/link/services.ts +120 -0
- package/src/platform.ts +293 -0
- package/src/procs/index.ts +15 -0
- package/src/procs/tree.ts +177 -0
- package/src/services/cloud.ts +419 -0
- package/src/services/control/client.ts +126 -0
- package/src/services/control/dispatch.ts +156 -0
- package/src/services/control/index.ts +17 -0
- package/src/services/control/protocol.ts +179 -0
- package/src/services/control/server.ts +241 -0
- package/src/services/deployments.ts +81 -0
- package/src/services/files.ts +329 -0
- package/src/services/index.ts +5 -0
- package/src/services/mic/capture.ts +248 -0
- package/src/services/mic/config.ts +109 -0
- package/src/services/mic/fft.ts +93 -0
- package/src/services/mic/index.ts +139 -0
- package/src/services/mic/visualizer.ts +46 -0
- package/src/services/ollama/catalog.ts +122 -0
- package/src/services/ollama/http.ts +124 -0
- package/src/services/ollama/index.ts +13 -0
- package/src/services/ollama/models.ts +153 -0
- package/src/services/ollama/ollama.ts +89 -0
- package/src/services/ollama/registry.ts +112 -0
- package/src/services/ollama/types.ts +72 -0
- package/src/services/prompts.ts +76 -0
- package/src/services/registry.ts +220 -0
- package/src/services/resources/hardware.ts +125 -0
- package/src/services/resources/index.ts +6 -0
- package/src/services/resources/reservations.ts +162 -0
- package/src/services/resources/resources.ts +156 -0
- package/src/services/running/index.ts +1 -0
- package/src/services/running/running.ts +200 -0
- package/src/services/store/disk.ts +97 -0
- package/src/services/store/index.ts +15 -0
- package/src/services/store/store.ts +729 -0
- package/src/services/store/types.ts +303 -0
- package/src/services/test/child.ts +150 -0
- package/src/services/test/events.ts +102 -0
- package/src/services/test/files.ts +26 -0
- package/src/services/test/frames.ts +39 -0
- package/src/services/test/index.ts +7 -0
- package/src/services/test/runner.ts +122 -0
- package/src/services/test/types.ts +26 -0
- package/src/services/update/contract.ts +77 -0
- package/src/services/update/index.ts +12 -0
- package/src/services/update/installer.ts +139 -0
- package/src/services/update/updates.ts +137 -0
- package/src/utils/fs.ts +148 -0
- package/src/utils/tsast.ts +102 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { err } from "@arcforge/err"
|
|
2
|
+
import type { HttpT } from "./http"
|
|
3
|
+
import type { LocalModel, PullProgress, RunningModel } from "./types"
|
|
4
|
+
|
|
5
|
+
type TagsResponse = {
|
|
6
|
+
models?: Array<{
|
|
7
|
+
name: string
|
|
8
|
+
size: number
|
|
9
|
+
digest: string
|
|
10
|
+
modified_at: string
|
|
11
|
+
details?: { family?: string; parameter_size?: string; quantization_level?: string }
|
|
12
|
+
}>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type PsResponse = {
|
|
16
|
+
models?: Array<{ name: string; size: number; expires_at: string }>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type PullEvent = {
|
|
20
|
+
status: string
|
|
21
|
+
/** Layer identity — the key progress is accumulated against. */
|
|
22
|
+
digest?: string
|
|
23
|
+
total?: number
|
|
24
|
+
completed?: number
|
|
25
|
+
error?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type ModelsOpts = {
|
|
29
|
+
http: HttpT
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Models — what is on this machine.
|
|
34
|
+
*
|
|
35
|
+
* Ollama owns the bytes. It keeps its own blob store under ~/.ollama/models,
|
|
36
|
+
* deduplicates layers across tags, and garbage-collects on delete — so this
|
|
37
|
+
* deliberately manages nothing on disk. Reimplementing that would mean a second
|
|
38
|
+
* store competing with the one `ollama pull` already writes to.
|
|
39
|
+
*/
|
|
40
|
+
export function Models(opts: ModelsOpts) {
|
|
41
|
+
const http = opts.http
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
/** Every model on disk, largest first — the order a user reclaiming space wants. */
|
|
45
|
+
async list(): Promise<LocalModel[]> {
|
|
46
|
+
const response = await http.json<TagsResponse>("/api/tags")
|
|
47
|
+
|
|
48
|
+
return (response.models ?? [])
|
|
49
|
+
.map(entry => ({
|
|
50
|
+
name: entry.name,
|
|
51
|
+
size: entry.size,
|
|
52
|
+
digest: entry.digest,
|
|
53
|
+
modifiedAt: entry.modified_at,
|
|
54
|
+
family: entry.details?.family ?? "unknown",
|
|
55
|
+
parameters: entry.details?.parameter_size ?? "unknown",
|
|
56
|
+
quantization: entry.details?.quantization_level ?? "unknown",
|
|
57
|
+
}))
|
|
58
|
+
.sort((a, b) => b.size - a.size)
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/** Whether this exact name is on disk. A bare name matches its `:latest` tag. */
|
|
62
|
+
async has(name: string): Promise<boolean> {
|
|
63
|
+
const qualified = name.includes(":") ? name : `${name}:latest`
|
|
64
|
+
return (await this.list()).some(model => model.name === qualified)
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
/** Models resident in memory right now — a subset of what is downloaded. */
|
|
68
|
+
async running(): Promise<RunningModel[]> {
|
|
69
|
+
const response = await http.json<PsResponse>("/api/ps")
|
|
70
|
+
|
|
71
|
+
return (response.models ?? []).map(entry => ({
|
|
72
|
+
name: entry.name,
|
|
73
|
+
size: entry.size,
|
|
74
|
+
expiresAt: entry.expires_at,
|
|
75
|
+
}))
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/** Total bytes Ollama is holding on disk. */
|
|
79
|
+
async usage(): Promise<{ count: number; bytes: number }> {
|
|
80
|
+
const models = await this.list()
|
|
81
|
+
return {
|
|
82
|
+
count: models.length,
|
|
83
|
+
bytes: models.reduce((total, model) => total + model.size, 0),
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Download a model, yielding progress as it goes.
|
|
89
|
+
*
|
|
90
|
+
* Ollama reports NDJSON: a manifest phase with no sizes, then per-layer
|
|
91
|
+
* byte counts, then verification. `percent` is null until the first
|
|
92
|
+
* total arrives, because a progress bar that starts at 0% and sits
|
|
93
|
+
* there is worse than one that admits it does not know yet.
|
|
94
|
+
*
|
|
95
|
+
* Consuming the generator IS the download — abandoning it early cancels
|
|
96
|
+
* the request. A partially pulled model leaves no usable tag; the next
|
|
97
|
+
* attempt resumes from Ollama's own layer cache.
|
|
98
|
+
*/
|
|
99
|
+
async *pull(name: string, signal?: AbortSignal): AsyncGenerator<PullProgress> {
|
|
100
|
+
// Progress is tracked ACROSS layers, not within one. Ollama reports
|
|
101
|
+
// a fresh total/completed pair per layer, so reading the newest pair
|
|
102
|
+
// alone makes percent hit 1 and snap back to near-zero every time a
|
|
103
|
+
// layer finishes — five times for a small model. Summing per-digest
|
|
104
|
+
// gives one monotonic number over the whole download.
|
|
105
|
+
const layers = new Map<string, { total: number; completed: number }>()
|
|
106
|
+
|
|
107
|
+
for await (const event of http.stream<PullEvent>("/api/pull", { model: name, stream: true })) {
|
|
108
|
+
if (signal?.aborted) return
|
|
109
|
+
|
|
110
|
+
// Ollama reports a failed pull in-band, on a 200 stream — an
|
|
111
|
+
// unknown model arrives here, not as an HTTP error.
|
|
112
|
+
if (event.error) {
|
|
113
|
+
throw err("OLLAMA_PULL_FAILED", {
|
|
114
|
+
detail: `${name}: ${event.error}`,
|
|
115
|
+
context: { model: name },
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (event.digest && event.total !== undefined) {
|
|
120
|
+
layers.set(event.digest, {
|
|
121
|
+
total: event.total,
|
|
122
|
+
completed: event.completed ?? layers.get(event.digest)?.completed ?? 0,
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let total = 0
|
|
127
|
+
let completed = 0
|
|
128
|
+
for (const layer of layers.values()) {
|
|
129
|
+
total += layer.total
|
|
130
|
+
completed += layer.completed
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const done = event.status === "success"
|
|
134
|
+
yield {
|
|
135
|
+
status: event.status,
|
|
136
|
+
...(total > 0 ? { total: total } : {}),
|
|
137
|
+
...(total > 0 ? { completed: completed } : {}),
|
|
138
|
+
// Null until the first layer size arrives: a bar that sits
|
|
139
|
+
// at 0% is worse than one that admits it does not know yet.
|
|
140
|
+
percent: done ? 1 : total > 0 ? Math.min(completed / total, 1) : null,
|
|
141
|
+
done: done,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/** Remove a model. Ollama reclaims any layer no remaining tag references. */
|
|
147
|
+
async remove(name: string): Promise<void> {
|
|
148
|
+
await http.json("/api/delete", { model: name })
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type ModelsT = ReturnType<typeof Models>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Http } from "./http"
|
|
2
|
+
import { Models } from "./models"
|
|
3
|
+
import { Registry } from "./registry"
|
|
4
|
+
import type { CatalogModel, OllamaStatus } from "./types"
|
|
5
|
+
|
|
6
|
+
/** Ollama's own default. Overridable for a daemon on another host or port. */
|
|
7
|
+
const DEFAULT_HOST = "http://localhost:11434"
|
|
8
|
+
|
|
9
|
+
type OllamaOpts = {
|
|
10
|
+
/** Daemon base URL. Defaults to OLLAMA_HOST, then http://localhost:11434. */
|
|
11
|
+
host?: string
|
|
12
|
+
/** Upstream registry base URL. Tests point this at a local stand-in. */
|
|
13
|
+
registryUrl?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Ollama — local models, programmatically.
|
|
18
|
+
*
|
|
19
|
+
* A user running Axon against local inference has three questions: what can I
|
|
20
|
+
* run, what do I have, and how do I get more. This answers all three:
|
|
21
|
+
*
|
|
22
|
+
* registry what is available to download (curated — Ollama has no search
|
|
23
|
+
* API) plus live resolution of ANY name against the upstream
|
|
24
|
+
* models what is on this machine, what is loaded, and pulling more
|
|
25
|
+
*
|
|
26
|
+
* Ollama owns the bytes. It has its own blob store, layer deduplication and
|
|
27
|
+
* garbage collection, so nothing here manages files — a second store competing
|
|
28
|
+
* with `ollama pull` would be a bug, not a feature.
|
|
29
|
+
*
|
|
30
|
+
* Construction touches no network. A machine with no Ollama installed
|
|
31
|
+
* constructs this happily and fails at the first call that needs the daemon,
|
|
32
|
+
* with OLLAMA_UNAVAILABLE naming the fix.
|
|
33
|
+
*/
|
|
34
|
+
export function Ollama(opts: OllamaOpts = {}) {
|
|
35
|
+
const host = opts.host ?? process.env.OLLAMA_HOST ?? DEFAULT_HOST
|
|
36
|
+
|
|
37
|
+
const http = Http({ host: host })
|
|
38
|
+
const models = Models({ http: http })
|
|
39
|
+
const registry = Registry(opts.registryUrl !== undefined ? { baseUrl: opts.registryUrl } : {})
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
host: http.host,
|
|
43
|
+
models: models,
|
|
44
|
+
registry: registry,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Whether the daemon is reachable.
|
|
48
|
+
*
|
|
49
|
+
* The one verb that answers instead of throwing: "is Ollama installed"
|
|
50
|
+
* is a question every caller asks BEFORE deciding to use it, so an
|
|
51
|
+
* unreachable daemon is the expected answer half the time rather than a
|
|
52
|
+
* fault. Every other verb throws.
|
|
53
|
+
*/
|
|
54
|
+
async status(): Promise<OllamaStatus> {
|
|
55
|
+
try {
|
|
56
|
+
const { version } = await http.json<{ version: string }>("/api/version")
|
|
57
|
+
return { running: true, version: version }
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
return { running: false, reason: cause instanceof Error ? cause.message : String(cause) }
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The catalog, marked up with what is already installed and what each
|
|
65
|
+
* entry actually weighs — the shape a model palette renders.
|
|
66
|
+
*
|
|
67
|
+
* Sizes come from the live registry in parallel, and a lookup that
|
|
68
|
+
* fails leaves `size` absent rather than failing the whole list: a
|
|
69
|
+
* network blip should grey out one number, not empty the palette.
|
|
70
|
+
*/
|
|
71
|
+
async available(): Promise<CatalogModel[]> {
|
|
72
|
+
const [entries, installed] = await Promise.all([
|
|
73
|
+
registry.browse(),
|
|
74
|
+
models.list().then(list => new Set(list.map(model => model.name))).catch(() => new Set<string>()),
|
|
75
|
+
])
|
|
76
|
+
|
|
77
|
+
return Promise.all(entries.map(async entry => {
|
|
78
|
+
const resolved = await registry.resolve(entry.name).catch(() => null)
|
|
79
|
+
return {
|
|
80
|
+
...entry,
|
|
81
|
+
installed: installed.has(entry.name),
|
|
82
|
+
...(resolved ? { size: resolved.size } : {}),
|
|
83
|
+
}
|
|
84
|
+
}))
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type OllamaT = ReturnType<typeof Ollama>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { err } from "@arcforge/err"
|
|
2
|
+
import { CATALOG, families } from "./catalog"
|
|
3
|
+
import type { CatalogModel } from "./types"
|
|
4
|
+
|
|
5
|
+
/** The upstream Ollama registry. Speaks the OCI distribution protocol. */
|
|
6
|
+
const REGISTRY = "https://registry.ollama.ai/v2"
|
|
7
|
+
const MANIFEST_ACCEPT = "application/vnd.docker.distribution.manifest.v2+json"
|
|
8
|
+
|
|
9
|
+
type Manifest = {
|
|
10
|
+
layers?: Array<{ mediaType: string; size: number }>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type RegistryOpts = {
|
|
14
|
+
/** Override the upstream base URL. Tests point this at a local stand-in. */
|
|
15
|
+
baseUrl?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Registry — what is available to download, and how big it is.
|
|
20
|
+
*
|
|
21
|
+
* Two halves, because the upstream gives us two very different things:
|
|
22
|
+
*
|
|
23
|
+
* browse() the curated catalog (see catalog.ts — Ollama publishes no
|
|
24
|
+
* search API, so there is nothing to enumerate)
|
|
25
|
+
* resolve() a live manifest lookup, which works for ANY name
|
|
26
|
+
*
|
|
27
|
+
* That split is why a user is never fenced in by the shelf: a palette lists
|
|
28
|
+
* `browse()`, but typing `mistral-small:24b` still resolves, reports its real
|
|
29
|
+
* size, and pulls.
|
|
30
|
+
*/
|
|
31
|
+
export function Registry(opts: RegistryOpts = {}) {
|
|
32
|
+
const baseUrl = (opts.baseUrl ?? REGISTRY).replace(/\/+$/, "")
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A bare name means the `latest` tag, and an unqualified model lives under
|
|
36
|
+
* `library/` — the same defaulting `ollama pull` applies, so a user's
|
|
37
|
+
* mental model of a name matches ours exactly.
|
|
38
|
+
*/
|
|
39
|
+
function parse(name: string): { repository: string; tag: string } {
|
|
40
|
+
const [path, tag = "latest"] = name.split(":")
|
|
41
|
+
const repository = path!.includes("/") ? path! : `library/${path}`
|
|
42
|
+
return { repository: repository, tag: tag }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function manifest(name: string): Promise<Manifest | null> {
|
|
46
|
+
const { repository, tag } = parse(name)
|
|
47
|
+
|
|
48
|
+
let response: Response
|
|
49
|
+
try {
|
|
50
|
+
response = await fetch(`${baseUrl}/${repository}/manifests/${tag}`, {
|
|
51
|
+
headers: { accept: MANIFEST_ACCEPT },
|
|
52
|
+
})
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
throw err("OLLAMA_REGISTRY_UNREACHABLE", {
|
|
55
|
+
detail: `could not reach ${baseUrl} — check the network connection`,
|
|
56
|
+
context: { name: name },
|
|
57
|
+
cause: cause,
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 404 is a real answer: no such model. Anything else is a fault.
|
|
62
|
+
if (response.status === 404) return null
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw err("OLLAMA_REGISTRY_UNREACHABLE", {
|
|
65
|
+
detail: `${name}: ${response.status} ${response.statusText}`,
|
|
66
|
+
context: { name: name, status: response.status },
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return await response.json() as Manifest
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
/** The curated shelf. A palette's list. */
|
|
75
|
+
browse(): CatalogModel[] {
|
|
76
|
+
return CATALOG.map(entry => ({ ...entry }))
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
/** Catalog entries for one family, e.g. every gemma3 variant. */
|
|
80
|
+
variants(model: string): CatalogModel[] {
|
|
81
|
+
return CATALOG.filter(entry => entry.model === model).map(entry => ({ ...entry }))
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
families: families,
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Confirm a model exists upstream and report its real download size.
|
|
88
|
+
*
|
|
89
|
+
* Null when the registry has no such name — a mistyped tag is
|
|
90
|
+
* information, not a fault, and the caller reports it as such.
|
|
91
|
+
*
|
|
92
|
+
* The size is the sum of the layer sizes, which is what actually
|
|
93
|
+
* crosses the network. It is asked for rather than recorded because a
|
|
94
|
+
* tag is mutable: `gemma3:4b` is a different number of bytes today than
|
|
95
|
+
* it was at the last release.
|
|
96
|
+
*/
|
|
97
|
+
async resolve(name: string): Promise<{ name: string; size: number } | null> {
|
|
98
|
+
const found = await manifest(name)
|
|
99
|
+
if (!found) return null
|
|
100
|
+
|
|
101
|
+
const size = (found.layers ?? []).reduce((total, layer) => total + layer.size, 0)
|
|
102
|
+
return { name: name, size: size }
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/** Whether the registry serves this name at all. */
|
|
106
|
+
async exists(name: string): Promise<boolean> {
|
|
107
|
+
return (await manifest(name)) !== null
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type RegistryT = ReturnType<typeof Registry>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** A model present on this machine, as Ollama reports it. */
|
|
2
|
+
export type LocalModel = {
|
|
3
|
+
/** Fully qualified name including tag, e.g. "gemma3:4b" — what an engine references. */
|
|
4
|
+
name: string
|
|
5
|
+
/** On-disk size in bytes. */
|
|
6
|
+
size: number
|
|
7
|
+
/** Content digest of the manifest. */
|
|
8
|
+
digest: string
|
|
9
|
+
/** Last write, ISO-8601. */
|
|
10
|
+
modifiedAt: string
|
|
11
|
+
family: string
|
|
12
|
+
/** e.g. "4.3B" — Ollama's own formatting, not ours to reinterpret. */
|
|
13
|
+
parameters: string
|
|
14
|
+
/** e.g. "Q4_K_M". */
|
|
15
|
+
quantization: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A model loaded into memory right now — a subset of what is downloaded. */
|
|
19
|
+
export type RunningModel = {
|
|
20
|
+
name: string
|
|
21
|
+
/** Resident size in bytes, which exceeds on-disk size once loaded. */
|
|
22
|
+
size: number
|
|
23
|
+
/** When Ollama will unload it unless used again, ISO-8601. */
|
|
24
|
+
expiresAt: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A model offered for download.
|
|
29
|
+
*
|
|
30
|
+
* `size` is absent until resolved: the catalog records what a variant IS, and
|
|
31
|
+
* only the registry knows how many bytes that currently amounts to.
|
|
32
|
+
*/
|
|
33
|
+
export type CatalogModel = {
|
|
34
|
+
/** Fully qualified name including tag, e.g. "gemma3:4b". */
|
|
35
|
+
name: string
|
|
36
|
+
/** Base name without the tag, e.g. "gemma3" — the family a user picks first. */
|
|
37
|
+
model: string
|
|
38
|
+
tag: string
|
|
39
|
+
/** One line, written for someone choosing between models. */
|
|
40
|
+
description: string
|
|
41
|
+
/** e.g. "4B" — as published, for comparison against `parameters` on a local model. */
|
|
42
|
+
parameters: string
|
|
43
|
+
/** Real download size in bytes, once the registry has been asked. */
|
|
44
|
+
size?: number
|
|
45
|
+
/** True when this exact name is already on disk. */
|
|
46
|
+
installed?: boolean
|
|
47
|
+
capabilities: Capability[]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type Capability = "chat" | "tools" | "vision" | "embedding" | "thinking"
|
|
51
|
+
|
|
52
|
+
/** One step of a download. Byte counts are absent while Ollama resolves the manifest. */
|
|
53
|
+
export type PullProgress = {
|
|
54
|
+
/** Ollama's own status line, e.g. "pulling manifest", "verifying sha256 digest". */
|
|
55
|
+
status: string
|
|
56
|
+
/** Bytes across EVERY layer seen so far, not just the one in flight. */
|
|
57
|
+
total?: number
|
|
58
|
+
completed?: number
|
|
59
|
+
/**
|
|
60
|
+
* 0–1 across the whole download, or null before any size is known.
|
|
61
|
+
* Monotonic: it never goes backwards as one layer finishes and the next
|
|
62
|
+
* starts.
|
|
63
|
+
*/
|
|
64
|
+
percent: number | null
|
|
65
|
+
/** True on the terminal event — the model is on disk and usable. */
|
|
66
|
+
done: boolean
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Whether the local daemon is reachable, and what it is. */
|
|
70
|
+
export type OllamaStatus =
|
|
71
|
+
| { running: true; version: string }
|
|
72
|
+
| { running: false; reason: string }
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AxonPrompt } from "@arcforge/types"
|
|
2
|
+
import { err } from "@arcforge/err"
|
|
3
|
+
import { scanPromptPackage } from "../build/blueprint/scan/promptPackages"
|
|
4
|
+
import type { PromptCacheT } from "./registry"
|
|
5
|
+
|
|
6
|
+
type PromptsOpts = {
|
|
7
|
+
cache: PromptCacheT
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Prompts — published prompts, resolved to something an agent can render.
|
|
12
|
+
*
|
|
13
|
+
* The whole service is two steps: put the artifact on disk (the cache), then
|
|
14
|
+
* scan it into the same `AxonPrompt` entries a declared prompt produces. What
|
|
15
|
+
* comes out is indistinguishable from an agent's own prompt except for where
|
|
16
|
+
* its filePath points — which is exactly the property that lets the runtime
|
|
17
|
+
* render it without the agent ever depending on it.
|
|
18
|
+
*
|
|
19
|
+
* This is deliberately NOT the module installer. A module is code: it links
|
|
20
|
+
* against the runtime, has an ABI, and must live in the agent's own
|
|
21
|
+
* node_modules. A prompt is content that a person picks off a palette, and
|
|
22
|
+
* routing it through an installer bought nothing while costing a tree rewrite,
|
|
23
|
+
* a manifest edit and an agent reload per use.
|
|
24
|
+
*/
|
|
25
|
+
export function Prompts(opts: PromptsOpts) {
|
|
26
|
+
/**
|
|
27
|
+
* A published prompt's entries, fetching it on first use.
|
|
28
|
+
*
|
|
29
|
+
* Returns every prompt the package ships (a package may carry several),
|
|
30
|
+
* named exactly as the blueprint would name them — "@cody/scout:reconcile",
|
|
31
|
+
* plus the bare "@cody/scout" shorthand for a single-prompt package.
|
|
32
|
+
*/
|
|
33
|
+
async function entries(ref: string): Promise<AxonPrompt[]> {
|
|
34
|
+
const { name, root } = await opts.cache.ensure(ref)
|
|
35
|
+
const scanned = await scanPromptPackage(root, name)
|
|
36
|
+
|
|
37
|
+
if (scanned.entries.length === 0) {
|
|
38
|
+
throw err("PROMPT_NOT_FOUND", {
|
|
39
|
+
detail: `${name} is published but ships no prompt files`,
|
|
40
|
+
context: { name },
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return scanned.entries
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
entries,
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The single entry a bare registry name refers to.
|
|
52
|
+
*
|
|
53
|
+
* A one-prompt package answers to its own name (the shorthand
|
|
54
|
+
* scanPromptPackage adds), so this is the common palette case: the user
|
|
55
|
+
* picked "@axon/tdd" and means the prompt of that name.
|
|
56
|
+
*/
|
|
57
|
+
async entry(ref: string): Promise<AxonPrompt> {
|
|
58
|
+
const found = await entries(ref)
|
|
59
|
+
const exact = found.find(entry => entry.name === ref)
|
|
60
|
+
if (exact) return exact
|
|
61
|
+
|
|
62
|
+
// A multi-prompt package has no single answer — naming one is the
|
|
63
|
+
// caller's job, and silently picking the first would be a guess.
|
|
64
|
+
if (found.length > 1) {
|
|
65
|
+
throw err("PROMPT_NOT_FOUND", {
|
|
66
|
+
detail: `${ref} ships ${found.length} prompts — name one of: ${found.map(e => e.name).join(", ")}`,
|
|
67
|
+
context: { name: ref },
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return found[0]!
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type PromptsT = ReturnType<typeof Prompts>
|