@superatomai/sdk-node 0.0.8-s → 0.0.9-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
@@ -1406,6 +1406,10 @@ interface ExecutedToolInfo {
1406
1406
  _recordsShown: number;
1407
1407
  _metadata?: any;
1408
1408
  _sampleData: any[];
1409
+ /** Bounded summary over the FULL fetched result (complete structure). */
1410
+ _summary?: any;
1411
+ /** Up to MAIN_AGENT_COMPLETE_ROWS rows — the complete result when small. */
1412
+ _mainAgentRows?: any[];
1409
1413
  };
1410
1414
  outputSchema?: any;
1411
1415
  sourceSchema?: string;
@@ -1619,8 +1623,16 @@ interface AgentWrittenScript {
1619
1623
  * Controls limits, models, and behavior.
1620
1624
  */
1621
1625
  interface AgentConfig {
1622
- /** Max rows a source agent can return (default: 50) */
1626
+ /** Max rows shown to the UI preview / inlined per source (default: 10) */
1623
1627
  maxRowsPerSource: number;
1628
+ /**
1629
+ * Max rows a source query may FETCH from the DB server-side (default: 2000).
1630
+ * Decoupled from what the main agent is shown: the full result is fetched and
1631
+ * summarized (bounded), but only a small/complete slice enters LLM context.
1632
+ * This lets small lookups (benchmark maps) arrive COMPLETE without letting
1633
+ * large results blow up context.
1634
+ */
1635
+ maxRowsFetched: number;
1624
1636
  /** Model for the main agent (routing + analysis in one LLM call) */
1625
1637
  mainAgentModel: string;
1626
1638
  /** Model for source agent query generation */
@@ -1773,10 +1785,12 @@ interface ScriptParameter {
1773
1785
  interface ScriptComponentSpec {
1774
1786
  /** Registered component name (e.g. "DynamicBarChart") — matched against the available component library. */
1775
1787
  componentType: string;
1776
- /** `executedQuery.sourceId` to bind to (e.g. a tool id or 'computed:_final'), or 'federation' for a cross-source component. */
1788
+ /** `executedQuery.sourceId` to bind to (e.g. a tool id or 'computed:_final'), 'federation' for a cross-source component, or 'markdown' for a content-only narrative block (no data source). */
1777
1789
  sourceRef: string;
1778
1790
  /** Present only when sourceRef === 'federation' — the DuckDB SQL to re-execute on replay. */
1779
1791
  federationSql?: string;
1792
+ /** Present only when sourceRef === 'markdown' — the narrative text to render on replay (markdown has no data source, so its content must be persisted). */
1793
+ content?: string;
1780
1794
  title?: string;
1781
1795
  description?: string;
1782
1796
  /** Validated axis/value keys + aggregation — all referencing real columns of the bound source. */
@@ -2115,7 +2129,16 @@ declare class MainAgent {
2115
2129
  private turnId;
2116
2130
  private createdFromPrompt;
2117
2131
  private scriptState;
2118
- constructor(externalTools: ExternalTool[], config: AgentConfig, scriptStore?: ScriptStore, turnId?: string, streamBuffer?: StreamBuffer, workflows?: WorkflowDescriptor[]);
2132
+ /**
2133
+ * Fork mode — set when this turn is adapting a near-matching parent script.
2134
+ * In fork mode there is no legitimate "answer with bare text" outcome: the
2135
+ * only correct first move is a tool call (write_script, or a source tool for
2136
+ * schema discovery). We therefore force tool use on the first LLM iteration
2137
+ * so the model can't end its turn with a bare "I'll adapt…" preamble and zero
2138
+ * tool calls. Never set on the fresh-authoring / general-question path.
2139
+ */
2140
+ private forkMode;
2141
+ constructor(externalTools: ExternalTool[], config: AgentConfig, scriptStore?: ScriptStore, turnId?: string, streamBuffer?: StreamBuffer, workflows?: WorkflowDescriptor[], forkMode?: boolean);
2119
2142
  private get scriptingEnabled();
2120
2143
  /**
2121
2144
  * Handle a user question using the multi-agent system.
@@ -2212,7 +2235,37 @@ interface LLMOptions {
2212
2235
  temperature?: number;
2213
2236
  topP?: number;
2214
2237
  apiKey?: string;
2238
+ baseURL?: string;
2215
2239
  partial?: (chunk: string) => void;
2240
+ /**
2241
+ * Forces a tool call on the FIRST iteration of streamWithTools only
2242
+ * (subsequent iterations revert to auto). Used by fork mode to stop the
2243
+ * model from ending its turn with a bare "I'll adapt the script…" preamble
2244
+ * and zero tool calls. `{ type: 'any' }` lets the model pick which tool
2245
+ * (write_script in the common case, a source tool for schema discovery);
2246
+ * `{ type: 'tool', name }` pins a specific tool. Honored on both the
2247
+ * Anthropic path and the OpenAI/OpenRouter path (mapped to OpenAI's
2248
+ * tool_choice: 'required' / a named function).
2249
+ */
2250
+ firstIterationToolChoice?: {
2251
+ type: 'any';
2252
+ } | {
2253
+ type: 'tool';
2254
+ name: string;
2255
+ };
2256
+ /**
2257
+ * Internal — set only by the OpenRouter wrappers when the target is a Claude
2258
+ * model. Tells the OpenAI-wire path to emit Anthropic `cache_control`
2259
+ * breakpoints (OpenRouter forwards them to Anthropic for prompt caching).
2260
+ * Never set for direct OpenAI/Groq calls, so their requests are unchanged.
2261
+ */
2262
+ _openrouterClaudeCaching?: boolean;
2263
+ /**
2264
+ * Internal — OpenRouter provider-routing preferences (forwarded as the
2265
+ * `provider` body field). Set by the OpenRouter wrappers to steer routing to
2266
+ * a fast backend (e.g. {sort:'throughput'}). Never set for direct OpenAI/Groq.
2267
+ */
2268
+ _openrouterProvider?: Record<string, unknown>;
2216
2269
  }
2217
2270
  interface Tool {
2218
2271
  name: string;
@@ -2260,11 +2313,44 @@ declare class LLM {
2260
2313
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
2261
2314
  */
2262
2315
  private static _parseModel;
2316
+ /**
2317
+ * Map an Anthropic model id (e.g. "claude-sonnet-4-5-20250929") to the OpenRouter slug
2318
+ * (e.g. "claude-sonnet-4.5"). OpenRouter slugs drop the date suffix and use dotted versions.
2319
+ */
2320
+ private static _toOpenRouterSlug;
2321
+ /**
2322
+ * Per-provider proxy base URL. Returns `${SUPERATOM_LLM_PROXY_URL}/<provider>`
2323
+ * when our Cloudflare LLM proxy is configured, else undefined (→ talk to the
2324
+ * provider directly, legacy behaviour). An explicit options.baseURL (e.g.
2325
+ * OpenRouter) always wins and is never overridden. See backend/docs/llm-proxy.md.
2326
+ */
2327
+ private static _proxyBaseURL;
2328
+ private static _openrouterOptions;
2329
+ private static _openrouterText;
2330
+ private static _openrouterStream;
2331
+ private static _openrouterStreamWithTools;
2332
+ /**
2333
+ * Build an Anthropic client. Routes through our Cloudflare LLM proxy when
2334
+ * SUPERATOM_LLM_PROXY_URL is set (each client ships a per-client proxy key as
2335
+ * ANTHROPIC_API_KEY and never holds the real key); otherwise talks to
2336
+ * api.anthropic.com directly. See backend/docs/llm-proxy.md.
2337
+ */
2338
+ private static _anthropicClient;
2339
+ /** True when OpenRouter is configured as a fail-open fallback for Claude. */
2340
+ private static _openrouterAvailable;
2341
+ /** Remap an Anthropic model id to the OpenRouter model path for fail-open. */
2342
+ private static _anthropicFallbackModel;
2263
2343
  private static _anthropicText;
2264
2344
  private static _anthropicStream;
2265
2345
  private static _anthropicStreamWithTools;
2266
2346
  private static _groqText;
2267
2347
  private static _groqStream;
2348
+ /**
2349
+ * Gemini request options carrying the proxy base URL, or undefined → talk to
2350
+ * generativelanguage.googleapis.com directly. The Google SDK takes baseUrl as a
2351
+ * per-model request option, not a constructor arg. See backend/docs/llm-proxy.md.
2352
+ */
2353
+ private static _geminiRequestOptions;
2268
2354
  private static _geminiText;
2269
2355
  private static _geminiStream;
2270
2356
  /**
@@ -2273,8 +2359,28 @@ declare class LLM {
2273
2359
  */
2274
2360
  private static _cleanSchemaForGemini;
2275
2361
  private static _geminiStreamWithTools;
2362
+ /** True for Anthropic/Claude model ids — gates OpenRouter prompt caching. */
2363
+ private static _isClaudeModel;
2364
+ /**
2365
+ * Build the OpenAI-wire system message. For OpenRouter + Claude
2366
+ * (cacheClaude=true) it emits content parts carrying Anthropic
2367
+ * `cache_control` breakpoints (preserving any the caller set, else marking
2368
+ * the last block), so OpenRouter forwards them to Anthropic for prompt
2369
+ * caching. Otherwise it returns a plain flattened string — unchanged for
2370
+ * direct OpenAI/Groq.
2371
+ */
2372
+ private static _openaiSystemMessage;
2373
+ /**
2374
+ * Split an OpenAI-wire usage object. `prompt_tokens` INCLUDES cached tokens,
2375
+ * so we subtract them out (Anthropic-style: input excludes cache reads) and
2376
+ * report cached separately — this makes calculateCost price cache reads at
2377
+ * the discounted rate and reflects OpenRouter prompt-cache savings in logs.
2378
+ */
2379
+ private static _openaiUsage;
2276
2380
  private static _openaiText;
2277
2381
  private static _openaiStream;
2382
+ /** Map the Anthropic-style firstIterationToolChoice to OpenAI's tool_choice. */
2383
+ private static _openaiToolChoice;
2278
2384
  private static _openaiStreamWithTools;
2279
2385
  /**
2280
2386
  * Parse JSON string, handling markdown code blocks and surrounding text
package/dist/index.d.ts CHANGED
@@ -1406,6 +1406,10 @@ interface ExecutedToolInfo {
1406
1406
  _recordsShown: number;
1407
1407
  _metadata?: any;
1408
1408
  _sampleData: any[];
1409
+ /** Bounded summary over the FULL fetched result (complete structure). */
1410
+ _summary?: any;
1411
+ /** Up to MAIN_AGENT_COMPLETE_ROWS rows — the complete result when small. */
1412
+ _mainAgentRows?: any[];
1409
1413
  };
1410
1414
  outputSchema?: any;
1411
1415
  sourceSchema?: string;
@@ -1619,8 +1623,16 @@ interface AgentWrittenScript {
1619
1623
  * Controls limits, models, and behavior.
1620
1624
  */
1621
1625
  interface AgentConfig {
1622
- /** Max rows a source agent can return (default: 50) */
1626
+ /** Max rows shown to the UI preview / inlined per source (default: 10) */
1623
1627
  maxRowsPerSource: number;
1628
+ /**
1629
+ * Max rows a source query may FETCH from the DB server-side (default: 2000).
1630
+ * Decoupled from what the main agent is shown: the full result is fetched and
1631
+ * summarized (bounded), but only a small/complete slice enters LLM context.
1632
+ * This lets small lookups (benchmark maps) arrive COMPLETE without letting
1633
+ * large results blow up context.
1634
+ */
1635
+ maxRowsFetched: number;
1624
1636
  /** Model for the main agent (routing + analysis in one LLM call) */
1625
1637
  mainAgentModel: string;
1626
1638
  /** Model for source agent query generation */
@@ -1773,10 +1785,12 @@ interface ScriptParameter {
1773
1785
  interface ScriptComponentSpec {
1774
1786
  /** Registered component name (e.g. "DynamicBarChart") — matched against the available component library. */
1775
1787
  componentType: string;
1776
- /** `executedQuery.sourceId` to bind to (e.g. a tool id or 'computed:_final'), or 'federation' for a cross-source component. */
1788
+ /** `executedQuery.sourceId` to bind to (e.g. a tool id or 'computed:_final'), 'federation' for a cross-source component, or 'markdown' for a content-only narrative block (no data source). */
1777
1789
  sourceRef: string;
1778
1790
  /** Present only when sourceRef === 'federation' — the DuckDB SQL to re-execute on replay. */
1779
1791
  federationSql?: string;
1792
+ /** Present only when sourceRef === 'markdown' — the narrative text to render on replay (markdown has no data source, so its content must be persisted). */
1793
+ content?: string;
1780
1794
  title?: string;
1781
1795
  description?: string;
1782
1796
  /** Validated axis/value keys + aggregation — all referencing real columns of the bound source. */
@@ -2115,7 +2129,16 @@ declare class MainAgent {
2115
2129
  private turnId;
2116
2130
  private createdFromPrompt;
2117
2131
  private scriptState;
2118
- constructor(externalTools: ExternalTool[], config: AgentConfig, scriptStore?: ScriptStore, turnId?: string, streamBuffer?: StreamBuffer, workflows?: WorkflowDescriptor[]);
2132
+ /**
2133
+ * Fork mode — set when this turn is adapting a near-matching parent script.
2134
+ * In fork mode there is no legitimate "answer with bare text" outcome: the
2135
+ * only correct first move is a tool call (write_script, or a source tool for
2136
+ * schema discovery). We therefore force tool use on the first LLM iteration
2137
+ * so the model can't end its turn with a bare "I'll adapt…" preamble and zero
2138
+ * tool calls. Never set on the fresh-authoring / general-question path.
2139
+ */
2140
+ private forkMode;
2141
+ constructor(externalTools: ExternalTool[], config: AgentConfig, scriptStore?: ScriptStore, turnId?: string, streamBuffer?: StreamBuffer, workflows?: WorkflowDescriptor[], forkMode?: boolean);
2119
2142
  private get scriptingEnabled();
2120
2143
  /**
2121
2144
  * Handle a user question using the multi-agent system.
@@ -2212,7 +2235,37 @@ interface LLMOptions {
2212
2235
  temperature?: number;
2213
2236
  topP?: number;
2214
2237
  apiKey?: string;
2238
+ baseURL?: string;
2215
2239
  partial?: (chunk: string) => void;
2240
+ /**
2241
+ * Forces a tool call on the FIRST iteration of streamWithTools only
2242
+ * (subsequent iterations revert to auto). Used by fork mode to stop the
2243
+ * model from ending its turn with a bare "I'll adapt the script…" preamble
2244
+ * and zero tool calls. `{ type: 'any' }` lets the model pick which tool
2245
+ * (write_script in the common case, a source tool for schema discovery);
2246
+ * `{ type: 'tool', name }` pins a specific tool. Honored on both the
2247
+ * Anthropic path and the OpenAI/OpenRouter path (mapped to OpenAI's
2248
+ * tool_choice: 'required' / a named function).
2249
+ */
2250
+ firstIterationToolChoice?: {
2251
+ type: 'any';
2252
+ } | {
2253
+ type: 'tool';
2254
+ name: string;
2255
+ };
2256
+ /**
2257
+ * Internal — set only by the OpenRouter wrappers when the target is a Claude
2258
+ * model. Tells the OpenAI-wire path to emit Anthropic `cache_control`
2259
+ * breakpoints (OpenRouter forwards them to Anthropic for prompt caching).
2260
+ * Never set for direct OpenAI/Groq calls, so their requests are unchanged.
2261
+ */
2262
+ _openrouterClaudeCaching?: boolean;
2263
+ /**
2264
+ * Internal — OpenRouter provider-routing preferences (forwarded as the
2265
+ * `provider` body field). Set by the OpenRouter wrappers to steer routing to
2266
+ * a fast backend (e.g. {sort:'throughput'}). Never set for direct OpenAI/Groq.
2267
+ */
2268
+ _openrouterProvider?: Record<string, unknown>;
2216
2269
  }
2217
2270
  interface Tool {
2218
2271
  name: string;
@@ -2260,11 +2313,44 @@ declare class LLM {
2260
2313
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
2261
2314
  */
2262
2315
  private static _parseModel;
2316
+ /**
2317
+ * Map an Anthropic model id (e.g. "claude-sonnet-4-5-20250929") to the OpenRouter slug
2318
+ * (e.g. "claude-sonnet-4.5"). OpenRouter slugs drop the date suffix and use dotted versions.
2319
+ */
2320
+ private static _toOpenRouterSlug;
2321
+ /**
2322
+ * Per-provider proxy base URL. Returns `${SUPERATOM_LLM_PROXY_URL}/<provider>`
2323
+ * when our Cloudflare LLM proxy is configured, else undefined (→ talk to the
2324
+ * provider directly, legacy behaviour). An explicit options.baseURL (e.g.
2325
+ * OpenRouter) always wins and is never overridden. See backend/docs/llm-proxy.md.
2326
+ */
2327
+ private static _proxyBaseURL;
2328
+ private static _openrouterOptions;
2329
+ private static _openrouterText;
2330
+ private static _openrouterStream;
2331
+ private static _openrouterStreamWithTools;
2332
+ /**
2333
+ * Build an Anthropic client. Routes through our Cloudflare LLM proxy when
2334
+ * SUPERATOM_LLM_PROXY_URL is set (each client ships a per-client proxy key as
2335
+ * ANTHROPIC_API_KEY and never holds the real key); otherwise talks to
2336
+ * api.anthropic.com directly. See backend/docs/llm-proxy.md.
2337
+ */
2338
+ private static _anthropicClient;
2339
+ /** True when OpenRouter is configured as a fail-open fallback for Claude. */
2340
+ private static _openrouterAvailable;
2341
+ /** Remap an Anthropic model id to the OpenRouter model path for fail-open. */
2342
+ private static _anthropicFallbackModel;
2263
2343
  private static _anthropicText;
2264
2344
  private static _anthropicStream;
2265
2345
  private static _anthropicStreamWithTools;
2266
2346
  private static _groqText;
2267
2347
  private static _groqStream;
2348
+ /**
2349
+ * Gemini request options carrying the proxy base URL, or undefined → talk to
2350
+ * generativelanguage.googleapis.com directly. The Google SDK takes baseUrl as a
2351
+ * per-model request option, not a constructor arg. See backend/docs/llm-proxy.md.
2352
+ */
2353
+ private static _geminiRequestOptions;
2268
2354
  private static _geminiText;
2269
2355
  private static _geminiStream;
2270
2356
  /**
@@ -2273,8 +2359,28 @@ declare class LLM {
2273
2359
  */
2274
2360
  private static _cleanSchemaForGemini;
2275
2361
  private static _geminiStreamWithTools;
2362
+ /** True for Anthropic/Claude model ids — gates OpenRouter prompt caching. */
2363
+ private static _isClaudeModel;
2364
+ /**
2365
+ * Build the OpenAI-wire system message. For OpenRouter + Claude
2366
+ * (cacheClaude=true) it emits content parts carrying Anthropic
2367
+ * `cache_control` breakpoints (preserving any the caller set, else marking
2368
+ * the last block), so OpenRouter forwards them to Anthropic for prompt
2369
+ * caching. Otherwise it returns a plain flattened string — unchanged for
2370
+ * direct OpenAI/Groq.
2371
+ */
2372
+ private static _openaiSystemMessage;
2373
+ /**
2374
+ * Split an OpenAI-wire usage object. `prompt_tokens` INCLUDES cached tokens,
2375
+ * so we subtract them out (Anthropic-style: input excludes cache reads) and
2376
+ * report cached separately — this makes calculateCost price cache reads at
2377
+ * the discounted rate and reflects OpenRouter prompt-cache savings in logs.
2378
+ */
2379
+ private static _openaiUsage;
2276
2380
  private static _openaiText;
2277
2381
  private static _openaiStream;
2382
+ /** Map the Anthropic-style firstIterationToolChoice to OpenAI's tool_choice. */
2383
+ private static _openaiToolChoice;
2278
2384
  private static _openaiStreamWithTools;
2279
2385
  /**
2280
2386
  * Parse JSON string, handling markdown code blocks and surrounding text