@onlyworlds/sdk 4.24.0 → 4.26.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,12 @@ against live data). The v1 surface (`OnlyWorldsClient`, the `ElementType` enum)
89
89
  body that carries it has it dropped, never an error. A **contributor** can change only what
90
90
  they created: anything else is 403 `not_author` (`err.isNotAuthor`; retrying will not help).
91
91
  `/bulk` reports it per slot, not as a throw.
92
+ - **If you are an agent, say so** (since 4.26.0): `new OwV2Client({ ..., agent: true })` sends
93
+ `X-OW-Agent` on every element write, and keel records those writes as agent-made. Every element read
94
+ carries `changed_by` and `changed_via` (the last write's membership and its door: `seat`,
95
+ `mcp`, `declared`, `api`, `v1`, `sync`, `server`), and a `/changes` delete carries
96
+ `deleted_by` and `deleted_via`; `isAgentDoor(door)` is true for the first three. An agent
97
+ seat's key is recorded as an agent without the option. Never set it in a tool people use.
92
98
  - A string holding an unpaired surrogate (text cut mid-emoji) is a 422 naming the field.
93
99
  Slice strings by code point, not by UTF-16 unit.
94
100
  - Colour carries the element's FAMILY (`elementColor(type, mode)`); the icon
package/CHANGELOG.md CHANGED
@@ -5,6 +5,32 @@ earlier history lives in git log only.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [4.26.0] — 2026-10-15
9
+
10
+ ### Added
11
+ - **The door of every write** (keel #299, D104; keel 7c1b493). An opt-in
12
+ `agent: true` on `OwClientConfig` sends `X-OW-Agent` on every element write (create, upsert,
13
+ patch, delete, editLinks, bulk: the operations keel's document declares it on; never on reads,
14
+ account routes or the image edge); keel records such writes as `declared`, agent-made, and stores only that the header was
15
+ there. Off by default: it describes the caller, so a tool people use never sets it.
16
+ - `OwElementBase` gains the read-only `changed_by` (the membership of the last write) and
17
+ `changed_via` (its door: `seat`, `mcp`, `declared`, `api`, `v1`, `sync`, `server`); a `/changes`
18
+ delete op gains `deleted_by` and `deleted_via`. Keel drops them from a write body, like `created_by`.
19
+ - `OwWriteDoor`, `AGENT_DOORS` and `isAgentDoor(door)`: seat, mcp and declared are agent-made.
20
+ - The two kinds of `/changes` item are named types, `OwChangeUpsert` and `OwChangeDelete` (`OwChange` is their union, as before), and both declare `change_seq`, which keel always sends and the type never named.
21
+
22
+ ## [4.25.0] — 2026-10-15
23
+
24
+ ### Changed
25
+ - **`OwWorldMeta` types every field keel's `World` declares** (it named four): the description and
26
+ picture, the calendar (`time_format_names`, `time_format_equivalents`, `time_basic_unit`, the three
27
+ `time_range_*`), the three unit labels, `public_read`, `owner_character`, `created_at`, and new
28
+ **`agent_narrator_rule`** (keel #298, D103: whether a Narrative written through an agent seat is
29
+ narrated by that seat's own Character; read-only, set on the world page). Past `id` and `name`
30
+ they stay optional so code that builds a world meta keeps compiling; keel always sends all of them.
31
+ `updated_at` and `created_at` read `string | null`, as the document says. Assembly's wire gate now
32
+ holds this type to `World` (it had held only the PATCH body). Council and Lantern type-check on it.
33
+
8
34
  ## [4.24.0] — 2026-10-15
9
35
 
10
36
  ### Added
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Every element carries these. The extension index signature admits namespaced
2
2
  * pass-through fields (atlas_* / shadow_* / x_*) returned verbatim by the server.
3
3
  * Derived from base_properties.yaml: `World` is dropped (the API rejects it in
4
- * bodies -- the key determines the world) and the five server-managed fields are
4
+ * bodies -- the key determines the world) and the seven server-managed fields are
5
5
  * added, since they ride every wire body and appear in no element YAML. */
6
6
  interface OwElementBase {
7
7
  /** Element type slug (server-managed, read-only). */
@@ -26,6 +26,10 @@ interface OwElementBase {
26
26
  change_seq?: number;
27
27
  /** The membership that created this element (server-managed, read-only); null for the world's owner and for anything created before memberships existed. */
28
28
  created_by?: string | null;
29
+ /** The membership whose write last changed this element (server-managed, read-only); null for the world's owner and for anything last changed before writes recorded it. */
30
+ changed_by?: string | null;
31
+ /** The door of the last write (server-managed, read-only): `seat` (an agent seat), `mcp`, `declared` (a client that sent X-OW-Agent), then `api`, `v1`, `sync`, or `server` (keel's own writes). The first three are agent-made. Null for anything last changed before writes recorded it. */
32
+ changed_via?: 'seat' | 'mcp' | 'declared' | 'api' | 'v1' | 'sync' | 'server' | null;
29
33
  /** Namespaced extension fields (atlas_* / shadow_* / x_*), returned verbatim. */
30
34
  [ext: string]: unknown;
31
35
  }
@@ -1858,11 +1862,44 @@ declare const FIELD_SCHEMA: {
1858
1862
  type OwElement = OwElementBase;
1859
1863
  /** Spatial types live under spatial/ in the OW Folder Format. */
1860
1864
  declare const SPATIAL_TYPES: readonly ElementType[];
1865
+ /**
1866
+ * GET /world: the world's own fields, as keel's `World` component declares them (since 4.25.0
1867
+ * every one is typed). keel always sends all of them; past `id` and `name` they are optional
1868
+ * here only so that code building a world meta keeps compiling within 4.x. Dates and durations
1869
+ * count in `time_basic_unit`; the three units are free-text labels, nothing converts.
1870
+ */
1861
1871
  interface OwWorldMeta {
1862
1872
  id: string;
1863
1873
  name: string;
1864
- updated_at?: string;
1874
+ description?: string;
1875
+ image_url?: string;
1876
+ /** The names of the calendar's steps, e.g. ['Day', 'Week', 'Month', 'Year']. */
1877
+ time_format_names?: string[];
1878
+ /** How many time_basic_unit each step holds, in the same order. Whole numbers in the standard; an older world may read back strings. */
1879
+ time_format_equivalents?: Array<number | string>;
1880
+ /** The unit every element date and duration counts in (e.g. 'Year'). */
1881
+ time_basic_unit?: string;
1882
+ time_range_min?: number | null;
1883
+ time_range_max?: number | null;
1884
+ /** The world's present moment (in a world folder: `time_current`). */
1885
+ time_range_current?: number | null;
1886
+ length_unit?: string;
1887
+ mass_unit?: string;
1888
+ distance_unit?: string;
1889
+ /** Whether the world can be read without its PIN. Read-only on the wire. */
1865
1890
  public_read?: boolean;
1891
+ /**
1892
+ * Whether a Narrative written through an agent seat is narrated by that seat's own Character,
1893
+ * as a guest's is (keel #298, D103): set by the owner on the world page; read-only on the wire.
1894
+ * With it on, an agent naming another narrator is a 422 (`param: narrator`), and a seat with no
1895
+ * Character a 403 `guest_not_supported`.
1896
+ */
1897
+ agent_narrator_rule?: boolean;
1898
+ /** The owner's "this Character is me": a Character id in this world, or null. */
1899
+ owner_character?: string | null;
1900
+ created_at?: string | null;
1901
+ /** Moves when the world's own fields change, not on element writes. */
1902
+ updated_at?: string | null;
1866
1903
  [field: string]: unknown;
1867
1904
  }
1868
1905
  /** List envelope: cursor-paginated. */
@@ -1872,20 +1909,43 @@ interface OwPage<T = OwElement> {
1872
1909
  next_cursor: string | null;
1873
1910
  }
1874
1911
  /** /changes feed -- discriminated union on `op`. Apply in order -> convergence. */
1875
- type OwChange = {
1912
+ type OwChange = OwChangeUpsert | OwChangeDelete;
1913
+ /** A /changes item for an element written: the element whole, as GET returns it. */
1914
+ interface OwChangeUpsert {
1876
1915
  op: 'upsert';
1877
1916
  id: string;
1878
1917
  type: string;
1879
1918
  element: OwElement;
1880
1919
  updated_at: string;
1920
+ /** The change's place in the world's feed. */
1921
+ change_seq: number;
1881
1922
  [k: string]: unknown;
1882
- } | {
1923
+ }
1924
+ /** A /changes item for an element deleted. */
1925
+ interface OwChangeDelete {
1883
1926
  op: 'delete';
1884
1927
  id: string;
1885
1928
  type: string;
1886
1929
  deleted_at: string;
1930
+ /** The change's place in the world's feed. */
1931
+ change_seq: number;
1932
+ /** The membership whose write deleted it; null for the world's owner, and for deletes before writes recorded it (keel #299). */
1933
+ deleted_by?: string | null;
1934
+ /** The door the delete came through (see {@link OwWriteDoor}); null for deletes before writes recorded it. */
1935
+ deleted_via?: OwWriteDoor | null;
1887
1936
  [k: string]: unknown;
1888
- };
1937
+ }
1938
+ /**
1939
+ * The door a write came through, as keel records it on every element (`changed_via`) and on a
1940
+ * delete (`deleted_via`) since keel #299: `seat` (an agent seat), `mcp` (the MCP server),
1941
+ * `declared` (a client that sent `X-OW-Agent`; see {@link OwClientConfig.agent}), then the
1942
+ * surface for everything else: `api`, `v1`, `sync`, and `server` for keel's own writes.
1943
+ */
1944
+ type OwWriteDoor = NonNullable<OwElementBase['changed_via']>;
1945
+ /** The doors that mean agent-made: an agent seat, the MCP server, or a client that declared itself. */
1946
+ declare const AGENT_DOORS: readonly OwWriteDoor[];
1947
+ /** Whether a write came through an agent's door (`changed_via` or `deleted_via`); false for null. */
1948
+ declare function isAgentDoor(door: OwWriteDoor | null | undefined): boolean;
1889
1949
  /**
1890
1950
  * /changes response. Wire shape verified in keel source (core/changes.py) and
1891
1951
  * pinned here: {cursor, changes, has_more, head}.
@@ -2275,6 +2335,15 @@ interface OwClientConfig {
2275
2335
  changesPageSize?: number;
2276
2336
  /** A fetch implementation to use instead of globalThis.fetch (for tests and other runtimes). */
2277
2337
  fetch?: typeof globalThis.fetch;
2338
+ /**
2339
+ * Declare this client an AI agent: every element write (create, upsert, patch, delete,
2340
+ * editLinks, bulk) carries `X-OW-Agent`, the operations keel declares it on, and keel
2341
+ * records its writes as agent-made (`changed_via: 'declared'`; keel stores that the header
2342
+ * was there, never its value). Off by default, and it must stay off in a tool people use:
2343
+ * it describes the caller, so only the caller can set it. An agent seat's key is recorded
2344
+ * as an agent without it.
2345
+ */
2346
+ agent?: boolean;
2278
2347
  }
2279
2348
 
2280
2349
  /**
@@ -2448,6 +2517,7 @@ declare class OwV2Client {
2448
2517
  private readonly apiKey;
2449
2518
  private readonly apiPin;
2450
2519
  private readonly fetchImpl;
2520
+ private readonly agent;
2451
2521
  constructor(config: OwClientConfig);
2452
2522
  /** GET /health -- unauthenticated liveness pulse. */
2453
2523
  health(): Promise<unknown>;
@@ -2731,6 +2801,8 @@ declare class OwV2Client {
2731
2801
  allowEmpty?: boolean;
2732
2802
  replayAware?: boolean;
2733
2803
  /** A `change_seq` to send as `If-Match` (keel #210); a whole number, else TypeError before sending. */
2804
+ /** An element write (create, put, patch, delete, links, bulk): where an agent client sends X-OW-Agent. */
2805
+ write?: boolean;
2734
2806
  ifMatch?: number;
2735
2807
  }): Promise<T>;
2736
2808
  }
