@anuma/sdk 10.5.4 → 10.6.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.
@@ -23655,16 +23655,34 @@ async function resumeStream(options) {
23655
23655
  onData,
23656
23656
  onThinking,
23657
23657
  onFinish,
23658
- onError
23658
+ onError,
23659
+ piiRedactor
23659
23660
  } = options;
23660
23661
  const strategy = getStrategy(handle.apiType);
23661
23662
  const accumulator = createStreamAccumulator(handle.model || void 0);
23663
+ const contentDeAnon = piiRedactor && onData ? createStreamingDeAnonymizer(piiRedactor, onData) : null;
23664
+ const thinkingDeAnon = piiRedactor && onThinking ? createStreamingDeAnonymizer(piiRedactor, onThinking) : null;
23662
23665
  const contentSmoother = new StreamSmoother((text12) => {
23663
- if (onData) onData(text12);
23666
+ if (contentDeAnon) contentDeAnon.push(text12);
23667
+ else if (onData) onData(text12);
23664
23668
  }, smoothing);
23665
23669
  const thinkingSmoother = new StreamSmoother((text12) => {
23666
- if (onThinking) onThinking(text12);
23670
+ if (thinkingDeAnon) thinkingDeAnon.push(text12);
23671
+ else if (onThinking) onThinking(text12);
23667
23672
  }, smoothing);
23673
+ const flushOutput = () => {
23674
+ contentSmoother.flush();
23675
+ thinkingSmoother.flush();
23676
+ contentDeAnon?.flush();
23677
+ thinkingDeAnon?.flush();
23678
+ };
23679
+ const buildFinal = () => strategy.buildFinalResponse(
23680
+ piiRedactor ? {
23681
+ ...accumulator,
23682
+ content: piiRedactor.deAnonymize(accumulator.content),
23683
+ thinking: piiRedactor.deAnonymize(accumulator.thinking)
23684
+ } : accumulator
23685
+ );
23668
23686
  const idleController = new AbortController();
23669
23687
  let watchdog;
23670
23688
  let idleFired = false;
@@ -23709,9 +23727,8 @@ async function resumeStream(options) {
23709
23727
  if (signal) signal.removeEventListener("abort", onCallerAbort);
23710
23728
  };
23711
23729
  const buildInterrupted = (message) => {
23712
- contentSmoother.flush();
23713
- thinkingSmoother.flush();
23714
- const data = accumulator.toolCalls.size > 0 ? stripToolCalls(strategy.buildFinalResponse(accumulator)) : strategy.buildFinalResponse(accumulator);
23730
+ flushOutput();
23731
+ const data = accumulator.toolCalls.size > 0 ? stripToolCalls(buildFinal()) : buildFinal();
23715
23732
  return { data, error: message, interrupted: true };
23716
23733
  };
