@onlyworlds/sdk 4.25.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,20 @@ 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
+
8
22
  ## [4.25.0] — 2026-10-15
9
23
 
10
24
  ### Changed
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
  }
@@ -1905,20 +1909,43 @@ interface OwPage<T = OwElement> {
1905
1909
  next_cursor: string | null;
1906
1910
  }
1907
1911
  /** /changes feed -- discriminated union on `op`. Apply in order -> convergence. */
1908
- 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 {
1909
1915
  op: 'upsert';
1910
1916
  id: string;
1911
1917
  type: string;
1912
1918
  element: OwElement;
1913
1919
  updated_at: string;
1920
+ /** The change's place in the world's feed. */
1921
+ change_seq: number;
1914
1922
  [k: string]: unknown;
1915
- } | {
1923
+ }
1924
+ /** A /changes item for an element deleted. */
1925
+ interface OwChangeDelete {
1916
1926
  op: 'delete';
1917
1927
  id: string;
1918
1928
  type: string;
1919
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;
1920
1936
  [k: string]: unknown;
1921
- };
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;
1922
1949
  /**
1923
1950
  * /changes response. Wire shape verified in keel source (core/changes.py) and
1924
1951
  * pinned here: {cursor, changes, has_more, head}.
@@ -2308,6 +2335,15 @@ interface OwClientConfig {
2308
2335
  changesPageSize?: number;
2309
2336
  /** A fetch implementation to use instead of globalThis.fetch (for tests and other runtimes). */
2310
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;
2311
2347
  }
2312
2348
 
2313
2349
  /**
@@ -2481,6 +2517,7 @@ declare class OwV2Client {
2481
2517
  private readonly apiKey;
2482
2518
  private readonly apiPin;
2483
2519
  private readonly fetchImpl;
2520
+ private readonly agent;
2484
2521
  constructor(config: OwClientConfig);
2485
2522
  /** GET /health -- unauthenticated liveness pulse. */
2486
2523
  health(): Promise<unknown>;
@@ -2764,6 +2801,8 @@ declare class OwV2Client {
2764
2801
  allowEmpty?: boolean;
2765
2802
  replayAware?: boolean;
2766
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;
2767
2806
  ifMatch?: number;
2768
2807
  }): Promise<T>;
2769
2808
  }
@@ -3711,4 +3750,4 @@ declare class TokenResource {
3711
3750
  getEncryptionInfo(): Promise<EncryptionInfo>;
3712
3751
  }
3713
3752
 
3714
- 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.25.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": {