@neta-art/cohub 2.14.1 → 3.0.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.
@@ -169,6 +169,9 @@ var ModelsApi = class {
169
169
  async listMultimodal() {
170
170
  return this.transport.request(`/api/models?modelType=${MULTIMODAL_MODEL_TYPE}`);
171
171
  }
172
+ async status() {
173
+ return this.transport.request("/api/models/status");
174
+ }
172
175
  };
173
176
  //#endregion
174
177
  //#region src/apis/prompts.ts
@@ -1313,21 +1316,23 @@ const getFilenameFromContentDisposition = (value) => {
1313
1316
  return value.match(/filename="?([^";]+)"?/i)?.[1] ?? null;
1314
1317
  };
1315
1318
  /**
1316
- * A canvas transaction rejected by the server. `status`/`code` let callers
1319
+ * A board transaction rejected by the server. `status`/`code` let callers
1317
1320
  * distinguish a recoverable version conflict (409 / "VERSION_CONFLICT") from
1318
1321
  * transient failures, so they can rebase and retry instead of surfacing an error.
1319
1322
  */
1320
- var CanvasTransactionError = class extends Error {
1323
+ var BoardTransactionError = class extends Error {
1321
1324
  status;
1322
1325
  code;
1323
- constructor(message, status, code) {
1324
- super(message);
1326
+ body;
1327
+ constructor(message, status, code, body, options) {
1328
+ super(message, options);
1325
1329
  this.status = status;
1326
1330
  this.code = code;
1327
- this.name = "CanvasTransactionError";
1331
+ this.body = body;
1332
+ this.name = "BoardTransactionError";
1328
1333
  }
1329
1334
  get isVersionConflict() {
1330
- return this.status === 409 || this.code === "VERSION_CONFLICT";
1335
+ return this.code === "VERSION_CONFLICT";
1331
1336
  }
1332
1337
  };
1333
1338
  const toSessionEventName = (type) => {
@@ -1805,15 +1810,11 @@ var SpaceEventsApi = class {
1805
1810
  handler(event);
1806
1811
  return;
1807
1812
  }
1808
- if (type === "canvas.tx.applied" && event.type === "canvas.tx.applied") {
1809
- handler(event);
1810
- return;
1811
- }
1812
- if (type === "canvas.tx.ack" && event.type === "canvas.tx.ack") {
1813
+ if (type === "board.transaction.applied" && event.type === "board.transaction.applied") {
1813
1814
  handler(event);
1814
1815
  return;
1815
1816
  }
1816
- if (type === "canvas.tx.error" && event.type === "canvas.tx.error") {
1817
+ if (type === "board.playback.changed" && event.type === "board.playback.changed") {
1817
1818
  handler(event);
1818
1819
  return;
1819
1820
  }
@@ -2148,34 +2149,159 @@ var SpaceCommerceApi = class {
2148
2149
  return this.transport.request(`/api/spaces/${this.spaceId}/commerce/orders${params.toString() ? `?${params.toString()}` : ""}`);
2149
2150
  }
2150
2151
  };
2151
- var SpaceCanvasApi = class {
2152
+ var BoardRealtimeClient = class {
2153
+ websocketClient;
2154
+ spaceId;
2155
+ boardId;
2156
+ constructor(websocketClient, spaceId, boardId) {
2157
+ this.websocketClient = websocketClient;
2158
+ this.spaceId = spaceId;
2159
+ this.boardId = boardId;
2160
+ }
2161
+ subscribe(handlers) {
2162
+ if (!this.websocketClient) throw new Error("realtime transport is not configured for this client");
2163
+ ensureRealtimeConnected(this.websocketClient);
2164
+ const releaseRoom = this.websocketClient.retainRooms([getRealtimeSpaceRoom(this.spaceId)]);
2165
+ const unsubscribe = this.websocketClient.on("event", (event) => {
2166
+ if (event.spaceId !== this.spaceId) return;
2167
+ if (event.type === "board.transaction.applied" && event.payload.boardId === this.boardId) {
2168
+ const transactionEvent = event;
2169
+ handlers.event?.(transactionEvent);
2170
+ handlers.transaction?.(transactionEvent);
2171
+ }
2172
+ if (event.type === "board.playback.changed" && event.payload.boardId === this.boardId) {
2173
+ const playbackEvent = event;
2174
+ handlers.event?.(playbackEvent);
2175
+ handlers.playback?.(playbackEvent);
2176
+ }
2177
+ });
2178
+ return () => {
2179
+ unsubscribe();
2180
+ releaseRoom();
2181
+ };
2182
+ }
2183
+ on(type, handler) {
2184
+ return type === "transaction" ? this.subscribe({ transaction: handler }) : this.subscribe({ playback: handler });
2185
+ }
2186
+ };
2187
+ var BoardClient = class {
2188
+ spaceId;
2189
+ id;
2190
+ realtime;
2191
+ boards;
2192
+ constructor(spaceId, id, transport, websocketClient) {
2193
+ this.spaceId = spaceId;
2194
+ this.id = id;
2195
+ this.boards = new SpaceBoardsApi(transport, spaceId, websocketClient);
2196
+ this.realtime = new BoardRealtimeClient(websocketClient, spaceId, id);
2197
+ }
2198
+ inspect(input = {}, customFetch) {
2199
+ return this.boards.inspect(this.id, input, customFetch);
2200
+ }
2201
+ capabilities(customFetch) {
2202
+ return this.boards.capabilities(this.id, customFetch);
2203
+ }
2204
+ validate(transaction) {
2205
+ return this.boards.validate({
2206
+ ...transaction,
2207
+ boardId: this.id
2208
+ });
2209
+ }
2210
+ apply(transaction) {
2211
+ return this.boards.apply({
2212
+ ...transaction,
2213
+ boardId: this.id
2214
+ });
2215
+ }
2216
+ playback(command) {
2217
+ return this.boards.playback(this.id, command);
2218
+ }
2219
+ play(command) {
2220
+ return this.boards.play(this.id, command);
2221
+ }
2222
+ pause(command) {
2223
+ return this.boards.pause(this.id, command);
2224
+ }
2225
+ seek(command) {
2226
+ return this.boards.seek(this.id, command);
2227
+ }
2228
+ stop(command) {
2229
+ return this.boards.stop(this.id, command);
2230
+ }
2231
+ subscribe(handlers) {
2232
+ return this.realtime.subscribe(handlers);
2233
+ }
2234
+ on(type, handler) {
2235
+ return type === "transaction" ? this.realtime.on("transaction", handler) : this.realtime.on("playback", handler);
2236
+ }
2237
+ };
2238
+ var SpaceBoardsApi = class {
2152
2239
  transport;
2153
2240
  spaceId;
2154
- constructor(transport, spaceId) {
2241
+ websocketClient;
2242
+ constructor(transport, spaceId, websocketClient) {
2155
2243
  this.transport = transport;
2156
2244
  this.spaceId = spaceId;
2245
+ this.websocketClient = websocketClient;
2246
+ }
2247
+ byId(boardId) {
2248
+ return new BoardClient(this.spaceId, boardId, this.transport, this.websocketClient);
2157
2249
  }
2158
2250
  create(input) {
2159
- return this.transport.request(`/api/spaces/${this.spaceId}/canvas`, {
2251
+ return this.transport.request(`/api/spaces/${this.spaceId}/boards`, {
2160
2252
  method: "POST",
2161
2253
  headers: { "Content-Type": "application/json" },
2162
2254
  body: JSON.stringify(input)
2163
2255
  });
2164
2256
  }
2165
- getByPath(path, customFetch) {
2166
- const params = new URLSearchParams({ path });
2167
- return this.transport.request(`/api/spaces/${this.spaceId}/canvas/by-path?${params.toString()}`, { fetch: customFetch });
2257
+ inspect(boardId, input = {}, customFetch) {
2258
+ const params = new URLSearchParams();
2259
+ for (const section of input.include ?? []) params.append("include", section);
2260
+ if (input.viewport) params.set("viewport", JSON.stringify(input.viewport));
2261
+ const query = params.toString();
2262
+ return this.transport.request(`/api/spaces/${this.spaceId}/boards/${boardId}${query ? `?${query}` : ""}`, { fetch: customFetch });
2168
2263
  }
2169
- bootstrap(documentId, customFetch) {
2170
- return this.transport.request(`/api/spaces/${this.spaceId}/canvas/${documentId}/bootstrap`, { fetch: customFetch });
2264
+ capabilities(boardId, customFetch) {
2265
+ return this.transport.request(`/api/spaces/${this.spaceId}/boards/${boardId}/capabilities`, { fetch: customFetch });
2171
2266
  }
2172
- sendTransaction(documentId, input) {
2173
- return this.transport.request(`/api/spaces/${this.spaceId}/canvas/${documentId}/ops`, {
2267
+ validate(transaction) {
2268
+ return this.transport.request(`/api/spaces/${this.spaceId}/boards/${transaction.boardId}/validate`, {
2174
2269
  method: "POST",
2175
2270
  headers: { "Content-Type": "application/json" },
2176
- body: JSON.stringify(input)
2271
+ body: JSON.stringify(transaction)
2272
+ });
2273
+ }
2274
+ async apply(transaction) {
2275
+ try {
2276
+ return await this.transport.request(`/api/spaces/${this.spaceId}/boards/${transaction.boardId}/transactions`, {
2277
+ method: "POST",
2278
+ headers: { "Content-Type": "application/json" },
2279
+ body: JSON.stringify(transaction)
2280
+ });
2281
+ } catch (cause) {
2282
+ if (cause instanceof HttpError) throw new BoardTransactionError(cause.message, cause.status, cause.code ?? void 0, cause.body, { cause });
2283
+ throw cause;
2284
+ }
2285
+ }
2286
+ playback(boardId, command) {
2287
+ return this.transport.request(`/api/spaces/${this.spaceId}/boards/${boardId}/playback`, {
2288
+ method: "POST",
2289
+ headers: { "Content-Type": "application/json" },
2290
+ body: JSON.stringify(command)
2177
2291
  });
2178
2292
  }
2293
+ play(boardId, command) {
2294
+ return this.playback(boardId, command);
2295
+ }
2296
+ pause(boardId, command) {
2297
+ return this.playback(boardId, command);
2298
+ }
2299
+ seek(boardId, command) {
2300
+ return this.playback(boardId, command);
2301
+ }
2302
+ stop(boardId, command) {
2303
+ return this.playback(boardId, command);
2304
+ }
2179
2305
  };
2180
2306
  var SpaceCheckpointFilesApi = class {
2181
2307
  transport;
@@ -2313,7 +2439,7 @@ var SpaceClient = class {
2313
2439
  sandbox;
2314
2440
  invitations;
2315
2441
  labels;
2316
- canvas;
2442
+ boards;
2317
2443
  commerce;
2318
2444
  constructor(id, transport, websocketClient) {
2319
2445
  this.id = id;
@@ -2332,12 +2458,15 @@ var SpaceClient = class {
2332
2458
  this.sandbox = new SpaceSandboxApi(transport, id);
2333
2459
  this.invitations = new SpaceInvitationsApi(transport, id);
2334
2460
  this.labels = new SpaceLabelsApi(transport, id);
2335
- this.canvas = new SpaceCanvasApi(transport, id);
2461
+ this.boards = new SpaceBoardsApi(transport, id, websocketClient);
2336
2462
  this.commerce = new SpaceCommerceApi(transport, id);
2337
2463
  }
2338
2464
  get(customFetch) {
2339
2465
  return this.transport.request(`/api/spaces/${this.id}`, { fetch: customFetch });
2340
2466
  }
2467
+ getStartup(customFetch) {
2468
+ return this.transport.request(`/api/spaces/${this.id}/startup`, { fetch: customFetch });
2469
+ }
2341
2470
  prompt(input) {
2342
2471
  return this.transport.request(`/api/spaces/${this.id}/prompt`, {
2343
2472
  method: "POST",
@@ -2471,46 +2600,6 @@ var SpaceClient = class {
2471
2600
  rename(name) {
2472
2601
  return this.update({ name });
2473
2602
  }
2474
- async sendCanvasTransactionRealtime(documentId, input) {
2475
- if (!this.websocketClient) return this.canvas.sendTransaction(documentId, input);
2476
- const requestId = `canvas-${input.txId}`;
2477
- const result = new Promise((resolve, reject) => {
2478
- let settled = false;
2479
- let timeout = null;
2480
- const settle = (fn) => {
2481
- if (settled) return;
2482
- settled = true;
2483
- if (timeout) clearTimeout(timeout);
2484
- cleanupAck?.();
2485
- cleanupError?.();
2486
- fn();
2487
- };
2488
- const cleanupAck = this.websocketClient?.on("event", (event) => {
2489
- if (event.type !== "canvas.tx.ack" || event.requestId !== requestId) return;
2490
- const version = event.payload.version;
2491
- settle(() => {
2492
- if (typeof version === "number") resolve({ document: { version } });
2493
- else reject(/* @__PURE__ */ new Error("Invalid canvas ack"));
2494
- });
2495
- });
2496
- const cleanupError = this.websocketClient?.on("event", (event) => {
2497
- if (event.type !== "canvas.tx.error" || event.requestId !== requestId) return;
2498
- settle(() => reject(new CanvasTransactionError(typeof event.payload.message === "string" ? event.payload.message : "Canvas sync failed", typeof event.payload.status === "number" ? event.payload.status : void 0, typeof event.payload.code === "string" ? event.payload.code : void 0)));
2499
- });
2500
- timeout = setTimeout(() => settle(() => reject(/* @__PURE__ */ new Error("Canvas sync timed out"))), 15e3);
2501
- });
2502
- await this.websocketClient.sendCanvasTransaction({
2503
- spaceId: this.id,
2504
- documentId,
2505
- txId: input.txId,
2506
- baseVersion: input.baseVersion ?? null,
2507
- clientId: input.clientId ?? null,
2508
- undoGroupId: input.undoGroupId ?? null,
2509
- ops: input.ops,
2510
- requestId
2511
- });
2512
- return result;
2513
- }
2514
2603
  profile(body) {
2515
2604
  return this.transport.request(`/api/spaces/${this.id}/profile`, {
2516
2605
  method: "PATCH",
@@ -2538,6 +2627,9 @@ var SpaceClient = class {
2538
2627
  session(sessionId) {
2539
2628
  return new SessionClient(this.id, sessionId, this.transport, this.websocketClient);
2540
2629
  }
2630
+ board(boardId) {
2631
+ return new BoardClient(this.id, boardId, this.transport, this.websocketClient);
2632
+ }
2541
2633
  updatePresence(meta) {
2542
2634
  if (!this.websocketClient) return Promise.resolve();
2543
2635
  return this.websocketClient.updatePresence({
@@ -2582,11 +2674,13 @@ var UserApi = class {
2582
2674
  transportBaseUrl;
2583
2675
  setStoredAuthToken;
2584
2676
  clearStoredAuthToken;
2677
+ labels;
2585
2678
  constructor(transport, transportBaseUrl, setStoredAuthToken, clearStoredAuthToken) {
2586
2679
  this.transport = transport;
2587
2680
  this.transportBaseUrl = transportBaseUrl;
2588
2681
  this.setStoredAuthToken = setStoredAuthToken;
2589
2682
  this.clearStoredAuthToken = clearStoredAuthToken;
2683
+ this.labels = new UserLabelsApi(transport);
2590
2684
  }
2591
2685
  getMe(options) {
2592
2686
  const init = typeof options === "function" ? { fetch: options } : options;
@@ -2636,6 +2730,25 @@ var UserApi = class {
2636
2730
  return null;
2637
2731
  }
2638
2732
  };
2733
+ /** User-scoped labels — same label/assignment model as space labels, but private to the viewer. */
2734
+ var UserLabelsApi = class {
2735
+ transport;
2736
+ constructor(transport) {
2737
+ this.transport = transport;
2738
+ }
2739
+ getResourceLabels(resourceType, resourceRef) {
2740
+ const params = new URLSearchParams({ resourceRef });
2741
+ return this.transport.request(`/api/me/resources/${resourceType}/labels?${params.toString()}`);
2742
+ }
2743
+ patchResourceLabels(resourceType, resourceRef, input) {
2744
+ const params = new URLSearchParams({ resourceRef });
2745
+ return this.transport.request(`/api/me/resources/${resourceType}/labels?${params.toString()}`, {
2746
+ method: "PATCH",
2747
+ headers: { "Content-Type": "application/json" },
2748
+ body: JSON.stringify(input)
2749
+ });
2750
+ }
2751
+ };
2639
2752
  //#endregion
2640
2753
  //#region src/apis/users.ts
2641
2754
  const MAX_BATCH_USER_PROFILES = 100;
@@ -2822,4 +2935,4 @@ var CohubHttpClient = class {
2822
2935
  };
2823
2936
  const createHttpClient = (options) => new CohubHttpClient(options);
2824
2937
  //#endregion
2825
- export { SkillsApi as C, CronJobsApi as D, GenerationsApi as E, ChannelsApi as O, PublicAssetsApi as S, ModelsApi as T, createSessionPatchReducer as _, ReferralsApi as a, ReferencesApi as b, TasksApi as c, SpacesApi as d, PublicInviteApi as f, SessionPatchReducer as g, parseAssistantMessageCommit as h, WorksApi as i, CanvasTransactionError as l, createSessionGenerationStreamClient as m, createHttpClient as n, UsersApi as o, SessionGenerationStreamClient as p, WorkCommerceApi as r, UserApi as s, CohubHttpClient as t, SpaceClient as u, ensureRealtimeConnected as v, PromptsApi as w, SearchApi as x, SessionAccessApi as y };
2938
+ export { PublicAssetsApi as C, GenerationsApi as D, ModelsApi as E, CronJobsApi as O, SearchApi as S, PromptsApi as T, SessionPatchReducer as _, ReferralsApi as a, SessionAccessApi as b, TasksApi as c, SpaceClient as d, SpacesApi as f, parseAssistantMessageCommit as g, createSessionGenerationStreamClient as h, WorksApi as i, ChannelsApi as k, BoardClient as l, SessionGenerationStreamClient as m, createHttpClient as n, UsersApi as o, PublicInviteApi as p, WorkCommerceApi as r, UserApi as s, CohubHttpClient as t, BoardTransactionError as u, createSessionPatchReducer as v, SkillsApi as w, ReferencesApi as x, ensureRealtimeConnected as y };