@neta-art/cohub 12.1.0 → 12.1.1

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.
@@ -9,6 +9,7 @@ import { Renderer } from "pixi.js";
9
9
  type NodeCanvasModule = {
10
10
  createCanvas: (width: number, height: number) => unknown;
11
11
  Image: new () => unknown;
12
+ DOMMatrix: new (init?: number[]) => unknown;
12
13
  GlobalFonts: BoardFontRegistry;
13
14
  };
14
15
  type BoardNodeRendererOptions = {
@@ -24,6 +24,10 @@ async function loadCanvasModule() {
24
24
  throw new Error("Board image export needs the optional '@napi-rs/canvas' package. Install it with: npm i @napi-rs/canvas", { cause });
25
25
  }
26
26
  }
27
+ function installDOMMatrix(canvasModule) {
28
+ const globals = globalThis;
29
+ globals.DOMMatrix ??= canvasModule.DOMMatrix;
30
+ }
27
31
  function installAnimationFrameShim() {
28
32
  const globals = globalThis;
29
33
  if (globals.requestAnimationFrame) return () => {};
@@ -78,6 +82,7 @@ async function createNodeBoardRenderer(options = {}) {
78
82
  throw new Error("XML parsing is not available in Node board export.");
79
83
  }
80
84
  });
85
+ installDOMMatrix(canvasModule);
81
86
  installBoardTextMeasurement();
82
87
  const restoreAnimationFrame = installAnimationFrameShim();
83
88
  const renderer = new CanvasRenderer();
@@ -1,5 +1,5 @@
1
1
  import { O as readRtcTransportStats, k as waitForIceGathering } from "./http.js";
2
- import { o as REALTIME_ROOM_EVENT_NAME_PATTERN, t as HttpError } from "./transport.js";
2
+ import { c as HttpError, p as REALTIME_ROOM_EVENT_NAME_PATTERN } from "./http-error.js";
3
3
  import { z } from "zod";
4
4
  //#region \0rolldown/runtime.js
5
5
  var __defProp = Object.defineProperty;
@@ -509,4 +509,40 @@ var HttpTransport = class {
509
509
  }
510
510
  };
511
511
  //#endregion
