@anuma/sdk 6.39.2 → 6.40.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.
@@ -19482,6 +19482,93 @@ function composeHooks(hooks) {
19482
19482
  };
19483
19483
  }
19484
19484
 
19485
+ // src/lib/chat/streamIdleTimeout.ts
19486
+ var StreamIdleTimeoutError = class extends Error {
19487
+ constructor(idleTimeoutMs) {
19488
+ super(`Stream timed out after ${idleTimeoutMs} ms without activity.`);
19489
+ this.name = "StreamIdleTimeoutError";
19490
+ this.idleTimeoutMs = idleTimeoutMs;
19491
+ }
19492
+ };
19493
+ function withStreamIdleTimeout(transport, idleTimeoutMs) {
19494
+ if (!(idleTimeoutMs > 0) || idleTimeoutMs === Infinity) return transport;
19495
+ return (options) => ({
19496
+ stream: (async function* () {
19497
+ const controller = new AbortController();
19498
+ let timer;
19499
+ let settled = false;
19500
+ let completed = false;
19501
+ let iterator;
19502
+ let interruption;
19503
+ let rejectPending;
19504
+ const disarm = () => {
19505
+ if (timer !== void 0) clearTimeout(timer);
19506
+ timer = void 0;
19507
+ };
19508
+ const interrupt = (error) => {
19509
+ if (interruption) return;
19510
+ interruption = error;
19511
+ rejectPending?.(error);
19512
+ controller.abort();
19513
+ };
19514
+ const arm = () => {
19515
+ if (settled || controller.signal.aborted) return;
19516
+ disarm();
19517
+ timer = setTimeout(() => {
19518
+ interrupt(new StreamIdleTimeoutError(idleTimeoutMs));
19519
+ }, idleTimeoutMs);
19520
+ };
19521
+ const onAbort = () => {
19522
+ controller.abort();
19523
+ };
19524
+ options.signal?.addEventListener("abort", onAbort, { once: true });
19525
+ try {
19526
+ if (options.signal?.aborted) {
19527
+ const error = new Error("Request aborted");
19528
+ error.name = "AbortError";
19529
+ throw error;
19530
+ }
19531
+ arm();
19532
+ iterator = transport({
19533
+ ...options,
19534
+ signal: controller.signal,
19535
+ onActivity: () => {
19536
+ arm();
19537
+ options.onActivity?.();
19538
+ }
19539
+ }).stream[Symbol.asyncIterator]();
19540
+ while (true) {
19541
+ if (interruption) throw interruption;
19542
+ const next = await new Promise((resolve, reject) => {
19543
+ rejectPending = reject;
19544
+ Promise.resolve(iterator.next()).then(resolve, reject);
19545
+ });
19546
+ rejectPending = void 0;
19547
+ if (next.done) {
19548
+ completed = true;
19549
+ break;
19550
+ }
19551
+ arm();
19552
+ yield next.value;
19553
+ }
19554
+ } finally {
19555
+ settled = true;
19556
+ rejectPending = void 0;
19557
+ disarm();
19558
+ options.signal?.removeEventListener("abort", onAbort);
19559
+ if (!completed) {
19560
+ controller.abort();
19561
+ try {
19562
+ void iterator?.return?.().catch(() => {
19563
+ });
19564
+ } catch {
19565
+ }
19566
+ }
19567
+ }
19568
+ })()
19569
+ });
19570
+ }
19571
+
19485
19572
  // src/lib/chat/useChat/utils.ts
19486
19573
  import { jsonrepair } from "jsonrepair";
19487
19574
  function parseToolArguments(raw) {
@@ -21645,7 +21732,20 @@ var defaultTransport = (options) => {
21645
21732
  } catch {
21646
21733
  }
21647
21734
  }
21648
- return response;
21735
+ if (!response.body || !options.onActivity) return response;
21736
+ const body = response.body.pipeThrough(
21737
+ new TransformStream({
21738
+ transform(chunk, controller) {
21739
+ if (chunk.byteLength > 0) options.onActivity?.();
21740
+ controller.enqueue(chunk);
21741
+ }
21742
+ })
21743
+ );
21744
+ return new Response(body, {
21745
+ status: response.status,
21746
+ statusText: response.statusText,
21747
+ headers: response.headers
21748
+ });
21649
21749
  };
