@silmaril-security/sdk 0.8.1 → 0.9.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.
package/dist/index.js CHANGED
@@ -263,6 +263,10 @@ function record(value) {
263
263
  function validThreadId(value) {
264
264
  return typeof value === "string" && value.trim().length > 0 ? value : void 0;
265
265
  }
266
+ function threadIds(first, second) {
267
+ if (first === void 0) return second === void 0 ? NO_THREAD_IDS : Object.freeze([second]);
268
+ return Object.freeze(second === void 0 || second === first ? [first] : [first, second]);
269
+ }
266
270
  function nativeThreadId(runtime, metadata, inherited, currentConfig) {
267
271
  const explicit = record(record(runtime)?.configurable);
268
272
  const current = record(record(currentConfig)?.configurable);
@@ -278,10 +282,11 @@ function rejectConversationOptions(options) {
278
282
  throw new TypeError("conversationId/conversation_id was removed. Pass the native configurable.thread_id when invoking the agent or runnable instead.");
279
283
  }
280
284
  }
281
- var RunThreadIdentity;
285
+ var NO_THREAD_IDS, RunThreadIdentity;
282
286
  var init_thread_identity = __esm({
283
287
  "src/adapters/thread-identity.ts"() {
284
288
  "use strict";
289
+ NO_THREAD_IDS = Object.freeze([]);
285
290
  RunThreadIdentity = class {
286
291
  constructor(boundIdentity, currentConfig = () => void 0) {
287
292
  this.boundIdentity = boundIdentity;
@@ -297,10 +302,50 @@ var init_thread_identity = __esm({
297
302
  const oldestRoot = [...this.runs].find(([, run]) => run.parentRunId === void 0 || !this.runs.has(run.parentRunId))?.[0] ?? this.runs.keys().next().value;
298
303
  if (oldestRoot !== void 0) discarded.push(...this.finish(oldestRoot));
299
304
  }
300
- const inherited = parentRunId === void 0 ? void 0 : this.runs.get(parentRunId)?.threadId;
305
+ const parent = parentRunId === void 0 ? void 0 : this.runs.get(parentRunId);
306
+ const inherited = parent?.threadId;
301
307
  const exposed = record(metadata);
302
- const threadId = this.boundIdentity && (parentRunId === void 0 || !this.runs.has(parentRunId)) ? this.boundIdentity.threadId : exposed && Object.prototype.hasOwnProperty.call(exposed, "thread_id") ? typeof exposed.langgraph_node === "string" ? nativeThreadId(void 0, exposed, inherited, this.currentConfig()) : validThreadId(exposed.thread_id) : inherited;
303
- this.runs.set(runId, { threadId, parentRunId });
308
+ const hasExposedThread = exposed !== void 0 && Object.prototype.hasOwnProperty.call(exposed, "thread_id");
309
+ const candidate = hasExposedThread ? validThreadId(exposed.thread_id) : void 0;
310
+ let threadId;
311
+ let untrustedThreadIds;
312
+ let graphProven;
313
+ if (this.boundIdentity && parent === void 0) {
314
+ threadId = this.boundIdentity.threadId;
315
+ untrustedThreadIds = threadIds(threadId, candidate);
316
+ graphProven = false;
317
+ } else if (exposed && (typeof exposed.langgraph_node === "string" || typeof exposed.langgraph_step === "number")) {
318
+ threadId = nativeThreadId(void 0, exposed, inherited, this.currentConfig());
319
+ untrustedThreadIds = NO_THREAD_IDS;
320
+ graphProven = true;
321
+ } else if (hasExposedThread) {
322
+ if (candidate === void 0) {
323
+ threadId = void 0;
324
+ untrustedThreadIds = NO_THREAD_IDS;
325
+ graphProven = false;
326
+ } else if (parent?.graphProven && candidate === inherited) {
327
+ threadId = inherited;
328
+ untrustedThreadIds = NO_THREAD_IDS;
329
+ graphProven = true;
330
+ } else if (parent && (candidate === inherited || parent.untrustedThreadIds.includes(candidate))) {
331
+ threadId = void 0;
332
+ untrustedThreadIds = parent.untrustedThreadIds;
333
+ graphProven = false;
334
+ } else {
335
+ threadId = candidate;
336
+ untrustedThreadIds = threadIds(candidate);
337
+ graphProven = false;
338
+ }
339
+ } else if (parent?.graphProven) {
340
+ threadId = inherited;
341
+ untrustedThreadIds = NO_THREAD_IDS;
342
+ graphProven = true;
343
+ } else {
344
+ threadId = void 0;
345
+ untrustedThreadIds = parent?.untrustedThreadIds ?? NO_THREAD_IDS;
346
+ graphProven = false;
347
+ }
348
+ this.runs.set(runId, { threadId, untrustedThreadIds, parentRunId, graphProven });
304
349
  if (parentRunId !== void 0 && parentRunId !== runId) {
305
350
  const children = this.children.get(parentRunId) ?? /* @__PURE__ */ new Set();
306
351
  children.add(runId);
@@ -1178,7 +1223,7 @@ function sanitizeText(text) {
1178
1223
  }
1179
1224
 
1180
1225
  // src/firewall.ts
1181
- var SDK_VERSION = "0.8.1";
1226
+ var SDK_VERSION = "0.9.0";
1182
1227
  var DEFAULT_TIMEOUT_MS = 1e4;
1183
1228
  var DEFAULT_MAX_RETRIES = 5;
1184
1229
  var MAX_BACKOFF_SECONDS = 30;