@camstack/addon-ai 0.4.28 → 0.4.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 (3) hide show
  1. package/dist/addon.js +270 -184
  2. package/dist/addon.mjs +282 -195
  3. package/package.json +1 -1
package/dist/addon.mjs CHANGED
@@ -1,11 +1,9 @@
1
1
  import { createRequire } from "node:module";
2
- import * as path$1 from "node:path";
2
+ import * as path from "node:path";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { connect, createServer } from "node:net";
5
- import * as fs from "node:fs";
6
5
  import { createReadStream, existsSync, statSync } from "node:fs";
7
- import { promisify } from "node:util";
8
- import { brotliCompress, gzip } from "node:zlib";
6
+ import { deleteModelFromDisk, downloadFile, getModelFilePath, isModelDownloaded } from "@camstack/system/addon-utils";
9
7
  import * as fsp from "node:fs/promises";
10
8
  import { spawn } from "node:child_process";
11
9
  //#region \0rolldown/runtime.js
@@ -41,7 +39,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
41
39
  }) : target, mod));
42
40
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
43
41
  //#endregion
44
- //#region ../types/dist/event-category-CIa_iT6b.mjs
42
+ //#region ../types/dist/event-category-BZL-fdNj.mjs
45
43
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
46
44
  EventCategory["SystemBoot"] = "system.boot";
47
45
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -478,7 +476,7 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
478
476
  EventCategory["MetricsNodeResourcesSnapshot"] = "metrics.node-resources-snapshot";
479
477
  /**
480
478
  * Periodic per-node process-tree snapshot (camstack-related pids
481
- * with ghost / managed / root classification). Emitted ~0.2 Hz by
479
+ * with root / managed / system classification). Emitted ~0.2 Hz by
482
480
  * the metrics-provider addon. Drives the Cluster → Processes tab
483
481
  * without polling `metricsProvider.listNodeProcesses`.
484
482
  */
@@ -11358,6 +11356,19 @@ var SettingsRecordSchema = object({
11358
11356
  data: record(string(), unknown())
11359
11357
  });
11360
11358
  /**
11359
+ * One record of a BULK insert — {@link SettingsRecordSchema} with the id made
11360
+ * optional.
11361
+ *
11362
+ * A separate schema rather than loosening the shared one: every other method
11363
+ * on this cap addresses a row BY its id, and making that field optional
11364
+ * everywhere would turn a forgotten key into a silently generated one on
11365
+ * `update` and `delete` as well.
11366
+ */
11367
+ var BulkRecordSchema = object({
11368
+ id: string().optional(),
11369
+ data: record(string(), unknown())
11370
+ });
11371
+ /**
11361
11372
  * Column declaration for a structured (SQL-backed) collection.
11362
11373
  *
11363
11374
  * Logical types — the backend translates each to the matching SQLite
@@ -11414,6 +11425,10 @@ method(object({
11414
11425
  collection: string(),
11415
11426
  record: SettingsRecordSchema
11416
11427
  }), _void(), { kind: "mutation" }), method(object({
11428
+ namespace: string().optional(),
11429
+ collection: string(),
11430
+ records: array(BulkRecordSchema).readonly()
11431
+ }), object({ inserted: number$1().int() }), { kind: "mutation" }), method(object({
11417
11432
  namespace: string().optional(),
11418
11433
  collection: string(),
11419
11434
  id: string(),
@@ -11522,6 +11537,13 @@ method(_void(), EngineInfoSchema, { auth: "admin" }), method(object({
11522
11537
  }), _void(), {
11523
11538
  kind: "mutation",
11524
11539
  auth: "admin"
11540
+ }), method(object({
11541
+ namespace: string().optional(),
11542
+ collection: string(),
11543
+ records: array(BulkRecordSchema).readonly()
11544
+ }), object({ inserted: number$1().int() }), {
11545
+ kind: "mutation",
11546
+ auth: "admin"
11525
11547
  }), method(object({
11526
11548
  namespace: string().optional(),
11527
11549
  collection: string(),
@@ -13384,6 +13406,68 @@ method(LogEntrySchema, _void(), { kind: "mutation" }), method(object({
13384
13406
  limit: number$1().optional(),
13385
13407
  tags: record(string(), string()).optional()
13386
13408
  }), array(LogEntrySchema).readonly());
13409
+ var LoadContributionSchema = object({
13410
+ role: _enum([
13411
+ "decode",
13412
+ "transcode",
13413
+ "recording",
13414
+ "streaming",
13415
+ "detection"
13416
+ ]),
13417
+ /**
13418
+ * The NUMERIC device id — the same value every log line carries as
13419
+ * `tags.deviceId`. `null` means this cost genuinely belongs to no single
13420
+ * camera (a shared pool), NOT that the contributor forgot to look it up: a
13421
+ * contributor that cannot name its camera must not emit the entry at all,
13422
+ * because an unnamed per-camera entry is indistinguishable from a shared one
13423
+ * and would quietly turn one camera's cost into everybody's.
13424
+ */
13425
+ deviceId: number$1().int().positive().nullable(),
13426
+ attribution: _enum([
13427
+ "measured",
13428
+ "accounted",
13429
+ "unattributable"
13430
+ ]),
13431
+ /**
13432
+ * What ONE entry is, in the contributor's own words — `615/high`,
13433
+ * `617/native`, `cuda:0 shared pool`. Free text because the unit differs per
13434
+ * family and inventing a common one would lose the only information that
13435
+ * makes two entries for the same camera distinguishable.
13436
+ */
13437
+ unit: string(),
13438
+ /**
13439
+ * The OS process this cost lives in, when there is one. Present so a
13440
+ * consumer can (a) tell two generations of the same unit apart across a
13441
+ * restart, and (b) subtract claimed processes from the node's process
13442
+ * snapshot to see what NOBODY claimed. Absent for an entry that owns no
13443
+ * process of its own.
13444
+ */
13445
+ pid: number$1().int().positive().optional(),
13446
+ /**
13447
+ * When this generation started. The pid's incarnation marker: a consumer
13448
+ * differencing {@link LoadContributionSchema.shape.cpuSeconds} must drop the
13449
+ * window when this changes, because the counter restarted from zero in a new
13450
+ * process.
13451
+ */
13452
+ startedAtMs: number$1().optional(),
13453
+ /**
13454
+ * CUMULATIVE CPU seconds this unit has consumed since it started — user +
13455
+ * system, read from the child's own `/proc/<pid>/stat` at the moment the
13456
+ * contribution is asked for.
13457
+ *
13458
+ * Cumulative and not a rate on purpose: a rate needs a window, a window
13459
+ * needs a sampler, and a new per-node sampler is the defect half of
13460
+ * `docs/architecture/load-ledger.md` documents. A counter can be differenced
13461
+ * by whoever already keeps a history; a rate cannot be un-averaged.
13462
+ *
13463
+ * Absent — never zero — on a node with no `/proc`, on a read failure, and on
13464
+ * an entry with no process.
13465
+ */
13466
+ cpuSeconds: number$1().optional(),
13467
+ /** Resident bytes of this unit's process, same source and same rules. */
13468
+ rssBytes: number$1().optional()
13469
+ });
13470
+ method(_void(), array(LoadContributionSchema).readonly());
13387
13471
  /**
13388
13472
  * `login-method` — collection cap through which auth addons contribute
13389
13473
  * their pre-auth login surfaces to the login page. This is the SINGLE,
@@ -13587,8 +13671,7 @@ var NodeProcessSchema = object({
13587
13671
  classification: _enum([
13588
13672
  "root",
13589
13673
  "managed",
13590
- "system",
13591
- "ghost"
13674
+ "system"
13592
13675
  ]),
13593
13676
  /** `$process` addon binding when `managed`, else null. */
