@opendatalabs/personal-server-ts-server 1.27.0 → 1.28.0

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.
@@ -45302,7 +45302,7 @@ function FpSqrt(P11) {
45302
45302
  return sqrt5mod8;
45303
45303
  return tonelliShanks(P11);
45304
45304
  }
45305
- function validateField(field) {
45305
+ function validateField(field2) {
45306
45306
  const initial = {
45307
45307
  ORDER: "bigint",
45308
45308
  MASK: "bigint",
@@ -45313,7 +45313,7 @@ function validateField(field) {
45313
45313
  map2[val] = "function";
45314
45314
  return map2;
45315
45315
  }, initial);
45316
- return validateObject(field, opts);
45316
+ return validateObject(field2, opts);
45317
45317
  }
45318
45318
  function FpPow(Fp2, num2, power) {
45319
45319
  if (power < _0n3)
@@ -45518,11 +45518,11 @@ function validateMSMPoints(points, c10) {
45518
45518
  throw new Error("invalid point at index " + i10);
45519
45519
  });
45520
45520
  }
45521
- function validateMSMScalars(scalars, field) {
45521
+ function validateMSMScalars(scalars, field2) {
45522
45522
  if (!Array.isArray(scalars))
45523
45523
  throw new Error("array of scalars expected");
45524
45524
  scalars.forEach((s10, i10) => {
45525
- if (!field.isValid(s10))
45525
+ if (!field2.isValid(s10))
45526
45526
  throw new Error("invalid scalar at index " + i10);
45527
45527
  });
45528
45528
  }
@@ -46827,13 +46827,13 @@ function hash_to_field(msg, count, options) {
46827
46827
  }
46828
46828
  return u10;
46829
46829
  }
