@superatomai/sdk-node 0.0.69-dsp → 0.0.70-dsp

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.d.mts CHANGED
@@ -1068,6 +1068,28 @@ interface RunTrace {
1068
1068
  note?: string;
1069
1069
  }>;
1070
1070
  };
1071
+ /**
1072
+ * Direct-tool activity this turn (main-agent.ts's handleDirectTool) — one
1073
+ * entry per direct-tool call, unconditional and generic across every
1074
+ * project's direct tools, not specific to one. For fusion-5's `concept`
1075
+ * tool this is what actually traces find/get/run (distinguished via
1076
+ * `input.method`) — unlike `concepts.calls` above, which only the
1077
+ * dashboard-agent flow's own, separate concept tool still populates;
1078
+ * MainAgent no longer resolves concepts itself, so nothing else writes
1079
+ * here for a chat/report turn.
1080
+ */
1081
+ directTools: {
1082
+ calls: Array<{
1083
+ toolId: string;
1084
+ /** Exact params the LLM called this tool with. */
1085
+ input: any;
1086
+ /** The tool's raw return value. Absent when `error` is set. */
1087
+ output?: any;
1088
+ /** Set whether the tool's own result carried an `error` field or the call threw. */
1089
+ error?: string;
1090
+ durationMs?: number;
1091
+ }>;
1092
+ };
1071
1093
  /**
1072
1094
  * The prior-turn conversation context injected into this turn's prompt as
1073
1095
  * CONVERSATION_HISTORY — exactly what each flow already builds for itself
@@ -1311,13 +1333,23 @@ declare class Logger {
1311
1333
  */
1312
1334
  debug(...args: any[]): void;
1313
1335
  /**
1314
- * Write to log file
1336
+ * Write to log file — each line timestamped so a request that made many
1337
+ * calls (LLM turns, tool dispatches, direct-tool runs) can be read back in
1338
+ * order, matching "know what happened when" rather than just "what
1339
+ * happened".
1315
1340
  */
1316
1341
  file(...args: any[]): void;
1342
+ /** The log file the current request is writing to — print/return this so it's easy to find afterward. */
1343
+ getCurrentLogFilePath(): string;
1317
1344
  /**
1318
- * Clear the log file (call at start of new user request)
1345
+ * Start a fresh, uniquely-named log file for a new top-level request
1346
+ * (chat turn, dashComp request, reportComp request, ...) instead of
1347
+ * truncating one shared file — pass a short label (a prompt snippet, a
1348
+ * request type) so the resulting filename is identifiable at a glance.
1349
+ * Falls back to the untimestamped legacy path when `label` is omitted, for
1350
+ * any caller not yet updated to pass one.
1319
1351
  */
1320
- clearFile(): void;
1352
+ clearFile(label?: string): void;
1321
1353
  /**
1322
1354
  * Log LLM method prompts with clear labeling
1323
1355
  */
@@ -2099,6 +2131,16 @@ interface DashCompModelConfig {
2099
2131
  */
2100
2132
  fastModel?: string;
2101
2133
  }
2134
+ /**
2135
+ * Where a question was asked from. Every field is optional; an empty object and
2136
+ * an absent context mean the same thing.
2137
+ */
2138
+ interface PromptContext {
2139
+ /** The dashboard on screen when the question was asked. */
2140
+ dashboardId?: string;
2141
+ /** The filter values set on that dashboard, keyed by parameter name. */
2142
+ filters?: Record<string, unknown>;
2143
+ }
2102
2144
  /**
2103
2145
  * Everything a replacement answer flow is handed for one question. Deliberately
2104
2146
  * the same material the built-in flow gets, so a provider is a drop-in and not a
@@ -2128,6 +2170,8 @@ interface AnswerProviderContext {
2128
2170
  text: string;
2129
2171
  }) => void;
2130
2172
  signal?: AbortSignal;
2173
+ /** Where the question was asked from, when the client said. */
2174
+ context?: PromptContext;
2131
2175
  }
2132
2176
  /**
2133
2177
  * One narrator tick while an answer was being produced: what the narrator was
@@ -2160,6 +2204,8 @@ interface NarrationUpdate {
2160
2204
  *
2161
2205
  * `data.narration` (NarrationUpdate[]) is optional and saved with the answer on
2162
2206
  * every outcome — success, error and abort — so return it on each of them.
2207
+ *
2208
+ * `data` may also carry `trace`, and `usage` and `model` per `AnswerProviderReport`.
2163
2209
  */
2164
2210
  type AnswerProvider = (ctx: AnswerProviderContext) => Promise<T_RESPONSE>;
