@anuma/sdk 6.11.0 → 6.12.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.
@@ -7148,6 +7148,9 @@ async function decomposeQuery(query, options) {
7148
7148
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
7149
7149
  model: options.model ?? DEFAULT_MODEL2,
7150
7150
  systemPrompt: SYSTEM_PROMPT2,
7151
+ // The query itself rides the user turn below, so SYSTEM_PROMPT is the whole
7152
+ // fixed instruction — which is what lets the portal own it outright.
7153
+ taskType: "memory_decompose",
7151
7154
  // Wrap the bare query in a task framing so the model treats it as
7152
7155
  // input to classify, not as a question to answer conversationally.
7153
7156
  // Bare-query inputs caused Anthropic models to respond with prose
@@ -7491,24 +7494,19 @@ function createLlmNeighborRefiner(options) {
7491
7494
  async refine(query, candidates, limit) {
7492
7495
  if (candidates.length === 0) return [];
7493
7496
  const numbered = candidates.map((name, i) => `[${i + 1}] ${name}`).join("\n");
7494
- const systemPrompt = `You help a memory-retrieval system decide which related topics to explore.
7495
-
7496
- Given a user's question and a numbered list of candidate topics/entities linked to memories found so far, pick the ones most likely to lead to memories that help ANSWER the question. Choose at most ${limit}. Prefer topics semantically related to the question; ignore incidental ones.
7497
-
7498
- Output strict JSON, no prose: { "expand": [<entity names to expand, verbatim from the list>] }`;
7499
7497
  const parsed = await callPortalJsonCompletion({
7500
7498
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
7501
7499
  ...options.getToken !== void 0 && { getToken: options.getToken },
7502
7500
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
7503
7501
  taskType: "memory_graph",
7504
7502
  model: options.model ?? DEFAULT_REFINER_MODEL,
7505
- systemPrompt,
7503
+ systemPrompt: REFINER_SYSTEM_PROMPT,
7506
7504
  userMessage: `Question: ${query}
7507
7505
 
7508
7506
  Candidate topics:
7509
7507
  ${numbered}
7510
7508
 
7511
- Which should be expanded?`,
7509
+ Which should be expanded? Choose at most ${limit}.`,
7512
7510
  tag: "memory/graph-refine",
7513
7511
  maxAttempts: options.maxAttempts ?? DEFAULT_REFINER_ATTEMPTS,
7514
7512
  totalTimeoutMs: options.totalTimeoutMs ?? DEFAULT_REFINER_TOTAL_TIMEOUT_MS,
@@ -7529,7 +7527,7 @@ Which should be expanded?`,
7529
7527
  }
7530
7528
  };
7531
7529
  }
7532
- var MAX_HOPS, ENTITY_FANOUT, MIN_REFINER_CANDIDATES, MAX_REFINER_CANDIDATES, NODE_BUDGET, VAULT_SIZE_HOP_CAP, DEFAULT_REFINER_MODEL, DEFAULT_REFINER_ATTEMPTS, DEFAULT_REFINER_TOTAL_TIMEOUT_MS;
7530
+ var MAX_HOPS, ENTITY_FANOUT, MIN_REFINER_CANDIDATES, MAX_REFINER_CANDIDATES, NODE_BUDGET, VAULT_SIZE_HOP_CAP, DEFAULT_REFINER_MODEL, DEFAULT_REFINER_ATTEMPTS, DEFAULT_REFINER_TOTAL_TIMEOUT_MS, REFINER_SYSTEM_PROMPT;
7533
7531
  var init_graphTraversal = __esm({
7534
7532
  "src/lib/memory/graphTraversal.ts"() {
7535
7533
  "use strict";
@@ -7548,6 +7546,11 @@ var init_graphTraversal = __esm({
7548
7546
  DEFAULT_REFINER_MODEL = "inclusionai/ling-2.6-flash";
7549
7547
  DEFAULT_REFINER_ATTEMPTS = 1;
7550
7548
  DEFAULT_REFINER_TOTAL_TIMEOUT_MS = 8e3;
7549
+ REFINER_SYSTEM_PROMPT = `You help a memory-retrieval system decide which related topics to explore.
7550
+
7551
+ Given a user's question and a numbered list of candidate topics/entities linked to memories found so far, pick the ones most likely to lead to memories that help ANSWER the question. Never return more than the maximum the user turn asks for. Prefer topics semantically related to the question; ignore incidental ones.
7552
+
7553
+ Output strict JSON, no prose: { "expand": [<entity names to expand, verbatim from the list>] }`;
7551
7554
  }
7552
7555
  });
7553
7556
 
@@ -19038,6 +19041,7 @@ ${TRUNCATION_NOTICE}` : formatted;
19038
19041
  // src/lib/memory/reflect.ts
19039
19042
  init_clientConfig();
19040
19043
  init_logger();
19044
+ init_taskType();
19041
19045
  init_portalLlm();
19042
19046
  init_recall();
19043
19047
  var DEFAULT_BASE_URL2 = BASE_URL;
@@ -19083,11 +19087,13 @@ Respond with ONLY a single JSON object conforming to this JSON Schema, with no p
19083
19087
  ${JSON.stringify(
19084
19088
  options.responseSchema
19085
19089
  )}` : basePrompt;
19086
- const userMessage = `Question:
19087
- ${trimmed}
19088
-
19089
- Memories (use only these as evidence):
19090
- ${evidence}`;
19090
+ const userMessage = [
19091
+ `Question:
19092
+ ${trimmed}`,
19093
+ ...options.userInstructions ? [options.userInstructions] : [],
19094
+ `Memories (use only these as evidence):
19095
+ ${evidence}`
19096
+ ].join("\n\n");
19091
19097
  const maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
19092
19098
  const fetchImpl = options.fetchFn ?? fetch;
19093
19099
  const log = getLogger();
@@ -19101,7 +19107,13 @@ ${evidence}`;
19101
19107
  try {
19102
19108
  response = await fetchImpl(`${baseUrl}/api/v1/chat/completions`, {
19103
19109
  method: "POST",
19104
- headers: { ...authHeaders, "Content-Type": "application/json" },
19110
+ // No task type unless the caller named one — an undeclared task adds no
19111
+ // header at all, which is what keeps user-facing reflect() unlabelled.
19112
+ headers: {
19113
+ ...authHeaders,
19114
+ ...taskTypeHeader(options.taskType),
19115
+ "Content-Type": "application/json"
19116
+ },
19105
19117
  body: JSON.stringify({
19106
19118
  model,
19107
19119
  // Modern OpenAI field; the portal reads only `max_completion_tokens`
@@ -19553,10 +19565,15 @@ async function synthesizeFacet(facet, ctx, options, prior) {
19553
19565
  limit,
19554
19566
  types: ["fact"],
19555
19567
  maxTokens: DEFAULT_FACET_MAX_TOKENS,
19556
- // Profile-facet synthesis is a background op, so it marks its own prompt.
19557
- // reflect() itself must NOT mark — it also serves the user's own questions,
19558
- // and that traffic is chat, not an internal flow. See ../internalFlowMarker.
19559
- systemPrompt: withInternalFlowMarker(buildFacetSystemPrompt(facet)),
19568
+ // Profile-facet synthesis is a background op, so it marks its own prompt AND
19569
+ // names its own task. reflect() itself must do neither — it also serves the
19570
+ // user's own questions, and that traffic is chat, not an internal flow. See
19571
+ // ../internalFlowMarker and ReflectOptions.taskType.
19572
+ taskType: "memory_profile_synth",
19573
+ systemPrompt: withInternalFlowMarker(FACET_SYSTEM_PROMPT),
19574
+ // The facet's label/guidance/response-fields, on the user turn — what keeps
19575
+ // the system half fixed and therefore server-ownable.
19576
+ userInstructions: buildFacetUserInstructions(facet),
19560
19577
  responseSchema: facetResponseSchema(facet.key),
19561
19578
  memories
19562
19579
  });
@@ -19614,19 +19631,22 @@ function fallbackSection(facet, prior) {
19614
19631
  stale: true
19615
19632
  };
19616
19633
  }
19617
- function buildFacetSystemPrompt(facet) {
19618
- const structuredField = FACET_STRUCTURED_RESPONSE_HINT[facet.key] ?? "";
19619
- return `You are writing the "${facet.label}" section of a person's shareable profile, using their private memories (supplied as evidence) as the only source of truth.
19620
-
19621
- Task for this section:
19622
- ${facet.guidance}
19634
+ var FACET_SYSTEM_PROMPT = `You are writing one section of a person's shareable profile, using their private memories (supplied as evidence) as the only source of truth. The user turn names the section, states the task for it, and gives the exact JSON shape to respond in.
19623
19635
 
19624
19636
  Rules:
19625
19637
  - Ground every claim in the supplied memories \u2014 never invent, infer beyond, or embellish what they support.
19626
19638
  - If the memories don't cover this section, return an empty summary with hasEvidence=false. Do not pad or guess.
19627
19639
  - Write in third person about the person, in a natural voice suitable for a public profile (no "I"/"you", no name repetition).
19628
19640
  - Be concise and specific; no preamble, hedging, or meta-commentary.
19629
- - Respond as JSON: { "summary": <the section text, or "">, "hasEvidence": <true|false>${structuredField} }.`;
19641
+ - Respond as JSON in exactly the shape the user turn states, with no extra fields.`;
19642
+ function buildFacetUserInstructions(facet) {
19643
+ const structuredField = FACET_STRUCTURED_RESPONSE_HINT[facet.key] ?? "";
19644
+ return `Section: "${facet.label}"
19645
+
19646
+ Task for this section:
19647
+ ${facet.guidance}
19648
+
19649
+ Respond as JSON: { "summary": <the section text, or "">, "hasEvidence": <true|false>${structuredField} }.`;
19630
19650
  }
19631
19651
  function extractFacetText(structured) {
19632
19652
  if (structured && typeof structured === "object") {
@@ -21680,6 +21700,20 @@ function clientToolToCompletionsFormat(tool) {
21680
21700
  }
21681
21701
  var TOOL_SEARCH_TOOL_TYPE = "tool_search_tool_regex_20251119";
21682
21702
  var TOOL_SEARCH_TOOL_NAME = "tool_search_tool_regex";
21703
+ function resolveDeferredServerTools(allServerTools, serverToolsFilter, config) {
21704
+ const allowed = serverToolsFilter === void 0 || typeof serverToolsFilter === "function" ? allServerTools : filterServerTools(allServerTools, [...serverToolsFilter]);
21705
+ const excluded = new Set(config.excludeTools ?? []);
21706
+ if (typeof serverToolsFilter === "function") {
21707
+ for (const name of serverToolsFilter.excludeTools ?? []) excluded.add(name);
21708
+ }
21709
+ if (excluded.size === 0) return allowed;
21710
+ return allowed.filter((tool) => !excluded.has(tool.name));
21711
+ }
21712
+ function deferFormattingConfig(serverToolsFilter, config) {
21713
+ if (!config?.enabled) return config;
21714
+ const isExplicitList = serverToolsFilter !== void 0 && typeof serverToolsFilter !== "function";
21715
+ return isExplicitList ? void 0 : config;
21716
+ }
21683
21717
  function byNameAscending(a, b) {
21684
21718
  if (a.name < b.name) return -1;
21685
21719
  if (a.name > b.name) return 1;
@@ -22006,7 +22040,7 @@ function createServerToolsFilter(options = {}) {
22006
22040
  const exclude = new Set(options.excludeTools ?? []);
22007
22041
  const sets = options.toolSets ?? [];
22008
22042
  const matchOpts = options.matchOptions;
22009
- return (embeddings, tools) => {
22043
+ const filter = (embeddings, tools) => {
22010
22044
  const matches = findMatchingTools(embeddings, tools, matchOpts);
22011
22045
  if (matches.length === 0) return [];
22012
22046
  const matchedNames = new Set(matches.map((m) => m.tool.name));
@@ -22024,6 +22058,10 @@ function createServerToolsFilter(options = {}) {
22024
22058
  for (const name of exclude) finalNames.delete(name);
22025
22059
  return [...finalNames];
22026
22060
  };
22061
+ return Object.defineProperty(filter, "excludeTools", {
22062
+ value: Object.freeze([...exclude]),
22063
+ enumerable: false
22064
+ });
22027
22065
  }
22028
22066
  var DEFAULT_EXCLUDED_SERVER_TOOLS = [
22029
22067
  "AnumaVisionMCP-anuma_analyze_image",
@@ -22105,7 +22143,8 @@ async function selectServerToolsForPrompt(options) {
22105
22143
  return [];
22106
22144
  }
22107
22145
  if (allServerTools.length === 0) return [];
22108
- if (deferLoading?.enabled) return allServerTools;
22146
+ if (deferLoading?.enabled)
22147
+ return resolveDeferredServerTools(allServerTools, serverToolsFilter, deferLoading);
22109
22148
  if (typeof serverToolsFilter === "function") {
22110
22149
  if (prompt.length < MIN_CONTENT_LENGTH_FOR_TOOLS) return [];
22111
22150
  let promptEmbedding;
@@ -22536,7 +22575,8 @@ async function previewToolSelection(options) {
22536
22575
  cache: serverToolsConfig?.cache
22537
22576
  });
22538
22577
  const allow = new Set(serverToolsFilter);
22539
- gatedServerNames = allServerTools.filter((t) => allow.has(t.name)).map((t) => t.name);
22578
+ const gated = allServerTools.filter((t) => allow.has(t.name));
22579
+ gatedServerNames = (serverToolsConfig?.deferLoading?.enabled ? resolveDeferredServerTools(gated, serverToolsFilter, serverToolsConfig.deferLoading) : gated).map((t) => t.name);
22540
22580
  } catch {
22541
22581
  }
22542
22582
  }
@@ -22585,7 +22625,11 @@ async function previewToolSelection(options) {
22585
22625
  cache: serverToolsConfig?.cache
22586
22626
  });
22587
22627
  if (serverToolsConfig?.deferLoading?.enabled) {
22588
- serverToolNames = allServerTools.map((t) => t.name);
22628
+ serverToolNames = resolveDeferredServerTools(
22629
+ allServerTools,
22630
+ serverToolsFilter,
22631
+ serverToolsConfig.deferLoading
22632
+ ).map((t) => t.name);
22589
22633
  } else if (typeof serverToolsFilter === "function") {
22590
22634
  serverToolNames = serverToolsFilter(promptEmbedding, allServerTools);
22591
22635
  } else {
@@ -23601,7 +23645,11 @@ function useChatStorage(options) {
23601
23645
  cache: serverToolsConfig?.cache
23602
23646
  });
23603
23647
  if (serverToolsConfig?.deferLoading?.enabled) {
23604
- filteredServerTools2 = allServerTools;
23648
+ filteredServerTools2 = resolveDeferredServerTools(
23649
+ allServerTools,
23650
+ serverToolsFilter,
23651
+ serverToolsConfig.deferLoading
23652
+ );
23605
23653
  } else if (isServerToolsFunction2) {
23606
23654
  if (skipStorageEmbeddings) {
23607
23655
  const toolNames = serverToolsFilter(skipStorageEmbeddings, allServerTools);
@@ -23642,7 +23690,7 @@ function useChatStorage(options) {
23642
23690
  filteredServerTools2,
23643
23691
  filteredClientTools2,
23644
23692
  effectiveApiType2,
23645
- serverToolsConfig?.deferLoading
23693
+ deferFormattingConfig(serverToolsFilter, serverToolsConfig?.deferLoading)
23646
23694
  );
23647
23695
  }
23648
23696
  if (onToolSelection) {
@@ -24001,7 +24049,11 @@ function useChatStorage(options) {
24001
24049
  if (allServerTools) {
24002
24050
  try {
24003
24051
  if (serverToolsConfig?.deferLoading?.enabled && effectiveApiType === "responses") {
24004
- filteredServerTools = allServerTools;
24052
+ filteredServerTools = resolveDeferredServerTools(
24053
+ allServerTools,
24054
+ serverToolsFilter,
24055
+ serverToolsConfig.deferLoading
24056
+ );
24005
24057
  } else if (isServerToolsFunction) {
24006
24058
  if (userMessageEmbeddings) {
24007
24059
  const toolNames = serverToolsFilter(userMessageEmbeddings, allServerTools);
@@ -24081,7 +24133,7 @@ function useChatStorage(options) {
24081
24133
  filteredServerTools,
24082
24134
  filteredClientTools,
24083
24135
  effectiveApiType,
24084
- serverToolsConfig?.deferLoading
24136
+ deferFormattingConfig(serverToolsFilter, serverToolsConfig?.deferLoading)
24085
24137
  );
24086
24138
  }
24087
24139
  if (onToolSelection) {
@@ -4465,6 +4465,22 @@ interface DeferLoadingConfig {
4465
4465
  enabled: boolean;
4466
4466
  /** Server-tool names to keep non-deferred (besides the tool-search tool), in priority order. */
4467
4467
  hotToolNames: readonly string[];
4468
+ /**
4469
+ * Server-tool names to drop entirely while defer-loading is on.
4470
+ *
4471
+ * Defer widens the per-turn selection to the whole catalog, which also bypasses the `excludeTools`
4472
+ * baked into a caller's semantic filter. A filter built by {@link createServerToolsFilter} tags itself
4473
+ * with its own exclusions and those are honoured automatically — so most callers need nothing here.
4474
+ *
4475
+ * Set this when the filter's tag can't be seen: a hand-written filter, a filter wrapped in a plain
4476
+ * closure (the wrapper drops the tag), or a static-array `serverToolsFilter`. Anything excluded
4477
+ * UNCONDITIONALLY (a tool the app replaces with its own UI, a capability the model already has
4478
+ * natively) belongs in one of the two places, or defer quietly hands it back to the model.
4479
+ *
4480
+ * This list is UNIONED with the filter's own tag, never a replacement for it — so adding one name
4481
+ * here cannot re-admit the tools the filter already excludes.
4482
+ */
4483
+ excludeTools?: readonly string[];
4468
4484
  }
4469
4485
  /**
4470
4486
  * Result of tool matching with similarity score
@@ -4642,7 +4658,7 @@ interface CreateServerToolsFilterOptions {
4642
4658
  * });
4643
4659
  * ```
4644
4660
  */
4645
- declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
4661
+ declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): ServerToolsFilterFunction;
4646
4662
  /**
4647
4663
  * Default exclusions baked into `defaultServerToolsFilter`.
4648
4664
  *
@@ -4708,13 +4724,21 @@ declare const SERVER_TOOL_DEPENDENCY_SETS: ToolSet[];
4708
4724
  * If you need to customize (extra excludes, different limits, opt into
4709
4725
  * tool-set expansion), call `createServerToolsFilter` directly.
4710
4726
  */
4711
- declare const defaultServerToolsFilter: (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
4727
+ declare const defaultServerToolsFilter: ServerToolsFilterFunction;
4712
4728
  /**
4713
4729
  * Type for a server-tools filter — a function that takes prompt embeddings
4714
4730
  * and the full server tool catalog and returns the names of tools to keep.
4715
4731
  * Matches `useChatStorage`'s `serverTools` callback signature.
4716
4732
  */
4717
- type ServerToolsFilterFunction = (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
4733
+ type ServerToolsFilterFunction = ((embeddings: number[] | number[][], tools: ServerTool[]) => string[]) & {
4734
+ /**
4735
+ * The unconditional exclusions this filter applies, exposed by
4736
+ * {@link createServerToolsFilter} so defer-loading can honour them without the caller
4737
+ * repeating the list — see {@link resolveDeferredServerTools}. Absent on a hand-written
4738
+ * filter, or on one wrapped in a plain closure.
4739
+ */
4740
+ readonly excludeTools?: readonly string[];
4741
+ };
4718
4742
  /**
4719
4743
  * Options for `selectServerToolsForPrompt`.
4720
4744
  */
@@ -4742,9 +4766,10 @@ interface SelectServerToolsForPromptOptions {
4742
4766
  */
4743
4767
  cache?: ToolsCacheBackend;
4744
4768
  /**
4745
- * Phase 3 defer-loading. When `enabled`, this helper returns the FULL catalog (skipping semantic/
4746
- * static filtering) to mirror useChatStorage's responses send path, which swaps in the full catalog
4747
- * for mergeTools + tool-search. Omit/disabled → today's filtered selection.
4769
+ * Phase 3 defer-loading. When `enabled`, this helper skips SEMANTIC filtering to mirror
4770
+ * useChatStorage's responses send path, which hands the catalog to mergeTools + tool-search. The
4771
+ * caller's unconditional constraints still apply — an explicit static array, and exclusions (see
4772
+ * {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
4748
4773
  */
4749
4774
  deferLoading?: DeferLoadingConfig;
4750
4775
  }
@@ -6140,6 +6165,51 @@ declare function getMemoriesByEntityNamesOp(ctx: EntityOperationsContext, entity
6140
6165
  */
6141
6166
  declare function getEntitiesByMemoryIdsOp(ctx: EntityOperationsContext, memoryIds: readonly string[]): Promise<Map<string, Set<string>>>;
6142
6167
 
6168
+ /**
6169
+ * Class-B task types — the vocabulary of the `X-Anuma-Task-Type` header.
6170
+ *
6171
+ * A Class-B flow has ONE fixed purpose and no conversation: extract memories
6172
+ * from a snippet, pick a topic, consolidate duplicates, classify a query. Today
6173
+ * each of those builds its own system prompt on the client and sends it as a
6174
+ * `role:system` message, which makes the prompt a suggestion rather than a
6175
+ * contract — a caller can reword it into "you are a general assistant" and get
6176
+ * general chat at internal-endpoint prices.
6177
+ *
6178
+ * The fix is that the SERVER owns the text and the client only names the task.
6179
+ * This header is the name. The portal allowlists it against its own copy of this
6180
+ * enum (ai-portal `internal/systemprompt/tasks.go`) and DROPS anything it does
6181
+ * not recognise, so an unknown value degrades to "no task declared" rather than
6182
+ * failing the request.
6183
+ *
6184
+ * ⚠ These string values are a wire contract with ai-portal. Adding one here
6185
+ * before the portal knows it is harmless (it is dropped); renaming or removing
6186
+ * one silently stops that flow being counted. Keep them in step with
6187
+ * `AllTaskTypes` on the portal side, and see ai-portal
6188
+ * `docs/BACKEND_OWNED_TASK_PROMPTS.md` for the rollout.
6189
+ *
6190
+ * ⚠ RELEASE ORDER. This union is a PUBLIC type, so a split is breaking in both
6191
+ * directions and has to be sequenced:
6192
+ *
6193
+ * 1. merge + publish this package;
6194
+ * 2. bump `@anuma/sdk` in the consumer and switch its call sites to the new
6195
+ * names in the same commit.
6196
+ *
6197
+ * A consumer on the OLD version cannot compile the new names, and a consumer on
6198
+ * the NEW version cannot compile the retired ones (`app_inspiration` is gone
6199
+ * here, replaced by the three `app_inspiration_*` names). Both halves of that
6200
+ * are type-only — the wire itself always degrades safely, because the portal
6201
+ * drops any value it does not recognise. Concretely: ai-memoryless-client#5782
6202
+ * is blocked on this publish for exactly that reason.
6203
+ *
6204
+ * Deliberately ABSENT: agent personas, `reflect()` when it answers the user, and
6205
+ * the app-idea chat. Those carry an open conversation with the user, so a fixed
6206
+ * server-owned prompt would be wrong rather than merely premature — the same
6207
+ * boundary {@link INTERNAL_FLOW_MARKER} draws.
6208
+ *
6209
+ * @public
6210
+ */
6211
+ type TaskType = "title" | "commit_message" | "memory_extract" | "memory_dedup" | "memory_decay" | "memory_injection_check" | "memory_verify_support" | "memory_autosort" | "memory_topic" | "memory_consolidate" | "memory_decompose" | "memory_profile_synth" | "memory_graph" | "folder_context" | "selection_memory" | "summarize" | "style_analysis" | "classify_search" | "app_inspiration_generate" | "app_inspiration_trends" | "app_inspiration_remix" | "spotlight_image" | "slide_image" | "slide_video" | "slide_music" | "slide_sfx" | "media_video" | "media_audio" | "media_bg_removal" | "media_image_preset" | "tool_app_builder" | "tool_document_builder" | "tool_slides" | "tool_slides_image_gen" | "connector_guidance" | "cf_task" | "xbot_intent" | "xbot_council" | "scheduled_task";
6212
+
6143
6213
  /**
6144
6214
  * Shared portal LLM call for the memory pipeline.
6145
6215
  *
@@ -9390,6 +9460,28 @@ interface ReflectOptions extends RecallOptions, PortalLlmAuth {
9390
9460
  maxTokens?: number;
9391
9461
  /** Override the grounding system prompt. */
9392
9462
  systemPrompt?: string;
9463
+ /**
9464
+ * Extra caller instruction to carry on the USER turn, between the question and
9465
+ * the evidence block (see the `userMessage` assembly below). This is the slot a
9466
+ * background caller uses to keep its per-request data OUT of the system message
9467
+ * without colliding with the numbered evidence list — profile-facet synthesis
9468
+ * puts its section label, guidance and response-field hint here so its system
9469
+ * half can stay fixed and server-ownable.
9470
+ */
9471
+ userInstructions?: string;
9472
+ /**
9473
+ * Class-B task name for the `X-Anuma-Task-Type` header, or nothing.
9474
+ *
9475
+ * Deliberately OPTIONAL and unset by default. reflect() also answers the user's
9476
+ * OWN question, and that traffic is chat, not an internal flow — declaring a
9477
+ * task type unconditionally here would put an internal-flow name on real
9478
+ * conversation, which is the same boundary `INTERNAL_FLOW_MARKER` draws
9479
+ * (reflect is deliberately unmarked; its background caller marks its own
9480
+ * prompt — see ../internalFlowMarker.ts). So the name is per call: only a
9481
+ * caller with ONE fixed purpose passes
9482
+ * one, and today that is profile-facet synthesis (`memory_profile_synth`).
9483
+ */
9484
+ taskType?: TaskType;
9393
9485
  /** Endpoint for the answer LLM. */
9394
9486
  baseUrl?: string;
9395
9487
  /** Override fetch (for tests). */
@@ -4465,6 +4465,22 @@ interface DeferLoadingConfig {
4465
4465
  enabled: boolean;
4466
4466
  /** Server-tool names to keep non-deferred (besides the tool-search tool), in priority order. */
4467
4467
  hotToolNames: readonly string[];
4468
+ /**
4469
+ * Server-tool names to drop entirely while defer-loading is on.
4470
+ *
4471
+ * Defer widens the per-turn selection to the whole catalog, which also bypasses the `excludeTools`
4472
+ * baked into a caller's semantic filter. A filter built by {@link createServerToolsFilter} tags itself
4473
+ * with its own exclusions and those are honoured automatically — so most callers need nothing here.
4474
+ *
4475
+ * Set this when the filter's tag can't be seen: a hand-written filter, a filter wrapped in a plain
4476
+ * closure (the wrapper drops the tag), or a static-array `serverToolsFilter`. Anything excluded
4477
+ * UNCONDITIONALLY (a tool the app replaces with its own UI, a capability the model already has
4478
+ * natively) belongs in one of the two places, or defer quietly hands it back to the model.
4479
+ *
4480
+ * This list is UNIONED with the filter's own tag, never a replacement for it — so adding one name
4481
+ * here cannot re-admit the tools the filter already excludes.
4482
+ */
4483
+ excludeTools?: readonly string[];
4468
4484
  }
4469
4485
  /**
4470
4486
  * Result of tool matching with similarity score
@@ -4642,7 +4658,7 @@ interface CreateServerToolsFilterOptions {
4642
4658
  * });
4643
4659
  * ```
4644
4660
  */
4645
- declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
4661
+ declare function createServerToolsFilter(options?: CreateServerToolsFilterOptions): ServerToolsFilterFunction;
4646
4662
  /**
4647
4663
  * Default exclusions baked into `defaultServerToolsFilter`.
4648
4664
  *
@@ -4708,13 +4724,21 @@ declare const SERVER_TOOL_DEPENDENCY_SETS: ToolSet[];
4708
4724
  * If you need to customize (extra excludes, different limits, opt into
4709
4725
  * tool-set expansion), call `createServerToolsFilter` directly.
4710
4726
  */
4711
- declare const defaultServerToolsFilter: (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
4727
+ declare const defaultServerToolsFilter: ServerToolsFilterFunction;
4712
4728
  /**
4713
4729
  * Type for a server-tools filter — a function that takes prompt embeddings
4714
4730
  * and the full server tool catalog and returns the names of tools to keep.
4715
4731
  * Matches `useChatStorage`'s `serverTools` callback signature.
4716
4732
  */
4717
- type ServerToolsFilterFunction = (embeddings: number[] | number[][], tools: ServerTool[]) => string[];
4733
+ type ServerToolsFilterFunction = ((embeddings: number[] | number[][], tools: ServerTool[]) => string[]) & {
4734
+ /**
4735
+ * The unconditional exclusions this filter applies, exposed by
4736
+ * {@link createServerToolsFilter} so defer-loading can honour them without the caller
4737
+ * repeating the list — see {@link resolveDeferredServerTools}. Absent on a hand-written
4738
+ * filter, or on one wrapped in a plain closure.
4739
+ */
4740
+ readonly excludeTools?: readonly string[];
4741
+ };
4718
4742
  /**
4719
4743
  * Options for `selectServerToolsForPrompt`.
4720
4744
  */
@@ -4742,9 +4766,10 @@ interface SelectServerToolsForPromptOptions {
4742
4766
  */
4743
4767
  cache?: ToolsCacheBackend;
4744
4768
  /**
4745
- * Phase 3 defer-loading. When `enabled`, this helper returns the FULL catalog (skipping semantic/
4746
- * static filtering) to mirror useChatStorage's responses send path, which swaps in the full catalog
4747
- * for mergeTools + tool-search. Omit/disabled → today's filtered selection.
4769
+ * Phase 3 defer-loading. When `enabled`, this helper skips SEMANTIC filtering to mirror
4770
+ * useChatStorage's responses send path, which hands the catalog to mergeTools + tool-search. The
4771
+ * caller's unconditional constraints still apply — an explicit static array, and exclusions (see
4772
+ * {@link resolveDeferredServerTools}). Omit/disabled → today's filtered selection.
4748
4773
  */
4749
4774
  deferLoading?: DeferLoadingConfig;
4750
4775
  }
@@ -6140,6 +6165,51 @@ declare function getMemoriesByEntityNamesOp(ctx: EntityOperationsContext, entity
6140
6165
  */
6141
6166
  declare function getEntitiesByMemoryIdsOp(ctx: EntityOperationsContext, memoryIds: readonly string[]): Promise<Map<string, Set<string>>>;
6142
6167
 
6168
+ /**
6169
+ * Class-B task types — the vocabulary of the `X-Anuma-Task-Type` header.
6170
+ *
6171
+ * A Class-B flow has ONE fixed purpose and no conversation: extract memories
6172
+ * from a snippet, pick a topic, consolidate duplicates, classify a query. Today
6173
+ * each of those builds its own system prompt on the client and sends it as a
6174
+ * `role:system` message, which makes the prompt a suggestion rather than a
6175
+ * contract — a caller can reword it into "you are a general assistant" and get
6176
+ * general chat at internal-endpoint prices.
6177
+ *
6178
+ * The fix is that the SERVER owns the text and the client only names the task.
6179
+ * This header is the name. The portal allowlists it against its own copy of this
6180
+ * enum (ai-portal `internal/systemprompt/tasks.go`) and DROPS anything it does
6181
+ * not recognise, so an unknown value degrades to "no task declared" rather than
6182
+ * failing the request.
6183
+ *
6184
+ * ⚠ These string values are a wire contract with ai-portal. Adding one here
6185
+ * before the portal knows it is harmless (it is dropped); renaming or removing
6186
+ * one silently stops that flow being counted. Keep them in step with
6187
+ * `AllTaskTypes` on the portal side, and see ai-portal
6188
+ * `docs/BACKEND_OWNED_TASK_PROMPTS.md` for the rollout.
6189
+ *
6190
+ * ⚠ RELEASE ORDER. This union is a PUBLIC type, so a split is breaking in both
6191
+ * directions and has to be sequenced:
6192
+ *
6193
+ * 1. merge + publish this package;
6194
+ * 2. bump `@anuma/sdk` in the consumer and switch its call sites to the new
6195
+ * names in the same commit.
6196
+ *
6197
+ * A consumer on the OLD version cannot compile the new names, and a consumer on
6198
+ * the NEW version cannot compile the retired ones (`app_inspiration` is gone
6199
+ * here, replaced by the three `app_inspiration_*` names). Both halves of that
6200
+ * are type-only — the wire itself always degrades safely, because the portal
6201
+ * drops any value it does not recognise. Concretely: ai-memoryless-client#5782
6202
+ * is blocked on this publish for exactly that reason.
6203
+ *
6204
+ * Deliberately ABSENT: agent personas, `reflect()` when it answers the user, and
6205
+ * the app-idea chat. Those carry an open conversation with the user, so a fixed
6206
+ * server-owned prompt would be wrong rather than merely premature — the same
6207
+ * boundary {@link INTERNAL_FLOW_MARKER} draws.
6208
+ *
6209
+ * @public
6210
+ */
6211
+ type TaskType = "title" | "commit_message" | "memory_extract" | "memory_dedup" | "memory_decay" | "memory_injection_check" | "memory_verify_support" | "memory_autosort" | "memory_topic" | "memory_consolidate" | "memory_decompose" | "memory_profile_synth" | "memory_graph" | "folder_context" | "selection_memory" | "summarize" | "style_analysis" | "classify_search" | "app_inspiration_generate" | "app_inspiration_trends" | "app_inspiration_remix" | "spotlight_image" | "slide_image" | "slide_video" | "slide_music" | "slide_sfx" | "media_video" | "media_audio" | "media_bg_removal" | "media_image_preset" | "tool_app_builder" | "tool_document_builder" | "tool_slides" | "tool_slides_image_gen" | "connector_guidance" | "cf_task" | "xbot_intent" | "xbot_council" | "scheduled_task";
6212
+
6143
6213
  /**
6144
6214
  * Shared portal LLM call for the memory pipeline.
6145
6215
  *
@@ -9390,6 +9460,28 @@ interface ReflectOptions extends RecallOptions, PortalLlmAuth {
9390
9460
  maxTokens?: number;
9391
9461
  /** Override the grounding system prompt. */
9392
9462
  systemPrompt?: string;
9463
+ /**
9464
+ * Extra caller instruction to carry on the USER turn, between the question and
9465
+ * the evidence block (see the `userMessage` assembly below). This is the slot a
9466
+ * background caller uses to keep its per-request data OUT of the system message
9467
+ * without colliding with the numbered evidence list — profile-facet synthesis
9468
+ * puts its section label, guidance and response-field hint here so its system
9469
+ * half can stay fixed and server-ownable.
9470
+ */
9471
+ userInstructions?: string;
9472
+ /**
9473
+ * Class-B task name for the `X-Anuma-Task-Type` header, or nothing.
9474
+ *
9475
+ * Deliberately OPTIONAL and unset by default. reflect() also answers the user's
9476
+ * OWN question, and that traffic is chat, not an internal flow — declaring a
9477
+ * task type unconditionally here would put an internal-flow name on real
9478
+ * conversation, which is the same boundary `INTERNAL_FLOW_MARKER` draws
9479
+ * (reflect is deliberately unmarked; its background caller marks its own
9480
+ * prompt — see ../internalFlowMarker.ts). So the name is per call: only a
9481
+ * caller with ONE fixed purpose passes
9482
+ * one, and today that is profile-facet synthesis (`memory_profile_synth`).
9483
+ */
9484
+ taskType?: TaskType;
9393
9485
  /** Endpoint for the answer LLM. */
9394
9486
  baseUrl?: string;
9395
9487
  /** Override fetch (for tests). */