@@ -3678,4 +3750,4 @@ declare class TokenResource {
3678
3750
  getEncryptionInfo(): Promise<EncryptionInfo>;
3679
3751
  }
3680
3752
 
3681
- export { 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_SCHEMA, type FieldInfo, type FieldType, GameTier, type ListParams, ONLYWORLDS_VERSION, type OwAllowance, OwApiError, type OwAskAnswer, type OwAskContext, type OwAuthErrorCode, type OwBulkItem, type OwBulkItemResult, type OwBulkResponse, type OwCalendarElement, type OwChange, type OwChangesPage, type OwClientConfig, type OwCreatedWorldLink, type OwElement, type OwElementBase, type OwErrorBody, type OwJoinPreview, type OwJoinedMembership, type OwKeyKind, type OwLinkEdit, type OwLookupElement, type OwLookupHit, type OwLookupLink, type OwLookupOptions, type OwLookupReason, type OwMe, type OwMediaTicket, type OwMember, type OwMemberRole, OwNetworkError, type OwPage, type OwPhotoOptions, type OwPhotoPlan, OwPreconditionFailedError, type OwPreparedPhoto, type OwReadWorldFile, type OwReadWorldFileOptions, type OwRemovalTicket, type OwRemovedImage, type OwRenderOptions, type OwSortAddToRow, type OwSortAnswer, type OwSortAskRow, type OwSortLinkRow, type OwSortMakeRow, type OwSortNote, type OwSortRef, type OwSortRow, type OwUploadedImage, OwV2Client, type OwWorldFileEntry, OwWorldFileError, type OwWorldFileReason, type OwWorldIndex, type OwWorldLink, type OwWorldMeta, PHOTO_MAX_BYTES, PHOTO_TYPES, type ParseError, type ParseOptions, type ParseResult, 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, type WorldCalendar, absYearForEraYear, absoluteYear, approxYearLength, breakdownStep, buildAskContext, buildWorldIndex, detectKeyKind, displayYear, elementColor, eraForStep, errorFromResponse, familyOf, floorDiv, floorMod, formatDuration, formatMidLabel, formatStep, formatYearLabel, getElementIcon, getElementLabel, isDemoKey, isLeapYear, isParseError, kindCanWrite, lookupWorld, monthStartSteps, parseDate, parseErrorEnvelope, pinExpectation, planPhoto, preparePhoto, readCalendarConfig, readCalendarValue, readWorldFile, renderElement, resolveCalendarLens, resolveEraDomains, validateCalendarConfig, weekdayForStep, worldCalendars, writeWorldFile, yearLength, yearStartStep };
3753
+ 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_SCHEMA, type FieldInfo, type FieldType, GameTier, type ListParams, ONLYWORLDS_VERSION, type OwAllowance, OwApiError, type OwAskAnswer, type OwAskContext, type OwAuthErrorCode, type OwBulkItem, type OwBulkItemResult, type OwBulkResponse, type OwCalendarElement, type OwChange, type OwChangeDelete, type OwChangeUpsert, type OwChangesPage, type OwClientConfig, type OwCreatedWorldLink, type OwElement, type OwElementBase, type OwErrorBody, type OwJoinPreview, type OwJoinedMembership, type OwKeyKind, type OwLinkEdit, type OwLookupElement, type OwLookupHit, type OwLookupLink, type OwLookupOptions, type OwLookupReason, type OwMe, type OwMediaTicket, type OwMember, type OwMemberRole, OwNetworkError, type OwPage, type OwPhotoOptions, type OwPhotoPlan, OwPreconditionFailedError, type OwPreparedPhoto, type OwReadWorldFile, type OwReadWorldFileOptions, type OwRemovalTicket, type OwRemovedImage, type OwRenderOptions, type OwSortAddToRow, type OwSortAnswer, type OwSortAskRow, type OwSortLinkRow, type OwSortMakeRow, type OwSortNote, type OwSortRef, type OwSortRow, type OwUploadedImage, OwV2Client, type OwWorldFileEntry, OwWorldFileError, type OwWorldFileReason, type OwWorldIndex, type OwWorldLink, type OwWorldMeta, type OwWriteDoor, PHOTO_MAX_BYTES, PHOTO_TYPES, type ParseError, type ParseOptions, type ParseResult, 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, type WorldCalendar, absYearForEraYear, absoluteYear, approxYearLength, breakdownStep, buildAskContext, buildWorldIndex, detectKeyKind, displayYear, elementColor, eraForStep, errorFromResponse, familyOf, floorDiv, floorMod, formatDuration, formatMidLabel, formatStep, formatYearLabel, getElementIcon, getElementLabel, isAgentDoor, isDemoKey, isLeapYear, isParseError, kindCanWrite, lookupWorld, monthStartSteps, parseDate, parseErrorEnvelope, pinExpectation, planPhoto, preparePhoto, readCalendarConfig, readCalendarValue, readWorldFile, renderElement, resolveCalendarLens, resolveEraDomains, validateCalendarConfig, weekdayForStep, worldCalendars, writeWorldFile, yearLength, yearStartStep };
package/dist/index.js CHANGED
@@ -191,6 +191,7 @@ var OwV2Client = class {
191
191
  this.pageSize = config.pageSize ?? DEFAULT_PAGE_SIZE;
192
192
  this.changesPageSize = config.changesPageSize ?? DEFAULT_CHANGES_PAGE_SIZE;
193
193
  this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
194
+ this.agent = config.agent === true;
194
195
  if (typeof this.fetchImpl !== "function") {
195
196
  throw new Error("OwV2Client: no fetch available -- supply config.fetch");
196
197
  }
@@ -276,13 +277,14 @@ var OwV2Client = class {
276
277
  body.id = mintUuid();
277
278
  }
278
279
  return this.request("POST", `/${type}/`, {
280
+ write: true,
279
281
  body,
280
282
  idempotencyKey: opts.idempotencyKey
281
283
  });
282
284
  }
