Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/components/credentials/OlostepApi.credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { INodeParams, INodeCredential } from '../src/Interface'

class OlostepApi implements INodeCredential {
label: string
name: string
version: number
description: string
inputs: INodeParams[]
Comment thread
umerkay marked this conversation as resolved.

constructor() {
this.label = 'Olostep API'
this.name = 'olostepApi'
this.version = 1.0
this.inputs = [
{
label: 'API Key',
name: 'apiKey',
type: 'password'
}
]
}
}

module.exports = { credClass: OlostepApi }
126 changes: 126 additions & 0 deletions packages/components/nodes/tools/OlostepScraper/OlostepScraper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { Tool } from '@langchain/core/tools'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'

class OlostepScraper extends Tool {
static lc_name() {
return 'OlostepScraper'
}

name = 'olostep_scrape'

description = 'Fetch and read the content of a web page from a URL.'

private readonly apiKey: string
private readonly Olostep: any
private readonly Format: any

constructor(apiKey: string, Olostep: any, Format: any, description?: string) {
super()
this.apiKey = apiKey
this.Olostep = Olostep
this.Format = Format
if (description) this.description = description
}

protected async _call(url: string): Promise<string> {
if (!url) return 'No URL provided'

try {
const client = new this.Olostep({ apiKey: this.apiKey })

const result = await client.scrapes.create({
url,
formats: [this.Format.MARKDOWN]
})

return result?.markdown_content || 'No content found'
} catch (error: any) {
return `Olostep scrape error: ${error?.message ?? String(error)}`
}
}
}

class OlostepScraperMissingSDK extends Tool {
static lc_name() {
return 'OlostepScraperMissingSDK'
}

name = 'olostep_scrape'

description = 'Fetch and read the content of a web page from a URL.'

private readonly message: string

constructor(message: string, description?: string) {
super()
this.message = message
if (description) this.description = description
}

protected async _call(_url: string): Promise<string> {
return this.message
}
}

class OlostepScraper_Tools implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
credential: INodeParams
inputs: INodeParams[]

constructor() {
this.label = 'Olostep Scraper'
this.name = 'olostepScraper'
this.version = 1.0
this.type = 'OlostepScraper'
this.icon = 'olostep.svg'
this.category = 'Tools'
this.description = 'Fetch and extract clean Markdown content from any URL using Olostep'
this.inputs = [
{
name: 'description',
label: 'Tool Description',
type: 'string',
rows: 4,
optional: true,
additionalParams: true,
default: 'Fetch and read the content of a web page from a URL.'
}
]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['olostepApi']
}
this.baseClasses = [this.type, ...getBaseClasses(OlostepScraper)]
}

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const apiKey = getCredentialParam('apiKey', credentialData, nodeData)
Comment thread
umerkay marked this conversation as resolved.

const description = nodeData.inputs?.description as string

try {
const olostepMod: any = await import('olostep')
const Olostep = olostepMod?.default
const Format = olostepMod?.Format
if (!Olostep || !Format) {
return new OlostepScraperMissingSDK('Olostep SDK is unavailable', description)
}
return new OlostepScraper(String(apiKey), Olostep, Format, description)
} catch (error: any) {
return new OlostepScraperMissingSDK(`Olostep SDK is not installed: ${error?.message ?? String(error)}`, description)
}
}
}

module.exports = { nodeClass: OlostepScraper_Tools }
4 changes: 4 additions & 0 deletions packages/components/nodes/tools/OlostepScraper/olostep.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 121 additions & 0 deletions packages/components/nodes/tools/OlostepSearch/OlostepSearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { Tool } from '@langchain/core/tools'
import axios from 'axios'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'

type OlostepLink = {
url: string
title: string
description: string
}

class OlostepSearch extends Tool {
static lc_name() {
return 'OlostepSearch'
}

name = 'olostep_search'

description = 'Search the web for current information, news, and facts.'

private readonly apiKey: string
private readonly numResults: number

constructor(apiKey: string, numResults = 5, description?: string) {
super()
this.apiKey = apiKey
this.numResults = numResults
if (description) this.description = description
}

protected async _call(query: string): Promise<string> {
if (!query) return 'No query provided'

try {
const response = await axios.post(
'https://api.olostep.com/v1/searches',
{ query },
{
headers: {
Authorization: `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
}
}
)

const links = response?.data?.result?.links as OlostepLink[] | undefined
if (!Array.isArray(links) || links.length === 0) return 'No results found'

const results = links.slice(0, this.numResults)
return results.map((r, i) => `${i + 1}. ${r.title}\n${r.description}\nURL: ${r.url}`).join('\n\n')
} catch (error: any) {
return `Olostep search error: ${error?.message ?? String(error)}`
}
}
}

class OlostepSearch_Tools implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
credential: INodeParams
inputs: INodeParams[]

constructor() {
this.label = 'Olostep Search'
this.name = 'olostepSearch'
this.version = 1.0
this.type = 'OlostepSearch'
this.icon = 'olostep.svg'
this.category = 'Tools'
this.description = 'Search the web using Olostep and return relevant results with titles, URLs, and descriptions'
this.inputs = [
{
name: 'numResults',
label: 'Number of Results',
type: 'number',
default: 5,
optional: true,
additionalParams: true
},
{
name: 'description',
label: 'Tool Description',
type: 'string',
rows: 4,
optional: true,
additionalParams: true,
default: 'Search the web for current information, news, and facts.'
}
]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['olostepApi']
}
this.baseClasses = [this.type, ...getBaseClasses(OlostepSearch)]
}

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const apiKey = getCredentialParam('apiKey', credentialData, nodeData)
Comment thread
umerkay marked this conversation as resolved.

const numResultsRaw = nodeData.inputs?.numResults as number | string | undefined
let numResults = 5
if (numResultsRaw !== undefined && numResultsRaw !== '') {
const parsed = parseInt(String(numResultsRaw), 10)
if (!isNaN(parsed) && parsed > 0) numResults = parsed
}
const description = nodeData.inputs?.description as string

return new OlostepSearch(String(apiKey), numResults, description)
}
}

module.exports = { nodeClass: OlostepSearch_Tools }
4 changes: 4 additions & 0 deletions packages/components/nodes/tools/OlostepSearch/olostep.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"object-hash": "^3.0.0",
"officeparser": "5.1.1",
"ollama": "^0.5.11",
"olostep": ">=0.1.0",
Comment thread
umerkay marked this conversation as resolved.
Outdated
"openai": "6.19.0",
"papaparse": "^5.4.1",
"pdf-parse": "^1.1.1",
Expand Down
Loading