2165
2211
  interface SuperatomSDKConfig {
@@ -2227,6 +2273,12 @@ interface SuperatomSDKConfig {
2227
2273
  * Default: 5 minutes
2228
2274
  */
2229
2275
  queryCacheTTL?: number;
2276
+ /**
2277
+ * Keep query results in the SDK's in-memory cache.
2278
+ * Set false when the host caches results itself; queryId tokens keep working.
2279
+ * Default: true
2280
+ */
2281
+ queryResultCache?: boolean;
2230
2282
  /**
2231
2283
  * Dashboard conversation history TTL (Time To Live) in minutes
2232
2284
  * Per-dashboard conversation histories expire after this duration
@@ -3104,9 +3156,11 @@ declare class MainAgent {
3104
3156
  */
3105
3157
  private resolvedEntities;
3106
3158
  /**
3107
- * Concept bodies resolved this turn (via resolve_entities' embedded concept
3108
- * lookup or a standalone resolve_concepts call) — retained the same way as
3109
- * resolvedEntities above, so they can be attached to the SourceAgent dispatch.
3159
+ * Concept bodies resolved this turn (currently: invariants only, via
3160
+ * loadConceptInvariants — concept resolution is no longer part of
3161
+ * resolve_entities or any other MainAgent-owned tool) — retained the same
3162
+ * way as resolvedEntities above, so they can be attached to the SourceAgent
3163
+ * dispatch.
3110
3164
  *
3111
3165
  * Without this, a concept resolved HERE (MainAgent's own tool loop) never
3112
3166
  * reaches SourceAgent at all: SourceAgent only gets the natural-language
@@ -3257,13 +3311,36 @@ declare class MainAgent {
3257
3311
  * it; scopeSql is the one thing worth this guarantee today.
3258
3312
  */
3259
3313
  private buildResolvedEntitiesBlock;
3260
- /** Dedupe-and-retain helper shared by resolveConceptsForTurn and handleResolveConcepts. */
3314
+ /**
3315
+ * Dedupe-and-retain helper shared by loadConceptInvariants and the generic
3316
+ * direct-tool `resolvedConcepts` opt-in hook. `alwaysInclude` marks entries
3317
+ * that buildResolvedConceptsBlock must attach to EVERY dispatch regardless
3318
+ * of that dispatch's `concepts` param — true only for invariants, which are
3319
+ * meant to apply everywhere by definition. Concepts retained without it
3320
+ * (e.g. via the `concept` tool's `get`) are scoped per-dispatch instead.
3321
+ */
3261
3322
  private retainResolvedConcepts;
3262
3323
  /**
3263
3324
  * Same purpose as buildResolvedEntitiesBlock, for concept bodies instead of
3264
3325
  * entity ids — appended to the dispatch intent so SourceAgent's own,
3265
3326
  * independent LLM call receives the resolved definitions verbatim rather
3266
3327
  * than only MainAgent's paraphrased intent text.
3328
+ *
3329
+ * Unlike buildResolvedEntitiesBlock, non-invariant entries here are SCOPED
3330
+ * to `names` (this dispatch's SourceToolInput.concepts) rather than
3331
+ * dumping the whole-turn `this.resolvedConcepts` accumulator into every
3332
+ * dispatch. A concept body is phrased as an authoritative override
3333
+ * ("overrides the schema... your own reasoning") — fetching several via
3334
+ * `get` to compare/discard, or a turn needing different concepts for
3335
+ * different sub-questions, must not leak an irrelevant concept's filters
3336
+ * into an unrelated dispatch. An entry not named in `names` and not
3337
+ * `alwaysInclude` is left out — a concept the model forgot to name is a
3338
+ * visible, fixable miss; one that leaks in uninvited is not.
3339
+ *
3340
+ * `alwaysInclude` entries (invariants — see loadConceptInvariants) bypass
3341
+ * `names` entirely and attach to every dispatch regardless, same as before
3342
+ * this method took a `names` param — they are meant to apply everywhere,
3343
+ * not just when the model happens to ask for them.
3267
3344
  */
3268
3345
  private buildResolvedConceptsBlock;
3269
3346
  /** True when the backend registered the entity-search collection. */
@@ -3271,11 +3348,21 @@ declare class MainAgent {
3271
3348
  /** True when the backend registered the concepts collection. */
3272
3349
  private get conceptsEnabled();
3273
3350
  /**
3274
- * Concept names for the system prompt. Names ONLY — the body comes back from
3351
+ * The concept catalog for the system prompt: one line per concept — name,
3352
+ * aliases, and what it is for. No bodies — the body comes back from
3275
3353
  * resolve_concepts once the LLM has named one, exactly as with the entity
3276
3354
  * catalog. Putting bodies here would rebuild the always-on context problem
3277
3355
  * concepts exist to solve.
3278
3356
  *
3357
+ * The description is what makes the list usable. It used to be names only,
3358
+ * which asked the model to judge from a name alone whether `ref-data null
3359
+ * sentinel` bears on the question in front of it — and a wrong judgement is
3360
+ * silent, since it simply does not fetch. A line of prose per concept costs
3361
+ * a few tokens and is read rather than matched.
3362
+ *
3363
+ * Aliases stay, because they are how a user is likely to phrase it, and
3364
+ * showing them is what stops the LLM inventing a near-miss name.
3365
+ *
3279
3366
  * Not cached, for the same reason loadEntityCatalog isn't: unchanged rows
3280
3367
  * render byte-identical text so the prompt-cache prefix still hits, and a
3281
3368
  * process cache would only buy a window where a new concept is invisible.
@@ -3291,40 +3378,21 @@ declare class MainAgent {
3291
3378
  * Bodies ARE included here — unlike the catalog — because there is nothing to
3292
3379
  * request: being unrequestable is what makes them invariants.
3293
3380
  *
3294
- * Also retained into resolvedConcepts (same as an explicit resolve_concepts
3295
- * call) so these bodies reach SourceAgent's dispatch too — an invariant is
3296
- * meant to apply everywhere, not just wherever the model happens to ask for
3297
- * something whose `requires` chain reaches it.
3381
+ * Also retained into resolvedConcepts so these bodies reach SourceAgent's
3382
+ * dispatch too — an invariant is meant to apply everywhere, not just
3383
+ * wherever the model happens to ask for something whose `requires` chain
3384
+ * reaches it. This is now the ONLY way a concept body reaches
3385
+ * resolvedConcepts/SourceAgent's dispatch automatically — a non-invariant
3386
+ * concept fetched through a project's own concept-lookup tool (if any) is
3387
+ * NOT retained here, and will not reach a later SourceAgent dispatch unless
3388
+ * the model itself restates it in the intent it writes.
3298
3389
  */
3299
3390
  private loadConceptInvariants;
3300
- /**
3301
- * Resolve the concepts for a turn, with a SERVER-SIDE FLOOR.
3302
- *
3303
- * Pinning a tool guarantees it is called; it does not guarantee the model
3304
- * fills in the arguments. Observed: a question containing the exact words
3305
- * "revenue forecast" produced a call with no concepts at all, and the agent
3306
- * then used an incomplete copy of the formula from the knowledge base — the
3307
- * resulting query filtered a customer id against a project column and
3308
- * returned zero rows on every attempt.
3309
- *
3310
- * So when the model names nothing, scan the question itself for catalog names
3311
- * and aliases on word boundaries. Precise (a literal name is evidence, not a
3312
- * guess) and asymmetric in the safe direction: an unneeded definition costs a
3313
- * few hundred ignorable tokens, a missing one costs a wrong answer.
3314
- */
3315
- /**
3316
- * Returns the tool-facing fields to spread into the resolve_entities JSON
3317
- * response, PLUS a `_trace` field with everything the trace needs that the
3318
- * model does not (asked/viaFloor/unmatched). Callers must pull `_trace` out
3319
- * before spreading the rest into what the model sees — see handleResolveEntities.
3320
- */
3321
- private resolveConceptsForTurn;
3322
3391
  /**
3323
3392
  * Never throws: a concept-store outage must degrade to "no definition found"
3324
3393
  * and leave the agent deriving the formula as it does today, not take the
3325
3394
  * whole answer down.
3326
3395
  */
3327
- private handleResolveConcepts;
3328
3396
  /**
3329
3397
  * Compact catalog (type + gloss) for the system prompt. This is what lets the
3330
3398
  * LLM NAME a concept instead of guessing at our vocabulary — it can infer
@@ -3446,6 +3514,23 @@ interface LLMOptions {
3446
3514
  type: 'tool';
3447
3515
  name: string;
3448
3516
  };
3517
+ /**
3518
+ * Same forcing as `firstIterationToolChoice`, for the SECOND iteration only
3519
+ * (iteration 3+ reverts to auto, same as iteration 2+ does for the first-
3520
+ * iteration option). Added for MainAgent's `concept` tool: `resolve_entities`
3521
+ * being pinned to iteration 1 doesn't, by itself, make `concept` reliable —
3522
+ * confirmed live, repeatedly, that a model can skip it even with a CRITICAL
3523
+ * prompt instruction telling it not to. Pinning iteration 2 the same way
3524
+ * `resolve_entities` pins iteration 1 makes it structurally guaranteed
3525
+ * instead of prose-dependent. Honored on both the Anthropic and OpenAI/
3526
+ * OpenRouter paths, same as `firstIterationToolChoice`.
3527
+ */
3528
+ secondIterationToolChoice?: {
3529
+ type: 'any';
3530
+ } | {
3531
+ type: 'tool';
3532
+ name: string;
3533
+ };
3449
3534
  /**
3450
3535
  * Internal — set only by the OpenRouter wrappers when the target is a Claude
3451
3536
  * model. Tells the OpenAI-wire path to emit Anthropic `cache_control`
@@ -4825,6 +4910,7 @@ declare class QueryCache {
4825
4910
  private ttlMs;
4826
4911
  private maxCacheSize;
4827
4912
  private cleanupInterval;
4913
+ private resultCacheEnabled;
4828
4914
  private readonly algorithm;
4829
4915
  private encryptionKey;
4830
4916
  constructor();
@@ -4837,6 +4923,11 @@ declare class QueryCache {
4837
4923
  * Get the current TTL in minutes
4838
4924
  */
4839
4925
  getTTL(): number;
4926
+ /**
4927
+ * Stop keeping result data in memory, for a host that caches results itself.
4928
+ * `set` stores nothing and `get` finds nothing; queryId tokens are unaffected.
4929
+ */
4930
+ disableResultCache(): void;
4840
4931
  /**
4841
4932
  * Which access bucket this call reads and writes.
4842
4933
  *
@@ -5445,11 +5536,7 @@ declare function createCodexSession(opts: CodexSessionOptions): CodingAgentSessi
5445
5536
 
5446
5537
  /**
5447
5538
  * One transcript entry — everything worth replaying to a caller that reconnects
5448
- * mid-run or after the fact, without having sent the prompt itself. Deliberately
5449
- * a separate, richer shape from AgentEvent: that one only carries tool/command
5450
- * activity (what events()/buffer() below still expose, unchanged), not prompts
5451
- * or finished answers — which a reconnecting client needs too, per-turn, not as
5452
- * a flat concatenated buffer.
5539
+ * mid-run or after the fact, without having sent the prompt itself.
5453
5540
  */
5454
5541
  interface PiTranscriptEntry {
5455
5542
  at: number;
@@ -5464,16 +5551,9 @@ interface PiSessionState {
5464
5551
  transcript: PiTranscriptEntry[];
5465
5552
  }
5466
5553
  type PiSessionListener = (sessionKey: string, entry: PiTranscriptEntry) => void;
5467
- /** Watch every live pi session's activity, not just one you started yourself — same broadcast idea dashboard-pi uses so a second, later caller can watch a session already in progress. */
5554
+ /** Watch every live pi session's activity, not just one you started yourself. */
5468
5555
  declare function onPiSessionUpdate(listener: PiSessionListener): () => void;
5469
- /**
5470
- * Current state of a live session — for a caller that reconnects mid-run or
5471
- * wants to replay what happened, without sending a prompt itself.
5472
- *
5473
- * undefined when the session isn't live: never started, evicted by the idle
5474
- * sweeper, or the backend restarted. Same "lost the transcript, not the work"
5475
- * tradeoff as everywhere else in this driver — nothing here survives a restart.
5476
- */
5556
+ /** Current state of a live session; undefined once it is no longer in memory. */
5477
5557
  declare function getPiSessionState(sessionKey: string): PiSessionState | undefined;
5478
5558
 
5479
5559
  /**
@@ -6548,4 +6628,4 @@ declare class SuperatomSDK {
6548
6628
  getConversationSimilarityThreshold(): number;
6549
6629
  }
6550
6630
 
6551
- export { ALL_COLUMN_KEYS, ANSWER_COMPONENT_NAMES, type AgentConfig, type AgentEvent, type AgentResponse, type AgentRunContext, type AgentRunHandlers, type AgentRunRecord, type AgentRunResult, type AgentTrigger, type AgentUsage, type AnalyticsEventType, type AnalyticsStatus, type AnswerProvider, type AnswerProviderContext, type ApplySummary, BM25L, type BM25LOptions, type BaseLLMConfig, type BuildTriggerInput, CATEGORY_KEYS, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CodexSessionOptions, type CodingAgentCollectionConfig, type CodingAgentDefinition, type CodingAgentSession, type CodingAgentSessionOptions, type CodingAgentsConfig, type ColInfo, type ColType, type CollectionHandler, type CollectionOperation, type Component, type DBUIBlock, DEFAULT_AGENT_CONFIG, DEFAULT_FMT_CONFIG, type DashboardAgentCollectionConfig, type DatabaseType, type FindingCode, type Fmt, type FmtConfig, type Harness, type HybridSearchOptions, INSTRUCTIONS_FILE, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, MainAgent, type McpServerSpec, type Message, MissingRequestContextError, type ModelStrategy, NUMERIC_KEYS, type NarrationUpdate, type OutputContract, type OutputField, type OutputValidator, type PiSessionListener, type PiSessionState, type PiTranscriptEntry, type Principal, type RequestContext, type RerankedResult, type RowFilter, type RunAgentOptions, STORAGE_CONFIG, type ScriptComponentSpec, ScriptMatcher, type ScriptParameter, type ScriptRecipe, type ScriptRecipeMetaRow, type ScriptRecipeStore, type ScriptResult, ScriptStore, type ScriptStoreOptions, type SelectedWorkflow, type ShimDef, type ShimSummary, type ShimTarget, type SourcePolicy, type SpecToValidate, SuperatomSDK, type SuperatomSDKConfig, type T_RESPONSE, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, type TriggerEvent, type TriggerFireInfo, UIBlock, UILogCollector, type User, UserManager, type UsersData, type ValidationContext, type ValidationFinding, type WorkflowDescriptor, type Workspace, analyticsClient, answerCatalogForBinding, answerComponents, anthropicLLM, assertReadOnlySql, bindContext, bridgePreamble, captureContext, clearContextTokens, contextTokenCount, createCodexSession, createCodingAgentSession, dashboardConversationHistory, dataFingerprint, describeContext, describeTriggers, emitAgentEvent, extractNamedExport, formatFindingsForAgent, geminiLLM, getCodingAgent, getCodingAgentsConfig, getPiSessionState, getRequestContext, groqLLM, hybridRerank, inferColumns, isUserContext, listCodingAgents, llmUsageLogger, logger, makeFmt, mintContextToken, normalizeScriptBody, onAgentRun, onPiSessionUpdate, openaiLLM, policiesFromConfig, projectForDatasetBinding, promptLoader, queryCache, registerCodingAgentCollection, registerCodingAgents, registerDashboardAgentCollection, requireRequestContext, rerankChromaResults, rerankConversationResults, resolveContextToken, resolveScriptRecipeStore, revokeContextToken, runAsSystem, runAsUser, runCodingAgent, runScript, runWithContext, runWithMessageIdentity, startAgentTriggers, stopAgentTriggers, userPromptErrorLogger, validateComponentSpec, withCapturedContext, writeBridgeShims, writeShims };
6631
+ export { ALL_COLUMN_KEYS, ANSWER_COMPONENT_NAMES, type AgentConfig, type AgentEvent, type AgentResponse, type AgentRunContext, type AgentRunHandlers, type AgentRunRecord, type AgentRunResult, type AgentTrigger, type AgentUsage, type AnalyticsEventType, type AnalyticsStatus, type AnswerProvider, type AnswerProviderContext, type ApplySummary, BM25L, type BM25LOptions, type BaseLLMConfig, type BuildTriggerInput, CATEGORY_KEYS, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CodexSessionOptions, type CodingAgentCollectionConfig, type CodingAgentDefinition, type CodingAgentSession, type CodingAgentSessionOptions, type CodingAgentsConfig, type ColInfo, type ColType, type CollectionHandler, type CollectionOperation, type Component, type DBUIBlock, DEFAULT_AGENT_CONFIG, DEFAULT_FMT_CONFIG, type DashboardAgentCollectionConfig, type DatabaseType, type FindingCode, type Fmt, type FmtConfig, type Harness, type HybridSearchOptions, INSTRUCTIONS_FILE, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, MainAgent, type McpServerSpec, type Message, MissingRequestContextError, type ModelStrategy, NUMERIC_KEYS, type NarrationUpdate, type OutputContract, type OutputField, type OutputValidator, type PiSessionListener, type PiSessionState, type PiTranscriptEntry, type Principal, type PromptContext, type RequestContext, type RerankedResult, type RowFilter, type RunAgentOptions, STORAGE_CONFIG, type ScriptComponentSpec, ScriptMatcher, type ScriptParameter, type ScriptRecipe, type ScriptRecipeMetaRow, type ScriptRecipeStore, type ScriptResult, ScriptStore, type ScriptStoreOptions, type SelectedWorkflow, type ShimDef, type ShimSummary, type ShimTarget, type SourcePolicy, type SpecToValidate, SuperatomSDK, type SuperatomSDKConfig, type T_RESPONSE, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, type TriggerEvent, type TriggerFireInfo, UIBlock, UILogCollector, type User, UserManager, type UsersData, type ValidationContext, type ValidationFinding, type WorkflowDescriptor, type Workspace, analyticsClient, answerCatalogForBinding, answerComponents, anthropicLLM, assertReadOnlySql, bindContext, bridgePreamble, captureContext, clearContextTokens, contextTokenCount, createCodexSession, createCodingAgentSession, dashboardConversationHistory, dataFingerprint, describeContext, describeTriggers, emitAgentEvent, extractNamedExport, formatFindingsForAgent, geminiLLM, getCodingAgent, getCodingAgentsConfig, getPiSessionState, getRequestContext, groqLLM, hybridRerank, inferColumns, isUserContext, listCodingAgents, llmUsageLogger, logger, makeFmt, mintContextToken, normalizeScriptBody, onAgentRun, onPiSessionUpdate, openaiLLM, policiesFromConfig, projectForDatasetBinding, promptLoader, queryCache, registerCodingAgentCollection, registerCodingAgents, registerDashboardAgentCollection, requireRequestContext, rerankChromaResults, rerankConversationResults, resolveContextToken, resolveScriptRecipeStore, revokeContextToken, runAsSystem, runAsUser, runCodingAgent, runScript, runWithContext, runWithMessageIdentity, startAgentTriggers, stopAgentTriggers, userPromptErrorLogger, validateComponentSpec, withCapturedContext, writeBridgeShims, writeShims };
package/dist/index.d.ts CHANGED
@@ -1068,6 +1068,28 @@ interface RunTrace {
1068
1068
  note?: string;
1069
1069
  }>;
1070
1070
  };
1071
+ /**
1072
+ * Direct-tool activity this turn (main-agent.ts's handleDirectTool) — one
1073
+ * entry per direct-tool call, unconditional and generic across every
1074
+ * project's direct tools, not specific to one. For fusion-5's `concept`
1075
+ * tool this is what actually traces find/get/run (distinguished via
1076
+ * `input.method`) — unlike `concepts.calls` above, which only the
1077
+ * dashboard-agent flow's own, separate concept tool still populates;
1078
+ * MainAgent no longer resolves concepts itself, so nothing else writes
1079
+ * here for a chat/report turn.
1080
+ */
1081
+ directTools: {
1082
+ calls: Array<{
1083
+ toolId: string;
1084
+ /** Exact params the LLM called this tool with. */
1085
+ input: any;
1086
+ /** The tool's raw return value. Absent when `error` is set. */
1087
+ output?: any;
1088
+ /** Set whether the tool's own result carried an `error` field or the call threw. */
1089
+ error?: string;
1090
+ durationMs?: number;
1091
+ }>;
1092
+ };
1071
1093
  /**
1072
1094
  * The prior-turn conversation context injected into this turn's prompt as
1073
1095
  * CONVERSATION_HISTORY — exactly what each flow already builds for itself
@@ -1311,13 +1333,23 @@ declare class Logger {
1311
1333
  */
1312
1334
  debug(...args: any[]): void;
1313
1335
  /**
1314
- * Write to log file
1336
+ * Write to log file — each line timestamped so a request that made many
1337
+ * calls (LLM turns, tool dispatches, direct-tool runs) can be read back in
1338
+ * order, matching "know what happened when" rather than just "what
1339
+ * happened".
1315
1340
  */
1316
1341
  file(...args: any[]): void;
1342
+ /** The log file the current request is writing to — print/return this so it's easy to find afterward. */
1343
+ getCurrentLogFilePath(): string;
1317
1344
  /**
1318
- * Clear the log file (call at start of new user request)
1345
+ * Start a fresh, uniquely-named log file for a new top-level request
1346
+ * (chat turn, dashComp request, reportComp request, ...) instead of
1347
+ * truncating one shared file — pass a short label (a prompt snippet, a
1348
+ * request type) so the resulting filename is identifiable at a glance.
1349
+ * Falls back to the untimestamped legacy path when `label` is omitted, for
1350
+ * any caller not yet updated to pass one.
1319
1351
  */
1320
- clearFile(): void;
1352
+ clearFile(label?: string): void;
1321
1353
  /**
1322
1354
  * Log LLM method prompts with clear labeling
1323
1355
  */
@@ -2099,6 +2131,16 @@ interface DashCompModelConfig {
2099
2131
  */
2100
2132
  fastModel?: string;
2101
2133
  }
2134
+ /**
2135
+ * Where a question was asked from. Every field is optional; an empty object and
2136
+ * an absent context mean the same thing.
2137
+ */
2138
+ interface PromptContext {
2139
+ /** The dashboard on screen when the question was asked. */
2140
+ dashboardId?: string;
2141
+ /** The filter values set on that dashboard, keyed by parameter name. */
2142
+ filters?: Record<string, unknown>;
2143
+ }
2102
2144
  /**
2103
2145
  * Everything a replacement answer flow is handed for one question. Deliberately
2104
2146
  * the same material the built-in flow gets, so a provider is a drop-in and not a
@@ -2128,6 +2170,8 @@ interface AnswerProviderContext {
2128
2170
  text: string;
2129
2171
  }) => void;
2130
2172
  signal?: AbortSignal;
2173
+ /** Where the question was asked from, when the client said. */
2174
+ context?: PromptContext;
2131
2175
  }
2132
2176
  /**
2133
2177
  * One narrator tick while an answer was being produced: what the narrator was
@@ -2160,6 +2204,8 @@ interface NarrationUpdate {
2160
2204
  *
2161
2205
  * `data.narration` (NarrationUpdate[]) is optional and saved with the answer on
2162
2206
  * every outcome — success, error and abort — so return it on each of them.
2207
+ *
2208
+ * `data` may also carry `trace`, and `usage` and `model` per `AnswerProviderReport`.
2163
2209
  */
2164
2210
  type AnswerProvider = (ctx: AnswerProviderContext) => Promise<T_RESPONSE>;
2165
2211
  interface SuperatomSDKConfig {
@@ -2227,6 +2273,12 @@ interface SuperatomSDKConfig {
2227
2273
  * Default: 5 minutes
2228
2274
  */
2229
2275
  queryCacheTTL?: number;
2276
+ /**
2277
+ * Keep query results in the SDK's in-memory cache.
2278
+ * Set false when the host caches results itself; queryId tokens keep working.
2279
+ * Default: true
2280
+ */
2281
+ queryResultCache?: boolean;
2230
2282
  /**
2231
2283
  * Dashboard conversation history TTL (Time To Live) in minutes
2232
2284
  * Per-dashboard conversation histories expire after this duration
@@ -3104,9 +3156,11 @@ declare class MainAgent {
3104
3156
  */
3105
3157
  private resolvedEntities;
3106
3158
  /**
3107
- * Concept bodies resolved this turn (via resolve_entities' embedded concept
3108
- * lookup or a standalone resolve_concepts call) — retained the same way as
3109
- * resolvedEntities above, so they can be attached to the SourceAgent dispatch.
3159
+ * Concept bodies resolved this turn (currently: invariants only, via
3160
+ * loadConceptInvariants — concept resolution is no longer part of
3161
+ * resolve_entities or any other MainAgent-owned tool) — retained the same
3162
+ * way as resolvedEntities above, so they can be attached to the SourceAgent
3163
+ * dispatch.
3110
3164
  *
3111
3165
  * Without this, a concept resolved HERE (MainAgent's own tool loop) never
3112
3166
  * reaches SourceAgent at all: SourceAgent only gets the natural-language
@@ -3257,13 +3311,36 @@ declare class MainAgent {
3257
3311
  * it; scopeSql is the one thing worth this guarantee today.
3258
3312
  */
3259
3313
  private buildResolvedEntitiesBlock;
3260
- /** Dedupe-and-retain helper shared by resolveConceptsForTurn and handleResolveConcepts. */
3314
+ /**
3315
+ * Dedupe-and-retain helper shared by loadConceptInvariants and the generic
3316
+ * direct-tool `resolvedConcepts` opt-in hook. `alwaysInclude` marks entries
3317
+ * that buildResolvedConceptsBlock must attach to EVERY dispatch regardless
3318
+ * of that dispatch's `concepts` param — true only for invariants, which are
3319
+ * meant to apply everywhere by definition. Concepts retained without it
3320
+ * (e.g. via the `concept` tool's `get`) are scoped per-dispatch instead.
3321
+ */
3261
3322
  private retainResolvedConcepts;
3262
3323
  /**
3263
3324
  * Same purpose as buildResolvedEntitiesBlock, for concept bodies instead of
3264
3325
  * entity ids — appended to the dispatch intent so SourceAgent's own,
3265
3326
  * independent LLM call receives the resolved definitions verbatim rather
3266
3327
  * than only MainAgent's paraphrased intent text.
3328
+ *
3329
+ * Unlike buildResolvedEntitiesBlock, non-invariant entries here are SCOPED
3330
+ * to `names` (this dispatch's SourceToolInput.concepts) rather than
3331
+ * dumping the whole-turn `this.resolvedConcepts` accumulator into every
3332
+ * dispatch. A concept body is phrased as an authoritative override
3333
+ * ("overrides the schema... your own reasoning") — fetching several via
3334
+ * `get` to compare/discard, or a turn needing different concepts for
3335
+ * different sub-questions, must not leak an irrelevant concept's filters
3336
+ * into an unrelated dispatch. An entry not named in `names` and not
3337
+ * `alwaysInclude` is left out — a concept the model forgot to name is a
3338
+ * visible, fixable miss; one that leaks in uninvited is not.
3339
+ *
3340
+ * `alwaysInclude` entries (invariants — see loadConceptInvariants) bypass
3341
+ * `names` entirely and attach to every dispatch regardless, same as before
3342
+ * this method took a `names` param — they are meant to apply everywhere,
3343
+ * not just when the model happens to ask for them.
3267
3344
  */
3268
3345
  private buildResolvedConceptsBlock;
3269
3346
  /** True when the backend registered the entity-search collection. */
@@ -3271,11 +3348,21 @@ declare class MainAgent {
3271
3348
  /** True when the backend registered the concepts collection. */
3272
3349
  private get conceptsEnabled();
3273
3350
  /**
3274
- * Concept names for the system prompt. Names ONLY — the body comes back from
3351
+ * The concept catalog for the system prompt: one line per concept — name,
3352
+ * aliases, and what it is for. No bodies — the body comes back from
3275
3353
  * resolve_concepts once the LLM has named one, exactly as with the entity
3276
3354
  * catalog. Putting bodies here would rebuild the always-on context problem
3277
3355
  * concepts exist to solve.
3278
3356
  *
3357
+ * The description is what makes the list usable. It used to be names only,
3358
+ * which asked the model to judge from a name alone whether `ref-data null
3359
+ * sentinel` bears on the question in front of it — and a wrong judgement is
3360
+ * silent, since it simply does not fetch. A line of prose per concept costs
3361
+ * a few tokens and is read rather than matched.
3362
+ *
3363
+ * Aliases stay, because they are how a user is likely to phrase it, and
3364
+ * showing them is what stops the LLM inventing a near-miss name.
3365
+ *
3279
3366
  * Not cached, for the same reason loadEntityCatalog isn't: unchanged rows
3280
3367
  * render byte-identical text so the prompt-cache prefix still hits, and a
3281
3368
  * process cache would only buy a window where a new concept is invisible.
@@ -3291,40 +3378,21 @@ declare class MainAgent {
3291
3378
  * Bodies ARE included here — unlike the catalog — because there is nothing to
3292
3379
  * request: being unrequestable is what makes them invariants.
3293
3380
  *
3294
- * Also retained into resolvedConcepts (same as an explicit resolve_concepts
3295
- * call) so these bodies reach SourceAgent's dispatch too — an invariant is
3296
- * meant to apply everywhere, not just wherever the model happens to ask for
3297
- * something whose `requires` chain reaches it.
3381
+ * Also retained into resolvedConcepts so these bodies reach SourceAgent's
3382
+ * dispatch too — an invariant is meant to apply everywhere, not just
3383
+ * wherever the model happens to ask for something whose `requires` chain
3384
+ * reaches it. This is now the ONLY way a concept body reaches
3385
+ * resolvedConcepts/SourceAgent's dispatch automatically — a non-invariant
3386
+ * concept fetched through a project's own concept-lookup tool (if any) is
3387
+ * NOT retained here, and will not reach a later SourceAgent dispatch unless
3388
+ * the model itself restates it in the intent it writes.
3298
3389
  */
3299
3390
  private loadConceptInvariants;
3300
- /**
3301
- * Resolve the concepts for a turn, with a SERVER-SIDE FLOOR.
3302
- *
3303
- * Pinning a tool guarantees it is called; it does not guarantee the model
3304
- * fills in the arguments. Observed: a question containing the exact words
3305
- * "revenue forecast" produced a call with no concepts at all, and the agent
3306
- * then used an incomplete copy of the formula from the knowledge base — the
3307
- * resulting query filtered a customer id against a project column and
3308
- * returned zero rows on every attempt.
3309
- *
3310
- * So when the model names nothing, scan the question itself for catalog names
3311
- * and aliases on word boundaries. Precise (a literal name is evidence, not a
3312
- * guess) and asymmetric in the safe direction: an unneeded definition costs a
3313
- * few hundred ignorable tokens, a missing one costs a wrong answer.
3314
- */
3315
- /**
3316
- * Returns the tool-facing fields to spread into the resolve_entities JSON
3317
- * response, PLUS a `_trace` field with everything the trace needs that the
3318
- * model does not (asked/viaFloor/unmatched). Callers must pull `_trace` out
3319
- * before spreading the rest into what the model sees — see handleResolveEntities.
3320
- */
3321
- private resolveConceptsForTurn;
3322
3391
  /**
3323
3392
  * Never throws: a concept-store outage must degrade to "no definition found"
3324
3393
  * and leave the agent deriving the formula as it does today, not take the
3325
3394
  * whole answer down.
3326
3395
  */
3327
- private handleResolveConcepts;
3328
3396
  /**
3329
3397
  * Compact catalog (type + gloss) for the system prompt. This is what lets the
3330
3398
  * LLM NAME a concept instead of guessing at our vocabulary — it can infer
@@ -3446,6 +3514,23 @@ interface LLMOptions {
3446
3514
  type: 'tool';
3447
3515
  name: string;
3448
3516
  };
3517
+ /**
3518
+ * Same forcing as `firstIterationToolChoice`, for the SECOND iteration only
3519
+ * (iteration 3+ reverts to auto, same as iteration 2+ does for the first-
3520
+ * iteration option). Added for MainAgent's `concept` tool: `resolve_entities`
3521
+ * being pinned to iteration 1 doesn't, by itself, make `concept` reliable —
3522
+ * confirmed live, repeatedly, that a model can skip it even with a CRITICAL
3523
+ * prompt instruction telling it not to. Pinning iteration 2 the same way
3524
+ * `resolve_entities` pins iteration 1 makes it structurally guaranteed
3525
+ * instead of prose-dependent. Honored on both the Anthropic and OpenAI/
3526
+ * OpenRouter paths, same as `firstIterationToolChoice`.
3527
+ */
3528
+ secondIterationToolChoice?: {
3529
+ type: 'any';
3530
+ } | {
3531
+ type: 'tool';
3532
+ name: string;
3533
+ };
3449
3534
  /**
3450
3535
  * Internal — set only by the OpenRouter wrappers when the target is a Claude
3451
3536
  * model. Tells the OpenAI-wire path to emit Anthropic `cache_control`
@@ -4825,6 +4910,7 @@ declare class QueryCache {
4825
4910
  private ttlMs;
4826
4911
  private maxCacheSize;
4827
4912
  private cleanupInterval;
4913
+ private resultCacheEnabled;
4828
4914
  private readonly algorithm;
4829
4915
  private encryptionKey;
4830
4916
  constructor();
@@ -4837,6 +4923,11 @@ declare class QueryCache {
4837
4923
  * Get the current TTL in minutes
4838
4924
  */
4839
4925
  getTTL(): number;
4926
+ /**
4927
+ * Stop keeping result data in memory, for a host that caches results itself.
4928
+ * `set` stores nothing and `get` finds nothing; queryId tokens are unaffected.
4929
+ */
4930
+ disableResultCache(): void;
4840
4931
  /**
4841
4932
  * Which access bucket this call reads and writes.
4842
4933
  *
@@ -5445,11 +5536,7 @@ declare function createCodexSession(opts: CodexSessionOptions): CodingAgentSessi
5445
5536
 
5446
5537
  /**
5447
5538
  * One transcript entry — everything worth replaying to a caller that reconnects
5448
- * mid-run or after the fact, without having sent the prompt itself. Deliberately
5449
- * a separate, richer shape from AgentEvent: that one only carries tool/command
5450
- * activity (what events()/buffer() below still expose, unchanged), not prompts
5451
- * or finished answers — which a reconnecting client needs too, per-turn, not as
5452
- * a flat concatenated buffer.
5539
+ * mid-run or after the fact, without having sent the prompt itself.
5453
5540
  */
5454
5541
  interface PiTranscriptEntry {
5455
5542
  at: number;
@@ -5464,16 +5551,9 @@ interface PiSessionState {
5464
5551
  transcript: PiTranscriptEntry[];
5465
5552
  }
5466
5553
  type PiSessionListener = (sessionKey: string, entry: PiTranscriptEntry) => void;
5467
- /** Watch every live pi session's activity, not just one you started yourself — same broadcast idea dashboard-pi uses so a second, later caller can watch a session already in progress. */
5554
+ /** Watch every live pi session's activity, not just one you started yourself. */
5468
5555
  declare function onPiSessionUpdate(listener: PiSessionListener): () => void;
5469
- /**
5470
- * Current state of a live session — for a caller that reconnects mid-run or
5471
- * wants to replay what happened, without sending a prompt itself.
5472
- *
5473
- * undefined when the session isn't live: never started, evicted by the idle
5474
- * sweeper, or the backend restarted. Same "lost the transcript, not the work"
5475
- * tradeoff as everywhere else in this driver — nothing here survives a restart.
5476
- */
5556
+ /** Current state of a live session; undefined once it is no longer in memory. */
5477
5557
  declare function getPiSessionState(sessionKey: string): PiSessionState | undefined;
5478
5558
 
5479
5559
  /**
@@ -6548,4 +6628,4 @@ declare class SuperatomSDK {
6548
6628
  getConversationSimilarityThreshold(): number;
6549
6629
  }
6550
6630
 
6551
- export { ALL_COLUMN_KEYS, ANSWER_COMPONENT_NAMES, type AgentConfig, type AgentEvent, type AgentResponse, type AgentRunContext, type AgentRunHandlers, type AgentRunRecord, type AgentRunResult, type AgentTrigger, type AgentUsage, type AnalyticsEventType, type AnalyticsStatus, type AnswerProvider, type AnswerProviderContext, type ApplySummary, BM25L, type BM25LOptions, type BaseLLMConfig, type BuildTriggerInput, CATEGORY_KEYS, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CodexSessionOptions, type CodingAgentCollectionConfig, type CodingAgentDefinition, type CodingAgentSession, type CodingAgentSessionOptions, type CodingAgentsConfig, type ColInfo, type ColType, type CollectionHandler, type CollectionOperation, type Component, type DBUIBlock, DEFAULT_AGENT_CONFIG, DEFAULT_FMT_CONFIG, type DashboardAgentCollectionConfig, type DatabaseType, type FindingCode, type Fmt, type FmtConfig, type Harness, type HybridSearchOptions, INSTRUCTIONS_FILE, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, MainAgent, type McpServerSpec, type Message, MissingRequestContextError, type ModelStrategy, NUMERIC_KEYS, type NarrationUpdate, type OutputContract, type OutputField, type OutputValidator, type PiSessionListener, type PiSessionState, type PiTranscriptEntry, type Principal, type RequestContext, type RerankedResult, type RowFilter, type RunAgentOptions, STORAGE_CONFIG, type ScriptComponentSpec, ScriptMatcher, type ScriptParameter, type ScriptRecipe, type ScriptRecipeMetaRow, type ScriptRecipeStore, type ScriptResult, ScriptStore, type ScriptStoreOptions, type SelectedWorkflow, type ShimDef, type ShimSummary, type ShimTarget, type SourcePolicy, type SpecToValidate, SuperatomSDK, type SuperatomSDKConfig, type T_RESPONSE, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, type TriggerEvent, type TriggerFireInfo, UIBlock, UILogCollector, type User, UserManager, type UsersData, type ValidationContext, type ValidationFinding, type WorkflowDescriptor, type Workspace, analyticsClient, answerCatalogForBinding, answerComponents, anthropicLLM, assertReadOnlySql, bindContext, bridgePreamble, captureContext, clearContextTokens, contextTokenCount, createCodexSession, createCodingAgentSession, dashboardConversationHistory, dataFingerprint, describeContext, describeTriggers, emitAgentEvent, extractNamedExport, formatFindingsForAgent, geminiLLM, getCodingAgent, getCodingAgentsConfig, getPiSessionState, getRequestContext, groqLLM, hybridRerank, inferColumns, isUserContext, listCodingAgents, llmUsageLogger, logger, makeFmt, mintContextToken, normalizeScriptBody, onAgentRun, onPiSessionUpdate, openaiLLM, policiesFromConfig, projectForDatasetBinding, promptLoader, queryCache, registerCodingAgentCollection, registerCodingAgents, registerDashboardAgentCollection, requireRequestContext, rerankChromaResults, rerankConversationResults, resolveContextToken, resolveScriptRecipeStore, revokeContextToken, runAsSystem, runAsUser, runCodingAgent, runScript, runWithContext, runWithMessageIdentity, startAgentTriggers, stopAgentTriggers, userPromptErrorLogger, validateComponentSpec, withCapturedContext, writeBridgeShims, writeShims };
6631
+ export { ALL_COLUMN_KEYS, ANSWER_COMPONENT_NAMES, type AgentConfig, type AgentEvent, type AgentResponse, type AgentRunContext, type AgentRunHandlers, type AgentRunRecord, type AgentRunResult, type AgentTrigger, type AgentUsage, type AnalyticsEventType, type AnalyticsStatus, type AnswerProvider, type AnswerProviderContext, type ApplySummary, BM25L, type BM25LOptions, type BaseLLMConfig, type BuildTriggerInput, CATEGORY_KEYS, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CodexSessionOptions, type CodingAgentCollectionConfig, type CodingAgentDefinition, type CodingAgentSession, type CodingAgentSessionOptions, type CodingAgentsConfig, type ColInfo, type ColType, type CollectionHandler, type CollectionOperation, type Component, type DBUIBlock, DEFAULT_AGENT_CONFIG, DEFAULT_FMT_CONFIG, type DashboardAgentCollectionConfig, type DatabaseType, type FindingCode, type Fmt, type FmtConfig, type Harness, type HybridSearchOptions, INSTRUCTIONS_FILE, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LLMUsageEntry, type LogLevel, MainAgent, type McpServerSpec, type Message, MissingRequestContextError, type ModelStrategy, NUMERIC_KEYS, type NarrationUpdate, type OutputContract, type OutputField, type OutputValidator, type PiSessionListener, type PiSessionState, type PiTranscriptEntry, type Principal, type PromptContext, type RequestContext, type RerankedResult, type RowFilter, type RunAgentOptions, STORAGE_CONFIG, type ScriptComponentSpec, ScriptMatcher, type ScriptParameter, type ScriptRecipe, type ScriptRecipeMetaRow, type ScriptRecipeStore, type ScriptResult, ScriptStore, type ScriptStoreOptions, type SelectedWorkflow, type ShimDef, type ShimSummary, type ShimTarget, type SourcePolicy, type SpecToValidate, SuperatomSDK, type SuperatomSDKConfig, type T_RESPONSE, type TaskType, Thread, ThreadManager, type Tool$1 as Tool, type ToolOutputSchema, type TriggerEvent, type TriggerFireInfo, UIBlock, UILogCollector, type User, UserManager, type UsersData, type ValidationContext, type ValidationFinding, type WorkflowDescriptor, type Workspace, analyticsClient, answerCatalogForBinding, answerComponents, anthropicLLM, assertReadOnlySql, bindContext, bridgePreamble, captureContext, clearContextTokens, contextTokenCount, createCodexSession, createCodingAgentSession, dashboardConversationHistory, dataFingerprint, describeContext, describeTriggers, emitAgentEvent, extractNamedExport, formatFindingsForAgent, geminiLLM, getCodingAgent, getCodingAgentsConfig, getPiSessionState, getRequestContext, groqLLM, hybridRerank, inferColumns, isUserContext, listCodingAgents, llmUsageLogger, logger, makeFmt, mintContextToken, normalizeScriptBody, onAgentRun, onPiSessionUpdate, openaiLLM, policiesFromConfig, projectForDatasetBinding, promptLoader, queryCache, registerCodingAgentCollection, registerCodingAgents, registerDashboardAgentCollection, requireRequestContext, rerankChromaResults, rerankConversationResults, resolveContextToken, resolveScriptRecipeStore, revokeContextToken, runAsSystem, runAsUser, runCodingAgent, runScript, runWithContext, runWithMessageIdentity, startAgentTriggers, stopAgentTriggers, userPromptErrorLogger, validateComponentSpec, withCapturedContext, writeBridgeShims, writeShims };