old-agentic
Travis Fischer 2024-05-26 01:43:10 -05:00
rodzic a91e3fe60b
commit cf688caea4
10 zmienionych plików z 61 dodań i 65 usunięć

Wyświetl plik

@ -4,14 +4,14 @@ import pThrottle from 'p-throttle'
import type { DeepNullable, KyInstance } from '../types.js' import type { DeepNullable, KyInstance } from '../types.js'
import { assert, delay, getEnv, throttleKy } from '../utils.js' import { assert, delay, getEnv, throttleKy } from '../utils.js'
// Only allow 20 clearbit API requests per 60s
const clearbitAPIThrottle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export namespace clearbit { export namespace clearbit {
// Only allow 20 clearbit API requests per 60s
export const throttle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export interface CompanyEnrichmentOptions { export interface CompanyEnrichmentOptions {
domain: string domain: string
webhook_url?: string webhook_url?: string
@ -528,7 +528,7 @@ export class ClearbitClient {
this.apiKey = apiKey this.apiKey = apiKey
const throttledKy = throttle ? throttleKy(ky, clearbitAPIThrottle) : ky const throttledKy = throttle ? throttleKy(ky, clearbit.throttle) : ky
this.ky = throttledKy.extend({ this.ky = throttledKy.extend({
timeout: timeoutMs, timeout: timeoutMs,

Wyświetl plik

@ -23,6 +23,7 @@ export class DexaClient {
this.apiKey = apiKey this.apiKey = apiKey
this.apiBaseUrl = apiBaseUrl this.apiBaseUrl = apiBaseUrl
this.ky = ky.extend({ prefixUrl: this.apiBaseUrl, timeout: timeoutMs }) this.ky = ky.extend({ prefixUrl: this.apiBaseUrl, timeout: timeoutMs })
} }

Wyświetl plik

@ -4,16 +4,16 @@ import pThrottle from 'p-throttle'
import { assert, getEnv, throttleKy } from '../utils.js' import { assert, getEnv, throttleKy } from '../utils.js'
const diffbotAPIThrottle = pThrottle({
limit: 5,
interval: 1000,
strict: true
})
export namespace diffbot { export namespace diffbot {
export const API_BASE_URL = 'https://api.diffbot.com' export const API_BASE_URL = 'https://api.diffbot.com'
export const KNOWLEDGE_GRAPH_API_BASE_URL = 'https://kg.diffbot.com' export const KNOWLEDGE_GRAPH_API_BASE_URL = 'https://kg.diffbot.com'
export const throttle = pThrottle({
limit: 5,
interval: 1000,
strict: true
})
export interface DiffbotExtractOptions { export interface DiffbotExtractOptions {
/** Specify optional fields to be returned from any fully-extracted pages, e.g.: &fields=querystring,links. See available fields within each API's individual documentation pages. /** Specify optional fields to be returned from any fully-extracted pages, e.g.: &fields=querystring,links. See available fields within each API's individual documentation pages.
* @see https://docs.diffbot.com/reference/extract-optional-fields * @see https://docs.diffbot.com/reference/extract-optional-fields
@ -357,7 +357,7 @@ export class DiffbotClient {
this.apiBaseUrl = apiBaseUrl this.apiBaseUrl = apiBaseUrl
this.apiKnowledgeGraphBaseUrl = apiKnowledgeGraphBaseUrl this.apiKnowledgeGraphBaseUrl = apiKnowledgeGraphBaseUrl
const throttledKy = throttle ? throttleKy(ky, diffbotAPIThrottle) : ky const throttledKy = throttle ? throttleKy(ky, diffbot.throttle) : ky
this.ky = throttledKy.extend({ this.ky = throttledKy.extend({
prefixUrl: apiBaseUrl, prefixUrl: apiBaseUrl,

Wyświetl plik

@ -147,6 +147,7 @@ export class ExaClient {
this.apiKey = apiKey this.apiKey = apiKey
this.apiBaseUrl = apiBaseUrl this.apiBaseUrl = apiBaseUrl
this.ky = ky.extend({ this.ky = ky.extend({
prefixUrl: this.apiBaseUrl, prefixUrl: this.apiBaseUrl,
headers: { headers: {

Wyświetl plik

@ -3,15 +3,15 @@ import pThrottle from 'p-throttle'
import { assert, getEnv, throttleKy } from '../utils.js' import { assert, getEnv, throttleKy } from '../utils.js'
const peopleDataLabsAPIThrottle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export namespace peopledatalabs { export namespace peopledatalabs {
export const BASE_URL = 'https://api.peopledatalabs.com/v5/' export const BASE_URL = 'https://api.peopledatalabs.com/v5/'
export const throttle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export const JobTitleLevels = [ export const JobTitleLevels = [
'cxo', 'cxo',
'director', 'director',
@ -453,9 +453,7 @@ export class PeopleDataLabsClient {
this.apiKey = apiKey this.apiKey = apiKey
this.apiBaseUrl = apiBaseUrl this.apiBaseUrl = apiBaseUrl
const throttledKy = throttle const throttledKy = throttle ? throttleKy(ky, peopledatalabs.throttle) : ky
? throttleKy(ky, peopleDataLabsAPIThrottle)
: ky
this.ky = throttledKy.extend({ this.ky = throttledKy.extend({
prefixUrl: apiBaseUrl, prefixUrl: apiBaseUrl,

Wyświetl plik

@ -3,13 +3,13 @@ import pThrottle from 'p-throttle'
import { assert, getEnv, throttleKy } from '../utils.js' import { assert, getEnv, throttleKy } from '../utils.js'
const perigonAPIThrottle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export namespace perigon { export namespace perigon {
export const throttle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export type ArticleLabel = export type ArticleLabel =
| 'Opinion' | 'Opinion'
| 'Non-news' | 'Non-news'
@ -268,7 +268,7 @@ export class PerigonClient {
this.apiKey = apiKey this.apiKey = apiKey
const throttledKy = throttle ? throttleKy(ky, perigonAPIThrottle) : ky const throttledKy = throttle ? throttleKy(ky, perigon.throttle) : ky
this.ky = throttledKy.extend({ this.ky = throttledKy.extend({
prefixUrl: 'https://api.goperigon.com/v1/', prefixUrl: 'https://api.goperigon.com/v1/',

Wyświetl plik

@ -4,13 +4,13 @@ import pThrottle from 'p-throttle'
import type { DeepNullable } from '../types.js' import type { DeepNullable } from '../types.js'
import { assert, getEnv, throttleKy } from '../utils.js' import { assert, getEnv, throttleKy } from '../utils.js'
const predictionLeadsAPIThrottle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export namespace predictleads { export namespace predictleads {
export const throttle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export type Meta = DeepNullable<{ export type Meta = DeepNullable<{
count: number count: number
message?: string | null message?: string | null
@ -210,9 +210,7 @@ export class PredictLeadsClient {
this.apiKey = apiKey this.apiKey = apiKey
this.apiToken = apiToken this.apiToken = apiToken
const throttledKy = throttle const throttledKy = throttle ? throttleKy(ky, predictleads.throttle) : ky
? throttleKy(ky, predictionLeadsAPIThrottle)
: ky
this.ky = throttledKy.extend({ this.ky = throttledKy.extend({
timeout: timeoutMs, timeout: timeoutMs,

Wyświetl plik

@ -2,7 +2,7 @@ import defaultKy, { type KyInstance } from 'ky'
import { z } from 'zod' import { z } from 'zod'
import { aiFunction, AIToolsProvider } from '../fns.js' import { aiFunction, AIToolsProvider } from '../fns.js'
import { getEnv } from '../utils.js' import { assert, getEnv } from '../utils.js'
/** /**
* All types have been exported from the `serpapi` package, which we're * All types have been exported from the `serpapi` package, which we're
@ -625,13 +625,7 @@ export namespace serpapi {
device?: 'desktop' | 'tablet' | 'mobile' device?: 'desktop' | 'tablet' | 'mobile'
} }
export type Params = Omit<GoogleParameters, 'q'> export type ClientParams = Partial<Omit<GoogleParameters, 'q'>>
export interface ClientOptions extends Partial<Params> {
apiKey?: string
apiBaseUrl?: string
ky?: KyInstance
}
} }
/** /**
@ -640,28 +634,29 @@ export namespace serpapi {
* @see https://serpapi.com/search-api * @see https://serpapi.com/search-api
*/ */
export class SerpAPIClient extends AIToolsProvider { export class SerpAPIClient extends AIToolsProvider {
protected api: KyInstance protected ky: KyInstance
protected apiKey: string protected apiKey: string
protected apiBaseUrl: string protected apiBaseUrl: string
protected params: Partial<serpapi.Params> protected params: serpapi.ClientParams
constructor({ constructor({
apiKey = getEnv('SERPAPI_API_KEY') ?? getEnv('SERP_API_KEY'), apiKey = getEnv('SERPAPI_API_KEY') ?? getEnv('SERP_API_KEY'),
apiBaseUrl = serpapi.BASE_URL, apiBaseUrl = serpapi.BASE_URL,
ky = defaultKy, ky = defaultKy,
...params ...params
}: serpapi.ClientOptions = {}) { }: {
if (!apiKey) { apiKey?: string
throw new Error(`Error SerpAPIClient missing required "apiKey"`) apiBaseUrl?: string
} ky?: KyInstance
} & serpapi.ClientParams = {}) {
assert(apiKey, `Error SerpAPIClient missing required "apiKey"`)
super() super()
this.apiKey = apiKey this.apiKey = apiKey
this.apiBaseUrl = apiBaseUrl this.apiBaseUrl = apiBaseUrl
this.params = params this.params = params
this.api = ky.extend({ this.ky = ky.extend({
prefixUrl: this.apiBaseUrl prefixUrl: this.apiBaseUrl
}) })
} }
@ -684,7 +679,7 @@ export class SerpAPIClient extends AIToolsProvider {
const { timeout, ...rest } = this.params const { timeout, ...rest } = this.params
// console.log('SerpAPIClient.search', options) // console.log('SerpAPIClient.search', options)
return this.api return this.ky
.get('search', { .get('search', {
searchParams: { searchParams: {
...rest, ...rest,

Wyświetl plik

@ -186,11 +186,7 @@ export namespace serper {
position: number position: number
} }
export interface ClientOptions extends Omit<Partial<SearchParams>, 'q'> { export type ClientParams = Partial<Omit<SearchParams, 'q'>>
apiKey?: string
apiBaseUrl?: string
ky?: KyInstance
}
} }
/** /**
@ -202,14 +198,18 @@ export class SerperClient extends AIToolsProvider {
readonly ky: KyInstance readonly ky: KyInstance
readonly apiKey: string readonly apiKey: string
readonly apiBaseUrl: string readonly apiBaseUrl: string
readonly params: Omit<Partial<serper.SearchParams>, 'q'> readonly params: serper.ClientParams
constructor({ constructor({
apiKey = getEnv('SERPER_API_KEY'), apiKey = getEnv('SERPER_API_KEY'),
apiBaseUrl = serper.BASE_URL, apiBaseUrl = serper.BASE_URL,
ky = defaultKy, ky = defaultKy,
...params ...params
}: serper.ClientOptions = {}) { }: {
apiKey?: string
apiBaseUrl?: string
ky?: KyInstance
} & serper.ClientParams = {}) {
assert( assert(
apiKey, apiKey,
`SerperClient missing required "apiKey" (defaults to "SERPER_API_KEY" env var)` `SerperClient missing required "apiKey" (defaults to "SERPER_API_KEY" env var)`

Wyświetl plik

@ -88,7 +88,10 @@ export class WeatherClient extends AIToolsProvider {
apiBaseUrl?: string apiBaseUrl?: string
ky?: KyInstance ky?: KyInstance
} = {}) { } = {}) {
assert(apiKey, 'WEATHER_API_KEY is required') assert(
apiKey,
'WeatherClient missing required "apiKey" (defaults to "WEATHER_API_KEY")'
)
super() super()
this.apiKey = apiKey this.apiKey = apiKey