@anuma/sdk 6.30.2 → 6.31.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.
@@ -32,6 +32,21 @@ type ToolConfig = LlmapiChatCompletionTool & {
32
32
  * execution fails, allowing the model to retry.
33
33
  */
34
34
  removeAfterExecution?: boolean;
35
+ /**
36
+ * Remove this tool for the rest of the turn once ANY tool returns a
37
+ * successful result this predicate accepts — its own or another's. Errors
38
+ * never count, as for `removeAfterExecution`.
39
+ *
40
+ * Only results of tools executed on this client are offered; tools the
41
+ * portal runs server-side never reach the predicate. A predicate that throws
42
+ * is treated as not matching.
43
+ *
44
+ * For a family of tools that has to leave together: when one of them
45
+ * declines an out-of-scope request, the model otherwise works through its
46
+ * siblings round after round until the round cap. Give every member the same
47
+ * predicate and the first refusal removes the whole family.
48
+ */
49
+ removeAfterResult?: (result: unknown) => boolean;
35
50
  /**
36
51
  * Timeout in milliseconds for this tool's executor.
37
52
  * Overrides the default 30-second timeout.
@@ -831,6 +846,9 @@ declare function computeToolGuidance(selectedServerTools: ServerTool[], selected
831
846
  * definitions that eat up the context window.
832
847
  *
833
848
  * @returns Filtered client tools, or the original array if filtering fails/skips.
849
+ * `activatedSetNames` is every set that activated, forced ones included.
850
+ * `matchedSetNames` is only the sets whose anchors cleared their floor on THIS
851
+ * prompt, ignoring `activeToolSets`; it is empty whenever no scoring ran.
834
852
  */
835
853
  declare function autoFilterClientTools(clientTools: LlmapiChatCompletionTool[], promptEmbeddings: number[] | number[][] | null, cache: Map<string, number[]>, embeddingOptions: {
836
854
  getToken?: () => Promise<string | null>;
@@ -847,6 +865,7 @@ declare function autoFilterClientTools(clientTools: LlmapiChatCompletionTool[],
847
865
  noEmbeddingsReason?: "short-prompt" | "error"): Promise<{
848
866
  tools: LlmapiChatCompletionTool[];
849
867
  activatedSetNames?: ReadonlySet<string>;
868
+ matchedSetNames: ReadonlySet<string>;
850
869
  }>;
851
870
 
852
871
  /**
@@ -1148,9 +1148,25 @@ var consoleLogger = {
1148
1148
  warn: console.warn.bind(console),
1149
1149
  error: console.error.bind(console)
1150
1150
  };
1151
- var currentLogger = consoleLogger;
1151
+ var LOGGER_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/logger/v1");
1152
+ var loggerGlobal = globalThis;
1153
+ var fallbackLoggerState = { logger: consoleLogger };
1154
+ var fallbackWarned = false;
1155
+ function getLoggerState() {
1156
+ try {
1157
+ return loggerGlobal[LOGGER_STATE_KEY] ?? (loggerGlobal[LOGGER_STATE_KEY] = fallbackLoggerState);
1158
+ } catch {
1159
+ if (!fallbackWarned) {
1160
+ fallbackWarned = true;
1161
+ fallbackLoggerState.logger.warn(
1162
+ "@anuma/sdk: the global object rejects new properties. This entrypoint keeps its own logger, so setLogger does not reach other entrypoints."
1163
+ );
1164
+ }
1165
+ return fallbackLoggerState;
1166
+ }
1167
+ }
1152
1168
  function getLogger() {
1153
- return currentLogger;
1169
+ return getLoggerState().logger;
1154
1170
  }
1155
1171
 
1156
1172
  // src/lib/memoryEngine/chunking.ts
@@ -1540,6 +1556,9 @@ function clientToolToResponsesFormat(tool) {
1540
1556
  ...toolConfig.removeAfterExecution !== void 0 && {
1541
1557
  removeAfterExecution: toolConfig.removeAfterExecution
1542
1558
  },
1559
+ ...toolConfig.removeAfterResult !== void 0 && {
1560
+ removeAfterResult: toolConfig.removeAfterResult
1561
+ },
1543
1562
  ...toolConfig.executorTimeout !== void 0 && {
1544
1563
  executorTimeout: toolConfig.executorTimeout
1545
1564
  },
@@ -1573,6 +1592,9 @@ function clientToolToCompletionsFormat(tool) {
1573
1592
  ...toolConfig.removeAfterExecution !== void 0 && {
1574
1593
  removeAfterExecution: toolConfig.removeAfterExecution
1575
1594
  },
1595
+ ...toolConfig.removeAfterResult !== void 0 && {
1596
+ removeAfterResult: toolConfig.removeAfterResult
1597
+ },
1576
1598
  ...toolConfig.executorTimeout !== void 0 && {
1577
1599
  executorTimeout: toolConfig.executorTimeout
1578
1600
  },
@@ -2239,14 +2261,14 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
2239
2261
  const alwaysInclude = clientTools.filter(isAlwaysIncluded);
2240
2262
  const filterCandidates = clientTools.filter((t) => !isAlwaysIncluded(t));
2241
2263
  if (filterCandidates.length === 0) {
2242
- return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
2264
+ return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
2243
2265
  }
2244
2266
  if (!promptEmbeddings && noEmbeddingsReason === "error") {
2245
- return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
2267
+ return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
2246
2268
  }
2247
2269
  if (!promptEmbeddings) {
2248
2270
  if (activeToolSets.length === 0) {
2249
- return { tools: [], activatedSetNames: /* @__PURE__ */ new Set() };
2271
+ return { tools: [], activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
2250
2272
  }
2251
2273
  const allSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
2252
2274
  const activeSets = allSets.filter((s) => activeToolSets.includes(s.name));
@@ -2256,7 +2278,8 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
2256
2278
  ...alwaysInclude,
2257
2279
  ...filterCandidates.filter((t) => stickyMembers.has(getToolName(t)))
2258
2280
  ],
2259
- activatedSetNames: new Set(activeSets.map((s) => s.name))
2281
+ activatedSetNames: new Set(activeSets.map((s) => s.name)),
2282
+ matchedSetNames: /* @__PURE__ */ new Set()
2260
2283
  };
