pull/643/head^2
Travis Fischer 2024-05-26 01:43:10 -05:00
rodzic 17f3912654
commit 4cd1f38dcb
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 { 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 {
// Only allow 20 clearbit API requests per 60s
export const throttle = pThrottle({
limit: 20,
interval: 60 * 1000,
strict: true
})
export interface CompanyEnrichmentOptions {
domain: string
webhook_url?: string
@ -528,7 +528,7 @@ export class ClearbitClient {
this.apiKey = apiKey
const throttledKy = throttle ? throttleKy(ky, clearbitAPIThrottle) : ky
const throttledKy = throttle ? throttleKy(ky, clearbit.throttle) : ky
this.ky = throttledKy.extend({
timeout: timeoutMs,

Wyświetl plik

@ -23,6 +23,7 @@ export class DexaClient {
this.apiKey = apiKey
this.apiBaseUrl = apiBaseUrl
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'
const diffbotAPIThrottle = pThrottle({
limit: 5,
interval: 1000,
strict: true
})
export namespace diffbot {
export const API_BASE_URL = 'https://api.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 {
/** 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
@ -357,7 +357,7 @@ export class DiffbotClient {
this.apiBaseUrl = apiBaseUrl
this.apiKnowledgeGraphBaseUrl = apiKnowledgeGraphBaseUrl
const throttledKy = throttle ? throttleKy(ky, diffbotAPIThrottle) : ky
const throttledKy = throttle ? throttleKy(ky, diffbot.throttle) : ky
this.ky = throttledKy.extend({
prefixUrl: apiBaseUrl,

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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