@onlyworlds/sdk 4.84.1 → 4.86.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.
package/AGENTS.md CHANGED
@@ -89,6 +89,10 @@ against live data). The v1 surface (`OnlyWorldsClient`, the `ElementType` enum)
89
89
  - Lookup without a model (since 4.11.0): `buildWorldIndex(elements)` then
90
90
  `lookupWorld(index, question)` ranks the elements a question is about (names, then kind, one
91
91
  link step, then text); `renderElement(el, index)` is a compact card with links by name.
92
+ - A Character's context as text: `draughtText(draught)` turns a `draught(characterId)` packet,
93
+ full or compact, into plain text, read from the packet alone (the same bytes as the Python
94
+ package's `draught_text`). Its title says "dated up to" the horizon, never what the Character
95
+ knew; its last line counts only what the budget left out.
92
96
  - Photos (browser only, since 4.11.0): `preparePhoto(blob)` shrinks to 2048 px and converts to
93
97
  webp (JPEG where webp can't be encoded) before `uploadImage`.
94
98
  - World files (no account needed; since 4.10.0): `readWorldFile(bytes)` opens a `.zip` holding one
@@ -106,7 +110,7 @@ against live data). The v1 surface (`OnlyWorldsClient`, the `ElementType` enum)
106
110
  folding, both Unicode 15.1's from its own files (`nfc` since 4.71.0, `simpleCaseFold`), never
107
111
  the runtime's `normalize`, whose Unicode is its ICU's (Node 22: 16.0).
108
112
  - World calendars (since 4.20.0): `worldCalendars(elements)` finds the elements carrying
109
- `atlas_calendar` (Atlas owns the field: read it, never write it); `resolveCalendarLens` picks
113
+ `atlas_calendar` (Atlas owns the field: read it, never write it); `resolveCalendar` picks
110
114
  one; `formatStep(config, step)` names a point on the world's integer time line, `parseDate`
111
115
  reads one back. No calendar or a broken one is null: show the bare number.
112
116
  - Ids: the client mints **UUIDv7** on an id-less `create` (since 4.2.0; keel mints v7 too).
package/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ earlier history lives in git log only.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [4.86.0] - 2026-10-26
9
+
10
+ ### Added
11
+
12
+ - **`draughtText(draught)`**: one Character's context packet (`draught(characterId)`, full or compact) as plain text to paste into a prompt or a note, the same bytes from both packages and held to them by one shared fixture (47 cases, the full and compact reads of each giving the same text). It reads the packet alone and calls nothing: a link the packet does not hold is counted, never looked up. The title claims only the read's horizon ("dated up to Year 300"), never what the Character knew; every row says how it was reached (`via`), its grade or date, and the marks hidden and proposed; the sections that hold nothing are named on one line, and the last line says only what the budget left out (`cut`). Nothing is trimmed or cut by length, so the two languages cannot disagree on where a string ends. One known difference between a full and a compact read: the server's compact form drops an empty `x_review_proposed` (`""`, `[]`, `{}`), which the full read counts as proposed. The Python package's `draught_text` (0.70.0) gives the same text.
13
+
14
+ ## [4.85.0] - 2026-10-26
15
+
16
+ ### Changed
17
+
18
+ - **`resolveCalendar` is the new name of `resolveCalendarLens`**, with the same arguments and answers. "Lens" now names a cut of a world (what a reader is shown of it), so the function that picks a world's chosen calendar no longer uses the word. `resolveCalendarLens` stays as a deprecated function with the same answers until 5.0; its refusal of an unknown option names the function called.
19
+
8
20
  ## [4.84.1] - 2026-10-26
9
21
 
10
22
  ### Fixed
package/README.md CHANGED
@@ -228,7 +228,7 @@ An accept is refused with nothing written when a proposed field moved since the
228
228
 
229
229
  A world's owner can have agent seats propose instead of write (`agent_writes_proposed` on `getWorld()`, set on the world page). An agent seat's `patch`, `upsert` or `editLinks` on an existing element then throws `OwProposedError` (status 202, `err.isProposed`), with the row under `err.proposal`. A `bulk` slot says `status: 202` and carries `proposal` instead. A person's key is never held.
230
230
 
231
- ## Finding things in a world
231
+ ## Finding elements in a world
232
232
 
233
233
  When you hold a world's elements in memory (from a sync, or a world file), `lookupWorld` finds the ones a plain question is about, with no model and no network:
234
234
 
@@ -268,6 +268,14 @@ Asking and sorting spend tokens from the account's token rating, its daily budge
268
268
  const { token_rating, tokens_remaining, resets_at } = await account.allowance(); // resets_at: the next midnight UTC
269
269
  ```
270
270
 
271
+ ### A Character's context as text
272
+
273
+ `draughtText(draught)` gives one Character's context packet (`draught(characterId)`, full or `compact`) as plain text to paste into a prompt or a note. It reads the packet alone and calls nothing, and the Python package's `draught_text` gives the same bytes. The title claims only the read's horizon ("dated up to Year 300"), never what the Character knew, and the last line says only what the budget left out (`cut`).
274
+
275
+ ```typescript
276
+ const text = draughtText(await client.draught(characterId));
277
+ ```
278
+
271
279
  ## World files
272
280
 
273
281
  A world file (`.owworld`, a `.zip` by another name) is one archive holding a whole world folder (`world.json` and `elements/<type>/*.json`, as Atlas keeps a world on disk), the way Atlas downloads and opens one. It needs no account and works in the browser and in Node. Both functions follow the Folder Format spec's §4.7 and pass its fixture set.
@@ -317,10 +325,10 @@ The two defaults differ on purpose: private records stay out unless you ask, hid
317
325
  A world's time is an integer line (`time_range_current` is a point on it, and so is an Event's `start_date`). A calendar names its points: months, days, eras. Atlas keeps a calendar on an element (a Construct by convention) in its `atlas_calendar` field, and the SDK reads it with Atlas's own calendar code (since 4.20.0). Atlas owns that field and is its only writer; read it, never write it.
318
326
 
319
327
  ```typescript
320
- import { worldCalendars, resolveCalendarLens, formatStep, formatYearLabel, parseDate } from '@onlyworlds/sdk';
328
+ import { worldCalendars, resolveCalendar, formatStep, formatYearLabel, parseDate } from '@onlyworlds/sdk';
321
329
 
322
330
  const calendars = worldCalendars(elements); // [{ id, name, config }]: every element with a valid atlas_calendar
323
- const cal = resolveCalendarLens(elements, chosenId, { fallbackToOnly: true }); // a world with one calendar uses it
331
+ const cal = resolveCalendar(elements, chosenId, { fallbackToOnly: true }); // a world with one calendar uses it
324
332
  if (cal) {
325
333
  formatStep(cal.config, 400); // "4 Alturiak, 1 DR" (with Harptos, from Atlas's tests)
326
334
  formatYearLabel(cal.config, 400); // "1 DR"
package/dist/index.d.ts CHANGED
@@ -5106,6 +5106,20 @@ interface OwAskContext {
5106
5106
  */
5107
5107
  declare function buildAskContext<T extends OwLookupElement>(items: Array<OwLookupHit<T> | T>, index: OwWorldIndex<T>, opts?: OwAskContextOptions): OwAskContext;
5108
5108
 
5109
+ /**
5110
+ * The draught as plain text: a `#` title, `##` sections and `- ` rows, LF line endings and one
5111
+ * newline at the end. The same read gives the same text served full or `compact`.
5112
+ *
5113
+ * The frame says what the packet does: the horizon (`as_of`), the world's now, and whose view it
5114
+ * was read through (`mode`). Her own element prints whole; every other row prints its name, type
5115
+ * and kind, how it reached her (`via`), its grade or date, the marks `hidden` and `proposed`, and
5116
+ * its description. The sections that hold nothing are named on one line, and what the budget left
5117
+ * out (`cut`) is always said.
5118
+ *
5119
+ * A draught that is not an object, or has no `world` object, is a TypeError. Takes no options.
5120
+ */
5121
+ declare function draughtText(draught: OwDraught | OwDraughtCompact): string;
5122
+
5109
5123
  /**
5110
5124
  * Photo preparation: make a picture from a phone's camera or files ready for
5111
5125
  * `uploadImage` (webp, png, jpeg or avif, at most 15 MB), in the browser,
@@ -5394,7 +5408,7 @@ declare function isParseError(r: ParseResult | ParseError): r is ParseError;
5394
5408
  * the one copy since Atlas 245aad3 deleted its own and imports this one:
5395
5409
  * a kernel change is an SDK release, and Atlas's 48 kernel tests run against it there too.
5396
5410
  * Its contract is still Atlas's calendar design, §5 and §5b. This file adapts Atlas's
5397
- * `src/core/calendar-lens.ts` (readCalendarValue, worldCalendars, resolveCalendarLens) to
5411
+ * `src/core/calendar-lens.ts` (readCalendarValue, worldCalendars, and its resolveCalendarLens as resolveCalendar) to
5398
5412
  * any element shape, since the SDK has no Atlas `Element`.
5399
5413
  *
5400
5414
  * The field: a calendar is an element (a Construct by convention) carrying `atlas_calendar`.
@@ -5442,6 +5456,15 @@ declare function worldCalendars(elements: Iterable<OwCalendarElement>): WorldCal
5442
5456
  * stays null. With several calendars and no choice, nothing is guessed. An unknown option is a
5443
5457
  * TypeError (the caller's bug, not the world's data).
5444
5458
  */
5459
+ declare function resolveCalendar(elements: Iterable<OwCalendarElement>, activeId: string | null | undefined, opts?: {
5460
+ fallbackToOnly?: boolean;
5461
+ }): WorldCalendar | null;
5462
+ /**
5463
+ * The old name of {@link resolveCalendar}, with the same answers: "lens" now names a cut of a
5464
+ * world, not a chosen calendar.
5465
+ *
5466
+ * @deprecated Since 4.85.0. Use `resolveCalendar`; this name leaves in 5.0.
5467
+ */
5445
5468
  declare function resolveCalendarLens(elements: Iterable<OwCalendarElement>, activeId: string | null | undefined, opts?: {
5446
5469
  fallbackToOnly?: boolean;
5447
5470
  }): WorldCalendar | null;
@@ -5750,4 +5773,4 @@ declare class TokenResource {
5750
5773
  getEncryptionInfo(): Promise<EncryptionInfo>;
5751
5774
  }
5752
5775
 
5753
- export { AGENT_DOORS, ASK_LIMITS, type AccessKeyResponse, CALENDAR_FIELD, CALENDAR_SUPERTYPE, type CalendarConfig, type CalendarEra, type CalendarIntercalary, type CalendarMonths, type CalendarWeek, ELEMENT_FAMILIES, ELEMENT_ICONS, ELEMENT_LABELS, ELEMENT_SECTIONS, ELEMENT_TYPES, type ElementFamily, type ElementType, type EncryptionInfo, type EraDomain, FAMILY_COLORS, FAMILY_ORDER, FIELD_ACRONYMS, FIELD_SCHEMA, FILE_EXTENSIONS, type FieldInfo, type FieldType, GameTier, type ListParams, MESSAGE_PAIR, ONLYWORLDS_VERSION, type OwAccountWorld, type OwAgentJoined, type OwAllowance, OwApiError, type OwAskAnswer, type OwAskContext, type OwAskContextOptions, type OwAskLeftOut, type OwAuthErrorCode, type OwBulkItem, type OwBulkItemResult, type OwBulkResponse, type OwCalendarElement, type OwChange, type OwChangeDelete, type OwChangeUpsert, type OwChangesPage, type OwClientConfig, type OwCreateAccountWorldInput, type OwCreatedAccountWorld, type OwCreatedWorldLink, type OwDeleteReason, type OwDraught, type OwDraughtCompact, type OwDraughtComponent, type OwDraughtItem, type OwDraughtPolicy, type OwElement, type OwElementBase, type OwErrorBody, type OwFileAddedBy, type OwFileDownload, type OwFileKind, type OwFileRow, type OwFileTicket, type OwFrontDoor, type OwHiddenRow, type OwJoinPreview, type OwJoined, type OwJoinedMembership, type OwKeyKind, type OwLinkEdit, type OwLookupElement, type OwLookupHit, type OwLookupLink, type OwLookupOptions, type OwLookupReason, type OwMe, type OwMediaTicket, type OwMember, type OwMemberRole, type OwMessageMember, type OwMintedKey, type OwMySeat, type OwNamesMap, OwNetworkError, type OwPage, type OwPhotoOptions, type OwPhotoPlan, type OwPlayerJoined, OwPreconditionFailedError, type OwPreparedPhoto, type OwProposal, type OwProposalAccepted, type OwProposalConflict, type OwProposalList, type OwProposalQuery, type OwProposalState, type OwProposeInput, type OwProposed, OwProposedError, type OwProposedMark, type OwProposedNewElement, type OwReadWorldFile, type OwReadWorldFileOptions, type OwRemovalTicket, type OwRemovedImage, type OwRenderOptions, type OwResyncReason, type OwReviewInput, type OwReviewed, type OwSeat, type OwSeatCreated, type OwSender, type OwSenderStatus, type OwSignInBegin, type OwSignInBegun, type OwSignInComplete, OwSignInError, type OwSignInReason, type OwSignInResult, type OwSignInStorage, type OwSignedIn, type OwSortAddToRow, type OwSortAnswer, type OwSortAskRow, type OwSortLinkRow, type OwSortMakeRow, type OwSortNote, type OwSortRef, type OwSortRow, OwStaleProposalError, type OwUploadedFile, type OwUploadedImage, OwV2Client, type OwWordPair, type OwWorldFileEntry, OwWorldFileError, type OwWorldFileReason, type OwWorldFileRow, type OwWorldFiles, type OwWorldIndex, type OwWorldLink, type OwWorldMeta, type OwWorldOrigin, type OwWorldProducer, type OwWorldProposalList, type OwWorldProposalQuery, type OwWorldProposalRow, type OwWorldPublicPage, type OwWorldSource, type OwWriteDoor, type OwWriteWorldFileOptions, type OwWriteWorldFileReport, PHOTO_MAX_BYTES, PHOTO_TYPES, PROPOSED_MARK, PUBLIC_FIELDS, type ParseError, type ParseOptions, type ParseResult, REVIEW_PROPOSED_LABEL, ROOM_PAIRS, type RevokeAllSessionsResponse, type RevokeSessionResponse, SPATIAL_TYPES, type SectionInfo, type StepBreakdown, type TokenConsumeParams, type TokenConsumeResponse, TokenResource, type TokenStatus, type TokenTransport, WORLD_FILE_MAX_BYTES, WORLD_FILE_MAX_ENTRIES, WORLD_FILE_MEDIA_TYPE, type WorldCalendar, absYearForEraYear, absoluteYear, approxYearLength, base64url, breakdownStep, buildAskContext, buildWorldIndex, detectKeyKind, displayYear, elementColor, eraForStep, errorFromResponse, familyOf, fieldLabel, fileKindOf, floorDiv, floorMod, formatDuration, formatMidLabel, formatStep, formatYearLabel, getElementIcon, getElementLabel, handsOnAsProposed, intercalaryInYear, isAddressedTo, isAgentDoor, isDemoKey, isKnownOf, isLeapYear, isMessage, isParseError, isRoomElement, isSentBy, isToEveryone, kindCanWrite, lookupWorld, monthStartSteps, nfc, parseDate, parseErrorEnvelope, pinExpectation, pkceChallenge, planPhoto, preparePhoto, proposedMarkOf, readCalendarConfig, readCalendarValue, readMarkOf, readWorldFile, recipientsOf, renderElement, resolveCalendarLens, resolveEraDomains, senderStatus, simpleCaseFold, threadOf, typeWord, unreadFor, validateCalendarConfig, weekdayForStep, worldCalendars, writeWorldFile, yearLength, yearStartStep };
5776
+ export { AGENT_DOORS, ASK_LIMITS, type AccessKeyResponse, CALENDAR_FIELD, CALENDAR_SUPERTYPE, type CalendarConfig, type CalendarEra, type CalendarIntercalary, type CalendarMonths, type CalendarWeek, ELEMENT_FAMILIES, ELEMENT_ICONS, ELEMENT_LABELS, ELEMENT_SECTIONS, ELEMENT_TYPES, type ElementFamily, type ElementType, type EncryptionInfo, type EraDomain, FAMILY_COLORS, FAMILY_ORDER, FIELD_ACRONYMS, FIELD_SCHEMA, FILE_EXTENSIONS, type FieldInfo, type FieldType, GameTier, type ListParams, MESSAGE_PAIR, ONLYWORLDS_VERSION, type OwAccountWorld, type OwAgentJoined, type OwAllowance, OwApiError, type OwAskAnswer, type OwAskContext, type OwAskContextOptions, type OwAskLeftOut, type OwAuthErrorCode, type OwBulkItem, type OwBulkItemResult, type OwBulkResponse, type OwCalendarElement, type OwChange, type OwChangeDelete, type OwChangeUpsert, type OwChangesPage, type OwClientConfig, type OwCreateAccountWorldInput, type OwCreatedAccountWorld, type OwCreatedWorldLink, type OwDeleteReason, type OwDraught, type OwDraughtCompact, type OwDraughtComponent, type OwDraughtItem, type OwDraughtPolicy, type OwElement, type OwElementBase, type OwErrorBody, type OwFileAddedBy, type OwFileDownload, type OwFileKind, type OwFileRow, type OwFileTicket, type OwFrontDoor, type OwHiddenRow, type OwJoinPreview, type OwJoined, type OwJoinedMembership, type OwKeyKind, type OwLinkEdit, type OwLookupElement, type OwLookupHit, type OwLookupLink, type OwLookupOptions, type OwLookupReason, type OwMe, type OwMediaTicket, type OwMember, type OwMemberRole, type OwMessageMember, type OwMintedKey, type OwMySeat, type OwNamesMap, OwNetworkError, type OwPage, type OwPhotoOptions, type OwPhotoPlan, type OwPlayerJoined, OwPreconditionFailedError, type OwPreparedPhoto, type OwProposal, type OwProposalAccepted, type OwProposalConflict, type OwProposalList, type OwProposalQuery, type OwProposalState, type OwProposeInput, type OwProposed, OwProposedError, type OwProposedMark, type OwProposedNewElement, type OwReadWorldFile, type OwReadWorldFileOptions, type OwRemovalTicket, type OwRemovedImage, type OwRenderOptions, type OwResyncReason, type OwReviewInput, type OwReviewed, type OwSeat, type OwSeatCreated, type OwSender, type OwSenderStatus, type OwSignInBegin, type OwSignInBegun, type OwSignInComplete, OwSignInError, type OwSignInReason, type OwSignInResult, type OwSignInStorage, type OwSignedIn, type OwSortAddToRow, type OwSortAnswer, type OwSortAskRow, type OwSortLinkRow, type OwSortMakeRow, type OwSortNote, type OwSortRef, type OwSortRow, OwStaleProposalError, type OwUploadedFile, type OwUploadedImage, OwV2Client, type OwWordPair, type OwWorldFileEntry, OwWorldFileError, type OwWorldFileReason, type OwWorldFileRow, type OwWorldFiles, type OwWorldIndex, type OwWorldLink, type OwWorldMeta, type OwWorldOrigin, type OwWorldProducer, type OwWorldProposalList, type OwWorldProposalQuery, type OwWorldProposalRow, type OwWorldPublicPage, type OwWorldSource, type OwWriteDoor, type OwWriteWorldFileOptions, type OwWriteWorldFileReport, PHOTO_MAX_BYTES, PHOTO_TYPES, PROPOSED_MARK, PUBLIC_FIELDS, type ParseError, type ParseOptions, type ParseResult, REVIEW_PROPOSED_LABEL, ROOM_PAIRS, type RevokeAllSessionsResponse, type RevokeSessionResponse, SPATIAL_TYPES, type SectionInfo, type StepBreakdown, type TokenConsumeParams, type TokenConsumeResponse, TokenResource, type TokenStatus, type TokenTransport, WORLD_FILE_MAX_BYTES, WORLD_FILE_MAX_ENTRIES, WORLD_FILE_MEDIA_TYPE, type WorldCalendar, absYearForEraYear, absoluteYear, approxYearLength, base64url, breakdownStep, buildAskContext, buildWorldIndex, detectKeyKind, displayYear, draughtText, elementColor, eraForStep, errorFromResponse, familyOf, fieldLabel, fileKindOf, floorDiv, floorMod, formatDuration, formatMidLabel, formatStep, formatYearLabel, getElementIcon, getElementLabel, handsOnAsProposed, intercalaryInYear, isAddressedTo, isAgentDoor, isDemoKey, isKnownOf, isLeapYear, isMessage, isParseError, isRoomElement, isSentBy, isToEveryone, kindCanWrite, lookupWorld, monthStartSteps, nfc, parseDate, parseErrorEnvelope, pinExpectation, pkceChallenge, planPhoto, preparePhoto, proposedMarkOf, readCalendarConfig, readCalendarValue, readMarkOf, readWorldFile, recipientsOf, renderElement, resolveCalendar, resolveCalendarLens, resolveEraDomains, senderStatus, simpleCaseFold, threadOf, typeWord, unreadFor, validateCalendarConfig, weekdayForStep, worldCalendars, writeWorldFile, yearLength, yearStartStep };
package/dist/index.js CHANGED
@@ -406,12 +406,12 @@ function parseRetryAfter(value, now = Date.now()) {
406
406
  }
407
407
  async function errorFromResponse(res) {
408
408
  let body = null;
409
- let text = "";
409
+ let text2 = "";
410
410
  try {
411
- text = await res.text();
412
- body = text ? JSON.parse(text) : null;
411
+ text2 = await res.text();
412
+ body = text2 ? JSON.parse(text2) : null;
413
413
  } catch {
414
- body = text || null;
414
+ body = text2 || null;
415
415
  }
416
416
  return parseErrorEnvelope(res.status, body, parseRetryAfter(res.headers?.get?.("Retry-After") ?? null));
417
417
  }
@@ -1285,7 +1285,7 @@ var OwV2Client = class {
1285
1285
  throw new TypeError("signInWithPassword needs a tokenName: the name the new token is listed under");
1286
1286
  }
1287
1287
  const auth = `${this.baseUrl}/auth/app/v1`;
1288
- const safe = (text, fallback) => typeof text === "string" && text !== "" && !text.includes(password) ? text : fallback;
1288
+ const safe = (text2, fallback) => typeof text2 === "string" && text2 !== "" && !text2.includes(password) ? text2 : fallback;
1289
1289
  let res;
1290
1290
  try {
1291
1291
  res = await this.fetchImpl(`${auth}/auth/login`, {
@@ -1880,8 +1880,8 @@ var OwV2Client = class {
1880
1880
  if (!res.ok) throw await errorFromResponse(res);
1881
1881
  if (opts.proposable && res.status === 202) throw await proposedFromResponse(res, method, path);
1882
1882
  if (res.status === 204 || opts.allowEmpty) {
1883
- const text = await res.text();
1884
- return text ? JSON.parse(text) : null;
1883
+ const text2 = await res.text();
1884
+ return text2 ? JSON.parse(text2) : null;
1885
1885
  }
1886
1886
  const parsed = await res.json();
1887
1887
  if (opts.replayAware && parsed && typeof parsed === "object") {
@@ -1948,8 +1948,8 @@ async function endAuthSession(fetchImpl, auth, session) {
1948
1948
  }
1949
1949
  async function readJsonBody(res) {
1950
1950
  try {
1951
- const text = await res.text();
1952
- return text ? JSON.parse(text) : null;
1951
+ const text2 = await res.text();
1952
+ return text2 ? JSON.parse(text2) : null;
1953
1953
  } catch {
1954
1954
  return null;
1955
1955
  }
@@ -2034,13 +2034,13 @@ function xhrUpload(XHR, url, headers, body, total, onProgress) {
2034
2034
  }
2035
2035
  const ok = status >= 200 && status < 300;
2036
2036
  if (ok && last !== total) report(total);
2037
- const text = typeof xhr.responseText === "string" ? xhr.responseText : "";
2037
+ const text2 = typeof xhr.responseText === "string" ? xhr.responseText : "";
2038
2038
  resolve({
2039
2039
  ok,
2040
2040
  status,
2041
2041
  headers: { get: (n) => xhr.getResponseHeader(n) },
2042
- text: async () => text,
2043
- json: async () => JSON.parse(text)
2042
+ text: async () => text2,
2043
+ json: async () => JSON.parse(text2)
2044
2044
  });
2045
2045
  };
2046
2046
  xhr.send(body);
@@ -3056,17 +3056,17 @@ function load() {
3056
3056
  for (const c of raw.keys()) full(c);
3057
3057
  return { ccc, decomp, compose };
3058
3058
  }
3059
- function nfc(text) {
3059
+ function nfc(text2) {
3060
3060
  let plain = true;
3061
- for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) >= 192) {
3061
+ for (let i = 0; i < text2.length; i++) if (text2.charCodeAt(i) >= 192) {
3062
3062
  plain = false;
3063
3063
  break;
3064
3064
  }
3065
- if (plain) return text;
3065
+ if (plain) return text2;
3066
3066
  const t = tables ?? (tables = load());
3067
3067
  const cls = (c) => t.ccc.get(c) ?? 0;
3068
3068
  const cps = [];
3069
- for (const ch of text) {
3069
+ for (const ch of text2) {
3070
3070
  const c = ch.codePointAt(0);
3071
3071
  const s = c - S_BASE;
3072
3072
  if (s >= 0 && s < S_COUNT) {
@@ -3174,7 +3174,7 @@ function isJunk(path) {
3174
3174
  }
3175
3175
  var FOLD_RUNS = "1t.q..w,51...lj,5c.n..w,60.7..w,74.o.2.1,8i.3.2.1,8p.8.2.1,96.n.2.1,ag...-3d,ah.3.2.1,an...-7g,ap...5u,aq.2.2.1,au...5q,av...1,ax.2..5p,az...1,b2...27,b3...5m,b4...5n,b5...1,b7...5p,b8...5r,ba...5v,bb...5t,bc...1,bg...5v,bh...5x,bj...5y,bk.3.2.1,bq...62,br...1,bt...62,bw...1,by...62,bz...1,c1.2..61,c3.2.2.1,c7...63,c8...1,cc...1,ck...2,cl...1,cn...2,co...1,cq...2,cr.9.2.1,da.9.2.1,dt...2,du.2.2.1,dy...-2p,dz...-1k,e0.k.2.1,f4...-3m,f6.9.2.1,fu...8bv,fv...1,fx...-4j,fy...8bs,g1...1,g3...-5f,g4...1x,g5...1z,g6.5.2.1,n9...38,og.2.2.1,om...1,ov...38,p2...12,p4.3..11,p8...1s,pa.2..1r,pd.h..w,pv.9..w,qq...1,r3...8,r4...-u,r5...-p,r9...-f,ra...-m,rc.c.2.1,s0...-1i,s1...-1c,s4...-1o,s5...-1s,s7...1,s9...-7,sa...1,sd.3..-3m,sg.g..28,sw.w..w,v4.h.2.1,wa.r.2.1,xs...f,xt.7.2.1,y8.1c.2.1,10x.12..1c,3a8.12..5ls,3bb...5ls,3bh...5ls,3y0.6..-8,5mo...-4su,5mp...-4st,5mq...-4sk,5mr.2..-4si,5mt...-4sj,5mu...-4sc,5mv...-4ro,5mw...r7n,5n4.17..-2bk,5od.3..-2bk,5xc.23.2.1,61n...-1m,61q...-5vj,61s.1c.2.1,64o.8..-8,654.6..-8,65k.8..-8,660.8..-8,66g.6..-8,66x.4.2.-8,67c.8..-8,688.8..-8,68o.8..-8,694.8..-8,69k.2..-8,69m.2..-22,69o...-9,69q...-5j9,6a0.4..-2e,6a4...-9,6ab...-5kz,6ag.2..-8,6ai.2..-2s,6ar...-5kj,6aw.2..-8,6ay.2..-34,6b0...-7,6bc.2..-3k,6be.2..-3i,6bg...-9,6jq...-5st,6ju...-6gv,6jv...-6di,6k2...s,6lc.g..g,6mb...1,792.q..q,8ow.1c..1c,8rk...1,8rm...-8af,8rn...-2xy,8ro...-89z,8rr.3.2.1,8rx...-8bg,8ry...-8al,8rz...-8bj,8s0...-8bi,8s2...1,8s5...1,8se.2..-8cf,8sg.1e.2.1,8vf.2.2.1,8vm...1,wu8.n.2.1,ww0.e.2.1,x0i.7.2.1,x0y.v.2.1,x2x.2.2.1,x31...-r9g,x32.5.2.1,x3f...1,x3h...-wmg,x3k.2.2.1,x3q.a.2.1,x4a...-wn8,x4b...-wnj,x4c...-wnf,x4d...-wn5,x4e...-wn8,x4g...-wlu,x4h...-wmi,x4i...-wlx,x4j...ps,x4k.8.2.1,x50...-1c,x51...-wn7,x52...-raw,x53.2.2.1,x5c...1,x5i.2.2.1,x6d...1,xv4.28..-tzk,1dl1...1,1ee9.q..w,1fcw.14..14,1fhs.10..14,1fn4.b..13,1fng.f..13,1fnw.7..13,1fo4.2..13,1h1c.1f..1s,1jfk.w..w,20cg.w..w,2olc.y..y";
3176
3176
  var foldTable = null;
3177
- function simpleCaseFold(text) {
3177
+ function simpleCaseFold(text2) {
3178
3178
  if (!foldTable) {
3179
3179
  foldTable = /* @__PURE__ */ new Map();
3180
3180
  for (const run of FOLD_RUNS.split(",")) {
@@ -3187,7 +3187,7 @@ function simpleCaseFold(text) {
3187
3187
  }
3188
3188
  }
3189
3189
  let out = "";
3190
- for (const c of text) {
3190
+ for (const c of text2) {
3191
3191
  const to = foldTable.get(c.codePointAt(0));
3192
3192
  out += to === void 0 ? c : String.fromCodePoint(to);
3193
3193
  }
@@ -3656,14 +3656,14 @@ var WHITE_SPACE = /* @__PURE__ */ new Set([
3656
3656
  8287,
3657
3657
  12288
3658
3658
  ]);
3659
- function trimWhiteSpace(text) {
3659
+ function trimWhiteSpace(text2) {
3660
3660
  let start = 0;
3661
- let end = text.length;
3662
- while (start < end && WHITE_SPACE.has(text.charCodeAt(start))) start++;
3663
- while (end > start && WHITE_SPACE.has(text.charCodeAt(end - 1))) end--;
3664
- return text.slice(start, end);
3661
+ let end = text2.length;
3662
+ while (start < end && WHITE_SPACE.has(text2.charCodeAt(start))) start++;
3663
+ while (end > start && WHITE_SPACE.has(text2.charCodeAt(end - 1))) end--;
3664
+ return text2.slice(start, end);
3665
3665
  }
3666
- var fold = (text) => simpleCaseFold(trimWhiteSpace(text));
3666
+ var fold = (text2) => simpleCaseFold(trimWhiteSpace(text2));
3667
3667
  function isRoomElement(el) {
3668
3668
  if (el == null || typeof el.type !== "string" || typeof el.supertype !== "string") return false;
3669
3669
  const mark = el[ROOM_MARK];
@@ -4377,25 +4377,254 @@ function buildAskContext(items, index, opts = {}) {
4377
4377
  out.dropped.push(el.id);
4378
4378
  continue;
4379
4379
  }
4380
- let text = renderElement(el, viewFor(el));
4381
- if (isProposed(el)) text = `[${REVIEW_PROPOSED_LABEL}] ${text}`;
4382
- if (chars(text) > ASK_LIMITS.itemMax) {
4383
- text = cut(text, ASK_LIMITS.itemMax);
4380
+ let text2 = renderElement(el, viewFor(el));
4381
+ if (isProposed(el)) text2 = `[${REVIEW_PROPOSED_LABEL}] ${text2}`;
4382
+ if (chars(text2) > ASK_LIMITS.itemMax) {
4383
+ text2 = cut(text2, ASK_LIMITS.itemMax);
4384
4384
  out.truncated.push(el.id);
4385
4385
  }
4386
- if (total + chars(text) > ASK_LIMITS.totalMax) {
4386
+ if (total + chars(text2) > ASK_LIMITS.totalMax) {
4387
4387
  full = true;
4388
4388
  out.truncated = out.truncated.filter((id) => id !== el.id);
4389
4389
  out.dropped.push(el.id);
4390
4390
  continue;
4391
4391
  }
4392
- total += chars(text);
4393
- out.context.push(text);
4392
+ total += chars(text2);
4393
+ out.context.push(text2);
4394
4394
  out.kept.push(el.id);
4395
4395
  }
4396
4396
  return out;
4397
4397
  }
4398
4398
 
4399
+ // src/draught-text.ts
4400
+ var SECTIONS = [
4401
+ ["role", "Role"],
4402
+ ["work", "Work"],
4403
+ ["style", "Style"],
4404
+ ["events", "Events"],
4405
+ ["knowledge", "Knowledge"],
4406
+ ["names", "Names"],
4407
+ ["sheet", "Sheet"],
4408
+ ["recent", "Recent"],
4409
+ ["messages", "Messages"],
4410
+ ["room", "Room"],
4411
+ ["proposed", "Proposed"],
4412
+ ["roster", "Members"]
4413
+ ];
4414
+ var ELEMENT_SECTIONS2 = ["role", "work", "style", "events", "knowledge", "names", "sheet", "messages", "room", "proposed"];
4415
+ var UNPRINTED = /* @__PURE__ */ new Set([
4416
+ "id",
4417
+ "type",
4418
+ "name",
4419
+ "description",
4420
+ "supertype",
4421
+ "subtype",
4422
+ "hidden",
4423
+ "known_of",
4424
+ "x_review_proposed",
4425
+ "image_url",
4426
+ "created_at",
4427
+ "updated_at",
4428
+ "change_seq",
4429
+ "created_by",
4430
+ "changed_by",
4431
+ "changed_via",
4432
+ "changed_client",
4433
+ "world"
4434
+ ]);
4435
+ var UNPRINTED_PREFIXES = ["x_", "atlas_", "shadow_"];
4436
+ var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
4437
+ var isInt = (v) => typeof v === "number" && Number.isInteger(v);
4438
+ var own = (o, k) => Object.prototype.hasOwnProperty.call(o, k) ? o[k] : void 0;
4439
+ function isSet(v) {
4440
+ if (v === null || v === void 0 || v === "") return false;
4441
+ if (Array.isArray(v)) return v.length > 0;
4442
+ if (isObj(v)) return Object.keys(v).length > 0;
4443
+ return true;
4444
+ }
4445
+ function text(v) {
4446
+ if (typeof v === "string") return v === "" ? null : v.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
4447
+ if (isInt(v)) return BigInt(v).toString();
4448
+ return null;
4449
+ }
4450
+ function typeWordOf(t) {
4451
+ const s = typeof t === "string" ? t : "";
4452
+ return s.charAt(0).toUpperCase() + s.slice(1);
4453
+ }
4454
+ function fieldsOf(t) {
4455
+ return typeof t === "string" && Object.prototype.hasOwnProperty.call(FIELD_SCHEMA, t) ? FIELD_SCHEMA[t] : {};
4456
+ }
4457
+ function isLinkField(t, field) {
4458
+ const info = own(fieldsOf(t), field);
4459
+ return isObj(info) && (info.type === "single_link" || info.type === "multi_link");
4460
+ }
4461
+ var isDatedType = (t) => own(fieldsOf(t), "start_date") !== void 0;
4462
+ function kindOf(el) {
4463
+ const sup = text(own(el, "supertype"));
4464
+ const sub = text(own(el, "subtype"));
4465
+ if (sup !== null && sub !== null) return `${sup} / ${sub}`;
4466
+ return sup ?? sub;
4467
+ }
4468
+ function marks(el) {
4469
+ const proposed = own(el, "x_review_proposed");
4470
+ return (own(el, "hidden") === true ? " \xB7 hidden" : "") + (proposed !== void 0 && proposed !== null ? " \xB7 proposed" : "");
4471
+ }
4472
+ function descriptionLines(el) {
4473
+ const d = text(own(el, "description"));
4474
+ return d === null ? [] : d.split("\n").map((l) => ` ${l}`);
4475
+ }
4476
+ function rowsOf(key, v) {
4477
+ if (key === "style") return [v];
4478
+ if (key === "names") {
4479
+ if (!isObj(v)) return [];
4480
+ return Object.keys(v).flatMap((t) => Array.isArray(v[t]) ? v[t] : []);
4481
+ }
4482
+ return Array.isArray(v) ? v : [];
4483
+ }
4484
+ function draughtText(draught) {
4485
+ const d = draught;
4486
+ if (!isObj(d)) throw new TypeError("draughtText: the draught is an object, as draught() returns it.");
4487
+ const world = own(d, "world");
4488
+ if (!isObj(world)) throw new TypeError("draughtText: the draught has no world object.");
4489
+ const names = /* @__PURE__ */ new Map();
4490
+ const hold = (el) => {
4491
+ if (!isObj(el)) return;
4492
+ const id = own(el, "id");
4493
+ if (typeof id === "string" && !names.has(id)) names.set(id, text(own(el, "name")) ?? "(unnamed)");
4494
+ };
4495
+ const asked = Object.prototype.hasOwnProperty.call(d, "character");
4496
+ const character = own(d, "character");
4497
+ const her = isObj(character) && isObj(own(character, "element")) ? own(character, "element") : null;
4498
+ hold(her);
4499
+ for (const key of ELEMENT_SECTIONS2) {
4500
+ for (const row of rowsOf(key, own(d, key))) if (isObj(row)) hold(own(row, "element"));
4501
+ }
4502
+ const calendar = own(d, "calendar");
4503
+ const unit = isObj(calendar) ? text(own(calendar, "time_basic_unit")) : null;
4504
+ const moment = (n) => unit === null ? BigInt(n).toString() : `${unit} ${BigInt(n).toString()}`;
4505
+ const herName = her === null ? "the Character" : text(own(her, "name")) ?? "(unnamed)";
4506
+ const out = [];
4507
+ const put = (line, cont = " ") => {
4508
+ const [first, ...rest] = line.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
4509
+ out.push(first, ...rest.map((l) => cont + l));
4510
+ };
4511
+ put(`# ${herName}, in ${text(own(world, "name")) ?? "(unnamed)"}`);
4512
+ const asOf = own(d, "as_of");
4513
+ const now = own(d, "now");
4514
+ const mode = own(d, "mode");
4515
+ put(
4516
+ `What the record holds around ${herName}` + (isInt(asOf) ? `, dated up to ${moment(asOf)}` : "") + (isInt(now) ? ` (the world's now: ${moment(now)})` : "") + "." + (mode === "voice" ? " Read as the Character's own view." : mode === "act" ? " Read as the caller's view." : "")
4517
+ );
4518
+ if (asked) {
4519
+ out.push("");
4520
+ put(`## ${herName}`);
4521
+ }
4522
+ if (asked && her === null) {
4523
+ out.push("Hidden from this reader.");
4524
+ } else if (her !== null) {
4525
+ const type = own(her, "type");
4526
+ const kind = kindOf(her);
4527
+ put(typeWordOf(type) + (kind === null ? "" : ` \xB7 ${kind}`) + marks(her));
4528
+ for (const l of descriptionLines(her)) put(l);
4529
+ for (const key of Object.keys(her)) {
4530
+ if (UNPRINTED.has(key) || UNPRINTED_PREFIXES.some((p) => key.startsWith(p))) continue;
4531
+ const v = her[key];
4532
+ if (!isSet(v)) continue;
4533
+ let value;
4534
+ if (isLinkField(type, key)) {
4535
+ const resolved = [];
4536
+ let missing = 0;
4537
+ for (const id of Array.isArray(v) ? v : [v]) {
4538
+ if (typeof id !== "string" || id === "") continue;
4539
+ const name = names.get(id);
4540
+ if (name === void 0) missing += 1;
4541
+ else resolved.push(name);
4542
+ }
4543
+ const notHeld = `${missing} not in this draught`;
4544
+ value = missing === 0 ? resolved.length ? resolved.join(", ") : null : resolved.length ? `${resolved.join(", ")}, and ${notHeld}` : notHeld;
4545
+ } else if (Array.isArray(v)) {
4546
+ const parts = v.map(text).filter((p) => p !== null);
4547
+ value = parts.length ? parts.join(", ") : null;
4548
+ } else {
4549
+ value = text(v);
4550
+ }
4551
+ if (value !== null) put(` ${key.replace(/_/g, " ")}: ${value}`, " ");
4552
+ }
4553
+ }
4554
+ const roster = own(d, "roster");
4555
+ const memberName = (id) => {
4556
+ if (!Array.isArray(roster) || typeof id !== "string") return null;
4557
+ for (const r of roster) if (isObj(r) && own(r, "id") === id) return text(own(r, "name"));
4558
+ return null;
4559
+ };
4560
+ const elementRow = (row) => {
4561
+ const el = isObj(own(row, "element")) ? own(row, "element") : {};
4562
+ const type = own(el, "type");
4563
+ const kind = kindOf(el);
4564
+ let line = `- ${text(own(el, "name")) ?? "(unnamed)"} (${typeWordOf(type)}${kind === null ? "" : ` \xB7 ${kind}`})`;
4565
+ const viaRaw = own(row, "via");
4566
+ const via = (Array.isArray(viaRaw) ? viaRaw : []).map(text).filter((f) => f !== null);
4567
+ if (via.length) line += ` \xB7 via ${via.map((f) => f.replace(/_/g, " ")).join(", ")}`;
4568
+ const start = own(el, "start_date");
4569
+ if (own(row, "grade") === "known_of") line += " \xB7 known of";
4570
+ else if (isInt(start)) line += ` \xB7 ${moment(start)}`;
4571
+ else if (isDatedType(type)) line += " \xB7 undated";
4572
+ line += marks(el);
4573
+ return [line, ...descriptionLines(el)];
4574
+ };
4575
+ const recentRow = (row) => {
4576
+ const op = own(row, "op");
4577
+ const verb = op === "upsert" ? "changed" : op === "delete" ? "deleted" : text(op) ?? "";
4578
+ const id = own(row, "id");
4579
+ const target = (typeof id === "string" ? names.get(id) : void 0) ?? text(id) ?? "";
4580
+ const who = own(row, "who");
4581
+ const writer = !isSet(who) ? "an unrecorded writer" : who === "owner" ? "the owner" : memberName(who) ?? "a member";
4582
+ const when = text(own(row, "when"));
4583
+ const door = text(own(row, "door"));
4584
+ return `- ${when === null ? "" : `${when} \xB7 `}${verb} ${typeWordOf(own(row, "type"))} ${target} \xB7 by ${writer}` + (door === null ? "" : ` \xB7 through ${door}`);
4585
+ };
4586
+ const memberRow = (row) => {
4587
+ let line = `- ${text(own(row, "role")) ?? ""}`;
4588
+ const name = text(own(row, "name"));
4589
+ if (name !== null) line += ` \xB7 ${name}`;
4590
+ const plays = own(row, "character");
4591
+ if (isSet(plays)) {
4592
+ const n = typeof plays === "string" ? names.get(plays) : void 0;
4593
+ line += n === void 0 ? " \xB7 plays a Character not in this draught" : ` \xB7 plays ${n}`;
4594
+ }
4595
+ if (own(row, "status") === "removed") line += " \xB7 removed";
4596
+ return line;
4597
+ };
4598
+ const recentMore = own(d, "recent_more") === true;
4599
+ const sectionSet = (key) => isSet(own(d, key)) || key === "recent" && recentMore;
4600
+ for (const [key, heading] of SECTIONS) {
4601
+ const v = own(d, key);
4602
+ if (!sectionSet(key)) continue;
4603
+ out.push("", `## ${heading}`);
4604
+ for (const row of rowsOf(key, v)) {
4605
+ if (!isObj(row)) continue;
4606
+ if (key === "recent") put(recentRow(row));
4607
+ else if (key === "roster") put(memberRow(row));
4608
+ else for (const l of elementRow(row)) put(l);
4609
+ }
4610
+ if (key === "recent" && recentMore) out.push("More changes than these; read on from recent_cursor.");
4611
+ }
4612
+ const policy = own(d, "policy");
4613
+ const components = isObj(policy) ? own(policy, "components") : void 0;
4614
+ if (Array.isArray(components)) {
4615
+ const empty = components.filter((c) => typeof c === "string" && c !== "self" && !sectionSet(c));
4616
+ if (empty.length) {
4617
+ out.push("");
4618
+ put(`Nothing in: ${empty.join(", ")}.`);
4619
+ }
4620
+ }
4621
+ const cut2 = own(d, "cut");
4622
+ const left = isObj(cut2) ? Object.keys(cut2).filter((k) => isInt(cut2[k])).map((k) => `${BigInt(cut2[k]).toString()} ${k}`) : [];
4623
+ out.push("");
4624
+ put(`Left out by the budget: ${left.length ? left.join(", ") : "nothing"}.`);
4625
+ return out.join("\n") + "\n";
4626
+ }
4627
+
4399
4628
  // src/photo.ts
4400
4629
  var PHOTO_TYPES = ["image/webp", "image/png", "image/jpeg", "image/avif"];
4401
4630
  var PHOTO_MAX_BYTES = 15 * 1024 * 1024;
@@ -4971,8 +5200,8 @@ function worldCalendars(elements) {
4971
5200
  }
4972
5201
  return out;
4973
5202
  }
4974
- function resolveCalendarLens(elements, activeId, opts) {
4975
- refuseUnknownOptions("resolveCalendarLens", opts, ["fallbackToOnly"]);
5203
+ function resolveCalendar(elements, activeId, opts) {
5204
+ refuseUnknownOptions("resolveCalendar", opts, ["fallbackToOnly"]);
4976
5205
  if (activeId === void 0 && opts?.fallbackToOnly) {
4977
5206
  const all = worldCalendars(elements);
4978
5207
  return all.length === 1 ? all[0] : null;
@@ -4980,6 +5209,10 @@ function resolveCalendarLens(elements, activeId, opts) {
4980
5209
  if (!activeId) return null;
4981
5210
  return worldCalendars(elements).find((c) => c.id === activeId) ?? null;
4982
5211
  }
5212
+ function resolveCalendarLens(elements, activeId, opts) {
5213
+ refuseUnknownOptions("resolveCalendarLens", opts, ["fallbackToOnly"]);
5214
+ return resolveCalendar(elements, activeId, opts);
5215
+ }
4983
5216
 
4984
5217
  // src/token-resource.ts
4985
5218
  var TokenResource = class {
@@ -5212,6 +5445,7 @@ export {
5212
5445
  buildWorldIndex,
5213
5446
  detectKeyKind,
5214
5447
  displayYear,
5448
+ draughtText,
5215
5449
  elementColor,
5216
5450
  eraForStep,
5217
5451
  errorFromResponse,
@@ -5255,6 +5489,7 @@ export {
5255
5489
  readWorldFile,
5256
5490
  recipientsOf,
5257
5491
  renderElement,
5492
+ resolveCalendar,
5258
5493
  resolveCalendarLens,
5259
5494
  resolveEraDomains,
5260
5495
  senderStatus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlyworlds/sdk",
3
- "version": "4.84.1",
3
+ "version": "4.86.0",
4
4
  "description": "TypeScript SDK for the OnlyWorlds API - build world-building applications with type safety",
5
5
  "type": "module",
6
6
  "exports": {