@librefang/sdk 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/index.d.ts +140 -0
- package/index.js +479 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @librefang/sdk
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript client for the LibreFang Agent OS REST API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @librefang/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { LibreFang } = require("@librefang/sdk");
|
|
15
|
+
|
|
16
|
+
const client = new LibreFang("http://localhost:4545");
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Create an Agent
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
const agent = await client.agents.create({ template: "assistant" });
|
|
23
|
+
console.log("Agent created:", agent.id);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Send a Message
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
const reply = await client.agents.message(agent.id, "Hello!");
|
|
30
|
+
console.log(reply);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Streaming Response
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
for await (const event of client.agents.stream(agent.id, "Tell me a story")) {
|
|
37
|
+
if (event.type === "text_delta") {
|
|
38
|
+
process.stdout.write(event.delta);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### List Agents
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const agents = await client.agents.list();
|
|
47
|
+
console.log(agents);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### More Examples
|
|
51
|
+
|
|
52
|
+
See the `examples/` directory for more examples:
|
|
53
|
+
- `basic.js` - Basic usage
|
|
54
|
+
- `streaming.js` - Streaming responses
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### Constructor
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
new LibreFang(baseUrl, options)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- `baseUrl` - LibreFang server URL (e.g., "http://localhost:4545")
|
|
65
|
+
- `options` - Optional configuration
|
|
66
|
+
- `headers` - Extra headers for every request
|
|
67
|
+
|
|
68
|
+
### Resources
|
|
69
|
+
|
|
70
|
+
The client provides the following resources:
|
|
71
|
+
|
|
72
|
+
- `client.agents` - Agent management
|
|
73
|
+
- `client.sessions` - Session management
|
|
74
|
+
- `client.workflows` - Workflow management
|
|
75
|
+
- `client.skills` - Skill management
|
|
76
|
+
- `client.channels` - Channel management
|
|
77
|
+
- `client.tools` - Tool listing
|
|
78
|
+
- `client.models` - Model management
|
|
79
|
+
- `client.providers` - Provider management
|
|
80
|
+
- `client.memory` - Memory/KV storage
|
|
81
|
+
- `client.triggers` - Trigger management
|
|
82
|
+
- `client.schedules` - Schedule management
|
|
83
|
+
|
|
84
|
+
### Server Methods
|
|
85
|
+
|
|
86
|
+
- `client.health()` - Basic health check
|
|
87
|
+
- `client.healthDetail()` - Detailed health
|
|
88
|
+
- `client.status()` - Server status
|
|
89
|
+
- `client.version()` - Server version
|
|
90
|
+
- `client.metrics()` - Prometheus metrics
|
|
91
|
+
- `client.usage()` - Usage statistics
|
|
92
|
+
- `client.config()` - Server configuration
|
|
93
|
+
|
|
94
|
+
## TypeScript
|
|
95
|
+
|
|
96
|
+
This SDK includes TypeScript definitions (`index.d.ts`). Simply import and use:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { LibreFang } from "@librefang/sdk";
|
|
100
|
+
|
|
101
|
+
const client = new LibreFang("http://localhost:4545");
|
|
102
|
+
const agents = await client.agents.list();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export class LibreFangError extends Error {
|
|
2
|
+
status: number;
|
|
3
|
+
body: string;
|
|
4
|
+
constructor(message: string, status: number, body: string);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AgentCreateOpts {
|
|
8
|
+
template?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
model?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MessageOpts {
|
|
15
|
+
attachments?: string[];
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface StreamEvent {
|
|
20
|
+
type?: string;
|
|
21
|
+
delta?: string;
|
|
22
|
+
raw?: string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class LibreFang {
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
agents: AgentResource;
|
|
29
|
+
sessions: SessionResource;
|
|
30
|
+
workflows: WorkflowResource;
|
|
31
|
+
skills: SkillResource;
|
|
32
|
+
channels: ChannelResource;
|
|
33
|
+
tools: ToolResource;
|
|
34
|
+
models: ModelResource;
|
|
35
|
+
providers: ProviderResource;
|
|
36
|
+
memory: MemoryResource;
|
|
37
|
+
triggers: TriggerResource;
|
|
38
|
+
schedules: ScheduleResource;
|
|
39
|
+
|
|
40
|
+
constructor(baseUrl: string, opts?: { headers?: Record<string, string> });
|
|
41
|
+
|
|
42
|
+
health(): Promise<unknown>;
|
|
43
|
+
healthDetail(): Promise<unknown>;
|
|
44
|
+
status(): Promise<unknown>;
|
|
45
|
+
version(): Promise<unknown>;
|
|
46
|
+
metrics(): Promise<string>;
|
|
47
|
+
usage(): Promise<unknown>;
|
|
48
|
+
config(): Promise<unknown>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class AgentResource {
|
|
52
|
+
list(): Promise<unknown[]>;
|
|
53
|
+
get(id: string): Promise<unknown>;
|
|
54
|
+
create(opts: AgentCreateOpts): Promise<{ id: string; [key: string]: unknown }>;
|
|
55
|
+
delete(id: string): Promise<unknown>;
|
|
56
|
+
stop(id: string): Promise<unknown>;
|
|
57
|
+
clone(id: string): Promise<unknown>;
|
|
58
|
+
update(id: string, data: Record<string, unknown>): Promise<unknown>;
|
|
59
|
+
setMode(id: string, mode: string): Promise<unknown>;
|
|
60
|
+
setModel(id: string, model: string): Promise<unknown>;
|
|
61
|
+
message(id: string, text: string, opts?: MessageOpts): Promise<unknown>;
|
|
62
|
+
stream(id: string, text: string, opts?: MessageOpts): AsyncGenerator<StreamEvent>;
|
|
63
|
+
session(id: string): Promise<unknown>;
|
|
64
|
+
resetSession(id: string): Promise<unknown>;
|
|
65
|
+
compactSession(id: string): Promise<unknown>;
|
|
66
|
+
listSessions(id: string): Promise<unknown[]>;
|
|
67
|
+
createSession(id: string, label?: string): Promise<unknown>;
|
|
68
|
+
switchSession(id: string, sessionId: string): Promise<unknown>;
|
|
69
|
+
getSkills(id: string): Promise<unknown>;
|
|
70
|
+
setSkills(id: string, skills: unknown): Promise<unknown>;
|
|
71
|
+
upload(id: string, file: Blob | File, filename: string): Promise<unknown>;
|
|
72
|
+
setIdentity(id: string, identity: Record<string, unknown>): Promise<unknown>;
|
|
73
|
+
patchConfig(id: string, config: Record<string, unknown>): Promise<unknown>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class SessionResource {
|
|
77
|
+
list(): Promise<unknown[]>;
|
|
78
|
+
delete(id: string): Promise<unknown>;
|
|
79
|
+
setLabel(id: string, label: string): Promise<unknown>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class WorkflowResource {
|
|
83
|
+
list(): Promise<unknown[]>;
|
|
84
|
+
create(workflow: Record<string, unknown>): Promise<unknown>;
|
|
85
|
+
run(id: string, input?: Record<string, unknown>): Promise<unknown>;
|
|
86
|
+
runs(id: string): Promise<unknown[]>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class SkillResource {
|
|
90
|
+
list(): Promise<unknown[]>;
|
|
91
|
+
install(skill: Record<string, unknown>): Promise<unknown>;
|
|
92
|
+
uninstall(skill: Record<string, unknown>): Promise<unknown>;
|
|
93
|
+
search(query: string): Promise<unknown[]>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class ChannelResource {
|
|
97
|
+
list(): Promise<unknown[]>;
|
|
98
|
+
configure(name: string, config: Record<string, unknown>): Promise<unknown>;
|
|
99
|
+
remove(name: string): Promise<unknown>;
|
|
100
|
+
test(name: string): Promise<unknown>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class ToolResource {
|
|
104
|
+
list(): Promise<unknown[]>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export class ModelResource {
|
|
108
|
+
list(): Promise<unknown[]>;
|
|
109
|
+
get(id: string): Promise<unknown>;
|
|
110
|
+
aliases(): Promise<unknown>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class ProviderResource {
|
|
114
|
+
list(): Promise<unknown[]>;
|
|
115
|
+
setKey(name: string, key: string): Promise<unknown>;
|
|
116
|
+
deleteKey(name: string): Promise<unknown>;
|
|
117
|
+
test(name: string): Promise<unknown>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class MemoryResource {
|
|
121
|
+
getAll(agentId: string): Promise<Record<string, unknown>>;
|
|
122
|
+
get(agentId: string, key: string): Promise<unknown>;
|
|
123
|
+
set(agentId: string, key: string, value: unknown): Promise<unknown>;
|
|
124
|
+
delete(agentId: string, key: string): Promise<unknown>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export class TriggerResource {
|
|
128
|
+
list(): Promise<unknown[]>;
|
|
129
|
+
create(trigger: Record<string, unknown>): Promise<unknown>;
|
|
130
|
+
update(id: string, trigger: Record<string, unknown>): Promise<unknown>;
|
|
131
|
+
delete(id: string): Promise<unknown>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class ScheduleResource {
|
|
135
|
+
list(): Promise<unknown[]>;
|
|
136
|
+
create(schedule: Record<string, unknown>): Promise<unknown>;
|
|
137
|
+
update(id: string, schedule: Record<string, unknown>): Promise<unknown>;
|
|
138
|
+
delete(id: string): Promise<unknown>;
|
|
139
|
+
run(id: string): Promise<unknown>;
|
|
140
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @librefang/sdk — Official JavaScript client for the LibreFang Agent OS REST API.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* const { LibreFang } = require("@librefang/sdk");
|
|
6
|
+
* const client = new LibreFang("http://localhost:4545");
|
|
7
|
+
*
|
|
8
|
+
* const agent = await client.agents.create({ template: "assistant" });
|
|
9
|
+
* const reply = await client.agents.message(agent.id, "Hello!");
|
|
10
|
+
* console.log(reply);
|
|
11
|
+
*
|
|
12
|
+
* // Streaming:
|
|
13
|
+
* for await (const event of client.agents.stream(agent.id, "Tell me a joke")) {
|
|
14
|
+
* process.stdout.write(event.delta || "");
|
|
15
|
+
* }
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
"use strict";
|
|
19
|
+
|
|
20
|
+
class LibreFangError extends Error {
|
|
21
|
+
constructor(message, status, body) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "LibreFangError";
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.body = body;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class LibreFang {
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} baseUrl - LibreFang server URL (e.g. "http://localhost:4545")
|
|
32
|
+
* @param {object} [opts]
|
|
33
|
+
* @param {Record<string, string>} [opts.headers] - Extra headers for every request
|
|
34
|
+
*/
|
|
35
|
+
constructor(baseUrl, opts) {
|
|
36
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
37
|
+
this._headers = Object.assign({ "Content-Type": "application/json" }, (opts && opts.headers) || {});
|
|
38
|
+
this.agents = new AgentResource(this);
|
|
39
|
+
this.sessions = new SessionResource(this);
|
|
40
|
+
this.workflows = new WorkflowResource(this);
|
|
41
|
+
this.skills = new SkillResource(this);
|
|
42
|
+
this.channels = new ChannelResource(this);
|
|
43
|
+
this.tools = new ToolResource(this);
|
|
44
|
+
this.models = new ModelResource(this);
|
|
45
|
+
this.providers = new ProviderResource(this);
|
|
46
|
+
this.memory = new MemoryResource(this);
|
|
47
|
+
this.triggers = new TriggerResource(this);
|
|
48
|
+
this.schedules = new ScheduleResource(this);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Low-level fetch wrapper. */
|
|
52
|
+
async _request(method, path, body) {
|
|
53
|
+
var url = this.baseUrl + path;
|
|
54
|
+
var init = { method: method, headers: Object.assign({}, this._headers) };
|
|
55
|
+
if (body !== undefined) {
|
|
56
|
+
init.body = JSON.stringify(body);
|
|
57
|
+
}
|
|
58
|
+
var res = await fetch(url, init);
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
var text = await res.text().catch(function () { return ""; });
|
|
61
|
+
throw new LibreFangError("HTTP " + res.status + ": " + text, res.status, text);
|
|
62
|
+
}
|
|
63
|
+
var ct = res.headers.get("content-type") || "";
|
|
64
|
+
if (ct.includes("application/json")) {
|
|
65
|
+
return res.json();
|
|
66
|
+
}
|
|
67
|
+
return res.text();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Low-level SSE streaming. Returns an async iterator of parsed events. */
|
|
71
|
+
async *_stream(method, path, body) {
|
|
72
|
+
var url = this.baseUrl + path;
|
|
73
|
+
var headers = Object.assign({}, this._headers, { Accept: "text/event-stream" });
|
|
74
|
+
var init = { method: method, headers: headers };
|
|
75
|
+
if (body !== undefined) {
|
|
76
|
+
init.body = JSON.stringify(body);
|
|
77
|
+
}
|
|
78
|
+
var res = await fetch(url, init);
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
var text = await res.text().catch(function () { return ""; });
|
|
81
|
+
throw new LibreFangError("HTTP " + res.status + ": " + text, res.status, text);
|
|
82
|
+
}
|
|
83
|
+
var reader = res.body.getReader();
|
|
84
|
+
var decoder = new TextDecoder();
|
|
85
|
+
var buffer = "";
|
|
86
|
+
while (true) {
|
|
87
|
+
var result = await reader.read();
|
|
88
|
+
if (result.done) break;
|
|
89
|
+
buffer += decoder.decode(result.value, { stream: true });
|
|
90
|
+
var lines = buffer.split("\n");
|
|
91
|
+
buffer = lines.pop() || "";
|
|
92
|
+
for (var i = 0; i < lines.length; i++) {
|
|
93
|
+
var line = lines[i].trim();
|
|
94
|
+
if (line.startsWith("data: ")) {
|
|
95
|
+
var data = line.slice(6);
|
|
96
|
+
if (data === "[DONE]") return;
|
|
97
|
+
try {
|
|
98
|
+
yield JSON.parse(data);
|
|
99
|
+
} catch (_) {
|
|
100
|
+
yield { raw: data };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Health check. */
|
|
108
|
+
async health() {
|
|
109
|
+
return this._request("GET", "/api/health");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Detailed health. */
|
|
113
|
+
async healthDetail() {
|
|
114
|
+
return this._request("GET", "/api/health/detail");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Server status. */
|
|
118
|
+
async status() {
|
|
119
|
+
return this._request("GET", "/api/status");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Server version. */
|
|
123
|
+
async version() {
|
|
124
|
+
return this._request("GET", "/api/version");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Prometheus metrics (text). */
|
|
128
|
+
async metrics() {
|
|
129
|
+
return this._request("GET", "/api/metrics");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Usage statistics. */
|
|
133
|
+
async usage() {
|
|
134
|
+
return this._request("GET", "/api/usage");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Config. */
|
|
138
|
+
async config() {
|
|
139
|
+
return this._request("GET", "/api/config");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ── Agent Resource ──────────────────────────────────────────────
|
|
144
|
+
|
|
145
|
+
class AgentResource {
|
|
146
|
+
constructor(client) { this._c = client; }
|
|
147
|
+
|
|
148
|
+
/** List all agents. */
|
|
149
|
+
async list() {
|
|
150
|
+
return this._c._request("GET", "/api/agents");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Get agent by ID. */
|
|
154
|
+
async get(id) {
|
|
155
|
+
return this._c._request("GET", "/api/agents/" + id);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Create (spawn) a new agent.
|
|
159
|
+
* @param {object} opts - e.g. { template: "assistant", name: "My Agent" }
|
|
160
|
+
*/
|
|
161
|
+
async create(opts) {
|
|
162
|
+
return this._c._request("POST", "/api/agents", opts);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Delete (kill) an agent. */
|
|
166
|
+
async delete(id) {
|
|
167
|
+
return this._c._request("DELETE", "/api/agents/" + id);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Stop an agent. */
|
|
171
|
+
async stop(id) {
|
|
172
|
+
return this._c._request("POST", "/api/agents/" + id + "/stop");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Clone an agent. */
|
|
176
|
+
async clone(id) {
|
|
177
|
+
return this._c._request("POST", "/api/agents/" + id + "/clone");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Update agent. */
|
|
181
|
+
async update(id, data) {
|
|
182
|
+
return this._c._request("PUT", "/api/agents/" + id + "/update", data);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Set agent mode. */
|
|
186
|
+
async setMode(id, mode) {
|
|
187
|
+
return this._c._request("PUT", "/api/agents/" + id + "/mode", { mode: mode });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Set agent model. */
|
|
191
|
+
async setModel(id, model) {
|
|
192
|
+
return this._c._request("PUT", "/api/agents/" + id + "/model", { model: model });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Send a message and get the full response. */
|
|
196
|
+
async message(id, text, opts) {
|
|
197
|
+
var body = Object.assign({ message: text }, opts || {});
|
|
198
|
+
return this._c._request("POST", "/api/agents/" + id + "/message", body);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Send a message and stream the response (async iterator of SSE events).
|
|
202
|
+
* @example
|
|
203
|
+
* for await (const evt of client.agents.stream(id, "Hello")) {
|
|
204
|
+
* if (evt.type === "text_delta") process.stdout.write(evt.delta);
|
|
205
|
+
* }
|
|
206
|
+
*/
|
|
207
|
+
async *stream(id, text, opts) {
|
|
208
|
+
var body = Object.assign({ message: text }, opts || {});
|
|
209
|
+
yield* this._c._stream("POST", "/api/agents/" + id + "/message/stream", body);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Get agent session. */
|
|
213
|
+
async session(id) {
|
|
214
|
+
return this._c._request("GET", "/api/agents/" + id + "/session");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Reset agent session. */
|
|
218
|
+
async resetSession(id) {
|
|
219
|
+
return this._c._request("POST", "/api/agents/" + id + "/session/reset");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Compact session. */
|
|
223
|
+
async compactSession(id) {
|
|
224
|
+
return this._c._request("POST", "/api/agents/" + id + "/session/compact");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** List sessions for an agent. */
|
|
228
|
+
async listSessions(id) {
|
|
229
|
+
return this._c._request("GET", "/api/agents/" + id + "/sessions");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Create a new session. */
|
|
233
|
+
async createSession(id, label) {
|
|
234
|
+
return this._c._request("POST", "/api/agents/" + id + "/sessions", { label: label });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Switch to a session. */
|
|
238
|
+
async switchSession(id, sessionId) {
|
|
239
|
+
return this._c._request("POST", "/api/agents/" + id + "/sessions/" + sessionId + "/switch");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Get agent skills. */
|
|
243
|
+
async getSkills(id) {
|
|
244
|
+
return this._c._request("GET", "/api/agents/" + id + "/skills");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Set agent skills. */
|
|
248
|
+
async setSkills(id, skills) {
|
|
249
|
+
return this._c._request("PUT", "/api/agents/" + id + "/skills", skills);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Upload a file to agent. */
|
|
253
|
+
async upload(id, file, filename) {
|
|
254
|
+
var url = this._c.baseUrl + "/api/agents/" + id + "/upload";
|
|
255
|
+
var form = new FormData();
|
|
256
|
+
form.append("file", file, filename);
|
|
257
|
+
var res = await fetch(url, { method: "POST", body: form });
|
|
258
|
+
if (!res.ok) throw new LibreFangError("Upload failed: " + res.status, res.status);
|
|
259
|
+
return res.json();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Update agent identity. */
|
|
263
|
+
async setIdentity(id, identity) {
|
|
264
|
+
return this._c._request("PATCH", "/api/agents/" + id + "/identity", identity);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Patch agent config. */
|
|
268
|
+
async patchConfig(id, config) {
|
|
269
|
+
return this._c._request("PATCH", "/api/agents/" + id + "/config", config);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ── Session Resource ────────────────────────────────────────────
|
|
274
|
+
|
|
275
|
+
class SessionResource {
|
|
276
|
+
constructor(client) { this._c = client; }
|
|
277
|
+
|
|
278
|
+
async list() {
|
|
279
|
+
return this._c._request("GET", "/api/sessions");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async delete(id) {
|
|
283
|
+
return this._c._request("DELETE", "/api/sessions/" + id);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async setLabel(id, label) {
|
|
287
|
+
return this._c._request("PUT", "/api/sessions/" + id + "/label", { label: label });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ── Workflow Resource ───────────────────────────────────────────
|
|
292
|
+
|
|
293
|
+
class WorkflowResource {
|
|
294
|
+
constructor(client) { this._c = client; }
|
|
295
|
+
|
|
296
|
+
async list() {
|
|
297
|
+
return this._c._request("GET", "/api/workflows");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async create(workflow) {
|
|
301
|
+
return this._c._request("POST", "/api/workflows", workflow);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async run(id, input) {
|
|
305
|
+
return this._c._request("POST", "/api/workflows/" + id + "/run", input);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async runs(id) {
|
|
309
|
+
return this._c._request("GET", "/api/workflows/" + id + "/runs");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// ── Skill Resource ──────────────────────────────────────────────
|
|
314
|
+
|
|
315
|
+
class SkillResource {
|
|
316
|
+
constructor(client) { this._c = client; }
|
|
317
|
+
|
|
318
|
+
async list() {
|
|
319
|
+
return this._c._request("GET", "/api/skills");
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async install(skill) {
|
|
323
|
+
return this._c._request("POST", "/api/skills/install", skill);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async uninstall(skill) {
|
|
327
|
+
return this._c._request("POST", "/api/skills/uninstall", skill);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async search(query) {
|
|
331
|
+
return this._c._request("GET", "/api/marketplace/search?q=" + encodeURIComponent(query));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ── Channel Resource ────────────────────────────────────────────
|
|
336
|
+
|
|
337
|
+
class ChannelResource {
|
|
338
|
+
constructor(client) { this._c = client; }
|
|
339
|
+
|
|
340
|
+
async list() {
|
|
341
|
+
return this._c._request("GET", "/api/channels");
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async configure(name, config) {
|
|
345
|
+
return this._c._request("POST", "/api/channels/" + name + "/configure", config);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async remove(name) {
|
|
349
|
+
return this._c._request("DELETE", "/api/channels/" + name + "/configure");
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async test(name) {
|
|
353
|
+
return this._c._request("POST", "/api/channels/" + name + "/test");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// ── Tool Resource ───────────────────────────────────────────────
|
|
358
|
+
|
|
359
|
+
class ToolResource {
|
|
360
|
+
constructor(client) { this._c = client; }
|
|
361
|
+
|
|
362
|
+
async list() {
|
|
363
|
+
return this._c._request("GET", "/api/tools");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ── Model Resource ──────────────────────────────────────────────
|
|
368
|
+
|
|
369
|
+
class ModelResource {
|
|
370
|
+
constructor(client) { this._c = client; }
|
|
371
|
+
|
|
372
|
+
async list() {
|
|
373
|
+
return this._c._request("GET", "/api/models");
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async get(id) {
|
|
377
|
+
return this._c._request("GET", "/api/models/" + id);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async aliases() {
|
|
381
|
+
return this._c._request("GET", "/api/models/aliases");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ── Provider Resource ───────────────────────────────────────────
|
|
386
|
+
|
|
387
|
+
class ProviderResource {
|
|
388
|
+
constructor(client) { this._c = client; }
|
|
389
|
+
|
|
390
|
+
async list() {
|
|
391
|
+
return this._c._request("GET", "/api/providers");
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async setKey(name, key) {
|
|
395
|
+
return this._c._request("POST", "/api/providers/" + name + "/key", { key: key });
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async deleteKey(name) {
|
|
399
|
+
return this._c._request("DELETE", "/api/providers/" + name + "/key");
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async test(name) {
|
|
403
|
+
return this._c._request("POST", "/api/providers/" + name + "/test");
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ── Memory Resource ─────────────────────────────────────────────
|
|
408
|
+
|
|
409
|
+
class MemoryResource {
|
|
410
|
+
constructor(client) { this._c = client; }
|
|
411
|
+
|
|
412
|
+
async getAll(agentId) {
|
|
413
|
+
return this._c._request("GET", "/api/memory/agents/" + agentId + "/kv");
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async get(agentId, key) {
|
|
417
|
+
return this._c._request("GET", "/api/memory/agents/" + agentId + "/kv/" + key);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async set(agentId, key, value) {
|
|
421
|
+
return this._c._request("PUT", "/api/memory/agents/" + agentId + "/kv/" + key, { value: value });
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
async delete(agentId, key) {
|
|
425
|
+
return this._c._request("DELETE", "/api/memory/agents/" + agentId + "/kv/" + key);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// ── Trigger Resource ────────────────────────────────────────────
|
|
430
|
+
|
|
431
|
+
class TriggerResource {
|
|
432
|
+
constructor(client) { this._c = client; }
|
|
433
|
+
|
|
434
|
+
async list() {
|
|
435
|
+
return this._c._request("GET", "/api/triggers");
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async create(trigger) {
|
|
439
|
+
return this._c._request("POST", "/api/triggers", trigger);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
async update(id, trigger) {
|
|
443
|
+
return this._c._request("PUT", "/api/triggers/" + id, trigger);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
async delete(id) {
|
|
447
|
+
return this._c._request("DELETE", "/api/triggers/" + id);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// ── Schedule Resource ───────────────────────────────────────────
|
|
452
|
+
|
|
453
|
+
class ScheduleResource {
|
|
454
|
+
constructor(client) { this._c = client; }
|
|
455
|
+
|
|
456
|
+
async list() {
|
|
457
|
+
return this._c._request("GET", "/api/schedules");
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
async create(schedule) {
|
|
461
|
+
return this._c._request("POST", "/api/schedules", schedule);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async update(id, schedule) {
|
|
465
|
+
return this._c._request("PUT", "/api/schedules/" + id, schedule);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
async delete(id) {
|
|
469
|
+
return this._c._request("DELETE", "/api/schedules/" + id);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
async run(id) {
|
|
473
|
+
return this._c._request("POST", "/api/schedules/" + id + "/run");
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// ── Exports ─────────────────────────────────────────────────────
|
|
478
|
+
|
|
479
|
+
module.exports = { LibreFang: LibreFang, LibreFangError: LibreFangError };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@librefang/sdk",
|
|
3
|
+
"version": "0.5.6",
|
|
4
|
+
"description": "Official JavaScript/TypeScript client for the LibreFang Agent OS REST API",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"librefang",
|
|
9
|
+
"agent",
|
|
10
|
+
"ai",
|
|
11
|
+
"llm",
|
|
12
|
+
"autonomous-agent",
|
|
13
|
+
"sdk"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/librefang/librefang",
|
|
19
|
+
"directory": "sdk/javascript"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://librefang.ai",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/librefang/librefang/issues"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18.0.0"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"index.js",
|
|
30
|
+
"index.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./index.d.ts",
|
|
35
|
+
"import": "./index.js",
|
|
36
|
+
"require": "./index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"type": "commonjs",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test": "node examples/basic.js"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"registry": "https://registry.npmjs.org"
|
|
46
|
+
}
|
|
47
|
+
}
|