283
285
  /** PUT /{type}/{id}/ -- upsert-by-client-id. The local-first write primitive. */
284
286
  async upsert(type, id, element) {
285
- return this.request("PUT", `/${type}/${id}/`, { body: sanitizePayload(element) });
287
+ return this.request("PUT", `/${type}/${id}/`, { write: true, body: sanitizePayload(element) });
286
288
  }
287
289
  /**
288
290
  * PATCH /{type}/{id}/ -- partial update. DESTRUCTIVE on sent fields: arrays
@@ -295,7 +297,7 @@ var OwV2Client = class {
295
297
  * it for today's unconditional write.
296
298
  */
297
299
  async patch(type, id, partial, opts = {}) {
298
- return this.request("PATCH", `/${type}/${id}/`, { body: sanitizePayload(partial), ifMatch: opts.ifMatch });
300
+ return this.request("PATCH", `/${type}/${id}/`, { write: true, body: sanitizePayload(partial), ifMatch: opts.ifMatch });
299
301
  }
300
302
  /**
301
303
  * DELETE /{type}/{id}/ -- idempotent (204 on absent). Server writes a
@@ -303,7 +305,7 @@ var OwV2Client = class {
303
305
  * transaction -- no client-side unlink pass needed, ever.
304
306
  */
305
307
  async delete(type, id) {
306
- await this.request("DELETE", `/${type}/${id}/`, { allowEmpty: true });
308
+ await this.request("DELETE", `/${type}/${id}/`, { write: true, allowEmpty: true });
307
309
  }