512
- export { requestSourceToHeaders as A, isRequestSourceClientId as C, normalizeRequestSource as D, mergeRequestSourceIntoMeta as E, isUuid as M, isUuidLike as N, parseRequestSourceFromHeaders as O, isUuidOrShortUuid as P, hasRequestSourceIdentity as S, isRequestSourceUuid as T, isRealtimeDomain as _, sanitizeAccessToken as a, COHUB_SOURCE_HEADER_NAMES as b, WS_BOARD_AWARENESS_CAPABILITY as c, WS_REALTIME_ROOM_HISTORY_CAPABILITY as d, WS_REALTIME_ROOM_RTC_CAPABILITY as f, getSessionTurnPatchStreamKey as g, getRealtimeSpaceRoom as h, matchesUnauthorizedErrorToken as i, resolveRequestSourceChannel as j, readRequestSourceFromEnv as k, WS_COMPACT_STREAM_CAPABILITY as l, getRealtimeBoardRoom as m, HttpTransport as n, REALTIME_ROOM_EVENT_NAME_PATTERN as o, WS_ROOM_SUBSCRIPTION_CAPABILITY as p, joinApiUrl as r, REALTIME_ROOM_MAX_PAYLOAD_BYTES as s, HttpError as t, WS_REALTIME_ROOM_CAPABILITY as u, normalizeRealtimeRooms as v, isRequestSourceEmpty as w, REQUEST_SOURCE_VIA_MAX_LENGTH as x, COHUB_SOURCE_HEADER as y };
512
+ //#region src/http-error.ts
513
+ /** Shared HTTP error code for every plan entitlement gate (402). */
514
+ const FEATURE_NOT_ENTITLED_ERROR_CODE = "feature_not_entitled";
515
+ /** Shared HTTP error code for a blocked usage gate (negative balance limit, 402). */
516
+ const BILLING_ACCESS_BLOCKED_ERROR_CODE = "billing_credit_limit_exceeded";
517
+ function isHttpErrorCode(error, code) {
518
+ return error instanceof HttpError && error.code === code;
519
+ }
520
+ function isFeatureNotEntitledError(error) {
521
+ return isHttpErrorCode(error, FEATURE_NOT_ENTITLED_ERROR_CODE);
522
+ }
523
+ function isBillingAccessBlockedError(error) {
524
+ return isHttpErrorCode(error, BILLING_ACCESS_BLOCKED_ERROR_CODE);
525
+ }
526
+ function isBillingAccessBlockedCode(code) {
527
+ return code === BILLING_ACCESS_BLOCKED_ERROR_CODE;
528
+ }
529
+ const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
530
+ function isBillingConversionIntent(value) {
531
+ if (!isRecord(value)) return false;
532
+ return (value.level === "soft" || value.level === "hard") && typeof value.title === "string" && typeof value.message === "string" && isRecord(value.primaryAction) && value.primaryAction.action === "open_billing_conversion";
533
+ }
534
+ /**
535
+ * Extracts the standard `billing` payload from a response body, an
536
+ * `HttpError`, or a bare billing payload (e.g. a realtime error event's
537
+ * `billing` field). Returns `null` unless it carries a valid conversion
538
+ * intent.
539
+ */
540
+ function extractBillingPayload(source) {
541
+ const root = source instanceof HttpError ? source.body : source;
542
+ if (!isRecord(root)) return null;
543
+ const billing = isRecord(root.billing) ? root.billing : root;
544
+ if (!isBillingConversionIntent(billing.conversion)) return null;
545
+ return billing;
546
+ }
547
+ //#endregion
548
+ export { isRequestSourceClientId as A, isUuidLike as B, getSessionTurnPatchStreamKey as C, COHUB_SOURCE_HEADER_NAMES as D, COHUB_SOURCE_HEADER as E, parseRequestSourceFromHeaders as F, readRequestSourceFromEnv as I, requestSourceToHeaders as L, isRequestSourceUuid as M, mergeRequestSourceIntoMeta as N, REQUEST_SOURCE_VIA_MAX_LENGTH as O, normalizeRequestSource as P, resolveRequestSourceChannel as R, getRealtimeSpaceRoom as S, normalizeRealtimeRooms as T, isUuidOrShortUuid as V, WS_REALTIME_ROOM_CAPABILITY as _, isBillingAccessBlockedError as a, WS_ROOM_SUBSCRIPTION_CAPABILITY as b, HttpError as c, matchesUnauthorizedErrorToken as d, sanitizeAccessToken as f, WS_COMPACT_STREAM_CAPABILITY as g, WS_BOARD_AWARENESS_CAPABILITY as h, isBillingAccessBlockedCode as i, isRequestSourceEmpty as j, hasRequestSourceIdentity as k, HttpTransport as l, REALTIME_ROOM_MAX_PAYLOAD_BYTES as m, FEATURE_NOT_ENTITLED_ERROR_CODE as n, isFeatureNotEntitledError as o, REALTIME_ROOM_EVENT_NAME_PATTERN as p, extractBillingPayload as r, isHttpErrorCode as s, BILLING_ACCESS_BLOCKED_ERROR_CODE as t, joinApiUrl as u, WS_REALTIME_ROOM_HISTORY_CAPABILITY as v, isRealtimeDomain as w, getRealtimeBoardRoom as x, WS_REALTIME_ROOM_RTC_CAPABILITY as y, isUuid as z };
@@ -1,4 +1,4 @@
1
- import { M as isUuid, h as getRealtimeSpaceRoom, m as getRealtimeBoardRoom, n as HttpTransport, t as HttpError } from "./transport.js";
1
+ import { S as getRealtimeSpaceRoom, c as HttpError, l as HttpTransport, s as isHttpErrorCode, x as getRealtimeBoardRoom, z as isUuid } from "./http-error.js";
2
2
  import { l as resolveExecutionToken, o as resolveApiBaseUrl } from "./environment.js";
3
3
  import { z } from "zod";
4
4
  //#region ../protocol/dist/model/metrics.js
@@ -1039,28 +1039,48 @@ var SessionAccessApi = class {
1039
1039
  };
1040
1040
  //#endregion
1041
1041
  //#region src/apis/file-list.ts