23717
23734
  if (combinedSignal.aborted) {
@@ -23759,18 +23776,16 @@ async function resumeStream(options) {
23759
23776
  const err = replayErr instanceof Error ? replayErr : new Error(String(replayErr));
23760
23777
  const statusCode = parseSseStatusCode(err);
23761
23778
  if (statusCode === 410) {
23762
- contentSmoother.flush();
23763
- thinkingSmoother.flush();
23779
+ flushOutput();
23764
23780
  throw new StreamExpiredError(handle.inferenceId);
23765
23781
  }
23766
23782
  if (err.name === "AbortError" || combinedSignal.aborted) {
23767
23783
  return buildInterrupted(abortMessage());
23768
23784
  }
23769
- contentSmoother.flush();
23770
- thinkingSmoother.flush();
23785
+ flushOutput();
23771
23786
  if (onError) onError(err);
23772
23787
  return {
23773
- data: strategy.buildFinalResponse(accumulator),
23788
+ data: buildFinal(),
23774
23789
  error: err.message,
23775
23790
  interrupted: false,
23776
23791
  statusCode
@@ -23786,7 +23801,9 @@ async function resumeStream(options) {
23786
23801
  draining = true;
23787
23802
  await Promise.all([contentSmoother.drain(), thinkingSmoother.drain()]);
23788
23803
  if (playbackAborted) return buildInterrupted(abortMessage());
23789
- const response = strategy.buildFinalResponse(accumulator);
23804
+ contentDeAnon?.flush();
23805
+ thinkingDeAnon?.flush();
23806
+ const response = buildFinal();
23790
23807
  const deliveredOutput = emittedOutput || (accumulator.toolCallEvents?.length ?? 0) > 0;
23791
23808
  if (onFinish && deliveredOutput) onFinish(response);
23792
23809
  return { data: response, error: null, interrupted: false, empty: !deliveredOutput };
@@ -28228,6 +28245,52 @@ async function getDecayCandidatesRawOp(ctx) {
28228
28245
  trustTier: raw.trust_tier ?? null
28229
28246
  }));
28230
28247
  }
28248
+ async function applyDecayTransitionsOp(ctx, candidates, opts) {
28249
+ assertVaultScopeForSweep(ctx);
28250
+ const byId = new Map(candidates.map((candidate) => [candidate.uniqueId, candidate]));
28251
+ const ids = Array.from(byId.keys());
28252
+ const changed = /* @__PURE__ */ new Set();
28253
+ const CHUNK = 500;
28254
+ for (let i = 0; i < ids.length; i += CHUNK) {
28255
+ let applied = [];
28256
+ try {
28257
+ await ctx.database.write(async () => {
28258
+ await assertCanWrite2(ctx);
28259
+ const records = await ctx.vaultMemoryCollection.query(
28260
+ import_watermelondb19.Q.where("id", import_watermelondb19.Q.oneOf(ids.slice(i, i + CHUNK))),
28261
+ ...ctx.userId !== void 0 ? [import_watermelondb19.Q.where("user_id", ctx.userId)] : []
28262
+ ).fetch();
28263
+ const eligible = records.filter((record) => {
28264
+ if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return false;
28265
+ if (opts.transition === "delete") {
28266
+ return record.archivedAt !== null && opts.now - record.archivedAt > opts.hardDeleteWindowMs;
28267
+ }
28268
+ const candidate = byId.get(record.id);
28269
+ return record.archivedAt === null && record.updatedAt.getTime() === candidate.updatedAt && (record.lastObservedAt ?? null) === (candidate.lastObservedAt ?? null);
28270
+ });
28271
+ const prepared = eligible.map(
28272
+ (record) => record.prepareUpdate((row) => {
28273
+ if (opts.transition === "archive") row._setRaw("archived_at", opts.now);
28274
+ else row._setRaw("is_deleted", true);
28275
+ })
28276
+ );
28277
+ if (prepared.length > 0) await ctx.database.batch(prepared);
28278
+ applied = eligible.map((record) => record.id);
28279
+ });
28280
+ } catch {
28281
+ continue;
28282
+ }
28283
+ for (const id of applied) changed.add(id);
28284
+ if (opts.transition === "delete" && ctx.entityCtx) {
28285
+ try {
28286
+ await unlinkMemoryEntitiesOp(ctx.entityCtx, applied);
28287
+ } catch {
28288
+ continue;
28289
+ }
28290
+ }
28291
+ }
28292
+ return changed;
28293
+ }
28231
28294
  async function archiveVaultMemoryOp(ctx, id, opts) {
28232
28295
  try {
28233
28296
  const record = await ctx.vaultMemoryCollection.find(id);
@@ -32965,25 +33028,8 @@ function isBorderline(input) {
32965
33028
  function vaultDecayBackend(vaultCtx) {
32966
33029
  return {
32967
33030
  candidates: () => getDecayCandidatesRawOp(vaultCtx),
32968
- archive: async (rows, now) => {
32969
- const archived = /* @__PURE__ */ new Set();
32970
- for (const c of rows) {
32971
- const ok = await archiveVaultMemoryOp(vaultCtx, c.uniqueId, {
32972
- now,
32973
- expectedUpdatedAt: c.updatedAt,
32974
- expectedLastObservedAt: c.lastObservedAt ?? null
32975
- });
32976
- if (ok) archived.add(c.uniqueId);
32977
- }
32978
- return archived;
32979
- },
32980
- hardDelete: async (rows, deleteOptions) => {
32981
- const deleted = /* @__PURE__ */ new Set();
32982
- for (const c of rows) {
32983
- if (await hardDeleteDecayedOp(vaultCtx, c.uniqueId, deleteOptions)) deleted.add(c.uniqueId);
32984
- }
32985
- return deleted;
32986
- }
33031
+ archive: (rows, now) => applyDecayTransitionsOp(vaultCtx, rows, { transition: "archive", now }),
33032
+ hardDelete: (rows, deleteOptions) => applyDecayTransitionsOp(vaultCtx, rows, { transition: "delete", ...deleteOptions })
32987
33033
  };
32988
33034
  }
32989
33035
  function createDecaySweeper(options) {
@@ -34996,6 +35042,7 @@ function createLocalMemoryStore(options) {
34996
35042
  "trust_tier",
34997
35043
  "superseded_by",
34998
35044
  "visibility",
35045
+ "twin_opt_in",
34999
35046
  "published_at",
35000
35047
  "geohash",
35001
35048
  "topics",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "10.5.4",
3
+ "version": "10.6.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",