@onlyworlds/sdk 4.25.0 → 4.27.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,28 @@ earlier history lives in git log only.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [4.27.0] — 2026-10-16
9
+
10
+ ### Added
11
+ - `OwApiError.isIdempotencyInFlight` (keel #307, D105): a request with the same Idempotency-Key is still
12
+ running (409 `idempotency_in_flight`, `retryAfter` 1). Nothing was written by this one; send again with
13
+ the same key and body after `retryAfter` and it replays the first answer. `isIdempotencyConflict` stays
14
+ the different-body case only. The client still does not retry for you.
15
+
16
+ ## [4.26.0] — 2026-10-15
17
+
18
+ ### Added
19
+ - **The door of every write** (keel #299, D104; keel 7c1b493). An opt-in
20
+ `agent: true` on `OwClientConfig` sends `X-OW-Agent` on every element write (create, upsert,
21
+ patch, delete, editLinks, bulk: the operations keel's document declares it on; never on reads,
22
+ account routes or the image edge); keel records such writes as `declared`, agent-made, and stores only that the header was
23
+ there. Off by default: it describes the caller, so a tool people use never sets it.
24
+ - `OwElementBase` gains the read-only `changed_by` (the membership of the last write) and
25
+ `changed_via` (its door: `seat`, `mcp`, `declared`, `api`, `v1`, `sync`, `server`); a `/changes`
26
+ delete op gains `deleted_by` and `deleted_via`. Keel drops them from a write body, like `created_by`.
27
+ - `OwWriteDoor`, `AGENT_DOORS` and `isAgentDoor(door)`: seat, mcp and declared are agent-made.
28
+ - 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.
29
+
8
30
  ## [4.25.0] — 2026-10-15
9
31
 
10
32
  ### 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
  /**
@@ -2358,6 +2394,13 @@ declare class OwApiError extends Error {
2358
2394
  * conflict: keel also answers 409 `id_conflict` (see isIdConflict).
2359
2395
  */
2360
2396
  get isIdempotencyConflict(): boolean;
2397
+ /**
2398
+ * A request with this Idempotency-Key is still running (409 `idempotency_in_flight`, keel
2399
+ * #307, D105): two sends of one create or bulk overlapped. Nothing was written by this one.
2400
+ * Wait `retryAfter` seconds (keel sends 1) and send again with the SAME key and body: once
2401
+ * the first has answered, that retry replays its answer. Not a key conflict (see above).
2402
+ */
2403
+ get isIdempotencyInFlight(): boolean;
2361
2404
  /**
2362
2405
  * The id is already taken (409 `id_conflict`): a create with an id that exists
2363
2406
  * (keel D39), or a PUT whose id belongs to another world (D70). Retrying will not
@@ -2481,6 +2524,7 @@ declare class OwV2Client {
2481
2524
  private readonly apiKey;
2482
2525
  private readonly apiPin;
2483
2526
  private readonly fetchImpl;
2527
+ private readonly agent;
2484
2528
  constructor(config: OwClientConfig);
2485
2529
  /** GET /health -- unauthenticated liveness pulse. */
2486
2530
  health(): Promise<unknown>;
@@ -2764,6 +2808,8 @@ declare class OwV2Client {
2764
2808
  allowEmpty?: boolean;
2765
2809
  replayAware?: boolean;
2766
2810
  /** A `change_seq` to send as `If-Match` (keel #210); a whole number, else TypeError before sending. */
2811
+ /** An element write (create, put, patch, delete, links, bulk): where an agent client sends X-OW-Agent. */
2812
+ write?: boolean;
2767
2813
  ifMatch?: number;
2768
2814
  }): Promise<T>;
2769
2815
  }
@@ -3711,4 +3757,4 @@ declare class TokenResource {
3711
3757
  getEncryptionInfo(): Promise<EncryptionInfo>;
3712
3758
  }