1042
+ const DIRECTORY_CHANGED_RETRY_DELAYS_MS = [
1043
+ 100,
1044
+ 250,
1045
+ 500
1046
+ ];
1042
1047
  async function listDirectory(transport, endpoint, path, options) {
1043
1048
  const pageOptions = typeof options === "object" ? options : void 0;
1044
1049
  const fetch = typeof options === "function" ? options : pageOptions?.fetch;
1045
- const entries = /* @__PURE__ */ new Map();
1046
- const seen = /* @__PURE__ */ new Set();
1047
- let cursor = pageOptions?.cursor;
1048
- let responsePath = path;
1049
- do {
1050
+ const readPage = (cursor) => {
1050
1051
  const params = new URLSearchParams({ pagination: "true" });
1051
1052
  if (path) params.set("path", path);
1052
1053
  if (pageOptions?.limit !== void 0) params.set("limit", String(pageOptions.limit));
1053
1054
  if (cursor) params.set("cursor", cursor);
1054
- const page = await transport.request(`${endpoint}?${params}`, {
1055
+ return transport.request(`${endpoint}?${params}`, {
1055
1056
  fetch,
1056
1057
  signal: pageOptions?.signal
1057
1058
  });
1058
- const nextCursor = page.nextCursor ?? null;
1059
- if (pageOptions) return {
1059
+ };
1060
+ if (pageOptions) {
1061
+ const page = await readPage(pageOptions.cursor);
1062
+ return {
1060
1063
  ...page,
1061
- nextCursor,
1064
+ nextCursor: page.nextCursor ?? null,
1062
1065
  truncated: page.truncated ?? true
1063
1066
  };
1067
+ }
1068
+ for (let attempt = 0;; attempt += 1) try {
1069
+ return await readAllPages(readPage, path);
1070
+ } catch (error) {
1071
+ const delay = DIRECTORY_CHANGED_RETRY_DELAYS_MS[attempt];
1072
+ if (delay === void 0 || !isHttpErrorCode(error, "directory_changed")) throw error;
1073
+ await new Promise((resolve) => setTimeout(resolve, delay));
1074
+ }
1075
+ }
1076
+ async function readAllPages(readPage, path) {
1077
+ const entries = /* @__PURE__ */ new Map();
1078
+ const seen = /* @__PURE__ */ new Set();
1079
+ let cursor;
1080
+ let responsePath = path;
1081
+ do {
1082
+ const page = await readPage(cursor);
1083
+ const nextCursor = page.nextCursor ?? null;
1064
1084
  responsePath = page.path;
1065
1085
  for (const entry of page.entries) entries.set(entry.path, entry);
1066
1086
  if (nextCursor && seen.has(nextCursor)) throw new Error("Server returned a repeated directory cursor.");
package/dist/http.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { n as createHttpClient, t as CohubHttpClient } from "./chunks/http.js";
2
- import { n as HttpTransport, t as HttpError } from "./chunks/transport.js";
2
+ import { c as HttpError, l as HttpTransport } from "./chunks/http-error.js";
3
3
  import { g as scopeListHasPermission, h as isUserLevelPermission, m as USER_LEVEL_PERMISSIONS, p as PERMISSIONS } from "./chunks/environment.js";
4
4
  export { CohubHttpClient, HttpError, HttpTransport, PERMISSIONS, USER_LEVEL_PERMISSIONS, createHttpClient, isUserLevelPermission, scopeListHasPermission };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { c as AppRtcError, i as WorkRoom, n as AppRoom, o as AppRoomRtc, r as WorkRealtimeApi, s as AppRtcChannel, t as AppRealtimeApi } from "./chunks/app-realtime.js";
2
2
  import { $ as isTerminalDesktopCommandStatus, A as BoardClient, B as CronJobsApi, C as SessionPatchReducer, D as connectDisplay, E as DisplayConnection, F as PublicAssetsApi, G as DESKTOP_COMMAND_OPEN_TIMEOUT_MS, H as DESKTOP_COMMAND_ACCEPT_TIMEOUT_MS, I as SkillsApi, J as DESKTOP_COMMAND_SETTLEMENT_GRACE_SECONDS, K as DESKTOP_COMMAND_PAYLOAD_MAX_BYTES, L as PromptsApi, M as SessionAccessApi, N as ReferencesApi, P as SearchApi, Q as isDesktopCallMethod, R as ModelsApi, S as parseAssistantMessageCommit, T as SpaceDisplaysApi, U as DESKTOP_COMMAND_DEFAULT_TIMEOUT_MS, V as ChannelsApi, W as DESKTOP_COMMAND_MAX_TIMEOUT_MS, X as DESKTOP_COMMAND_VERSION, Y as DESKTOP_COMMAND_TERMINAL_TTL_SECONDS, Z as defaultDesktopCommandTimeoutMs, _ as PublicInviteApi, a as WorkCommerceApi, b as SessionGenerationStreamClient, c as AppsApi, ct as normalizeDisplayPoint, d as UserApi, et as parseDesktopCommand, f as TasksApi, g as SpacesApi, h as SpaceWebhooksApi, i as AppCommerceApi, it as DISPLAY_ELEMENT_REF_PATTERN, j as ensureRealtimeConnected, l as ReferralsApi, lt as splitDisplayText, m as SpacePublicFilesApi, n as createHttpClient, nt as resolveOpenSurface, o as DesktopCommandsApi, ot as DISPLAY_INPUT_MAX_TEXT, p as SpaceClient, q as DESKTOP_COMMAND_PENDING_TTL_SECONDS, r as RoomsApi, rt as NAVIGATION_ERROR_MESSAGE_MAX_LENGTH, s as UiCommandsApi, st as DISPLAY_SYSTEM_ACTIONS, t as CohubHttpClient, tt as parseDesktopCommandId, u as UsersApi, v as buildSpaceInvitePath, w as createSessionPatchReducer, x as createSessionGenerationStreamClient, y as buildSpacePath, z as GenerationsApi } from "./chunks/http.js";
3
- import { A as requestSourceToHeaders, C as isRequestSourceClientId, D as normalizeRequestSource, E as mergeRequestSourceIntoMeta, M as isUuid, N as isUuidLike, O as parseRequestSourceFromHeaders, P as isUuidOrShortUuid, S as hasRequestSourceIdentity, T as isRequestSourceUuid, a as sanitizeAccessToken, b as COHUB_SOURCE_HEADER_NAMES, i as matchesUnauthorizedErrorToken, j as resolveRequestSourceChannel, k as readRequestSourceFromEnv, n as HttpTransport, r as joinApiUrl, t as HttpError, w as isRequestSourceEmpty, x as REQUEST_SOURCE_VIA_MAX_LENGTH, y as COHUB_SOURCE_HEADER } from "./chunks/transport.js";
3
+ import { A as isRequestSourceClientId, B as isUuidLike, D as COHUB_SOURCE_HEADER_NAMES, E as COHUB_SOURCE_HEADER, F as parseRequestSourceFromHeaders, I as readRequestSourceFromEnv, L as requestSourceToHeaders, M as isRequestSourceUuid, N as mergeRequestSourceIntoMeta, O as REQUEST_SOURCE_VIA_MAX_LENGTH, P as normalizeRequestSource, R as resolveRequestSourceChannel, V as isUuidOrShortUuid, a as isBillingAccessBlockedError, c as HttpError, d as matchesUnauthorizedErrorToken, f as sanitizeAccessToken, i as isBillingAccessBlockedCode, j as isRequestSourceEmpty, k as hasRequestSourceIdentity, l as HttpTransport, n as FEATURE_NOT_ENTITLED_ERROR_CODE, o as isFeatureNotEntitledError, r as extractBillingPayload, s as isHttpErrorCode, t as BILLING_ACCESS_BLOCKED_ERROR_CODE, u as joinApiUrl, z as isUuid } from "./chunks/http-error.js";
4
4
  import { a as normalizeWebsocketUrl, c as resolveExecutionAppId, d as resolveWebBaseUrl, f as resolveWebsocketUrl, g as scopeListHasPermission, h as isUserLevelPermission, i as normalizeVoiceInputWebsocketUrl, l as resolveExecutionToken, m as USER_LEVEL_PERMISSIONS, n as getCohubContext, o as resolveApiBaseUrl, p as PERMISSIONS, r as normalizeBaseUrl, s as resolveCohubEnvironment, t as COHUB_ENVIRONMENTS, u as resolveVoiceInputWebsocketUrl } from "./chunks/environment.js";
5
- import { a as extractBillingPayload, c as isFeatureNotEntitledError, i as FEATURE_NOT_ENTITLED_ERROR_CODE, l as isHttpErrorCode, n as createWebsocketClient, o as isBillingAccessBlockedCode, r as BILLING_ACCESS_BLOCKED_ERROR_CODE, s as isBillingAccessBlockedError, t as WebsocketClient } from "./chunks/websocket.js";
5
+ import { WebsocketClient, createWebsocketClient } from "./websocket.js";
6
6
  import { VoiceApi, VoiceInputClient, createVoiceInputClient } from "./voice-input.js";
7
7
  import { filterSpacePickerItems, normalizeSpacePickerQuery, orderSpacePickerItems, selectSpacePickerItems } from "./space-picker.js";
8
8
  import { z } from "zod";