@broberg/ai-sdk 0.59.1 → 0.60.0
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.ts +26 -7
- package/dist/index.js +43 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1882,8 +1882,9 @@ declare const aiConfigSchema: z.ZodObject<{
|
|
|
1882
1882
|
}>>;
|
|
1883
1883
|
}, "strip", z.ZodTypeAny, {
|
|
1884
1884
|
labels?: Record<string, string> | undefined;
|
|
1885
|
-
|
|
1885
|
+
costSink?: CostSink | null | undefined;
|
|
1886
1886
|
byok?: boolean | undefined;
|
|
1887
|
+
promptCache?: boolean | undefined;
|
|
1887
1888
|
strictPinning?: boolean | undefined;
|
|
1888
1889
|
defaults?: Partial<Record<"vision" | "video" | "embedding" | "fast" | "smart" | "powerful" | "cheap", {
|
|
1889
1890
|
provider: string;
|
|
@@ -1891,7 +1892,6 @@ declare const aiConfigSchema: z.ZodObject<{
|
|
|
1891
1892
|
transport: "http" | "subprocess";
|
|
1892
1893
|
}>> | undefined;
|
|
1893
1894
|
providers?: Record<string, ProviderAdapter> | undefined;
|
|
1894
|
-
costSink?: CostSink | null | undefined;
|
|
1895
1895
|
budget?: {
|
|
1896
1896
|
perCallUsd?: number | undefined;
|
|
1897
1897
|
rollingUsd?: number | undefined;
|
|
@@ -1902,8 +1902,9 @@ declare const aiConfigSchema: z.ZodObject<{
|
|
|
1902
1902
|
} | undefined;
|
|
1903
1903
|
}, {
|
|
1904
1904
|
labels?: Record<string, string> | undefined;
|
|
1905
|
-
|
|
1905
|
+
costSink?: CostSink | null | undefined;
|
|
1906
1906
|
byok?: boolean | undefined;
|
|
1907
|
+
promptCache?: boolean | undefined;
|
|
1907
1908
|
strictPinning?: boolean | undefined;
|
|
1908
1909
|
defaults?: Partial<Record<"vision" | "video" | "embedding" | "fast" | "smart" | "powerful" | "cheap", {
|
|
1909
1910
|
provider: string;
|
|
@@ -1911,7 +1912,6 @@ declare const aiConfigSchema: z.ZodObject<{
|
|
|
1911
1912
|
transport: "http" | "subprocess";
|
|
1912
1913
|
}>> | undefined;
|
|
1913
1914
|
providers?: Record<string, ProviderAdapter> | undefined;
|
|
1914
|
-
costSink?: CostSink | null | undefined;
|
|
1915
1915
|
budget?: {
|
|
1916
1916
|
perCallUsd?: number | undefined;
|
|
1917
1917
|
rollingUsd?: number | undefined;
|
|
@@ -2330,8 +2330,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
2330
2330
|
* wires the live adapters. */
|
|
2331
2331
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
2332
2332
|
|
|
2333
|
-
declare const VERSION: "0.
|
|
2334
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
2333
|
+
declare const VERSION: "0.60.0";
|
|
2334
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.60.0";
|
|
2335
2335
|
|
|
2336
2336
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
2337
2337
|
* per-call override.
|
|
@@ -2858,6 +2858,25 @@ declare function streamTransport(req: StreamTransportRequest): AsyncIterable<str
|
|
|
2858
2858
|
|
|
2859
2859
|
declare const SEARCH_PRICE_USD: Record<SearchProviderId, number>;
|
|
2860
2860
|
|
|
2861
|
+
declare const webSearchTool: Tool;
|
|
2862
|
+
/** What the app decides — never the model. */
|
|
2863
|
+
interface WebSearchContext extends SearchOptions {
|
|
2864
|
+
/** Customer data may be in the query: only Zero-Data-Retention providers. */
|
|
2865
|
+
zdr?: boolean;
|
|
2866
|
+
/** Attribution, e.g. { tenantId } — also selects the tenant's daily cap. */
|
|
2867
|
+
labels?: Record<string, string>;
|
|
2868
|
+
}
|
|
2869
|
+
interface WebSearchToolResult {
|
|
2870
|
+
provider: string;
|
|
2871
|
+
results: {
|
|
2872
|
+
title: string;
|
|
2873
|
+
url: string;
|
|
2874
|
+
snippet: string;
|
|
2875
|
+
}[];
|
|
2876
|
+
}
|
|
2877
|
+
/** Run a `web_search` tool call. Throws on invalid arguments before any request. */
|
|
2878
|
+
declare function runWebSearch(args: Record<string, unknown>, ctx?: WebSearchContext): Promise<WebSearchToolResult>;
|
|
2879
|
+
|
|
2861
2880
|
interface SearchRoute {
|
|
2862
2881
|
/** Readable name — shows up in tests and in the reason a provider was picked. */
|
|
2863
2882
|
name: string;
|
|
@@ -2878,4 +2897,4 @@ declare function memorySearchCache(max?: number): SearchCache;
|
|
|
2878
2897
|
|
|
2879
2898
|
declare function search(req: SearchRequest, opts?: SearchOptions): Promise<SearchResult>;
|
|
2880
2899
|
|
|
2881
|
-
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, type AiClient, type AiConfig, type AzureVoiceInfo, BatchJob, BatchRequestItem, BatchResultItem, type BflAdapterConfig, type BflCredits, BudgetConfig, BudgetExceededError, BudgetGuard, BudgetStore, CONFIG_DERIVED_HOSTS, Capability, type ChatInput, ChatResult, ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type Contracts, type CostQuery, CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_SEARCH_ROUTES, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, type ImageInput, ImageResult, type JudgeInput, JudgeResult, LOCALLY_PINNED_HOSTS, type MockupInput, type MockupResult, type ModerationInput, ModerationResult, type OcrInput, OcrResult, type OpenAICompatibleConfig, type PodcastInput, PodcastResult, type PriceDriftResult, type PriceDriftRow, type PricingEntry, ProviderAdapter, type RefreshOptions, type RefreshResult, Region, type RerankInput, type RerankResult, type RouteForecast, SDK_TAG, SEARCH_CACHE_TTL_MS, SEARCH_PRICE_USD, SearchBudgetExceededError, type SearchCache, type SearchCapStore, type SearchCredentials, type SearchItem, SearchKeyMissingError, type SearchOptions, type SearchProviderId, type SearchPurpose, type SearchRequest, type SearchResult, type SearchRoute, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, Tier, TierSpec, Tool, ToolCall, type TrainStyleInput, TrainStyleResult, type TranscribeInput, TranscribeResult, type TranslateInput, TranslateResult, Transport, type TransportRequest, type TransportResponse, type TtsInput, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, ZDR_PROVIDERS, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, byokAdapter, chatInputSchema, checkPriceDrift, checkVoice, computeCost, createAI, deepinfraAdapter, deeplAdapter, deepseekAdapter, defaultBaseUrl, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, isByokKeyed, listAzureDanishVoices, listVoices, makeContracts, makeOpenAICompatibleAdapter, matchLabel, memorySearchCache, messageSchema, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, refreshAvailability, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, routeSearch, search, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, wouldProviderRouteTo, wouldRouteTo };
|
|
2900
|
+
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, type AiClient, type AiConfig, type AzureVoiceInfo, BatchJob, BatchRequestItem, BatchResultItem, type BflAdapterConfig, type BflCredits, BudgetConfig, BudgetExceededError, BudgetGuard, BudgetStore, CONFIG_DERIVED_HOSTS, Capability, type ChatInput, ChatResult, ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type Contracts, type CostQuery, CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_SEARCH_ROUTES, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, type ImageInput, ImageResult, type JudgeInput, JudgeResult, LOCALLY_PINNED_HOSTS, type MockupInput, type MockupResult, type ModerationInput, ModerationResult, type OcrInput, OcrResult, type OpenAICompatibleConfig, type PodcastInput, PodcastResult, type PriceDriftResult, type PriceDriftRow, type PricingEntry, ProviderAdapter, type RefreshOptions, type RefreshResult, Region, type RerankInput, type RerankResult, type RouteForecast, SDK_TAG, SEARCH_CACHE_TTL_MS, SEARCH_PRICE_USD, SearchBudgetExceededError, type SearchCache, type SearchCapStore, type SearchCredentials, type SearchItem, SearchKeyMissingError, type SearchOptions, type SearchProviderId, type SearchPurpose, type SearchRequest, type SearchResult, type SearchRoute, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, Tier, TierSpec, Tool, ToolCall, type TrainStyleInput, TrainStyleResult, type TranscribeInput, TranscribeResult, type TranslateInput, TranslateResult, Transport, type TransportRequest, type TransportResponse, type TtsInput, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, type WebSearchContext, type WebSearchToolResult, ZDR_PROVIDERS, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, byokAdapter, chatInputSchema, checkPriceDrift, checkVoice, computeCost, createAI, deepinfraAdapter, deeplAdapter, deepseekAdapter, defaultBaseUrl, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, isByokKeyed, listAzureDanishVoices, listVoices, makeContracts, makeOpenAICompatibleAdapter, matchLabel, memorySearchCache, messageSchema, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, refreshAvailability, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, routeSearch, runWebSearch, search, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, webSearchTool, wouldProviderRouteTo, wouldRouteTo };
|
package/dist/index.js
CHANGED
|
@@ -188,6 +188,45 @@ var SearchBudgetExceededError = class extends Error {
|
|
|
188
188
|
requestedUsd;
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
+
// src/search/tool.ts
|
|
192
|
+
var PURPOSES = ["agent", "grounding", "discovery", "monitor"];
|
|
193
|
+
var webSearchTool = {
|
|
194
|
+
name: "web_search",
|
|
195
|
+
description: "Search the open web. Returns up to 10 results with title, url and snippet. Set lang to the query's language (e.g. 'da', 'en'). Set fresh when the answer must be recent (news, prices, events).",
|
|
196
|
+
parameters: {
|
|
197
|
+
type: "object",
|
|
198
|
+
properties: {
|
|
199
|
+
query: { type: "string", minLength: 1, maxLength: 1024, description: "What to search for." },
|
|
200
|
+
lang: { type: "string", description: "Language of the query, e.g. 'da' or 'en'." },
|
|
201
|
+
limit: { type: "integer", minimum: 1, maximum: 10, description: "Number of results (default 10)." },
|
|
202
|
+
purpose: { type: "string", enum: PURPOSES, description: "agent (default), grounding, discovery or monitor." },
|
|
203
|
+
fresh: { type: "boolean", description: "Results must be recent." }
|
|
204
|
+
},
|
|
205
|
+
required: ["query"],
|
|
206
|
+
additionalProperties: false
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
async function runWebSearch(args, ctx = {}) {
|
|
210
|
+
const { query, lang, limit, purpose, fresh } = args;
|
|
211
|
+
if (typeof query !== "string" || query.trim() === "") throw new Error("web_search: `query` must be a non-empty string");
|
|
212
|
+
if (lang !== void 0 && typeof lang !== "string") throw new Error("web_search: `lang` must be a string");
|
|
213
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit < 1 || limit > 10)) throw new Error("web_search: `limit` must be an integer 1\u201310");
|
|
214
|
+
if (purpose !== void 0 && !PURPOSES.includes(purpose)) throw new Error(`web_search: \`purpose\` must be one of ${PURPOSES.join(", ")}`);
|
|
215
|
+
if (fresh !== void 0 && typeof fresh !== "boolean") throw new Error("web_search: `fresh` must be a boolean");
|
|
216
|
+
const { zdr, labels, ...opts } = ctx;
|
|
217
|
+
const req = {
|
|
218
|
+
query,
|
|
219
|
+
...lang !== void 0 ? { lang } : {},
|
|
220
|
+
...limit !== void 0 ? { limit } : {},
|
|
221
|
+
...purpose !== void 0 ? { purpose } : {},
|
|
222
|
+
...fresh !== void 0 ? { fresh } : {},
|
|
223
|
+
...zdr ? { zdr } : {},
|
|
224
|
+
...labels ? { labels } : {}
|
|
225
|
+
};
|
|
226
|
+
const r = await search(req, opts);
|
|
227
|
+
return { provider: r.meta.provider, results: r.items.map((i) => ({ title: i.title, url: i.url, snippet: i.description })) };
|
|
228
|
+
}
|
|
229
|
+
|
|
191
230
|
// src/search/index.ts
|
|
192
231
|
var sharedCache = memorySearchCache();
|
|
193
232
|
var sharedCapStore = /* @__PURE__ */ (() => {
|
|
@@ -3829,8 +3868,8 @@ var aiConfigSchema = z.object({
|
|
|
3829
3868
|
import { randomUUID } from "crypto";
|
|
3830
3869
|
|
|
3831
3870
|
// src/version.ts
|
|
3832
|
-
var VERSION = "0.
|
|
3833
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
3871
|
+
var VERSION = "0.60.0";
|
|
3872
|
+
var SDK_TAG = "@broberg/ai-sdk@0.60.0";
|
|
3834
3873
|
|
|
3835
3874
|
// src/cost/sinks/upmetrics.ts
|
|
3836
3875
|
function isRetryableStatus(status) {
|
|
@@ -5447,6 +5486,7 @@ export {
|
|
|
5447
5486
|
resolveTier,
|
|
5448
5487
|
resolveVoice,
|
|
5449
5488
|
routeSearch,
|
|
5489
|
+
runWebSearch,
|
|
5450
5490
|
search,
|
|
5451
5491
|
sqliteBudgetStore,
|
|
5452
5492
|
sqliteSink,
|
|
@@ -5463,6 +5503,7 @@ export {
|
|
|
5463
5503
|
usdFromMicro,
|
|
5464
5504
|
vertexAdapter,
|
|
5465
5505
|
visionInputSchema,
|
|
5506
|
+
webSearchTool,
|
|
5466
5507
|
wouldProviderRouteTo,
|
|
5467
5508
|
wouldRouteTo
|
|
5468
5509
|
};
|