3713
3759
 
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 };
3760
+ 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
@@ -26,6 +26,15 @@ var OwApiError = class extends Error {
26
26
  get isIdempotencyConflict() {
27
27
  return this.status === 409 && this.code === "idempotency_error";
28
28
  }
29
+ /**
30
+ * A request with this Idempotency-Key is still running (409 `idempotency_in_flight`, keel
31
+ * #307, D105): two sends of one create or bulk overlapped. Nothing was written by this one.
32
+ * Wait `retryAfter` seconds (keel sends 1) and send again with the SAME key and body: once
33
+ * the first has answered, that retry replays its answer. Not a key conflict (see above).
34
+ */
35
+ get isIdempotencyInFlight() {
36
+ return this.status === 409 && this.code === "idempotency_in_flight";
37
+ }
29
38
  /**
30
39
  * The id is already taken (409 `id_conflict`): a create with an id that exists
31
40
  * (keel D39), or a PUT whose id belongs to another world (D70). Retrying will not
@@ -191,6 +200,7 @@ var OwV2Client = class {
191
200
  this.pageSize = config.pageSize ?? DEFAULT_PAGE_SIZE;
192
201
  this.changesPageSize = config.changesPageSize ?? DEFAULT_CHANGES_PAGE_SIZE;
193
202
  this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
203
+ this.agent = config.agent === true;
194
204
  if (typeof this.fetchImpl !== "function") {
195
205
  throw new Error("OwV2Client: no fetch available -- supply config.fetch");
196
206
  }
@@ -276,13 +286,14 @@ var OwV2Client = class {
276
286
  body.id = mintUuid();
277
287
  }
278
288
  return this.request("POST", `/${type}/`, {
289
+ write: true,
279
290
  body,
280
291
  idempotencyKey: opts.idempotencyKey
281
292
  });
282
293
  }
283
294
  /** PUT /{type}/{id}/ -- upsert-by-client-id. The local-first write primitive. */
284
295
  async upsert(type, id, element) {
285
- return this.request("PUT", `/${type}/${id}/`, { body: sanitizePayload(element) });
296
+ return this.request("PUT", `/${type}/${id}/`, { write: true, body: sanitizePayload(element) });
286
297
  }
287
298
  /**
288
299
  * PATCH /{type}/{id}/ -- partial update. DESTRUCTIVE on sent fields: arrays
@@ -295,7 +306,7 @@ var OwV2Client = class {
295
306
  * it for today's unconditional write.
296
307
  */
297
308
  async patch(type, id, partial, opts = {}) {
298
- return this.request("PATCH", `/${type}/${id}/`, { body: sanitizePayload(partial), ifMatch: opts.ifMatch });
309
+ return this.request("PATCH", `/${type}/${id}/`, { write: true, body: sanitizePayload(partial), ifMatch: opts.ifMatch });
299
310
  }
300
311
  /**
301
312
  * DELETE /{type}/{id}/ -- idempotent (204 on absent). Server writes a
@@ -303,7 +314,7 @@ var OwV2Client = class {
303
314
  * transaction -- no client-side unlink pass needed, ever.
304
315
  */
305
316
  async delete(type, id) {
306
- await this.request("DELETE", `/${type}/${id}/`, { allowEmpty: true });
317
+ await this.request("DELETE", `/${type}/${id}/`, { write: true, allowEmpty: true });
307
318
  }
308
319
  /**
309
320
  * POST /{type}/{id}/links/{field} with {add, remove} -- atomic link merge.
@@ -313,7 +324,7 @@ var OwV2Client = class {
313
324
  * moves the element too.
314
325
  */
315
326
  async editLinks(type, id, field, edit, opts = {}) {
316
- return this.request("POST", `/${type}/${id}/links/${field}`, { body: edit, ifMatch: opts.ifMatch });
327
+ return this.request("POST", `/${type}/${id}/links/${field}`, { write: true, body: edit, ifMatch: opts.ifMatch });
317
328
  }
318
329
  // -- Bulk ----------------------------------------------------------------
319
330
  /**
@@ -334,6 +345,7 @@ var OwV2Client = class {
334
345
  atomic: opts.atomic ?? false
335
346
  };
336
347
  return this.request("POST", "/bulk/", {
348
+ write: true,
337
349
  body,
338
350
  idempotencyKey: opts.idempotencyKey,
339
351
  replayAware: true
@@ -617,6 +629,7 @@ var OwV2Client = class {
617
629
  if (opts.body !== void 0) headers["Content-Type"] = "application/json";
618
630
  if (opts.idempotencyKey) headers["Idempotency-Key"] = opts.idempotencyKey;
619
631
  if (opts.ifMatch !== void 0) headers["If-Match"] = `"${opts.ifMatch}"`;
632
+ if (this.agent && opts.write) headers["X-OW-Agent"] = "1";
620
633
  let res;
621
634
  try {
622
635
  res = await this.fetchImpl(url, {
@@ -1431,6 +1444,10 @@ var FIELD_SCHEMA = {
1431
1444
 
1432
1445
  // src/v2/types.ts
1433
1446
  var SPATIAL_TYPES = ["map", "pin", "marker", "zone"];
1447
+ var AGENT_DOORS = ["seat", "mcp", "declared"];
1448
+ function isAgentDoor(door) {
1449
+ return door != null && AGENT_DOORS.includes(door);
1450
+ }
1434
1451
 
1435
1452
  // src/v2/palette.ts
1436
1453
  var FAMILY_COLORS = {
@@ -2849,6 +2866,7 @@ var GameTier = /* @__PURE__ */ ((GameTier2) => {
2849
2866
  return GameTier2;
2850
2867
  })(GameTier || {});
2851
2868
  export {
2869
+ AGENT_DOORS,
2852
2870
  ASK_LIMITS,
2853
2871
  CALENDAR_FIELD,
2854
2872
  CALENDAR_SUPERTYPE,
@@ -2893,6 +2911,7 @@ export {
2893
2911
  formatYearLabel,
2894
2912
  getElementIcon,
2895
2913
  getElementLabel,
2914
+ isAgentDoor,
2896
2915
  isDemoKey,
2897
2916
  isLeapYear,
2898
2917
  isParseError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlyworlds/sdk",
3
- "version": "4.25.0",
3
+ "version": "4.27.0",
4
4
  "description": "TypeScript SDK for the OnlyWorlds API - build world-building applications with type safety",
5
5
  "type": "module",
6
6
  "exports": {