Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@isdk/ai-tool
Advanced tools
A library for abstracting AI utility functions (ToolFunc
), providing a series of convenient helper functions.
Note: All ToolFunc
parameters are object-based, not positional.
Install the package:
npm install @isdk/ai-tool
Register ordinary functions as ToolFunc
.
import { ToolFunc } from '@isdk/ai-tool';
// Register a function directly
ToolFunc.register({
name: 'add',
description: 'Return the sum of a and b',
params: { a: { type: 'number' }, b: { type: 'number' } },
result: 'number',
func: ({ a, b }: { a: number; b: number }) => a + b,
});
console.log('Result:', ToolFunc.runSync('add', { a: 1, b: 2 }));
// Result: 3
Properties
func
: The main body of the tool function.name
: Name of the tool function.params
: Parameter schema for the tool function.result
: Return type of the tool function.scope
: Scope of the function.description
: Description of the tool function.setup
: Executed during the construction of the ToolFunc instance.depends
: Dependencies on other ToolFunc instances.Server-side AI tool functions.
Features
toJSON()
method to export all service API definitions.interface ServerFuncItem extends FuncItem {
apiRoot?: string
/**
* API request method, can be 'get' or 'post'
*/
action?: 'get'|'post'
// Options for the Node.js fetch function
fetchOptions?: any
// Whether to allow exporting the func body itself, default to false
allowExportFunc?: boolean
}
Usage: Parameters are sent via query string for GET requests and in the body for POST requests.
Used to call remote AI tool functions (ServerTools).
Features
interface ClientFuncItem extends FuncItem {
apiRoot?: string
action?: 'get'|'post'
fetchOptions?: any
}
Resource-based server tools, where resources are named ToolFunc.
GET /api/res/:id
: Get resource.GET /api/res
: List resources.POST /api/res
: Create resource.PUT /api/res/:id
: Update resource.DELETE /api/res/:id
: Delete resource.Methods prefixed with $
are custom resource methods, accessible via POST
.
Example
class TestResTool extends ResServerTools {
items: any = {}
params: FuncParams = {
'id': {type: 'number'},
'val': {type: 'any'},
}
$customMethod({id}: ResServerFuncParams) {
if (id) {
const item = this.items[id]
if (!item) {
throw new NotFoundError(id, 'res')
}
return {name: 'customMethod', id, item}
}
}
get({id}: ResServerFuncParams) {
if (id) {
const item = this.items[id]
if (!item) {
throw new NotFoundError(id, 'res')
}
return item
}
}
post({id, val}: ResServerFuncParams) {
if (id !== undefined && val !== undefined) {
this.items[id] = val
return {id}
} else {
throwError('id or val is undefined')
}
}
list() {
return Object.keys(this.items)
}
delete({id}: ResServerFuncParams) {
if (id) {
const item = this.items[id]
if (item === undefined) {
throw new NotFoundError(id, 'res')
}
delete this.items[id]
return {id}
}
}
}
ResServerTools.apiRoot = apiRoot
const res = new TestResTool('res')
res.register()
Resource-based client tools that generate methods based on ServerTools agreements.
Example
ResClientTools.apiRoot = apiRoot
await ResClientTools.loadFrom()
const resFunc = ResClientTools.getFunc(funcName)
if (resFunc) {
let result = await res.post({id: '...', val: '...'})
result = await res.put({id: '...', val: '...'})
result = await res.get({id: '...'})
result = await res.customMethod({id: '...'})
}
Endpoints
GET /api/event
: List server event channel (stream).POST /api/event
: Subscribe to server events.DELETE /api/event
: Unsubscribe from server events.PUT /api/event
: Publish messages to server events.The EventClient
component facilitates communication between the client and server through Server-Sent Events (SSE). Its primary responsibilities include subscribing to server events and publishing messages to the server.
initEventSource(events)
: Specifies which events to receive from the server. If events
is not provided, all events are received.subscribe(events)
: Subscribes to specified server events and forwards them to the local event bus.
unsubscribe(events)
: Cancels subscriptions to specified server events.forwardEvent(events)
: Forwards specific local events to the server.unforwardEvent(events)
: Stops forwarding specific local events to the server.forwardEvent
method.ToolFunc
to maintain flexibility and separation of concerns.The EventServer
component manages server-side event processing, including publishing and subscribing to events.
Key Features
Actions
pub
: Publishes an SSE event.sub
: Subscribes to server events.unsub
: Unsubscribes from server events.Usage
act
or with only events
specified are used for server-side event handling.act
define specific actions such as publishing, subscribing, or unsubscribing from events.If you would like to contribute to the project, please read the CONTRIBUTING.md file for guidelines on how to get started.
The project is licensed under the MIT License. See the LICENSE-MIT file for more details.
FAQs
AI tools
We found that @isdk/ai-tool demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.