Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.