308
310
  /**
309
311
  * POST /{type}/{id}/links/{field} with {add, remove} -- atomic link merge.
@@ -313,7 +315,7 @@ var OwV2Client = class {
313
315
  * moves the element too.
314
316
  */
315
317
  async editLinks(type, id, field, edit, opts = {}) {
316
- return this.request("POST", `/${type}/${id}/links/${field}`, { body: edit, ifMatch: opts.ifMatch });
318
+ return this.request("POST", `/${type}/${id}/links/${field}`, { write: true, body: edit, ifMatch: opts.ifMatch });
317
319
  }
318
320
  // -- Bulk ----------------------------------------------------------------
319
321
  /**
@@ -334,6 +336,7 @@ var OwV2Client = class {
334
336
  atomic: opts.atomic ?? false
335
337
  };
336
338
  return this.request("POST", "/bulk/", {
339
+ write: true,
337
340
  body,
338
341
  idempotencyKey: opts.idempotencyKey,
339
342
  replayAware: true
@@ -617,6 +620,7 @@ var OwV2Client = class {
617
620
  if (opts.body !== void 0) headers["Content-Type"] = "application/json";
618
621
  if (opts.idempotencyKey) headers["Idempotency-Key"] = opts.idempotencyKey;
619
622
  if (opts.ifMatch !== void 0) headers["If-Match"] = `"${opts.ifMatch}"`;
623
+ if (this.agent && opts.write) headers["X-OW-Agent"] = "1";
620
624
  let res;
621
625
  try {
622
626
  res = await this.fetchImpl(url, {
@@ -1431,6 +1435,10 @@ var FIELD_SCHEMA = {
1431
1435
 
1432
1436
  // src/v2/types.ts
1433
1437
  var SPATIAL_TYPES = ["map", "pin", "marker", "zone"];
1438
+ var AGENT_DOORS = ["seat", "mcp", "declared"];
1439
+ function isAgentDoor(door) {
1440
+ return door != null && AGENT_DOORS.includes(door);
1441
+ }
1434
1442
 
1435
1443
  // src/v2/palette.ts
1436
1444
  var FAMILY_COLORS = {
@@ -2849,6 +2857,7 @@ var GameTier = /* @__PURE__ */ ((GameTier2) => {
2849
2857
  return GameTier2;
2850
2858
  })(GameTier || {});
2851
2859
  export {
2860
+ AGENT_DOORS,
2852
2861
  ASK_LIMITS,
2853
2862
  CALENDAR_FIELD,
2854
2863
  CALENDAR_SUPERTYPE,
@@ -2893,6 +2902,7 @@ export {
2893
2902
  formatYearLabel,
2894
2903
  getElementIcon,
2895
2904
  getElementLabel,
2905
+ isAgentDoor,
2896
2906
  isDemoKey,
2897
2907
  isLeapYear,
2898
2908
  isParseError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlyworlds/sdk",
3
- "version": "4.24.0",
3
+ "version": "4.26.0",
4
4
  "description": "TypeScript SDK for the OnlyWorlds API - build world-building applications with type safety",
5
5
  "type": "module",
6
6
  "exports": {