13594
13677
  addonId: string().nullable(),
@@ -13596,22 +13679,39 @@ var NodeProcessSchema = object({
13596
13679
  nodeId: string().nullable(),
13597
13680
  /** Truncated command line. */
13598
13681
  command: string(),
13682
+ /**
13683
+ * `ps pcpu` — CPU averaged over the process's WHOLE LIFETIME, not a rate.
13684
+ * On a runner up for days it barely moves. Fine as a column, useless as a
13685
+ * series: use `cpuMainPercent + cpuGcPercent` for anything time-varying.
13686
+ */
13599
13687
  cpuPercent: number$1(),
13600
13688
  memoryRssBytes: number$1(),
13689
+ /**
13690
+ * Instantaneous CPU% of the process's own threads over the last
13691
+ * process-snapshot window, from a `/proc/<pid>/task/*` tick delta.
13692
+ *
13693
+ * `null` = UNKNOWN, never zero: no previous sample yet (first tick after
13694
+ * boot), the pid was recycled, or this node is not Linux.
13695
+ */
13696
+ cpuMainPercent: number$1().nullable(),
13697
+ /**
13698
+ * Instantaneous CPU% of V8's `V8Worker` platform pool over the same window.
13699
+ *
13700
+ * This is the number that rewrote the 2026-08-27 diagnosis — hub-main 73%,
13701
+ * `stream-broker` 61% (`docs/architecture/load-ledger.md`). A CPU chart that
13702
+ * does not separate it from `cpuMainPercent` shows "busy" where the truth is
13703
+ * "allocating too much".
13704
+ *
13705
+ * Concurrent GC is the dominant tenant of that pool but not the only one
13706
+ * (background compilation runs there too), so it is reported as
13707
+ * "GC / V8 helpers" rather than as pure collection time. `null` has the same
13708
+ * meaning as on `cpuMainPercent`.
13709
+ */
13710
+ cpuGcPercent: number$1().nullable(),
13711
+ /** Threads seen in the tick scan. `null` under the same conditions. */
13712
+ threadCount: number$1().nullable(),
13601
13713
  /** Wall-clock uptime (seconds). Parsed from `ps etime`. */
13602
- uptimeSec: number$1(),
13603
- /** True when ancestor walk reaches `ppid=1` (reparented to init/launchd). */
13604
- orphaned: boolean()
13605
- });
13606
- var KillProcessInputSchema = object({
13607
- pid: number$1(),
13608
- /** Force = SIGKILL. Default is SIGTERM. */
13609
- force: boolean().optional()
13610
- });
13611
- var KillProcessResultSchema = object({
13612
- success: boolean(),
13613
- reason: string().optional(),
13614
- signal: _enum(["SIGTERM", "SIGKILL"]).optional()
13714
+ uptimeSec: number$1()
13615
13715
  });