46830
- function isogenyMap(field, map2) {
46830
+ function isogenyMap(field2, map2) {
46831
46831
  const coeff = map2.map((i10) => Array.from(i10).reverse());
46832
46832
  return (x10, y10) => {
46833
- const [xn3, xd2, yn3, yd2] = coeff.map((val) => val.reduce((acc, i10) => field.add(field.mul(acc, x10), i10)));
46834
- const [xd_inv, yd_inv] = FpInvertBatch(field, [xd2, yd2], true);
46835
- x10 = field.mul(xn3, xd_inv);
46836
- y10 = field.mul(y10, field.mul(yn3, yd_inv));
46833
+ const [xn3, xd2, yn3, yd2] = coeff.map((val) => val.reduce((acc, i10) => field2.add(field2.mul(acc, x10), i10)));
46834
+ const [xd_inv, yd_inv] = FpInvertBatch(field2, [xd2, yd2], true);
46835
+ x10 = field2.mul(xn3, xd_inv);
46836
+ y10 = field2.mul(y10, field2.mul(yn3, yd_inv));
46837
46837
  return { x: x10, y: y10 };
46838
46838
  };
46839
46839
  }
@@ -90109,24 +90109,24 @@ var hebNutrition = {
90109
90109
  if (["high", "medium", "low"].includes(String(n10.confidence))) {
90110
90110
  item.confidence = n10.confidence;
90111
90111
  }
90112
- for (const field of hebNutritionFields.slice(4, 19)) {
90113
- if (n10[field] === null || typeof n10[field] === "number") {
90114
- item[field] = n10[field];
90112
+ for (const field2 of hebNutritionFields.slice(4, 19)) {
90113
+ if (n10[field2] === null || typeof n10[field2] === "number") {
90114
+ item[field2] = n10[field2];
90115
90115
  }
90116
90116
  }
90117
90117
  if (n10.serving_size === null || typeof n10.serving_size === "string")
90118
90118
  item.servingSize = n10.serving_size;
90119
90119
  if (n10.servings_per_container === null || typeof n10.servings_per_container === "string")
90120
90120
  item.servingsPerContainer = n10.servings_per_container;
90121
- for (const field of [
90121
+ for (const field2 of [
90122
90122
  "upc",
90123
90123
  "ingredients",
90124
90124
  "allergens",
90125
90125
  "category",
90126
90126
  "highlights"
90127
90127
  ]) {
90128
- if (n10[field] !== void 0)
90129
- item[field] = n10[field];
90128
+ if (n10[field2] !== void 0)
90129
+ item[field2] = n10[field2];
90130
90130
  }
90131
90131
  const paddedProductId = n10.product_id.padStart(9, "0");
90132
90132
  item.images = {
@@ -90580,7 +90580,7 @@ var wholefoodsNutrition = {
90580
90580
  if (["high", "medium", "low"].includes(String(n10.confidence))) {
90581
90581
  item.confidence = n10.confidence;
90582
90582
  }
90583
- for (const field of [
90583
+ for (const field2 of [
90584
90584
  "calories",
90585
90585
  "protein_g",
90586
90586
  "carbs_g",
@@ -90589,8 +90589,8 @@ var wholefoodsNutrition = {
90589
90589
  "fiber_g",
90590
90590
  "sugar_g"
90591
90591
  ]) {
90592
- if (n10[field] === null || typeof n10[field] === "number") {
90593
- item[field] = n10[field];
90592
+ if (n10[field2] === null || typeof n10[field2] === "number") {
90593
+ item[field2] = n10[field2];
90594
90594
  }
90595
90595
  }
90596
90596
  if (n10.serving_size === null || typeof n10.serving_size === "string")
@@ -90721,8 +90721,8 @@ var icloudNotes = {
90721
90721
  const notes = byStream(records, "notes").map((note) => {
90722
90722
  if (typeof note.id !== "string" || note.id.length === 0)
90723
90723
  return void 0;
90724
- const optionalString = (field) => {
90725
- const value = note[field];
90724
+ const optionalString = (field2) => {
90725
+ const value = note[field2];
90726
90726
  return value == null || typeof value === "string" ? value ?? null : void 0;
90727
90727
  };
90728
90728
  const title = optionalString("title");
@@ -90899,22 +90899,22 @@ function browserBinding(stream) {
90899
90899
  }
90900
90900
  };
90901
90901
  }
90902
- for (const field of requiredByStream[stream]) {
90903
- if (snapshot[field] === void 0 || snapshot[field] === null) {
90902
+ for (const field2 of requiredByStream[stream]) {
90903
+ if (snapshot[field2] === void 0 || snapshot[field2] === null) {
90904
90904
  return {
90905
90905
  ok: false,
90906
90906
  error: {
90907
90907
  kind: "incomplete_scope",
90908
90908
  scope,
90909
- reason: `${stream}.${field} is unavailable`
90909
+ reason: `${stream}.${field2} is unavailable`
90910
90910
  }
90911
90911
  };
90912
90912
  }
90913
90913
  }
90914
90914
  const payload = {};
90915
- for (const field of fields) {
90916
- if (Object.hasOwn(snapshot, field))
90917
- payload[field] = snapshot[field];
90915
+ for (const field2 of fields) {
90916
+ if (Object.hasOwn(snapshot, field2))
90917
+ payload[field2] = snapshot[field2];
90918
90918
  }
90919
90919
  if (stream === "events" && Object.hasOwn(payload, "windowDescription")) {
90920
90920
  payload.windowDescription = legacyEventsWindowDescription;
@@ -91211,7 +91211,7 @@ function inPrimaryKeyOrder(records, primaryKey) {
91211
91211
  const keyOf = (record2) => {
91212
91212
  const data = record2.data;
91213
91213
  const fields = primaryKey[record2.stream] ?? [];
91214
- return JSON.stringify(fields.map((field) => data && typeof data === "object" ? data[field] ?? null : null));
91214
+ return JSON.stringify(fields.map((field2) => data && typeof data === "object" ? data[field2] ?? null : null));
91215
91215
  };
91216
91216
  return records.map((record2, index) => ({ record: record2, index, key: keyOf(record2) })).sort((a10, b10) => {
91217
91217
  if (a10.record.stream !== b10.record.stream)
@@ -91788,14 +91788,14 @@ function malformedCursor(message) {
91788
91788
  }
91789
91789
  };
91790
91790
  }
91791
- function assertNonEmptyString(value, field) {
91791
+ function assertNonEmptyString(value, field2) {
91792
91792
  if (value.length === 0) {
91793
- throw new Error(`${field} must be a non-empty string`);
91793
+ throw new Error(`${field2} must be a non-empty string`);
91794
91794
  }
91795
91795
  }
91796
- function assertNonNegativeInteger(value, field) {
91796
+ function assertNonNegativeInteger(value, field2) {
91797
91797
  if (!isNonNegativeInteger(value)) {
91798
- throw new Error(`${field} must be a non-negative integer`);
91798
+ throw new Error(`${field2} must be a non-negative integer`);
91799
91799
  }
91800
91800
  }
91801
91801
  function isNonNegativeInteger(value) {
@@ -92257,6 +92257,7 @@ function classifyStoredBody(scope, data) {
92257
92257
  return isProjectedScope(scope) && !data.records.some(isTaggedRecord) ? "pdpp-projected" : "pdpp-unprojected";
92258
92258
  }
92259
92259
  var SERVED = /* @__PURE__ */ Symbol.for("personal-server-ts.legacy-projection.served");
92260
+ var PROJECTED_VIEW = /* @__PURE__ */ Symbol.for("personal-server-ts.legacy-projection.projected-view");
92260
92261
  var textEncoder5 = new TextEncoder();
92261
92262
  var FORM_CACHE_SIZE = 64;
92262
92263
  function withLegacyProjection(raw, options = {}) {
@@ -92361,7 +92362,8 @@ function withLegacyProjection(raw, options = {}) {
92361
92362
  const envelope = { ...own, data: result.payload };
92362
92363
  return {
92363
92364
  envelope,
92364
- bytes: textEncoder5.encode(JSON.stringify(envelope))
92365
+ bytes: textEncoder5.encode(JSON.stringify(envelope)),
92366
+ ...result.diagnostics?.length ? { diagnostics: result.diagnostics } : {}
92365
92367
  };
92366
92368
  }
92367
92369
  async function builtBlocks(scope, view) {
@@ -92375,6 +92377,7 @@ function withLegacyProjection(raw, options = {}) {
92375
92377
  }
92376
92378
  const overrides = {
92377
92379
  [SERVED]: true,
92380
+ [PROJECTED_VIEW]: projected,
92378
92381
  async readEnvelope(scope, collectedAt) {
92379
92382
  const { view, own } = await resolve(scope, collectedAt);
92380
92383
  return view?.envelope ?? own ?? raw.readEnvelope(scope, collectedAt);
@@ -92512,6 +92515,128 @@ function isRecordsBody(data) {
92512
92515
  const keys = Object.keys(data).filter((key) => !SERVER_STAMP_KEYS.has(key));
92513
92516
  return keys.length === 1 && keys[0] === "records" && Array.isArray(data.records);
92514
92517
  }
92518
+ async function supersedeLegacyVersions(storage, scope, committedAt) {
92519
+ const refuse = (refused) => ({
92520
+ superseded: [],
92521
+ refused
92522
+ });
92523
+ const readStored = (storage.readStoredEnvelope ?? storage.readEnvelope).bind(storage);
92524
+ const committed = await readStored(scope, committedAt);
92525
+ if (classifyStoredBody(scope, committed.data) !== "pdpp-projected") {
92526
+ return refuse("the new version is not PDPP records of a projected scope");
92527
+ }
92528
+ const projectedView = storage[PROJECTED_VIEW];
92529
+ const view = projectedView ? await projectedView(scope, committedAt) : null;
92530
+ if (!view)
92531
+ return refuse("the new version cannot be projected");
92532
+ if (view.diagnostics?.length) {
92533
+ const kinds = [...new Set(view.diagnostics.map((d10) => d10.kind))];
92534
+ return refuse(`the projection is partial (${kinds.join(", ")})`);
92535
+ }
92536
+ const collection = legacyCollectionKey(scope);
92537
+ const projectedItems = view.envelope.data[collection];
92538
+ const projectedCount = projectedItems.length;
92539
+ const committedMs = Date.parse(committedAt);
92540
+ const older = [];
92541
+ const pageSize = 100;
92542
+ for (let offset = 0; ; offset += pageSize) {
92543
+ const page = storage.listVersions(scope, { limit: pageSize, offset });
92544
+ for (const entry of page) {
92545
+ if (Date.parse(entry.collectedAt) < committedMs) {
92546
+ older.push(entry.collectedAt);
92547
+ }
92548
+ }
92549
+ if (page.length < pageSize)
92550
+ break;
92551
+ }
92552
+ const legacy = [];
92553
+ for (const collectedAt of older) {
92554
+ const envelope = await readStored(scope, collectedAt);
92555
+ if (isBinaryEnvelope(envelope))
92556
+ continue;
92557
+ const items = legacyCollection(scope, envelope.data);
92558
+ if (items === null)
92559
+ continue;
92560
+ legacy.push({
92561
+ collectedAt,
92562
+ count: items.length,
92563
+ ids: items.map(itemId).filter((id2) => id2 !== void 0),
92564
+ items
92565
+ });
92566
+ }
92567
+ const newest = legacy.reduce((best, version4) => !best || Date.parse(version4.collectedAt) > Date.parse(best.collectedAt) ? version4 : best, void 0);
92568
+ if (newest && projectedCount < newest.count) {
92569
+ return refuse(`the projection has ${projectedCount} ${collection}; the newest legacy version has ${newest.count}`);
92570
+ }
92571
+ if (newest) {
92572
+ const projectedIds = new Set(projectedItems.map(itemId).filter((id2) => id2 !== void 0));
92573
+ const missing = newest.ids.filter((id2) => !projectedIds.has(id2));
92574
+ if (missing.length > 0) {
92575
+ return refuse(`the projection lacks ${missing.length} of the ${collection} in the newest legacy version`);
92576
+ }
92577
+ const shortfall = nestedShortfall(scope, newest.items, projectedItems);
92578
+ if (shortfall)
92579
+ return refuse(shortfall);
92580
+ }
92581
+ const superseded = [];
92582
+ for (const { collectedAt } of legacy) {
92583
+ if (await storage.deleteVersion(scope, collectedAt)) {
92584
+ superseded.push(collectedAt);
92585
+ }
92586
+ }
92587
+ return { superseded };
92588
+ }
92589
+ var NESTED_ITEMS = {
92590
+ "claude.conversations": (item) => ({
92591
+ held: arrayLength(field(item, "messages")),
92592
+ selfShort: false
92593
+ }),
92594
+ "claude.projects": (item) => {
92595
+ const detail = field(item, "detail");
92596
+ const rawDocs = field(detail, "raw_docs");
92597
+ const raw = Array.isArray(rawDocs) ? rawDocs : [];
92598
+ const withId = raw.filter((doc) => typeof field(doc, "uuid") === "string");
92599
+ const docs = arrayLength(field(detail, "docs"));
92600
+ return {
92601
+ held: docs + raw.length - withId.length,
92602
+ selfShort: docs < withId.length
92603
+ };
92604
+ }
92605
+ };
92606
+ function field(value, key) {
92607
+ return value !== null && typeof value === "object" ? value[key] : void 0;
92608
+ }
92609
+ function arrayLength(value) {
92610
+ return Array.isArray(value) ? value.length : 0;
92611
+ }
92612
+ function nestedShortfall(scope, legacyItems, projectedItems) {
92613
+ const nested = NESTED_ITEMS[scope];
92614
+ if (!nested)
92615
+ return void 0;
92616
+ const projectedById = new Map(projectedItems.map((item) => [itemId(item), nested(item).held]));
92617
+ const short = legacyItems.filter((item) => (projectedById.get(itemId(item)) ?? 0) < nested(item).held);
92618
+ const incomplete = projectedItems.filter((item) => nested(item).selfShort);
92619
+ const count = short.length + incomplete.length;
92620
+ return count > 0 ? `the projection holds fewer nested rows than the source or the newest legacy version for ${count} of the ${legacyCollectionKey(scope)}` : void 0;
92621
+ }
92622
+ function legacyCollectionKey(scope) {
92623
+ return scope.slice(scope.indexOf(".") + 1);
92624
+ }
92625
+ function legacyCollection(scope, data) {
92626
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
92627
+ return null;
92628
+ }
92629
+ if (isRecordsBody(data) || "$writtenBy" in data)
92630
+ return null;
92631
+ const items = data[legacyCollectionKey(scope)];
92632
+ return Array.isArray(items) ? items : null;
92633
+ }
92634
+ function itemId(item) {
92635
+ if (item === null || typeof item !== "object")
92636
+ return void 0;
92637
+ const { id: id2, uuid: uuid3 } = item;
92638
+ return typeof id2 === "string" ? id2 : typeof uuid3 === "string" ? uuid3 : void 0;
92639
+ }
92515
92640
 
92516
92641
  // ../../node_modules/viem/_esm/index.js
92517
92642
  init_exports();
@@ -93400,12 +93525,12 @@ function hashStruct({ data, primaryType, types }) {
93400
93525
  function encodeData({ data, primaryType, types }) {
93401
93526
  const encodedTypes = [{ type: "bytes32" }];
93402
93527
  const encodedValues = [hashType({ primaryType, types })];
93403
- for (const field of types[primaryType]) {
93528
+ for (const field2 of types[primaryType]) {
93404
93529
  const [type, value] = encodeField({
93405
93530
  types,
93406
- name: field.name,
93407
- type: field.type,
93408
- value: data[field.name]
93531
+ name: field2.name,
93532
+ type: field2.type,
93533
+ value: data[field2.name]
93409
93534
  });
93410
93535
  encodedTypes.push(type);
93411
93536
  encodedValues.push(value);
@@ -93433,8 +93558,8 @@ function findTypeDependencies({ primaryType: primaryType_, types }, results = /*
93433
93558
  return results;
93434
93559
  }
93435
93560
  results.add(primaryType);
93436
- for (const field of types[primaryType]) {
93437
- findTypeDependencies({ primaryType: field.type, types }, results);
93561
+ for (const field2 of types[primaryType]) {
93562
+ findTypeDependencies({ primaryType: field2.type, types }, results);
93438
93563
  }
93439
93564
  return results;
93440
93565
  }
@@ -97185,10 +97310,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
97185
97310
  const shape = def.shape;
97186
97311
  const propValues = {};
97187
97312
  for (const key in shape) {
97188
- const field = shape[key]._zod;
97189
- if (field.values) {
97313
+ const field2 = shape[key]._zod;
97314
+ if (field2.values) {
97190
97315
  propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
97191
- for (const v10 of field.values)
97316
+ for (const v10 of field2.values)
97192
97317
  propValues[key].add(v10);
97193
97318
  }
97194
97319
  }
@@ -115112,6 +115237,25 @@ function encodePaymentResponseHeader(body) {
115112
115237
  function contractResponse(result) {
115113
115238
  return jsonResponse(result.body, { status: result.status });
115114
115239
  }
115240
+ async function supersedeAfterCommit(deps, scope, committedAt) {
115241
+ try {
115242
+ const result = await supersedeLegacyVersions(deps.storage, scope, committedAt);
115243
+ if (result.superseded.length > 0) {
115244
+ deps.logger?.info?.({ scope, committedAt, superseded: result.superseded }, "Deleted legacy-form versions superseded by a PDPP write");
115245
+ }
115246
+ if (result.refused) {
115247
+ deps.logger?.info?.({ scope, committedAt, refused: result.refused }, "Kept legacy-form versions; superseding was refused");
115248
+ }
115249
+ return result;
115250
+ } catch (err2) {
115251
+ deps.logger?.warn?.({
115252
+ scope,
115253
+ committedAt,
115254
+ error: err2 instanceof Error ? err2.message : String(err2)
115255
+ }, "Superseding legacy-form versions failed; the write is stored");
115256
+ return { superseded: [], refused: "superseding failed" };
115257
+ }
115258
+ }
115115
115259
  function contractErrorResponse(err2) {
115116
115260
  return jsonResponse(err2.body, { status: err2.status });
115117
115261
  }
@@ -115412,12 +115556,12 @@ function fireReadReport(deps, event, send) {
115412
115556
  warnReadFulfillmentReporterFailed(deps, event, err2);
115413
115557
  }
115414
115558
  }
115415
- async function prepareWriteLineage(deps, scope, field) {
115416
- if (field === void 0 || field === null)
115559
+ async function prepareWriteLineage(deps, scope, field2) {
115560
+ if (field2 === void 0 || field2 === null)
115417
115561
  return void 0;
115418
115562
  return prepareLineage({
115419
115563
  scope,
115420
- field,
115564
+ field: field2,
115421
115565
  serverOwner: deps.serverOwner,
115422
115566
  storage: deps.storage,
115423
115567
  gateway: deps.lineageGateway,
@@ -115730,6 +115874,15 @@ async function handlePersonalServerDataRequest(request2, deps, options = {}) {
115730
115874
  } else {
115731
115875
  await deps.auth.authorizeOwner(request2);
115732
115876
  }
115877
+ const supersede = url2.searchParams.get("supersede");
115878
+ if (supersede !== null && supersede !== "legacy") {
115879
+ await writeAuth?.releaseProof?.();
115880
+ return errorResponse(400, "INVALID_SUPERSEDE", 'supersede must be "legacy" or absent');
115881
+ }
115882
+ if (supersede !== null && writeAuth) {
115883
+ await writeAuth.releaseProof?.();
115884
+ return errorResponse(403, "FORBIDDEN", "Only the owner can supersede stored versions");
115885
+ }
115733
115886
  let committed = false;
115734
115887
  let releaseStamp;
115735
115888
  const failWrite = async (response) => {
@@ -115769,6 +115922,9 @@ async function handlePersonalServerDataRequest(request2, deps, options = {}) {
115769
115922
  }
115770
115923
  };
115771
115924
  if (!isJsonContentType(request2)) {
115925
+ if (supersede !== null) {
115926
+ return failWrite(errorResponse(400, "INVALID_SUPERSEDE", "supersede applies to JSON writes only"));
115927
+ }
115772
115928
  const bytes2 = new Uint8Array(await request2.arrayBuffer());
115773
115929
  const metadata = parseMetadataHeader(request2.headers.get("x-vana-metadata"));
115774
115930
  const lineage2 = await prepareWriteLineage(deps, scopeResult.scope, extractLineageField(metadata));
@@ -115829,13 +115985,18 @@ async function handlePersonalServerDataRequest(request2, deps, options = {}) {
115829
115985
  ...writeAuth ? { builder: writeAuth.builder } : {}
115830
115986
  }, "Data file ingested");
115831
115987
  await logBuilderWrite();
115988
+ const supersedeResult = supersede === "legacy" ? await supersedeAfterCommit(deps, scopeResult.scope, collectedAtValue) : void 0;
115832
115989
  notifyNewData(deps.syncManager);
115833
115990
  notifyDataWritten(deps, {
115834
115991
  scope: scopeResult.scope,
115835
115992
  collectedAt: collectedAtValue,
115836
115993
  lineageSources: lineage?.sources
115837
115994
  });
115838
- return jsonResponse(result.response, { status: 201 });
115995
+ return jsonResponse(supersedeResult ? {
115996
+ ...result.response,
115997
+ superseded: supersedeResult.superseded,
115998
+ ...supersedeResult.refused ? { supersedeRefused: supersedeResult.refused } : {}
115999
+ } : result.response, { status: 201 });
115839
116000
  } catch (err2) {
115840
116001
  if (err2 instanceof IngestPersistedError) {
115841
116002
  deps.logger?.error?.({
@@ -117684,7 +117845,7 @@ function parseField(value, index) {
117684
117845
  }
117685
117846
  required2 = value.required;
117686
117847
  }
117687
- const field = { name, type, required: required2 };
117848
+ const field2 = { name, type, required: required2 };
117688
117849
  if (type === "string") {
117689
117850
  let maxLength = MAX_ANSWER_STRING_CHARS;
117690
117851
  if (value.maxLength !== void 0 && value.maxLength !== null) {
@@ -117693,26 +117854,26 @@ function parseField(value, index) {
117693
117854
  }
117694
117855
  maxLength = value.maxLength;
117695
117856
  }
117696
- field.maxLength = maxLength;
117857
+ field2.maxLength = maxLength;
117697
117858
  }
117698
117859
  if (type === "number" || type === "integer") {
117699
117860
  const integer2 = type === "integer";
117700
117861
  if (value.min !== void 0 && value.min !== null) {
117701
- field.min = parseBound(value.min, index, "min", integer2);
117862
+ field2.min = parseBound(value.min, index, "min", integer2);
117702
117863
  }
117703
117864
  if (value.max !== void 0 && value.max !== null) {
117704
- field.max = parseBound(value.max, index, "max", integer2);
117865
+ field2.max = parseBound(value.max, index, "max", integer2);
117705
117866
  }
117706
- if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) {
117867
+ if (field2.min !== void 0 && field2.max !== void 0 && field2.min > field2.max) {
117707
117868
  invalid(`answerShape.fields[${index}].min is greater than its max`, {
117708
117869
  index
117709
117870
  });
117710
117871
  }
117711
117872
  }
117712
117873
  if (type === "enum") {
117713
- field.values = parseEnumValues(value.values, index);
117874
+ field2.values = parseEnumValues(value.values, index);
117714
117875
  }
117715
- return field;
117876
+ return field2;
117716
117877
  }
117717
117878
  function parseAnswerShapeInput(value) {
117718
117879
  if (value === void 0 || value === null)
@@ -117736,30 +117897,30 @@ function parseAnswerShapeInput(value) {
117736
117897
  const fields = [];
117737
117898
  const names = /* @__PURE__ */ new Set();
117738
117899
  value.fields.forEach((entry, index) => {
117739
- const field = parseField(entry, index);
117740
- if (names.has(field.name)) {
117741
- invalid(`answerShape.fields names "${field.name}" twice`, { index });
117900
+ const field2 = parseField(entry, index);
117901
+ if (names.has(field2.name)) {
117902
+ invalid(`answerShape.fields names "${field2.name}" twice`, { index });
117742
117903
  }
117743
- names.add(field.name);
117744
- fields.push(field);
117904
+ names.add(field2.name);
117905
+ fields.push(field2);
117745
117906
  });
117746
117907
  return { fields };
117747
117908
  }
117748
117909
  function compileAnswerShape(shape) {
117749
117910
  const entries = {};
117750
- for (const field of shape.fields) {
117911
+ for (const field2 of shape.fields) {
117751
117912
  let schema;
117752
- switch (field.type) {
117913
+ switch (field2.type) {
117753
117914
  case "string":
117754
- schema = external_exports.string().max(field.maxLength ?? MAX_ANSWER_STRING_CHARS);
117915
+ schema = external_exports.string().max(field2.maxLength ?? MAX_ANSWER_STRING_CHARS);
117755
117916
  break;
117756
117917
  case "number":
117757
117918
  case "integer": {
117758
- let numeric = field.type === "integer" ? external_exports.int() : external_exports.number();
117759
- if (field.min !== void 0)
117760
- numeric = numeric.min(field.min);
117761
- if (field.max !== void 0)
117762
- numeric = numeric.max(field.max);
117919
+ let numeric = field2.type === "integer" ? external_exports.int() : external_exports.number();
117920
+ if (field2.min !== void 0)
117921
+ numeric = numeric.min(field2.min);
117922
+ if (field2.max !== void 0)
117923
+ numeric = numeric.max(field2.max);
117763
117924
  schema = numeric;
117764
117925
  break;
117765
117926
  }
@@ -117767,10 +117928,10 @@ function compileAnswerShape(shape) {
117767
117928
  schema = external_exports.boolean();
117768
117929
  break;
117769
117930
  case "enum":
117770
- schema = external_exports.enum(field.values ?? []);
117931
+ schema = external_exports.enum(field2.values ?? []);
117771
117932
  break;
117772
117933
  }
117773
- entries[field.name] = field.required ? schema : schema.nullish();
117934
+ entries[field2.name] = field2.required ? schema : schema.nullish();
117774
117935
  }
117775
117936
  return external_exports.object(entries);
117776
117937
  }
@@ -117789,44 +117950,44 @@ function validateAnswerShape(shape, compiled, candidate) {
117789
117950
  };
117790
117951
  }
117791
117952
  const value = {};
117792
- for (const field of shape.fields) {
117793
- const entry = parsed.data[field.name];
117953
+ for (const field2 of shape.fields) {
117954
+ const entry = parsed.data[field2.name];
117794
117955
  if (entry === void 0 || entry === null)
117795
117956
  continue;
117796
- value[field.name] = entry;
117957
+ value[field2.name] = entry;
117797
117958
  }
117798
117959
  return { ok: true, value };
117799
117960
  }
117800
- function describeField(field) {
117801
- const requirement = field.required ? "required" : "optional";
117802
- switch (field.type) {
117961
+ function describeField(field2) {
117962
+ const requirement = field2.required ? "required" : "optional";
117963
+ switch (field2.type) {
117803
117964
  case "string":
117804
- return `"${field.name}": string, at most ${field.maxLength ?? MAX_ANSWER_STRING_CHARS} characters (${requirement})`;
117965
+ return `"${field2.name}": string, at most ${field2.maxLength ?? MAX_ANSWER_STRING_CHARS} characters (${requirement})`;
117805
117966
  case "number":
117806
117967
  case "integer": {
117807
- const kind = field.type === "integer" ? "integer" : "number";
117808
- const range = field.min !== void 0 && field.max !== void 0 ? ` between ${field.min} and ${field.max}` : field.min !== void 0 ? ` of at least ${field.min}` : field.max !== void 0 ? ` of at most ${field.max}` : "";
117809
- return `"${field.name}": ${kind}${range} (${requirement})`;
117968
+ const kind = field2.type === "integer" ? "integer" : "number";
117969
+ const range = field2.min !== void 0 && field2.max !== void 0 ? ` between ${field2.min} and ${field2.max}` : field2.min !== void 0 ? ` of at least ${field2.min}` : field2.max !== void 0 ? ` of at most ${field2.max}` : "";
117970
+ return `"${field2.name}": ${kind}${range} (${requirement})`;
117810
117971
  }
117811
117972
  case "boolean":
117812
- return `"${field.name}": true or false (${requirement})`;
117973
+ return `"${field2.name}": true or false (${requirement})`;
117813
117974
  case "enum":
117814
- return `"${field.name}": exactly one of ${(field.values ?? []).map((entry) => JSON.stringify(entry)).join(", ")} (${requirement})`;
117975
+ return `"${field2.name}": exactly one of ${(field2.values ?? []).map((entry) => JSON.stringify(entry)).join(", ")} (${requirement})`;
117815
117976
  }
117816
117977
  }
117817
117978
  function describeAnswerShape(shape) {
117818
- return shape.fields.map((field) => ` ${describeField(field)}`);
117979
+ return shape.fields.map((field2) => ` ${describeField(field2)}`);
117819
117980
  }
117820
117981
  function renderShapedAnswer(shape, value) {
117821
- return shape.fields.filter((field) => value[field.name] !== void 0).map((field) => `${field.name}: ${String(value[field.name])}`).join("\n");
117982
+ return shape.fields.filter((field2) => value[field2.name] !== void 0).map((field2) => `${field2.name}: ${String(value[field2.name])}`).join("\n");
117822
117983
  }
117823
117984
  function cloneAnswerShape(shape) {
117824
117985
  if (!shape)
117825
117986
  return null;
117826
117987
  return {
117827
- fields: shape.fields.map((field) => ({
117828
- ...field,
117829
- ...field.values ? { values: [...field.values] } : {}
117988
+ fields: shape.fields.map((field2) => ({
117989
+ ...field2,
117990
+ ...field2.values ? { values: [...field2.values] } : {}
117830
117991
  }))
117831
117992
  };
117832
117993
  }
@@ -117933,15 +118094,15 @@ var MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/;
117933
118094
  function isRecord5(value) {
117934
118095
  return value !== null && typeof value === "object" && !Array.isArray(value);
117935
118096
  }
117936
- function parseScope(value, field) {
118097
+ function parseScope(value, field2) {
117937
118098
  if (typeof value !== "string") {
117938
- throw new DerivativeQuestionInvalidError(`${field} must be a scope string`, {
117939
- field
118099
+ throw new DerivativeQuestionInvalidError(`${field2} must be a scope string`, {
118100
+ field: field2
117940
118101
  });
117941
118102
  }
117942
118103
  const parsed = parseDataScopeContract(value);
117943
118104
  if (!parsed.ok) {
117944
- throw new DerivativeQuestionInvalidError(`${field} is not a valid scope: ${parsed.body.message}`, { field, scope: value.slice(0, MAX_ECHOED_SCOPE_CHARS) });
118105
+ throw new DerivativeQuestionInvalidError(`${field2} is not a valid scope: ${parsed.body.message}`, { field: field2, scope: value.slice(0, MAX_ECHOED_SCOPE_CHARS) });
117945
118106
  }
117946
118107
  return parsed.scope;
117947
118108
  }
@@ -118318,14 +118479,14 @@ function readContent(body) {
118318
118479
  if (!isRecord7(first) || !isRecord7(first.message))
118319
118480
  return null;
118320
118481
  const index = typeof first.index === "number" ? first.index : 0;
118321
- const field = `choices.${index}.message.content`;
118482
+ const field2 = `choices.${index}.message.content`;
118322
118483
  const id2 = typeof body.id === "string" ? body.id : "";
118323
118484
  const content = first.message.content;
118324
118485
  if (typeof content === "string")
118325
- return { content, field, id: id2 };
118486
+ return { content, field: field2, id: id2 };
118326
118487
  if (Array.isArray(content)) {
118327
118488
  const text = content.map((part) => isRecord7(part) && typeof part.text === "string" ? part.text : "").join("");
118328
- return { content: text, field, id: id2 };
118489
+ return { content: text, field: field2, id: id2 };
118329
118490
  }
118330
118491
  return null;
118331
118492
  }
@@ -118558,7 +118719,7 @@ async function produceAnswer(deps, registration, model, messages) {
118558
118719
  answerShape: shape
118559
118720
  });
118560
118721
  }
118561
- throw new ComputeFailure(`answer did not match the declared shape (fields: ${shape.fields.map((field) => field.name).join(", ")})`, "internal");
118722
+ throw new ComputeFailure(`answer did not match the declared shape (fields: ${shape.fields.map((field2) => field2.name).join(", ")})`, "internal");
118562
118723
  }
118563
118724
  function collectedAtStamp(now, isTaken) {
118564
118725
  const base = now();
@@ -119379,23 +119540,23 @@ function canonicalJsonBytes(value) {
119379
119540
  // ../core/dist/derivatives/e2ee/aad.js
119380
119541
  var E2EE_REQUEST_AAD_PURPOSE = "aci.e2ee.request.v2";
119381
119542
  var E2EE_RESPONSE_AAD_PURPOSE = "aci.e2ee.response.v2";
119382
- function requestFieldAad(context, field) {
119543
+ function requestFieldAad(context, field2) {
119383
119544
  return canonicalJsonBytes({
119384
119545
  purpose: E2EE_REQUEST_AAD_PURPOSE,
119385
119546
  algo: context.algo,
119386
119547
  model: context.model,
119387
- field,
119548
+ field: field2,
119388
119549
  nonce: context.nonce,
119389
119550
  ts: context.ts
119390
119551
  });
119391
119552
  }
119392
- function responseFieldAad(context, field, id2) {
119553
+ function responseFieldAad(context, field2, id2) {
119393
119554
  return canonicalJsonBytes({
119394
119555
  purpose: E2EE_RESPONSE_AAD_PURPOSE,
119395
119556
  algo: context.algo,
119396
119557
  model: context.model,
119397
119558
  id: id2,
119398
- field,
119559
+ field: field2,
119399
119560
  nonce: context.nonce,
119400
119561
  ts: context.ts
119401
119562
  });
@@ -119815,7 +119976,7 @@ function createPhalaE2eeEncryption(options) {
119815
119976
  }
119816
119977
  const request2 = {
119817
119978
  messages: encrypted,
119818
- async decryptResponse({ content, field, id: id2, headers: response }) {
119979
+ async decryptResponse({ content, field: field2, id: id2, headers: response }) {
119819
119980
  const served = response.get(ACI_HEADER_KEYSET_DIGEST);
119820
119981
  if (served && served !== gatewayKey.keysetDigest) {
119821
119982
  options.logger?.warn?.({ pinned: gatewayKey.keysetDigest, served }, "E2EE keyset digest changed; refetching the attestation report");
@@ -119825,11 +119986,11 @@ function createPhalaE2eeEncryption(options) {
119825
119986
  return await decryptField({
119826
119987
  wire: content,
119827
119988
  privateKey: client.privateKey,
119828
- aad: responseFieldAad(context, field, id2)
119989
+ aad: responseFieldAad(context, field2, id2)
119829
119990
  });
119830
119991
  } catch (err2) {
119831
119992
  const detail = err2 instanceof E2eeCipherError ? err2.message : "unexpected error";
119832
- throw new InferenceRequestError(`e2ee response decryption failed for ${field} (${detail})`, null, { errorType: "e2ee_decryption_failed", retryable: false });
119993
+ throw new InferenceRequestError(`e2ee response decryption failed for ${field2} (${detail})`, null, { errorType: "e2ee_decryption_failed", retryable: false });
119833
119994
  }
119834
119995
  }
119835
119996
  };
@@ -120946,16 +121107,16 @@ var MiniSearch = class _MiniSearch {
120946
121107
  }
120947
121108
  const shortDocumentId = this.addDocumentId(id2);
120948
121109
  this.saveStoredFields(shortDocumentId, document2);
120949
- for (const field of fields) {
120950
- const fieldValue = extractField(document2, field);
121110
+ for (const field2 of fields) {
121111
+ const fieldValue = extractField(document2, field2);
120951
121112
  if (fieldValue == null)
120952
121113
  continue;
120953
- const tokens = tokenize(stringifyField(fieldValue, field), field);
120954
- const fieldId = this._fieldIds[field];
121114
+ const tokens = tokenize(stringifyField(fieldValue, field2), field2);
121115
+ const fieldId = this._fieldIds[field2];
120955
121116
  const uniqueTerms = new Set(tokens).size;
120956
121117
  this.addFieldLength(shortDocumentId, fieldId, this._documentCount - 1, uniqueTerms);
120957
121118
  for (const term of tokens) {
120958
- const processedTerm = processTerm2(term, field);
121119
+ const processedTerm = processTerm2(term, field2);
120959
121120
  if (Array.isArray(processedTerm)) {
120960
121121
  for (const t10 of processedTerm) {
120961
121122
  this.addTerm(fieldId, shortDocumentId, t10);
@@ -121026,16 +121187,16 @@ var MiniSearch = class _MiniSearch {
121026
121187
  if (shortId == null) {
121027
121188
  throw new Error(`MiniSearch: cannot remove document with ID ${id2}: it is not in the index`);
121028
121189
  }
121029
- for (const field of fields) {
121030
- const fieldValue = extractField(document2, field);
121190
+ for (const field2 of fields) {
121191
+ const fieldValue = extractField(document2, field2);
121031
121192
  if (fieldValue == null)
121032
121193
  continue;
121033
- const tokens = tokenize(stringifyField(fieldValue, field), field);
121034
- const fieldId = this._fieldIds[field];
121194
+ const tokens = tokenize(stringifyField(fieldValue, field2), field2);
121195
+ const fieldId = this._fieldIds[field2];
121035
121196
  const uniqueTerms = new Set(tokens).size;
121036
121197
  this.removeFieldLength(shortId, fieldId, this._documentCount, uniqueTerms);
121037
121198
  for (const term of tokens) {
121038
- const processedTerm = processTerm2(term, field);
121199
+ const processedTerm = processTerm2(term, field2);
121039
121200
  if (Array.isArray(processedTerm)) {
121040
121201
  for (const t10 of processedTerm) {
121041
121202
  this.removeTerm(fieldId, shortId, t10);
@@ -121785,7 +121946,7 @@ var MiniSearch = class _MiniSearch {
121785
121946
  */
121786
121947
  executeQuerySpec(query, searchOptions) {
121787
121948
  const options = { ...this._options.searchOptions, ...searchOptions };
121788
- const boosts = (options.fields || this._options.fields).reduce((boosts2, field) => ({ ...boosts2, [field]: getOwnProperty(options.boost, field) || 1 }), {});
121949
+ const boosts = (options.fields || this._options.fields).reduce((boosts2, field2) => ({ ...boosts2, [field2]: getOwnProperty(options.boost, field2) || 1 }), {});
121789
121950
  const { boostDocument, weights, maxFuzzy, bm25: bm25params } = options;
121790
121951
  const { fuzzy: fuzzyWeight, prefix: prefixWeight } = { ...defaultSearchOptions.weights, ...weights };
121791
121952
  const data = this._index.get(query.term);
@@ -121906,9 +122067,9 @@ var MiniSearch = class _MiniSearch {
121906
122067
  termResults(sourceTerm, derivedTerm, termWeight, termBoost, fieldTermData, fieldBoosts, boostDocumentFn, bm25params, results = /* @__PURE__ */ new Map()) {
121907
122068
  if (fieldTermData == null)
121908
122069
  return results;
121909
- for (const field of Object.keys(fieldBoosts)) {
121910
- const fieldBoost = fieldBoosts[field];
121911
- const fieldId = this._fieldIds[field];
122070
+ for (const field2 of Object.keys(fieldBoosts)) {
122071
+ const fieldBoost = fieldBoosts[field2];
122072
+ const fieldId = this._fieldIds[field2];
121912
122073
  const fieldTermFreqs = fieldTermData.get(fieldId);
121913
122074
  if (fieldTermFreqs == null)
121914
122075
  continue;
@@ -121933,15 +122094,15 @@ var MiniSearch = class _MiniSearch {
121933
122094
  assignUniqueTerm(result.terms, sourceTerm);
121934
122095
  const match = getOwnProperty(result.match, derivedTerm);
121935
122096
  if (match) {
121936
- match.push(field);
122097
+ match.push(field2);
121937
122098
  } else {
121938
- result.match[derivedTerm] = [field];
122099
+ result.match[derivedTerm] = [field2];
121939
122100
  }
121940
122101
  } else {
121941
122102
  results.set(docId, {
121942
122103
  score: weightedScore,
121943
122104
  terms: [sourceTerm],
121944
- match: { [derivedTerm]: [field] }
122105
+ match: { [derivedTerm]: [field2] }
121945
122106
  });
121946
122107
  }
121947
122108
  }
@@ -132709,11 +132870,11 @@ var McpServer = class {
132709
132870
  return EMPTY_COMPLETION_RESULT;
132710
132871
  }
132711
132872
  const promptShape = getObjectShape(prompt.argsSchema);
132712
- const field = promptShape?.[request2.params.argument.name];
132713
- if (!isCompletable(field)) {
132873
+ const field2 = promptShape?.[request2.params.argument.name];
132874
+ if (!isCompletable(field2)) {
132714
132875
  return EMPTY_COMPLETION_RESULT;
132715
132876
  }
132716
- const completer = getCompleter(field);
132877
+ const completer = getCompleter(field2);
132717
132878
  if (!completer) {
132718
132879
  return EMPTY_COMPLETION_RESULT;
132719
132880
  }
@@ -132986,8 +133147,8 @@ var McpServer = class {
132986
133147
  };
132987
133148
  this._registeredPrompts[name] = registeredPrompt;
132988
133149
  if (argsSchema) {
132989
- const hasCompletable = Object.values(argsSchema).some((field) => {
132990
- const inner = field instanceof ZodOptional ? field._def?.innerType : field;
133150
+ const hasCompletable = Object.values(argsSchema).some((field2) => {
133151
+ const inner = field2 instanceof ZodOptional ? field2._def?.innerType : field2;
132991
133152
  return isCompletable(inner);
132992
133153
  });
132993
133154
  if (hasCompletable) {
@@ -133220,9 +133381,9 @@ function promptArgumentsFromSchema(schema) {
133220
133381
  const shape = getObjectShape(schema);
133221
133382
  if (!shape)
133222
133383
  return [];
133223
- return Object.entries(shape).map(([name, field]) => {
133224
- const description = getSchemaDescription(field);
133225
- const isOptional = isSchemaOptional(field);
133384
+ return Object.entries(shape).map(([name, field2]) => {
133385
+ const description = getSchemaDescription(field2);
133386
+ const isOptional = isSchemaOptional(field2);
133226
133387
  return {
133227
133388
  name,
133228
133389
  description,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendatalabs/personal-server-ts-server",
3
- "version": "1.27.0",
3
+ "version": "1.28.0",
4
4
  "description": "Hono HTTP server for the Vana Personal Server — routes, middleware, composition root",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@hono/node-server": "^1.19.13",
54
- "@opendatalabs/personal-server-ts-core": "1.27.0",
55
- "@opendatalabs/personal-server-ts-lite": "1.27.0",
54
+ "@opendatalabs/personal-server-ts-core": "1.28.0",
55
+ "@opendatalabs/personal-server-ts-lite": "1.28.0",
56
56
  "@opendatalabs/vana-sdk": "3.23.0-pr.211.36da1d8",
57
57
  "better-sqlite3": "^12.11.1",
58
58
  "hono": "^4.12.27",