@umituz/web-ai 1.0.6 → 1.0.7

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.
@@ -1,4 +1,5 @@
1
- export { C as ChatMessage, F as FinishReason, G as GenerationResult, P as ProviderHealth, S as StreamCallbacks, a as StructuredGeneration, b as StructuredTextRequest, T as TextRequest, c as TextTier, d as TokenUsage } from '../index-fXjxTR5W.cjs';
1
+ import { d as TokenUsage } from '../index-fXjxTR5W.cjs';
2
+ export { C as ChatMessage, F as FinishReason, G as GenerationResult, P as ProviderHealth, S as StreamCallbacks, a as StructuredGeneration, b as StructuredTextRequest, T as TextRequest, c as TextTier } from '../index-fXjxTR5W.cjs';
2
3
  import { A as AIError, b as AIErrorType, a as AIErrorMetadata } from '../index-DKHNcMbl.cjs';
3
4
  export { T as TEXT_TIERS, c as TierModelMap, U as USER_FRIENDLY_ERROR_MESSAGES, i as isTextTier, m as mergeTierOverrides, r as resolveModel } from '../index-DKHNcMbl.cjs';
4
5
  import { b as RetryManager, c as RetryOptions, a as RequestQueue, R as RequestDeduplicator } from '../request-deduplicator.util-NDo0_n1y.cjs';
@@ -140,6 +141,27 @@ declare function asTrimmedOptionalString(value: unknown): string | undefined;
140
141
  declare function clampScore(value: unknown, min: number, max: number): number | null;
141
142
  declare function oneOfCatalog<T extends readonly string[]>(catalog: T, value: unknown): T[number] | null;
142
143
 
144
+ declare const TRANSIENT_ERROR_CODES: ReadonlySet<string>;
145
+ interface FailoverErrorLike {
146
+ readonly code?: string;
147
+ readonly type?: string;
148
+ readonly status?: number;
149
+ }
150
+ declare function isTransientError(err: unknown): boolean;
151
+ declare function canFailover(err: unknown, streamedChars: number): boolean;
152
+ interface ModelWithProvider {
153
+ readonly model: {
154
+ readonly id: string;
155
+ readonly capabilities?: {
156
+ readonly streaming?: boolean;
157
+ };
158
+ };
159
+ readonly provider: {
160
+ readonly id: string;
161
+ };
162
+ }
163
+ declare function failoverCandidate<T extends ModelWithProvider>(primary: T, fallback: T | null): T | null;
164
+
143
165
  declare function isSseDataLine(line: string): boolean;
144
166
  declare function extractSseDataPayload(line: string): string;
145
167
  declare function isSseDoneMarker(payload: string): boolean;
@@ -186,6 +208,101 @@ declare class StructuredPromptBuilder {
186
208
  build(): string;
187
209
  }
188
210
 