13616
13716
  var DumpHeapSnapshotInputSchema = object({
13617
13717
  /** The addon whose runner should dump a heap snapshot. */
@@ -13624,6 +13724,104 @@ var DumpHeapSnapshotResultSchema = object({
13624
13724
  pid: number$1().optional(),
13625
13725
  reason: string().optional()
13626
13726
  });
13727
+ /**
13728
+ * One point of one function's series.
13729
+ *
13730
+ * The unsuffixed fields are the bucket's **MAXIMUM**, and that choice is the
13731
+ * point of the whole surface. The two obvious reductions both lie: a mean per
13732
+ * bucket smears a spike away, and taking every Nth sample skips it outright.
13733
+ * Either would give us a tool built to find peaks that does not show peaks.
13734
+ * `...Min` carries the other end, `samples` says how many raw snapshots folded
13735
+ * into the bucket, and a mean stays derivable where it is wanted.
13736
+ *
13737
+ * An UNREDUCED point is a one-sample bucket: `samples === 1` and each `...Min`
13738
+ * equals its unsuffixed twin. Reduced and unreduced are the same shape, so a
13739
+ * caller cannot tell which it received — which is what "one reader" means.
13740
+ */
13741
+ var LoadPointSchema = object({
13742
+ /** Bucket START, or the snapshot's own timestamp when unreduced. */
13743
+ atMs: number$1(),
13744
+ /** Raw snapshots in this bucket. Never 0 — AN EMPTY BUCKET IS ABSENT. */
13745
+ samples: number$1().int(),
13746
+ /**
13747
+ * `null` = UNKNOWN and it PROPAGATES: a bucket is null unless every process
13748
+ * of every snapshot in it reported a thread split. A partial sum is a
13749
+ * smaller number that looks exactly as real as a complete one.
13750
+ */
13751
+ cpuMainPercent: number$1().nullable(),
13752
+ cpuMainPercentMin: number$1().nullable(),
13753
+ cpuGcPercent: number$1().nullable(),
13754
+ cpuGcPercentMin: number$1().nullable(),
13755
+ /** Lifetime-average CPU%, summed. Always known — and never a rate. */
13756
+ cpuLifetimePercent: number$1(),
13757
+ cpuLifetimePercentMin: number$1(),
13758
+ memoryRssBytes: number$1(),
13759
+ memoryRssBytesMin: number$1(),
13760
+ processCount: number$1().int(),
13761
+ processCountMin: number$1().int()
13762
+ });
13763
+ /** One function's series. `key` is an addonId, `__root__` or `__unattributed__`. */
13764
+ var LoadFunctionSeriesSchema = object({
13765
+ key: string(),
13766
+ kind: _enum([
13767
+ "addon",
13768
+ "root",
13769
+ "unattributed"
13770
+ ]),
13771
+ /** Oldest-first. A missing interval is MISSING — never zero-filled. */
13772
+ points: array(LoadPointSchema).readonly()
13773
+ });
13774
+ var NodeLoadSeriesSchema = object({
13775
+ nodeId: string(),
13776
+ /** One entry per function seen in the window, heaviest-first. */
13777
+ series: array(LoadFunctionSeriesSchema).readonly(),
13778
+ /**
13779
+ * Width of one returned bucket, in ms. Equals the sampling cadence when no
13780
+ * reduction was needed — so a caller can always say what one point covers
13781
+ * without having to know whether it was reduced.
13782
+ */
13783
+ bucketMs: number$1(),
13784
+ /** Raw snapshots that went into this answer, across both tiers. */
13785
+ retainedSamples: number$1(),
13786
+ /** Oldest snapshot represented, or `null` when nothing is retained. */
13787
+ oldestAtMs: number$1().nullable(),
13788
+ /** The fixed sampling cadence in force on the cluster, in ms. */
13789
+ cadenceMs: number$1(),
13790
+ /**
13791
+ * Did the DURABLE tier contribute? `false` means the answer is the hot ring
13792
+ * alone — an agent (which holds no table), or a store that refused.
13793
+ * Reported because "the last hour" and "the last six hours" are different
13794
+ * questions and an operator must not have to guess which was answered.
13795
+ */
13796
+ durable: boolean()
13797
+ });
13798
+ var GetLoadSeriesInputSchema = object({
13799
+ /**
13800
+ * The node whose series is wanted.
13801
+ *
13802
+ * NOT named `nodeId`: the generated cap router strips a top-level
13803
+ * `nodeId` from every method input and uses it to ROUTE the call to
13804
+ * that node's provider (`generated-cap-routers.ts`). A series target
13805
+ * called `nodeId` would silently become a routing pin and never reach
13806
+ * the provider. The hub holds every node it hears from, so the
13807
+ * ordinary call is unpinned — answered by the hub, for any node.
13808
+ */
13809
+ forNodeId: string(),
13810
+ /**
13811
+ * EXCLUSIVE lower bound. A caller passes the newest `atMs` it already
13812
+ * holds and receives only what it is missing, so seeding a live chart
13813
+ * from this method cannot double a point already drawn.
13814
+ */
13815
+ sinceMs: number$1().optional(),
13816
+ /**
13817
+ * Most points the caller wants PER FUNCTION. The window is reduced to fit,
13818
+ * preserving min and max per bucket.
13819
+ *
13820
+ * Absent means NO reduction — legitimate for a short window and a trap for a
13821
+ * long one, which is why a chart passes its own pixel width.
13822
+ */
13823
+ maxPoints: number$1().int().positive().optional()
13824
+ });
13627
13825
  var SystemMetricsSchema = object({
13628
13826
  cpuPercent: number$1(),
13629
13827
  memoryPercent: number$1(),
@@ -13634,10 +13832,7 @@ var SystemMetricsSchema = object({
13634
13832
  gpuPercent: number$1().optional(),
13635
13833
  gpuMemoryPercent: number$1().optional()
13636
13834
  });
13637
- method(_void(), SystemResourceSnapshotSchema), method(_void(), SystemResourceSnapshotSchema.nullable()), method(_void(), SystemMetricsSchema), method(object({ dirPath: string() }), DiskSpaceInfoSchema), method(_void(), MetricsGpuInfoSchema.nullable()), method(_void(), number$1().nullable()), method(object({ pids: array(number$1()) }), array(PidResourceStatsSchema)), method(_void(), array(AddonInstanceSchema).readonly()), method(object({ addonId: string() }), PidResourceStatsSchema.nullable()), method(_void(), array(NodeProcessSchema).readonly()), method(KillProcessInputSchema, KillProcessResultSchema, {
13638
- kind: "mutation",
13639
- auth: "admin"
13640
- }), method(DumpHeapSnapshotInputSchema, DumpHeapSnapshotResultSchema, {
13835
+ method(_void(), SystemResourceSnapshotSchema), method(_void(), SystemResourceSnapshotSchema.nullable()), method(_void(), SystemMetricsSchema), method(object({ dirPath: string() }), DiskSpaceInfoSchema), method(_void(), MetricsGpuInfoSchema.nullable()), method(_void(), number$1().nullable()), method(object({ pids: array(number$1()) }), array(PidResourceStatsSchema)), method(_void(), array(AddonInstanceSchema).readonly()), method(object({ addonId: string() }), PidResourceStatsSchema.nullable()), method(_void(), array(NodeProcessSchema).readonly()), method(GetLoadSeriesInputSchema, NodeLoadSeriesSchema), method(DumpHeapSnapshotInputSchema, DumpHeapSnapshotResultSchema, {
13641
13836
  kind: "mutation",
13642
13837
  auth: "admin"
13643
13838
  });
@@ -26940,6 +27135,15 @@ var LoggingSettingsPatchSchema = object({
26940
27135
  * authority over the whole hierarchy and answers for every layer, so the
26941
27136
  * layer selector needs a name the transport does not already own.
26942
27137
  */
27138
+ /**
27139
+ * One contribution, plus WHO reported it.
27140
+ *
27141
+ * The addon and node are added by the hub as it enumerates providers, never by
27142
+ * the contributor: an addon reporting its own identity could report somebody
27143
+ * else's, and the whole point of this surface is that no claim is made by
27144
+ * anyone but its owner.
27145
+ */
27146
+ var ReportedLoadContributionSchema = LoadContributionSchema.extend({ addonId: string() });
26943
27147
  var GetLoggingSettingsInputSchema = object({
26944
27148
  scopeNodeId: string().optional(),
26945
27149
  /**
@@ -26998,7 +27202,7 @@ method(_void(), FeatureManifestSchema), method(_void(), HealthStatusSchema), met
26998
27202
  }), method(_void(), SiteLocationStatusSchema, {
26999
27203
  kind: "mutation",
27000
27204
  auth: "admin"
27001
- }), method(_void(), RequestCensusStatusSchema, { auth: "admin" }), method(GetLoggingSettingsInputSchema, LoggingSettingsStateSchema, { auth: "admin" }), method(SetLoggingSettingsInputSchema, LoggingSettingsStateSchema, {
27205
+ }), method(_void(), RequestCensusStatusSchema, { auth: "admin" }), method(_void(), array(ReportedLoadContributionSchema).readonly(), { auth: "admin" }), method(GetLoggingSettingsInputSchema, LoggingSettingsStateSchema, { auth: "admin" }), method(SetLoggingSettingsInputSchema, LoggingSettingsStateSchema, {
27002
27206
  kind: "mutation",
27003
27207
  auth: "admin"
27004
27208
  });
@@ -28614,6 +28818,12 @@ Object.freeze({
28614
28818
  addonId: null,
28615
28819
  access: "create"
28616
28820
  },
28821
+ "dataStoreProvider.insertMany": {
28822
+ capName: "data-store-provider",
28823
+ capScope: "system",
28824
+ addonId: null,
28825
+ access: "create"
28826
+ },
28617
28827
  "dataStoreProvider.isEmpty": {
28618
28828
  capName: "data-store-provider",
28619
28829
  capScope: "system",
@@ -29928,6 +30138,12 @@ Object.freeze({
29928
30138
  addonId: null,
29929
30139
  access: "create"
29930
30140
  },
30141
+ "loadContribution.list": {
30142
+ capName: "load-contribution",
30143
+ capScope: "system",
30144
+ addonId: null,
30145
+ access: "view"
30146
+ },
29931
30147
  "localNetwork.downloadCa": {
29932
30148
  capName: "local-network",
29933
30149
  capScope: "system",
@@ -30228,17 +30444,17 @@ Object.freeze({
30228
30444
  addonId: null,
30229
30445
  access: "view"
30230
30446
  },
30231
- "metricsProvider.getProcessStats": {
30447
+ "metricsProvider.getLoadSeries": {
30232
30448
  capName: "metrics-provider",
30233
30449
  capScope: "system",
30234
30450
  addonId: null,
30235
30451
  access: "view"
30236
30452
  },
30237
- "metricsProvider.killProcess": {
30453
+ "metricsProvider.getProcessStats": {
30238
30454
  capName: "metrics-provider",
30239
30455
  capScope: "system",
30240
30456
  addonId: null,
30241
- access: "create"
30457
+ access: "view"
30242
30458
  },
30243
30459
  "metricsProvider.listAddonInstances": {
30244
30460
  capName: "metrics-provider",
@@ -32250,6 +32466,12 @@ Object.freeze({
32250
32466
  addonId: null,
32251
32467
  access: "create"
32252
32468
  },
32469
+ "settingsStore.insertMany": {
32470
+ capName: "settings-store",
32471
+ capScope: "system",
32472
+ addonId: null,
32473
+ access: "create"
32474
+ },
32253
32475
  "settingsStore.isEmpty": {
32254
32476
  capName: "settings-store",
32255
32477
  capScope: "system",
@@ -32862,6 +33084,12 @@ Object.freeze({
32862
33084
  addonId: null,
32863
33085
  access: "create"
32864
33086
  },
33087
+ "system.getLoadContributions": {
33088
+ capName: "system",
33089
+ capScope: "system",
33090
+ addonId: null,
33091
+ access: "view"
33092
+ },
32865
33093
  "system.getLoggingSettings": {
32866
33094
  capName: "system",
32867
33095
  capScope: "system",
@@ -61021,7 +61249,7 @@ var require_auth_config = /* @__PURE__ */ __commonJSMin(((exports, module) => {
61021
61249
  writeAuthConfig: () => writeAuthConfig
61022
61250
  });
61023
61251
  module.exports = __toCommonJS(auth_config_exports);
61024
- var fs$2 = __toESM(__require("fs"));
61252
+ var fs$1 = __toESM(__require("fs"));
61025
61253
  var path$2 = __toESM(__require("path"));
61026
61254
  var import_token_util = require_token_util();
61027
61255
  function getAuthConfigPath() {
@@ -61032,8 +61260,8 @@ var require_auth_config = /* @__PURE__ */ __commonJSMin(((exports, module) => {
61032
61260
  function readAuthConfig() {
61033
61261
  try {
61034
61262
  const authPath = getAuthConfigPath();
61035
- if (!fs$2.existsSync(authPath)) return null;
61036
- const content = fs$2.readFileSync(authPath, "utf8");
61263
+ if (!fs$1.existsSync(authPath)) return null;
61264
+ const content = fs$1.readFileSync(authPath, "utf8");
61037
61265
  if (!content) return null;
61038
61266
  return JSON.parse(content);
61039
61267
  } catch (error) {
@@ -61043,11 +61271,11 @@ var require_auth_config = /* @__PURE__ */ __commonJSMin(((exports, module) => {
61043
61271
  function writeAuthConfig(config) {
61044
61272
  const authPath = getAuthConfigPath();
61045
61273
  const authDir = path$2.dirname(authPath);
61046
- if (!fs$2.existsSync(authDir)) fs$2.mkdirSync(authDir, {
61274
+ if (!fs$1.existsSync(authDir)) fs$1.mkdirSync(authDir, {
61047
61275
  mode: 504,
61048
61276
  recursive: true
61049
61277
  });
61050
- fs$2.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
61278
+ fs$1.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
61051
61279
  }
61052
61280
  function isValidAccessToken(authConfig, expirationBufferMs = 0) {
61053
61281
  if (!authConfig.token) return false;
@@ -61180,8 +61408,8 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
61180
61408
  saveToken: () => saveToken
61181
61409
  });
61182
61410
  module.exports = __toCommonJS(token_util_exports);
61183
- var path = __toESM(__require("path"));
61184
- var fs$1 = __toESM(__require("fs"));
61411
+ var path$1 = __toESM(__require("path"));
61412
+ var fs = __toESM(__require("fs"));
61185
61413
  var import_token_error = require_token_error();
61186
61414
  var import_token_io = require_token_io();
61187
61415
  var import_auth_config = require_auth_config();
@@ -61191,7 +61419,7 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
61191
61419
  const vercelFolder = "com.vercel.cli";
61192
61420
  const dataDir = (0, import_token_io.getUserDataDir)();
61193
61421
  if (!dataDir) return null;
61194
- return path.join(dataDir, vercelFolder);
61422
+ return path$1.join(dataDir, vercelFolder);
61195
61423
  }
61196
61424
  async function getVercelToken(options) {
61197
61425
  const authConfig = (0, import_auth_config.readAuthConfig)();
@@ -61239,9 +61467,9 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
61239
61467
  function findProjectInfo() {
61240
61468
  const dir = (0, import_token_io.findRootDir)();
61241
61469
  if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");
61242
- const prjPath = path.join(dir, ".vercel", "project.json");
61243
- if (!fs$1.existsSync(prjPath)) throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
61244
- const prj = JSON.parse(fs$1.readFileSync(prjPath, "utf8"));
61470
+ const prjPath = path$1.join(dir, ".vercel", "project.json");
61471
+ if (!fs.existsSync(prjPath)) throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
61472
+ const prj = JSON.parse(fs.readFileSync(prjPath, "utf8"));
61245
61473
  if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") throw new TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");
61246
61474
  return {
61247
61475
  projectId: prj.projectId,
@@ -61251,21 +61479,21 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
61251
61479
  function saveToken(token, projectId) {
61252
61480
  const dir = (0, import_token_io.getUserDataDir)();
61253
61481
  if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
61254
- const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
61482
+ const tokenPath = path$1.join(dir, "com.vercel.token", `${projectId}.json`);
61255
61483
  const tokenJson = JSON.stringify(token);
61256
- fs$1.mkdirSync(path.dirname(tokenPath), {
61484
+ fs.mkdirSync(path$1.dirname(tokenPath), {
61257
61485
  mode: 504,
61258
61486
  recursive: true
61259
61487
  });
61260
- fs$1.writeFileSync(tokenPath, tokenJson);
61261
- fs$1.chmodSync(tokenPath, 432);
61488
+ fs.writeFileSync(tokenPath, tokenJson);
61489
+ fs.chmodSync(tokenPath, 432);
61262
61490
  }
61263
61491
  function loadToken(projectId) {
61264
61492
  const dir = (0, import_token_io.getUserDataDir)();
61265
61493
  if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
61266
- const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
61267
- if (!fs$1.existsSync(tokenPath)) return null;
61268
- const token = JSON.parse(fs$1.readFileSync(tokenPath, "utf8"));
61494
+ const tokenPath = path$1.join(dir, "com.vercel.token", `${projectId}.json`);
61495
+ if (!fs.existsSync(tokenPath)) return null;
61496
+ const token = JSON.parse(fs.readFileSync(tokenPath, "utf8"));
61269
61497
  assertVercelOidcTokenResponse(token);
61270
61498
  return token;
61271
61499
  }
@@ -73269,147 +73497,6 @@ function entryForRef(ref) {
73269
73497
  };
73270
73498
  }
73271
73499
  //#endregion
73272
- //#region ../system/dist/file-data-plane-BhKdxJgf.mjs
73273
- function isNonEmptyFile(filePath) {
73274
- return fs.existsSync(filePath) && fs.statSync(filePath).size > 0;
73275
- }
73276
- /**
73277
- * Sibling files of a single-file (non-directory) format — extra files the
73278
- * format needs, fetched from the same remote directory as `url` and stored
73279
- * flat alongside the main file in `modelsDir`. Catalog-declared via
73280
- * `formatEntry.files`, e.g. OpenVINO IR lists its `.bin` weights next to the
73281
- * `.xml`. The downloader stays format-agnostic; the convention lives in the
73282
- * catalog data (like `MLPACKAGE_FILES` for the directory case).
73283
- */
73284
- function siblingFilesFor(formatEntry) {
73285
- return formatEntry.isDirectory ? [] : formatEntry.files ?? [];
73286
- }
73287
- /** Build fetch headers, including HF auth token for huggingface.co URLs */
73288
- function buildHeaders(url) {
73289
- const headers = { "User-Agent": "CamStack/1.0" };
73290
- const hfToken = process.env["HF_TOKEN"] ?? process.env["HUGGING_FACE_HUB_TOKEN"];
73291
- if (hfToken && url.includes("huggingface.co")) headers["Authorization"] = `Bearer ${hfToken}`;
73292
- return headers;
73293
- }
73294
- var DEFAULT_MAX_REDIRECTS = 5;
73295
- function normalizeDownloadOptions(third) {
73296
- if (typeof third === "function") return { onProgress: third };
73297
- return third ?? {};
73298
- }
73299
- function isRedirectStatus(status) {
73300
- return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
73301
- }
73302
- function resolveRedirectUrl(current, location) {
73303
- return new URL(location, current);
73304
- }
73305
- async function downloadFile(url, destPath, onProgressOrOptions) {
73306
- if (fs.existsSync(destPath)) return destPath;
73307
- const opts = normalizeDownloadOptions(onProgressOrOptions);
73308
- const fetchImpl = opts.fetchImpl ?? fetch;
73309
- const maxRedirects = opts.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
73310
- fs.mkdirSync(path$1.dirname(destPath), { recursive: true });
73311
- const tmpPath = destPath + ".downloading";
73312
- try {
73313
- let current = url;
73314
- const seen = /* @__PURE__ */ new Set();
73315
- let response;
73316
- const manual = opts.redirectPolicy !== void 0;
73317
- for (let hop = 0; hop <= maxRedirects; hop++) {
73318
- const parsed = new URL(current);
73319
- if (opts.redirectPolicy) opts.redirectPolicy(parsed, hop);
73320
- if (seen.has(parsed.href)) throw new Error(`Redirect loop detected at ${parsed.href}`);
73321
- seen.add(parsed.href);
73322
- const controller = opts.timeoutMs !== void 0 ? new AbortController() : void 0;
73323
- const timer = controller && opts.timeoutMs !== void 0 ? setTimeout(() => controller.abort(), opts.timeoutMs) : void 0;
73324
- try {
73325
- response = await fetchImpl(current, {
73326
- redirect: manual ? "manual" : "follow",
73327
- headers: buildHeaders(current),
73328
- ...controller ? { signal: controller.signal } : {}
73329
- });
73330
- } finally {
73331
- if (timer) clearTimeout(timer);
73332
- }
73333
- if (manual && isRedirectStatus(response.status)) {
73334
- const location = response.headers.get("location");
73335
- if (!location) throw new Error(`Redirect ${response.status} missing Location header`);
73336
- if (hop >= maxRedirects) throw new Error(`Too many redirects (max ${maxRedirects}) downloading ${url}`);
73337
- current = resolveRedirectUrl(current, location).href;
73338
- continue;
73339
- }
73340
- break;
73341
- }
73342
- if (!response) throw new Error(`No response downloading ${url}`);
73343
- if (manual && isRedirectStatus(response.status)) throw new Error(`Too many redirects (max ${maxRedirects}) downloading ${url}`);
73344
- if (!response.ok) throw new Error(`HTTP ${response.status} downloading ${url}`);
73345
- if (!response.body) throw new Error(`No response body from ${url}`);
73346
- const total = parseInt(response.headers.get("content-length") ?? "0", 10);
73347
- let downloaded = 0;
73348
- const fileStream = fs.createWriteStream(tmpPath);
73349
- const reader = response.body.getReader();
73350
- try {
73351
- for (;;) {
73352
- const { done, value } = await reader.read();
73353
- if (done || !value) break;
73354
- downloaded += value.length;
73355
- if (opts.maxBytes !== void 0 && downloaded > opts.maxBytes) throw new Error(`Downloaded ${downloaded} bytes exceeds the ${opts.maxBytes}-byte limit`);
73356
- fileStream.write(value);
73357
- opts.onProgress?.(downloaded, total);
73358
- }
73359
- } finally {
73360
- fileStream.end();
73361
- await new Promise((resolve, reject) => {
73362
- fileStream.on("finish", resolve);
73363
- fileStream.on("error", reject);
73364
- });
73365
- }
73366
- fs.renameSync(tmpPath, destPath);
73367
- return destPath;
73368
- } catch (err) {
73369
- try {
73370
- fs.unlinkSync(tmpPath);
73371
- } catch {}
73372
- throw err;
73373
- }
73374
- }
73375
- /** Compute the on-disk path for a given model + format, even when not yet downloaded. */
73376
- function getModelFilePath(modelsDir, entry, format) {
73377
- const formatEntry = entry.formats[format];
73378
- if (!formatEntry) return null;
73379
- const filename = formatEntry.url.split("/").pop() ?? `${entry.id}.${format}`;
73380
- return path$1.join(modelsDir, filename);
73381
- }
73382
- /** True iff the model file (or `Manifest.json` for directory bundles) exists and is non-empty. */
73383
- function isModelDownloaded(modelsDir, entry, format) {
73384
- const formatEntry = entry.formats[format];
73385
- if (!formatEntry) return false;
73386
- const modelPath = getModelFilePath(modelsDir, entry, format);
73387
- if (!modelPath || !fs.existsSync(modelPath)) return false;
73388
- if (formatEntry.isDirectory) return fs.existsSync(path$1.join(modelPath, "Manifest.json"));
73389
- if (fs.statSync(modelPath).size <= 0) return false;
73390
- return siblingFilesFor(formatEntry).every((f) => isNonEmptyFile(path$1.join(modelsDir, f)));
73391
- }
73392
- /** Remove the on-disk model file/directory. Returns true if something was deleted. */
73393
- function deleteModelFromDisk(modelsDir, entry, format) {
73394
- const modelPath = getModelFilePath(modelsDir, entry, format);
73395
- if (!modelPath || !fs.existsSync(modelPath)) return false;
73396
- const formatEntry = entry.formats[format];
73397
- if (formatEntry?.isDirectory) fs.rmSync(modelPath, {
73398
- recursive: true,
73399
- force: true
73400
- });
73401
- else {
73402
- fs.unlinkSync(modelPath);
73403
- if (formatEntry) for (const sibling of siblingFilesFor(formatEntry)) {
73404
- const sibPath = path$1.join(modelsDir, sibling);
73405
- if (fs.existsSync(sibPath)) fs.unlinkSync(sibPath);
73406
- }
73407
- }
73408
- return true;
73409
- }
73410
- promisify(brotliCompress);
73411
- promisify(gzip);
73412
- //#endregion
73413
73500
  //#region src/runtime/model-ops.ts
73414
73501
  /**
73415
73502
  * Default `RuntimeModelOps` — the ONLY place the reused object-detection model
@@ -73445,14 +73532,14 @@ function planFiles(modelsDir, entry) {
73445
73532
  const filename = formatEntry.url.split("/").pop() ?? `${entry.id}.${GGUF}`;
73446
73533
  out.push({
73447
73534
  url: formatEntry.url,
73448
- destPath: path$1.join(modelsDir, filename),
73535
+ destPath: path.join(modelsDir, filename),
73449
73536
  filename,
73450
73537
  expectedBytes: formatEntry.sizeMB * BYTES_PER_MB
73451
73538
  });
73452
73539
  }
73453
73540
  for (const extra of entry.extraFiles ?? []) out.push({
73454
73541
  url: extra.url,
73455
- destPath: path$1.join(modelsDir, extra.filename),
73542
+ destPath: path.join(modelsDir, extra.filename),
73456
73543
  filename: extra.filename,
73457
73544
  expectedBytes: extra.sizeMB * BYTES_PER_MB
73458
73545
  });
@@ -73497,7 +73584,7 @@ function createDefaultModelOps(modelsDir) {
73497
73584
  delete: async (entry) => {
73498
73585
  deleteModelFromDisk(modelsDir, entry, GGUF);
73499
73586
  },
73500
- extraFilePath: (_entry, filename) => path$1.join(modelsDir, filename)
73587
+ extraFilePath: (_entry, filename) => path.join(modelsDir, filename)
73501
73588
  };
73502
73589
  }
73503
73590
  //#endregion
@@ -74207,7 +74294,7 @@ function createLlmRuntimeProvider(deps) {
74207
74294
  deleteModel: async ({ file }) => {
74208
74295
  const loaded = deps.supervisor.status().modelPath;
74209
74296
  if (loaded !== void 0 && basename(loaded) === file) throw new Error(`cannot delete ${file}: loaded by the running runtime`);
74210
- await fsp.rm(path$1.join(deps.modelsDir, file), { force: true });
74297
+ await fsp.rm(path.join(deps.modelsDir, file), { force: true });
74211
74298
  },
74212
74299
  listLocalModels: async () => {
74213
74300
  return (await listGgufFiles(deps.modelsDir)).map((f) => {
@@ -74215,7 +74302,7 @@ function createLlmRuntimeProvider(deps) {
74215
74302
  return {
74216
74303
  file: f.file,
74217
74304
  sizeBytes: f.sizeBytes,
74218
- path: path$1.join(deps.modelsDir, f.file),
74305
+ path: path.join(deps.modelsDir, f.file),
74219
74306
  ...catalogId !== void 0 ? { catalogId } : {}
74220
74307
  };
74221
74308
  });
@@ -74240,7 +74327,7 @@ async function listGgufFiles(dir) {
74240
74327
  for (const name of names) {
74241
74328
  if (!name.endsWith(".gguf")) continue;
74242
74329
  try {
74243
- const stat = await fsp.stat(path$1.join(dir, name));
74330
+ const stat = await fsp.stat(path.join(dir, name));
74244
74331
  out.push({
74245
74332
  file: name,
74246
74333
  sizeBytes: stat.size
@@ -75574,7 +75661,7 @@ var AiAddon = class extends BaseAddon {
75574
75661
  this.supervisor = supervisor;
75575
75662
  const settingsPort = api !== void 0 ? createApiSettingsStorePort(api) : createMemorySettingsStorePort();
75576
75663
  if (api === void 0) logger.warn("addon-ai: no ctx.api — profiles are in-memory only");
75577
- const binDir = path$1.join(ctx.nodeDataDir, "bin");
75664
+ const binDir = path.join(ctx.nodeDataDir, "bin");
75578
75665
  const { ensureLlamaServer } = await import("./ensure-llama-server-D_uzfSep.mjs").then((n) => n.r);
75579
75666
  const assembly = await assembleAi({
75580
75667
  nodeId: ownNodeId,