@arcforge/platform 2.0.180 → 2.0.181

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcforge/platform",
3
- "version": "2.0.180",
3
+ "version": "2.0.181",
4
4
  "description": "The Axon developer platform — headless project discovery, blueprint scanning, typegen, agent lifecycle, registry, benches and tests. Shared by the CLI/TUI and the Fleet extension.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -44,20 +44,20 @@
44
44
  "deploy": "echo \"This package is published ONLY by apps/tui/scripts/release.ts, which pins workspace:* deps to concrete versions first. Publishing it directly ships an unresolvable dependency.\" && exit 1"
45
45
  },
46
46
  "dependencies": {
47
- "@arcforge/session": "2.0.180",
48
- "@arcforge/engines": "2.0.180",
49
- "@arcforge/err": "2.0.180",
50
- "@arcforge/types": "2.0.180",
51
- "@arcforge/cloud": "2.0.180",
52
- "@arcforge/capsule": "2.0.180",
53
- "@arcforge/core": "2.0.180",
54
- "@arcforge/vstr": "2.0.180",
47
+ "@arcforge/session": "2.0.181",
48
+ "@arcforge/engines": "2.0.181",
49
+ "@arcforge/err": "2.0.181",
50
+ "@arcforge/types": "2.0.181",
51
+ "@arcforge/cloud": "2.0.181",
52
+ "@arcforge/capsule": "2.0.181",
53
+ "@arcforge/core": "2.0.181",
54
+ "@arcforge/vstr": "2.0.181",
55
55
  "fft.js": "^4.0.4",
56
56
  "h3": "^1.15.11",
57
57
  "semver": "^7.7.4",
58
58
  "sharp": "^0.35.3",
59
59
  "typescript": "5.9.2",
60
- "@arcforge/link": "2.0.180"
60
+ "@arcforge/link": "2.0.181"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@arcforge/air": "2.0.167",
@@ -53,6 +53,18 @@ export type FetchOpts = {
53
53
  store: ModelStoreT
54
54
  /** Called before a download actually starts — nothing is emitted for a cache hit. */
55
55
  onDownload?: (model: ParsedModel) => void
56
+ /**
57
+ * Bytes received so far, and the total when the server declares one.
58
+ *
59
+ * `total` is null when the response carries no `Content-Length`, which
60
+ * happens on chunked transfers — a surface must render that as "downloading"
61
+ * rather than as a bar stuck at zero, so the absence is reported rather
62
+ * than guessed at.
63
+ *
64
+ * Called on every chunk. A consumer that wants to throttle should do so;
65
+ * throttling here would decide the cadence for every caller.
66
+ */
67
+ onProgress?: (progress: { model: ParsedModel; received: number; total: number | null }) => void
56
68
  }
57
69
 
58
70
  /**
@@ -109,7 +121,9 @@ export async function fetchModel(model: ParsedModel, opts: FetchOpts): Promise<S
109
121
  })
110
122
  }
111
123
 
112
- const data = new Uint8Array(await response.arrayBuffer())
124
+ const data = opts.onProgress
125
+ ? await readWithProgress(response, model, opts.onProgress)
126
+ : new Uint8Array(await response.arrayBuffer())
113
127
  // put() hashes and refuses a mismatch — verification lives at the write,
114
128
  // so nothing can reach the cache unverified by any path.
115
129
  const stored = await opts.store.put(basenameOf(model), data, expected ?? undefined)
@@ -117,6 +131,53 @@ export async function fetchModel(model: ParsedModel, opts: FetchOpts): Promise<S
117
131
  return stored
118
132
  }
119
133
 
134
+ /**
135
+ * Drain the body, reporting progress as it arrives.
136
+ *
137
+ * Only used when a caller asked for progress. `arrayBuffer()` remains the path
138
+ * otherwise, because it is the runtime's own and there is no reason to
139
+ * reimplement it for callers who are not watching.
140
+ *
141
+ * The chunks are joined once at the end rather than grown incrementally: a
142
+ * multi-gigabyte weight reallocated on every chunk is how a download becomes
143
+ * quadratic. `put()` still hashes the result, so nothing here weakens the
144
+ * verification — this changes how the bytes arrive, not whether they are
145
+ * checked.
146
+ */
147
+ async function readWithProgress(
148
+ response: Response,
149
+ model: ParsedModel,
150
+ onProgress: NonNullable<FetchOpts["onProgress"]>,
151
+ ): Promise<Uint8Array> {
152
+ const declared = Number.parseInt(response.headers.get("content-length") ?? "", 10)
153
+ const total = Number.isFinite(declared) && declared > 0 ? declared : null
154
+
155
+ const body = response.body
156
+ if (!body) return new Uint8Array(await response.arrayBuffer())
157
+
158
+ const reader = body.getReader()
159
+ const chunks: Uint8Array[] = []
160
+ let received = 0
161
+
162
+ onProgress({ model, received: 0, total })
163
+ for (;;) {
164
+ const { done, value } = await reader.read()
165
+ if (done) break
166
+ if (!value) continue
167
+ chunks.push(value)
168
+ received += value.byteLength
169
+ onProgress({ model, received, total })
170
+ }
171
+
172
+ const data = new Uint8Array(received)
173
+ let offset = 0
174
+ for (const chunk of chunks) {
175
+ data.set(chunk, offset)
176
+ offset += chunk.byteLength
177
+ }
178
+ return data
179
+ }
180
+
120
181
  /** The index key: what was declared, including the revision it was declared at. */
121
182
  function specifierOf(model: ParsedModel): string {
122
183
  return `${model.host}:${model.repo}@${model.rev}/${model.file}`
@@ -196,6 +196,53 @@ export function ModelStore(opts: ModelStoreOpts = {}) {
196
196
 
197
197
  return { path: target, sha256, bytes: data.byteLength }
198
198
  },
199
+
200
+ /**
201
+ * Forget a specifier, and delete its bytes when nothing else wants them.
202
+ *
203
+ * ── The index is the owner, the file is shared ──────────────────────
204
+ *
205
+ * The store is content-addressed, so two specifiers that resolved to
206
+ * the same bytes name ONE file — which is the whole reason ten agents
207
+ * can hold a weight without ten copies on disk. Deleting the file
208
+ * because one specifier no longer wants it would pull the bytes out
209
+ * from under every other name for them.
210
+ *
211
+ * So the entry always goes and the file goes only when no surviving
212
+ * entry references that hash. A hash still referenced leaves a
213
+ * perfectly good file behind, which is correct rather than a leak.
214
+ *
215
+ * ── Order matters ───────────────────────────────────────────────────
216
+ *
217
+ * The index is written BEFORE the file is unlinked. `list()` already
218
+ * skips entries whose file is missing, so an index that still names a
219
+ * deleted file is merely stale; a file deleted while the index still
220
+ * claims it would be reported as cached by anything reading the index
221
+ * directly. Crash between the two and the next `list()` is still
222
+ * right.
223
+ *
224
+ * Returns false when the specifier was not cached — a caller asking to
225
+ * remove something absent has not failed, and should not be told it
226
+ * has.
227
+ */
228
+ async remove(specifier: string): Promise<boolean> {
229
+ const index = await fsx.readJson<Record<string, { sha256: string; file: string }>>(indexPath)
230
+ const hit = index?.[specifier]
231
+ if (!index || !hit) return false
232
+
233
+ delete index[specifier]
234
+ await mkdir(root, { recursive: true })
235
+ await Bun.write(indexPath, JSON.stringify(index, null, 4))
236
+
237
+ const shared = Object.values(index).some(entry => entry.sha256 === hit.sha256)
238
+ if (shared) return true
239
+
240
+ // The hash directory, not just the file: a hash addresses exactly
241
+ // one set of bytes, so with the last reference gone the directory
242
+ // holding them has nothing left to hold.
243
+ await rm(join(root, hit.sha256), { recursive: true, force: true })
244
+ return true
245
+ },
199
246
  }
200
247
  }
201
248