211
+ declare const CHUNK_MAX_CHARS = 1200;
212
+ declare const CHUNK_OVERLAP_CHARS = 160;
213
+ declare const CHUNK_TEXT_LIMIT = 200000;
214
+ interface ChunkOptions {
215
+ maxChars?: number;
216
+ overlapChars?: number;
217
+ }
218
+ declare function chunkText(text: string, options?: ChunkOptions): string[];
219
+
220
+ interface AccessTimestamped {
221
+ readonly lastAccess: number;
222
+ }
223
+ declare function selectLeastRecentlyUsedKey<K, V extends AccessTimestamped>(entries: ReadonlyMap<K, V>): K | null;
224
+
225
+ interface ExponentialBackoffParams {
226
+ readonly attempt: number;
227
+ readonly initialDelay: number;
228
+ readonly maxDelay: number;
229
+ readonly backoffMultiplier: number;
230
+ readonly jitterFactor: number;
231
+ readonly random?: () => number;
232
+ }
233
+ declare function calculateExponentialBackoff(params: ExponentialBackoffParams): number;
234
+
235
+ declare function generateRandomBase36Suffix(length: number, random?: () => number): string;
236
+
237
+ interface AccessCounted {
238
+ readonly accessCount: number;
239
+ }
240
+ declare function calculateCacheHitRate(entries: ReadonlyArray<AccessCounted>): number;
241
+
242
+ interface LeadingEdgeParams {
243
+ readonly now: number;
244
+ readonly lastCallTime: number;
245
+ readonly interval: number;
246
+ readonly leadingEnabled: boolean;
247
+ readonly isThrottled: boolean;
248
+ }
249
+ declare function shouldCallOnLeadingEdge(params: LeadingEdgeParams): boolean;
250
+ interface TrailingDelayParams {
251
+ readonly interval: number;
252
+ readonly timeSinceLastCall: number;
253
+ }
254
+ declare function calculateTrailingDelay(params: TrailingDelayParams): number;
255
+ declare function isWithinWindow(now: number, lastCallTime: number, interval: number): boolean;
256
+
257
+ declare const MICROS_PER_UNIT = 1000000;
258
+ interface ModelPricing {
259
+ readonly inputPerMTok: number;
260
+ readonly outputPerMTok: number;
261
+ readonly currency: 'USD';
262
+ }
263
+ declare function computeCostMicros(pricing: ModelPricing, usage: Pick<TokenUsage, 'inputTokens' | 'outputTokens'>): number;
264
+ interface UsageRecordInput {
265
+ readonly usage: TokenUsage & {
266
+ readonly reasoningTokens?: number;
267
+ };
268
+ readonly pricing: ModelPricing;
269
+ readonly durationMs: number;
270
+ }
271
+ interface UsageRecordData {
272
+ readonly inputTokens: number;
273
+ readonly outputTokens: number;
274
+ readonly reasoningTokens: number;
275
+ readonly costMicros: number;
276
+ readonly durationMs: number;
277
+ }
278
+ declare function buildUsageData(input: UsageRecordInput): UsageRecordData;
279
+ declare function formatCost(costMicros: number): string;
280
+
281
+ interface TaskPolicy {
282
+ readonly maxAttempts: number;
283
+ readonly backoffBaseMs: number;
284
+ }
285
+ declare const DEFAULT_TASK_POLICIES: Record<string, TaskPolicy>;
286
+ declare function nextAttemptDelayMs(attempt: number, baseMs: number): number;
287
+ interface TaskState {
288
+ readonly status: string;
289
+ readonly nextAttemptAt?: string | null;
290
+ }
291
+ declare function canStartTask(task: TaskState, now?: Date): boolean;
292
+ interface TaskPlan {
293
+ readonly status: 'queued' | 'failed';
294
+ readonly nextAttemptAt: string | null;
295
+ readonly log: {
296
+ readonly at: string;
297
+ readonly level: 'info' | 'warn' | 'error';
298
+ readonly message: string;
299
+ };
300
+ }
301
+ declare function planTaskFailure(task: {
302
+ attempts: number;
303
+ maxAttempts: number;
304
+ }, errorDetail: string, backoffBaseMs: number, now?: Date): TaskPlan;
305
+
189
306
  declare const SSE_BRIDGE_EVENTS: {
190
307
  readonly delta: "delta";
191
308
  readonly done: "done";
@@ -201,6 +318,96 @@ interface SseResponseOptions {
201
318
  declare function defaultSseDeltaExtractor(payload: string): string | null;
202
319
  declare function createSseResponse(openUpstream: () => Promise<ReadableStream<Uint8Array>>, options: SseResponseOptions): Response;
203
320
 
321
+ interface WireToolCallDelta {
322
+ readonly index?: number;
323
+ readonly id?: string;
324
+ readonly function?: {
325
+ readonly name?: string;
326
+ readonly arguments?: string;
327
+ };
328
+ }
329
+ interface AssistantToolCall {
330
+ readonly id: string;
331
+ readonly name: string;
332
+ readonly arguments: string;
333
+ }
334
+ declare class ToolCallAccumulator {
335
+ private readonly slots;
336
+ push(delta: WireToolCallDelta): void;
337
+ finish(): AssistantToolCall[];
338
+ }
339
+
340
+ type ContextRole = 'system' | 'user' | 'assistant' | 'tool';
341
+ interface ContextMessage {
342
+ readonly role: ContextRole;
343
+ readonly content: string;
344
+ readonly toolCalls?: ReadonlyArray<{
345
+ id: string;
346
+ name: string;
347
+ arguments: string;
348
+ }>;
349
+ readonly toolCallId?: string;
350
+ }
351
+ interface ContextBudget {
352
+ readonly contextWindow: number;
353
+ readonly maxOutputTokens: number;
354
+ }
355
+ declare function estimateTokens(text: string): number;
356
+ declare function estimateMessageTokens(message: ContextMessage): number;
357
+ declare function buildContext<T extends ContextMessage = ContextMessage>(history: ReadonlyArray<T>, systemPrompt: string, budget: ContextBudget): T[];
358
+
359
+ declare const SYSTEM_PROMPT_VERSION = 2;
360
+ declare const DEFAULT_AI_IDENTITY: string;
361
+ interface ProjectContext {
362
+ name: string;
363
+ instructions: string;
364
+ }
365
+ interface AgentContext {
366
+ name: string;
367
+ instructions: string;
368
+ }
369
+ interface SystemPromptInput {
370
+ identity?: string;
371
+ settings?: {
372
+ systemExtra?: string;
373
+ };
374
+ project?: ProjectContext | null;
375
+ agent?: AgentContext | null;
376
+ attachments?: readonly {
377
+ name: string;
378
+ text: string;
379
+ }[];
380
+ memories?: readonly string[];
381
+ now?: Date;
382
+ }
383
+ declare function buildSystemPrompt(input?: SystemPromptInput): string;
384
+
385
+ type SearchTopic = 'general' | 'news';
386
+ interface WebSearchResult {
387
+ readonly title: string;
388
+ readonly url: string;
389
+ readonly content: string;
390
+ readonly score: number | null;
391
+ }
392
+ interface WebSearchResponse {
393
+ readonly query: string;
394
+ readonly answer: string | null;
395
+ readonly results: ReadonlyArray<WebSearchResult>;
396
+ readonly responseTime: number | null;
397
+ }
398
+ interface WebSearchInput {
399
+ readonly query: string;
400
+ readonly maxResults?: number;
401
+ readonly topic?: SearchTopic;
402
+ readonly includeAnswer?: boolean;
403
+ }
404
+ type FetchLike = (input: string, init: Record<string, unknown>) => Promise<Response>;
405
+ declare const SEARCH_MAX_RESULTS = 5;
406
+ declare function searchWeb(env: {
407
+ readonly TAVILY_API_KEY?: string;
408
+ readonly TAVILY_BASE_URL?: string;
409
+ }, input: WebSearchInput, fetchImpl?: FetchLike): Promise<WebSearchResponse>;
410
+
204
411
  declare const SSE_PREFIX: "data: ";
205
412
  declare const SSE_DONE_MARKER: "[DONE]";
206
413
  declare const JSON_CODE_BLOCK_PATTERN: RegExp;
@@ -212,4 +419,4 @@ declare const DEFAULT_RETRY_MAX_DELAY_MS = 10000;
212
419
  declare const DEFAULT_RETRY_BACKOFF_MULTIPLIER = 2;
213
420
  declare const DEFAULT_RETRY_JITTER_FACTOR = 0.1;
214
421
 
215
- export { AIError, type AIErrorBody, AIErrorMetadata, AIErrorType, type ApiKeyValidationRule, CompositeExecutor, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DebounceManager, type DebounceOptions, DedupeExecutor, type DedupeExecutorOptions, type ErrorClassificationRule, GroqError, type GroqErrorMetadata, AIErrorType as GroqErrorType, type HttpStatusClassificationRule, type IRequestExecutor, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, type LoggedError, type NormalizedSseChunk, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, RetryOptions, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, type SseDeltaExtractor, type SseResponseOptions, type StreamingParserCallbacks, StreamingResponseParser, StructuredPromptBuilder, ThrottleManager, type ThrottleOptions, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildHttpStatusFallback, clampScore, classifyHttpStatus, createSseResponse, debounce, debounceManager, defaultSseDeltaExtractor, describeAIErrorType, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonArray, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, formatErrorForLogging, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isValidApiKey, normalizeSseChunk, oneOfCatalog, repairCommonJsonDefects, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, splitSseLines, throttle, throttleManager, validateApiKey };
422
+ export { AIError, type AIErrorBody, AIErrorMetadata, AIErrorType, type AccessCounted, type AccessTimestamped, type AgentContext, type ApiKeyValidationRule, type AssistantToolCall, CHUNK_MAX_CHARS, CHUNK_OVERLAP_CHARS, CHUNK_TEXT_LIMIT, type ChunkOptions, CompositeExecutor, type ContextBudget, type ContextMessage, type ContextRole, DEFAULT_AI_IDENTITY, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TASK_POLICIES, DebounceManager, type DebounceOptions, DedupeExecutor, type DedupeExecutorOptions, type ErrorClassificationRule, type ExponentialBackoffParams, type FailoverErrorLike, type FetchLike, GroqError, type GroqErrorMetadata, AIErrorType as GroqErrorType, type HttpStatusClassificationRule, type IRequestExecutor, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, type LeadingEdgeParams, type LoggedError, MICROS_PER_UNIT, type ModelPricing, type ModelWithProvider, type NormalizedSseChunk, type ProjectContext, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, RetryOptions, SEARCH_MAX_RESULTS, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, SYSTEM_PROMPT_VERSION, type SearchTopic, type SseDeltaExtractor, type SseResponseOptions, type StreamingParserCallbacks, StreamingResponseParser, StructuredPromptBuilder, type SystemPromptInput, TRANSIENT_ERROR_CODES, type TaskPlan, type TaskPolicy, type TaskState, ThrottleManager, type ThrottleOptions, TokenUsage, ToolCallAccumulator, type TrailingDelayParams, type UsageRecordData, type UsageRecordInput, type WebSearchInput, type WebSearchResponse, type WebSearchResult, type WireToolCallDelta, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildContext, buildHttpStatusFallback, buildSystemPrompt, buildUsageData, calculateCacheHitRate, calculateExponentialBackoff, calculateTrailingDelay, canFailover, canStartTask, chunkText, clampScore, classifyHttpStatus, computeCostMicros, createSseResponse, debounce, debounceManager, defaultSseDeltaExtractor, describeAIErrorType, estimateMessageTokens, estimateTokens, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonArray, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, failoverCandidate, formatCost, formatErrorForLogging, generateRandomBase36Suffix, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isTransientError, isValidApiKey, isWithinWindow, nextAttemptDelayMs, normalizeSseChunk, oneOfCatalog, planTaskFailure, repairCommonJsonDefects, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, searchWeb, selectLeastRecentlyUsedKey, shouldCallOnLeadingEdge, splitSseLines, throttle, throttleManager, validateApiKey };
@@ -1,4 +1,5 @@
1
- export { C as ChatMessage, F as FinishReason, G as GenerationResult, P as ProviderHealth, S as StreamCallbacks, a as StructuredGeneration, b as StructuredTextRequest, T as TextRequest, c as TextTier, d as TokenUsage } from '../index-fXjxTR5W.js';
1
+ import { d as TokenUsage } from '../index-fXjxTR5W.js';
2
+ export { C as ChatMessage, F as FinishReason, G as GenerationResult, P as ProviderHealth, S as StreamCallbacks, a as StructuredGeneration, b as StructuredTextRequest, T as TextRequest, c as TextTier } from '../index-fXjxTR5W.js';
2
3
  import { A as AIError, b as AIErrorType, a as AIErrorMetadata } from '../index-DIHz8_OJ.js';
3
4
  export { T as TEXT_TIERS, c as TierModelMap, U as USER_FRIENDLY_ERROR_MESSAGES, i as isTextTier, m as mergeTierOverrides, r as resolveModel } from '../index-DIHz8_OJ.js';
4
5
  import { b as RetryManager, c as RetryOptions, a as RequestQueue, R as RequestDeduplicator } from '../request-deduplicator.util-NDo0_n1y.js';
@@ -140,6 +141,27 @@ declare function asTrimmedOptionalString(value: unknown): string | undefined;
140
141
  declare function clampScore(value: unknown, min: number, max: number): number | null;
141
142
  declare function oneOfCatalog<T extends readonly string[]>(catalog: T, value: unknown): T[number] | null;
142
143
 
144
+ declare const TRANSIENT_ERROR_CODES: ReadonlySet<string>;
145
+ interface FailoverErrorLike {
146
+ readonly code?: string;
147
+ readonly type?: string;
148
+ readonly status?: number;
149
+ }
150
+ declare function isTransientError(err: unknown): boolean;
151
+ declare function canFailover(err: unknown, streamedChars: number): boolean;
152
+ interface ModelWithProvider {
153
+ readonly model: {
154
+ readonly id: string;
155
+ readonly capabilities?: {
156
+ readonly streaming?: boolean;
157
+ };
158
+ };
159
+ readonly provider: {
160
+ readonly id: string;
161
+ };
162
+ }
163
+ declare function failoverCandidate<T extends ModelWithProvider>(primary: T, fallback: T | null): T | null;
164
+
143
165
  declare function isSseDataLine(line: string): boolean;
144
166
  declare function extractSseDataPayload(line: string): string;
145
167
  declare function isSseDoneMarker(payload: string): boolean;
@@ -186,6 +208,101 @@ declare class StructuredPromptBuilder {
186
208
  build(): string;
187
209
  }
188
210
 
211
+ declare const CHUNK_MAX_CHARS = 1200;
212
+ declare const CHUNK_OVERLAP_CHARS = 160;
213
+ declare const CHUNK_TEXT_LIMIT = 200000;
214
+ interface ChunkOptions {
215
+ maxChars?: number;
216
+ overlapChars?: number;
217
+ }
218
+ declare function chunkText(text: string, options?: ChunkOptions): string[];
219
+
220
+ interface AccessTimestamped {
221
+ readonly lastAccess: number;
222
+ }
223
+ declare function selectLeastRecentlyUsedKey<K, V extends AccessTimestamped>(entries: ReadonlyMap<K, V>): K | null;
224
+
225
+ interface ExponentialBackoffParams {
226
+ readonly attempt: number;
227
+ readonly initialDelay: number;
228
+ readonly maxDelay: number;
229
+ readonly backoffMultiplier: number;
230
+ readonly jitterFactor: number;
231
+ readonly random?: () => number;
232
+ }
233
+ declare function calculateExponentialBackoff(params: ExponentialBackoffParams): number;
234
+
235
+ declare function generateRandomBase36Suffix(length: number, random?: () => number): string;
236
+
237
+ interface AccessCounted {
238
+ readonly accessCount: number;
239
+ }
240
+ declare function calculateCacheHitRate(entries: ReadonlyArray<AccessCounted>): number;
241
+
242
+ interface LeadingEdgeParams {
243
+ readonly now: number;
244
+ readonly lastCallTime: number;
245
+ readonly interval: number;
246
+ readonly leadingEnabled: boolean;
247
+ readonly isThrottled: boolean;
248
+ }
249
+ declare function shouldCallOnLeadingEdge(params: LeadingEdgeParams): boolean;
250
+ interface TrailingDelayParams {
251
+ readonly interval: number;
252
+ readonly timeSinceLastCall: number;
253
+ }
254
+ declare function calculateTrailingDelay(params: TrailingDelayParams): number;
255
+ declare function isWithinWindow(now: number, lastCallTime: number, interval: number): boolean;
256
+
257
+ declare const MICROS_PER_UNIT = 1000000;
258
+ interface ModelPricing {
259
+ readonly inputPerMTok: number;
260
+ readonly outputPerMTok: number;
261
+ readonly currency: 'USD';
262
+ }
263
+ declare function computeCostMicros(pricing: ModelPricing, usage: Pick<TokenUsage, 'inputTokens' | 'outputTokens'>): number;
264
+ interface UsageRecordInput {
265
+ readonly usage: TokenUsage & {
266
+ readonly reasoningTokens?: number;
267
+ };
268
+ readonly pricing: ModelPricing;
269
+ readonly durationMs: number;
270
+ }
271
+ interface UsageRecordData {
272
+ readonly inputTokens: number;
273
+ readonly outputTokens: number;
274
+ readonly reasoningTokens: number;
275
+ readonly costMicros: number;
276
+ readonly durationMs: number;
277
+ }
278
+ declare function buildUsageData(input: UsageRecordInput): UsageRecordData;
279
+ declare function formatCost(costMicros: number): string;
280
+
281
+ interface TaskPolicy {
282
+ readonly maxAttempts: number;
283
+ readonly backoffBaseMs: number;
284
+ }
285
+ declare const DEFAULT_TASK_POLICIES: Record<string, TaskPolicy>;
286
+ declare function nextAttemptDelayMs(attempt: number, baseMs: number): number;
287
+ interface TaskState {
288
+ readonly status: string;
289
+ readonly nextAttemptAt?: string | null;
290
+ }
291
+ declare function canStartTask(task: TaskState, now?: Date): boolean;
292
+ interface TaskPlan {
293
+ readonly status: 'queued' | 'failed';
294
+ readonly nextAttemptAt: string | null;
295
+ readonly log: {
296
+ readonly at: string;
297
+ readonly level: 'info' | 'warn' | 'error';
298
+ readonly message: string;
299
+ };
300
+ }
301
+ declare function planTaskFailure(task: {
302
+ attempts: number;
303
+ maxAttempts: number;
304
+ }, errorDetail: string, backoffBaseMs: number, now?: Date): TaskPlan;
305
+
189
306
  declare const SSE_BRIDGE_EVENTS: {
190
307
  readonly delta: "delta";
191
308
  readonly done: "done";
@@ -201,6 +318,96 @@ interface SseResponseOptions {
201
318
  declare function defaultSseDeltaExtractor(payload: string): string | null;
202
319
  declare function createSseResponse(openUpstream: () => Promise<ReadableStream<Uint8Array>>, options: SseResponseOptions): Response;
203
320
 
321
+ interface WireToolCallDelta {
322
+ readonly index?: number;
323
+ readonly id?: string;
324
+ readonly function?: {
325
+ readonly name?: string;
326
+ readonly arguments?: string;
327
+ };
328
+ }
329
+ interface AssistantToolCall {
330
+ readonly id: string;
331
+ readonly name: string;
332
+ readonly arguments: string;
333
+ }
334
+ declare class ToolCallAccumulator {
335
+ private readonly slots;
336
+ push(delta: WireToolCallDelta): void;
337
+ finish(): AssistantToolCall[];
338
+ }
339
+
340
+ type ContextRole = 'system' | 'user' | 'assistant' | 'tool';
341
+ interface ContextMessage {
342
+ readonly role: ContextRole;
343
+ readonly content: string;
344
+ readonly toolCalls?: ReadonlyArray<{
345
+ id: string;
346
+ name: string;
347
+ arguments: string;
348
+ }>;
349
+ readonly toolCallId?: string;
350
+ }
351
+ interface ContextBudget {
352
+ readonly contextWindow: number;
353
+ readonly maxOutputTokens: number;
354
+ }
355
+ declare function estimateTokens(text: string): number;
356
+ declare function estimateMessageTokens(message: ContextMessage): number;
357
+ declare function buildContext<T extends ContextMessage = ContextMessage>(history: ReadonlyArray<T>, systemPrompt: string, budget: ContextBudget): T[];
358
+
359
+ declare const SYSTEM_PROMPT_VERSION = 2;
360
+ declare const DEFAULT_AI_IDENTITY: string;
361
+ interface ProjectContext {
362
+ name: string;
363
+ instructions: string;
364
+ }
365
+ interface AgentContext {
366
+ name: string;
367
+ instructions: string;
368
+ }
369
+ interface SystemPromptInput {
370
+ identity?: string;
371
+ settings?: {
372
+ systemExtra?: string;
373
+ };
374
+ project?: ProjectContext | null;
375
+ agent?: AgentContext | null;
376
+ attachments?: readonly {
377
+ name: string;
378
+ text: string;
379
+ }[];
380
+ memories?: readonly string[];
381
+ now?: Date;
382
+ }
383
+ declare function buildSystemPrompt(input?: SystemPromptInput): string;
384
+
385
+ type SearchTopic = 'general' | 'news';
386
+ interface WebSearchResult {
387
+ readonly title: string;
388
+ readonly url: string;
389
+ readonly content: string;
390
+ readonly score: number | null;
391
+ }
392
+ interface WebSearchResponse {
393
+ readonly query: string;
394
+ readonly answer: string | null;
395
+ readonly results: ReadonlyArray<WebSearchResult>;
396
+ readonly responseTime: number | null;
397
+ }
398
+ interface WebSearchInput {
399
+ readonly query: string;
400
+ readonly maxResults?: number;
401
+ readonly topic?: SearchTopic;
402
+ readonly includeAnswer?: boolean;
403
+ }
404
+ type FetchLike = (input: string, init: Record<string, unknown>) => Promise<Response>;
405
+ declare const SEARCH_MAX_RESULTS = 5;
406
+ declare function searchWeb(env: {
407
+ readonly TAVILY_API_KEY?: string;
408
+ readonly TAVILY_BASE_URL?: string;
409
+ }, input: WebSearchInput, fetchImpl?: FetchLike): Promise<WebSearchResponse>;
410
+
204
411
  declare const SSE_PREFIX: "data: ";
205
412
  declare const SSE_DONE_MARKER: "[DONE]";
206
413
  declare const JSON_CODE_BLOCK_PATTERN: RegExp;
@@ -212,4 +419,4 @@ declare const DEFAULT_RETRY_MAX_DELAY_MS = 10000;
212
419
  declare const DEFAULT_RETRY_BACKOFF_MULTIPLIER = 2;
213
420
  declare const DEFAULT_RETRY_JITTER_FACTOR = 0.1;
214
421
 
215
- export { AIError, type AIErrorBody, AIErrorMetadata, AIErrorType, type ApiKeyValidationRule, CompositeExecutor, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DebounceManager, type DebounceOptions, DedupeExecutor, type DedupeExecutorOptions, type ErrorClassificationRule, GroqError, type GroqErrorMetadata, AIErrorType as GroqErrorType, type HttpStatusClassificationRule, type IRequestExecutor, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, type LoggedError, type NormalizedSseChunk, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, RetryOptions, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, type SseDeltaExtractor, type SseResponseOptions, type StreamingParserCallbacks, StreamingResponseParser, StructuredPromptBuilder, ThrottleManager, type ThrottleOptions, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildHttpStatusFallback, clampScore, classifyHttpStatus, createSseResponse, debounce, debounceManager, defaultSseDeltaExtractor, describeAIErrorType, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonArray, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, formatErrorForLogging, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isValidApiKey, normalizeSseChunk, oneOfCatalog, repairCommonJsonDefects, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, splitSseLines, throttle, throttleManager, validateApiKey };
422
+ export { AIError, type AIErrorBody, AIErrorMetadata, AIErrorType, type AccessCounted, type AccessTimestamped, type AgentContext, type ApiKeyValidationRule, type AssistantToolCall, CHUNK_MAX_CHARS, CHUNK_OVERLAP_CHARS, CHUNK_TEXT_LIMIT, type ChunkOptions, CompositeExecutor, type ContextBudget, type ContextMessage, type ContextRole, DEFAULT_AI_IDENTITY, DEFAULT_API_KEY_RULE, DEFAULT_ERROR_CLASSIFICATION_RULE, DEFAULT_HTTP_STATUS_RULE, DEFAULT_RETRY_BACKOFF_MULTIPLIER, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_JITTER_FACTOR, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TASK_POLICIES, DebounceManager, type DebounceOptions, DedupeExecutor, type DedupeExecutorOptions, type ErrorClassificationRule, type ExponentialBackoffParams, type FailoverErrorLike, type FetchLike, GroqError, type GroqErrorMetadata, AIErrorType as GroqErrorType, type HttpStatusClassificationRule, type IRequestExecutor, JSON_CODE_BLOCK_PATTERN, JSON_OBJECT_PATTERN, JsonResponseParser, type LeadingEdgeParams, type LoggedError, MICROS_PER_UNIT, type ModelPricing, type ModelWithProvider, type NormalizedSseChunk, type ProjectContext, QueueExecutor, RequestDeduplicator, RequestQueue, RetryExecutor, RetryManager, RetryOptions, SEARCH_MAX_RESULTS, SSE_BRIDGE_EVENTS, SSE_DONE_MARKER, SSE_PREFIX, SYSTEM_PROMPT_VERSION, type SearchTopic, type SseDeltaExtractor, type SseResponseOptions, type StreamingParserCallbacks, StreamingResponseParser, StructuredPromptBuilder, type SystemPromptInput, TRANSIENT_ERROR_CODES, type TaskPlan, type TaskPolicy, type TaskState, ThrottleManager, type ThrottleOptions, TokenUsage, ToolCallAccumulator, type TrailingDelayParams, type UsageRecordData, type UsageRecordInput, type WebSearchInput, type WebSearchResponse, type WebSearchResult, type WireToolCallDelta, asObjectArray, asRecord, asStringArray, asTrimmedOptionalString, buildCacheKey, buildContext, buildHttpStatusFallback, buildSystemPrompt, buildUsageData, calculateCacheHitRate, calculateExponentialBackoff, calculateTrailingDelay, canFailover, canStartTask, chunkText, clampScore, classifyHttpStatus, computeCostMicros, createSseResponse, debounce, debounceManager, defaultSseDeltaExtractor, describeAIErrorType, estimateMessageTokens, estimateTokens, extractErrorMessageFromJsonBody, extractErrorMessageFromResponse, extractJsonArray, extractJsonCandidate, extractJsonFromCodeFence, extractJsonObject, extractSseDataPayload, failoverCandidate, formatCost, formatErrorForLogging, generateRandomBase36Suffix, isAuthErrorType, isRetryableErrorType, isSseDataLine, isSseDoneMarker, isTransientError, isValidApiKey, isWithinWindow, nextAttemptDelayMs, normalizeSseChunk, oneOfCatalog, planTaskFailure, repairCommonJsonDefects, resolveUserFriendlyErrorMessage, resolveUserFriendlyMessage, searchWeb, selectLeastRecentlyUsedKey, shouldCallOnLeadingEdge, splitSseLines, throttle, throttleManager, validateApiKey };