21650
21750
  return createSseClient({
21651
21751
  method: options.method ?? "POST",
@@ -21702,6 +21802,7 @@ async function runToolLoop(options) {
21702
21802
  conversationId,
21703
21803
  smoothing,
21704
21804
  signal,
21805
+ idleTimeoutMs = 12e4,
21705
21806
  resumable,
21706
21807
  detachSignal,
21707
21808
  onStreamMeta,
@@ -21715,13 +21816,14 @@ async function runToolLoop(options) {
21715
21816
  onStepFinish,
21716
21817
  onRequest,
21717
21818
  onStreamRetry,
21718
- transport: makeStreamingRequest = defaultTransport,
21819
+ transport = defaultTransport,
21719
21820
  preProcessors,
21720
21821
  maxConnectorCalls = 2,
21721
21822
  hooks: hooksOption,
21722
21823
  piiRedaction,
21723
21824
  onPiiRedacted
21724
21825
  } = options;
21826
+ const makeStreamingRequest = withStreamIdleTimeout(transport, idleTimeoutMs);
21725
21827
  const hooks = Array.isArray(hooksOption) ? composeHooks(hooksOption) : hooksOption;
21726
21828
  const runId = generateRunId();
21727
21829
  let messages = options.messages;
@@ -33302,6 +33404,14 @@ function createLocalMemoryStore(options) {
33302
33404
  getLogger().warn("[memory/store] Failed to embed memory:", err);
33303
33405
  });
33304
33406
  };
33407
+ const maintenance = {
33408
+ createDecaySweeper: (sweeperOptions) => createDecaySweeper({ ...sweeperOptions, vaultCtx }),
33409
+ getTopicBacklog: (backlogOptions) => getMemoriesNeedingTopicExtractionOp(vaultCtx, backlogOptions),
33410
+ extractTopics: (memoryIds, extractOptions) => extractAndLinkEntitiesForMemoriesOp(vaultCtx, memoryIds, extractOptions),
33411
+ stampTopicsExtracted: (memoryIds, extractedAt, version) => stampTopicsExtractedAtOp(vaultCtx, memoryIds, extractedAt, version),
33412
+ relinkTopics: (memoryIds) => relinkMemoryTopicsOp(vaultCtx, memoryIds),
33413
+ backfillTopics: (memoryIds) => backfillMemoryTopicsOp(vaultCtx, memoryIds)
33414
+ };
33305
33415
  return {
33306
33416
  masksEmbeddingInput: options.embeddingOptions.maskInput !== void 0,
33307
33417
  list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
@@ -33315,21 +33425,22 @@ function createLocalMemoryStore(options) {
33315
33425
  memoriesByTopics: (names) => getMemoriesByEntityNamesOp(entityCtx, names),
33316
33426
  topicsByMemories: (memoryIds) => getEntitiesByMemoryIdsOp(entityCtx, memoryIds),
33317
33427
  listTopics: async () => {
33318
- const links = await entityCtx.memoryEntityCollection.query(...linksOwnedBy).fetch();
33428
+ const links = await entityCtx.memoryEntityCollection.query(...linksOwnedBy).unsafeFetchRaw();
33319
33429
  const members = /* @__PURE__ */ new Map();
33320
33430
  for (const link of links) {
33321
- const entityId = String(link.entityId);
33431
+ const entityId = String(link.entity_id);
33322
33432
  const set = members.get(entityId) ?? /* @__PURE__ */ new Set();
33323
- set.add(String(link.memoryId));
33433
+ set.add(String(link.memory_id));
33324
33434
  members.set(entityId, set);
33325
33435
  }
33326
- const entities = userId === void 0 ? await entityCtx.entityCollection.query().fetch() : members.size ? await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf([...members.keys()]))).fetch() : [];
33436
+ const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
33327
33437
  const byName = /* @__PURE__ */ new Map();
33328
33438
  for (const entity of entities) {
33329
- const count = members.get(entity.id)?.size ?? 0;
33330
- const existing = byName.get(entity.canonicalName);
33331
- byName.set(entity.canonicalName, {
33332
- name: entity.canonicalName,
33439
+ const name = String(entity.canonical_name);
33440
+ const count = members.get(String(entity.id))?.size ?? 0;
33441
+ const existing = byName.get(name);
33442
+ byName.set(name, {
33443
+ name,
33333
33444
  kind: existing?.kind ?? entity.kind ?? null,
33334
33445
  memoryCount: (existing?.memoryCount ?? 0) + count
33335
33446
  });
@@ -33420,14 +33531,8 @@ function createLocalMemoryStore(options) {
33420
33531
  }
33421
33532
  return () => subscriptions.forEach((s) => s.unsubscribe());
33422
33533
  },
33423
- maintenance: {
33424
- createDecaySweeper: (sweeperOptions) => createDecaySweeper({ ...sweeperOptions, vaultCtx }),
33425
- getTopicBacklog: (backlogOptions) => getMemoriesNeedingTopicExtractionOp(vaultCtx, backlogOptions),
33426
- extractTopics: (memoryIds, extractOptions) => extractAndLinkEntitiesForMemoriesOp(vaultCtx, memoryIds, extractOptions),
33427
- stampTopicsExtracted: (memoryIds, extractedAt, version) => stampTopicsExtractedAtOp(vaultCtx, memoryIds, extractedAt, version),
33428
- relinkTopics: (memoryIds) => relinkMemoryTopicsOp(vaultCtx, memoryIds),
33429
- backfillTopics: (memoryIds) => backfillMemoryTopicsOp(vaultCtx, memoryIds)
33430
- }
33534
+ maintenance,
33535
+ topicMaintenance: maintenance
33431
33536
  };
33432
33537
  }
33433
33538
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "6.39.2",
3
+ "version": "6.40.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",