@maximem/synap-js-sdk 0.7.0 → 0.7.2

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/dist/index.d.cts CHANGED
@@ -272,7 +272,16 @@ declare class ScopeAddress {
272
272
  customer_id?: string | null;
273
273
  scope_path?: Record<string, string> | null;
274
274
  });
275
- /** Options for reads (`fetch`, `*.context.fetch`, `send_message`, ...): the path is `scope_path`. */
275
+ /**
276
+ * Options for reads: `fetch`, `send_message`, `record_message`,
277
+ * `user.context.fetch`, `conversation.context.fetch` and
278
+ * `client.context.fetch`. The path is `scope_path`.
279
+ *
280
+ * Not for `customer.context.fetch`: that route refuses a path that names the
281
+ * identity rung (HTTP 400, it reads shared material only) and takes no
282
+ * `user_id`. Call `client.fetch(addr.read_kwargs())`, which sends the
283
+ * customer route the path cut above the identity rung.
284
+ */
276
285
  read_kwargs(): {
277
286
  user_id?: string;
278
287
  customer_id?: string;
@@ -447,6 +456,8 @@ declare class HttpTransport {
447
456
  * observed here.
448
457
  */
449
458
  invalidateScopeLadder(): void;
459
+ /** The ladder already held, or null when none has been read. Makes no request. */
460
+ cachedScopeLadder(): ScopeLadder | null;
450
461
  /**
451
462
  * The account's ladder, from whoami, cached for 300 s (`null` included).
452
463
  * Concurrent callers share one read. A failed re-read after expiry keeps the
@@ -1881,6 +1892,9 @@ interface AsToolOptions {
1881
1892
  /**
1882
1893
  * Closed-over rung for an account with a deeper ladder. Never part of the
1883
1894
  * schema the LLM sees, so the model cannot change it. Forwarded only when set.
1895
+ * With `scope: 'unified'` the customer fetch gets it cut above the identity
1896
+ * rung, as in `fetch`. With `scope: 'customer'` it goes as given, and the
1897
+ * server refuses (HTTP 400) a path that names the identity rung.
1884
1898
  */
1885
1899
  scope_path?: Record<string, string> | null;
1886
1900
  }
@@ -2105,8 +2119,23 @@ interface UnifiedFetchOptions {
2105
2119
  /**
2106
2120
  * The rung to read at, one entry per level from the first, for an account
2107
2121
  * with a deeper ladder (see `get_scope_ladder` and `ScopeLadder.address`).
2108
- * Forwarded to every scope fetch that runs, and only when set. Send ids as
2109
- * well. Not needed on a default ladder.
2122
+ * Only when set. Send ids as well. Not needed on a default ladder. The user
2123
+ * and conversation fetches get the path as given. The client fetch gets no
2124
+ * path. The client read is meant to return the account-wide shared memory,
2125
+ * and the user and customer reads already cover the person's and the team's
2126
+ * own levels. The server does apply a path on that route (it narrows the read
2127
+ * to that chain's own nodes), so sending one would narrow the shared read,
2128
+ * duplicate results the other reads return, and create registry nodes on a
2129
+ * read; it is also validated strictly (HTTP 400 if it is invalid or nested
2130
+ * scoping is off). SDK 0.7.0 sent it. The customer fetch
2131
+ * reads shared material only and the server refuses (HTTP 400) a path that
2132
+ * names the identity rung, so it gets the path with the identity level and
2133
+ * every level below it removed. The identity level is found by its role on
2134
+ * the account's ladder, which `fetch` reads first when a path is set and the
2135
+ * customer scope runs (one shared read, cached 300 s; no request when it is
2136
+ * cached, and none for a call without a path). If that read fails, a warning
2137
+ * is logged and only the reserved key `user` is removed. A path with no
2138
+ * identity level goes to the user, conversation and customer fetches as given.
2110
2139
  */
2111
2140
  scope_path?: Record<string, string> | null;
2112
2141
  }
@@ -2311,7 +2340,7 @@ declare class SynapClient {
2311
2340
  * build when the two disagree, which is the only thing that makes a manual
2312
2341
  * publish safe.
2313
2342
  */
2314
- declare const SDK_VERSION = "0.7.0";
2343
+ declare const SDK_VERSION = "0.7.2";
2315
2344
 
2316
2345
  /**
2317
2346
  * `response_shape: "ranked"`: one list in the order the server ranked it.
package/dist/index.d.ts CHANGED
@@ -272,7 +272,16 @@ declare class ScopeAddress {
272
272
  customer_id?: string | null;
273
273
  scope_path?: Record<string, string> | null;
274
274
  });
275
- /** Options for reads (`fetch`, `*.context.fetch`, `send_message`, ...): the path is `scope_path`. */
275
+ /**
276
+ * Options for reads: `fetch`, `send_message`, `record_message`,
277
+ * `user.context.fetch`, `conversation.context.fetch` and
278
+ * `client.context.fetch`. The path is `scope_path`.
279
+ *
280
+ * Not for `customer.context.fetch`: that route refuses a path that names the
281
+ * identity rung (HTTP 400, it reads shared material only) and takes no
282
+ * `user_id`. Call `client.fetch(addr.read_kwargs())`, which sends the
283
+ * customer route the path cut above the identity rung.
284
+ */
276
285
  read_kwargs(): {
277
286
  user_id?: string;
278
287
  customer_id?: string;
@@ -447,6 +456,8 @@ declare class HttpTransport {
447
456
  * observed here.
448
457
  */
449
458
  invalidateScopeLadder(): void;
459
+ /** The ladder already held, or null when none has been read. Makes no request. */
460
+ cachedScopeLadder(): ScopeLadder | null;
450
461
  /**
451
462
  * The account's ladder, from whoami, cached for 300 s (`null` included).
452
463
  * Concurrent callers share one read. A failed re-read after expiry keeps the
@@ -1881,6 +1892,9 @@ interface AsToolOptions {
1881
1892
  /**
1882
1893
  * Closed-over rung for an account with a deeper ladder. Never part of the
1883
1894
  * schema the LLM sees, so the model cannot change it. Forwarded only when set.
1895
+ * With `scope: 'unified'` the customer fetch gets it cut above the identity
1896
+ * rung, as in `fetch`. With `scope: 'customer'` it goes as given, and the
1897
+ * server refuses (HTTP 400) a path that names the identity rung.
1884
1898
  */
1885
1899
  scope_path?: Record<string, string> | null;
1886
1900
  }
@@ -2105,8 +2119,23 @@ interface UnifiedFetchOptions {
2105
2119
  /**
2106
2120
  * The rung to read at, one entry per level from the first, for an account
2107
2121
  * with a deeper ladder (see `get_scope_ladder` and `ScopeLadder.address`).
2108
- * Forwarded to every scope fetch that runs, and only when set. Send ids as
2109
- * well. Not needed on a default ladder.
2122
+ * Only when set. Send ids as well. Not needed on a default ladder. The user
2123
+ * and conversation fetches get the path as given. The client fetch gets no
2124
+ * path. The client read is meant to return the account-wide shared memory,
2125
+ * and the user and customer reads already cover the person's and the team's
2126
+ * own levels. The server does apply a path on that route (it narrows the read
2127
+ * to that chain's own nodes), so sending one would narrow the shared read,
2128
+ * duplicate results the other reads return, and create registry nodes on a
2129
+ * read; it is also validated strictly (HTTP 400 if it is invalid or nested
2130
+ * scoping is off). SDK 0.7.0 sent it. The customer fetch
2131
+ * reads shared material only and the server refuses (HTTP 400) a path that
2132
+ * names the identity rung, so it gets the path with the identity level and
2133
+ * every level below it removed. The identity level is found by its role on
2134
+ * the account's ladder, which `fetch` reads first when a path is set and the
2135
+ * customer scope runs (one shared read, cached 300 s; no request when it is
2136
+ * cached, and none for a call without a path). If that read fails, a warning
2137
+ * is logged and only the reserved key `user` is removed. A path with no
2138
+ * identity level goes to the user, conversation and customer fetches as given.
2110
2139
  */
2111
2140
  scope_path?: Record<string, string> | null;
2112
2141
  }
@@ -2311,7 +2340,7 @@ declare class SynapClient {
2311
2340
  * build when the two disagree, which is the only thing that makes a manual
2312
2341
  * publish safe.
2313
2342
  */
2314
- declare const SDK_VERSION = "0.7.0";
2343
+ declare const SDK_VERSION = "0.7.2";
2315
2344
 
2316
2345
  /**
2317
2346
  * `response_shape: "ranked"`: one list in the order the server ranked it.
package/dist/index.js CHANGED
@@ -6,10 +6,11 @@ import {
6
6
  HISTORY_SEARCH,
7
7
  SEMANTIC_MATCH,
8
8
  THRESHOLDS,
9
+ normalizeConversationId,
9
10
  rungKey,
10
11
  stem,
11
12
  tokenize
12
- } from "./chunk-CSG3N5E3.js";
13
+ } from "./chunk-W6AH4CPC.js";
13
14
  import {
14
15
  getEnv
15
16
  } from "./chunk-QBCVMPGK.js";
@@ -232,7 +233,16 @@ var ScopeAddress = class {
232
233
  this.customer_id = init.customer_id ?? null;
233
234
  this.scope_path = init.scope_path ?? null;
234
235
  }
235
- /** Options for reads (`fetch`, `*.context.fetch`, `send_message`, ...): the path is `scope_path`. */
236
+ /**
237
+ * Options for reads: `fetch`, `send_message`, `record_message`,
238
+ * `user.context.fetch`, `conversation.context.fetch` and
239
+ * `client.context.fetch`. The path is `scope_path`.
240
+ *
241
+ * Not for `customer.context.fetch`: that route refuses a path that names the
242
+ * identity rung (HTTP 400, it reads shared material only) and takes no
243
+ * `user_id`. Call `client.fetch(addr.read_kwargs())`, which sends the
244
+ * customer route the path cut above the identity rung.
245
+ */
236
246
  read_kwargs() {
237
247
  const out = {};
238
248
  if (this.user_id) out.user_id = this.user_id;
@@ -253,6 +263,21 @@ var ScopeAddress = class {
253
263
  return out;
254
264
  }
255
265
  };
266
+ var RESERVED_IDENTITY_KEY = "user";
267
+ function pathAboveIdentity(scopePath, ladder) {
268
+ if (!scopePath || Object.keys(scopePath).length === 0) return void 0;
269
+ const identity = ladder?.levels.find((lv) => lv.role === ROLE_IDENTITY);
270
+ const out = {};
271
+ if (!ladder || !identity) {
272
+ for (const [k, v] of Object.entries(scopePath)) if (k !== RESERVED_IDENTITY_KEY) out[k] = v;
273
+ } else {
274
+ const position = new Map(ladder.levels.map((lv) => [lv.key, lv.position]));
275
+ for (const [k, v] of Object.entries(scopePath)) {
276
+ if ((position.get(k) ?? -1) < identity.position) out[k] = v;
277
+ }
278
+ }
279
+ return Object.keys(out).length > 0 ? out : void 0;
280
+ }
256
281
  var REFRESH_HINT = "The account's ladder may not be accepted yet, or nested scoping may be off for this instance. If that changed recently, `await sdk.get_scope_ladder({ refresh: true })` re-reads it.";
257
282
  var ScopeLadder = class {
258
283
  levels;
@@ -560,6 +585,10 @@ var HttpTransport = class {
560
585
  this.#ladderInvalidated = true;
561
586
  this.#ladderRetryAt = 0;
562
587
  }
588
+ /** The ladder already held, or null when none has been read. Makes no request. */
589
+ cachedScopeLadder() {
590
+ return this.#ladderLoaded ? this.#ladder : null;
591
+ }
563
592
  /**
564
593
  * The account's ladder, from whoami, cached for 300 s (`null` included).
565
594
  * Concurrent callers share one read. A failed re-read after expiry keeps the
@@ -2311,6 +2340,7 @@ function buildCompactBody(options) {
2311
2340
  var CompactionSubscribers = class {
2312
2341
  #byConversation = /* @__PURE__ */ new Map();
2313
2342
  add(conversationId, callback) {
2343
+ conversationId = normalizeConversationId(conversationId);
2314
2344
  const list = this.#byConversation.get(conversationId);
2315
2345
  if (list === void 0) this.#byConversation.set(conversationId, [callback]);
2316
2346
  else list.push(callback);
@@ -2326,6 +2356,7 @@ var CompactionSubscribers = class {
2326
2356
  };
2327
2357
  }
2328
2358
  removeAll(conversationId) {
2359
+ if (conversationId !== void 0) conversationId = normalizeConversationId(conversationId);
2329
2360
  if (conversationId === void 0) {
2330
2361
  let count = 0;
2331
2362
  for (const list2 of this.#byConversation.values()) count += list2.length;
@@ -2339,6 +2370,7 @@ var CompactionSubscribers = class {
2339
2370
  }
2340
2371
  /** Fires subscribers in registration order. A throwing listener must not break the stream reader. */
2341
2372
  dispatch(conversationId, bundle, onError) {
2373
+ conversationId = normalizeConversationId(conversationId);
2342
2374
  for (const callback of [...this.#byConversation.get(conversationId) ?? []]) {
2343
2375
  try {
2344
2376
  const result = callback(bundle);
@@ -2966,9 +2998,18 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
2966
2998
  return client !== null && client.isConnected;
2967
2999
  }
2968
3000
  };
3001
+ function openSessionKey(conversationId) {
3002
+ if (!conversationId) return void 0;
3003
+ if (openSessions.has(conversationId)) return conversationId;
3004
+ const wanted = normalizeConversationId(conversationId);
3005
+ for (const key of openSessions.keys()) {
3006
+ if (normalizeConversationId(key) === wanted) return key;
3007
+ }
3008
+ return void 0;
3009
+ }
2969
3010
  function ensureSession(conversationId, userId, customerId) {
2970
3011
  if (!conversationId || !userId || client === null) return;
2971
- if (openSessions.has(conversationId)) return;
3012
+ if (openSessionKey(conversationId) !== void 0) return;
2972
3013
  const sessionId = newCorrelationId();
2973
3014
  try {
2974
3015
  client.sendSessionControl({
@@ -3062,9 +3103,10 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3062
3103
  await active.disconnect();
3063
3104
  },
3064
3105
  async end_session(conversationId) {
3065
- const sessionId = openSessions.get(conversationId);
3066
- if (sessionId === void 0 || client === null) return;
3067
- openSessions.delete(conversationId);
3106
+ const openedAs = openSessionKey(conversationId);
3107
+ const sessionId = openedAs === void 0 ? void 0 : openSessions.get(openedAs);
3108
+ if (openedAs === void 0 || sessionId === void 0 || client === null) return;
3109
+ openSessions.delete(openedAs);
3068
3110
  try {
3069
3111
  client.sendSessionControl({
3070
3112
  action: "end",
@@ -3114,7 +3156,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3114
3156
  conversation_id: options.conversation_id ?? options.conversationId ?? "",
3115
3157
  user_id: options.user_id ?? options.userId ?? "",
3116
3158
  customer_id: options.customer_id ?? options.customerId ?? "",
3117
- session_id: options.session_id ?? options.sessionId ?? openSessions.get(conversationId) ?? "",
3159
+ session_id: options.session_id ?? options.sessionId ?? openSessions.get(openSessionKey(conversationId) ?? "") ?? "",
3118
3160
  metadata: withAgentModel(metadata, agentModelOf(options), agentModel(), true) ?? {},
3119
3161
  timestamp_ms: Date.now(),
3120
3162
  tool_name: options.tool_name ?? options.toolName ?? "",
@@ -3227,7 +3269,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
3227
3269
  }
3228
3270
 
3229
3271
  // src/version.ts
3230
- var SDK_VERSION = "0.7.0";
3272
+ var SDK_VERSION = "0.7.2";
3231
3273
 
3232
3274
  // src/registry.ts
3233
3275
  var instances = /* @__PURE__ */ new Map();
@@ -3335,6 +3377,7 @@ var ShortTermStore = class {
3335
3377
  /** The entry, or null. Age-evicts on read, as Python does. */
3336
3378
  get(conversationId) {
3337
3379
  if (!conversationId) return null;
3380
+ conversationId = normalizeConversationId(conversationId);
3338
3381
  const entry = this.#entries.get(conversationId);
3339
3382
  if (entry === void 0) return null;
3340
3383
  if (this.#now() - entry.lastActivityAt > this.#maxAgeMs) {
@@ -3363,6 +3406,7 @@ var ShortTermStore = class {
3363
3406
  */
3364
3407
  appendTurn(conversationId, role, content, timestamp, confirmation = {}) {
3365
3408
  if (!conversationId) return;
3409
+ conversationId = normalizeConversationId(conversationId);
3366
3410
  const stamp = timestamp ?? new Date(this.#now()).toISOString();
3367
3411
  if (this.#archive !== null) {
3368
3412
  try {
@@ -3396,6 +3440,7 @@ var ShortTermStore = class {
3396
3440
  */
3397
3441
  noteServerCount(conversationId, count) {
3398
3442
  if (!conversationId) return;
3443
+ conversationId = normalizeConversationId(conversationId);
3399
3444
  const entry = this.#entries.get(conversationId);
3400
3445
  if (entry !== void 0) this.#noteCount(entry, Number(count), 0);
3401
3446
  }
@@ -3443,10 +3488,11 @@ var ShortTermStore = class {
3443
3488
  applyCompaction(bundle) {
3444
3489
  if (typeof bundle !== "object" || bundle === null) return;
3445
3490
  const cc = bundle["conversation_context"] ?? {};
3446
- const conversationId = String(
3491
+ const rawConversationId = String(
3447
3492
  cc["conversation_id"] ?? bundle["anticipation_conversation_id"] ?? bundle["conversation_id"] ?? ""
3448
3493
  );
3449
- if (!conversationId) return;
3494
+ if (!rawConversationId) return;
3495
+ const conversationId = normalizeConversationId(rawConversationId);
3450
3496
  const endTs = parseIso(cc["end_timestamp"] ?? cc["compacted_at"]);
3451
3497
  const compactedAt = parseIso(cc["compacted_at"]);
3452
3498
  const compactedCount = Number(cc["compacted_message_count"] ?? 0) || 0;
@@ -3511,6 +3557,7 @@ var ShortTermStore = class {
3511
3557
  */
3512
3558
  reseed(conversationId, state) {
3513
3559
  if (!conversationId) return;
3560
+ conversationId = normalizeConversationId(conversationId);
3514
3561
  const entry = this.#entries.get(conversationId);
3515
3562
  if (entry === void 0 || entry.shared) return;
3516
3563
  entry.serverMessageCount = Math.max(
@@ -3527,7 +3574,7 @@ var ShortTermStore = class {
3527
3574
  entry.synced = true;
3528
3575
  }
3529
3576
  invalidate(conversationId) {
3530
- this.#entries.delete(conversationId);
3577
+ this.#entries.delete(normalizeConversationId(conversationId));
3531
3578
  }
3532
3579
  clear() {
3533
3580
  this.#entries.clear();
@@ -4328,7 +4375,7 @@ var TurnCounter = class {
4328
4375
  #counts = /* @__PURE__ */ new Map();
4329
4376
  /** Increment and return the new count. Python buckets a missing id under `_global`. */
4330
4377
  increment(conversationId) {
4331
- const key = conversationId !== void 0 && conversationId !== "" ? conversationId : "_global";
4378
+ const key = conversationId !== void 0 && conversationId !== "" ? normalizeConversationId(conversationId) : "_global";
4332
4379
  const next = (this.#counts.get(key) ?? 0) + 1;
4333
4380
  this.#counts.set(key, next);
4334
4381
  return next;
@@ -4341,7 +4388,7 @@ var TurnCounter = class {
4341
4388
  * triggered a fresh retrieval anyway.
4342
4389
  */
4343
4390
  shouldInject(conversationId) {
4344
- const key = conversationId !== void 0 && conversationId !== "" ? conversationId : "_global";
4391
+ const key = conversationId !== void 0 && conversationId !== "" ? normalizeConversationId(conversationId) : "_global";
4345
4392
  const count = this.#counts.get(key) ?? 0;
4346
4393
  return count > 0 && count % USER_SUMMARY_INTERVAL === 0;
4347
4394
  }
@@ -5188,7 +5235,7 @@ var SynapClient = class _SynapClient {
5188
5235
  if (scope === "conversation") {
5189
5236
  if (conversationId) {
5190
5237
  this.#shortTerm.invalidate(conversationId);
5191
- this.#turnStore.drop(conversationId);
5238
+ this.#turnStore.drop(normalizeConversationId(conversationId));
5192
5239
  cleared.push("short_term_context", "turns");
5193
5240
  }
5194
5241
  } else {
@@ -5499,6 +5546,19 @@ var SynapClient = class _SynapClient {
5499
5546
  // one hands every scope fetch exactly the options it always got.
5500
5547
  ...scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0 ? { scope_path: scopePath } : {}
5501
5548
  };
5549
+ const { scope_path: _fullPath, ...sharedNoPath } = shared;
5550
+ void _fullPath;
5551
+ let customerPath;
5552
+ if (scopePath && Object.keys(scopePath).length > 0 && customerId !== void 0 && customerId !== null && customerId !== "" && wants("customer")) {
5553
+ let ladder = null;
5554
+ try {
5555
+ ladder = await this.get_scope_ladder();
5556
+ } catch (e) {
5557
+ this.#warn(`Could not read the scope ladder (${e instanceof Error ? e.message : String(e)}); cutting the customer scope's path at the reserved key 'user'.`);
5558
+ }
5559
+ customerPath = pathAboveIdentity(scopePath, ladder);
5560
+ }
5561
+ const customerShared = customerPath ? { ...sharedNoPath, scope_path: customerPath } : sharedNoPath;
5502
5562
  const labels = [];
5503
5563
  const tasks = [];
5504
5564
  const present = (v) => v !== void 0 && v !== null && v !== "";
@@ -5530,14 +5590,14 @@ var SynapClient = class _SynapClient {
5530
5590
  tasks.push(this.customer.context.fetch({
5531
5591
  customer_id: customerId,
5532
5592
  conversation_id: conversationId,
5533
- ...shared
5593
+ ...customerShared
5534
5594
  }));
5535
5595
  }
5536
5596
  if (scopes !== void 0 && scopes.includes("client")) {
5537
5597
  labels.push("client");
5538
5598
  tasks.push(this.client.context.fetch({
5539
5599
  conversation_id: conversationId,
5540
- ...shared
5600
+ ...sharedNoPath
5541
5601
  }));
5542
5602
  }
5543
5603
  if (tasks.length === 0 && !(conversationState && includeConversationContext)) {
@@ -5694,6 +5754,7 @@ var SynapClient = class _SynapClient {
5694
5754
  async #withHistoryExcerpts(conversationId, response, query) {
5695
5755
  const r = response ?? {};
5696
5756
  const store = this.#turnStore;
5757
+ conversationId = normalizeConversationId(conversationId);
5697
5758
  const recent = Array.isArray(r["recent_messages"]) ? r["recent_messages"] : [];
5698
5759
  store.addMany(
5699
5760
  conversationId,
@@ -5741,7 +5802,7 @@ var SynapClient = class _SynapClient {
5741
5802
  if (!conversationId || result === null || result === void 0) return;
5742
5803
  try {
5743
5804
  this.#turnStore.add(
5744
- conversationId,
5805
+ normalizeConversationId(conversationId),
5745
5806
  "tool",
5746
5807
  toolResultText(result, options.tool_name ?? options.toolName),
5747
5808
  options.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
@@ -5771,6 +5832,7 @@ var SynapClient = class _SynapClient {
5771
5832
  });
5772
5833
  }
5773
5834
  #maybeBackfillTurns(conversationId, total) {
5835
+ conversationId = normalizeConversationId(conversationId);
5774
5836
  if (total <= this.#turnStore.count(conversationId)) return;
5775
5837
  const now = Date.now();
5776
5838
  if (now < (this.#backfillAfter.get(conversationId) ?? 0)) return;
@@ -5778,6 +5840,7 @@ var SynapClient = class _SynapClient {
5778
5840
  void this.#backfillTurns(conversationId, total);
5779
5841
  }
5780
5842
  async #backfillTurns(conversationId, total) {
5843
+ conversationId = normalizeConversationId(conversationId);
5781
5844
  try {
5782
5845
  let start = 1;
5783
5846
  while (start <= total) {