2261
2284
  }
2262
2285
  const toolsNeedingEmbeddings = [];
@@ -2274,7 +2297,7 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
2274
2297
  cache.set(toolsNeedingEmbeddings[i].name, embeddings[i]);
2275
2298
  }
2276
2299
  } catch {
2277
- return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
2300
+ return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
2278
2301
  }
2279
2302
  }
2280
2303
  const pseudoServerTools = [];
@@ -2320,14 +2343,15 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
2320
2343
  activeSetNames
2321
2344
  );
2322
2345
  const activatedSetNames = activatedToolSetNames(scores, toolSets, activeSetNames);
2346
+ const matchedSetNames = activatedToolSetNames(scores, toolSets);
2323
2347
  if (finalNames.size === 0) {
2324
- return { tools: alwaysInclude, activatedSetNames };
2348
+ return { tools: alwaysInclude, activatedSetNames, matchedSetNames };
2325
2349
  }
2326
2350
  const filtered = filterCandidates.filter((t) => {
2327
2351
  const name = getToolName(t);
2328
2352
  return name && finalNames.has(name);
2329
2353
  });
2330
- return { tools: [...alwaysInclude, ...filtered], activatedSetNames };
2354
+ return { tools: [...alwaysInclude, ...filtered], activatedSetNames, matchedSetNames };
2331
2355
  }
2332
2356
 
2333
2357
  // src/lib/tools/toolCatalog.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "6.30.2",
3
+ "version": "6.31.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -154,7 +154,7 @@
154
154
  "check:excluded-suites": "node scripts/assert-excluded-suites-still-fail.mjs",
155
155
  "knip": "knip",
156
156
  "check:export-consumers": "node scripts/assert-export-consumers.mjs",
157
- "check-exports": "publint && attw --pack --ignore-rules no-resolution false-cjs && node scripts/assert-no-client-self-import.mjs",
157
+ "check-exports": "publint && attw --pack --ignore-rules no-resolution false-cjs && node scripts/assert-no-client-self-import.mjs && node scripts/assert-shared-logger.mjs",
158
158
  "check": "pnpm run lint && pnpm run knip && pnpm run check:export-consumers && pnpm run format && pnpm run generate",
159
159
  "eval:extraction": "tsx test/memory/src/extraction/benchmark.test.ts",
160
160
  "eval:topic": "tsx test/memory/src/topic/benchmark.ts",