@node-llm/core 0.2.2 → 0.3.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/README.md +125 -4
- package/dist/chat/Chat.d.ts +32 -16
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +102 -32
- package/dist/chat/ChatOptions.d.ts +5 -0
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +18 -0
- package/dist/chat/ChatResponse.d.ts.map +1 -0
- package/dist/chat/ChatResponse.js +26 -0
- package/dist/chat/Stream.d.ts.map +1 -1
- package/dist/chat/Stream.js +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/llm.d.ts +25 -3
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +48 -1
- package/dist/models/ModelRegistry.d.ts +23 -0
- package/dist/models/ModelRegistry.d.ts.map +1 -0
- package/dist/models/ModelRegistry.js +54 -0
- package/dist/moderation/Moderation.d.ts +56 -0
- package/dist/moderation/Moderation.d.ts.map +1 -0
- package/dist/moderation/Moderation.js +92 -0
- package/dist/providers/Provider.d.ts +39 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +1 -0
- package/dist/providers/openai/Moderation.d.ts +8 -0
- package/dist/providers/openai/Moderation.d.ts.map +1 -0
- package/dist/providers/openai/Moderation.js +26 -0
- package/dist/providers/openai/OpenAIProvider.d.ts +6 -1
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +12 -0
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +19 -8
- package/dist/providers/openai/Transcription.d.ts +10 -0
- package/dist/providers/openai/Transcription.d.ts.map +1 -0
- package/dist/providers/openai/Transcription.js +161 -0
- package/dist/providers/openai/index.d.ts +8 -0
- package/dist/providers/openai/index.d.ts.map +1 -1
- package/dist/providers/openai/index.js +12 -0
- package/dist/transcription/Transcription.d.ts +11 -0
- package/dist/transcription/Transcription.d.ts.map +1 -0
- package/dist/transcription/Transcription.js +21 -0
- package/dist/utils/FileLoader.d.ts.map +1 -1
- package/dist/utils/FileLoader.js +12 -1
- package/dist/utils/audio.d.ts +10 -0
- package/dist/utils/audio.d.ts.map +1 -0
- package/dist/utils/audio.js +46 -0
- package/package.json +17 -7
- package/dist/providers/openai/register.d.ts +0 -2
- package/dist/providers/openai/register.d.ts.map +0 -1
- package/dist/providers/openai/register.js +0 -15
- package/dist/tools/Tool.d.ts +0 -8
- package/dist/tools/Tool.d.ts.map +0 -1
- package/dist/tools/Tool.js +0 -1
- package/dist/tools/ToolSet.d.ts +0 -15
- package/dist/tools/ToolSet.d.ts.map +0 -1
- package/dist/tools/ToolSet.js +0 -29
- package/dist/tools/index.d.ts +0 -2
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -1
- package/dist/tools/runCommandTool.d.ts +0 -8
- package/dist/tools/runCommandTool.d.ts.map +0 -1
- package/dist/tools/runCommandTool.js +0 -19
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { handleOpenAIError } from "./Errors.js";
|
|
2
|
+
import { AudioUtils } from "../../utils/audio.js";
|
|
3
|
+
export class OpenAITranscription {
|
|
4
|
+
baseUrl;
|
|
5
|
+
apiKey;
|
|
6
|
+
constructor(baseUrl, apiKey) {
|
|
7
|
+
this.baseUrl = baseUrl;
|
|
8
|
+
this.apiKey = apiKey;
|
|
9
|
+
}
|
|
10
|
+
async execute(request) {
|
|
11
|
+
const model = request.model || "whisper-1";
|
|
12
|
+
if (model.startsWith("gpt-4o")) {
|
|
13
|
+
return this.transcribeViaChat(request);
|
|
14
|
+
}
|
|
15
|
+
return this.transcribeViaWhisper(request);
|
|
16
|
+
}
|
|
17
|
+
async transcribeViaWhisper(request) {
|
|
18
|
+
const formData = new FormData();
|
|
19
|
+
const { data, fileName, duration: estimatedDuration } = await AudioUtils.load(request.file);
|
|
20
|
+
const mimeType = fileName.endsWith(".wav") ? "audio/wav" : "audio/mpeg";
|
|
21
|
+
const file = new File([data], fileName, { type: mimeType });
|
|
22
|
+
formData.append("file", file);
|
|
23
|
+
formData.append("model", request.model || "whisper-1");
|
|
24
|
+
formData.append("response_format", "verbose_json");
|
|
25
|
+
if (request.prompt) {
|
|
26
|
+
formData.append("prompt", request.prompt);
|
|
27
|
+
}
|
|
28
|
+
if (request.language) {
|
|
29
|
+
formData.append("language", request.language);
|
|
30
|
+
}
|
|
31
|
+
const response = await fetch(`${this.baseUrl}/audio/transcriptions`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
35
|
+
},
|
|
36
|
+
body: formData,
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
await handleOpenAIError(response, request.model || "whisper-1");
|
|
40
|
+
}
|
|
41
|
+
const json = (await response.json());
|
|
42
|
+
return {
|
|
43
|
+
text: json.text,
|
|
44
|
+
model: json.model || request.model || "whisper-1",
|
|
45
|
+
duration: json.duration || estimatedDuration,
|
|
46
|
+
segments: json.segments?.map(s => ({
|
|
47
|
+
id: s.id,
|
|
48
|
+
start: s.start,
|
|
49
|
+
end: s.end,
|
|
50
|
+
text: s.text
|
|
51
|
+
}))
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async transcribeViaChat(request) {
|
|
55
|
+
const { data, fileName, duration: estimatedDuration } = await AudioUtils.load(request.file);
|
|
56
|
+
const base64Audio = Buffer.from(data).toString("base64");
|
|
57
|
+
const model = request.model || "gpt-4o";
|
|
58
|
+
let actualModel = "gpt-4o-audio-preview";
|
|
59
|
+
let defaultPrompt = "Transcribe the audio exactly. Return only the transcription text.";
|
|
60
|
+
let isDiarization = false;
|
|
61
|
+
if (model.includes("diarize")) {
|
|
62
|
+
isDiarization = true;
|
|
63
|
+
const names = request.speakerNames?.join(", ") || "Speaker A, Speaker B";
|
|
64
|
+
defaultPrompt = `Transcribe the audio and identify different speakers.
|
|
65
|
+
I will provide reference clips for specific voices. Please map the voices in the main audio to these names: ${names}.
|
|
66
|
+
Return the output as a JSON array of objects, each with 'speaker', 'text', 'start', and 'end' (in seconds).
|
|
67
|
+
Example: [{"speaker": "Alice", "text": "Hello", "start": 0.5, "end": 1.2}]`;
|
|
68
|
+
}
|
|
69
|
+
if (request.language) {
|
|
70
|
+
defaultPrompt += ` The audio is in ${request.language}.`;
|
|
71
|
+
}
|
|
72
|
+
const messagesContent = [
|
|
73
|
+
{
|
|
74
|
+
type: "text",
|
|
75
|
+
text: request.prompt
|
|
76
|
+
? `${defaultPrompt}\n\nContext for transcription: ${request.prompt}`
|
|
77
|
+
: defaultPrompt
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
if (request.speakerReferences && request.speakerNames) {
|
|
81
|
+
for (let i = 0; i < request.speakerReferences.length; i++) {
|
|
82
|
+
const refFile = request.speakerReferences[i];
|
|
83
|
+
if (!refFile)
|
|
84
|
+
continue;
|
|
85
|
+
const name = request.speakerNames[i] || `Speaker ${i + 1}`;
|
|
86
|
+
const { data: refData } = await AudioUtils.load(refFile);
|
|
87
|
+
const refBase64 = Buffer.from(refData).toString("base64");
|
|
88
|
+
messagesContent.push({
|
|
89
|
+
type: "text",
|
|
90
|
+
text: `The following audio clip is the voice of ${name}:`
|
|
91
|
+
});
|
|
92
|
+
messagesContent.push({
|
|
93
|
+
type: "input_audio",
|
|
94
|
+
input_audio: {
|
|
95
|
+
data: refBase64,
|
|
96
|
+
format: refFile.endsWith(".wav") ? "wav" : "mp3"
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
messagesContent.push({
|
|
101
|
+
type: "text",
|
|
102
|
+
text: "Now, transcribe this main audio file using identified names:"
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
messagesContent.push({
|
|
106
|
+
type: "input_audio",
|
|
107
|
+
input_audio: {
|
|
108
|
+
data: base64Audio,
|
|
109
|
+
format: fileName.endsWith(".wav") ? "wav" : "mp3"
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const body = {
|
|
113
|
+
model: actualModel,
|
|
114
|
+
messages: [
|
|
115
|
+
{
|
|
116
|
+
role: "user",
|
|
117
|
+
content: messagesContent
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
};
|
|
121
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: {
|
|
124
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
125
|
+
"Content-Type": "application/json",
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify(body),
|
|
128
|
+
});
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
await handleOpenAIError(response, actualModel);
|
|
131
|
+
}
|
|
132
|
+
const json = await response.json();
|
|
133
|
+
const content = json.choices[0]?.message?.content || "";
|
|
134
|
+
let text = content;
|
|
135
|
+
let segments = [];
|
|
136
|
+
if (isDiarization) {
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(content);
|
|
139
|
+
if (Array.isArray(parsed)) {
|
|
140
|
+
segments = parsed.map((s, i) => ({
|
|
141
|
+
id: i,
|
|
142
|
+
start: s.start || 0,
|
|
143
|
+
end: s.end || 0,
|
|
144
|
+
text: s.text || "",
|
|
145
|
+
speaker: s.speaker
|
|
146
|
+
}));
|
|
147
|
+
text = segments.map(s => `${s.speaker}: ${s.text}`).join("\n");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
text = content;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
text,
|
|
156
|
+
model,
|
|
157
|
+
duration: estimatedDuration || 0,
|
|
158
|
+
segments
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotent registration of the OpenAI provider.
|
|
3
|
+
* Automatically called by LLM.configure({ provider: 'openai' })
|
|
4
|
+
*/
|
|
1
5
|
export declare function registerOpenAIProvider(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Alias for registerOpenAIProvider for internal use.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ensureOpenAIRegistered: typeof registerOpenAIProvider;
|
|
2
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/index.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,sBAAsB,SAcrC;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,+BAAyB,CAAC"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { providerRegistry } from "../registry.js";
|
|
2
2
|
import { OpenAIProvider } from "./OpenAIProvider.js";
|
|
3
|
+
let registered = false;
|
|
4
|
+
/**
|
|
5
|
+
* Idempotent registration of the OpenAI provider.
|
|
6
|
+
* Automatically called by LLM.configure({ provider: 'openai' })
|
|
7
|
+
*/
|
|
3
8
|
export function registerOpenAIProvider() {
|
|
9
|
+
if (registered)
|
|
10
|
+
return;
|
|
4
11
|
providerRegistry.register("openai", () => {
|
|
5
12
|
const apiKey = process.env.OPENAI_API_KEY;
|
|
6
13
|
if (!apiKey) {
|
|
@@ -8,4 +15,9 @@ export function registerOpenAIProvider() {
|
|
|
8
15
|
}
|
|
9
16
|
return new OpenAIProvider({ apiKey });
|
|
10
17
|
});
|
|
18
|
+
registered = true;
|
|
11
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Alias for registerOpenAIProvider for internal use.
|
|
22
|
+
*/
|
|
23
|
+
export const ensureOpenAIRegistered = registerOpenAIProvider;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TranscriptionResponse, TranscriptionSegment } from "../providers/Provider.js";
|
|
2
|
+
export declare class Transcription {
|
|
3
|
+
private readonly response;
|
|
4
|
+
constructor(response: TranscriptionResponse);
|
|
5
|
+
get text(): string;
|
|
6
|
+
get model(): string;
|
|
7
|
+
get segments(): TranscriptionSegment[];
|
|
8
|
+
get duration(): number | undefined;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Transcription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../src/transcription/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEvF,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,qBAAqB;IAE5D,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,QAAQ,IAAI,oBAAoB,EAAE,CAErC;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjC;IAED,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class Transcription {
|
|
2
|
+
response;
|
|
3
|
+
constructor(response) {
|
|
4
|
+
this.response = response;
|
|
5
|
+
}
|
|
6
|
+
get text() {
|
|
7
|
+
return this.response.text;
|
|
8
|
+
}
|
|
9
|
+
get model() {
|
|
10
|
+
return this.response.model;
|
|
11
|
+
}
|
|
12
|
+
get segments() {
|
|
13
|
+
return this.response.segments || [];
|
|
14
|
+
}
|
|
15
|
+
get duration() {
|
|
16
|
+
return this.response.duration;
|
|
17
|
+
}
|
|
18
|
+
toString() {
|
|
19
|
+
return this.text;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileLoader.d.ts","sourceRoot":"","sources":["../../src/utils/FileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"FileLoader.d.ts","sourceRoot":"","sources":["../../src/utils/FileLoader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA0CjD,qBAAa,UAAU;WACR,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CA+C1D"}
|
package/dist/utils/FileLoader.js
CHANGED
|
@@ -13,6 +13,8 @@ const MIME_TYPES = {
|
|
|
13
13
|
".mp3": "audio/mpeg",
|
|
14
14
|
".json": "application/json",
|
|
15
15
|
".js": "text/javascript",
|
|
16
|
+
".mjs": "text/javascript",
|
|
17
|
+
".cjs": "text/javascript",
|
|
16
18
|
".ts": "text/typescript",
|
|
17
19
|
".rb": "text/x-ruby",
|
|
18
20
|
".py": "text/x-python",
|
|
@@ -23,9 +25,18 @@ const MIME_TYPES = {
|
|
|
23
25
|
".xml": "text/xml",
|
|
24
26
|
".yml": "text/yaml",
|
|
25
27
|
".yaml": "text/yaml",
|
|
28
|
+
".csv": "text/csv",
|
|
29
|
+
".go": "text/x-go",
|
|
30
|
+
".java": "text/x-java",
|
|
31
|
+
".c": "text/x-c",
|
|
32
|
+
".cpp": "text/x-c++",
|
|
33
|
+
".rs": "text/x-rust",
|
|
34
|
+
".swift": "text/x-swift",
|
|
35
|
+
".kt": "text/x-kotlin",
|
|
26
36
|
};
|
|
27
37
|
const TEXT_EXTENSIONS = new Set([
|
|
28
|
-
".json", ".js", ".ts", ".rb", ".py", ".txt", ".md", ".html", ".css", ".xml", ".yml", ".yaml", ".env"
|
|
38
|
+
".json", ".js", ".mjs", ".cjs", ".ts", ".rb", ".py", ".txt", ".md", ".html", ".css", ".xml", ".yml", ".yaml", ".env",
|
|
39
|
+
".csv", ".go", ".java", ".c", ".cpp", ".rs", ".swift", ".kt"
|
|
29
40
|
]);
|
|
30
41
|
export class FileLoader {
|
|
31
42
|
static async load(filePath) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface AudioFileData {
|
|
2
|
+
data: Uint8Array;
|
|
3
|
+
fileName: string;
|
|
4
|
+
duration?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class AudioUtils {
|
|
7
|
+
static load(filePath: string): Promise<AudioFileData>;
|
|
8
|
+
static estimateDuration(data: Uint8Array, fileName: string): number | undefined;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=audio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/utils/audio.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,UAAU;WACR,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAuB3D,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAkBhF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export class AudioUtils {
|
|
4
|
+
static async load(filePath) {
|
|
5
|
+
let data;
|
|
6
|
+
let fileName;
|
|
7
|
+
if (filePath.startsWith("http")) {
|
|
8
|
+
const response = await fetch(filePath);
|
|
9
|
+
if (!response.ok) {
|
|
10
|
+
throw new Error(`Failed to fetch remote audio file: ${response.statusText}`);
|
|
11
|
+
}
|
|
12
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
13
|
+
data = new Uint8Array(arrayBuffer);
|
|
14
|
+
const urlPath = new URL(filePath).pathname;
|
|
15
|
+
fileName = path.basename(urlPath) || "audio.mp3";
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const buffer = fs.readFileSync(filePath);
|
|
19
|
+
data = new Uint8Array(buffer);
|
|
20
|
+
fileName = path.basename(filePath);
|
|
21
|
+
}
|
|
22
|
+
const duration = this.estimateDuration(data, fileName);
|
|
23
|
+
return { data, fileName, duration };
|
|
24
|
+
}
|
|
25
|
+
static estimateDuration(data, fileName) {
|
|
26
|
+
try {
|
|
27
|
+
const ext = path.extname(fileName).toLowerCase();
|
|
28
|
+
if (ext === ".wav") {
|
|
29
|
+
// Simple WAV duration: (DataSize / ByteRate)
|
|
30
|
+
const view = new DataView(data.buffer, data.byteOffset, data.length);
|
|
31
|
+
const byteRate = view.getUint32(28, true);
|
|
32
|
+
const dataSize = view.getUint32(40, true);
|
|
33
|
+
if (byteRate > 0)
|
|
34
|
+
return dataSize / byteRate;
|
|
35
|
+
}
|
|
36
|
+
else if (ext === ".mp3") {
|
|
37
|
+
// Very rough MP3 estimate (assume 128kbps)
|
|
38
|
+
return data.length / (128000 / 8);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
// Ignore estimation errors
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-llm/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -13,17 +13,27 @@
|
|
|
13
13
|
"description": "A provider-agnostic LLM core for Node.js, inspired by ruby-llm.",
|
|
14
14
|
"author": "node-llm contributors",
|
|
15
15
|
"license": "MIT",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20.0.0"
|
|
18
|
+
},
|
|
16
19
|
"files": [
|
|
17
20
|
"dist",
|
|
18
21
|
"README.md"
|
|
19
22
|
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"zod": "^3.23.8"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@pollyjs/adapter-fetch": "^6.0.7",
|
|
28
|
+
"@pollyjs/adapter-node-http": "^6.0.6",
|
|
29
|
+
"@pollyjs/core": "^6.0.6",
|
|
30
|
+
"@pollyjs/persister-fs": "^6.0.6"
|
|
31
|
+
},
|
|
20
32
|
"scripts": {
|
|
21
33
|
"build": "tsc -p tsconfig.json",
|
|
22
34
|
"dev": "tsc -w",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"zod": "^3.23.8"
|
|
35
|
+
"lint": "tsc --noEmit",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:watch": "vitest"
|
|
28
38
|
}
|
|
29
|
-
}
|
|
39
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/register.ts"],"names":[],"mappings":"AAKA,wBAAgB,sBAAsB,SAcrC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { providerRegistry } from "../registry.js";
|
|
2
|
-
import { OpenAIProvider } from "./OpenAIProvider.js";
|
|
3
|
-
let registered = false;
|
|
4
|
-
export function ensureOpenAIRegistered() {
|
|
5
|
-
if (registered)
|
|
6
|
-
return;
|
|
7
|
-
providerRegistry.register("openai", () => {
|
|
8
|
-
const apiKey = process.env.OPENAI_API_KEY;
|
|
9
|
-
if (!apiKey) {
|
|
10
|
-
throw new Error("OPENAI_API_KEY is not set");
|
|
11
|
-
}
|
|
12
|
-
return new OpenAIProvider({ apiKey });
|
|
13
|
-
});
|
|
14
|
-
registered = true;
|
|
15
|
-
}
|
package/dist/tools/Tool.d.ts
DELETED
package/dist/tools/Tool.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tool.d.ts","sourceRoot":"","sources":["../../src/tools/Tool.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAE5D,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,EAAE,WAAW,CAAC;CACtB"}
|
package/dist/tools/Tool.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/tools/ToolSet.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Tool, ToolHandler } from "./Tool.js";
|
|
2
|
-
type ToolDefinition = ToolHandler | {
|
|
3
|
-
description?: string;
|
|
4
|
-
parameters?: Record<string, any>;
|
|
5
|
-
handler: ToolHandler;
|
|
6
|
-
};
|
|
7
|
-
export declare class ToolSet {
|
|
8
|
-
private tools;
|
|
9
|
-
constructor(defs?: Record<string, ToolDefinition>);
|
|
10
|
-
register(tool: Tool): void;
|
|
11
|
-
get(name: string): Tool | undefined;
|
|
12
|
-
list(): Tool[];
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=ToolSet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolSet.d.ts","sourceRoot":"","sources":["../../src/tools/ToolSet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE9C,KAAK,cAAc,GACf,WAAW,GACX;IACE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,EAAE,WAAW,CAAC;CACtB,CAAC;AAEN,qBAAa,OAAO;IAClB,OAAO,CAAC,KAAK,CAA2B;gBAE5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC;IAiBjD,QAAQ,CAAC,IAAI,EAAE,IAAI;IAInB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAInC,IAAI,IAAI,IAAI,EAAE;CAGf"}
|
package/dist/tools/ToolSet.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export class ToolSet {
|
|
2
|
-
tools = new Map();
|
|
3
|
-
constructor(defs) {
|
|
4
|
-
if (defs) {
|
|
5
|
-
for (const [name, def] of Object.entries(defs)) {
|
|
6
|
-
if (typeof def === "function") {
|
|
7
|
-
this.register({ name, handler: def });
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
this.register({
|
|
11
|
-
name,
|
|
12
|
-
handler: def.handler,
|
|
13
|
-
description: def.description,
|
|
14
|
-
parameters: def.parameters,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
register(tool) {
|
|
21
|
-
this.tools.set(tool.name, tool);
|
|
22
|
-
}
|
|
23
|
-
get(name) {
|
|
24
|
-
return this.tools.get(name);
|
|
25
|
-
}
|
|
26
|
-
list() {
|
|
27
|
-
return [...this.tools.values()];
|
|
28
|
-
}
|
|
29
|
-
}
|
package/dist/tools/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/tools/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { runCommand } from './runCommandTool.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executes a shell command and returns its stdout as a string.
|
|
3
|
-
*
|
|
4
|
-
* @param command - The command to execute.
|
|
5
|
-
* @returns A promise that resolves with the command's standard output.
|
|
6
|
-
*/
|
|
7
|
-
export declare function runCommand(command: string): Promise<string>;
|
|
8
|
-
//# sourceMappingURL=runCommandTool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runCommandTool.d.ts","sourceRoot":"","sources":["../../src/tools/runCommandTool.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW3D"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { exec } from 'child_process';
|
|
2
|
-
/**
|
|
3
|
-
* Executes a shell command and returns its stdout as a string.
|
|
4
|
-
*
|
|
5
|
-
* @param command - The command to execute.
|
|
6
|
-
* @returns A promise that resolves with the command's standard output.
|
|
7
|
-
*/
|
|
8
|
-
export function runCommand(command) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
exec(command, { maxBuffer: 1024 * 1024 }, (error, stdout, stderr) => {
|
|
11
|
-
if (error) {
|
|
12
|
-
reject(error);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
// Trim trailing newlines for cleaner output
|
|
16
|
-
resolve(stdout.trim());
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|