@agents-eco/open-agentic-framework 0.1.0
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/LICENSE +21 -0
- package/README.md +427 -0
- package/dist/agent.d.ts +58 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +306 -0
- package/dist/agent.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +273 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +36 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +166 -0
- package/dist/memory.js.map +1 -0
- package/dist/provider.d.ts +24 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +124 -0
- package/dist/provider.js.map +1 -0
- package/dist/skills.d.ts +53 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +139 -0
- package/dist/skills.js.map +1 -0
- package/dist/types.d.ts +166 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/icon.png +0 -0
- package/package.json +58 -0
- package/skills/code-exec/SKILL.md +34 -0
- package/skills/file-ops/SKILL.md +50 -0
- package/skills/web-search/SKILL.md +31 -0
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { MemoryStore, MemoryEntry } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* File-based memory store using JSONL (one JSON object per line).
|
|
4
|
+
* Human-readable, inspectable, and portable — inspired by OpenClaw's flat-file approach.
|
|
5
|
+
*
|
|
6
|
+
* Files:
|
|
7
|
+
* - memory.jsonl — append-only log of all memory entries
|
|
8
|
+
* - context.md — auto-generated markdown summary for human reading
|
|
9
|
+
*/
|
|
10
|
+
export declare class MarkdownMemory implements MemoryStore {
|
|
11
|
+
private dir;
|
|
12
|
+
private jsonlPath;
|
|
13
|
+
private contextPath;
|
|
14
|
+
private entries;
|
|
15
|
+
private loaded;
|
|
16
|
+
constructor(dir?: string);
|
|
17
|
+
private ensureDir;
|
|
18
|
+
private load;
|
|
19
|
+
private appendLine;
|
|
20
|
+
private updateContextMd;
|
|
21
|
+
add(entry: Omit<MemoryEntry, "id" | "timestamp">): Promise<MemoryEntry>;
|
|
22
|
+
search(query: string, limit?: number): Promise<MemoryEntry[]>;
|
|
23
|
+
list(limit?: number): Promise<MemoryEntry[]>;
|
|
24
|
+
clear(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* In-memory store (no persistence). Useful for testing or ephemeral agents.
|
|
28
|
+
*/
|
|
29
|
+
export declare class InMemoryStore implements MemoryStore {
|
|
30
|
+
private entries;
|
|
31
|
+
add(entry: Omit<MemoryEntry, "id" | "timestamp">): Promise<MemoryEntry>;
|
|
32
|
+
search(query: string, limit?: number): Promise<MemoryEntry[]>;
|
|
33
|
+
list(limit?: number): Promise<MemoryEntry[]>;
|
|
34
|
+
clear(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;GAOG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,MAAM,CAAS;gBAEX,GAAG,CAAC,EAAE,MAAM;IAMxB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,IAAI;IAuBZ,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,eAAe;IA8BjB,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAgBvE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAuBxD,IAAI,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAKxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,WAAW;IAC/C,OAAO,CAAC,OAAO,CAAqB;IAE9B,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAoBxD,IAAI,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
/**
|
|
5
|
+
* File-based memory store using JSONL (one JSON object per line).
|
|
6
|
+
* Human-readable, inspectable, and portable — inspired by OpenClaw's flat-file approach.
|
|
7
|
+
*
|
|
8
|
+
* Files:
|
|
9
|
+
* - memory.jsonl — append-only log of all memory entries
|
|
10
|
+
* - context.md — auto-generated markdown summary for human reading
|
|
11
|
+
*/
|
|
12
|
+
export class MarkdownMemory {
|
|
13
|
+
dir;
|
|
14
|
+
jsonlPath;
|
|
15
|
+
contextPath;
|
|
16
|
+
entries = [];
|
|
17
|
+
loaded = false;
|
|
18
|
+
constructor(dir) {
|
|
19
|
+
this.dir = resolve(dir ?? "./.agent/memory");
|
|
20
|
+
this.jsonlPath = join(this.dir, "memory.jsonl");
|
|
21
|
+
this.contextPath = join(this.dir, "context.md");
|
|
22
|
+
}
|
|
23
|
+
ensureDir() {
|
|
24
|
+
if (!existsSync(this.dir)) {
|
|
25
|
+
mkdirSync(this.dir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
load() {
|
|
29
|
+
if (this.loaded)
|
|
30
|
+
return;
|
|
31
|
+
this.loaded = true;
|
|
32
|
+
if (!existsSync(this.jsonlPath)) {
|
|
33
|
+
this.entries = [];
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const raw = readFileSync(this.jsonlPath, "utf-8");
|
|
37
|
+
this.entries = raw
|
|
38
|
+
.split("\n")
|
|
39
|
+
.filter((line) => line.trim())
|
|
40
|
+
.map((line) => {
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(line);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.filter((e) => e !== null);
|
|
49
|
+
}
|
|
50
|
+
appendLine(entry) {
|
|
51
|
+
this.ensureDir();
|
|
52
|
+
const line = JSON.stringify(entry) + "\n";
|
|
53
|
+
writeFileSync(this.jsonlPath, line, { flag: "a" });
|
|
54
|
+
}
|
|
55
|
+
updateContextMd() {
|
|
56
|
+
this.ensureDir();
|
|
57
|
+
const lines = [
|
|
58
|
+
"# Agent Memory",
|
|
59
|
+
"",
|
|
60
|
+
`> Auto-generated. ${this.entries.length} entries. Last updated: ${new Date().toISOString()}`,
|
|
61
|
+
"",
|
|
62
|
+
];
|
|
63
|
+
// Group by type
|
|
64
|
+
const grouped = new Map();
|
|
65
|
+
for (const e of this.entries) {
|
|
66
|
+
const arr = grouped.get(e.type) ?? [];
|
|
67
|
+
arr.push(e);
|
|
68
|
+
grouped.set(e.type, arr);
|
|
69
|
+
}
|
|
70
|
+
for (const [type, entries] of grouped) {
|
|
71
|
+
lines.push(`## ${type.charAt(0).toUpperCase() + type.slice(1)}s`);
|
|
72
|
+
lines.push("");
|
|
73
|
+
for (const e of entries.slice(-20)) {
|
|
74
|
+
const date = new Date(e.timestamp).toLocaleDateString();
|
|
75
|
+
lines.push(`- [${date}] ${e.content.slice(0, 200)}`);
|
|
76
|
+
}
|
|
77
|
+
lines.push("");
|
|
78
|
+
}
|
|
79
|
+
writeFileSync(this.contextPath, lines.join("\n"));
|
|
80
|
+
}
|
|
81
|
+
async add(entry) {
|
|
82
|
+
this.load();
|
|
83
|
+
const full = {
|
|
84
|
+
...entry,
|
|
85
|
+
id: randomUUID(),
|
|
86
|
+
timestamp: new Date().toISOString(),
|
|
87
|
+
};
|
|
88
|
+
this.entries.push(full);
|
|
89
|
+
this.appendLine(full);
|
|
90
|
+
this.updateContextMd();
|
|
91
|
+
return full;
|
|
92
|
+
}
|
|
93
|
+
async search(query, limit = 5) {
|
|
94
|
+
this.load();
|
|
95
|
+
// Simple keyword search — score by number of matching words
|
|
96
|
+
const queryWords = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
97
|
+
if (queryWords.length === 0)
|
|
98
|
+
return this.entries.slice(-limit);
|
|
99
|
+
const scored = this.entries.map((e) => {
|
|
100
|
+
const text = e.content.toLowerCase();
|
|
101
|
+
let score = 0;
|
|
102
|
+
for (const word of queryWords) {
|
|
103
|
+
if (text.includes(word))
|
|
104
|
+
score++;
|
|
105
|
+
}
|
|
106
|
+
return { entry: e, score };
|
|
107
|
+
});
|
|
108
|
+
return scored
|
|
109
|
+
.filter((s) => s.score > 0)
|
|
110
|
+
.sort((a, b) => b.score - a.score)
|
|
111
|
+
.slice(0, limit)
|
|
112
|
+
.map((s) => s.entry);
|
|
113
|
+
}
|
|
114
|
+
async list(limit = 50) {
|
|
115
|
+
this.load();
|
|
116
|
+
return this.entries.slice(-limit);
|
|
117
|
+
}
|
|
118
|
+
async clear() {
|
|
119
|
+
this.entries = [];
|
|
120
|
+
this.loaded = true;
|
|
121
|
+
this.ensureDir();
|
|
122
|
+
writeFileSync(this.jsonlPath, "");
|
|
123
|
+
this.updateContextMd();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* In-memory store (no persistence). Useful for testing or ephemeral agents.
|
|
128
|
+
*/
|
|
129
|
+
export class InMemoryStore {
|
|
130
|
+
entries = [];
|
|
131
|
+
async add(entry) {
|
|
132
|
+
const full = {
|
|
133
|
+
...entry,
|
|
134
|
+
id: randomUUID(),
|
|
135
|
+
timestamp: new Date().toISOString(),
|
|
136
|
+
};
|
|
137
|
+
this.entries.push(full);
|
|
138
|
+
return full;
|
|
139
|
+
}
|
|
140
|
+
async search(query, limit = 5) {
|
|
141
|
+
const queryWords = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
142
|
+
if (queryWords.length === 0)
|
|
143
|
+
return this.entries.slice(-limit);
|
|
144
|
+
const scored = this.entries.map((e) => {
|
|
145
|
+
const text = e.content.toLowerCase();
|
|
146
|
+
let score = 0;
|
|
147
|
+
for (const word of queryWords) {
|
|
148
|
+
if (text.includes(word))
|
|
149
|
+
score++;
|
|
150
|
+
}
|
|
151
|
+
return { entry: e, score };
|
|
152
|
+
});
|
|
153
|
+
return scored
|
|
154
|
+
.filter((s) => s.score > 0)
|
|
155
|
+
.sort((a, b) => b.score - a.score)
|
|
156
|
+
.slice(0, limit)
|
|
157
|
+
.map((s) => s.entry);
|
|
158
|
+
}
|
|
159
|
+
async list(limit = 50) {
|
|
160
|
+
return this.entries.slice(-limit);
|
|
161
|
+
}
|
|
162
|
+
async clear() {
|
|
163
|
+
this.entries = [];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mapp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,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;aACjC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;aACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Provider, ProviderConfig, LLMRequest, LLMResponse } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* OpenAI-compatible provider.
|
|
4
|
+
* Works with: OpenAI, Venice, Groq, Together, Ollama, agents.eco, any OpenAI-compatible API.
|
|
5
|
+
*/
|
|
6
|
+
export declare class OpenAIProvider implements Provider {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
private apiKey;
|
|
9
|
+
private baseUrl;
|
|
10
|
+
private headers;
|
|
11
|
+
constructor(config: ProviderConfig);
|
|
12
|
+
chat(request: LLMRequest): Promise<LLMResponse>;
|
|
13
|
+
}
|
|
14
|
+
/** Create a provider for agents.eco API */
|
|
15
|
+
export declare function agentsEcoProvider(apiKey: string, baseUrl?: string): Provider;
|
|
16
|
+
/** Create a provider for Venice AI */
|
|
17
|
+
export declare function veniceProvider(apiKey: string): Provider;
|
|
18
|
+
/** Create a provider for OpenAI */
|
|
19
|
+
export declare function openaiProvider(apiKey: string): Provider;
|
|
20
|
+
/** Create a provider for Groq */
|
|
21
|
+
export declare function groqProvider(apiKey: string): Provider;
|
|
22
|
+
/** Create a provider for a local Ollama instance */
|
|
23
|
+
export declare function ollamaProvider(model?: string, baseUrl?: string): Provider;
|
|
24
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,UAAU,EACV,WAAW,EAGZ,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,qBAAa,cAAe,YAAW,QAAQ;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAyB;gBAE5B,MAAM,EAAE,cAAc;IAO5B,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CAqEtD;AAID,2CAA2C;AAC3C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,SAAkD,GAAG,QAAQ,CAOrH;AAED,sCAAsC;AACtC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAOvD;AAED,mCAAmC;AACnC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAOvD;AAED,iCAAiC;AACjC,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAOrD;AAED,oDAAoD;AACpD,wBAAgB,cAAc,CAAC,KAAK,SAAa,EAAE,OAAO,SAA2B,GAAG,QAAQ,CAM/F"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible provider.
|
|
3
|
+
* Works with: OpenAI, Venice, Groq, Together, Ollama, agents.eco, any OpenAI-compatible API.
|
|
4
|
+
*/
|
|
5
|
+
export class OpenAIProvider {
|
|
6
|
+
name;
|
|
7
|
+
apiKey;
|
|
8
|
+
baseUrl;
|
|
9
|
+
headers;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.name = config.name;
|
|
12
|
+
this.apiKey = config.apiKey ?? "";
|
|
13
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
14
|
+
this.headers = config.headers ?? {};
|
|
15
|
+
}
|
|
16
|
+
async chat(request) {
|
|
17
|
+
const messages = request.messages.map((m) => {
|
|
18
|
+
const msg = { role: m.role, content: m.content };
|
|
19
|
+
if (m.name)
|
|
20
|
+
msg.name = m.name;
|
|
21
|
+
if (m.toolCallId)
|
|
22
|
+
msg.tool_call_id = m.toolCallId;
|
|
23
|
+
return msg;
|
|
24
|
+
});
|
|
25
|
+
const body = {
|
|
26
|
+
model: request.model,
|
|
27
|
+
messages,
|
|
28
|
+
temperature: request.temperature ?? 0.7,
|
|
29
|
+
max_tokens: request.maxTokens ?? 4096,
|
|
30
|
+
};
|
|
31
|
+
if (request.tools && request.tools.length > 0) {
|
|
32
|
+
body.tools = request.tools;
|
|
33
|
+
if (request.toolChoice) {
|
|
34
|
+
body.tool_choice = request.toolChoice;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const headers = {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
...this.headers,
|
|
40
|
+
};
|
|
41
|
+
if (this.apiKey) {
|
|
42
|
+
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
43
|
+
}
|
|
44
|
+
const res = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers,
|
|
47
|
+
body: JSON.stringify(body),
|
|
48
|
+
});
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
const errText = await res.text();
|
|
51
|
+
throw new Error(`[${this.name}] LLM request failed (${res.status}): ${errText}`);
|
|
52
|
+
}
|
|
53
|
+
const data = await res.json();
|
|
54
|
+
const choice = data.choices?.[0];
|
|
55
|
+
if (!choice) {
|
|
56
|
+
throw new Error(`[${this.name}] No choices in response`);
|
|
57
|
+
}
|
|
58
|
+
const toolCalls = (choice.message?.tool_calls ?? []).map((tc) => ({
|
|
59
|
+
id: tc.id,
|
|
60
|
+
type: "function",
|
|
61
|
+
function: {
|
|
62
|
+
name: tc.function.name,
|
|
63
|
+
arguments: tc.function.arguments,
|
|
64
|
+
},
|
|
65
|
+
}));
|
|
66
|
+
return {
|
|
67
|
+
content: choice.message?.content ?? "",
|
|
68
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
69
|
+
usage: {
|
|
70
|
+
promptTokens: data.usage?.prompt_tokens ?? 0,
|
|
71
|
+
completionTokens: data.usage?.completion_tokens ?? 0,
|
|
72
|
+
totalTokens: data.usage?.total_tokens ?? 0,
|
|
73
|
+
},
|
|
74
|
+
model: data.model ?? request.model,
|
|
75
|
+
finishReason: choice.finish_reason ?? "stop",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ── Pre-configured provider factories ───────────────────
|
|
80
|
+
/** Create a provider for agents.eco API */
|
|
81
|
+
export function agentsEcoProvider(apiKey, baseUrl = "https://agents-eco-dfc6baa9f955.herokuapp.com") {
|
|
82
|
+
return new OpenAIProvider({
|
|
83
|
+
name: "agents.eco",
|
|
84
|
+
apiKey,
|
|
85
|
+
baseUrl: `${baseUrl}/v1`,
|
|
86
|
+
defaultModel: "qwen3-4b",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Create a provider for Venice AI */
|
|
90
|
+
export function veniceProvider(apiKey) {
|
|
91
|
+
return new OpenAIProvider({
|
|
92
|
+
name: "venice",
|
|
93
|
+
apiKey,
|
|
94
|
+
baseUrl: "https://api.venice.ai/api/v1",
|
|
95
|
+
defaultModel: "qwen3-4b",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** Create a provider for OpenAI */
|
|
99
|
+
export function openaiProvider(apiKey) {
|
|
100
|
+
return new OpenAIProvider({
|
|
101
|
+
name: "openai",
|
|
102
|
+
apiKey,
|
|
103
|
+
baseUrl: "https://api.openai.com/v1",
|
|
104
|
+
defaultModel: "gpt-4o-mini",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** Create a provider for Groq */
|
|
108
|
+
export function groqProvider(apiKey) {
|
|
109
|
+
return new OpenAIProvider({
|
|
110
|
+
name: "groq",
|
|
111
|
+
apiKey,
|
|
112
|
+
baseUrl: "https://api.groq.com/openai/v1",
|
|
113
|
+
defaultModel: "llama-3.3-70b-versatile",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** Create a provider for a local Ollama instance */
|
|
117
|
+
export function ollamaProvider(model = "llama3.2", baseUrl = "http://localhost:11434") {
|
|
118
|
+
return new OpenAIProvider({
|
|
119
|
+
name: "ollama",
|
|
120
|
+
baseUrl: `${baseUrl}/v1`,
|
|
121
|
+
defaultModel: model,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,OAAO,cAAc;IAChB,IAAI,CAAS;IACd,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,OAAO,CAAyB;IAExC,YAAY,MAAsB;QAChC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAmB;QAC5B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC1C,MAAM,GAAG,GAA4B,EAAE,IAAI,EAAE,CAAC,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IACJ,CAAC;CACF;AAED,2DAA2D;AAE3D,2CAA2C;AAC3C,MAAM,UAAU,iBAAiB,CAAC,MAAc,EAAE,OAAO,GAAG,+CAA+C;IACzG,OAAO,IAAI,cAAc,CAAC;QACxB,IAAI,EAAE,YAAY;QAClB,MAAM;QACN,OAAO,EAAE,GAAG,OAAO,KAAK;QACxB,YAAY,EAAE,UAAU;KACzB,CAAC,CAAC;AACL,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,IAAI,cAAc,CAAC;QACxB,IAAI,EAAE,QAAQ;QACd,MAAM;QACN,OAAO,EAAE,8BAA8B;QACvC,YAAY,EAAE,UAAU;KACzB,CAAC,CAAC;AACL,CAAC;AAED,mCAAmC;AACnC,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,IAAI,cAAc,CAAC;QACxB,IAAI,EAAE,QAAQ;QACd,MAAM;QACN,OAAO,EAAE,2BAA2B;QACpC,YAAY,EAAE,aAAa;KAC5B,CAAC,CAAC;AACL,CAAC;AAED,iCAAiC;AACjC,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,IAAI,cAAc,CAAC;QACxB,IAAI,EAAE,MAAM;QACZ,MAAM;QACN,OAAO,EAAE,gCAAgC;QACzC,YAAY,EAAE,yBAAyB;KACxC,CAAC,CAAC;AACL,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,cAAc,CAAC,KAAK,GAAG,UAAU,EAAE,OAAO,GAAG,wBAAwB;IACnF,OAAO,IAAI,cAAc,CAAC;QACxB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,GAAG,OAAO,KAAK;QACxB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;AACL,CAAC"}
|
package/dist/skills.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Skill, ToolDef } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a SKILL.md file into a Skill object.
|
|
4
|
+
*
|
|
5
|
+
* Format:
|
|
6
|
+
* ```
|
|
7
|
+
* ---
|
|
8
|
+
* name: my-skill
|
|
9
|
+
* description: Does something useful
|
|
10
|
+
* tools:
|
|
11
|
+
* - name: do_thing
|
|
12
|
+
* description: Does the thing
|
|
13
|
+
* parameters:
|
|
14
|
+
* type: object
|
|
15
|
+
* properties:
|
|
16
|
+
* input:
|
|
17
|
+
* type: string
|
|
18
|
+
* description: The input
|
|
19
|
+
* required: [input]
|
|
20
|
+
* ---
|
|
21
|
+
*
|
|
22
|
+
* # My Skill
|
|
23
|
+
*
|
|
24
|
+
* Instructions for the LLM on how to use this skill...
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseSkill(raw: string, source: string): Skill;
|
|
28
|
+
/**
|
|
29
|
+
* Load a single skill from a file path.
|
|
30
|
+
* Accepts either a SKILL.md file or a directory containing SKILL.md.
|
|
31
|
+
*/
|
|
32
|
+
export declare function loadSkill(path: string): Skill;
|
|
33
|
+
/**
|
|
34
|
+
* Discover and load all skills from a directory.
|
|
35
|
+
* Looks for:
|
|
36
|
+
* - *.md files with YAML frontmatter in the directory
|
|
37
|
+
* - Subdirectories containing SKILL.md
|
|
38
|
+
*/
|
|
39
|
+
export declare function loadSkillsFromDir(dir: string): Skill[];
|
|
40
|
+
/**
|
|
41
|
+
* Build the skill context string for injection into the system prompt.
|
|
42
|
+
* Uses progressive disclosure: only names + descriptions by default.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildSkillSummary(skills: Skill[]): string;
|
|
45
|
+
/**
|
|
46
|
+
* Build the full skill context for a specific skill (injected when activated).
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildSkillContext(skill: Skill): string;
|
|
49
|
+
/**
|
|
50
|
+
* Collect all tool definitions from loaded skills.
|
|
51
|
+
*/
|
|
52
|
+
export declare function collectTools(skills: Skill[]): ToolDef[];
|
|
53
|
+
//# sourceMappingURL=skills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../src/skills.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAoB,OAAO,EAAgB,MAAM,YAAY,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CA+B7D;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAe7C;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,EAAE,CAkCtD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAQzD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAEtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAEvD"}
|
package/dist/skills.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
/**
|
|
5
|
+
* Parse a SKILL.md file into a Skill object.
|
|
6
|
+
*
|
|
7
|
+
* Format:
|
|
8
|
+
* ```
|
|
9
|
+
* ---
|
|
10
|
+
* name: my-skill
|
|
11
|
+
* description: Does something useful
|
|
12
|
+
* tools:
|
|
13
|
+
* - name: do_thing
|
|
14
|
+
* description: Does the thing
|
|
15
|
+
* parameters:
|
|
16
|
+
* type: object
|
|
17
|
+
* properties:
|
|
18
|
+
* input:
|
|
19
|
+
* type: string
|
|
20
|
+
* description: The input
|
|
21
|
+
* required: [input]
|
|
22
|
+
* ---
|
|
23
|
+
*
|
|
24
|
+
* # My Skill
|
|
25
|
+
*
|
|
26
|
+
* Instructions for the LLM on how to use this skill...
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function parseSkill(raw, source) {
|
|
30
|
+
const fmMatch = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
31
|
+
if (!fmMatch) {
|
|
32
|
+
throw new Error(`Invalid skill format in ${source}: missing YAML frontmatter (---)`);
|
|
33
|
+
}
|
|
34
|
+
const frontmatter = parseYaml(fmMatch[1]);
|
|
35
|
+
const content = fmMatch[2].trim();
|
|
36
|
+
if (!frontmatter.name) {
|
|
37
|
+
throw new Error(`Skill in ${source} is missing required 'name' field`);
|
|
38
|
+
}
|
|
39
|
+
if (!frontmatter.description) {
|
|
40
|
+
throw new Error(`Skill in ${source} is missing required 'description' field`);
|
|
41
|
+
}
|
|
42
|
+
const tools = (frontmatter.tools ?? []).map((t) => ({
|
|
43
|
+
type: "function",
|
|
44
|
+
function: {
|
|
45
|
+
name: t.name,
|
|
46
|
+
description: t.description,
|
|
47
|
+
parameters: t.parameters ?? { type: "object", properties: {} },
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
return {
|
|
51
|
+
meta: frontmatter,
|
|
52
|
+
content,
|
|
53
|
+
source,
|
|
54
|
+
tools,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Load a single skill from a file path.
|
|
59
|
+
* Accepts either a SKILL.md file or a directory containing SKILL.md.
|
|
60
|
+
*/
|
|
61
|
+
export function loadSkill(path) {
|
|
62
|
+
const resolved = resolve(path);
|
|
63
|
+
let filePath;
|
|
64
|
+
if (statSync(resolved).isDirectory()) {
|
|
65
|
+
filePath = join(resolved, "SKILL.md");
|
|
66
|
+
if (!existsSync(filePath)) {
|
|
67
|
+
throw new Error(`No SKILL.md found in directory: ${resolved}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
filePath = resolved;
|
|
72
|
+
}
|
|
73
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
74
|
+
return parseSkill(raw, filePath);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Discover and load all skills from a directory.
|
|
78
|
+
* Looks for:
|
|
79
|
+
* - *.md files with YAML frontmatter in the directory
|
|
80
|
+
* - Subdirectories containing SKILL.md
|
|
81
|
+
*/
|
|
82
|
+
export function loadSkillsFromDir(dir) {
|
|
83
|
+
const resolved = resolve(dir);
|
|
84
|
+
if (!existsSync(resolved))
|
|
85
|
+
return [];
|
|
86
|
+
const skills = [];
|
|
87
|
+
const entries = readdirSync(resolved, { withFileTypes: true });
|
|
88
|
+
for (const entry of entries) {
|
|
89
|
+
const fullPath = join(resolved, entry.name);
|
|
90
|
+
if (entry.isDirectory()) {
|
|
91
|
+
// Look for SKILL.md inside subdirectory
|
|
92
|
+
const skillFile = join(fullPath, "SKILL.md");
|
|
93
|
+
if (existsSync(skillFile)) {
|
|
94
|
+
try {
|
|
95
|
+
skills.push(loadSkill(skillFile));
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
console.warn(`[skills] Failed to load ${skillFile}: ${err.message}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (entry.name.endsWith(".md") && entry.name !== "README.md") {
|
|
103
|
+
// Try to parse as a skill
|
|
104
|
+
try {
|
|
105
|
+
const raw = readFileSync(fullPath, "utf-8");
|
|
106
|
+
if (raw.startsWith("---")) {
|
|
107
|
+
skills.push(parseSkill(raw, fullPath));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Not a valid skill file, skip
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return skills;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Build the skill context string for injection into the system prompt.
|
|
119
|
+
* Uses progressive disclosure: only names + descriptions by default.
|
|
120
|
+
*/
|
|
121
|
+
export function buildSkillSummary(skills) {
|
|
122
|
+
if (skills.length === 0)
|
|
123
|
+
return "";
|
|
124
|
+
const lines = skills.map((s) => `- **${s.meta.name}**: ${s.meta.description}`);
|
|
125
|
+
return `\nYou have the following skills available:\n${lines.join("\n")}\n`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Build the full skill context for a specific skill (injected when activated).
|
|
129
|
+
*/
|
|
130
|
+
export function buildSkillContext(skill) {
|
|
131
|
+
return `\n<skill name="${skill.meta.name}">\n${skill.content}\n</skill>\n`;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Collect all tool definitions from loaded skills.
|
|
135
|
+
*/
|
|
136
|
+
export function collectTools(skills) {
|
|
137
|
+
return skills.flatMap((s) => s.tools);
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.js","sourceRoot":"","sources":["../src/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,MAAc;IACpD,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAChE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,kCAAkC,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAqB,CAAC;IAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,C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